-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure.py
74 lines (59 loc) · 1.78 KB
/
configure.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
"""
Implements discovery of environment vars and command-line "superoptions".
Also manages persistence via pickle files.
Currently defined settings (Key: Value):
"hdf5": <path to HDF5>
"""
import os, sys
import warnings
def loadpickle(name):
""" Load object from pickle file, or None if it can't be opened """
import pickle
try:
f = open(name,'r')
except IOError:
return None
try:
return pickle.load(f)
except Exception:
return None
finally:
f.close()
def savepickle(name, data):
""" Save to pickle file, ignoring if it can't be written """
import pickle
try:
f = open(name, 'wb')
except IOError:
return
try:
pickle.dump(data, f)
finally:
f.close()
def scrape_eargs():
""" Locate settings in environment vars """
settings = {}
hdf5 = os.environ.get("HDF5_DIR", '')
if hdf5 != '':
settings['hdf5'] = hdf5
api = os.environ.get("HDF5_API", '')
if api != '':
warnings.warn("HDF5_API environment variable ignored (Support for HDF5 1.6 dropped)")
return settings
def scrape_cargs():
""" Locate settings in command line or pickle file """
settings = loadpickle('h5py_config.pickle')
if settings is None: settings = {}
for arg in sys.argv[:]:
if arg.find('--hdf5=') == 0:
hdf5 = arg.split('=')[-1]
if hdf5.lower() == 'default':
settings.pop('hdf5', None)
else:
settings['hdf5'] = hdf5
sys.argv.remove(arg)
if arg.find('--api=') == 0:
warnings.warn("--api option ignored (Support for HDF5 1.6 dropped)")
sys.argv.remove(arg)
savepickle('h5py_config.pickle', settings)
return settings