Bug 1294109 - Strip time prefix from process output; r?ekyle
run-task already prints a full datetime string in its output. Processes
like mozharness always prefix their output with the current time. This
is redundant with run-task.
This commit changes the behavior of run-task to strip leading times
from observed process output before printing.
Before:
[task 2016-08-09T22:22:24.457402Z] 22:22:24 INFO - rmtree: /home/worker/workspace/build
After:
[task 2016-08-09T22:22:24.457402Z] INFO - rmtree: /home/worker/workspace/build
Much cleaner.
MozReview-Commit-ID: FpYTydV6Pcz
--- a/testing/docker/recipes/run-task
+++ b/testing/docker/recipes/run-task
@@ -21,16 +21,19 @@ import errno
import grp
import os
import pwd
import re
import subprocess
import sys
+RE_TIME_PREFIX = re.compile('^\d{2}:\d{2}:\d{2}\s+')
+
+
def print_line(prefix, m):
now = datetime.datetime.utcnow()
print(b'[%s %sZ] %s' % (prefix, now.isoformat(), m), end=b'')
def run_and_prefix_output(prefix, args):
"""Runs a process and prefixes its output with the time.
@@ -55,16 +58,20 @@ def run_and_prefix_output(prefix, args):
# lines, preserving progress indicators.
universal_newlines=True)
while True:
data = p.stdout.readline()
if data == b'':
break
+ # Some other process is printing out times. Strip that output since
+ # our lines are prefixed with the full datetime.
+ data = RE_TIME_PREFIX.sub(b'', data, count=1)
+
print_line(prefix, data)
return p.wait()
def vcs_checkout(args):
# TODO get VCS parameters from arguments.
base_repo = os.environ.get('GECKO_BASE_REPOSITORY')