| 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 calendar | 5 import calendar |
| 6 import collections | 6 import collections |
| 7 import contextlib | 7 import contextlib |
| 8 import datetime | 8 import datetime |
| 9 import itertools | 9 import itertools |
| 10 import json | 10 import json |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 """Return the stream engine that this StepRunner uses, if meaningful. | 85 """Return the stream engine that this StepRunner uses, if meaningful. |
| 86 | 86 |
| 87 Users of this method must be prepared to handle None. | 87 Users of this method must be prepared to handle None. |
| 88 """ | 88 """ |
| 89 return None | 89 return None |
| 90 | 90 |
| 91 def open_step(self, step_config): | 91 def open_step(self, step_config): |
| 92 """Constructs an OpenStep object which can be used to actually run a step. | 92 """Constructs an OpenStep object which can be used to actually run a step. |
| 93 | 93 |
| 94 Args: | 94 Args: |
| 95 step_config (StepConfig): The step data. | 95 step_config (recipe_api.StepClient.StepConfig): The step data. |
| 96 | 96 |
| 97 Returns: an OpenStep object. | 97 Returns: an OpenStep object. |
| 98 """ | 98 """ |
| 99 raise NotImplementedError() | 99 raise NotImplementedError() |
| 100 | 100 |
| 101 def run_recipe(self, universe, recipe, properties): | 101 def run_recipe(self, universe, recipe, properties): |
| 102 """Run the recipe named |recipe|. | 102 """Run the recipe named |recipe|. |
| 103 | 103 |
| 104 Args: | 104 Args: |
| 105 universe: The RecipeUniverse where the recipe lives. | 105 universe: The RecipeUniverse where the recipe lives. |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 for name, rs in self._step_history.iteritems()) | 542 for name, rs in self._step_history.iteritems()) |
| 543 | 543 |
| 544 | 544 |
| 545 # Placeholders associated with a rendered step. | 545 # Placeholders associated with a rendered step. |
| 546 Placeholders = collections.namedtuple('Placeholders', | 546 Placeholders = collections.namedtuple('Placeholders', |
| 547 ('inputs_cmd', 'outputs_cmd', 'stdout', 'stderr', 'stdin')) | 547 ('inputs_cmd', 'outputs_cmd', 'stdout', 'stderr', 'stdin')) |
| 548 | 548 |
| 549 # Result of 'render_step'. | 549 # Result of 'render_step'. |
| 550 # | 550 # |
| 551 # Fields: | 551 # Fields: |
| 552 # config (recipe_api.StepConfig): The step configuration. | 552 # config (recipe_api.StepClient.StepConfig): The step configuration. |
| 553 # placeholders (Placeholders): Placeholders for this rendered step. | 553 # placeholders (Placeholders): Placeholders for this rendered step. |
| 554 # followup_annotations (list): A list of followup annotation, populated during | 554 # followup_annotations (list): A list of followup annotation, populated during |
| 555 # simulation test. | 555 # simulation test. |
| 556 RenderedStep = collections.namedtuple('RenderedStep', | 556 RenderedStep = collections.namedtuple('RenderedStep', |
| 557 ('config', 'placeholders', 'followup_annotations')) | 557 ('config', 'placeholders', 'followup_annotations')) |
| 558 | 558 |
| 559 | 559 |
| 560 # Singleton object to indicate a value is not set. | 560 # Singleton object to indicate a value is not set. |
| 561 UNSET_VALUE = object() | 561 UNSET_VALUE = object() |
| 562 | 562 |
| 563 | 563 |
| 564 def render_step(step_config, step_test): | 564 def render_step(step_config, step_test): |
| 565 """Renders a step so that it can be fed to annotator.py. | 565 """Renders a step so that it can be fed to annotator.py. |
| 566 | 566 |
| 567 Args: | 567 Args: |
| 568 step_config (StepConfig): The step config to render. | 568 step_config (recipe_api.StepClient.StepConfig): The step config to render. |
| 569 step_test: The test data json dictionary for this step, if any. | 569 step_test: The test data json dictionary for this step, if any. |
| 570 Passed through unaltered to each placeholder. | 570 Passed through unaltered to each placeholder. |
| 571 | 571 |
| 572 Returns (RenderedStep): the rendered step, including a Placeholders object | 572 Returns (RenderedStep): the rendered step, including a Placeholders object |
| 573 representing any placeholder instances that were found while rendering. | 573 representing any placeholder instances that were found while rendering. |
| 574 """ | 574 """ |
| 575 # Process 'cmd', rendering placeholders there. | 575 # Process 'cmd', rendering placeholders there. |
| 576 input_phs = collections.defaultdict(lambda: collections.defaultdict(list)) | 576 input_phs = collections.defaultdict(lambda: collections.defaultdict(list)) |
| 577 output_phs = collections.defaultdict( | 577 output_phs = collections.defaultdict( |
| 578 lambda: collections.defaultdict(collections.OrderedDict)) | 578 lambda: collections.defaultdict(collections.OrderedDict)) |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 supplied command, and only uses the |env| kwarg for modifying the environment | 788 supplied command, and only uses the |env| kwarg for modifying the environment |
| 789 of the child process. | 789 of the child process. |
| 790 """ | 790 """ |
| 791 saved_path = os.environ['PATH'] | 791 saved_path = os.environ['PATH'] |
| 792 try: | 792 try: |
| 793 if path is not None: | 793 if path is not None: |
| 794 os.environ['PATH'] = path | 794 os.environ['PATH'] = path |
| 795 yield | 795 yield |
| 796 finally: | 796 finally: |
| 797 os.environ['PATH'] = saved_path | 797 os.environ['PATH'] = saved_path |
| OLD | NEW |