| OLD | NEW |
| 1 # -*- encoding: utf-8 -*- | 1 # -*- encoding: utf-8 -*- |
| 2 # Copyright 2014 The LUCI Authors. All rights reserved. | 2 # Copyright 2014 The LUCI Authors. All rights reserved. |
| 3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
| 4 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
| 5 | 5 |
| 6 from recipe_engine import recipe_api | 6 from recipe_engine import recipe_api |
| 7 from recipe_engine import util as recipe_util | 7 from recipe_engine import util as recipe_util |
| 8 | 8 |
| 9 import os | 9 import os |
| 10 import shutil | 10 import shutil |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 def backing_file(self): # pragma: no cover | 131 def backing_file(self): # pragma: no cover |
| 132 raise ValueError('Output dir placeholders can not be used for stdin, ' | 132 raise ValueError('Output dir placeholders can not be used for stdin, ' |
| 133 'stdout or stderr') | 133 'stdout or stderr') |
| 134 | 134 |
| 135 def render(self, test): | 135 def render(self, test): |
| 136 assert not self._backing_dir, 'Placeholder can be used only once' | 136 assert not self._backing_dir, 'Placeholder can be used only once' |
| 137 if self.leak_to: | 137 if self.leak_to: |
| 138 self._backing_dir = str(self.leak_to) | 138 self._backing_dir = str(self.leak_to) |
| 139 if not test.enabled: # pragma: no cover | 139 if not test.enabled: # pragma: no cover |
| 140 if not os.path.exists(self._backing_dir): | 140 if not os.path.exists(self._backing_dir): |
| 141 os.mkdir(self._backing_dir) | 141 os.makedirs(self._backing_dir) |
| 142 else: | 142 else: |
| 143 if not test.enabled: # pragma: no cover | 143 if not test.enabled: # pragma: no cover |
| 144 self._backing_dir = tempfile.mkdtemp(suffix=self.suffix) | 144 self._backing_dir = tempfile.mkdtemp(suffix=self.suffix) |
| 145 else: | 145 else: |
| 146 self._backing_dir = '/path/to/tmp/' + self.suffix | 146 self._backing_dir = '/path/to/tmp/' + self.suffix |
| 147 | 147 |
| 148 return [self._backing_dir] | 148 return [self._backing_dir] |
| 149 | 149 |
| 150 def result(self, presentation, test): | 150 def result(self, presentation, test): |
| 151 assert self._backing_dir | 151 assert self._backing_dir |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 """Returns a directory Placeholder for use as a step argument. | 232 """Returns a directory Placeholder for use as a step argument. |
| 233 | 233 |
| 234 If 'leak_to' is None, the placeholder is backed by a temporary dir with | 234 If 'leak_to' is None, the placeholder is backed by a temporary dir with |
| 235 a suffix 'suffix'. The dir is deleted when the step finishes. | 235 a suffix 'suffix'. The dir is deleted when the step finishes. |
| 236 | 236 |
| 237 If 'leak_to' is not None, then it should be a Path and placeholder | 237 If 'leak_to' is not None, then it should be a Path and placeholder |
| 238 redirects IO to a dir at that path. Once step finishes, the dir is | 238 redirects IO to a dir at that path. Once step finishes, the dir is |
| 239 NOT deleted (i.e. it's 'leaking'). 'suffix' is ignored in that case. | 239 NOT deleted (i.e. it's 'leaking'). 'suffix' is ignored in that case. |
| 240 """ | 240 """ |
| 241 return OutputDataDirPlaceholder(suffix, leak_to, name=name) | 241 return OutputDataDirPlaceholder(suffix, leak_to, name=name) |
| OLD | NEW |