comparison unixSoft/bin/patchpipe @ 523:a5a4f9e12c9f

patchpipe: py3 support
author Augie Fackler <raf@durin42.com>
date Sat, 06 Aug 2022 10:41:27 -0400
parents c7a9cd793e37
children
comparison
equal deleted inserted replaced
522:7983184eb8d8 523:a5a4f9e12c9f
3 import os 3 import os
4 import subprocess 4 import subprocess
5 import sys 5 import sys
6 import tempfile 6 import tempfile
7 7
8 _PATCHHDR = '# HG changeset patch' 8 _PATCHHDR = b'# HG changeset patch'
9 9
10 _BASE64_MAGIC = 'Content-Transfer-Encoding: base64' 10 _BASE64_MAGIC = b'Content-Transfer-Encoding: base64'
11 11
12 12
13 def main(argv): 13 def main(argv):
14 tf = tempfile.NamedTemporaryFile(suffix='.diff') 14 tf = tempfile.NamedTemporaryFile(suffix='.diff')
15 d = sys.stdin.read() 15 d = sys.stdin.buffer.read()
16 if _PATCHHDR in d: 16 if _PATCHHDR in d:
17 junk, d = d.split(_PATCHHDR, 1) 17 junk, d = d.split(_PATCHHDR, 1)
18 d = _PATCHHDR + d 18 d = _PATCHHDR + d
19 elif _BASE64_MAGIC in d: 19 elif _BASE64_MAGIC in d:
20 junk, d = d.split('\n\n', 1) 20 junk, d = d.split('\n\n', 1)
21 d = d.decode('base64') 21 d = d.decode('base64')
22 tf.write(d) 22 tf.write(d)
23 tf.flush() 23 tf.flush()
24 subprocess.check_call([os.environ['EDITOR'], tf.name], 24 subprocess.check_call([os.environ['EDITOR'], tf.name],
25 stdout=sys.stderr) 25 stdout=sys.stderr)
26 sys.stdout.write(open(tf.name).read()) 26 sys.stdout.buffer.write(open(tf.name, 'rb').read())
27 27
28 28
29 if __name__ == '__main__': 29 if __name__ == '__main__':
30 main(argv=sys.argv) 30 main(argv=sys.argv)