summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2019-06-06 20:49:22 +1000
committerChris Johns <chrisj@rtems.org>2019-06-11 11:00:30 +1000
commit89dcdbc9fface5e52ad75043c3cb6745233ba987 (patch)
treeaf0b000536cecd28ecad145ce8165a3936dbee0f
parentaf9b561e92cf3c1d8275bde3003b03e9c8f7c852 (diff)
rtemstoolkit/configuration: Add get_sections() to get the sections.
- Fix module access when catching exceptions.
-rw-r--r--rtemstoolkit/configuration.py28
1 files changed, 20 insertions, 8 deletions
diff --git a/rtemstoolkit/configuration.py b/rtemstoolkit/configuration.py
index 3b03296..bc3ec93 100644
--- a/rtemstoolkit/configuration.py
+++ b/rtemstoolkit/configuration.py
@@ -40,16 +40,21 @@ import re
from rtemstoolkit import error
from rtemstoolkit import path
+try:
+ import configparser
+ has_strict = True
+except:
+ # python2
+ import ConfigParser as configparser
+ has_strict = False
+
class configuration:
def __init__(self, raw = True):
self.raw = True
- try:
- import configparser
+ if has_strict:
self.config = configparser.ConfigParser(strict = False)
- except:
- # python2
- import ConfigParser as configparser
+ else:
self.config = configparser.ConfigParser()
self.ini = None
self.macro_filter = re.compile('\$\{.+\}')
@@ -74,9 +79,14 @@ class configuration:
raw = self.raw))]
return os.linesep.join(s)
+ def get_sections(self):
+ return self.config.sections()
+
def get_item(self, section, label, err = True):
try:
- rec = self.config.get(section, label, raw = self.raw).replace(os.linesep, ' ')
+ rec = self.config.get(section,
+ label,
+ raw = self.raw).replace(os.linesep, ' ')
except:
if err:
raise error.general('config: no "%s" found in "%s"' % (label, section))
@@ -88,10 +98,12 @@ class configuration:
#
for m in self.macro_filter.findall(rec):
if ':' not in m:
- raise error.general('config: interpolation is ${section:value}: %s' % (m))
+ err = 'config: interpolation is ${section:value}: %s' % (m)
+ raise error.general(err)
section_value = m[2:-1].split(':')
if len(section_value) != 2:
- raise error.general('config: interpolation is ${section:value}: %s' % (m))
+ err = 'config: interpolation is ${section:value}: %s' % (m)
+ raise error.general(err)
try:
ref = self.config.get(section_value[0],
section_value[1],