| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
from pathlib import Path |
| 4 |
import argparse |
| 5 |
import re |
| 6 |
|
| 7 |
if __name__== '__main__': |
| 8 |
parser = argparse.ArgumentParser() |
| 9 |
parser.add_argument('input') |
| 10 |
parser.add_argument('output') |
| 11 |
args = parser.parse_args() |
| 12 |
|
| 13 |
input_lines = Path(args.input).read_text(encoding='utf-8').splitlines() |
| 14 |
with Path(args.output).open('w', encoding='utf-8') as out: |
| 15 |
write = True |
| 16 |
for l in input_lines: |
| 17 |
if l.startswith('CUT_OUT_BEGIN'): |
| 18 |
write = False |
| 19 |
|
| 20 |
if write and l: |
| 21 |
stripped = re.sub(r'^\s+', '', l) |
| 22 |
stripped = re.sub(r'\s*,\s*', ',', stripped) |
| 23 |
if not stripped.isspace() and stripped: |
| 24 |
out.write('%s\n' % stripped) |
| 25 |
|
| 26 |
if l.startswith('CUT_OUT_END'): |
| 27 |
write = True |