aboutsummaryrefslogtreecommitdiffstats
path: root/fg21sim/configs
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2016-11-03 20:15:38 +0800
committerAaron LI <aaronly.me@outlook.com>2016-11-03 20:15:38 +0800
commitba8c9b10a45528405c8d96faea2208f1d21fa267 (patch)
treef243dd76d9e6430e6bda150c54f42efcc0dcdd2a /fg21sim/configs
parentc3e41b62dfdbdbdd17703caf98754531879bd753 (diff)
downloadfg21sim-ba8c9b10a45528405c8d96faea2208f1d21fa267.tar.bz2
configs/manager.py: Reset before loading user config file again
Originally, the user configuration file is only allowed to load once, and prevent any future loading of user configuration file. This change allows load user configuration file again by resetting the current configurations to defaults before loading.
Diffstat (limited to 'fg21sim/configs')
-rw-r--r--fg21sim/configs/manager.py22
1 files changed, 10 insertions, 12 deletions
diff --git a/fg21sim/configs/manager.py b/fg21sim/configs/manager.py
index d03479e..ff950bb 100644
--- a/fg21sim/configs/manager.py
+++ b/fg21sim/configs/manager.py
@@ -69,11 +69,11 @@ class ConfigManager:
userconfig : str
The filename and path to the user-provided configurations.
NOTE:
- - This attribute only presents after loading the user configuration
- by ``self.read_userconfig()``;
+ - This attribute has valid value only after loading the user
+ configuration by ``self.read_userconfig()``;
- This attribute is used to determine the absolute path of the
configs specifying the input templates or data files, therefore
- allow the use of relative path for those configs.
+ allow the use of relative path for those config options.
"""
# Path to the user provided configuration file, which indicates user
# configurations merged if not ``None``.
@@ -126,21 +126,19 @@ class ConfigManager:
NOTE
----
- The user configuration file can be loaded *only once*, i.e.,
- *only one* user configuration file supported.
- Since the *path* of the user configuration file is recorded, and
- thus allow the use of *relative path* of some input files (e.g.,
- "galactic/synchrotron/template") within the configurations.
+ If a user configuration file is already loaded, then the
+ configurations are *reset* before loading the supplied user
+ configuration file.
"""
- if self.userconfig is not None:
- raise ConfigError('User configuration already loaded from "%s"' %
- self.userconfig)
- #
try:
config = open(userconfig).read().split("\n")
except IOError:
raise ConfigError('Cannot read config from "%s"' % userconfig)
#
+ if self.userconfig is not None:
+ logger.warning('User configuration already loaded from "%s"' %
+ self.userconfig)
+ self.reset()
self.read_config(config)
self.userconfig = os.path.abspath(userconfig)
logger.info("Loaded user config: {0}".format(self.userconfig))