From ba8c9b10a45528405c8d96faea2208f1d21fa267 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Thu, 3 Nov 2016 20:15:38 +0800 Subject: 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. --- fg21sim/configs/manager.py | 22 ++++++++++------------ 1 file 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)) -- cgit v1.2.2