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

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

Issue 24737002: Add Paths as first-class types in configs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Address comments Created 7 years, 2 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 contextlib 6 import contextlib
7 import json 7 import json
8 8
9 from cStringIO import StringIO 9 from cStringIO import StringIO
10 10
11 from slave import recipe_api 11 from slave import recipe_api
12 from slave import recipe_util 12 from slave import recipe_util
13 from slave import recipe_config_types
13 14
14 from .util import TestResults 15 from .util import TestResults
15 16
16 class StringListIO(object): 17 class StringListIO(object):
17 def __init__(self): 18 def __init__(self):
18 self.lines = [StringIO()] 19 self.lines = [StringIO()]
19 20
20 def write(self, s): 21 def write(self, s):
21 while s: 22 while s:
22 i = s.find('\n') 23 i = s.find('\n')
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 return TestResults(ret) 79 return TestResults(ret)
79 80
80 81
81 class JsonApi(recipe_api.RecipeApi): 82 class JsonApi(recipe_api.RecipeApi):
82 def __init__(self, **kwargs): 83 def __init__(self, **kwargs):
83 super(JsonApi, self).__init__(**kwargs) 84 super(JsonApi, self).__init__(**kwargs)
84 self.loads = json.loads 85 self.loads = json.loads
85 @functools.wraps(json.dumps) 86 @functools.wraps(json.dumps)
86 def dumps(*args, **kwargs): 87 def dumps(*args, **kwargs):
87 kwargs['sort_keys'] = True 88 kwargs['sort_keys'] = True
89 kwargs.setdefault('default', recipe_config_types.json_fixup)
88 return json.dumps(*args, **kwargs) 90 return json.dumps(*args, **kwargs)
89 self.dumps = dumps 91 self.dumps = dumps
90 92
91 @recipe_util.returns_placeholder 93 @recipe_util.returns_placeholder
92 def input(self, data): 94 def input(self, data):
93 """A placeholder which will expand to a file path containing <data>.""" 95 """A placeholder which will expand to a file path containing <data>."""
94 return self.m.raw_io.input(self.dumps(data), '.json') 96 return self.m.raw_io.input(self.dumps(data), '.json')
95 97
96 @recipe_util.returns_placeholder 98 @recipe_util.returns_placeholder
97 def output(self): 99 def output(self):
(...skipping 16 matching lines...) Expand all
114 116
115 It's vastly preferable to have your recipe only pass the bare minimum 117 It's vastly preferable to have your recipe only pass the bare minimum
116 of arguments to steps. Passing property objects obscures the data that 118 of arguments to steps. Passing property objects obscures the data that
117 the script actually consumes from the property object. 119 the script actually consumes from the property object.
118 """ 120 """
119 prop_str = self.dumps(dict(self.m.properties)) 121 prop_str = self.dumps(dict(self.m.properties))
120 return [ 122 return [
121 '--factory-properties', prop_str, 123 '--factory-properties', prop_str,
122 '--build-properties', prop_str 124 '--build-properties', prop_str
123 ] 125 ]
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698