| OLD | NEW |
| 1 # Copyright 2016 The LUCI Authors. All rights reserved. | 1 # Copyright 2016 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 import cStringIO | 5 import StringIO |
| 6 import collections | 6 import collections |
| 7 import contextlib | 7 import contextlib |
| 8 import datetime | 8 import datetime |
| 9 import json | 9 import json |
| 10 import os | 10 import os |
| 11 import re | 11 import re |
| 12 import sys | 12 import sys |
| 13 import time | 13 import time |
| 14 import tempfile | 14 import tempfile |
| 15 import traceback | 15 import traceback |
| (...skipping 22 matching lines...) Expand all Loading... |
| 38 # ). | 38 # ). |
| 39 # | 39 # |
| 40 # For more information, see: | 40 # For more information, see: |
| 41 # https://msdn.microsoft.com/en-us/library/windows/desktop/ms680621.aspx | 41 # https://msdn.microsoft.com/en-us/library/windows/desktop/ms680621.aspx |
| 42 ctypes.windll.kernel32.SetErrorMode(0x0001|0x0002|0x8000) | 42 ctypes.windll.kernel32.SetErrorMode(0x0001|0x0002|0x8000) |
| 43 | 43 |
| 44 | 44 |
| 45 class _streamingLinebuf(object): | 45 class _streamingLinebuf(object): |
| 46 def __init__(self): | 46 def __init__(self): |
| 47 self.buffedlines = [] | 47 self.buffedlines = [] |
| 48 self.extra = cStringIO.StringIO() | 48 self.extra = StringIO.StringIO() |
| 49 | 49 |
| 50 def ingest(self, data): | 50 def ingest(self, data): |
| 51 lines = data.splitlines() | 51 lines = data.splitlines() |
| 52 endedOnLinebreak = data.endswith("\n") | 52 endedOnLinebreak = data.endswith("\n") |
| 53 | 53 |
| 54 if self.extra.tell(): | 54 if self.extra.tell(): |
| 55 # we had leftovers from some previous ingest | 55 # we had leftovers from some previous ingest |
| 56 self.extra.write(lines[0]) | 56 self.extra.write(lines[0]) |
| 57 if len(lines) > 1 or endedOnLinebreak: | 57 if len(lines) > 1 or endedOnLinebreak: |
| 58 lines[0] = self.extra.getvalue() | 58 lines[0] = self.extra.getvalue() |
| 59 self.extra = cStringIO.StringIO() | 59 self.extra = StringIO.StringIO() |
| 60 else: | 60 else: |
| 61 return | 61 return |
| 62 | 62 |
| 63 if not endedOnLinebreak: | 63 if not endedOnLinebreak: |
| 64 self.extra.write(lines[-1]) | 64 self.extra.write(lines[-1]) |
| 65 lines = lines[:-1] | 65 lines = lines[:-1] |
| 66 | 66 |
| 67 self.buffedlines += lines | 67 self.buffedlines += lines |
| 68 | 68 |
| 69 def get_buffered(self): | 69 def get_buffered(self): |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 # We modify step_dict. In particular, we add ~followup_annotations during | 412 # We modify step_dict. In particular, we add ~followup_annotations during |
| 413 # finalize, and depend on that side-effect being carried into what we | 413 # finalize, and depend on that side-effect being carried into what we |
| 414 # added to self._step_history, earlier. So copy it here so at least we | 414 # added to self._step_history, earlier. So copy it here so at least we |
| 415 # keep the modifications local. | 415 # keep the modifications local. |
| 416 step_dict = dict(step_dict) | 416 step_dict = dict(step_dict) |
| 417 | 417 |
| 418 test_data_fn = step_dict.pop('step_test_data', recipe_test_api.StepTestData) | 418 test_data_fn = step_dict.pop('step_test_data', recipe_test_api.StepTestData) |
| 419 step_test = self._test_data.pop_step_test_data( | 419 step_test = self._test_data.pop_step_test_data( |
| 420 step_dict['name'], test_data_fn) | 420 step_dict['name'], test_data_fn) |
| 421 step_dict, placeholders = render_step(step_dict, step_test) | 421 step_dict, placeholders = render_step(step_dict, step_test) |
| 422 outstream = cStringIO.StringIO() | 422 outstream = StringIO.StringIO() |
| 423 | 423 |
| 424 # Layer the simulation step on top of the given stream engine. | 424 # Layer the simulation step on top of the given stream engine. |
| 425 step_stream = stream.ProductStreamEngine.StepStream( | 425 step_stream = stream.ProductStreamEngine.StepStream( |
| 426 self._stream_engine.new_step_stream(step_dict['name']), | 426 self._stream_engine.new_step_stream(step_dict['name']), |
| 427 stream.BareAnnotationStepStream(outstream)) | 427 stream.BareAnnotationStepStream(outstream)) |
| 428 | 428 |
| 429 class ReturnOpenStep(OpenStep): | 429 class ReturnOpenStep(OpenStep): |
| 430 def run(inner): | 430 def run(inner): |
| 431 timeout = step_dict.get('timeout') | 431 timeout = step_dict.get('timeout') |
| 432 if (timeout and step_test.times_out_after and | 432 if (timeout and step_test.times_out_after and |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 supplied command, and only uses the |env| kwarg for modifying the environment | 655 supplied command, and only uses the |env| kwarg for modifying the environment |
| 656 of the child process. | 656 of the child process. |
| 657 """ | 657 """ |
| 658 saved_path = os.environ['PATH'] | 658 saved_path = os.environ['PATH'] |
| 659 try: | 659 try: |
| 660 if path is not None: | 660 if path is not None: |
| 661 os.environ['PATH'] = path | 661 os.environ['PATH'] = path |
| 662 yield | 662 yield |
| 663 finally: | 663 finally: |
| 664 os.environ['PATH'] = saved_path | 664 os.environ['PATH'] = saved_path |
| OLD | NEW |