Mercurial > hg > config
comparison python/hgrc.py @ 481:65e38d33acae
python/hgrc.py
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Sat, 10 Aug 2013 20:42:04 -0700 |
| parents | 529fd4e1087e |
| children | 6c0aac8799da |
comparison
equal
deleted
inserted
replaced
| 480:529fd4e1087e | 481:65e38d33acae |
|---|---|
| 88 if not args: | 88 if not args: |
| 89 args = [subprocess.check_output(['hg', 'root']).strip()] | 89 args = [subprocess.check_output(['hg', 'root']).strip()] |
| 90 | 90 |
| 91 # if not specified, set a default action | 91 # if not specified, set a default action |
| 92 default_action = 'default_push_ssh' | 92 default_action = 'default_push_ssh' |
| 93 available_actions = ('default_push', | 93 available_actions = ('default', |
| 94 'default_push_ssh', | 94 'default_push', |
| 95 'list_hgrc', | 95 'default_push_ssh', |
| 96 'list_hgrc', | |
| 96 ) | 97 ) |
| 97 actions = dict([(name, getattr(options, name)) | 98 actions = [(name, getattr(options, name)) |
| 98 for name in available_actions | 99 for name in available_actions |
| 99 if getattr(options, name)]) | 100 if getattr(options, name)]) |
| 100 if not actions: | 101 if not actions: |
| 101 actions = {'default_push_ssh': True} | 102 actions = [('default_push_ssh', True)] |
| 102 | 103 |
| 103 # find all hgrc files | 104 # find all hgrc files |
| 104 hgrc = [] | 105 hgrc = [] |
| 105 missing = [] | 106 missing = [] |
| 106 not_hg = [] | 107 not_hg = [] |
| 146 if isinstance(path, basestring): | 147 if isinstance(path, basestring): |
| 147 if os.path.exists(path): | 148 if os.path.exists(path): |
| 148 config[path].read(path) | 149 config[path].read(path) |
| 149 | 150 |
| 150 # print the chosen hgrc paths | 151 # print the chosen hgrc paths |
| 151 if actions.pop('list_hgrc', None): | 152 if options.list_hgrc: |
| 152 print '\n'.join(hgrc) | 153 print '\n'.join(hgrc) |
| 154 | |
| 155 # TODO -> OrderedDict | |
| 156 actions.pop('list_hgrc', None): | |
| 153 | 157 |
| 154 # map of actions -> functions; | 158 # map of actions -> functions; |
| 155 # XXX this is pretty improv; to be improved | 159 # XXX this is pretty improv; to be improved |
| 156 action_map = {'default_push_ssh': set_default_push_to_ssh, | 160 action_map = {'default_push_ssh': set_default_push_to_ssh, |
| 157 'default_push': set_default_push | 161 'default_push': set_default_push |
| 158 } | 162 } |
| 159 | 163 |
| 160 # alter .hgrc files | 164 # alter .hgrc files |
| 161 action_names = actions.keys() | 165 for action_name, parameter in actions: |
| 162 while actions: | |
| 163 | 166 |
| 164 # XXX crappy | 167 # XXX crappy |
| 165 action_name = action_names.pop() | |
| 166 parameter = actions.pop(action_name) | |
| 167 method = action_map[action_name] | 168 method = action_map[action_name] |
| 168 if action_name == 'default_push_ssh': | 169 if action_name == 'default_push_ssh': |
| 169 parameter = None | 170 parameter = None |
| 170 | 171 |
| 171 # apply to all files | 172 # apply to all files |
| 172 for path, ini in config.items(): | 173 for path, ini in config.items(): |
| 174 | |
| 175 # call method with parser | |
| 173 if parameter is not None: | 176 if parameter is not None: |
| 174 method(ini, parameter) | 177 method(ini, parameter) |
| 175 else: | 178 else: |
| 176 method(ini) | 179 method(ini) |
| 177 | 180 |
