annotate unixSoft/bin/patchpipe @ 403:5c60aa185a97

common_env: add pip --user paths on OS X to PATH
author Augie Fackler <raf@durin42.com>
date Thu, 28 Jul 2016 10:15:18 -0400
parents c7a9cd793e37
children a5a4f9e12c9f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
357
c7a9cd793e37 patchpipe: handle base64-encoded message bodies
Augie Fackler <raf@durin42.com>
parents: 344
diff changeset
2 import base64
344
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
3 import os
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
4 import subprocess
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
5 import sys
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
6 import tempfile
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
7
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
8 _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
9
357
c7a9cd793e37 patchpipe: handle base64-encoded message bodies
Augie Fackler <raf@durin42.com>
parents: 344
diff changeset
10 _BASE64_MAGIC = 'Content-Transfer-Encoding: base64'
c7a9cd793e37 patchpipe: handle base64-encoded message bodies
Augie Fackler <raf@durin42.com>
parents: 344
diff changeset
11
344
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
12
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
13 def main(argv):
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
14 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
15 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
16 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
17 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
18 d = _PATCHHDR + d
357
c7a9cd793e37 patchpipe: handle base64-encoded message bodies
Augie Fackler <raf@durin42.com>
parents: 344
diff changeset
19 elif _BASE64_MAGIC in d:
c7a9cd793e37 patchpipe: handle base64-encoded message bodies
Augie Fackler <raf@durin42.com>
parents: 344
diff changeset
20 junk, d = d.split('\n\n', 1)
c7a9cd793e37 patchpipe: handle base64-encoded message bodies
Augie Fackler <raf@durin42.com>
parents: 344
diff changeset
21 d = d.decode('base64')
344
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
22 tf.write(d)
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
23 tf.flush()
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
24 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
25 stdout=sys.stderr)
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
26 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
27
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
28
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
29 if __name__ == '__main__':
4e83916a4303 patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff changeset
30 main(argv=sys.argv)