Skip to content

Commit 641569a

Browse files
committed
Hid GlobalConfig
Wrapped GlobalConfig with methods to prevent accidental modification.
1 parent 1b2f8e8 commit 641569a

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

ngcsimlib/configManager.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
"""
22
ngc libraries have a need for global level configuration which will all be
33
handled here. It will also be possible to add custom configuration sections to
4-
this file with no issues or additional setup. However the main purpose of these
4+
this file with no issues or additional setup. However, the main purpose of these
55
configurations are not control specific parts of the model but control ngc
66
libraries at a high level.
77
"""
88
import json
9+
from types import SimpleNamespace
910

1011

1112
class ConfigManager:
@@ -25,5 +26,24 @@ def get_config(self, name):
2526

2627
return self.loadedConfig.get(name, None)
2728

29+
def provide_namespace(self, configName):
30+
config = self.get_config(configName)
31+
if config is None:
32+
return None
33+
else:
34+
return SimpleNamespace(**config)
35+
36+
37+
_GlobalConfig = ConfigManager()
38+
39+
40+
def init_config(path):
41+
_GlobalConfig.init_config(path)
42+
43+
44+
def get_config(configName):
45+
return _GlobalConfig.get_config(configName)
46+
2847

29-
GlobalConfig = ConfigManager()
48+
def provide_namespace(configName):
49+
return _GlobalConfig.provide_namespace(configName)

ngcsimlib/logger.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22
import sys
3-
from ngcsimlib.configManager import GlobalConfig
3+
from ngcsimlib.configManager import get_config
44

55
def _concatArgs(*args, **kwargs):
66
"""Internal Decorator for concatenating arguments into a single string"""
@@ -19,7 +19,7 @@ def wrapped(*wargs, sep=" ", end="", **kwargs):
1919

2020

2121
def init_logging():
22-
loggingConfig = GlobalConfig.get_config("logging")
22+
loggingConfig = get_config("logging")
2323
if loggingConfig is None:
2424
loggingConfig = {"logging_file": None,
2525
"logging_level": logging.WARNING,

0 commit comments

Comments
 (0)