-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
48 lines (40 loc) · 1.84 KB
/
Copy pathsetup.py
File metadata and controls
48 lines (40 loc) · 1.84 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
import yaml
import sys
import os
setup = os.path.abspath(os.path.dirname(os.path.realpath(__file__))+'/config_files')
def YN(q1,q2,default):
choice = input(f'{q1} {default} ')
if choice.lower()=='y':
return (default)
else:
return(input(f'{q2} '))
def run(wd):
print(setup)
with open(f'{setup}/user_path_definitions_template.yml') as yml:
config = yaml.safe_load(yml)
print('Verify paths for setup or specify custom locations')
for key,value in config['rootDir'].items():
value = os.path.abspath(value)
value = YN(f'Y/N Path to {key}:',f'Specify alternative location for {key}: ',value)
config["rootDir"][key] = value
for key,value in config['relDir'].items():
value = os.path.abspath(f'{wd}/{value}')
value = YN(f'Y/N Path to {key}:',f'Specify alternative location for {key}: ',value)
if os.path.isdir(value) == False:
os.makedirs(value)
config["rootDir"][key] = value
config.pop('relDir')
if os.path.isdir(f'{wd}/config_files') == False:
os.makedirs(f'{wd}/config_files')
if os.path.isdir(f'{wd}/config_files/user_defined') == False:
os.makedirs(f'{wd}/config_files/user_defined')
with open(f'{wd}/config_files/user_defined/user_path_definitions.yml', 'w') as outfile:
yaml.dump(config, outfile, default_flow_style=False)
if os.path.isfile(f'{wd}/.gitmodules'):
with open('.gitmodules') as f:
for l in f.readlines():
if 'path = ' in l:
l = l.split('path = ')[1].replace('\n','')
if os.path.isdir(f"{wd}/{l}/config_files"):
with open(f"{wd}/{l}/config_files/user_defined/user_path_definitions.yml", 'w') as outfile:
yaml.dump(config, outfile, default_flow_style=False)