Mercurial > hg > config
comparison python/setup_repo.py @ 401:f652f9d4765b
flesh out
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 30 Jul 2013 03:30:30 -0700 |
parents | 8964b285c2f7 |
children | c00b70509fff |
comparison
equal
deleted
inserted
replaced
400:8964b285c2f7 | 401:f652f9d4765b |
---|---|
38 def main(args=sys.argv[1:]): | 38 def main(args=sys.argv[1:]): |
39 | 39 |
40 # parse command line arguments | 40 # parse command line arguments |
41 parser = OptionParser('%prog [options] location') | 41 parser = OptionParser('%prog [options] location') |
42 parser.add_option('-m', '--message', dest='message', | 42 parser.add_option('-m', '--message', dest='message', |
43 help='commit message') | 43 default='initial commit', |
44 help='commit message [Default: %default]') | |
44 parser.add_option('-u', '--remote-url', dest='remote_url', | 45 parser.add_option('-u', '--remote-url', dest='remote_url', |
45 default="http://k0s.org/hg/", | 46 default="http://k0s.org/hg/", |
46 help="URL of host hg repository collection [Default: %default]") | 47 help="URL of host hg repository collection [Default: %default]") |
47 parser.add_option('-p', '--remote-path', dest='remote_path', | 48 parser.add_option('-p', '--remote-path', dest='remote_path', |
48 help="remote path of hg repository links; otherwise taken from --remote-url, if specified") | 49 help="remote path of hg repository links; otherwise taken from --remote-url, if specified") |
50 parser.add_option | |
49 options, args = parser.parse_args(args) | 51 options, args = parser.parse_args(args) |
50 if len(args) != 1: | 52 if len(args) != 1: |
51 parser.print_usage() | 53 parser.print_usage() |
52 parser.exit() | 54 parser.exit() |
53 # TODO: sanity check for remote_url, remote_path | 55 # TODO: sanity check for remote_url, remote_path |
54 | 56 |
55 # setup repository | 57 # setup repository |
56 name = os.path.basename(directory) | 58 directory = args[0] |
57 call(['hg', 'init']) | 59 name = os.path.basename(directory) # XXX unnecessary? |
58 call(['hg', 'add']) | 60 call(['hg', 'init', directory]) |
59 call(['hg', 'commit', '-m', options.message or 'initial commit of %s' %name]) | 61 call(['hg', 'add', '-R', directory]) |
62 call(['hg', 'commit', '-m', options.message, '-R', directory]) | |
60 | 63 |
61 # setup remote, if specified | 64 # setup remote, if specified |
62 if options.remote_url: | 65 if options.remote_url: |
63 | 66 |
64 # parse remote URL | 67 # parse remote URL |
69 remote_host, remote_path = remote_path.split(':', 1) | 72 remote_host, remote_path = remote_path.split(':', 1) |
70 else: | 73 else: |
71 remote_path = path | 74 remote_path = path |
72 | 75 |
73 # setup remote repository | 76 # setup remote repository |
74 call(['ssh', HOST, "cd %s/%s && hg init && hg add && hg ci -m '%s'" % (repo, name, options.message or 'initial commit of %s' % name)]) | 77 call(['ssh', host, "mkdir -p cd %s/%s && hg init && hg add && hg ci -m '%s'" % (repo, name, options.message)]) |
75 | 78 |
76 # write local .hgrc file | 79 # write local .hgrc file |
77 # TODO: use ConfigParser | 80 # TODO: use ConfigParser |
78 f = file(os.path.join('.hg', 'hgrc'), 'w') | 81 f = file(os.path.join('.hg', 'hgrc'), 'w') |
79 print >> f, HGRC % { 'host': HOST, 'repo': repo, 'name': name} | 82 print >> f, HGRC % { 'host': HOST, 'repo': repo, 'name': name} |
80 | 83 |
84 # push changes | |
85 call(['hg', 'push', '-R', directory]) | |
86 | |
81 if __name__ == '__main__': | 87 if __name__ == '__main__': |
82 main() | 88 main() |