-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto_create_objcet_maper_code.py
More file actions
72 lines (50 loc) · 1.71 KB
/
auto_create_objcet_maper_code.py
File metadata and controls
72 lines (50 loc) · 1.71 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
import os
import re
import argparse
strong_type = ['copy', 'strong', 'retain']
def codeCreate(hPath):
data = open(hPath, "r", encoding="utf-8", errors="ignore")
each = data.readline()
my_property = list()
whole_string_list = []
insertIndex = 0
count = 0
while each:
whole_string_list.append(each)
if each.find("var") != -1:
clean_each = each.strip("\n")
start = clean_each.index("var")
end = clean_each.index(":")
clean_each = clean_each[start+3:end]
clean_each = clean_each.strip()
my_property.append(clean_each)
insertIndex = count + 1
each = data.readline()
count += 1
factory_string = "\n"
factory_string += "\trequired init?(map: Map) {\n\n\t}\n\n"
factory_string += "\tfunc mapping(map: Map) {\n"
for index in range(len(my_property)):
each = my_property[index]
pre = "\t\t" + each
if len(pre) < 14:
for index in range(14 - len(pre)):
pre += " "
factory_string += pre
factory_string += '<- map["%s"]\n' %(each)
factory_string += "\t}\n"
whole_string_list.insert(insertIndex, factory_string)
whole_string = "".join(whole_string_list)
with open(hPath, 'w', encoding='utf-8', errors='ignore') as f:
f.write(whole_string)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-path", "--path", help=".h的全路径", metavar="path")
options = parser.parse_args()
hPath = ""
hPath = options.path
if hPath:
codeCreate(hPath)
print("Done")
else:
print(".h路径为空 使用 -path带上路径")