comparison python/hgrc.py @ 353:ee8ab3de9c7f

f-ing print
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 27 Jun 2013 02:41:53 -0700
parents eeff298cc922
children 6797477f6a8f
comparison
equal deleted inserted replaced
352:eeff298cc922 353:ee8ab3de9c7f
15 def main(args=sys.argv[1:]): 15 def main(args=sys.argv[1:]):
16 16
17 # command line parser 17 # command line parser
18 usage = '%prog [options] repository <repository> <...>' 18 usage = '%prog [options] repository <repository> <...>'
19 parser = optparse.OptionParser(usage=usage, description=__doc__) 19 parser = optparse.OptionParser(usage=usage, description=__doc__)
20 parser.add_option('-p', '--print', dest='print', 20 parser.add_option('-p', '--print', dest='print_hgrc',
21 action='store_true', default=False, 21 action='store_true', default=False,
22 help="print full path to hgrc files and exit") 22 help="print full path to hgrc files and exit")
23 parser.add_option('--ssh', dest='default_push_ssh', 23 parser.add_option('--ssh', dest='default_push_ssh',
24 action='store_true', default=False, 24 action='store_true', default=False,
25 help="use `default` entries for `default-push`") 25 help="use `default` entries for `default-push`")
26 parser.add_option('--push', '--default-push', dest='default_push',
27 help="set [paths] default-push location")
26 options, args = options.parse_args(args) 28 options, args = options.parse_args(args)
27 if not args: 29 if not args:
28 parser.print_usage() 30 parser.print_usage()
29 parser.exit() 31 parser.exit()
30 32
31 # find all .hgrc files 33 # find all hgrc files
32 hgrc = [] 34 hgrc = []
33 missing = [] 35 missing = []
34 not_hg = [] 36 not_hg = []
35 not_a_directory = [] 37 not_a_directory = []
36 errors = {'Missing path': missing, 38 errors = {'Missing path': missing,
55 continue 57 continue
56 else: 58 else:
57 assert os.path.isfile(path), "%s is not a file, exiting" % path 59 assert os.path.isfile(path), "%s is not a file, exiting" % path
58 hgrc.append(path) 60 hgrc.append(path)
59 61
62 # raise errors if encountered
63 if sum(errors.values()):
64 for key, value in errors.items():
65 if value:
66 print '%s: %s' % (key, ', '.join(value))
67 parser.exit(1)
68
60 # construct ConfigParser objects and 69 # construct ConfigParser objects and
61 # ensure that all the files are parseable 70 # ensure that all the files are parseable
62 config = {} 71 config = {}
63 for path in hgrc: 72 for path in hgrc:
64 config['path'] = ConfigParser() 73 config[path] = ConfigParser()
65 if isinstance(path, basestring): 74 if isinstance(path, basestring):
66 config['path'].read(path) 75 if os.path.exists(path):
67 76 config[path].read(path)
68 if options.print: 77 else:
78 # XXX this code path is untenable
79 config[path].
80
81 if options.print_hgrc:
69 # print the chosen hgrc paths and you're done 82 # print the chosen hgrc paths and you're done
70 print '\n'.join(hgrc) 83 print '\n'.join(hgrc)
71 parser.exit() 84 parser.exit()
72 85
73 if __name__ == '__main__': 86 if __name__ == '__main__':