From: Christian Herdtweck Date: Tue, 24 Jun 2025 11:52:43 +0000 (+0200) Subject: Fix linter and docstyle warnings for connd & sysmisc X-Git-Tag: v1.7.4~1^2~1 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=ecd1a2feb2c7aa076f36a357c48394b62ccf68bb;p=pyi2ncommon Fix linter and docstyle warnings for connd & sysmisc Ignore for now warnings in convenience modules that are hardly ever used (e.g. text_helpers, log_helpers) --- diff --git a/src/connd_state.py b/src/connd_state.py index 8bb3b18..dfff149 100755 --- a/src/connd_state.py +++ b/src/connd_state.py @@ -81,7 +81,6 @@ class ConndState(object): def complete_str(self): """Return a string representating the complete state.""" - # general parts = [ 'ConndState: online mode = "{0}" (default provider: {1})\n' @@ -207,7 +206,6 @@ class ConndState(object): .. todo:: Use reST parameter description here. """ - state = ConndState() err_code, all_lines = ConndState.run_tell_connd(tell_connd_binary, @@ -219,12 +217,12 @@ class ConndState(object): # first section line = next(output).strip() - state.online_mode = regexp('online mode\s*:\s*(.+)$', line).groups()[0] + state.online_mode = regexp(r'online mode\s*:\s*(.+)$', line).groups()[0] assert state.online_mode in ALL_MODES, \ 'unexpected online mode: {0}'.format(state.online_mode) line = next(output).strip() - state.default_provider = regexp('default provider\s*:\s*(.*)$', + state.default_provider = regexp(r'default provider\s*:\s*(.*)$', line).groups()[0] if len(state.default_provider) == 0: state.default_provider = None @@ -235,19 +233,19 @@ class ConndState(object): line = next(output).strip() assert line == 'subsys', 'expected subsys but got {0}'.format(line) line = next(output).strip() - state.subsys_online = regexp('online\s*:\s*(.*)$', line) \ + state.subsys_online = regexp(r'online\s*:\s*(.*)$', line) \ .groups()[0].split() for subsys in state.subsys_online: assert subsys in ALL_SUBSYS, \ 'unexpected subsys: {0}'.format(subsys) line = next(output).strip() - state.subsys_offline = regexp('offline\s*:\s*(.*)$', line) \ + state.subsys_offline = regexp(r'offline\s*:\s*(.*)$', line) \ .groups()[0].split() for subsys in state.subsys_offline: assert subsys in ALL_SUBSYS, \ 'unexpected subsys: {0}'.format(subsys) line = next(output).strip() - state.subsys_disabled = regexp('disabled\s*:\s*(.*)$', line) \ + state.subsys_disabled = regexp(r'disabled\s*:\s*(.*)$', line) \ .groups()[0].split() for subsys in state.subsys_disabled: assert subsys in ALL_SUBSYS, \ @@ -271,10 +269,10 @@ class ConndState(object): if line == 'end of connection map': break conn_name, conn_info = regexp( - '\[\s*(.+)\s*\]\s*:\s*\(\s*(.*)\s*\)', line).groups() + r'\[\s*(.+)\s*\]\s*:\s*\(\s*(.*)\s*\)', line).groups() expect_new = False else: - conn_actions = regexp('actions\s*:\s*\[\s*(.+)\s*\]', line) \ + conn_actions = regexp(r'actions\s*:\s*\[\s*(.+)\s*\]', line) \ .groups() assert conn_name is not None and conn_info is not None, \ 'error parsing connection maps' @@ -288,7 +286,7 @@ class ConndState(object): # actions line = next(output).strip() - state.actions = regexp('actions\s*:\s*(.*)', line).groups()[0].split() + state.actions = regexp(r'actions\s*:\s*(.*)', line).groups()[0].split() if len(state.actions) == 1 and state.actions[0].strip() == '-': state.actions = [] line = next(output).strip() @@ -296,7 +294,7 @@ class ConndState(object): # online IPs line = next(output).strip() - state.online_ips = regexp('list of online ips\s*:\s*(.*)', line) \ + state.online_ips = regexp(r'list of online ips\s*:\s*(.*)', line) \ .groups()[0].split() if len(state.online_ips) == 1 \ and state.online_ips[0].strip() == 'NONE': @@ -323,7 +321,7 @@ class ConndState(object): # log level line = next(output).strip() state.log_level, state.log_file = \ - regexp('Logging with level (.+)(?:\s+to\s+(.+))?', line).groups() + regexp(r'Logging with level (.+)(?:\s+to\s+(.+))?', line).groups() # done line = next(output).strip() @@ -344,7 +342,6 @@ class ConndState(object): Returns result of :py:func:`run_tell_connd`: (error_code, output_lines). """ - # check args need_provider = True if state == ONLINE_MODE_DIAL_ON_DEMAND: diff --git a/src/sysmisc.py b/src/sysmisc.py index 47d6d43..43ff842 100644 --- a/src/sysmisc.py +++ b/src/sysmisc.py @@ -159,6 +159,8 @@ procmounts = "/proc/mounts" def get_mountpoints_by_type(fstype): """ + Use */proc/mounts* to find filesystem mount points. + Determine where some filesystem is mounted by reading the list of mountpoints from */proc/mounts*. @@ -174,7 +176,7 @@ def get_mountpoints_by_type(fstype): lines = list(m) pat = re.compile(r"^\S+\s+(\S+)\s+" + fstype + r"\s+.*$") mps = [mp.group(1) - for mp in map(lambda l: re.match(pat, l), lines) + for mp in map(lambda line: re.match(pat, line), lines) if mp] except IOError: raise IOError(f"Failed to read {procmounts}") @@ -241,6 +243,7 @@ def hash_file(fname, new=hashlib.sha512, bs=4096): class ServiceState(enum.Enum): """State of a system service, see `get_service_state`.""" + RUNNING = 0 DEAD_WITH_PIDFILE = 1 DEAD_WITH_LOCKFILE = 2 @@ -414,8 +417,7 @@ def replace_file_regex(edited_file, value, regex=None, ignore_fail=False): searched into the config text but matched within a larger regex in in order to avoid any mismatch. - Example: - provider.cnf, 'PROVIDER_LOCALIP,0: "(\\d+)"', 127.0.0.1 + Example: provider.cnf, 'PROVIDER_LOCALIP,0: "(\\d+)"', 127.0.0.1 """ pattern = regex.encode() if regex else "(.+)"