| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 self._backing_file = '/path/to/tmp/' + self.suffix.lstrip('.') | 87 self._backing_file = '/path/to/tmp/' + self.suffix.lstrip('.') |
| 88 else: # pragma: no cover | 88 else: # pragma: no cover |
| 89 output_fd, self._backing_file = tempfile.mkstemp(suffix=self.suffix) | 89 output_fd, self._backing_file = tempfile.mkstemp(suffix=self.suffix) |
| 90 os.close(output_fd) | 90 os.close(output_fd) |
| 91 return [self._backing_file] | 91 return [self._backing_file] |
| 92 | 92 |
| 93 def result(self, presentation, test): | 93 def result(self, presentation, test): |
| 94 assert self._backing_file | 94 assert self._backing_file |
| 95 if test.enabled: | 95 if test.enabled: |
| 96 self._backing_file = None | 96 self._backing_file = None |
| 97 return self.decode(test.data) | 97 return self.decode(test.data or '') |
| 98 else: # pragma: no cover | 98 else: # pragma: no cover |
| 99 try: | 99 try: |
| 100 with open(self._backing_file, 'rb') as f: | 100 with open(self._backing_file, 'rb') as f: |
| 101 return self.decode(f.read()) | 101 return self.decode(f.read()) |
| 102 finally: | 102 finally: |
| 103 if not self.leak_to: | 103 if not self.leak_to: |
| 104 os.unlink(self._backing_file) | 104 os.unlink(self._backing_file) |
| 105 self._backing_file = None | 105 self._backing_file = None |
| 106 | 106 |
| 107 def decode(self, result): | 107 def decode(self, result): |
| (...skipping 124 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 |