comparison python/hgrc.py @ 437:2588ca4ae849

python/hgrc.py
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 08 Aug 2013 11:01:21 -0700
parents ac7973ec485e
children ae2db9e613f1
comparison
equal deleted inserted replaced
436:651caa15d80f 437:2588ca4ae849
9 # imports 9 # imports
10 import optparse 10 import optparse
11 import os 11 import os
12 import subprocess 12 import subprocess
13 import sys 13 import sys
14 from ConfigParser import RawCOnfigParser as ConfigParser 14 from ConfigParser import RawConfigParser as ConfigParser
15 15
16 def main(args=sys.argv[1:]): 16 def main(args=sys.argv[1:]):
17 17
18 # parse command line arguments 18 # parse command line arguments
19 usage = '%prog [options] repository <repository> <...>' 19 usage = '%prog [options] repository <repository> <...>'
24 parser.add_option('--ssh', dest='default_push_ssh', 24 parser.add_option('--ssh', dest='default_push_ssh',
25 action='store_true', default=False, 25 action='store_true', default=False,
26 help="use `default` entries for `default-push`") 26 help="use `default` entries for `default-push`")
27 parser.add_option('--push', '--default-push', dest='default_push', 27 parser.add_option('--push', '--default-push', dest='default_push',
28 help="set [paths] default-push location") 28 help="set [paths] default-push location")
29 options, args = options.parse_args(args) 29 options, args = parser.parse_args(args)
30 30
31 # if not specified, use repo from `hg root` 31 # if not specified, use repo from `hg root`
32 if not args: 32 if not args:
33 args = [subprocess.check_output(['hg', 'root'])] 33 args = [subprocess.check_output(['hg', 'root']).strip()]
34 34
35 # if not specified, set a default action 35 # if not specified, set a default action
36 default_action = 'default_push_ssh' 36 default_action = 'default_push_ssh'
37 actions = ('default_push', 37 actions = ('default_push',
38 'default_push_ssh', 38 'default_push_ssh',
58 hgrcpath = os.path.join(path, 'hgrc') 58 hgrcpath = os.path.join(path, 'hgrc')
59 elif os.path.exists(subhgdir): 59 elif os.path.exists(subhgdir):
60 if not os.path.isdir(subhgdir): 60 if not os.path.isdir(subhgdir):
61 not_a_directory.append(subhgdir) 61 not_a_directory.append(subhgdir)
62 continue 62 continue
63 hgrcpath = os.path.join(subhgdir, 'hgrc')
63 else: 64 else:
64 not_hg.append(path) 65 not_hg.append(path)
65 continue 66 continue
67 hgrc.append(hgrcpath)
66 else: 68 else:
67 assert os.path.isfile(path), "%s is not a file, exiting" % path 69 assert os.path.isfile(path), "%s is not a file, exiting" % path
68 hgrc.append(path) 70 hgrc.append(path)
69 71
70 # raise errors if encountered 72 # raise errors if encountered
71 if sum(errors.values()): 73 if filter(None, errors.values()):
72 for key, value in errors.items(): 74 for key, value in errors.items():
73 if value: 75 if value:
74 print '%s: %s' % (key, ', '.join(value)) 76 print '%s: %s' % (key, ', '.join(value))
75 parser.exit(1) 77 parser.exit(1)
76 78