Source

hgswitch / switch.py

#!/usr/bin/env python

"""switch default path for repository - eiriktest"""

import os, ConfigParser
from mercurial import hg

from mercurial.url import hidepassword

def switch(ui, repo, source=None, **opts):
    """switch default path for repository"""
    hgrc = repo.join('hgrc')
    config = ConfigParser.ConfigParser()
    config.read(hgrc)
    
    if not config.has_section('paths'):
        config.add_section('paths')
    elif not source and 'default' in config.options('paths'):
        print "default =", hidepassword(config.get('paths', 'default'))
        return
        
    config.set('paths', 'default', source)
    
    try:
        f = open(hgrc, 'w')
        config.write(f)
    except:
        print "failed to write", hgrc
    finally:
        f.close()

cmdtable = { 
    "switch": (switch, [ ], "hg switch [SOURCE]"),
}