Index: recipe_modules/json/api.py |
diff --git a/recipe_modules/json/api.py b/recipe_modules/json/api.py |
index a6e5e5473fe4c316b0ce602e01ae2f382a61ec2d..f79c5d4237eccf88b81f7dbcf3c120560a3567cd 100644 |
--- a/recipe_modules/json/api.py |
+++ b/recipe_modules/json/api.py |
@@ -27,8 +27,8 @@ class JsonOutputPlaceholder(recipe_util.OutputPlaceholder): |
JSON document, which will be set as the json.output for that step in the |
step_history OrderedDict passed to your recipe generator. |
""" |
- def __init__(self, api, add_json_log, name=None): |
- self.raw = api.m.raw_io.output_text('.json') |
+ def __init__(self, api, add_json_log, name=None, leak_to=None): |
+ self.raw = api.m.raw_io.output_text('.json', leak_to=leak_to) |
self.add_json_log = add_json_log |
super(JsonOutputPlaceholder, self).__init__(name=name) |
@@ -54,10 +54,12 @@ class JsonOutputPlaceholder(recipe_util.OutputPlaceholder): |
pass |
if self.add_json_log: |
- key = self.label + ('' if valid else ' (invalid)') |
- with contextlib.closing(recipe_util.StringListIO()) as listio: |
- json.dump(ret, listio, indent=2, sort_keys=True) |
- presentation.logs[key] = listio.lines |
+ if valid: |
+ with contextlib.closing(recipe_util.StringListIO()) as listio: |
+ json.dump(ret, listio, indent=2, sort_keys=True) |
+ presentation.logs[self.label] = listio.lines |
+ else: |
+ presentation.logs[self.label + ' (invalid)'] = raw_data.splitlines() |
return ret |
@@ -104,9 +106,14 @@ class JsonApi(recipe_api.RecipeApi): |
return self.m.raw_io.input_text(self.dumps(data), '.json') |
@recipe_util.returns_placeholder |
- def output(self, add_json_log=True, name=None): |
- """A placeholder which will expand to '/tmp/file'.""" |
- return JsonOutputPlaceholder(self, add_json_log, name=name) |
+ def output(self, add_json_log=True, name=None, leak_to=None): |
+ """A placeholder which will expand to '/tmp/file'. |
+ |
+ If leak_to is provided, it must be a Path object. This path will be used in |
+ place of a random temporary file, and the file will not be deleted at the |
+ end of the step. |
+ """ |
+ return JsonOutputPlaceholder(self, add_json_log, name=name, leak_to=leak_to) |
# TODO(you): This method should be in the `file` recipe_module |
def read(self, name, path, add_json_log=True, output_name=None, **kwargs): |