forked from LycheeOrg/LycheeOrg.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen.py
More file actions
75 lines (57 loc) · 1.96 KB
/
Copy pathgen.py
File metadata and controls
75 lines (57 loc) · 1.96 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
#!/usr/bin/env python3
# this script will directly use the version.md from Lychee to determine the current version
from docs.utils.tools import read, save, bcolors
import urllib.request
import pytest
import os
from git import Repo
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(bcolors.YELLOW + 'version number: ' + bcolors.NORMAL + version+'\n')
head = read('template/head.tpl')
index = read('template/index.tpl')
support = read('template/support.tpl')
footer = read('template/footer.tpl')
update = read('template/update.tpl')
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)
save("index.html", index_full)
print(bcolors.GREEN + 'index' + bcolors.NORMAL + " generated.")
save("support.html", support_full)
print(bcolors.GREEN + 'support' + bcolors.NORMAL + " generated.")
save("update.json", update_full)
print(bcolors.GREEN + 'update' + bcolors.NORMAL + " generated.")
print("")
def check():
repo = Repo.init('.')
if repo.is_dirty(): # check the dirty state
for item in repo.index.diff(None):
print(bcolors.RED + item.a_path + " changed." + bcolors.NORMAL)
print("")
print(bcolors.RED + "Please commit them." + bcolors.NORMAL)
return True
else:
print(bcolors.GREEN + "No changes detected." + bcolors.NORMAL)
return False
def test_main():
generate()
assert(not check())
def main():
generate()
check()
if __name__ == '__main__':
main()