Mercurial > dotfiles
annotate unixSoft/bin/patchpipe @ 358:08af9e123baa
emacs: load customize file earlier so it can matter for things like smart-modeline
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Thu, 08 Jan 2015 16:22:23 -0500 |
parents | 4e83916a4303 |
children | c7a9cd793e37 |
rev | line source |
---|---|
344
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
2 import os |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
3 import subprocess |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
4 import sys |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
5 import tempfile |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
6 |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
7 _PATCHHDR = '# HG changeset patch' |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
8 |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
9 |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
10 def main(argv): |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
11 tf = tempfile.NamedTemporaryFile(suffix='.diff') |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
12 d = sys.stdin.read() |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
13 if _PATCHHDR in d: |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
14 junk, d = d.split(_PATCHHDR, 1) |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
15 d = _PATCHHDR + d |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
16 tf.write(d) |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
17 tf.flush() |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
18 subprocess.check_call([os.environ['EDITOR'], tf.name], |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
19 stdout=sys.stderr) |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
20 sys.stdout.write(open(tf.name).read()) |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
21 |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
22 |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
23 if __name__ == '__main__': |
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
24 main(argv=sys.argv) |