-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathelcapitan-setup.py
319 lines (251 loc) · 7.43 KB
/
elcapitan-setup.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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#!/usr/bin/env python
# contains ~*~ magic ~*~ installation code.
import os, sys, time
C4_FINDAPR_PATH = "./lib/c4/cmake/FindApr.cmake"
SETUP_DEBUG = True
DEBUG = True
#################
# GETAPR_LIST #
#################
def getAPR_list() :
cmd = 'find / -name "apr_file_io.h" | grep -v "Permission denied" > out.txt'
print "Finding Apache Runtime library using command: " + cmd
time.sleep(5) # message to user
os.system( cmd )
fo = open( "out.txt", "r" )
pathList = []
for path in fo :
path = path.strip()
path_split = path.split( "/" )
path_split = path_split[:len(path_split)-1]
path = "/".join( path_split )
pathList.append( path )
os.system( 'rm out.txt' )
return pathList
##########################
# SET PYLDFI VIZ PATHS #
##########################
# set the p5.js and p5.dom.js paths in pyLDFIviz.html
def set_PYLDFI_VIZ_paths() :
p5_paths = getP5_paths()
p5dom_paths = getP5dom_paths()
if DEBUG :
print "ALL p5.js paths :"
print p5_paths
print "ALL p5.dom.js paths :"
print p5dom_paths
chosen_p5 = None
chosen_p5dom = None
# pick a p5.js path
for path in p5_paths :
if "/lib/p5.js" in path :
chosen_p5 = path
# pick a p5.dom.js path
for path in p5dom_paths :
if "/addons/p5.dom.js" in path and not "test/unit" in path :
chosen_p5dom = path
# sanity checks
if not chosen_p5 :
sys.exit( ">>> FATAL ERROR : could not find valid p5.js path. Aborting..." )
if not chosen_p5dom :
sys.exit( ">>> FATAL ERROR : could not find valid p5.dom.js path. Aborting..." )
if DEBUG :
print "chosen_p5 = " + chosen_p5
print "chosen_p5dom = " + chosen_p5dom
# make custom pyLDFIviz.html file
html_tag = "<html>\n"
head_tag = " <head>\n"
p5_line = ' <script language="javascript" type="text/javascript" src="' + chosen_p5 + '"></script>\n'
p5dom_line = ' <script language="javascript" src="' + chosen_p5dom + '"></script>\n'
uiFile = "./src/ui/pyLDFIviz.html"
tempFile = "./src/templateFiles/pyLDFIviz_temp.html"
f = open( uiFile, "w" )
f.write( html_tag )
f.write( head_tag )
f.write( p5_line )
f.write( p5dom_line )
f2 = open( tempFile, "r" )
for line in f2 :
f.write( line )
#####################
# GETP5 DOM PATHS #
#####################
def getP5dom_paths() :
cmd_p5dom = 'find / -name "p5.dom.js" | grep -v "Permission denied" > p5dom_out.txt'
print "Finding p5.dom.js using command: " + cmd_p5dom
time.sleep(5) # message to user
# execute find p5dom
os.system( cmd_p5dom )
# collect paths from save file
fo = open( "p5dom_out.txt", "r" )
pathList = []
for path in fo :
path = path.strip()
pathList.append( path )
os.system( 'rm p5dom_out.txt' )
return pathList
#################
# GETP5 PATHS #
#################
def getP5_paths() :
cmd_p5 = 'find / -name "p5.js" | grep -v "Permission denied" > p5_out.txt'
print "Finding p5.js using command: " + cmd_p5
time.sleep(5) # message to user
# execute find p5
os.system( cmd_p5 )
# collect paths from save file
fo = open( "p5_out.txt", "r" )
pathList = []
for path in fo :
path = path.strip()
pathList.append( path )
os.system( 'rm p5_out.txt' )
return pathList
########################
# DE DUPLICATE SETUP #
########################
# this script modifies the contents of FindAPR.cmake in the c4 submodule
# prior to compilation.
# need to ensure only one SET command exists in FindAPR.cmake after discovering
# a valid apr library.
def deduplicateSetup() :
# http://stackoverflow.com/questions/4710067/deleting-a-specific-line-in-a-file-python
# protect against multiple runs of setup
f = open( C4_FINDAPR_PATH, "r+" )
d = f.readlines()
f.seek(0)
for i in d:
if not "set(APR_INCLUDES" in i :
f.write(i)
f.truncate()
f.close()
#############
# SET APR #
#############
def setAPR( path ) :
# set one of the candidate APR paths
newCmd = 'set(APR_INCLUDES "' + path + '")'
cmd = "(head -48 " + C4_FINDAPR_PATH + "; " + "echo '" + newCmd + "'; " + "tail -n +49 " + C4_FINDAPR_PATH + ")" + " > temp ; mv temp " + C4_FINDAPR_PATH + ";"
os.system( cmd )
os.system( "make c4" )
##########################
# CHECK FOR MAKE ERROR #
##########################
def checkForMakeError( path ) :
flag = True
if os.path.exists( os.path.dirname(os.path.abspath( __file__ )) + "/c4_out.txt" ) :
fo = open( "./c4_out.txt", "r" )
for line in fo :
line = line.strip()
if containsError( line ) :
print "failed path apr = " + path
flag = False
fo.close()
os.system( "rm ./c4_out.txt" ) # clean up
return flag
####################
# CONTAINS ERROR #
####################
def containsError( line ) :
if "error generated." in line :
return True
#elif "Error" in line :
# return True
else :
return False
##########
# MAIN #
##########
def main() :
print "Running pyLDFI setup with args : \n" + str(sys.argv)
# clean any existing libs
os.system( "make clean" )
# download submodules
os.system( "make get-submodules" )
# ---------------------------------------------- #
# run make for orik
os.system( "make orik" )
## ---------------------------------------------- #
## run make for c4
## find candidate apr locations
#apr_path_cands = getAPR_list()
#
## set correct apr location
#flag = True
#for path in apr_path_cands :
# try :
# deduplicateSetup()
# except IOError :
# setAPR( path )
# setAPR( path )
# try :
# flag = checkForMakeError( path )
# except IOError :
# print "./c4_out.txt does not exist"
#
# # found a valid apr library
# if flag :
# print ">>> C4 installed successfully <<<"
# print "... Done installing C4 Datalog evaluator"
# print "C4 install using APR path : " + path
# print "done installing c4."
# break
# else :
# sys.exit( "failed to install C4. No fully functioning APR found." )
# ---------------------------------------------- #
# set p5 file paths
#set_PYLDFI_VIZ_paths()
###################
# CHECK PY DEPS #
###################
# check python package dependencies
def checkPyDeps() :
print "*******************************"
print " CHECKING PYTHON DEPENDECIES "
print "*******************************"
# argparse
import argparse
if argparse.__name__ :
print "argparse...verified"
# pyparsing
import pyparsing
if pyparsing.__name__ :
print "pyparsing...verified"
# sqlite3
import sqlite3
if sqlite3.__name__ :
print "sqlite3...verified"
# pydatalog
#import pyDatalog
#if pyDatalog.__name__ :
# print "pyDatalog...verified"
# pydot
import pydot
if pydot.__name__ :
print "pydot...verified"
# mpmath
import mpmath
if mpmath.__name__ :
print "mpmath...verified"
# sympy
import sympy
if not sympy.__version__ == "1.0.1.dev" :
sys.exit( "FATAL ERROR : unsupported version of package 'sympy' : version " + sympy.__version__ + "\nPyLDFI currently only supports sympy version 1.0.1.dev.\nAborting..." )
else :
print "sympy...verified"
# pycosat
import pycosat
if pycosat.__name__ :
print "pycosat...verified"
print "All python dependencies installed! Yay! =D"
print "*******************************"
print "*******************************"
return None
##############################
# MAIN THREAD OF EXECUTION #
##############################
checkPyDeps()
main()
#########
# EOF #
#########