diff options
-rw-r--r-- | build/android/pylib/cmd_helper.py | 6 | ||||
-rw-r--r-- | build/android/pylib/utils/run_tests_helper.py | 26 |
2 files changed, 29 insertions, 3 deletions
diff --git a/build/android/pylib/cmd_helper.py b/build/android/pylib/cmd_helper.py index b6bbac7..6dcc911 100644 --- a/build/android/pylib/cmd_helper.py +++ b/build/android/pylib/cmd_helper.py @@ -10,6 +10,7 @@ import subprocess import constants + def RunCmd(args, cwd=None): """Opens a subprocess to execute a program and returns its return value. @@ -23,8 +24,7 @@ def RunCmd(args, cwd=None): Return code from the command execution. """ logging.info(str(args) + ' ' + (cwd or '')) - p = subprocess.Popen(args=args, cwd=cwd) - return p.wait() + return subprocess.call(args, cwd=cwd) def GetCmdOutput(args, cwd=None, shell=False): @@ -44,6 +44,7 @@ def GetCmdOutput(args, cwd=None, shell=False): (_, output) = GetCmdStatusAndOutput(args, cwd, shell) return output + def GetCmdStatusAndOutput(args, cwd=None, shell=False): """Executes a subprocess and returns its exit code and output. @@ -67,6 +68,7 @@ def GetCmdStatusAndOutput(args, cwd=None, shell=False): logging.info(stdout[:4096]) # Truncate output longer than 4k. return (exit_code, stdout) + class OutDirectory(object): _out_directory = os.path.join(constants.CHROME_DIR, 'out') @staticmethod diff --git a/build/android/pylib/utils/run_tests_helper.py b/build/android/pylib/utils/run_tests_helper.py index 15e5d53..b5730b6 100644 --- a/build/android/pylib/utils/run_tests_helper.py +++ b/build/android/pylib/utils/run_tests_helper.py @@ -6,6 +6,26 @@ import logging import os +import time + + +class CustomFormatter(logging.Formatter): + """Custom log formatter.""" + + #override + def __init__(self, fmt=''): + # Can't use super() because in older Python versions logging.Formatter does + # not inherit from object. + logging.Formatter.__init__(self, fmt=fmt) + self._creation_time = time.time() + + #override + def format(self, record): + # Can't use super() because in older Python versions logging.Formatter does + # not inherit from object. + msg = logging.Formatter.format(self, record) + timediff = str(int(time.time() - self._creation_time)) + return '%s %ss %s' % (record.levelname[0], timediff.rjust(4), msg) def GetExpectations(file_name): @@ -23,4 +43,8 @@ def SetLogLevel(verbose_count): log_level = logging.INFO elif verbose_count >= 2: log_level = logging.DEBUG - logging.getLogger().setLevel(log_level) + logger = logging.getLogger() + logger.setLevel(log_level) + custom_handler = logging.StreamHandler() + custom_handler.setFormatter(CustomFormatter()) + logging.getLogger().addHandler(custom_handler) |