forked from IvS-KULeuven/IvSPythonRepository
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
118 lines (95 loc) · 3.98 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
# -*- coding: utf-8 -*-
"""
Global configuration of the IvS package.
Usage: $ python config.py compile
"""
import os
import collections
import ast
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/']
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
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 sys.argv[1]=='compile':
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'):
#-- 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!='Y':
answer = raw_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
if os.path.isfile(pname+'.so'):
shutil.move(pname+'.so',name+'.so')
logger.info('... succeeded')
else:
logger.error('FAILED')
else:
logger.info('%s already compiled'%(pname.upper()))