-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
66 lines (45 loc) · 2.06 KB
/
build.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
import json
import os
import argparse
if __name__=='__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-template_file', action='store',
dest='template',
help='template file with file structure', type=str, default='template.json')
parser.add_argument('-dir', action='store',
dest='directory',
help=' where create the structure', type=str, required=True)
parser.add_argument('-hiddenfile', action='store',
dest='hiddenfile',
help='if you want to have hidden file to save folder in git', type=bool, default=True)
args = parser.parse_args()
template_file = args.template
directory= args.directory
hidden=args.hiddenfile
with open(template_file) as f:
data = json.load(f)
for main_directory in data['main_directories']:
if "@" in main_directory:
main_directory = main_directory.split('@')[1]
os.mkdir(os.path.join(directory,main_directory))
open(os.path.join(directory,main_directory,'__init__.py'), 'w').close()
else:
os.mkdir(os.path.join(directory, main_directory))
if hidden:
open(os.path.join(directory, main_directory, '.4git'), 'w').close()
for sub_directory in data['sub_directories']:
father = sub_directory['father']
for dir in sub_directory['dirs']:
if '*' in dir:
suffix,num = dir.split('*')
l_dir = []
for n in range(0, int(data[num]), 1):
l_dir.append(data[suffix]+str(n))
for item in l_dir:
os.mkdir(os.path.join(directory,father,item))
if hidden:
open(os.path.join(directory,father,item,'.4git'), 'w').close()
else:
os.mkdir(os.path.join(directory,father,dir))
if hidden:
open(os.path.join(directory, father, item, '.4git'), 'w').close()