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

Side by Side Diff: scripts/slave/recipe_config_types.py

Issue 24737002: Add Paths as first-class types in configs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: 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
(Empty)
1 import re
2
3 def ResetHandlers():
4 RecipeConfigType._HANDLER_MAP.clear() # pylint: disable=W0212
5
6
7 def json_fixup(obj):
8 if isinstance(obj, RecipeConfigType):
9 return str(obj)
10 raise TypeError("%r is not JSON serializable" % obj)
11
12
13 class RecipeConfigType(object):
agable 2013/09/26 21:46:02 docstrings docstrings docstrings.
iannucci 2013/09/27 02:08:20 Done.
14 _HANDLER_MAP = {}
15
16 def handle(self):
17 return self._HANDLER_MAP.get(self.__class__.__name__,
18 self.__class__.default_handler)(self)
19
20 @classmethod
21 def set_handler(cls, new_handler):
22 assert cls.__name__ not in cls._HANDLER_MAP, (
23 'Handler already installed for %s' % cls)
24 cls._HANDLER_MAP[cls.__name__] = new_handler
25
26 def default_handler(self, *args, **kwargs):
agable 2013/09/26 21:46:02 default_tostring maybe? Not clear what it means to
iannucci 2013/09/27 02:08:20 how about default_tostring_fn . Makes sense to tal
27 raise NotImplementedError
28
29 def __str__(self):
30 return self.handle()
31
32
33 class Path(RecipeConfigType):
34 BASE_RE = re.compile("[a-z][a-z_]*")
agable 2013/09/26 21:46:02 This RE seems incredibly restrictive. Also, (due t
iannucci 2013/09/27 02:08:20 docstrings should clear this up more, added commen
35
36 def __init__(self, base=None, *pieces, **kwargs):
37 super(Path, self).__init__()
agable 2013/09/26 21:46:02 Should pass kwargs to init. Otherwise there's no r
iannucci 2013/09/27 02:08:20 I would love to have wrapper=False at the end here
38 assert '..' not in pieces
39 assert self.BASE_RE.match(base)
40
41 self.base = base
42 self.pieces = pieces
43 self.wrapper = kwargs.get('wrapper', False)
agable 2013/09/26 21:46:02 Since there's only one wrapper function, and it is
iannucci 2013/09/27 02:08:20 Ok, changed this to a more generic fixed-function
44
45 def __call__(self, *pieces, **kwargs):
46 wrapper = kwargs.get('wrapper', self.wrapper)
47 new_pieces = filter(bool, self.pieces + pieces)
48 return Path(self.base, *new_pieces, wrapper=wrapper)
49
50 def default_handler(self):
51 suffix = ', wrapper=True' if self.wrapper else ''
52 return 'Path([%s], %r%s)' % (self.base.upper(), self.pieces, suffix)
agable 2013/09/26 21:58:08 Path([ROOT], piece, piece, piece) looks better tha
iannucci 2013/09/27 02:09:20 Since I changed the signature of this class, I dec
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698