comparison python/hgrc.py @ 477:6274107e477e

python/hgrc.py
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 10 Aug 2013 19:26:22 -0700
parents 9d81ec713f1b
children df60292c29b2
comparison
equal deleted inserted replaced
476:9d81ec713f1b 477:6274107e477e
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 import urlparse
14 from ConfigParser import RawConfigParser as ConfigParser 15 from ConfigParser import RawConfigParser as ConfigParser
15 16
16 #@parser # decorator makes this x-form path -> ConfigParser automagically 17 #@parser # decorator makes this x-form path -> ConfigParser automagically
18 #@section('paths')
17 def set_default_push(parser, default_push): 19 def set_default_push(parser, default_push):
18 """ 20 """
19 set [paths]:default_push to `default_push` 21 set [paths]:default_push to `default_push`
20 """ 22 """
21 pass 23 pass
22 24
23 def set_default_push_to_ssh(parser): 25 def set_default_push_to_ssh(parser):
24 """ 26 """
25 set `[path]:default_push` to that given by `[path]:default` but 27 set `[paths]:default_push` to that given by `[paths]:default` but
26 turn the protocol to 'ssh' 28 turn the protocol to 'ssh'
29 If `[paths]:default` is not there, do nothing.
30 Returns True if written, otherwise False
27 """ 31 """
28 32
29 import pdb; pdb.set_trace() 33 # get [paths]:default value
34 if 'paths' not in parser.sections():
35 return False
36 if not parser.has_option('paths', 'default'):
37 return False
38 default = parser.get('paths', 'default')
30 39
31 # get default path 40 # parse URL
32 default = '' 41 scheme, netloc, path, query, anchor = urlparse.urlsplit(default)
42 ssh_url = urlparse.urlunsplit(('ssh', netloc, path, query, anchor))
43
33 44
34 def main(args=sys.argv[1:]): 45 def main(args=sys.argv[1:]):
35 46
36 # parse command line arguments 47 # parse command line arguments
37 usage = '%prog [options] repository <repository> <...>' 48 usage = '%prog [options] repository <repository> <...>'