OLD | NEW |
1 # Copyright 2015 The LUCI Authors. All rights reserved. | 1 # Copyright 2015 The LUCI Authors. All rights reserved. |
2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
4 | 4 |
5 """Abstract stream interface for representing recipe runs. | 5 """Abstract stream interface for representing recipe runs. |
6 | 6 |
7 We need to create streams for steps (and substeps) and also LOG_LINE steps. | 7 We need to create streams for steps (and substeps) and also LOG_LINE steps. |
8 LogDog will implement LOG_LINE steps as real logs (i.e. uniformly), but | 8 LogDog will implement LOG_LINE steps as real logs (i.e. uniformly), but |
9 annotations will implement them differently from normal logs, so we need | 9 annotations will implement them differently from normal logs, so we need |
10 a way to distinguish. | 10 a way to distinguish. |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 | 264 |
265 class AnnotationStepStream(StreamEngine.StepStream): | 265 class AnnotationStepStream(StreamEngine.StepStream): |
266 def __init__(self, emit_timestamps=False, time_fn=None): | 266 def __init__(self, emit_timestamps=False, time_fn=None): |
267 self.emit_timestamps = emit_timestamps | 267 self.emit_timestamps = emit_timestamps |
268 self.time_fn = time_fn or time.time | 268 self.time_fn = time_fn or time.time |
269 | 269 |
270 def basic_write(self, line): | 270 def basic_write(self, line): |
271 raise NotImplementedError() | 271 raise NotImplementedError() |
272 | 272 |
273 def output_annotation(self, *args): | 273 def output_annotation(self, *args): |
274 self.basic_write('@@@' + '@'.join(map(str, args)) + '@@@\n') | 274 self.basic_write('@@@' + '@'.join(map(unicode, args)) + '@@@\n') |
275 | 275 |
276 def write_line(self, line): | 276 def write_line(self, line): |
277 if line.startswith('@@@'): | 277 if line.startswith('@@@'): |
278 self.basic_write('!' + line + '\n') | 278 self.basic_write('!' + line + '\n') |
279 else: | 279 else: |
280 self.basic_write(line + '\n') | 280 self.basic_write(line + '\n') |
281 | 281 |
282 def close(self): | 282 def close(self): |
283 if self.emit_timestamps: | 283 if self.emit_timestamps: |
284 self.output_annotation('CURRENT_TIMESTAMP', self.time_fn()) | 284 self.output_annotation('CURRENT_TIMESTAMP', self.time_fn()) |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 """A StepStream that is not tied to any engine, and emits assuming it has the | 403 """A StepStream that is not tied to any engine, and emits assuming it has the |
404 cursor. | 404 cursor. |
405 | 405 |
406 This is used for capturing the annotations in the engine. | 406 This is used for capturing the annotations in the engine. |
407 """ | 407 """ |
408 def __init__(self, outstream): | 408 def __init__(self, outstream): |
409 self._outstream = outstream | 409 self._outstream = outstream |
410 | 410 |
411 def basic_write(self, line): | 411 def basic_write(self, line): |
412 self._outstream.write(line) | 412 self._outstream.write(line) |
OLD | NEW |