-
Notifications
You must be signed in to change notification settings - Fork 114
/
config.py
107 lines (77 loc) · 3.49 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
# Collective Mind configuration
#
# Written by Grigori Fursin
import os
class Config(object):
"""
CM configuration class
"""
def __init__(self, config_file = None):
"""
Initialize CM configuration class
Args:
(config_file) (str): If not None, merge this file with the internal configuration
Returns:
(python class) with the following vars:
* cfg (dict): internal CM configuration
"""
self.cfg = {
"name": "cm",
"env_home": "CM_HOME",
"env_repos": "CM_REPOS",
"env_debug": "CM_DEBUG",
"env_config": "CM_CONFIG",
"env_index": "CM_INDEX",
"flag_debug": "cm-debug",
"flag_help": "h",
"flag_help2": "help",
"error_prefix": "CM error:",
"error_prefix2": "CMX detected an issue",
"info_cli": "cm {action} {automation} {artifact(s)} {flags} @input.yaml @input.json",
"info_clix": "cmx {action} {automation} {artifact(s)} {CMX control flags (-)} {CMX automation flags (--)}",
"default_home_dir": "CM",
"file_repos": "repos.json",
"dir_repos": "repos",
"cmind_repo": "repo",
"file_index": "index.json",
"file_meta_repo": "cmr",
"common_automation_module_name": "module",
"common_automation_module_namex": "modulex",
"action_substitutions": {
"ls":"search",
"list":"search",
"find":"search",
"rm":"delete",
"mv":"move",
"ren":"move",
"rename":"move",
"cp":"copy"
},
"new_repo_requirements": "cmind >= 3.1.0\n",
"cmind_automation":"automation",
"file_cmeta":"_cm",
"local_repo_name": "local",
"local_repo_meta": {
"uid": "9a3280b14a4285c9",
"alias": "local",
"name": "local CM repository"
},
"default_repo_pack": "cm.zip",
"repo_url_prefix":"https://github.com/",
"repo_url_org":"mlcommons",
"fail_if_automation_not_found": True,
"line":"=======================================================",
"artifact_keys":['automation', 'artifact', 'parsed_automation', 'parsed_artifact']
}
# Attempt to update config from file if specified explicitly during initialization
# or specified by the environment variable
if config_file is None or config_file.strip() == '':
config_file = os.environ.get(self.cfg['env_config'])
if config_file is not None and config_file.strip() != '':
from cmind import utils
r = utils.load_json_or_yaml(config_file)
if r['return'] > 0:
# Raise here because it's an initializer of a class
raise Exception(r['error'])
meta = r.get('meta', {})
self.cfg.update(meta)