annotate python/setup_repo.py @ 168:09c748a71b1b

handle overlapping files
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 26 Sep 2011 16:33:02 -0700
parents 5a6f89cc6bc4
children fd0e81fdf1fa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
72
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 #!/usr/bin/env python
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 import os
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 import subprocess
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 import sys
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7 from optparse import OptionParser
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 HOST='k0s.org'
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10 HGRC="""[paths]
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 default = http://%(host)s/%(repo)s/%(name)s
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12 default-push = ssh://%(host)s/%(repo)s/%(name)s
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 """
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 def call(command, *args, **kw):
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16 code = subprocess.call(command, *args, **kw)
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17 if isinstance(command, basestring):
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18 cmdstr = command
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19 else:
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20 cmdstr = ' '.join(command)
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21 print cmdstr
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
22 if code:
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23 raise SystemExit("Command `%s` exited with code %d" % (cmdstr, code))
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
24
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
25 def main(args=sys.argv[1:]):
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
26
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
27 parser = OptionParser('%prog [options] location')
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
28 parser.add_option('-m', '--message',
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
29 help='commit message')
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
30 options, args = parser.parse_args(args)
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
31
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
32 if len(args) != 1:
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
33 parser.print_usage()
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
34 parser.exit()
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
35
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
36 repo = args[0].strip('/')
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
37
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
38 directory = os.getcwd()
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
39 name = os.path.basename(directory)
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
40 os.chdir('..')
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
41 call(['scp', '-r', name, '%s:~/%s/' % (HOST, repo)])
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
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)])
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
43 os.chdir(directory)
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
44 call(['hg', 'init'])
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
45 call(['hg', 'pull', 'http://%s/%s/%s' % (HOST, repo, name)])
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
46 call(['hg', 'update', '-C'])
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
47 f = file(os.path.join('.hg', 'hgrc'), 'a')
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
48 print >> f, HGRC % { 'host': HOST, 'repo': repo, 'name': name}
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
49
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
50 if __name__ == '__main__':
5a6f89cc6bc4 add a script to add a hg repo
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
51 main()