aboutsummaryrefslogtreecommitdiffstats
path: root/fg21sim
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2016-11-03 10:05:18 +0800
committerAaron LI <aaronly.me@outlook.com>2016-11-03 10:05:18 +0800
commita28ad462495b2a41ce5a1c2501dab3678cf3c22f (patch)
treead0ab4ca4341ab0752688da7650e7beced8abc43 /fg21sim
parentd702cb4c1453981c80117a8bc68a8e46b08969ac (diff)
downloadfg21sim-a28ad462495b2a41ce5a1c2501dab3678cf3c22f.tar.bz2
configs/manager.py: Add method "reset()" and attribute "userconfig"
Diffstat (limited to 'fg21sim')
-rw-r--r--fg21sim/configs/manager.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/fg21sim/configs/manager.py b/fg21sim/configs/manager.py
index d406dc7..d03479e 100644
--- a/fg21sim/configs/manager.py
+++ b/fg21sim/configs/manager.py
@@ -75,6 +75,10 @@ class ConfigManager:
configs specifying the input templates or data files, therefore
allow the use of relative path for those configs.
"""
+ # Path to the user provided configuration file, which indicates user
+ # configurations merged if not ``None``.
+ userconfig = None
+
def __init__(self, userconfig=None):
"""Load the bundled default configurations and specifications.
If the ``userconfig`` provided, the user configurations is also
@@ -128,7 +132,7 @@ class ConfigManager:
thus allow the use of *relative path* of some input files (e.g.,
"galactic/synchrotron/template") within the configurations.
"""
- if hasattr(self, "userconfig"):
+ if self.userconfig is not None:
raise ConfigError('User configuration already loaded from "%s"' %
self.userconfig)
#
@@ -141,6 +145,17 @@ class ConfigManager:
self.userconfig = os.path.abspath(userconfig)
logger.info("Loaded user config: {0}".format(self.userconfig))
+ def reset(self):
+ """Reset the current configurations to the copy of defaults from
+ the specifications.
+
+ NOTE: Also reset ``self.userconfig`` to ``None``.
+ """
+ # NOTE: `_config_default.copy()` only returns a *shallow* copy.
+ self._config = ConfigObj(self._config_default, interpolation=False)
+ self.userconfig = None
+ logger.warning("Reset the configurations to the copy of defaults!")
+
def _validate(self, config):
"""Validate the config against the specification using a default
validator. The validated config values are returned if success,