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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 return getattr(value, '__name__', 'UNKNOWN_CALLABLE')+'(...)' | 277 return getattr(value, '__name__', 'UNKNOWN_CALLABLE')+'(...)' |
278 | 278 |
279 def _print_step(self, step_stream, step, env): | 279 def _print_step(self, step_stream, step, env): |
280 """Prints the step command and relevant metadata. | 280 """Prints the step command and relevant metadata. |
281 | 281 |
282 Intended to be similar to the information that Buildbot prints at the | 282 Intended to be similar to the information that Buildbot prints at the |
283 beginning of each non-annotator step. | 283 beginning of each non-annotator step. |
284 """ | 284 """ |
285 def gen_step_prelude(): | 285 def gen_step_prelude(): |
286 yield ' '.join(map(_shell_quote, step.config.cmd)) | 286 yield ' '.join(map(_shell_quote, step.config.cmd)) |
287 yield 'in dir %s:' % (step.config.cwd or os.getcwd()) | 287 cwd = step.config.cwd |
| 288 if cwd is None: |
| 289 try: |
| 290 cwd = os.getcwd() |
| 291 except OSError as ex: |
| 292 cwd = '??? (ENGINE START_DIR IS MISSING: %r)' % (ex,) |
| 293 elif not os.path.isdir(cwd): |
| 294 cwd += ' (ENGINE START_DIR IS MISSING OR NOT A DIR)' |
| 295 yield 'in dir %s:' % (cwd,) |
288 for key, value in sorted(step.config._asdict().items()): | 296 for key, value in sorted(step.config._asdict().items()): |
289 if value is not None: | 297 if value is not None: |
290 yield ' %s: %s' % (key, self._render_step_value(value)) | 298 yield ' %s: %s' % (key, self._render_step_value(value)) |
291 yield 'full environment:' | 299 yield 'full environment:' |
292 for key, value in sorted(env.items()): | 300 for key, value in sorted(env.items()): |
293 yield ' %s: %s' % (key, value) | 301 yield ' %s: %s' % (key, value) |
294 yield '' | 302 yield '' |
295 stream.output_iter(step_stream, gen_step_prelude()) | 303 stream.output_iter(step_stream, gen_step_prelude()) |
296 | 304 |
297 def _run_cmd(self, cmd, timeout, handles, env, cwd): | 305 def _run_cmd(self, cmd, timeout, handles, env, cwd): |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 supplied command, and only uses the |env| kwarg for modifying the environment | 748 supplied command, and only uses the |env| kwarg for modifying the environment |
741 of the child process. | 749 of the child process. |
742 """ | 750 """ |
743 saved_path = os.environ['PATH'] | 751 saved_path = os.environ['PATH'] |
744 try: | 752 try: |
745 if path is not None: | 753 if path is not None: |
746 os.environ['PATH'] = path | 754 os.environ['PATH'] = path |
747 yield | 755 yield |
748 finally: | 756 finally: |
749 os.environ['PATH'] = saved_path | 757 os.environ['PATH'] = saved_path |
OLD | NEW |