-
Notifications
You must be signed in to change notification settings - Fork 27
/
install.py
207 lines (198 loc) · 8.55 KB
/
install.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
######################## Install Script v.1.0. #########################
# #
# This script installs CERES in your computer #
# #
# UPDATES: #
# #
# 02-09-2016: Finished code. Working like a charm! #
# #
########################################################################
p_name = "CERES"
gsl_path = '/usr/local'
import glob
import sys
import os
import shutil
import subprocess
sys.path.append("utils/SSEphem")
import update_ssephem
f = open('gsl.temp','w')
f.write(gsl_path)
f.close()
def CheckLibraries():
print " ----------------------------------------------------------"
try:
import numpy
except ImportError:
print " ----------------------------------------------------------"
print ' ERROR: '+p_name+' will not be installed in your system because'
print ' numpy is not installed in your system.'
print ' To install it, go to: http://www.numpy.org/\n\n'
sys.exit(1)
print " > Numpy is ok!"
try:
import scipy
except ImportError:
print " ----------------------------------------------------------"
print ' ERROR: '+p_name+' will not be installed in your system because'
print ' scipy is not installed in your system.'
print ' To install it, go to: http://www.scipy.org/\n\n'
sys.exit(1)
print " > Scipy is ok!"
#try:
# import pyfits
#except ImportError:
# print " ----------------------------------------------------------"
# print ' ERROR: '+p_name+' will not be installed in your system because'
# print ' pyfits is not installed in your system.'
# print ' To install it, go to: http://www.stsci.edu/institute/software_hardware/pyfits \n\n'
# sys.exit(1)
#print " > Pyfits is ok!"
def getDirs(foldername):
return os.walk(foldername).next()[1]
def spaced(input,space):
fixed = False
i = 0
input = space+input
while(not fixed):
if(input[i:i+1] == '\n'):
input = input[0:i+1]+space+input[i+1:]
i = i + len(space)
i = i + 1
if(i == len(input)-1):
fixed = True
return input
def Build(directory):
# We obtain al files and folders of the current directory...
files_and_folders = glob.glob(directory+'/*')
CFileFound = False
SetupFileFound = False
# ...and we check each folder or file:
for cf in files_and_folders:
# We search for files named Proceso_f2py, or for the setup.py - file.c
# combination. If present, we build the process.
pf2py = 'Proceso_f2py'
stp = 'setup.py'
if( cf[-len(pf2py):] == pf2py ):
print " > Fortran code found in directory "+directory+". Building..."
cwd = os.getcwd()
os.chdir(directory)
subprocess.Popen('chmod u+wrx Proceso_f2py',shell = True).wait()
subprocess.Popen('chmod g+wrx Proceso_f2py',shell = True).wait()
subprocess.Popen('chmod o+wrx Proceso_f2py',shell = True).wait()
p = subprocess.Popen('./Proceso_f2py',stdout = subprocess.PIPE, stderr = subprocess.PIPE,shell = True)
p.wait()
if(p.returncode != 0 and p.returncode != None):
print " ----------------------------------------------------------"
print " > ERROR: "+p_name+" couldn't be installed."
print " > Problem building code in "+directory+". The error was:\n"
out, err = p.communicate()
print err
print " > If you can't solve the problem, please communicate"
print " > with the "+p_name+" team for help.\n\n"
os.chdir(cwd)
sys.exit()
os.chdir(cwd)
print " >...done!"
elif( cf[-len(stp):] == stp ):
SetupFileFound = True
elif( cf[-2:] == '.c' ):
CFileFound = True
if( SetupFileFound and CFileFound ):
print " > C code found in directory "+directory+". Building..."
cwd = os.getcwd()
os.chdir(directory)
p = subprocess.Popen('{python} setup.py build'.format(python=sys.executable),stdout = subprocess.PIPE, stderr = subprocess.PIPE,shell = True)
p.wait()
if(p.returncode != 0 and p.returncode != None):
print " ----------------------------------------------------------"
print " > ERROR: "+p_name+" couldn't be installed."
print " > Problem building code in "+directory+". The error was:\n"
out, err = p.communicate()
print spaced(err,"\t \t")
print " > If you can't solve the problem, please communicate"
print " > with the "+p_name+" team for help.\n \n"
os.chdir(cwd)
sys.exit()
libfolder = getDirs('build/.')
for name in libfolder:
if(name[0:3]=='lib'):
filename = glob.glob('build/'+name+'/*')
shutil.copy2(filename[0],'.')
shutil.rmtree('build')
os.chdir(cwd)
print ' >...done!'
# If the current file or folder is a directory, we apply the same
# code to it:
elif( os.path.isdir(cf) ):
Build(cf)
print " \n\n "+p_name+" Installer v.1.0. \n\n"
print " The "+p_name+" team is composed of: \n"
print " - Rafael Brahm (PUC, [email protected])."
print " - Andres Jordan (PUC, [email protected])."
print " - Nestor Espinoza (PUC, [email protected]). \n"
print " DISCLAIMER: If you use this pipeline or part of it, please "
print " acknowledge us and our current institutions. If you find any bugs,"
print " please contact us. \n"
print " 1.- Preparing to install. Checking if your system has the libraries"
print " needed to compile the codes...\n"
CheckLibraries()
print " ---------------------------------------------------------- \n"
print " Done! All libraries checked. \n"
import numpy
print " 2.- Building processes...\n"
print " ----------------------------------------------------------"
# First, we get all the directories in the current folder:
dirs = getDirs('utils/')
ndirs = []
for dire in dirs:
ndirs.append('utils/'+dire)
dirs = ndirs
for directory in dirs:
# To each directory, we apply the build function:
if(directory == 'utils/SSEphem'):
print " > Installing SSEphem...\n \n"
os.chdir('utils/SSEphem/SOFA')
os.system('mkdir lib')
os.system('mkdir include')
p = subprocess.Popen('make',stdout = subprocess.PIPE, stderr = subprocess.PIPE,shell = True)
p.wait()
if(p.returncode != 0 and p.returncode != None):
print ' Error in SSEphem installation! The error was:'
out, err = p.communicate()
print spaced(err,"\t \t")
sys.exit()
p = subprocess.Popen('make test',stdout = subprocess.PIPE, stderr = subprocess.PIPE,shell = True)
p.wait()
if(p.returncode != 0 and p.returncode != None):
print ' Error in SSEphem installation! The error was:'
out, err = p.communicate()
print spaced(err,"\t \t")
sys.exit()
os.chdir('../')
p = subprocess.Popen('make clean',stdout = subprocess.PIPE, stderr = subprocess.PIPE,shell = True)
p.wait()
if(p.returncode != 0 and p.returncode != None):
print ' Error in SSEphem installation! The error was:'
out, err = p.communicate()
print spaced(err,"\t \t")
sys.exit()
p = subprocess.Popen('make',stdout = subprocess.PIPE, stderr = subprocess.PIPE,shell = True)
p.wait()
if(p.returncode != 0 and p.returncode != None):
print ' Error in SSEphem installation! The error was:'
out, err = p.communicate()
print spaced(err,"\t \t")
sys.exit()
else:
update_ssephem.SSEphemDownload()
update_ssephem.LeapSecUpdate()
update_ssephem.IersUpdate()
os.chdir('../../')
else:
Build(directory)
print " ---------------------------------------------------------- \n \n"
print " Installation of "+p_name+" finished without problems! \n \n"
print " Please read the README file in order to learn how to "
print " use the routines. \n \n"
os.system('rm gsl.temp')