summaryrefslogtreecommitdiff
path: root/kvmd/apps
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 /kvmd/apps
parent002031baf15d328dad764a620e1c83c01e7a55a6 (diff)
refactoring
Diffstat (limited to 'kvmd/apps')
-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
8 files changed, 28 insertions, 28 deletions
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: