Chromium Code Reviews| 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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 * copy() returns self | 418 * copy() returns self |
| 419 | 419 |
| 420 The 'formatted' result can be obtained by looking at .data. | 420 The 'formatted' result can be obtained by looking at .data. |
| 421 """ | 421 """ |
| 422 def __init__(self): | 422 def __init__(self): |
| 423 self.data = {} | 423 self.data = {} |
| 424 | 424 |
| 425 def __getitem__(self, key): | 425 def __getitem__(self, key): |
| 426 return '<%s>' % key | 426 return '<%s>' % key |
| 427 | 427 |
| 428 def keys(self): | |
| 429 return self.data.keys() | |
| 430 | |
| 428 def __delitem__(self, key): | 431 def __delitem__(self, key): |
| 429 self.data[key] = None | 432 self.data[key] = None |
| 430 | 433 |
| 431 def __contains__(self, key): | 434 def __contains__(self, key): |
| 432 return True | 435 return True |
| 433 | 436 |
| 434 def __setitem__(self, key, value): | 437 def __setitem__(self, key, value): |
| 435 self.data[key] = value | 438 self.data[key] = value |
| 436 | 439 |
| 437 def copy(self): | 440 def copy(self): |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 688 def _merge_envs(original, override): | 691 def _merge_envs(original, override): |
| 689 """Merges two environments. | 692 """Merges two environments. |
| 690 | 693 |
| 691 Returns a new environment dict with entries from |override| overwriting | 694 Returns a new environment dict with entries from |override| overwriting |
| 692 corresponding entries in |original|. Keys whose value is None will completely | 695 corresponding entries in |original|. Keys whose value is None will completely |
| 693 remove the environment variable. Values can contain %(KEY)s strings, which | 696 remove the environment variable. Values can contain %(KEY)s strings, which |
| 694 will be substituted with the values from the original (useful for amending, as | 697 will be substituted with the values from the original (useful for amending, as |
| 695 opposed to overwriting, variables like PATH). | 698 opposed to overwriting, variables like PATH). |
| 696 """ | 699 """ |
| 697 result = original.copy() | 700 result = original.copy() |
| 701 subst = (original if isinstance(original, fakeEnviron) | |
| 702 else collections.defaultdict(lambda: '', **original)) | |
| 698 if not override: | 703 if not override: |
| 699 return result | 704 return result |
| 700 for k, v in override.items(): | 705 for k, v in override.items(): |
| 701 if v is None: | 706 if v is None: |
| 702 if k in result: | 707 if k in result: |
| 703 del result[k] | 708 del result[k] |
| 704 else: | 709 else: |
| 705 result[str(k)] = str(v) % original | 710 result[str(k)] = str(v) % subst |
|
dnj
2017/06/03 15:37:33
This fixes a bug where an environment variable tha
iannucci
2017/06/05 19:23:04
Yeah, and with this CL I'd like to eventually elim
dnj
2017/06/07 02:59:28
ACK, but I think for now we still need it for back
| |
| 706 return result | 711 return result |
| 707 | 712 |
| 708 | 713 |
| 709 if sys.platform == "win32": | 714 if sys.platform == "win32": |
| 710 _hunt_path_exts = ('.exe', '.bat') | 715 _hunt_path_exts = ('.exe', '.bat') |
| 711 def _hunt_path(rendered_step, step_env): | 716 def _hunt_path(rendered_step, step_env): |
| 712 """This takes the lazy cross-product of PATH and ('.exe', '.bat') to find | 717 """This takes the lazy cross-product of PATH and ('.exe', '.bat') to find |
| 713 what cmd.exe would have found for the command if we used shell=True. | 718 what cmd.exe would have found for the command if we used shell=True. |
| 714 | 719 |
| 715 This must be called on the render_step AFTER _merge_envs has produced | 720 This must be called on the render_step AFTER _merge_envs has produced |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 783 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 |
| 784 of the child process. | 789 of the child process. |
| 785 """ | 790 """ |
| 786 saved_path = os.environ['PATH'] | 791 saved_path = os.environ['PATH'] |
| 787 try: | 792 try: |
| 788 if path is not None: | 793 if path is not None: |
| 789 os.environ['PATH'] = path | 794 os.environ['PATH'] = path |
| 790 yield | 795 yield |
| 791 finally: | 796 finally: |
| 792 os.environ['PATH'] = saved_path | 797 os.environ['PATH'] = saved_path |
| OLD | NEW |