File: cutout.py

package info (click to toggle)
fontconfig 2.17.1-5
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,160 kB
  • sloc: ansic: 26,595; makefile: 1,282; sh: 1,201; python: 1,010
file content (27 lines) | stat: -rwxr-xr-x 825 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env python3

from pathlib import Path
import argparse
import re

if __name__== '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('input')
    parser.add_argument('output')
    args = parser.parse_args()

    input_lines = Path(args.input).read_text(encoding='utf-8').splitlines()
    with Path(args.output).open('w', encoding='utf-8') as out:
        write = True
        for l in input_lines:
            if l.startswith('CUT_OUT_BEGIN'):
                write = False

            if write and l:
                stripped = re.sub(r'^\s+', '', l)
                stripped = re.sub(r'\s*,\s*', ',', stripped)
                if not stripped.isspace() and stripped:
                    out.write('%s\n' % stripped)

            if l.startswith('CUT_OUT_END'):
                write = True