-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmklib.py
More file actions
executable file
·88 lines (67 loc) · 1.52 KB
/
Copy pathmklib.py
File metadata and controls
executable file
·88 lines (67 loc) · 1.52 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python3
import os
import sys
def getHelp():
print("""\
mklib BASEPATH [-L SUBDIR] NAME [-D|-d] [-f FILENAMES...]
Create BASEPATH/[lib_SUBDIR/]NAME/, containing, optionally, default and/or files.
Arguments:
BASEPATH library's language path
-L SUBDIR create library (NAME) in subdir (lib_SUBDIR) of language (BASEPATH)
-d don't create default files
-D (default) create default files
-f FILENAMES... create specified files in library dir
""")
raise Exception("wrong parameters")
def removeExtension(f:str):
return f[:f.rfind('.')] if '.' in f else f
SUBDIR_START = "lib_"
BASEPATH, SUBDIR, NAME = [""] * 3
FILENAMES = [
'basics.md',
'objects.md'
]
args = sys.argv
try:
i = 1
BASEPATH = args[i]
i += 1
if args[i] == '-L':
SUBDIR = SUBDIR_START + args[i+1]
i += 2
if args[i][0] == '-':
getHelp()
NAME = args[i]
i += 1
if i < len(args):
if args[i] == '-d':
FILENAMES.clear()
i += 1
elif args[i] == '-D':
i += 1
if i < len(args) and args[i] == '-f':
FILENAMES.extend(args[i+1:])
except:
getHelp()
PATH = BASEPATH
FILENAMES.extend([
'README.md'
])
# create SUBDIR
if len(SUBDIR) > 0:
PATH += '/' + SUBDIR
if not os.path.exists(PATH):
os.mkdir(PATH)
# create NAME
PATH += '/' + NAME
if not os.path.exists(PATH):
os.mkdir(PATH)
for filename in FILENAMES:
p = PATH + '/' + filename
if not os.path.exists(p):
f = open(p, 'w')
if filename == 'README.md':
f.write(f"# {PATH.upper()}\n")
else:
f.write(f"# {removeExtension(filename).upper()}\n")
f.close()