diff options
author | David Sommerseth <davids@redhat.com> | 2012-12-19 17:04:27 +0100 |
---|---|---|
committer | David Sommerseth <davids@redhat.com> | 2012-12-19 17:04:27 +0100 |
commit | 96d0f3853fbac2b05dfb9fa97372f3a354083dd2 (patch) | |
tree | baa2637c1bfb4a6d2f3d8c7bb0074a69c185f913 | |
parent | 9332c914f6bae11c3a244cec4ecb06fbe6f17f4b (diff) | |
download | rteval-96d0f3853fbac2b05dfb9fa97372f3a354083dd2.tar.gz rteval-96d0f3853fbac2b05dfb9fa97372f3a354083dd2.tar.xz rteval-96d0f3853fbac2b05dfb9fa97372f3a354083dd2.zip |
Tackle if trying to set a configuration value not found in the config file
If a section was missing in the config file when being set from the command
line, an exception would occur. In these cases, create the section
"on-the-fly" in the configuration object.
Signed-off-by: David Sommerseth <davids@redhat.com>
-rw-r--r-- | rteval/rtevalConfig.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/rteval/rtevalConfig.py b/rteval/rtevalConfig.py index 4d7ba17..631007b 100644 --- a/rteval/rtevalConfig.py +++ b/rteval/rtevalConfig.py @@ -219,8 +219,15 @@ class rtevalConfig(object): k = sk.split('___') if k[0] != last_sect: # If the section name changed, retrieve the section variables - sect = self.GetSection(k[0]) + try: + sect = self.GetSection(k[0]) + except KeyError: + # If section does not exist, create it + self.AppendConfig(k[0], {k[1]: v}) + sect = self.GetSection(k[0]) + last_sect = k[0] + setattr(sect, k[1], v) |