# HG changeset patch # User Jeff Hammel # Date 1376193921 25200 # Node ID 50379f607e03ca2f3a4063abf6a26e011d7d8d4a # Parent 4bd2932d21d42ebb912eeed35731546153beb4e7 python/hgrc.py diff -r 4bd2932d21d4 -r 50379f607e03 python/hgrc.py --- a/python/hgrc.py Sat Aug 10 20:51:40 2013 -0700 +++ b/python/hgrc.py Sat Aug 10 21:05:21 2013 -0700 @@ -12,8 +12,11 @@ import subprocess import sys import urlparse +from collections import OrderedDict from ConfigParser import RawConfigParser as ConfigParser +### global methods + class section(object): def __init__(self, section_name, *section_names): self.sections = [section_name] @@ -78,7 +81,7 @@ help="use `default` entries for `default-push`") parser.add_option('--push', '--default-push', dest='default_push', help="set [paths] default-push location") - parser.add_option('--default', dest='default', + parser.add_option('-d', '--default', dest='default', help="set [paths] default entry") parser.add_option('-p', '--print', dest='print_ini', action='store_true', default=False, @@ -98,13 +101,15 @@ available_actions = ('default', 'default_push', 'default_push_ssh', + 'print_ini', 'list_hgrc', ) 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)] + actions = OrderedDict(actions) # find all hgrc files hgrc = [] @@ -154,20 +159,22 @@ config[path].read(path) # print the chosen hgrc paths - if options.list_hgrc: + if 'list_hgrc' in actions: print '\n'.join(hgrc) # remove from actions list - # TODO -> OrderedDict - # actions.pop('list_hgrc', None) - actions.pop() + actions.pop('list_hgrc', None) # map of actions -> functions; # XXX this is pretty improv; to be improved action_map = {'default_push_ssh': set_default_push_to_ssh, - 'default_push': set_default_push + 'default_push': set_default_push, + 'default': set_default } + # cache for later (XXX) + print_ini = actions.pop('print_ini', None) + # alter .hgrc files for action_name, parameter in actions: @@ -186,10 +193,11 @@ method(ini) # print .hgrc files, if specified - for path, ini in config.items(): - print '+++ %s' % (path) - ini.write(sys.stdout) - print + if print_ini: + for path, ini in config.items(): + print '+++ %s' % (path) + ini.write(sys.stdout) + print if __name__ == '__main__': main()