comparison python/hgrc.py @ 478:df60292c29b2

python/hgrc.py
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 10 Aug 2013 19:37:50 -0700
parents 6274107e477e
children 0a9e1e0d077c
comparison
equal deleted inserted replaced
477:6274107e477e 478:df60292c29b2
16 16
17 #@parser # decorator makes this x-form path -> ConfigParser automagically 17 #@parser # decorator makes this x-form path -> ConfigParser automagically
18 #@section('paths') 18 #@section('paths')
19 def set_default_push(parser, default_push): 19 def set_default_push(parser, default_push):
20 """ 20 """
21 set [paths]:default_push to `default_push` 21 set [paths]:default-push to `default_push`
22 """ 22 """
23 pass 23 if 'paths' not in parser.sections():
24 parser.add_section('paths')
25 parser.set('paths', 'default-push', default_push)
26
24 27
25 def set_default_push_to_ssh(parser): 28 def set_default_push_to_ssh(parser):
26 """ 29 """
27 set `[paths]:default_push` to that given by `[paths]:default` but 30 set `[paths]:default-push` to that given by `[paths]:default` but
28 turn the protocol to 'ssh' 31 turn the protocol to 'ssh'
29 If `[paths]:default` is not there, do nothing. 32 If `[paths]:default` is not there, do nothing.
30 Returns True if written, otherwise False 33 Returns True if written, otherwise False
31 """ 34 """
32 35
39 42
40 # parse URL 43 # parse URL
41 scheme, netloc, path, query, anchor = urlparse.urlsplit(default) 44 scheme, netloc, path, query, anchor = urlparse.urlsplit(default)
42 ssh_url = urlparse.urlunsplit(('ssh', netloc, path, query, anchor)) 45 ssh_url = urlparse.urlunsplit(('ssh', netloc, path, query, anchor))
43 46
47 # set
48 set_default_push(parser, ssh_url)
49 return True # XXX could instead be url to set to or old value
50
44 51
45 def main(args=sys.argv[1:]): 52 def main(args=sys.argv[1:]):
46 53
47 # parse command line arguments 54 # parse command line arguments
48 usage = '%prog [options] repository <repository> <...>' 55 usage = '%prog [options] repository <repository> <...>'
53 parser.add_option('--ssh', dest='default_push_ssh', 60 parser.add_option('--ssh', dest='default_push_ssh',
54 action='store_true', default=False, 61 action='store_true', default=False,
55 help="use `default` entries for `default-push`") 62 help="use `default` entries for `default-push`")
56 parser.add_option('--push', '--default-push', dest='default_push', 63 parser.add_option('--push', '--default-push', dest='default_push',
57 help="set [paths] default-push location") 64 help="set [paths] default-push location")
65 parser.add_option('-p', '--print', dest='print_ini',
66 action='store_true', default=False,
67 help="print .ini contents")
58 options, args = parser.parse_args(args) 68 options, args = parser.parse_args(args)
59 69
60 # sanitization 70 # sanitization
61 if options.default_push and options.default_push_ssh: 71 if options.default_push and options.default_push_ssh:
62 parser.error("Cannot set --push and --ssh") 72 parser.error("Cannot set --push and --ssh")
150 if parameter is not None: 160 if parameter is not None:
151 method(ini, parameter) 161 method(ini, parameter)
152 else: 162 else:
153 method(ini) 163 method(ini)
154 164
165 # print .hgrc files, if specified
166 for path, ini in config.items():
167 print '+++ %s' % (path)
168 ini.write(sys.stdout)
169 print
155 170
156 if __name__ == '__main__': 171 if __name__ == '__main__':
157 main() 172 main()