Mercurial > hg > config
comparison python/setup_repo.py @ 404:fb304dcd1e64
factor to its own method
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Tue, 30 Jul 2013 10:35:47 -0700 |
| parents | 62eb670a408f |
| children | 815eb5c796e9 |
comparison
equal
deleted
inserted
replaced
| 403:62eb670a408f | 404:fb304dcd1e64 |
|---|---|
| 23 default-push = ssh://%(host)s/%(repo)s/%(name)s | 23 default-push = ssh://%(host)s/%(repo)s/%(name)s |
| 24 """ | 24 """ |
| 25 | 25 |
| 26 call = subprocess.check_output | 26 call = subprocess.check_output |
| 27 | 27 |
| 28 def init_repo(directory): | |
| 29 """setup repository""" | |
| 30 call(['hg', 'init', directory]) | |
| 31 call(['hg', 'add', '-R', directory]) | |
| 32 call(['hg', 'commit', '-m', options.message, '-R', directory]) | |
| 33 | |
| 34 | |
| 28 def main(args=sys.argv[1:]): | 35 def main(args=sys.argv[1:]): |
| 29 | 36 |
| 30 # parse command line arguments | 37 # parse command line arguments |
| 31 parser = OptionParser('%prog [options] directory') | 38 parser = OptionParser('%prog [options] directory') |
| 32 parser.add_option('-m', '--message', dest='message', | 39 parser.add_option('-m', '--message', dest='message', |
| 40 parser.add_option | 47 parser.add_option |
| 41 options, args = parser.parse_args(args) | 48 options, args = parser.parse_args(args) |
| 42 if len(args) != 1: | 49 if len(args) != 1: |
| 43 parser.print_usage() | 50 parser.print_usage() |
| 44 parser.exit() | 51 parser.exit() |
| 45 # TODO: sanity check for remote_url, remote_path | 52 directory = args[0] |
| 46 | 53 |
| 47 # setup repository | 54 # initialize repository |
| 48 directory = args[0] | 55 init_repo(directory) |
| 49 name = os.path.basename(directory) # XXX unnecessary? | |
| 50 call(['hg', 'init', directory]) | |
| 51 call(['hg', 'add', '-R', directory]) | |
| 52 call(['hg', 'commit', '-m', options.message, '-R', directory]) | |
| 53 | 56 |
| 54 # setup remote, if specified | 57 # setup remote, if specified |
| 58 name = os.path.basename(directory) | |
| 55 if options.remote_url: | 59 if options.remote_url: |
| 56 | 60 |
| 57 # parse remote URL | 61 # parse remote URL |
| 58 host, netloc, path, query, anchor = urlparse.urlsplit(options.remote_url) | 62 host, netloc, path, query, anchor = urlparse.urlsplit(options.remote_url) |
| 59 if options.remote_path: | 63 if options.remote_path: |
