comparison python/setup_repo.py @ 452:7d6bd51f0323

python/setup_repo.py
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 10 Aug 2013 16:51:24 -0700
parents 96859ac4d23f
children f7c49c61f092
comparison
equal deleted inserted replaced
451:96859ac4d23f 452:7d6bd51f0323
40 # TODO: use ConfigParser 40 # TODO: use ConfigParser
41 with file(os.path.join(directory, '.hg', 'hgrc'), 'w') as f: 41 with file(os.path.join(directory, '.hg', 'hgrc'), 'w') as f:
42 print >> f, HGRC % { 'host': host, 'repo': repo, 'name': name} 42 print >> f, HGRC % { 'host': host, 'repo': repo, 'name': name}
43 43
44 44
45 def setup_remote(local_repo, remote_url, push='ssh', remote_path=None): 45 def setup_remote(local_repo, remote_url, push='ssh', remote_path=None, name=None):
46 """ 46 """
47 setup a remote repository for local_repo 47 setup a remote repository for local_repo
48 - remote_url : public (pull) URL for remote repository 48 - remote_url : public (pull) URL for remote repository
49 - push : protocol for push 49 - push : protocol for push
50 - remote_path : remote path of hg repository links; otherwise taken from --remote-url, if specified 50 - remote_path : remote path of hg repository links; otherwise taken from --remote-url, if specified
51 """ 51 """
52 52
53 # parse remote URL 53 # parse remote URL
54 host, netloc, path, query, anchor = urlparse.urlsplit(remote_url) 54 host, netloc, path, query, anchor = urlparse.urlsplit(remote_url)
55 path = path.rstrip('/')
56
57 # derive name
58 if name is None:
59 if '/' in path:
60 prefix, name = path.rsplit('/', 1)
61 else:
62 name = path
63 assert name
64
65 # get remote path, if specified
55 if remote_path: 66 if remote_path:
56 67
57 # split off remote host and path 68 # split off remote host and path
58 # XXX is a separate host necessary? 69 # XXX is a separate host necessary?
59 remote_host = host 70 remote_host = host
61 remote_host, remote_path = remote_path.split(':', 1) 72 remote_host, remote_path = remote_path.split(':', 1)
62 else: 73 else:
63 remote_path = path 74 remote_path = path
64 75
65 # setup remote repository 76 # setup remote repository
66 remote_dir = '%s/%s' % (path, name) 77 remote_dir = '~/%s/%s' % (path.lstrip('/'), name)
67 command = ['ssh', host, "mkdir -p %s && cd %s && hg init" % (remote_dir, remote_dir)] 78 command = ['ssh', host, "mkdir -p %s && cd %s && hg init" % (remote_dir, remote_dir)]
68 print command 79 print command
69 # call(command) 80 # call(command)
70 81
71 82
103 # setup remote, if specified 114 # setup remote, if specified
104 name = os.path.basename(directory) 115 name = os.path.basename(directory)
105 if options.remote_url: 116 if options.remote_url:
106 117
107 # setup remote repository 118 # setup remote repository
108 setup_remote(directory, options.remote_url, remote_path=options.remote_path) 119 setup_remote(directory, options.remote_url, name=name, remote_path=options.remote_path)
109 120
110 # push changes 121 # push changes
111 call(['hg', 'push', '-R', directory]) 122 call(['hg', 'push', '-R', directory])
112 123
113 if __name__ == '__main__': 124 if __name__ == '__main__':