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

Side by Side Diff: recipe_engine/util.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: Address comments. 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 unified diff | Download patch
« no previous file with comments | « recipe_engine/step_runner.py ('k') | recipe_modules/json/api.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013-2015 The Chromium Authors. All rights reserved. 1 # Copyright 2013-2015 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 contextlib 5 import contextlib
6 import functools 6 import functools
7 import os 7 import os
8 import sys 8 import sys
9 import traceback 9 import traceback
10 import urllib 10 import urllib
(...skipping 17 matching lines...) Expand all
28 raise ModuleInjectionError( 28 raise ModuleInjectionError(
29 "RecipeApi has no dependency %r. (Add it to DEPS?)" % (key,)) 29 "RecipeApi has no dependency %r. (Add it to DEPS?)" % (key,))
30 else: 30 else:
31 raise ModuleInjectionError( 31 raise ModuleInjectionError(
32 "Recipe Module %r has no dependency %r. (Add it to __init__.py:DEPS?)" 32 "Recipe Module %r has no dependency %r. (Add it to __init__.py:DEPS?)"
33 % (self.owner_module.name, key)) 33 % (self.owner_module.name, key))
34 34
35 35
36 class Placeholder(object): 36 class Placeholder(object):
37 """Base class for command line argument placeholders. Do not use directly.""" 37 """Base class for command line argument placeholders. Do not use directly."""
38 def __init__(self): 38 def __init__(self, name=None):
39 self.name_pieces = None 39 if name is not None:
40 assert isinstance(name, basestring), (
41 'Expect a string name for a placeholder, but got %r' % name)
42 self.name = name
43 self.namespaces = None
40 44
41 @property 45 @property
42 def backing_file(self): # pragma: no cover 46 def backing_file(self): # pragma: no cover
43 """Return path to a temp file that holds or receives the data. 47 """Return path to a temp file that holds or receives the data.
44 48
45 Valid only after 'render' has been called. 49 Valid only after 'render' has been called.
46 """ 50 """
47 raise NotImplementedError 51 raise NotImplementedError
48 52
49 def render(self, test): # pragma: no cover 53 def render(self, test): # pragma: no cover
50 """Return [cmd items]*""" 54 """Return [cmd items]*"""
51 raise NotImplementedError 55 raise NotImplementedError
52 56
53 @property 57 @property
54 def name(self): 58 def label(self):
55 assert self.name_pieces 59 if self.name is None:
56 return "%s.%s" % self.name_pieces 60 return "%s.%s" % self.namespaces
iannucci 2016/03/23 18:50:13 "%s.%s[DEFAULT]" ?
stgao 2016/03/23 19:01:44 This is used as the log name in buildbots. For bac
61 else:
62 return "%s.%s[%s]" % (self.namespaces[0], self.namespaces[1], self.name)
57 63
58 64
59 class InputPlaceholder(Placeholder): 65 class InputPlaceholder(Placeholder):
60 """Base class for json/raw_io input placeholders. Do not use directly.""" 66 """Base class for json/raw_io input placeholders. Do not use directly."""
61 def cleanup(self, test_enabled): 67 def cleanup(self, test_enabled):
62 """Called after step completion. 68 """Called after step completion.
63 69
64 Args: 70 Args:
65 test_enabled (bool) - indicate whether running in simulation mode. 71 test_enabled (bool) - indicate whether running in simulation mode.
66 """ 72 """
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 return func.__get__(obj).__name__ 111 return func.__get__(obj).__name__
106 else: 112 else:
107 return func.__name__ 113 return func.__name__
108 114
109 115
110 def returns_placeholder(func): 116 def returns_placeholder(func):
111 @static_wraps(func) 117 @static_wraps(func)
112 def inner(self, *args, **kwargs): 118 def inner(self, *args, **kwargs):
113 ret = static_call(self, func, *args, **kwargs) 119 ret = static_call(self, func, *args, **kwargs)
114 assert isinstance(ret, Placeholder) 120 assert isinstance(ret, Placeholder)
115 ret.name_pieces = (self.name, static_name(self, func)) 121 ret.namespaces = (self.name, static_name(self, func))
116 return ret 122 return ret
117 # prevent this placeholder-returning function from becoming a composite_step. 123 # prevent this placeholder-returning function from becoming a composite_step.
118 inner._non_step = True # pylint: disable=protected-access 124 inner._non_step = True # pylint: disable=protected-access
119 return inner 125 return inner
120 126
121 127
122 def scan_directory(path, predicate): 128 def scan_directory(path, predicate):
123 """Recursively scans a directory and yields paths that match predicate.""" 129 """Recursively scans a directory and yields paths that match predicate."""
124 for root, _dirs, files in os.walk(path): 130 for root, _dirs, files in os.walk(path):
125 for file_name in (f for f in files if predicate(f)): 131 for file_name in (f for f in files if predicate(f)):
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 self.lines[-1].write(s) 183 self.lines[-1].write(s)
178 break 184 break
179 self.lines[-1].write(s[:i]) 185 self.lines[-1].write(s[:i])
180 self.lines[-1] = self.lines[-1].getvalue() 186 self.lines[-1] = self.lines[-1].getvalue()
181 self.lines.append(StringIO()) 187 self.lines.append(StringIO())
182 s = s[i+1:] 188 s = s[i+1:]
183 189
184 def close(self): 190 def close(self):
185 if not isinstance(self.lines[-1], basestring): 191 if not isinstance(self.lines[-1], basestring):
186 self.lines[-1] = self.lines[-1].getvalue() 192 self.lines[-1] = self.lines[-1].getvalue()
OLDNEW
« no previous file with comments | « recipe_engine/step_runner.py ('k') | recipe_modules/json/api.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698