comparison python/hgrc.py @ 486:c9aab7092af1

python/hgrc.py
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 10 Aug 2013 21:13:42 -0700
parents e192c235d5d6
children 178419da6e0b
comparison
equal deleted inserted replaced
485:e192c235d5d6 486:c9aab7092af1
19 19
20 class section(object): 20 class section(object):
21 def __init__(self, section_name, *section_names): 21 def __init__(self, section_name, *section_names):
22 self.sections = [section_name] 22 self.sections = [section_name]
23 self.sections.extend(section_names) 23 self.sections.extend(section_names)
24 def __call__(self, parser): 24 def __call__(self, function):
25 def wrapped(parser, *args, **kwargs): 25 def wrapped(parser, *args, **kwargs):
26 for section in self.sections: 26 for section in self.sections:
27 if section not in parser.sections(): 27 if section not in parser.sections():
28 parser.add_section(section) 28 parser.add_section(section)
29 f(*args, **kwargs) 29 function(parser, *args, **kwargs)
30 return wrapped 30 return wrapped
31 31
32 #@parser # decorator makes this x-form path -> ConfigParser automagically 32 #@parser # decorator makes this x-form path -> ConfigParser automagically
33 @section('paths') 33 @section('paths')
34 def set_default(parser, default): 34 def set_default(parser, default):
35 """set [paths]:default""" 35 """set [paths]:default"""
36 print 'OIOIOIOI!'
36 37
37 @section('paths') 38 @section('paths')
38 def set_default_push(parser, default_push): 39 def set_default_push(parser, default_push):
39 """ 40 """
40 set [paths]:default-push to `default_push` 41 set [paths]:default-push to `default_push`
174 175
175 # cache for later (XXX) 176 # cache for later (XXX)
176 print_ini = actions.pop('print_ini', None) 177 print_ini = actions.pop('print_ini', None)
177 178
178 # alter .hgrc files 179 # alter .hgrc files
179 for action_name, parameter in actions: 180 for action_name, parameter in actions.items():
180 181
181 # XXX crappy 182 # XXX crappy
182 method = action_map[action_name] 183 method = action_map[action_name]
183 if action_name == 'default_push_ssh': 184 if action_name == 'default_push_ssh':
184 parameter = None 185 parameter = None
185 186
186 # apply to all files 187 # apply to all files
187 for path, ini in config.items(): 188 for path, ini in config.items():
188 189
189 # call method with parser 190 # call method with parser
190 if parameter is not None: 191 if parameter is None:
192 method(ini)
193 else:
191 method(ini, parameter) 194 method(ini, parameter)
192 else:
193 method(ini)
194 195
195 # print .hgrc files, if specified 196 # print .hgrc files, if specified
196 if print_ini: 197 if print_ini:
197 for path, ini in config.items(): 198 for path, ini in config.items():
198 print '+++ %s' % (path) 199 print '+++ %s' % (path)