]> arthur.barton.de Git - bup.git/blob - dev/replace
test-restore-map-owner: accommodate python 3 and test there
[bup.git] / dev / replace
1 #!/bin/sh
2 """": # -*-python-*-
3 exec env LC_CTYPE=iso-8859-1 python "$0" ${1+"$@"}
4 """
5
6 from __future__ import absolute_import, print_function
7 import sys
8
9 py_maj = sys.version_info[0]
10
11 import argparse
12 if py_maj > 2:
13     byte_stream = lambda x: x.buffer
14     from os import fsencode
15 else:
16     byte_stream = lambda x: x
17     fsencode = lambda x: x
18
19 parser = argparse.ArgumentParser()
20 parser.add_argument('-l', nargs=2, metavar=('ORIG', 'NEW'), action='append',
21                     help='literally replace ORIG with NEW')
22 opt = parser.parse_args()
23
24 sys.stdout.flush()
25 with byte_stream(sys.stdin) as stdin:
26     content = stdin.read()
27 for orig, new in opt.l:
28     content = content.replace(fsencode(orig), fsencode(new))
29 byte_stream(sys.stdout).write(content)