Changeset 89dcdbc in rtems-tools


Ignore:
Timestamp:
Jun 6, 2019, 10:49:22 AM (5 months ago)
Author:
Chris Johns <chrisj@…>
Branches:
master
Children:
2b27eec
Parents:
af9b561
git-author:
Chris Johns <chrisj@…> (06/06/19 10:49:22)
git-committer:
Chris Johns <chrisj@…> (06/11/19 01:00:30)
Message:

rtemstoolkit/configuration: Add get_sections() to get the sections.

  • Fix module access when catching exceptions.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • rtemstoolkit/configuration.py

    raf9b561 r89dcdbc  
    4141from rtemstoolkit import path
    4242
     43try:
     44    import configparser
     45    has_strict = True
     46except:
     47    # python2
     48    import ConfigParser as configparser
     49    has_strict = False
     50
    4351class configuration:
    4452
    4553    def __init__(self, raw = True):
    4654        self.raw = True
    47         try:
    48             import configparser
     55        if has_strict:
    4956            self.config = configparser.ConfigParser(strict = False)
    50         except:
    51             # python2
    52             import ConfigParser as configparser
     57        else:
    5358            self.config = configparser.ConfigParser()
    5459        self.ini = None
     
    7580        return os.linesep.join(s)
    7681
     82    def get_sections(self):
     83        return self.config.sections()
     84
    7785    def get_item(self, section, label, err = True):
    7886        try:
    79             rec = self.config.get(section, label, raw = self.raw).replace(os.linesep, ' ')
     87            rec = self.config.get(section,
     88                                  label,
     89                                  raw = self.raw).replace(os.linesep, ' ')
    8090        except:
    8191            if err:
     
    8999        for m in self.macro_filter.findall(rec):
    90100            if ':' not in m:
    91                 raise error.general('config: interpolation is ${section:value}: %s' % (m))
     101                err = 'config: interpolation is ${section:value}: %s' % (m)
     102                raise error.general(err)
    92103            section_value = m[2:-1].split(':')
    93104            if len(section_value) != 2:
    94                 raise error.general('config: interpolation is ${section:value}: %s' % (m))
     105                err = 'config: interpolation is ${section:value}: %s' % (m)
     106                raise error.general(err)
    95107            try:
    96108                ref = self.config.get(section_value[0],
Note: See TracChangeset for help on using the changeset viewer.