diff options
author | Daniel Narvaez <dwnarvaez@gmail.com> | 2012-12-26 17:16:07 (GMT) |
---|---|---|
committer | Daniel Narvaez <dwnarvaez@gmail.com> | 2012-12-26 18:17:29 (GMT) |
commit | dab868b20b936add86967eafe32711413b80dd6e (patch) | |
tree | 60fa49f59a8de148bd3fad607f688851678bbde8 /devbot/command.py | |
parent | 67d36d7eed2bf07063ba9cc7b3720f1efa4560ce (diff) |
Rework logging and output
Use the logs for all the commands output. Tail the log
if there is an error. Create a link to the latest log
so that buildbot can find it easily.
Diffstat (limited to 'devbot/command.py')
-rw-r--r-- | devbot/command.py | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/devbot/command.py b/devbot/command.py index 8ccef6c..3b2bc30 100644 --- a/devbot/command.py +++ b/devbot/command.py @@ -1,7 +1,15 @@ import subprocess import time +from devbot import utils + _logger = None +_log_path = None + + +def set_log_path(path): + global _log_path + _log_path = path def set_logger(logger): @@ -9,32 +17,42 @@ def set_logger(logger): _logger = logger -def run(args, log=None, test=False, retry=0): - print " ".join(args) +def run(args, test=False, retry=0): if test: + print " ".join(args) return - full_args = args[:] - if log is not None: - full_args.insert(0, _logger) - full_args.append(log) + if _log_path: + stdout = open(_log_path, "w") + stderr = subprocess.STDOUT + else: + stdout = None + stderr = None tries = 0 while tries < retry + 1: try: tries = tries + 1 - subprocess.check_call(full_args) - return + subprocess.check_call(args, stdout=stdout, stderr=stderr) + break except subprocess.CalledProcessError, e: + print "\nCommand failed, tail of %s\n" % _log_path + if _log_path: + subprocess.call(["tail", _log_path]) + if tries < retry + 1: print "Retrying (attempt %d) in 1 minute" % tries time.sleep(60) else: raise e + if stdout: + stdout.close() def run_with_sudo(args, test=False, retry=0): args_with_sudo = ["sudo"] args_with_sudo.extend(args) + print " ".join(args_with_sudo) + run(args_with_sudo, test=test, retry=retry) |