generated from Valheim-Modding/JotunnModStub
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_config_docs.py
executable file
·74 lines (58 loc) · 1.94 KB
/
generate_config_docs.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
#!/usr/bin/env python3
import re
import os
import fnmatch
import json
def main():
parsed = parse_config_file(
'/home/joshua/.config/r2modmanPlus-local/Valheim/profiles/cheb-development/BepInEx/config/com.chebgonaz.chebsmythicalweapons.cfg')
print(render_markdown(parsed))
def parse_config_file(filepath):
result = {}
with open(filepath, 'r') as file:
contents = file.readlines()
contents = [x.strip() for x in contents]
current_key = None
for line in contents:
if len(line) < 1:
continue
#print(f'line={line}')
if line[0] == '[' and line[-1] == ']':
current_key = line[1:-1]
if current_key is not None and current_key not in result:
result[current_key] = []
continue
if current_key is not None:
bah = result[current_key]
bah.append(line)
result[current_key] = bah
sigh = {}
for key in result:
sigh[key] = []
lines = result[key]
subdict = {}
comments = []
for line in lines:
if line[0] == "#":
comments.append(line)
else:
subdict[line] = comments
comments = []
sigh[key].append(subdict)
return sigh
def render_markdown(data):
markdown = """# Configs\n\n"""
for key in data.keys():
markdown += f"## {key}\n\n"
table_data = data[key][0]
markdown += "| Setting | Description | Type | Default Value |\n"
markdown += "| ------- | ----------- | ---- | ------------- |\n"
try:
for setting, info in table_data.items():
markdown += f"| `{setting.split(' ')[0]}` | {info[0][3:]} | `{info[1][2:]}` | `{info[2][2:]}` |\n"
except:
pass
markdown += "\n"
return markdown
if __name__ == '__main__':
main()