-
Notifications
You must be signed in to change notification settings - Fork 0
/
mlabgen-dir-html
executable file
·45 lines (35 loc) · 1.29 KB
/
mlabgen-dir-html
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
#! /usr/bin/python3
import mlabgen
from sys import argv
from os import chdir, listdir
from os.path import join
from string import Template
if ("-h" in argv) or (len(argv) < 4):
print("usage: mlabgen-dir-html [HTML] [DIRINFO] [DIR] [OUT]")
exit()
modules = {}
dirs = {}
ls = listdir(argv[3])
ls.sort()
for item in ls:
try:
if "PrjInfo.txt" in listdir(join(argv[3], item)):
modules[item[:-3]] = mlabgen.prjinfo2dict(join(argv[3], item, "PrjInfo.txt"))
modules[item[:-3]]["Module"] = item
elif "DirInfo.txt" in listdir(join(argv[3], item)):
dirs[item] = mlabgen.prjinfo2dict(join(argv[3], item, "DirInfo.txt"))
dirs[item]["Module"] = item
except NotADirectoryError:
pass
index = ""
if list(dirs.keys()) != []:
for directory in dirs.values():
index += Template(mlabgen.index_dirs_line).safe_substitute(directory)
if (list(dirs.keys()) != []) and (list(modules.keys()) != []):
index += mlabgen.index_line_sep
if list(modules.keys()) != []:
for module in modules.values():
index += Template(mlabgen.index_modules_line).safe_substitute(module)
dirinfo = mlabgen.prjinfo2dict(argv[2])
dirinfo.update({"Index": index})
open(argv[4], "w").write(Template(open(argv[1], "r").read()).safe_substitute(dirinfo))