Mercurial > dotfiles
annotate unixSoft/bin/patchpipe @ 526:852565046ed0
zsh: fidget with screen/tmux message
This should speed things up very slightly by avoiding some `grep` action
in the common case of no detached screens/tmuxes.
| author | Augie Fackler <raf@durin42.com> |
|---|---|
| date | Mon, 14 Nov 2022 11:02:35 -0500 |
| parents | a5a4f9e12c9f |
| children |
| 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 |
| 523 | 8 _PATCHHDR = b'# HG changeset patch' |
|
344
4e83916a4303
patchpipe: tool to edit hg patches while piping them to 'hg import'
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
9 |
| 523 | 10 _BASE64_MAGIC = b'Content-Transfer-Encoding: base64' |
|
357
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') |
| 523 | 15 d = sys.stdin.buffer.read() |
|
344
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) |
| 523 | 26 sys.stdout.buffer.write(open(tf.name, 'rb').read()) |
|
344
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) |
