From 0e923f49eb80586bf18fa17284b7dceac4264619 Mon Sep 17 00:00:00 2001 From: Ferry Boender Date: Sun, 2 Oct 2016 10:16:52 +0200 Subject: [PATCH] Code quality: Use proper logging msg formatting --- src/daemon.py | 4 ++-- src/runscript.py | 11 ++++++----- src/scriptform.py | 2 +- src/webapp.py | 8 ++++---- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/daemon.py b/src/daemon.py index 6a42b19..d62277b 100644 --- a/src/daemon.py +++ b/src/daemon.py @@ -136,7 +136,7 @@ class Daemon(object): # pragma: no cover # Fork a child and end parent (so init now owns process) pid = os.fork() if pid > 0: - self.log.info("PID = {0}".format(pid)) + self.log.info("PID = %s", (pid)) pidfile = file(self.pid_file, 'w') pidfile.write(str(pid)) pidfile.close() @@ -165,7 +165,7 @@ class Daemon(object): # pragma: no cover """ Remvoe pid files and call registered shutodnw callbacks. """ - self.log.info("Received signal {0}".format(sig)) + self.log.info("Received signal %s", (sig)) if os.path.exists(self.pid_file): os.unlink(self.pid_file) self.shutdown_callback() diff --git a/src/runscript.py b/src/runscript.py index 37660f6..e6b5736 100644 --- a/src/runscript.py +++ b/src/runscript.py @@ -61,13 +61,14 @@ def run_script(form_def, form_values, stdout=None, stderr=None): ] msg = "Running script as user={0}, gid={1}, groups={2}" run_as_fn = run_as(runas_pw.pw_uid, runas_pw.pw_gid, groups) - log.info(msg.format(runas_pw.pw_name, runas_gr.gr_name, - str(groups))) + log.info("%s", (msg.format(runas_pw.pw_name, + runas_gr.gr_name, + str(groups)))) else: run_as_fn = None if form_def.run_as is not None: log.critical("Not running as root, so we can't run the " - "script as user '{0}'".format(form_def.run_as)) + "script as user '%s'", (form_def.run_as)) # If the form output type is 'raw', we directly stream the output to # the browser. Otherwise we store it for later displaying. @@ -81,7 +82,7 @@ def run_script(form_def, form_values, stdout=None, stderr=None): close_fds=True, preexec_fn=run_as_fn) stdout, stderr = proc.communicate(input) - log.info("Exit code: {0}".format(proc.returncode)) + log.info("Exit code: %s", (proc.returncode)) return proc.returncode except OSError as err: log.exception(err) @@ -98,7 +99,7 @@ def run_script(form_def, form_values, stdout=None, stderr=None): close_fds=True, preexec_fn=run_as_fn) stdout, stderr = proc.communicate() - log.info("Exit code: {0}".format(proc.returncode)) + log.info("Exit code: %s", (proc.returncode)) return { 'stdout': stdout, 'stderr': stderr, diff --git a/src/scriptform.py b/src/scriptform.py index d61e20d..6e26f5e 100755 --- a/src/scriptform.py +++ b/src/scriptform.py @@ -139,7 +139,7 @@ class ScriptForm(object): self.httpd = ThreadedHTTPServer((listen_addr, listen_port), ScriptFormWebApp) self.httpd.daemon_threads = True - self.log.info("Listening on {0}:{1}".format(listen_addr, listen_port)) + self.log.info("Listening on %s:%s", (listen_addr, listen_port)) self.running = True self.httpd.serve_forever() self.running = False diff --git a/src/webapp.py b/src/webapp.py index 255f259..6475bac 100644 --- a/src/webapp.py +++ b/src/webapp.py @@ -413,10 +413,10 @@ class ScriptFormWebApp(RequestHandler): # Log the callback and its parameters for auditing purposes. log = logging.getLogger('CALLBACK_AUDIT') cwd = os.path.realpath(os.curdir) - log.info("Calling script: {0}".format(form_def.script)) - log.info("Current working dir: {0}".format(cwd)) - log.info("User: {0}".format(username)) - log.info("Variables: {0}".format(dict(form_values.items()))) + log.info("Calling script: %s", (form_def.script)) + log.info("Current working dir: %s", (cwd)) + log.info("User: %s", (username)) + log.info("Variables: %s", (dict(form_values.items()))) form_def = form_config.get_form_def(form_name) result = runscript.run_script(form_def, form_values, self.wfile,