full.section.name.include files/to/include
Description of this include statement
-
-Dots in section/option names may be escaped with a backslash. For instance,
-with the following section description
-
-charon.filelog./var/log/daemon\.log {}
- Section to define logging into /var/log/daemon.log
-
-/var/log/daemon.log will be the name of the last section.
"""
import sys
@total_ordering
class ConfigOption:
"""Representing a configuration option or described section in strongswan.conf"""
- def __init__(self, path, default = None, section = False, commented = False, include = False):
- self.path = path
- self.name = path[-1]
- self.fullname = '.'.join(path)
+ def __init__(self, fullname, default = None, section = False, commented = False, include = False):
+ self.path = fullname.split('.')
+ self.name = self.path[-1]
+ self.fullname = fullname
self.default = default
self.section = section
self.commented = commented
if m:
if self.__current:
self.__add_option(self.__current)
- path = self.__split_name(m.group('name'))
- self.__current = ConfigOption(path, m.group('default'),
+ self.__current = ConfigOption(m.group('name'), m.group('default'),
commented = not m.group('assign'))
return
# section definition
if m:
if self.__current:
self.__add_option(self.__current)
- path = self.__split_name(m.group('name'))
- self.__current = ConfigOption(path, section = True,
+ self.__current = ConfigOption(m.group('name'), section = True,
commented = m.group('comment'))
return
# include definition
if m:
if self.__current:
self.__add_option(self.__current)
- path = self.__split_name(m.group('name'))
- self.__current = ConfigOption(path, m.group('pattern'), include = True)
+ self.__current = ConfigOption(m.group('name'), m.group('pattern'), include = True)
return
# paragraph separator
m = re.match(r'^\s*$', line)
if m and self.__current:
self.__current.add(m.group('text'))
- def __split_name(self, name):
- """Split the given full name in a list of section/option names"""
- return [x.replace('\.', '.') for x in re.split(r'(?<!\\)\.', name)]
-
def __add_option(self, option):
"""Adds the given option to the abstract storage"""
option.desc = [desc for desc in option.desc if len(desc)]
"""Searches/Creates the option (section) based on a list of section names"""
option = None
options = self.options
- for i, name in enumerate(path, 1):
+ fullname = ""
+ for name in path:
+ fullname += '.' + name if len(fullname) else name
option = next((x for x in options if x.name == name and x.section), None)
if not option:
if not create:
break
- option = ConfigOption(path[:i], section = True)
+ option = ConfigOption(fullname, section = True)
options.append(option)
if self.sort:
options.sort()
def get_option(self, name):
"""Retrieves the option with the given name"""
- return self.__get_option(self.__split_name(name))
+ return self.__get_option(name.split('.'))
class TagReplacer:
"""Replaces formatting tags in text"""