]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/defer: resolve pylint warning docs-develop-defe-yjbb02/deployments/6458 defer-hard-timeout 1661/head
authorLukáš Ondráček <lukas.ondracek@nic.cz>
Mon, 24 Mar 2025 16:48:20 +0000 (17:48 +0100)
committerLukáš Ondráček <lukas.ondracek@nic.cz>
Mon, 24 Mar 2025 16:48:20 +0000 (17:48 +0100)
python/knot_resolver/controller/supervisord/config_file.py
python/knot_resolver/controller/supervisord/plugin/patch_logger.py

index 743ca4b5790e0e8e8635e31c3ed425b9a5cbfa22..fdde29607a594b028515e136d6f62f00fafd41a7 100644 (file)
@@ -140,9 +140,11 @@ class ProcessTypeConfig:
             logfile=Path(""),  # this will be ignored
         )
 
+
 def sd_booted():
     return os.path.lexists("/run/systemd/system")  # same as in libsystemd
 
+
 @dataclass
 class SupervisordConfig:
     unix_http_server: Path
@@ -181,7 +183,7 @@ class SupervisordConfig:
             logfile=Path("syslog" if config.logging.target == "syslog" else "/dev/null"),
             loglevel=loglevel,  # type: ignore[arg-type]
             target=config.logging.target,
-            systemd_logfile = systemd_logfile,
+            systemd_logfile=systemd_logfile,  # type: ignore[arg-type]
         )
 
 
index 223271baf9c433b3d5424d9f29369e67749454b2..f401d95c877b8278621e2660446bddd06395dd27 100644 (file)
@@ -2,15 +2,15 @@
 # pylint: disable=protected-access
 
 import os
+import re
 import sys
 import traceback
-import re
 from typing import Any, Literal
 
 from supervisor.dispatchers import POutputDispatcher
 from supervisor.loggers import LevelsByName, StreamHandler, SyslogHandler
-from supervisor.supervisord import Supervisor
 from supervisor.process import Subprocess
+from supervisor.supervisord import Supervisor
 
 FORWARD_LOG_LEVEL = LevelsByName.CRIT  # to make sure it's always printed
 
@@ -24,6 +24,7 @@ FORWARD_MSG_PREFIX: str = ""
 
 loglevel_re = re.compile(r"<(\d)>(.*)")
 
+
 def p_output_dispatcher_log(self: POutputDispatcher, data: bytearray):
     if data:
         # parse the input
@@ -45,14 +46,20 @@ def p_output_dispatcher_log(self: POutputDispatcher, data: bytearray):
             if loglevel_match:
                 # just strip the loglevel as supervisor cannot handle it;
                 # used only for target=syslog without systemd
-                line = loglevel_match.group(2)
+                line = loglevel_match.group(2)  # pylint: disable=redefined-loop-name
             else:
                 # no loglevel found, mark as stdio output to retain previous behaviour
                 if self.channel == "stderr":
                     stream = " (stderr)"
                 prefix = FORWARD_MSG_PREFIX
             config.options.logger.log(
-                FORWARD_LOG_LEVEL, FORWARD_MSG_FORMAT, prefix=prefix, name=config.name, stream=stream, data=line, pid=self.process.pid
+                FORWARD_LOG_LEVEL,
+                FORWARD_MSG_FORMAT,
+                prefix=prefix,
+                name=config.name,
+                stream=stream,
+                data=line,
+                pid=self.process.pid,
             )
         config.options.logger.handlers = supervisord_handlers
 
@@ -71,13 +78,13 @@ def _create_handler(fmt, level, target: Literal["stdout", "stderr", "syslog"]) -
 # we use "" as other strings involve creation of file of that name (bool("") == False)
 def _prepare_child_fds(self):
     options = self.config.options
-    options.dup2(self.pipes['child_stdin'], 0)
-    options.dup2(self.pipes['child_stdout'], 1)
+    options.dup2(self.pipes["child_stdin"], 0)
+    options.dup2(self.pipes["child_stdout"], 1)
     if self.config.stderr_logfile != "":
         if self.config.redirect_stderr:
-            options.dup2(self.pipes['child_stdout'], 2)
+            options.dup2(self.pipes["child_stdout"], 2)
         else:
-            options.dup2(self.pipes['child_stderr'], 2)
+            options.dup2(self.pipes["child_stderr"], 2)
     for i in range(3, options.minfds):
         options.close_fd(i)
 
@@ -85,6 +92,7 @@ def _prepare_child_fds(self):
 supervisord_handlers = []
 forward_handlers = []
 
+
 def inject(supervisord: Supervisor, **config: Any) -> Any:  # pylint: disable=useless-return
     try:
         # reconfigure log handlers
@@ -105,7 +113,7 @@ def inject(supervisord: Supervisor, **config: Any) -> Any:  # pylint: disable=us
         POutputDispatcher._log = p_output_dispatcher_log  # noqa: SLF001
 
         # replace setting FDs of subprocesses
-        Subprocess._prepare_child_fds = _prepare_child_fds
+        Subprocess._prepare_child_fds = _prepare_child_fds  # noqa: SLF001
 
         # we forward stdio in all cases, even when logging to syslog. This should prevent the unforturtunate
         # case of swallowing an error message leaving the users confused. To make the forwarded lines obvious