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

Unified Diff: recipe_modules/json/api.py

Issue 1773273003: Make output placeholders like json.output index-able by name. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/recipes-py@master
Patch Set: Created 4 years, 9 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
Index: recipe_modules/json/api.py
diff --git a/recipe_modules/json/api.py b/recipe_modules/json/api.py
index e65e3135d723d3313bddedc52cb6340efa9f101c..4c8b3ce0aac175cdda704981a6a1e7b732a72001 100644
--- a/recipe_modules/json/api.py
+++ b/recipe_modules/json/api.py
@@ -27,10 +27,10 @@ class JsonOutputPlaceholder(recipe_util.Placeholder):
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):
- self.raw = api.m.raw_io.output('.json')
+ def __init__(self, api, add_json_log, id=id):
iannucci 2016/03/10 03:17:42 we should use something other than 'id', which is
stgao 2016/03/10 20:34:23 Sounds good. Note: PlaceHolder already has a prop
+ self.raw = api.m.raw_io.output('.json', id=id)
self.add_json_log = add_json_log
- super(JsonOutputPlaceholder, self).__init__()
+ super(JsonOutputPlaceholder, self).__init__(id=id)
@property
def backing_file(self):
@@ -54,7 +54,10 @@ class JsonOutputPlaceholder(recipe_util.Placeholder):
pass
if self.add_json_log:
- key = self.name + ('' if valid else ' (invalid)')
+ # Use the combination of id and name to differentiate multiple
+ # json.outputs in the same step. Otherwise, only the last one shows up
+ # as the log.
+ key = self.id_name + ('' 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
@@ -102,17 +105,17 @@ class JsonApi(recipe_api.RecipeApi):
return False
@recipe_util.returns_placeholder
- def input(self, data):
+ def input(self, data, id=None):
"""A placeholder which will expand to a file path containing <data>."""
- return self.m.raw_io.input(self.dumps(data), '.json')
+ return self.m.raw_io.input(self.dumps(data), '.json', id=id)
@recipe_util.returns_placeholder
- def output(self, add_json_log=True):
+ def output(self, add_json_log=True, id=None):
"""A placeholder which will expand to '/tmp/file'."""
- return JsonOutputPlaceholder(self, add_json_log)
+ return JsonOutputPlaceholder(self, add_json_log, id=id)
# TODO(you): This method should be in the `file` recipe_module
- def read(self, name, path, add_json_log=True, **kwargs):
+ def read(self, name, path, add_json_log=True, id=None, **kwargs):
"""Returns a step that reads a JSON file."""
return self.m.python.inline(
name,
@@ -121,7 +124,7 @@ class JsonApi(recipe_api.RecipeApi):
import sys
shutil.copy(sys.argv[1], sys.argv[2])
""",
- args=[path, self.output(add_json_log=add_json_log)],
+ args=[path, self.output(add_json_log=add_json_log, id=id)],
add_python_log=False,
**kwargs
)

Powered by Google App Engine
This is Rietveld 408576698