-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclean_substitution.py
More file actions
executable file
·66 lines (50 loc) · 1.75 KB
/
clean_substitution.py
File metadata and controls
executable file
·66 lines (50 loc) · 1.75 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
#encoding=utf-8
from os import listdir, remove, rename
from os.path import join
def overwrite_config_file(file_path, readonly):
output_filepath = file_path + ".tmp"
input_file = open(file_path, 'r')
output_file = open(output_filepath, 'w')
left_part_substitution = 'Substitution2:'
left_part_substitution_length = len(left_part_substitution)
for x_line in input_file:
#print(x_line)
new_line = x_line
# match Substitution2 line.
if left_part_substitution == x_line[:left_part_substitution_length]:
print("match at file:", file_path)
continue
output_file.write(new_line)
input_file.close()
output_file.close()
if not readonly:
remove(file_path)
rename(output_filepath, file_path)
def scan_files_from_folder(ff_folder, readonly):
files = listdir(ff_folder)
match_count = 0
for f in files:
if '.glyph' in f:
# skip hidden files.
if f[:1] == ".":
continue
target_path = join(ff_folder,f)
overwrite_config_file(target_path, readonly)
def clean_ff(source_ff, readonly):
#source_ff = 'Bakudai-Regular.sfdir'
scan_files_from_folder(source_ff, readonly)
if __name__ == '__main__':
#readonly = True # for test
readonly = False # online
import sys
argument_count = 2
if len(sys.argv)==argument_count:
source_ff = sys.argv[1]
if len(source_ff) > 1:
if not ".sfdir" in source_ff:
source_ff += ".sfdir"
clean_ff(source_ff, readonly)
else:
print("Argument must be: %d" % (argument_count -1))
print("Ex:%s folder_name" % (sys.argv[0]))