-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
71 lines (46 loc) · 1.5 KB
/
main.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
import yaml
import os
BASE_PATH = "./"
def define_env(env):
@env.macro
def generateTemplateImgNameList():
with open(BASE_PATH + "mkdocs.yml") as stream:
splitConf = stream.read().split("nav:")
navConfig = "nav:\n" + splitConf[1]
try:
navYaml = yaml.safe_load(navConfig)["nav"][1:]
pageNameList = generatePageNameList(navYaml)
imgNameList = generateImgNameList(pageNameList)
return imgNameList
except yaml.YAMLError as exc:
print(exc)
def generatePageNameList(navYaml):
pageNameList = {}
for gadgetLinks in navYaml:
key, val = list(gadgetLinks.items())[0]
name = key
page = ""
for link in val:
dirName = link.split('/')[0]
if dirName in getGadgetDirs():
page = dirName
break
pageNameList[page] = name
return pageNameList
def getGadgetDirs():
projectDirs = []
for root, dirs, files in os.walk(BASE_PATH + 'gadgets'):
projectDirs = dirs
break
blacklist = ['assets', 'usbPad']
filtered = []
for dir in projectDirs:
if dir not in blacklist:
filtered.append(dir)
return filtered
def generateImgNameList(pageNameList):
imgNameList = []
for page, name in pageNameList.items():
imgPath = page + "/assets/default.png"
imgNameList.append((imgPath, name, page))
return imgNameList