-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathconfig.py
68 lines (51 loc) · 1.74 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
"""Configuration and global defaults."""
import os
import subprocess
import configparser
import getpass
def home():
return os.path.expanduser('~')
def get_default_config():
"""Dictionary of all config option defaults.
Returns
-------
rcParams : configparser.ConfigParser
A dict-like object containing parameters.
"""
rcParams = configparser.ConfigParser()
rcParams['DEFAULT']['data_directory'] = ""
rcParams['DEFAULT']['ssl_cert'] = "True" # note this can be True,
# False (bad
# idea/permissive) or a
# path to ssl certs,
# e.g. /etc/ssl/cert.perm
# or similar
rcParams['DEFAULT']['proj_network'] = "False"
rcParams.add_section('AppEEARS')
rcParams['AppEEARS']['username'] = 'NOT_PROVIDED'
rcParams['AppEEARS']['password'] = 'NOT_PROVIDED'
return rcParams
def get_config():
try:
data_directory = os.path.join(os.environ['WATERSHED_WORKFLOW_DATA_DIR'])
except KeyError:
data_directory = os.path.join(os.getcwd(), 'data')
rc = get_default_config()
rc['DEFAULT']['data_directory'] = data_directory
# paths to search for rc files
rc_paths = [
os.path.join(home(), '.watershed_workflowrc'),
os.path.join(os.getcwd(), '.watershed_workflowrc'),
os.path.join(os.getcwd(), 'watershed_workflowrc'),
]
# this is a bit fragile -- it checks if the user is the docker user
if getpass.getuser() == 'jovyan':
rc_paths.append('/home/jovyan/workdir/.docker_watershed_workflowrc')
# read the rc files
rc.read(rc_paths)
return rc
def set_data_directory(path):
"""Sets the directory in which all data is stored."""
rcParams['DEFAULT']['data_directory'] = path
# global config
rcParams = get_config()