-
Notifications
You must be signed in to change notification settings - Fork 8
/
mafInstallFoundation.py
235 lines (196 loc) · 7.74 KB
/
mafInstallFoundation.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#script for build on different platforms with different compilers maf.
#Using this prevent from using cmake. (support compilers are gcc on linux and mac, mingw and visual studio 2008 in windows)
import os, sys
import getopt
import shutil
import httplib, urlparse, string
import platform
import urllib2
from base64 import encodestring, decodestring
currentPathScript = os.path.abspath(os.path.split(os.path.realpath(__file__))[0])
param = {}
paramError = {}
bt_home = "http://www.biomedtown.org"
def errhandler():
print "Unrecognized compiler"
def createFoundationDirectories():
try:
foundationDir = param['foundation-output-dir']
except:
param['foundation-output-dir'] = os.path.join(currentPathScript, ".." , "MAF3_Foundation_Libs")
foundationDir = param['foundation-output-dir']
if not os.path.exists(foundationDir):
os.makedirs(foundationDir)
pass
def download64BitLinux():
print "64 bit Linux Foundation libraries"
library = '/biomed_town/MAF/MAF3%20Floor/download/foundation_libraries/Linux_i386/foundation_linux_64'
url = bt_home + library
localFileName = 'MAF_Foundation_Libs.tar.gz'
downloadFromLink(url, localFileName)
pass
def download32BitLinux():
print "32 bit Linux Foundation libraries"
library = '/biomed_town/MAF/MAF3%20Floor/download/foundation_libraries/Linux_i386/foundation_libs'
url = bt_home + library
localFileName = 'MAF_Foundation_Libs.tar.gz'
downloadFromLink(url, localFileName)
pass
def download64BitMacOSX():
print "64 bit MacOSX Foundation libraries"
library = '/biomed_town/MAF/MAF3%20Floor/download/foundation_libraries/macosx/foundation_libs_snowleopard'
url = bt_home + library
localFileName = 'MAF_Foundation_Libs.tar.gz'
downloadFromLink(url, localFileName)
pass
def download32BitMacOSX():
print "32 bit MacOSX Foundation libraries"
library = '/biomed_town/MAF/MAF3%20Floor/download/foundation_libraries/macosx/foundation_libs'
url = bt_home + library
localFileName = 'MAF_Foundation_Libs.tar.gz'
downloadFromLink(url, localFileName)
pass
def download32BitWin32VS2008():
print "32 bit Windows Foundation libraries for Visual Studio 2008"
library = '/biomed_town/MAF/MAF3%20Floor/download/foundation_libraries/Win32/MAF3_Foundation_Libs.zip'
url = bt_home + library
localFileName = 'MAF_Foundation_Libs.zip'
downloadFromLink(url, localFileName)
pass
def download32BitWin32Mingw():
print "32 bit Windows Foundation libraries for Mingw"
library = '/biomed_town/MAF/MAF3%20Floor/download/foundation_libraries/Win32/foundation_libs'
url = bt_home + library
localFileName = 'MAF_Foundation_Libs.zip'
downloadFromLink(url, localFileName)
pass
def chunk_report(bytes_so_far, chunk_size, total_size):
percent = float(bytes_so_far) / total_size
percent = round(percent*100, 2)
sys.stdout.write("Downloaded %d of %d bytes (%0.2f%%)\r" %
(bytes_so_far, total_size, percent))
if bytes_so_far >= total_size:
sys.stdout.write('\n')
def chunk_read(response, chunk_size=8192, report_hook=None):
total_size = response.info().getheader('Content-Length').strip()
total_size = int(total_size)
bytes_so_far = 0
total = ""
while 1:
chunk = response.read(chunk_size)
total += chunk
bytes_so_far += len(chunk)
if not chunk:
break
if report_hook:
report_hook(bytes_so_far, chunk_size, total_size)
return total
def downloadFromLink(url, localFileName):
response = urllib2.urlopen(url);
data = chunk_read(response, report_hook=chunk_report)
f = open(os.path.join(param['foundation-output-dir'],localFileName), 'wb')
f.write(data)
f.close()
def errhandler():
print "Unrecognized system."
def downloadFromBiomedtown():
platformOS = {
"64bit-linux2": download64BitLinux,
"32bit-linux2": download32BitLinux,
"64bit-darwin": download64BitMacOSX,
"32bit-darwin": download32BitMacOSX,
"64bit-linux2-gcc4": download64BitLinux,
"32bit-linux2-gcc4": download32BitLinux,
"64bit-darwin-gcc4": download64BitMacOSX,
"32bit-darwin-gcc4": download32BitMacOSX,
#"64bit-win32" : download64BitWin32,
"32bit-win32" : download32BitWin32VS2008,
"32bit-win32-vs2008" : download32BitWin32VS2008,
"32bit-win32-mingw" : download32BitWin32Mingw,
}
#construct variable
value = platform.architecture()[0] + "-" + str(os.sys.platform).lower()
key = 'compiler'
if(key in param):
value = value + "-" + param[key]
print "Detected System..." + value
try:
print "Download in Progress..."
platformOS.get(value,errhandler)()
print "Download Completed"
except Exception, e:
print "Error trying to launch the download from biomedtown..." , e
def createEnvironmentVariables():
print "Create Environment variables..."
pass
def gitDownloadFromCTKRepository():
print "Download from CTK repository..."
mafRootDir = currentPathScript
eventBusDir = os.path.join(mafRootDir, "org.commontk.eventbus")
ctkRepository = "git://github.com/dgiunchi/CTK.git"
ctkLocalDir = os.path.join(param['foundation-output-dir'], "CTK")
gitExecutable = os.path.join(param['git-path'], "git")
command = ""
if not os.path.exists(ctkLocalDir):
#clone
command = gitExecutable + " clone " + ctkRepository + " " + ctkLocalDir
else:
#pull
os.chdir(ctkLocalDir)
command = gitExecutable + " pull"
os.system(command)
os.chdir(currentPathScript)
def extractFromLocalCTK():
print "Extract module from CTK..."
mafRootDir = currentPathScript
mafEventBusDir = os.path.join(mafRootDir, "ctkEventBus")
ctkLocalDir = os.path.join(param['foundation-output-dir'], "CTK")
ctkEventBus = os.path.join(ctkLocalDir, "Plugins", "org.commontk.eventbus", "mafEventBus")
if os.path.exists(mafEventBusDir):
shutil.rmtree(mafEventBusDir)
shutil.copytree(ctkEventBus, mafEventBusDir)
def install():
createFoundationDirectories()
downloadFromBiomedtown()
createEnvironmentVariables()
gitDownloadFromCTKRepository()
extractFromLocalCTK()
def usage():
print "python mafBuild.py [-h] [-f foundation-output-dir] [-g git-path]"
print "-h, --help show help (this)"
print "-f, --foundation-output-dir select where set foundation library"
print "-c, --compiler= select the compiler (used only if process is code)"
print "-g, --git-path set directory of git"
print
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "hf:g:", ["help", "foundation-output-dir=", "compiler=", "git-path="])
except getopt.GetoptError, err:
# print help information and exit:
print str(err) # will print something like "option -a not recognized"
usage()
sys.exit(2)
for o, a in opts:
if o in ("-h", "--help"):
usage()
sys.exit()
elif o in ("-c", "--compiler"):
acceptance = ["vs2008","mingw","gcc4"]
if(a in acceptance):
param['compiler'] = a
else:
paramError['compiler'] = a
elif o in ("-f", "--foundation-output-dir"):
param['foundation-output-dir'] = os.path.abspath(os.path.normpath(a))
elif o in ("-g", "--git-path"):
param['git-path'] = os.path.abspath(os.path.normpath(a))
else:
assert False, "unhandled option"
if(len(paramError) != 0 ):
for k, v in paramError.iteritems():
print v, " is not a valid " , k
usage()
exit()
install()
if __name__ == "__main__":
main()