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

Side by Side Diff: scripts/slave/recipe_modules/json/api.py

Issue 1151423002: Move recipe engine to third_party/recipe_engine. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Moved field_composer_test with its buddies Created 5 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import functools 5 import functools
6 import collections 6 import collections
7 import contextlib 7 import contextlib
8 import json 8 import json
9 9
10 from slave import recipe_api 10 from recipe_engine import recipe_api
11 from slave import recipe_util 11 from recipe_engine import util as recipe_util
12 from slave import recipe_config_types 12 from recipe_engine import config_types
13 13
14 14
15 class JsonOutputPlaceholder(recipe_util.Placeholder): 15 class JsonOutputPlaceholder(recipe_util.Placeholder):
16 """JsonOutputPlaceholder is meant to be a placeholder object which, when added 16 """JsonOutputPlaceholder is meant to be a placeholder object which, when added
17 to a step's cmd list, will be replaced by annotated_run with the path to a 17 to a step's cmd list, will be replaced by annotated_run with the path to a
18 temporary file (e.g. /tmp/tmp4lp1qM) which will exist only for the duration of 18 temporary file (e.g. /tmp/tmp4lp1qM) which will exist only for the duration of
19 the step. If the script requires a flag (e.g. --output-json /path/to/file), 19 the step. If the script requires a flag (e.g. --output-json /path/to/file),
20 you must supply that flag yourself in the cmd list. 20 you must supply that flag yourself in the cmd list.
21 21
22 This placeholder can be optionally added when you use the Steps.step() 22 This placeholder can be optionally added when you use the Steps.step()
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 return ret 61 return ret
62 62
63 63
64 class JsonApi(recipe_api.RecipeApi): 64 class JsonApi(recipe_api.RecipeApi):
65 def __init__(self, **kwargs): 65 def __init__(self, **kwargs):
66 super(JsonApi, self).__init__(**kwargs) 66 super(JsonApi, self).__init__(**kwargs)
67 self.loads = json.loads 67 self.loads = json.loads
68 @functools.wraps(json.dumps) 68 @functools.wraps(json.dumps)
69 def dumps(*args, **kwargs): 69 def dumps(*args, **kwargs):
70 kwargs['sort_keys'] = True 70 kwargs['sort_keys'] = True
71 kwargs.setdefault('default', recipe_config_types.json_fixup) 71 kwargs.setdefault('default', config_types.json_fixup)
72 return json.dumps(*args, **kwargs) 72 return json.dumps(*args, **kwargs)
73 self.dumps = dumps 73 self.dumps = dumps
74 74
75 def is_serializable(self, obj): 75 def is_serializable(self, obj):
76 """Returns True if the object is JSON-serializable.""" 76 """Returns True if the object is JSON-serializable."""
77 try: 77 try:
78 self.dumps(obj) 78 self.dumps(obj)
79 return True 79 return True
80 except Exception: 80 except Exception:
81 return False 81 return False
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 113
114 It's vastly preferable to have your recipe only pass the bare minimum 114 It's vastly preferable to have your recipe only pass the bare minimum
115 of arguments to steps. Passing property objects obscures the data that 115 of arguments to steps. Passing property objects obscures the data that
116 the script actually consumes from the property object. 116 the script actually consumes from the property object.
117 """ 117 """
118 prop_str = self.dumps(dict(self.m.properties.legacy())) 118 prop_str = self.dumps(dict(self.m.properties.legacy()))
119 return [ 119 return [
120 '--factory-properties', prop_str, 120 '--factory-properties', prop_str,
121 '--build-properties', prop_str 121 '--build-properties', prop_str
122 ] 122 ]
OLDNEW
« no previous file with comments | « scripts/slave/recipe_modules/itertools/api.py ('k') | scripts/slave/recipe_modules/json/test_api.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698