-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
62 lines (47 loc) · 2.05 KB
/
setup.py
File metadata and controls
62 lines (47 loc) · 2.05 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
import os
import sys
from collections import defaultdict
import json
class setup_maker(object):
def __init__(self,json_path):
self.json_path = json_path
def folder_setup(self,project_name,project_path,json_template):
json_file_path = os.path.join(self.json_path,json_template)
with open('{}'.format(json_file_path)) as template_file:
template = json.load(template_file)
type(template)
project_path = os.path.join(project_path,project_name)
self.makedir(project_path)
container = [x for x in template][0]
self.recursive_foldering(project_path, template[container])
def recursive_foldering(self, project_path, container):
try:
for (i,i_group) in enumerate(container):
#print(i,i_group)
subfolder_id = container[i]
for (parent_dir, children_dirs) in subfolder_id.items():
subfolder = os.path.join(project_path,parent_dir)
self.makedir(subfolder)
print(subfolder)
for (j,j_group) in enumerate(children_dirs):
child_folder_id = children_dirs[j]
for (x_folder, dummy) in child_folder_id.items():
mod_path = os.path.join(subfolder,x_folder)
print(mod_path)
self.makedir(mod_path)
#print(new_path)
self.recursive_foldering(mod_path,child_folder_id[x_folder])
except:
pass
def makedir(self,folder_name):
try:
os.makedirs(folder_name, exist_ok=True)
except OSError as exc:
if exc.errno != errno.EEXIST:
raise
pass
#os.rmdir('/home/kg/Documents/MIKE')
#cur_dir = os.path.dirname(__file__)
#cur_path = os.path.join(cur_dir,'JSON/3D-Short')
#setup = setup_maker(cur_path)
#setup.folder_setup('PINATA','/Users/patagu/Documents/','Pinata.json')