-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathconfig.py
124 lines (101 loc) · 4.43 KB
/
config.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
# -*- coding: utf-8 -*-
"""
Global configuration of the IvS package.
Usage: $ python config.py compile
$ python config.py recompile
"""
import os
import sys
import glob as glob_module
#-- You can add directories here, but be sure that the relative paths within
# those directories are correct!
data_dirs = [os.getenv('ivsdata'),'/STER/pieterd/IVSDATA/', '/STER/kristofs/IVSdata','/STER/jorisv/IVSDATA/',
'/STER/kenneth/Python_repository/','/home/ben/public_html/opacities','/STER/michelh/IVSDATA/',
'/STER/mike/IVSDATA/', '/STER/anae/IVSDATA/']
ivs_dirs = dict(coralie='/STER/coralie/',
hermes='/STER/mercator/hermes/')
def get_datafile(relative_path,basename):
"""
Reconstruct the location of a data file and check whether it exists.
If the file exists, it will return the absolute path of the filename.
If the file does not exist, it will raise an IOError.
@param relative_path: relative path starting from main data directory tree
@type relative_path: str
@param basename: filename
@type basename: str
@return: absolute path to the file
@rtype: str
"""
for data_dir in data_dirs:
if data_dir is None: continue
filename = os.path.join(data_dir,relative_path,basename)
if os.path.isfile(filename):
break
else:
str_data_dirs = ", ".join([idir for idir in data_dirs if idir is not None])
relative_file = os.path.join(relative_path,basename)
raise IOError("File %s not found in any of the specified data directories %s"%(relative_file,str_data_dirs))
return filename
def glob(relative_path,arg='*'):
"""
Glob the files in a relative path.
@param relative_path: relative path starting from main data directory tree
@type relative_path: str
@param arg: argument to use in glob
@type arg: str
@return: sorted list of files
@rtype: list of str
"""
files = []
for data_dir in data_dirs:
if data_dir is None: continue
files += glob_module.glob(os.path.join(data_dir,relative_path,arg))
files.sort()
return files
if __name__=="__main__":
import subprocess
from ivs.aux import loggers
import shutil
import time
import glob
logger = loggers.get_basic_logger()
to_install = ['spectra/pyrotin4',
'timeseries/deeming','timeseries/eebls','timeseries/multih',
'timeseries/pyclean','timeseries/pyKEP','timeseries/pyscargle',
'timeseries/pyGLS','timeseries/pyfasper_single','timeseries/pyfasper',
'timeseries/pyscargle_single','timeseries/pydft','sigproc/pyfinterpol']
main_dir = os.getcwd()
if len(sys.argv)>1:
if len(sys.argv)>=3:
compiler = sys.argv[2]
else:
compiler = 'gfortran'
if 'compile' in sys.argv[1]:
answer = 'y'
for name in to_install:
#-- break up fortran filepath in file and directory name
direc,pname = os.path.dirname(name),os.path.basename(name)
if not os.path.isfile(name+'.so') or sys.argv[1] == 'recompile':
#-- build the command to compile the program and log it to
# the user
cmd = 'f2py --fcompiler=%s -c %s.f -m %s'%(compiler,os.path.join(direc,pname),pname)
logger.info('Compiling %s: %s'%(pname.upper(),cmd))
if answer.lower()!='y':
answer = input('Continue? [Y/n] ')
if answer.lower()=='n':
continue
#-- call the compiling command
p = subprocess.check_output(cmd,shell=True)#,stdout=devnull)
#-- check if compilation went fine
# find compiled file name
compiled_filename = list(filter(os.path.isfile, glob.glob('./'+pname+'*.so')))
# if it exists move it to to appropriate dir
# and change the compiled name e.g. deeming.cpython-36m-x86_64-linux-gnu.so
# to e.g. deeming.so
if compiled_filename:
shutil.move(compiled_filename[0],name+'.so')
logger.info('... succeeded')
else:
logger.error('FAILED')
else:
logger.info('%s already compiled'%(pname.upper()))