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

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: Rebase. 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
« no previous file with comments | « recipe_engine/util.py ('k') | recipe_modules/json/example.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 eda76483fb95920380ba7a2e32874744136cf335..287fe1dab0622fe7b41e755034824be9eb98d1cc 100644
--- a/recipe_modules/json/api.py
+++ b/recipe_modules/json/api.py
@@ -27,10 +27,10 @@ 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):
+ def __init__(self, api, add_json_log, name=None):
self.raw = api.m.raw_io.output('.json')
self.add_json_log = add_json_log
- super(JsonOutputPlaceholder, self).__init__()
+ super(JsonOutputPlaceholder, self).__init__(name=name)
@property
def backing_file(self):
@@ -54,7 +54,7 @@ class JsonOutputPlaceholder(recipe_util.OutputPlaceholder):
pass
if self.add_json_log:
- key = self.name + ('' if valid else ' (invalid)')
+ 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
@@ -107,12 +107,12 @@ class JsonApi(recipe_api.RecipeApi):
return self.m.raw_io.input(self.dumps(data), '.json')
@recipe_util.returns_placeholder
- def output(self, add_json_log=True):
+ def output(self, add_json_log=True, name=None):
"""A placeholder which will expand to '/tmp/file'."""
- return JsonOutputPlaceholder(self, add_json_log)
+ return JsonOutputPlaceholder(self, add_json_log, name=name)
# 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, output_name=None, **kwargs):
"""Returns a step that reads a JSON file."""
return self.m.python.inline(
name,
@@ -121,7 +121,8 @@ 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, name=output_name)],
add_python_log=False,
**kwargs
)
« no previous file with comments | « recipe_engine/util.py ('k') | recipe_modules/json/example.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698