comparison unixSoft/bin/patchpipe @ 357:c7a9cd793e37

patchpipe: handle base64-encoded message bodies It looks like the new version of mailman on selenic now base64s message bodies, so detect that and unpack the base64'd body.
author Augie Fackler <raf@durin42.com>
date Mon, 22 Dec 2014 17:12:53 -0500
parents 4e83916a4303
children a5a4f9e12c9f
comparison
equal deleted inserted replaced
356:b9fd69a36e0c 357:c7a9cd793e37
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 import base64
2 import os 3 import os
3 import subprocess 4 import subprocess
4 import sys 5 import sys
5 import tempfile 6 import tempfile
6 7
7 _PATCHHDR = '# HG changeset patch' 8 _PATCHHDR = '# HG changeset patch'
9
10 _BASE64_MAGIC = 'Content-Transfer-Encoding: base64'
8 11
9 12
10 def main(argv): 13 def main(argv):
11 tf = tempfile.NamedTemporaryFile(suffix='.diff') 14 tf = tempfile.NamedTemporaryFile(suffix='.diff')
12 d = sys.stdin.read() 15 d = sys.stdin.read()
13 if _PATCHHDR in d: 16 if _PATCHHDR in d:
14 junk, d = d.split(_PATCHHDR, 1) 17 junk, d = d.split(_PATCHHDR, 1)
15 d = _PATCHHDR + d 18 d = _PATCHHDR + d
19 elif _BASE64_MAGIC in d:
20 junk, d = d.split('\n\n', 1)
21 d = d.decode('base64')
16 tf.write(d) 22 tf.write(d)
17 tf.flush() 23 tf.flush()
18 subprocess.check_call([os.environ['EDITOR'], tf.name], 24 subprocess.check_call([os.environ['EDITOR'], tf.name],
19 stdout=sys.stderr) 25 stdout=sys.stderr)
20 sys.stdout.write(open(tf.name).read()) 26 sys.stdout.write(open(tf.name).read())