annotate unixSoft/bin/hgimp @ 352:3111d61151be

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