blob: be883be4a0dbf9f89113bdd1d864984462b598b8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
import sys
def convert_file(input_filename, output_filename, converter):
with open(input_filename, 'rb') as input_file:
content = input_file.read()
output = converter(content)
with open(output_filename, 'wb+') as output_file:
output_file.write(output)
def main(from_ext, to_ext, converter):
del sys.argv[0]
if len(sys.argv) == 0:
print("error: no input files!", file=sys.stderr)
exit(1)
for input_filename in sys.argv:
output_filename = input_filename.removesuffix(f".{from_ext}") + f".{to_ext}"
convert_file(input_filename, output_filename, converter)
|