comparison unixSoft/bin/hgimp @ 343:70e76c545606

hgimp: utility to make importing hg patches from mutt easier
author Augie Fackler <raf@durin42.com>
date Wed, 10 Sep 2014 14:52:33 -0400
parents
children 2ac43cd7bbf7
comparison
equal deleted inserted replaced
342:f95ae07fb55a 343:70e76c545606
1 #!/usr/bin/env python
2 import argparse
3 import os
4 import subprocess
5 import sys
6
7 _MAP = {
8 'hg': '~/Programming/hg/crew',
9 'hgsubversion': '~/Programming/hg/hgsubversion',
10 'hg-git': '~/Programming/hg/hg-git',
11 }
12
13
14 def main(argv):
15 p = argparse.ArgumentParser('import patches')
16 p.add_argument('repo', type=str, nargs=1,
17 help='repo name to apply patches to')
18 args = p.parse_args(argv[1:])
19 name, = args.repo
20 if name in _MAP:
21 repo = _MAP[name]
22 else:
23 c = []
24 for n in _MAP:
25 if n.startswith(name):
26 c.append(n)
27 if not c:
28 print 'abort: no repo named %s' % name
29 sys.exit(1)
30 elif len(c) != 1:
31 print 'abort: ambiguous repo name %s matches %s' % (
32 name, ', '.join(c))
33 sys.exit(1)
34 repo = _MAP[c[0]]
35 hg = subprocess.Popen(['hg', '-R', repo, 'import', '--obsolete', '-'],
36 stdin=subprocess.PIPE)
37 hg.stdin.write(sys.stdin.read())
38 hg.stdin.close()
39 hg.wait()
40 sys.exit(hg.returncode)
41
42
43 if __name__ == '__main__':
44 main(argv=sys.argv)