-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjects.py
64 lines (61 loc) · 2.22 KB
/
Projects.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
63
64
#!/usr/bin/env python3
import argparse
import fileinput
import os
import subprocess
import time
parser=argparse.ArgumentParser(description='Take in project name to switch or create.')
parser.add_argument('project_name', type=str, help='name of project')
args= parser.parse_args()
project_name=args.project_name
parent_dir = "./projects"
path = os.path.join(parent_dir, project_name)
make_file_name="Makefile"
make_path=os.path.join(path,make_file_name)
cpp_file=project_name+".cpp"
h_file=project_name+".h"
cpp_path=os.path.join(path,cpp_file)
h_path=os.path.join(path,h_file)
main_file="main-test.cpp"
main_path=os.path.join(path,main_file)
config_file="PhysiCell_settings.xml"
config_path=os.path.join(path,config_file)
if os.path.exists(path):
switch_answer=input(f'switch project to {project_name}? ([y]es/[n]o')
if switch_answer!= 'y' or 'yes' or 'Yes' or 'YES':
exit()
#switch to this project and set everything up
# back up current
os.popen(f'make zip')
print("saving current files in archives")
os.popen(f'cp -R {path}/* ./')
#os.popen(f'cp {make_path} ./')
#os.popen(f'cp {cpp_path} ./custom_modules/')
#os.popen(f'cp {h_path} ./custom_modules/')
#os.popen(f'cp {main_path} ./')
#os.popen(f'cp {config_path} ./config/')
else:
#optionally create project
print(f'create new project named {project_name} ?')
answer=input('[y]es/[n]o ?')
if answer== 'y' or 'yes' or 'Yes':
if os.path.exists(parent_dir)!=True:
os.mkdir(parent_dir)
os.mkdir(path)
# create the template files
os.popen(f'make zip')
print("saving current files in archives")
os.popen(f'cp -R ./sample_projects/template/* {path}')
os.popen(f'cp ./Makefile_template {path}')
print(f'{path}/Makefile_template')
os.popen(f'mv -f {path}/Makefile_template {path}/Makefile')
print(make_path)
#eventually copy all these from template directory
time.sleep(2)
with fileinput.FileInput(files=make_path,inplace=True,backup='.bak') as file:
for line in file:
print(line.replace("joes_project", project_name), end='')
#cp from ./project/templates
# etc
else:
exit()