Mercurial > hg > config
comparison python/setup_repo.py @ 403:62eb670a408f
dont roll your own
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Tue, 30 Jul 2013 03:42:15 -0700 |
| parents | c00b70509fff |
| children | fb304dcd1e64 |
comparison
equal
deleted
inserted
replaced
| 402:c00b70509fff | 403:62eb670a408f |
|---|---|
| 11 import os | 11 import os |
| 12 import subprocess | 12 import subprocess |
| 13 import sys | 13 import sys |
| 14 import urlparse | 14 import urlparse |
| 15 | 15 |
| 16 from subprocess import check_call as call | |
| 17 from optparse import OptionParser | 16 from optparse import OptionParser |
| 18 | 17 |
| 19 | 18 |
| 20 # global variables | 19 # global variables |
| 21 HOST='k0s.org' | 20 HOST='k0s.org' |
| 22 HGRC="""[paths] | 21 HGRC="""[paths] |
| 23 default = http://%(host)s/%(repo)s/%(name)s | 22 default = http://%(host)s/%(repo)s/%(name)s |
| 24 default-push = ssh://%(host)s/%(repo)s/%(name)s | 23 default-push = ssh://%(host)s/%(repo)s/%(name)s |
| 25 """ | 24 """ |
| 26 | 25 |
| 27 def call(command, *args, **kw): | 26 call = subprocess.check_output |
| 28 | |
| 29 code = subprocess.call(command, *args, **kw) | |
| 30 if isinstance(command, basestring): | |
| 31 cmdstr = command | |
| 32 else: | |
| 33 cmdstr = ' '.join(command) | |
| 34 print cmdstr | |
| 35 if code: | |
| 36 raise SystemExit("Command `%s` exited with code %d" % (cmdstr, code)) | |
| 37 | 27 |
| 38 def main(args=sys.argv[1:]): | 28 def main(args=sys.argv[1:]): |
| 39 | 29 |
| 40 # parse command line arguments | 30 # parse command line arguments |
| 41 parser = OptionParser('%prog [options] location') | 31 parser = OptionParser('%prog [options] directory') |
| 42 parser.add_option('-m', '--message', dest='message', | 32 parser.add_option('-m', '--message', dest='message', |
| 43 default='initial commit', | 33 default='initial commit', |
| 44 help='commit message [Default: %default]') | 34 help='commit message [Default: %default]') |
| 45 parser.add_option('-u', '--remote-url', dest='remote_url', | 35 parser.add_option('-u', '--remote-url', dest='remote_url', |
| 46 default="http://k0s.org/hg/", | 36 default="http://k0s.org/hg/", |
| 72 remote_host, remote_path = remote_path.split(':', 1) | 62 remote_host, remote_path = remote_path.split(':', 1) |
| 73 else: | 63 else: |
| 74 remote_path = path | 64 remote_path = path |
| 75 | 65 |
| 76 # setup remote repository | 66 # setup remote repository |
| 77 call(['ssh', host, "mkdir -p cd %s/%s && hg init && hg add && hg ci -m '%s'" % (repo, name, options.message)]) | 67 remote_dir = '%s/%s' % (path, name) |
| 68 call(['ssh', host, "mkdir -p %s && cd %s && hg init" % (remote_dir, remote_dir)]) | |
| 78 | 69 |
| 79 # write local .hgrc file | 70 # write local .hgrc file |
| 80 # TODO: use ConfigParser | 71 # TODO: use ConfigParser |
| 81 with file(os.path.join(directory, '.hg', 'hgrc'), 'w') as f: | 72 with file(os.path.join(directory, '.hg', 'hgrc'), 'w') as f: |
| 82 print >> f, HGRC % { 'host': host, 'repo': repo, 'name': name} | 73 print >> f, HGRC % { 'host': host, 'repo': repo, 'name': name} |
