changeset 477:6274107e477e

python/hgrc.py
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 10 Aug 2013 19:26:22 -0700 (2013-08-11)
parents 9d81ec713f1b
children df60292c29b2
files python/hgrc.py
diffstat 1 files changed, 15 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/python/hgrc.py	Sat Aug 10 19:15:40 2013 -0700
+++ b/python/hgrc.py	Sat Aug 10 19:26:22 2013 -0700
@@ -11,9 +11,11 @@
 import os
 import subprocess
 import sys
+import urlparse
 from ConfigParser import RawConfigParser as ConfigParser
 
 #@parser # decorator makes this x-form path -> ConfigParser automagically
+#@section('paths')
 def set_default_push(parser, default_push):
     """
     set [paths]:default_push to `default_push`
@@ -22,14 +24,23 @@
 
 def set_default_push_to_ssh(parser):
     """
-    set `[path]:default_push` to that given by `[path]:default` but
+    set `[paths]:default_push` to that given by `[paths]:default` but
     turn the protocol to 'ssh'
+    If `[paths]:default` is not there, do nothing.
+    Returns True if written, otherwise False
     """
 
-    import pdb; pdb.set_trace()
+    # get [paths]:default value
+    if 'paths' not in parser.sections():
+        return False
+    if not parser.has_option('paths', 'default'):
+        return False
+    default = parser.get('paths', 'default')
 
-    # get default path
-    default = ''
+    # parse URL
+    scheme, netloc, path, query, anchor = urlparse.urlsplit(default)
+    ssh_url = urlparse.urlunsplit(('ssh', netloc, path, query, anchor))
+
 
 def main(args=sys.argv[1:]):