forked from PhysiCell-Tools/PhysiCell-Jupyter-GUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_my_tool.py
89 lines (75 loc) · 2.56 KB
/
make_my_tool.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import sys
import shutil
import os
import platform
num_args = len(sys.argv)
print('num_args=',num_args)
if (num_args < 2):
# print("Usage: %s <new tool name>")
print("Usage: %s <your repo name>")
sys.exit(1)
gui_name = sys.argv[1]
print('gui_name=',gui_name)
# NOTE: let's not do this now; rather edit the invoke script *on* github to avoid
# the (Windows) problem of making it a non-executable file
#with open('middleware/invoke', 'r') as myfile:
# new_text = myfile.read().replace('tool4nanobio', gui_name)
#with open('middleware/invoke', 'w') as myfile:
# myfile.write(new_text)
#--------------
old_file = os.path.join("bin", 'tool4nanobio.py')
new_file = os.path.join("bin", gui_name + '.py')
try:
shutil.move(old_file, new_file)
print('Renaming ',old_file, ' to ',new_file)
except:
print(" ---> Cannot rename ",old_file," to ",new_file, ", but we will continue")
print('Replacing gui_name in ',new_file)
with open(new_file, 'r') as myfile:
new_text = myfile.read().replace('tool4nanobio', gui_name)
with open(new_file, 'w') as myfile:
myfile.write(new_text)
#--------------
old_file = 'tool4nanobio.ipynb'
new_file = gui_name + '.ipynb'
try:
shutil.move(old_file, new_file)
print('Renaming ',old_file, ' to ',new_file)
except:
print(" ---> Cannot rename ",old_file," to ",new_file, ", but we will continue")
print('Replacing gui_name in ',new_file)
with open(new_file, 'r') as myfile:
new_text = myfile.read().replace('tool4nanobio', gui_name)
with open(new_file, 'w') as myfile:
myfile.write(new_text)
#--------------
"""
In /data:
python xml2jupyter.py PhysiCell_settings.xml
Copy the generated user_params.py to ../bin
"""
print('Trying to run xml2jupyter.py on your .xml file in /data')
os.chdir("data")
cmd = "python xml2jupyter.py PhysiCell_settings.xml"
try:
os.system("python xml2jupyter.py PhysiCell_settings.xml")
except:
print(" ---> Cannot execute: ",cmd)
new_file = os.path.join("..","bin")
try:
shutil.copy("user_params.py", new_file)
except:
print(" ---> Cannot copy data/user_params.py to bin/user_params.py")
print(" You will need to do that manually.\n")
try:
shutil.copy("microenv_params.py", new_file)
except:
print(" ---> Cannot copy data/microenv_params.py to bin/microenv_params.py")
print(" You will need to do that manually.\n")
if platform.system() != 'Windows':
try:
print("Trying to import hublib.ui")
import hublib.ui
except:
print("hublib.ui is not found, will try to install it.")
os.system("pip install -U hublib")