-
Notifications
You must be signed in to change notification settings - Fork 38
/
gen-code.py
67 lines (48 loc) · 2.22 KB
/
gen-code.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
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
import os
codePath = "/Users/yanfeiwuji/IdeaProjects/yfwj/temp/keycloak-justauth/src/main/java/io/github/yanfeiwuji/justauth/social"
needTempPath = "/Users/yanfeiwuji/IdeaProjects/yfwj/temp/keycloak-justauth/temp"
codeTempPath = "/Users/yanfeiwuji/IdeaProjects/yfwj/temp/keycloak-justauth/gen-temp/WeChatOpenIdentityProviderFactory.java"
jpath = "/Users/yanfeiwuji/IdeaProjects/yfwj/temp/keycloak-justauth/src/main/java/io/github/yanfeiwuji/justauth/social/common/JustAuthKey.java"
def printO(result):
for r in result:
print("com.yfwj.justauth.social." +
r["c"] + 'IdentityProviderFactory')
def printKicon(result):
for r in result:
print("kcLogoIdP-" +
r["o"] + '=')
def getR():
result = []
with open(jpath) as f:
for line in f.readlines():
if ("\"" in line) and (not ("//" in line)):
print(line)
result.append(
{
"o": line.split("\"")[1],
"c": line.split("\"")[1].title().replace("_", ""),
"j": line.split("(")[0],
"r":line.split(",")[2].split(".")[0]
}
)
return result
def genClass(result):
for r in result:
print(r)
with open(codeTempPath) as temp, open(codePath+"/" + r["c"] + 'IdentityProviderFactory.java', "w", encoding='utf-8') as need:
for line in temp:
new_line = line.replace("${C}", r["c"]).replace("${J}", r["j"]).replace("${R}",r["r"])
need.write(new_line)
def genTemp(result):
need = """<div data-ng-include data-src="resourceUrl + '/partials/realm-identity-provider-social.html'"></div>"""
for r in result:
p = needTempPath + "/realm-identity-provider-" + r['o'] + ".html"
open(p, mode="w+", encoding="utf-8")
with open(needTempPath+"/realm-identity-provider-"+r['o']+".html", mode="w", encoding='utf-8') as t1, open(needTempPath+"/realm-identity-provider-"+r["o"]+"-ext.html", mode="w", encoding='utf-8') as t2:
t1.write(need)
if __name__ == "__main__":
result = getR()
genClass(result)
#genTemp(result)
#printO(result)
printKicon(result)