-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake_print_version.py
executable file
·38 lines (30 loc) · 1.03 KB
/
make_print_version.py
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
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python3
import os
import sys
if __name__ == '__main__':
if len(sys.argv) != 2:
print(f'Error: Usage {sys.argv[0]} [file_name]')
sys.exit(1)
file_name = sys.argv[1]
if not os.path.isfile(file_name):
print(f'Error: File \'{file_name}\' does not exist!')
sys.exit(1)
out_lines = []
skip_state = False
with open(file_name, 'r') as f:
for line in f.readlines():
if line.strip().startswith('% REMOVE_FOR_PRINT {'):
if skip_state:
print('Parsing error!')
sys.exit(2)
skip_state = True
elif line.strip().startswith('% REMOVE_FOR_PRINT }'):
if not skip_state:
print('Parsing error!')
sys.exit(3)
skip_state = False
elif not skip_state:
out_lines.append(line)
file_name = file_name.rstrip('.tex') + '_pv.tex'
with open(file_name, 'w') as f:
f.write(''.join(out_lines))