-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathREADME.py
113 lines (99 loc) · 3.07 KB
/
README.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
import os
from pathlib import Path
from typing import List
readmeFile = Path("README.md")
orig = readmeFile.read_text()
ctx = str(orig)
finishedC = "✓"
noneC = "X"
# unsupportedC = ":question:"
impossibleC = "-"
def getMediaList() -> List[str]:
actual = []
for folder in os.listdir(Path.cwd()):
# if not start with . and is a directory
if not folder.startswith('.') and os.path.isdir(folder):
actual.append(folder)
actual.sort()
return actual
def getLanguageList(folder) -> List[str]:
langs = []
for file in os.listdir(folder):
if os.path.isdir(folder + '/' + file):
langs.append(file)
return langs
def getMatrix(folders: List[str]) -> dict:
matrix = {
'Media': folders,
}
language = set()
# discover all languages
for folder in folders:
langs = getLanguageList(folder)
language.update(langs)
language = list(language)
language.sort()
for lang in language:
matrix[lang] = []
for folder in folders:
if lang in getLanguageList(folder):
# if lang folder contain IMPOSSIBLE.txt
impossibleTxt = folder + '/' + lang + '/IMPOSSIBLE.txt'
if os.path.exists(impossibleTxt):#enable hyperlink
matrix[lang].append("[ " + impossibleC + " ]("+impossibleTxt+")")
else:
matrix[lang].append(finishedC)
else:
matrix[lang].append(noneC)
return matrix
def buildTable(matrix: dict) -> str:
colsWidth = {}
for col in matrix:
length = 0
for row in matrix[col]:
length = max(length, len(row))
# length = length + 2 # add 2 for the border at start and end
colsWidth[col] = length
# print head
tableMatrix = "|"
for col, width in colsWidth.items():
tableMatrix += " " + col + " " * (width - len(col)) + " |"
tableMatrix += "\n"
# print border
tableMatrix += "|"
for col, width in colsWidth.items():
width = width + 2
tableMatrix += "-" * width + "|"
tableMatrix += "\n"
# print body
rows = 0
for i in range(len(matrix['Media'])):
tableMatrix += "|"
for col, width in colsWidth.items():
tableMatrix += " " + matrix[col][i] + " " * (width - len(matrix[col][i])) + " |"
tableMatrix += "\n"
rows += 1
return tableMatrix
mat = getMatrix(getMediaList())
table = buildTable(mat)
ctx = ctx.split("<GENERATED>\n") # this is retarded
ctx[1] = table + "\n" + "</GENERATED>"
ctx = "<GENERATED>\n\n".join(ctx)
if ctx != orig:
readmeFile.write_text(ctx, 'utf-8')
print('TABLE GENERATED')
else:
print("TABLE UP TO DATE")
exit(0)
try:
if os.getlogin() != "runner":
print("Not runner, skipping git commit")
exit(0)
except:
pass
os.system("git config --global user.email volas@mindustry.me")
os.system("git config --global user.name Volas Updater")
os.system('git add README.md')
os.system('git commit -m "Volas Bot"')
os.system('git push')
print("Great Success!")