From 34365b696c4693103804ea8068e7af5f704ee207 Mon Sep 17 00:00:00 2001 From: Ferry Boender Date: Sun, 2 Oct 2016 10:21:13 +0200 Subject: [PATCH] Code quality: logging --- src/daemon.py | 4 ++-- src/runscript.py | 12 ++++++------ src/scriptform.py | 2 +- src/webapp.py | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/daemon.py b/src/daemon.py index d62277b..e0dc358 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 = %s", (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 %s", (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 e6b5736..c75e083 100644 --- a/src/runscript.py +++ b/src/runscript.py @@ -61,14 +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("%s", (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 '%s'", (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. @@ -82,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: %s", (proc.returncode)) + log.info("Exit code: %s", proc.returncode) return proc.returncode except OSError as err: log.exception(err) @@ -99,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: %s", (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 6e26f5e..02f0649 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 %s:%s", (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 6475bac..ebc8a98 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: %s", (form_def.script)) - log.info("Current working dir: %s", (cwd)) - log.info("User: %s", (username)) - log.info("Variables: %s", (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,