aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Sommerseth <davids@redhat.com>2012-12-19 17:04:27 +0100
committerDavid Sommerseth <davids@redhat.com>2012-12-19 17:04:27 +0100
commit96d0f3853fbac2b05dfb9fa97372f3a354083dd2 (patch)
treebaa2637c1bfb4a6d2f3d8c7bb0074a69c185f913
parent9332c914f6bae11c3a244cec4ecb06fbe6f17f4b (diff)
downloadrteval-96d0f3853fbac2b05dfb9fa97372f3a354083dd2.tar.gz
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.py9
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)