Mercurial > hg > config
changeset 482:6c0aac8799da
python/hgrc.py
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Sat, 10 Aug 2013 20:51:25 -0700 (2013-08-11) |
parents | 65e38d33acae |
children | 4bd2932d21d4 |
files | python/hgrc.py |
diffstat | 1 files changed, 12 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/python/hgrc.py Sat Aug 10 20:42:04 2013 -0700 +++ b/python/hgrc.py Sat Aug 10 20:51:25 2013 -0700 @@ -15,18 +15,23 @@ from ConfigParser import RawConfigParser as ConfigParser class section(object): - def __init__(self, function, section_name, *section_names): - self.function = function + def __init__(self, section_name, *section_names): self.sections = [section_name] self.sections.extend(section_names) def __call__(self, parser): - import pdb; pdb.set_trace() + def wrapped(parser, *args, **kwargs): + for section in self.sections: + if section not in parser.sections(): + parser.add_section(section) + f(*args, **kwargs) + return wrapped #@parser # decorator makes this x-form path -> ConfigParser automagically @section('paths') def set_default(parser, default): """set [paths]:default""" +@section('paths') def set_default_push(parser, default_push): """ set [paths]:default-push to `default_push` @@ -97,7 +102,7 @@ ) actions = [(name, getattr(options, name)) for name in available_actions - if getattr(options, name)]) + if getattr(options, name)] if not actions: actions = [('default_push_ssh', True)] @@ -152,8 +157,10 @@ if options.list_hgrc: print '\n'.join(hgrc) + # remove from actions list # TODO -> OrderedDict - actions.pop('list_hgrc', None): + actions.pop('list_hgrc', None) + actions.pop() # map of actions -> functions; # XXX this is pretty improv; to be improved