forked from LycheeOrg/LycheeOrg.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen.py
136 lines (102 loc) · 3.81 KB
/
gen.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
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
#!/usr/bin/env python3
# this script will directly use the version.md from Lychee to determine the current version
import urllib.request
import pytest
def numberify_version(v):
v = v.split('.')
if len(v[1]) < 2:
v[1] = '0'+v[1]
if len(v[2]) < 2:
v[2] = '0'+v[2]
return "".join(v)
def generate():
version = urllib.request.urlopen(
"https://raw.githubusercontent.com/LycheeOrg/Lychee/master/version.md").read().decode("utf-8")
version = version.strip()
print('version number: ' + version+'\n')
with open('template/head.tpl', 'r', encoding="utf-8") as file:
head = file.read()
with open('template/index.tpl', 'r', encoding="utf-8") as file:
index = file.read()
with open('template/support.tpl', 'r', encoding="utf-8") as file:
support = file.read()
with open('template/footer.tpl', 'r', encoding="utf-8") as file:
footer = file.read()
with open('template/update.tpl', 'r', encoding="utf-8") as file:
update = file.read()
index_full = head % version
index_full += index % version
index_full += footer
support_full = head % version
support_full += support % version
support_full += footer
update_full = update % numberify_version(version)
return index_full, support_full, update_full
with open("index.html", 'w', encoding="utf-8") as out:
out.write(index_full)
print("regenerated index.html")
with open("support.html", 'w', encoding="utf-8") as out:
out.write(support_full)
print("regenerated support.html")
with open("update.json", 'w', encoding="utf-8") as out:
out.write(update_full)
print("regenerated update.json")
print("")
changes = False
if index_full != old_index:
print("No changes in index.html")
changes = True
if support_full != old_support:
print("No changes in support.html")
changes = True
if update_full != old_update:
print("No changes in update.json")
changes = True
if changes:
print("")
print("[index/support/update] changed. Please commit them.")
else:
print("\tNo changes detected.")
def check(index_full, support_full, update_full):
with open('index.html', 'r', encoding="utf-8") as file:
old_index = file.read()
with open('support.html', 'r', encoding="utf-8") as file:
old_support = file.read()
with open('update.json', 'r', encoding="utf-8") as file:
old_update = file.read()
changes = False
if index_full != old_index:
changes = True
if support_full != old_support:
changes = True
if update_full != old_update:
changes = True
return changes
def test_main():
index_full, support_full, update_full = generate()
assert(not check(index_full, support_full, update_full))
def main():
with open('index.html', 'r', encoding="utf-8") as file:
old_index = file.read()
with open('support.html', 'r', encoding="utf-8") as file:
old_support = file.read()
with open('update.json', 'r', encoding="utf-8") as file:
old_update = file.read()
index_full, support_full, update_full = generate()
changes = check(index_full, support_full, update_full)
with open("index.html", 'w', encoding="utf-8") as out:
out.write(index_full)
print("regenerated index.html")
with open("support.html", 'w', encoding="utf-8") as out:
out.write(support_full)
print("regenerated support.html")
with open("update.json", 'w', encoding="utf-8") as out:
out.write(update_full)
print("regenerated update.json")
print("")
if changes:
print("[index/support/update] changed. Please commit them.")
else:
print("No changes detected.")
if __name__ == '__main__':
main()