-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmklib-list.py
More file actions
executable file
·67 lines (47 loc) · 1.53 KB
/
Copy pathmklib-list.py
File metadata and controls
executable file
·67 lines (47 loc) · 1.53 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
#!/usr/bin/env python3
import os
import sys
def getHelp():
print("""\
mklib-list BASEPATH [-L|-l]
Create BASEPATH/libraries.md, containing list and links of libraries in subdirectories.
Arguments:
BASEPATH path containing libraries, where libraries.md will be created
-L search libraries directories in any BASEPATH/lib_SUBDIR/LIBDIR,
where libraries dirs are divided in subdirectories of BASEPATH
-l search libraries directories in BASEPATH;
-L, -l are alternatives, -L is default
""")
raise Exception("wrong parameters")
def hasReadme(prnt, dr):
return os.path.exists(prnt + '/' + dr + '/README.md')
def addLibs(f, base, libs, subdir=False):
path = base + '/' + libs
for lb in os.listdir(path):
if hasReadme(path, lb):
if subdir:
f.write(f"* [{lb}]({libspath}/{lb}/README.md) \n")
else:
f.write(f"* [{lb}]({lb}/README.md) \n")
LIBS_SUBDIR_START = "lib_"
args = sys.argv
if len(args) == 1:
getHelp()
basepath = args[1]
if len(args) == 2:
args.append('-L')
# create libraries.md
print(basepath + '/' + 'libraries.md')
with open(basepath + '/' + 'libraries.md', "w") as md:
md.write("# LIBRARIES\n\n")
libspath = basepath
# with subdirs categories
if args[2] == '-L':
libsdirs = list(filter(lambda s: s.startswith(LIBS_SUBDIR_START), os.listdir(basepath)))
libsdirs.sort()
for libspath in libsdirs:
md.write(f"## {libspath[len(LIBS_SUBDIR_START):]} \n")
addLibs(md, basepath, libspath, subdir=True)
# without subdirs categories
else:
addLibs(md, libspath, libspath)