# HG changeset patch # User Jeff Hammel # Date 1274912880 25200 # Node ID 5a6f89cc6bc4b346ef44c9c836e08fe2bba1a08f # Parent 3d111401010fda827cd3ae63574951c7465060d0 add a script to add a hg repo diff -r 3d111401010f -r 5a6f89cc6bc4 python/setup_repo.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/setup_repo.py Wed May 26 15:28:00 2010 -0700 @@ -0,0 +1,51 @@ +#!/usr/bin/env python + +import os +import subprocess +import sys + +from optparse import OptionParser + +HOST='k0s.org' +HGRC="""[paths] +default = http://%(host)s/%(repo)s/%(name)s +default-push = ssh://%(host)s/%(repo)s/%(name)s +""" + +def call(command, *args, **kw): + code = subprocess.call(command, *args, **kw) + if isinstance(command, basestring): + cmdstr = command + else: + cmdstr = ' '.join(command) + print cmdstr + if code: + raise SystemExit("Command `%s` exited with code %d" % (cmdstr, code)) + +def main(args=sys.argv[1:]): + + parser = OptionParser('%prog [options] location') + parser.add_option('-m', '--message', + help='commit message') + options, args = parser.parse_args(args) + + if len(args) != 1: + parser.print_usage() + parser.exit() + + repo = args[0].strip('/') + + directory = os.getcwd() + name = os.path.basename(directory) + os.chdir('..') + call(['scp', '-r', name, '%s:~/%s/' % (HOST, repo)]) + call(['ssh', HOST, "cd %s/%s && hg init && hg add && hg ci -m '%s'" % (repo, name, options.message or 'initial commit of %s' % name)]) + os.chdir(directory) + call(['hg', 'init']) + call(['hg', 'pull', 'http://%s/%s/%s' % (HOST, repo, name)]) + call(['hg', 'update', '-C']) + f = file(os.path.join('.hg', 'hgrc'), 'a') + print >> f, HGRC % { 'host': HOST, 'repo': repo, 'name': name} + +if __name__ == '__main__': + main()