Mercurial > hg > config
comparison python/setup_repo.py @ 72:5a6f89cc6bc4
add a script to add a hg repo
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Wed, 26 May 2010 15:28:00 -0700 |
parents | |
children | fd0e81fdf1fa |
comparison
equal
deleted
inserted
replaced
71:3d111401010f | 72:5a6f89cc6bc4 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 import os | |
4 import subprocess | |
5 import sys | |
6 | |
7 from optparse import OptionParser | |
8 | |
9 HOST='k0s.org' | |
10 HGRC="""[paths] | |
11 default = http://%(host)s/%(repo)s/%(name)s | |
12 default-push = ssh://%(host)s/%(repo)s/%(name)s | |
13 """ | |
14 | |
15 def call(command, *args, **kw): | |
16 code = subprocess.call(command, *args, **kw) | |
17 if isinstance(command, basestring): | |
18 cmdstr = command | |
19 else: | |
20 cmdstr = ' '.join(command) | |
21 print cmdstr | |
22 if code: | |
23 raise SystemExit("Command `%s` exited with code %d" % (cmdstr, code)) | |
24 | |
25 def main(args=sys.argv[1:]): | |
26 | |
27 parser = OptionParser('%prog [options] location') | |
28 parser.add_option('-m', '--message', | |
29 help='commit message') | |
30 options, args = parser.parse_args(args) | |
31 | |
32 if len(args) != 1: | |
33 parser.print_usage() | |
34 parser.exit() | |
35 | |
36 repo = args[0].strip('/') | |
37 | |
38 directory = os.getcwd() | |
39 name = os.path.basename(directory) | |
40 os.chdir('..') | |
41 call(['scp', '-r', name, '%s:~/%s/' % (HOST, repo)]) | |
42 call(['ssh', HOST, "cd %s/%s && hg init && hg add && hg ci -m '%s'" % (repo, name, options.message or 'initial commit of %s' % name)]) | |
43 os.chdir(directory) | |
44 call(['hg', 'init']) | |
45 call(['hg', 'pull', 'http://%s/%s/%s' % (HOST, repo, name)]) | |
46 call(['hg', 'update', '-C']) | |
47 f = file(os.path.join('.hg', 'hgrc'), 'a') | |
48 print >> f, HGRC % { 'host': HOST, 'repo': repo, 'name': name} | |
49 | |
50 if __name__ == '__main__': | |
51 main() |