Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(691)

Unified Diff: recipe_modules/json/api.py

Issue 2989423002: Add add_json_log='on_failure' to json module. (Closed)
Patch Set: Add unittests Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « README.recipes.md ('k') | recipe_modules/json/tests/add_json_log.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: recipe_modules/json/api.py
diff --git a/recipe_modules/json/api.py b/recipe_modules/json/api.py
index a881b7168d91e3cfa95139ceface6081c175bebd..b92b4deb2a30b08d1e6ae4c0d044405f460cb147 100644
--- a/recipe_modules/json/api.py
+++ b/recipe_modules/json/api.py
@@ -38,6 +38,8 @@ class JsonOutputPlaceholder(recipe_util.OutputPlaceholder):
See the example recipe (./examples/full.py) for some more uses.
"""
def __init__(self, api, add_json_log, name=None, leak_to=None):
+ assert add_json_log in (True, False, 'on_failure'), (
+ 'add_json_log=%r' % add_json_log)
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)
@@ -64,7 +66,8 @@ class JsonOutputPlaceholder(recipe_util.OutputPlaceholder):
except (ValueError, TypeError) as ex: # pragma: no cover
invalid_error = str(ex)
- if self.add_json_log:
+ if self.add_json_log is True or (
+ self.add_json_log == 'on_failure' and presentation.status != 'SUCCESS'):
if valid:
with contextlib.closing(recipe_util.StringListIO()) as listio:
json.dump(ret, listio, indent=2, sort_keys=True)
@@ -108,6 +111,11 @@ class JsonApi(recipe_api.RecipeApi):
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.
+
+ Args:
+ * add_json_log (True|False|'on_failure') - Log a copy of the output json
+ to a step link named `name`. If this is 'on_failure', only create this
+ log when the step has a non-SUCCESS status.
"""
return JsonOutputPlaceholder(self, add_json_log, name=name, leak_to=leak_to)
« no previous file with comments | « README.recipes.md ('k') | recipe_modules/json/tests/add_json_log.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698