Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(502)

Unified Diff: gclient_utils.py

Issue 3347019: Enable annotated output for --jobs N!=1. (Closed)
Patch Set: Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/gclient_utils_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gclient_utils.py
diff --git a/gclient_utils.py b/gclient_utils.py
index a70d0fc3370eb75158f48cccbaee2b68a35bce15..7c1c2eb995fedb327bda08df067d4d9ac6469aea 100644
--- a/gclient_utils.py
+++ b/gclient_utils.py
@@ -314,6 +314,29 @@ class StdoutAutoFlush(object):
self.stdout.flush()
+class StdoutAnnotated(object):
+ """Prepends every line with a string."""
+ def __init__(self, prepend, stdout):
+ self.prepend = prepend
+ self.buf = ''
+ self.stdout = stdout
+
+ def write(self, out):
+ self.buf += out
+ while '\n' in self.buf:
+ line, self.buf = self.buf.split('\n', 1)
+ self.stdout.write(self.prepend + line + '\n')
+
+ def flush(self):
+ pass
+
+ def full_flush(self):
+ if self.buf:
+ self.stdout.write(self.prepend + self.buf)
+ self.stdout.flush()
+ self.buf = ''
+
+
def CheckCallAndFilter(args, stdout=None, filter_fn=None,
print_stdout=None, call_filter_on_first_line=False,
**kwargs):
@@ -569,7 +592,7 @@ class ExecutionQueue(object):
self.running.append(t)
else:
t.join()
- t.kwargs['options'].stdout.flush()
+ t.kwargs['options'].stdout.full_flush()
if self.progress:
self.progress.update(1)
assert not t.name in self.ran
@@ -580,9 +603,11 @@ class ExecutionQueue(object):
if self.jobs > 1:
# Start the thread.
index = len(self.ran) + len(self.running) + 1
- # Copy 'options' just to be safe.
+ # Copy 'options' and add annotated stdout.
task_kwargs = kwargs.copy()
task_kwargs['options'] = copy.copy(task_kwargs['options'])
+ task_kwargs['options'].stdout = StdoutAnnotated(
+ '%d>' % index, task_kwargs['options'].stdout)
new_thread = self._Worker(task_item, args, task_kwargs)
self.running.append(new_thread)
new_thread.start()
« no previous file with comments | « no previous file | tests/gclient_utils_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698