summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2023-03-07 23:54:05 +0200
committerMaxim Devaev <[email protected]>2023-03-07 23:54:05 +0200
commitf652eca9c213dd783cf2ffd02109b2353ccb86c1 (patch)
tree3c2a5c68e0b03536ec5c482b9b5be708795e8292
parent002031baf15d328dad764a620e1c83c01e7a55a6 (diff)
refactoring
-rwxr-xr-xgenmap.py4
-rw-r--r--kvmd/apps/htpasswd/__init__.py4
-rw-r--r--kvmd/apps/ipmi/auth.py4
-rw-r--r--kvmd/apps/kvmd/auth.py4
-rw-r--r--kvmd/apps/otg/__init__.py8
-rw-r--r--kvmd/apps/otgconf/__init__.py16
-rw-r--r--kvmd/apps/otgmsd/__init__.py8
-rw-r--r--kvmd/apps/otgnet/__init__.py4
-rw-r--r--kvmd/apps/watchdog/__init__.py8
-rw-r--r--kvmd/keyboard/keysym.py4
-rw-r--r--kvmd/plugins/auth/radius.py4
-rw-r--r--kvmd/plugins/hid/otg/device.py4
-rw-r--r--kvmd/plugins/msd/otg/drive.py8
-rw-r--r--kvmd/plugins/ugpio/otgconf.py8
-rw-r--r--kvmd/yamlconf/loader.py10
15 files changed, 49 insertions, 49 deletions
diff --git a/genmap.py b/genmap.py
index 5e827725..edb40f53 100755
--- a/genmap.py
+++ b/genmap.py
@@ -117,8 +117,8 @@ def _parse_ps2_key(key: str) -> _Ps2Key:
def _read_keymap_csv(path: str) -> list[_KeyMapping]:
keymap: list[_KeyMapping] = []
- with open(path) as keymap_file:
- for row in csv.DictReader(keymap_file):
+ with open(path) as file:
+ for row in csv.DictReader(file):
if len(row) >= 6:
keymap.append(_KeyMapping(
web_name=row["web_name"],
diff --git a/kvmd/apps/htpasswd/__init__.py b/kvmd/apps/htpasswd/__init__.py
index dd1213f7..b3862965 100644
--- a/kvmd/apps/htpasswd/__init__.py
+++ b/kvmd/apps/htpasswd/__init__.py
@@ -59,8 +59,8 @@ def _get_htpasswd_for_write(config: Section) -> Generator[passlib.apache.Htpassw
try:
try:
st = os.stat(path)
- with open(path, "rb") as htpasswd_file:
- os.write(tmp_fd, htpasswd_file.read())
+ with open(path, "rb") as file:
+ os.write(tmp_fd, file.read())
os.fchown(tmp_fd, st.st_uid, st.st_gid)
os.fchmod(tmp_fd, st.st_mode)
finally:
diff --git a/kvmd/apps/ipmi/auth.py b/kvmd/apps/ipmi/auth.py
index 2e495af8..e5c004eb 100644
--- a/kvmd/apps/ipmi/auth.py
+++ b/kvmd/apps/ipmi/auth.py
@@ -40,8 +40,8 @@ class IpmiUserCredentials:
class IpmiAuthManager:
def __init__(self, path: str) -> None:
self.__path = path
- with open(path) as passwd_file:
- self.__credentials = self.__parse_passwd_file(passwd_file.read().split("\n"))
+ with open(path) as file:
+ self.__credentials = self.__parse_passwd_file(file.read().split("\n"))
def __contains__(self, ipmi_user: str) -> bool:
return (ipmi_user in self.__credentials)
diff --git a/kvmd/apps/kvmd/auth.py b/kvmd/apps/kvmd/auth.py
index 02639eb0..cb4869f0 100644
--- a/kvmd/apps/kvmd/auth.py
+++ b/kvmd/apps/kvmd/auth.py
@@ -77,8 +77,8 @@ class AuthManager:
assert self.__internal_service
if self.__totp_secret_path:
- with open(self.__totp_secret_path) as secret_file:
- secret = secret_file.read().strip()
+ with open(self.__totp_secret_path) as file:
+ secret = file.read().strip()
if secret:
code = passwd[-6:]
if not pyotp.TOTP(secret).verify(code):
diff --git a/kvmd/apps/otg/__init__.py b/kvmd/apps/otg/__init__.py
index 560d84bb..bb24a199 100644
--- a/kvmd/apps/otg/__init__.py
+++ b/kvmd/apps/otg/__init__.py
@@ -80,14 +80,14 @@ def _write(path: str, value: (str | int), optional: bool=False) -> None:
logger.info("WRITE --- [SKIPPED] %s", path)
return
logger.info("WRITE --- %s", path)
- with open(path, "w") as param_file:
- param_file.write(str(value))
+ with open(path, "w") as file:
+ file.write(str(value))
def _write_bytes(path: str, data: bytes) -> None:
get_logger().info("WRITE --- %s", path)
- with open(path, "wb") as param_file:
- param_file.write(data)
+ with open(path, "wb") as file:
+ file.write(data)
def _check_config(config: Section) -> None:
diff --git a/kvmd/apps/otgconf/__init__.py b/kvmd/apps/otgconf/__init__.py
index 1a1e0f99..f6aa99ef 100644
--- a/kvmd/apps/otgconf/__init__.py
+++ b/kvmd/apps/otgconf/__init__.py
@@ -49,22 +49,22 @@ class _GadgetControl:
def __udc_stopped(self) -> Generator[None, None, None]:
udc = usb.find_udc(self.__udc)
udc_path = usb.get_gadget_path(self.__gadget, usb.G_UDC)
- with open(udc_path) as udc_file:
- enabled = bool(udc_file.read().strip())
+ with open(udc_path) as file:
+ enabled = bool(file.read().strip())
if enabled:
- with open(udc_path, "w") as udc_file:
- udc_file.write("\n")
+ with open(udc_path, "w") as file:
+ file.write("\n")
try:
yield
finally:
time.sleep(self.__init_delay)
- with open(udc_path, "w") as udc_file:
- udc_file.write(udc)
+ with open(udc_path, "w") as file:
+ file.write(udc)
def __read_metas(self) -> Generator[dict, None, None]:
for meta_name in sorted(os.listdir(self.__meta_path)):
- with open(os.path.join(self.__meta_path, meta_name)) as meta_file:
- yield json.loads(meta_file.read())
+ with open(os.path.join(self.__meta_path, meta_name)) as file:
+ yield json.loads(file.read())
def enable_function(self, func: str) -> None:
with self.__udc_stopped():
diff --git a/kvmd/apps/otgmsd/__init__.py b/kvmd/apps/otgmsd/__init__.py
index 2540eb0b..eb894217 100644
--- a/kvmd/apps/otgmsd/__init__.py
+++ b/kvmd/apps/otgmsd/__init__.py
@@ -39,14 +39,14 @@ def _get_param_path(gadget: str, instance: int, param: str) -> str:
def _get_param(gadget: str, instance: int, param: str) -> str:
- with open(_get_param_path(gadget, instance, param)) as param_file:
- return param_file.read().strip()
+ with open(_get_param_path(gadget, instance, param)) as file:
+ return file.read().strip()
def _set_param(gadget: str, instance: int, param: str, value: str) -> None:
try:
- with open(_get_param_path(gadget, instance, param), "w") as param_file:
- param_file.write(value + "\n")
+ with open(_get_param_path(gadget, instance, param), "w") as file:
+ file.write(value + "\n")
except OSError as err:
if err.errno == errno.EBUSY:
raise SystemExit(f"Can't change {param!r} value because device is locked: {err}")
diff --git a/kvmd/apps/otgnet/__init__.py b/kvmd/apps/otgnet/__init__.py
index 98213346..a3d69216 100644
--- a/kvmd/apps/otgnet/__init__.py
+++ b/kvmd/apps/otgnet/__init__.py
@@ -174,8 +174,8 @@ class _Service: # pylint: disable=too-many-instance-attributes
real_driver = "rndis"
path = usb.get_gadget_path(self.__gadget, usb.G_FUNCTIONS, f"{real_driver}.usb0/ifname")
logger.info("Using OTG gadget %r ...", self.__gadget)
- with open(path) as iface_file:
- iface = iface_file.read().strip()
+ with open(path) as file:
+ iface = file.read().strip()
logger.info("Using OTG Ethernet interface %r ...", iface)
assert iface
return iface
diff --git a/kvmd/apps/watchdog/__init__.py b/kvmd/apps/watchdog/__init__.py
index c8a50729..0e7901b0 100644
--- a/kvmd/apps/watchdog/__init__.py
+++ b/kvmd/apps/watchdog/__init__.py
@@ -44,13 +44,13 @@ def _join_rtc(rtc: int, key: str) -> str:
def _read_int(rtc: int, key: str) -> int:
- with open(_join_rtc(rtc, key)) as value_file:
- return int(value_file.read().strip() or "0")
+ with open(_join_rtc(rtc, key)) as file:
+ return int(file.read().strip() or "0")
def _write_int(rtc: int, key: str, value: int) -> None:
- with open(_join_rtc(rtc, key), "w") as value_file:
- value_file.write(str(value))
+ with open(_join_rtc(rtc, key), "w") as file:
+ file.write(str(value))
def _reset_alarm(rtc: int, timeout: int) -> None:
diff --git a/kvmd/keyboard/keysym.py b/kvmd/keyboard/keysym.py
index e9697717..c744e675 100644
--- a/kvmd/keyboard/keysym.py
+++ b/kvmd/keyboard/keysym.py
@@ -110,8 +110,8 @@ def _read_keyboard_layout(path: str) -> dict[int, list[At1Key]]: # Keysym to ev
logger = get_logger(0)
logger.info("Reading keyboard layout %s ...", path)
- with open(path) as layout_file:
- lines = list(map(str.strip, layout_file.read().split("\n")))
+ with open(path) as file:
+ lines = list(map(str.strip, file.read().split("\n")))
layout: dict[int, list[At1Key]] = {}
for (lineno, line) in enumerate(lines):
diff --git a/kvmd/plugins/auth/radius.py b/kvmd/plugins/auth/radius.py
index d7c6390e..94d27883 100644
--- a/kvmd/plugins/auth/radius.py
+++ b/kvmd/plugins/auth/radius.py
@@ -426,8 +426,8 @@ class Plugin(BaseAuthService):
assert user == user.strip()
assert user
try:
- with io.StringIO(_FREERADUIS_DICT) as dct_file:
- dct = pyrad.dictionary.Dictionary(dct_file)
+ with io.StringIO(_FREERADUIS_DICT) as file:
+ dct = pyrad.dictionary.Dictionary(file)
client = pyrad.client.Client(
server=self.__host,
authport=self.__port,
diff --git a/kvmd/plugins/hid/otg/device.py b/kvmd/plugins/hid/otg/device.py
index 630ad186..e8b4302a 100644
--- a/kvmd/plugins/hid/otg/device.py
+++ b/kvmd/plugins/hid/otg/device.py
@@ -172,8 +172,8 @@ class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-in
return get_logger()
def __is_udc_configured(self) -> bool:
- with open(self.__udc_state_path) as udc_state_file:
- return (udc_state_file.read().strip().lower() == "configured")
+ with open(self.__udc_state_path) as file:
+ return (file.read().strip().lower() == "configured")
def __write_report(self, report: bytes) -> bool:
assert report
diff --git a/kvmd/plugins/msd/otg/drive.py b/kvmd/plugins/msd/otg/drive.py
index 9fc947ab..e5dbdbb1 100644
--- a/kvmd/plugins/msd/otg/drive.py
+++ b/kvmd/plugins/msd/otg/drive.py
@@ -75,13 +75,13 @@ class Drive:
# =====
def __get_param(self, param: str) -> str:
- with open(os.path.join(self.__lun_path, param)) as param_file:
- return param_file.read().strip()
+ with open(os.path.join(self.__lun_path, param)) as file:
+ return file.read().strip()
def __set_param(self, param: str, value: str) -> None:
try:
- with open(os.path.join(self.__lun_path, param), "w") as param_file:
- param_file.write(value + "\n")
+ with open(os.path.join(self.__lun_path, param), "w") as file:
+ file.write(value + "\n")
except OSError as err:
if err.errno == errno.EBUSY:
raise MsdDriveLockedError()
diff --git a/kvmd/plugins/ugpio/otgconf.py b/kvmd/plugins/ugpio/otgconf.py
index 28eae8fe..e24c26b9 100644
--- a/kvmd/plugins/ugpio/otgconf.py
+++ b/kvmd/plugins/ugpio/otgconf.py
@@ -129,12 +129,12 @@ class Plugin(BaseUserGpioDriver):
self.__set_udc_enabled(True)
def __set_udc_enabled(self, enabled: bool) -> None:
- with open(self.__udc_path, "w") as udc_file:
- udc_file.write(self.__udc if enabled else "\n")
+ with open(self.__udc_path, "w") as file:
+ file.write(self.__udc if enabled else "\n")
def __is_udc_enabled(self) -> bool:
- with open(self.__udc_path) as udc_file:
- return bool(udc_file.read().strip())
+ with open(self.__udc_path) as file:
+ return bool(file.read().strip())
def __str__(self) -> str:
return f"GPIO({self._instance_name})"
diff --git a/kvmd/yamlconf/loader.py b/kvmd/yamlconf/loader.py
index 2dedc017..0d2933da 100644
--- a/kvmd/yamlconf/loader.py
+++ b/kvmd/yamlconf/loader.py
@@ -35,9 +35,9 @@ from .. import tools
# =====
def load_yaml_file(path: str) -> Any:
- with open(path) as yaml_file:
+ with open(path) as file:
try:
- return yaml.load(yaml_file, _YamlLoader)
+ return yaml.load(file, _YamlLoader)
except Exception as err:
# Reraise internal exception as standard ValueError and show the incorrect file
raise ValueError(f"Invalid YAML in the file {path!r}:\n{tools.efmt(err)}") from None
@@ -45,9 +45,9 @@ def load_yaml_file(path: str) -> Any:
# =====
class _YamlLoader(yaml.SafeLoader):
- def __init__(self, yaml_file: IO) -> None:
- super().__init__(yaml_file)
- self.__root = os.path.dirname(yaml_file.name)
+ def __init__(self, file: IO) -> None:
+ super().__init__(file)
+ self.__root = os.path.dirname(file.name)
def include(self, node: yaml.nodes.Node) -> Any:
incs: list[str]