-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup_libroadrunner.py
149 lines (129 loc) · 4.73 KB
/
setup_libroadrunner.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# This script attempts to download the libRoadrunner (binary) libraries and
# headers for your particular operating system. It puts them in a directory
# of your choosing (default = your home dir) and sets an environment variable
# to that location which can then be used by a PhysiCell Makefile.
#
# Author: Randy Heiland
import platform
import urllib.request
import os
import sys
import tarfile
import zipfile
os_type = platform.system()
print('operating system = ',os_type)
# Assume Windows
rr_file = ""
url = ""
if os_type.lower() == 'darwin':
rr_file = "roadrunner-osx-10.9-cp36m.tar.gz"
url = "https://sourceforge.net/projects/libroadrunner/files/libroadrunner-1.4.18/" + rr_file + "/download"
elif os_type.lower().startswith("win"):
rr_file = "roadrunner-win64-vs14-cp35m.zip"
url = "https://sourceforge.net/projects/libroadrunner/files/libroadrunner-1.4.18/" + rr_file + "/download"
elif os_type.lower().startswith("linux"):
rr_file = "cpplibroadrunner-1.3.0-linux_x86_64.tar.gz"
url = "https://sourceforge.net/projects/libroadrunner/files/libroadrunner-1.3/" + rr_file + "/download"
else:
print("Your operating system seems to be unsupported. Please submit a ticket at https://sourceforge.net/p/physicell/tickets/ ")
sys.exit(1)
fname = url.split('/')[-2]
home = os.path.expanduser("~")
print('libRoadRunner will now be installed into this location:')
dir_name = os.path.join(home, 'libroadrunner')
print(dir_name + '\n')
print(' - Press ENTER to confirm the location')
print(' - Press CTL-C to abort the installation')
print(' - Or specify a different location below\n')
prompt_str = '[' + dir_name + '] >>> '
try:
response = input(prompt_str)
if (response == ""):
print('got Enter')
if not os.path.exists(dir_name):
try:
os.makedirs(dir_name)
except:
print('Error trying to create directory: ',dir_name)
exit(1)
else:
print(type(response))
dir_name = os.path.expanduser(response)
if not os.path.exists(dir_name):
try:
os.makedirs(dir_name)
except:
print('Error trying to create directory: ',dir_name)
exit(1)
except:
print(' installation canceled\n')
exit(1)
print('Beginning download of libroadrunner into ' + dir_name + ' ...')
print(url)
my_file = os.path.join(dir_name, fname)
print('my_file = ',my_file)
if os_type.lower().startswith("win"):
rrlib_dir = my_file[:-4]
else: # darwin or linux
rrlib_dir = my_file[:-7]
print('rrlib_dir = ',rrlib_dir)
def download_cb(blocknum, blocksize, totalsize):
readsofar = blocknum * blocksize
if totalsize > 0:
percent = readsofar * 1e2 / totalsize
s = "\r%5.1f%% %*d / %d" % (
percent, len(str(totalsize)), readsofar, totalsize)
sys.stderr.write(s)
if readsofar >= totalsize: # near the end
sys.stderr.write("\n")
else: # total size is unknown
sys.stderr.write("read %d\n" % (readsofar,))
try:
urllib.request.urlretrieve(url, my_file, download_cb)
except Exception:
print('------- got a urllib exception')
# print str(e)
traceback.print_exc()
os.chdir(dir_name)
print('installing (uncompressing) the file...')
if os_type.lower().startswith("win"):
try:
with zipfile.ZipFile(rr_file) as zf:
zf.extractall('.')
except:
print('error unzipping the file')
exit(1)
else: # Darwin or Linux
try:
tar = tarfile.open(rr_file)
tar.extractall()
tar.close()
except:
print('error untarring the file')
exit(1)
print('Done.\n')
# LIBRR_DIR := /Users/heiland/libroadrunner/roadrunner-osx-10.9-cp36m
#----------------------------------
print("Do the following 2 steps:")
print("1) Replace the following variables in your PhysiCell Makefile with these:\n")
#print("LIBRR_DIR := /Users/heiland/libroadrunner/roadrunner-osx-10.9-cp36m")
print("LIBRR_DIR := " + rrlib_dir)
#if os_type == 'Windows':
if os_type.lower().startswith("win"):
print("LIBRR_LIBS := " + rrlib_dir + "/bin\n")
else:
print("LIBRR_LIBS := " + rrlib_dir + "/lib\n")
win_lib_path = rrlib_dir + "/bin"
unix_lib_path = rrlib_dir + "/lib"
print()
more_info = ("2) follow instructions for your particular operating system to permanently\n"
"append this path to the appropriate environment variable. e.g.,")
print(more_info)
if os_type.lower().startswith("win"):
print("add " + win_lib_path + " to your PATH env variable.")
else:
unix_info = ("macOS:\n"
"export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:" + unix_lib_path + "\n\n"
"Linux:\n"
"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:" + unix_lib_path + "\n")
print(unix_info)