1
2 """
3 Global configuration of the IvS package.
4
5 Usage: $ python config.py compile
6 """
7
8 import os
9 import collections
10 import ast
11 import sys
12 import glob as glob_module
13
14
15
16 data_dirs = [os.getenv('ivsdata'),'/STER/pieterd/IVSDATA/', '/STER/kristofs/IVSdata','/STER/jorisv/IVSDATA/',
17 '/STER/kenneth/Python_repository/','/home/ben/public_html/opacities','/STER/michelh/IVSDATA/']
18
19 ivs_dirs = dict(coralie='/STER/coralie/',
20 hermes='/STER/mercator/hermes/')
21
22
23
25 """
26 Reconstruct the location of a data file and check whether it exists.
27
28 If the file exists, it will return the absolute path of the filename.
29
30 If the file does not exist, it will raise an IOError.
31
32 @param relative_path: relative path starting from main data directory tree
33 @type relative_path: str
34 @param basename: filename
35 @type basename: str
36 @return: absolute path to the file
37 @rtype: str
38 """
39 for data_dir in data_dirs:
40 if data_dir is None: continue
41
42 filename = os.path.join(data_dir,relative_path,basename)
43
44 if os.path.isfile(filename):
45 break
46 else:
47 str_data_dirs = ", ".join([idir for idir in data_dirs if idir is not None])
48 relative_file = os.path.join(relative_path,basename)
49 raise IOError, "File %s not found in any of the specified data directories %s"%(relative_file,str_data_dirs)
50
51 return filename
52
53
54
55
56 -def glob(relative_path,arg='*'):
57 """
58 Glob the files in a relative path.
59
60 @param relative_path: relative path starting from main data directory tree
61 @type relative_path: str
62 @param arg: argument to use in glob
63 @type arg: str
64 @return: sorted list of files
65 @rtype: list of str
66 """
67 files = []
68 for data_dir in data_dirs:
69 if data_dir is None: continue
70 files += glob_module.glob(os.path.join(data_dir,relative_path,arg))
71 files.sort()
72 return files
73
74
75
76
77 if __name__=="__main__":
78 import subprocess
79 from ivs.aux import loggers
80 import shutil
81 import time
82 logger = loggers.get_basic_logger()
83
84 to_install = ['spectra/pyrotin4',
85 'timeseries/deeming','timeseries/eebls','timeseries/multih',
86 'timeseries/pyclean','timeseries/pyKEP','timeseries/pyscargle',
87 'timeseries/pyGLS','timeseries/pyfasper_single','timeseries/pyfasper',
88 'timeseries/pyscargle_single','timeseries/pydft','sigproc/pyfinterpol']
89 main_dir = os.getcwd()
90 if len(sys.argv)>1:
91 if len(sys.argv)>=3:
92 compiler = sys.argv[2]
93 else:
94 compiler = 'gfortran'
95 if sys.argv[1]=='compile':
96 answer = 'y'
97 for name in to_install:
98
99 direc,pname = os.path.dirname(name),os.path.basename(name)
100 if not os.path.isfile(name+'.so'):
101
102
103 cmd = 'f2py --fcompiler=%s -c %s.f -m %s'%(compiler,os.path.join(direc,pname),pname)
104 logger.info('Compiling %s: %s'%(pname.upper(),cmd))
105 if answer!='Y':
106 answer = raw_input('Continue? [Y/n] ')
107 if answer.lower()=='n':
108 continue
109
110 p = subprocess.check_output(cmd,shell=True)
111
112 if os.path.isfile(pname+'.so'):
113 shutil.move(pname+'.so',name+'.so')
114 logger.info('... succeeded')
115 else:
116 logger.error('FAILED')
117 else:
118 logger.info('%s already compiled'%(pname.upper()))
119