changeset 484:50379f607e03

python/hgrc.py
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 10 Aug 2013 21:05:21 -0700
parents 4bd2932d21d4
children e192c235d5d6
files python/hgrc.py
diffstat 1 files changed, 19 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- 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()