comparison python/hgrc.py @ 482:6c0aac8799da

python/hgrc.py
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 10 Aug 2013 20:51:25 -0700
parents 65e38d33acae
children 4bd2932d21d4
comparison
equal deleted inserted replaced
481:65e38d33acae 482:6c0aac8799da
13 import sys 13 import sys
14 import urlparse 14 import urlparse
15 from ConfigParser import RawConfigParser as ConfigParser 15 from ConfigParser import RawConfigParser as ConfigParser
16 16
17 class section(object): 17 class section(object):
18 def __init__(self, function, section_name, *section_names): 18 def __init__(self, section_name, *section_names):
19 self.function = function
20 self.sections = [section_name] 19 self.sections = [section_name]
21 self.sections.extend(section_names) 20 self.sections.extend(section_names)
22 def __call__(self, parser): 21 def __call__(self, parser):
23 import pdb; pdb.set_trace() 22 def wrapped(parser, *args, **kwargs):
23 for section in self.sections:
24 if section not in parser.sections():
25 parser.add_section(section)
26 f(*args, **kwargs)
27 return wrapped
24 28
25 #@parser # decorator makes this x-form path -> ConfigParser automagically 29 #@parser # decorator makes this x-form path -> ConfigParser automagically
26 @section('paths') 30 @section('paths')
27 def set_default(parser, default): 31 def set_default(parser, default):
28 """set [paths]:default""" 32 """set [paths]:default"""
29 33
34 @section('paths')
30 def set_default_push(parser, default_push): 35 def set_default_push(parser, default_push):
31 """ 36 """
32 set [paths]:default-push to `default_push` 37 set [paths]:default-push to `default_push`
33 """ 38 """
34 if 'paths' not in parser.sections(): 39 if 'paths' not in parser.sections():
95 'default_push_ssh', 100 'default_push_ssh',
96 'list_hgrc', 101 'list_hgrc',
97 ) 102 )
98 actions = [(name, getattr(options, name)) 103 actions = [(name, getattr(options, name))
99 for name in available_actions 104 for name in available_actions
100 if getattr(options, name)]) 105 if getattr(options, name)]
101 if not actions: 106 if not actions:
102 actions = [('default_push_ssh', True)] 107 actions = [('default_push_ssh', True)]
103 108
104 # find all hgrc files 109 # find all hgrc files
105 hgrc = [] 110 hgrc = []
150 155
151 # print the chosen hgrc paths 156 # print the chosen hgrc paths
152 if options.list_hgrc: 157 if options.list_hgrc:
153 print '\n'.join(hgrc) 158 print '\n'.join(hgrc)
154 159
160 # remove from actions list
155 # TODO -> OrderedDict 161 # TODO -> OrderedDict
156 actions.pop('list_hgrc', None): 162 actions.pop('list_hgrc', None)
163 actions.pop()
157 164
158 # map of actions -> functions; 165 # map of actions -> functions;
159 # XXX this is pretty improv; to be improved 166 # XXX this is pretty improv; to be improved
160 action_map = {'default_push_ssh': set_default_push_to_ssh, 167 action_map = {'default_push_ssh': set_default_push_to_ssh,
161 'default_push': set_default_push 168 'default_push': set_default_push