14
14
"""
15
15
import argparse
16
16
import logging
17
+ import os
17
18
import sys
18
19
19
20
from .application import run_service
20
21
from .application_config import CLI_DEFAULT_CONFIGFILE , CONFIG_SCHEMA
21
22
from .cli_config import add_cli_options , config_from_options
23
+ from .utils import search_osparc_repo_dir
22
24
23
25
log = logging .getLogger (__name__ )
24
26
25
27
26
28
def create_default_parser ():
27
29
return argparse .ArgumentParser (description = 'Service to manage data storage in simcore.' )
28
30
31
+
29
32
def setup_parser (parser ):
30
33
""" Adds all options to a parser"""
31
34
#parser.add_argument('names', metavar='NAME', nargs=argparse.ZERO_OR_MORE,
@@ -37,14 +40,35 @@ def setup_parser(parser):
37
40
38
41
return parser
39
42
43
+
44
+ def create_environ ():
45
+ """
46
+ Build environment with substitutable variables
47
+
48
+ """
49
+ # system's environment variables
50
+ environ = dict (os .environ )
51
+
52
+ # project-related environment variables
53
+ rootdir = search_osparc_repo_dir ()
54
+ if rootdir is not None :
55
+ environ .update ({
56
+ 'OSPARC_SIMCORE_REPO_ROOTDIR' : str (rootdir ),
57
+ })
58
+
59
+ return environ
60
+
61
+
62
+
40
63
def parse (args , parser ):
41
64
""" Parse options and returns a configuration object """
42
65
if args is None :
43
66
args = sys .argv [1 :]
44
67
45
68
# ignore unknown options
46
69
options , _ = parser .parse_known_args (args )
47
- config = config_from_options (options , CONFIG_SCHEMA )
70
+
71
+ config = config_from_options (options , CONFIG_SCHEMA , vars = create_environ ())
48
72
49
73
# TODO: check whether extra options can be added to the config?!
50
74
return config
0 commit comments