-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathchange_version.py
More file actions
executable file
·160 lines (131 loc) · 6 KB
/
change_version.py
File metadata and controls
executable file
·160 lines (131 loc) · 6 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env python3
#encoding=utf-8
from os import listdir, remove, rename
from os.path import join, isdir, isfile
# common functions.
def find_between( s, first, last ):
try:
start = s.index( first ) + len( first )
end = s.index( last, start )
return s[start:end]
except ValueError:
return ""
def overwrite_config_file(file_path, new_version_string):
output_filepath = file_path + ".tmp"
input_file = open(file_path, 'r')
output_file = open(output_filepath, 'w')
left_part_version = 'Version: '
left_part_version_length = len(left_part_version)
left_part_lang = 'LangName: '
left_part_lang_length = len(left_part_lang)
left_part_fontname = 'FontName:'
left_part_fontname_length = len(left_part_fontname)
left_part_fullname = 'FullName:'
left_part_fullname_length = len(left_part_fullname)
left_part_weight = 'Weight: '
left_part_weight_length = len(left_part_weight)
new_weight = ""
if '-' in file_path:
file_path_array = file_path.split("-")
last_item = file_path_array[len(file_path_array)-1]
my_delimitor_symbol = u'.sfdir'
if my_delimitor_symbol in last_item:
my_delimitor_index = last_item.find(my_delimitor_symbol)
if my_delimitor_index >=0:
new_weight = last_item[:my_delimitor_index]
print("Weight:", new_weight)
left_part_ttfweight = 'TTFWeight: '
left_part_ttfweight_length = len(left_part_ttfweight)
if not("-" in file_path and ".sfdir" in file_path):
print("Error: must match weight in folder name, ex: fontname-Regular.sfdir")
return
old_weight = None
for x_line in input_file:
#print(x_line)
new_line = x_line
# chage font name
if left_part_fontname == x_line[:left_part_fontname_length]:
if "-" in new_line:
old_weight = new_line.split('-')[1].strip()
print('weight in config:"%s"' % (old_weight))
if not old_weight is None:
print('weight change to:"%s"' % (new_weight))
new_line = new_line.replace('-'+old_weight,'-'+new_weight)
# change fullname
if left_part_fullname == x_line[:left_part_fullname_length]:
if not old_weight is None:
new_line = new_line.replace('-'+old_weight,'-'+new_weight)
# chagne weight
if left_part_weight == x_line[:left_part_weight_length]:
new_line = left_part_weight + new_weight + "\n"
if new_weight == "ExtraLight":
new_line = left_part_weight + "Extra-Light\n"
if new_weight == "Semi-Bold":
new_line = left_part_weight + "Semi-Light\n"
if new_weight == "Extra-Bold":
new_line = left_part_weight + "Extra-Bold\n"
# chage ttfweight
if left_part_ttfweight == x_line[:left_part_ttfweight_length]:
if new_weight == "ExtraLight" or new_weight == "Extra-Light":
new_line = left_part_ttfweight + "200\n"
if new_weight == "Light":
new_line = left_part_ttfweight + "300\n"
if new_weight == "Regular":
new_line = left_part_ttfweight + "400\n"
if new_weight == "Medium":
new_line = left_part_ttfweight + "500\n"
if new_weight == "SemiBold" or new_weight == "Semi-Bold":
new_line = left_part_ttfweight + "600\n"
if new_weight == "Bold":
new_line = left_part_ttfweight + "700\n"
if new_weight == "ExtraBold" or new_weight == "Extra-Bold":
new_line = left_part_ttfweight + "800\n"
if new_weight == "Black"or new_weight == "Heavy":
new_line = left_part_ttfweight + "900\n"
# chage version
if left_part_version == x_line[:left_part_version_length]:
new_line = left_part_version + new_version_string + "\n"
# change version in lang
if left_part_lang == x_line[:left_part_lang_length]:
lang_version_string = "Version "
if lang_version_string in x_line:
mychar_array = x_line.split(lang_version_string)
if len(mychar_array) > 0:
new_line = mychar_array[0] + lang_version_string + new_version_string
version_right_part = mychar_array[1]
my_delimitor_symbol = u'"'
if my_delimitor_symbol in version_right_part:
my_delimitor_index = version_right_part.find(my_delimitor_symbol)
my_delimitor_right_part = version_right_part[my_delimitor_index+len(my_delimitor_symbol):]
new_line += my_delimitor_symbol + my_delimitor_right_part
if not old_weight is None:
new_line = new_line.replace('-'+old_weight,'-'+new_weight)
new_line = new_line.replace('"'+old_weight+'"','"'+new_weight+'"')
output_file.write(new_line)
input_file.close()
output_file.close()
remove(file_path)
rename(output_filepath, file_path)
def scan_folders(new_version_string, prefix_string):
# 指定要列出所有檔案的目錄
folders = listdir(".")
folders_count = 0
for item in folders:
if ".sfdir" in item and isdir(item) and prefix_string in item:
folders_count += 1
target_path = join(item,"font.props")
if isfile(target_path):
print("open config:", target_path)
overwrite_config_file(target_path, new_version_string)
print("match folders count:", folders_count)
if __name__ == '__main__':
#prefix_string = "Baku"
import sys
argument_count = 3
if len(sys.argv)==argument_count:
new_version_string = sys.argv[1]
prefix_string = sys.argv[2]
scan_folders(new_version_string, prefix_string)
else:
print("Argument must be: %d" % (argument_count -1))
print("Ex:%s 1.01 FontProjectPreix" % (sys.argv[0]))