diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2011-12-30 09:50:05 -0500 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2011-12-30 09:50:05 -0500 |
commit | 5fc3effb174ff6e9fbfd05346134ac8861477884 (patch) | |
tree | 2772e81b9447d2d85247f2aeb5491fe32b48644b /src/lib/Server/Plugin.py | |
parent | 6a9e492eaaca81609e7dd149a660bb24e119572c (diff) | |
download | bcfg2-5fc3effb174ff6e9fbfd05346134ac8861477884.tar.gz bcfg2-5fc3effb174ff6e9fbfd05346134ac8861477884.tar.bz2 bcfg2-5fc3effb174ff6e9fbfd05346134ac8861477884.zip |
added SimpleConfig plugin for easy config files; made Packages and Rules use SimpleConfig; made regex in rules off by default, but configurable in rules.conf
Diffstat (limited to 'src/lib/Server/Plugin.py')
-rw-r--r-- | src/lib/Server/Plugin.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/lib/Server/Plugin.py b/src/lib/Server/Plugin.py index 3dc1cab38..41ac9dc20 100644 --- a/src/lib/Server/Plugin.py +++ b/src/lib/Server/Plugin.py @@ -11,6 +11,7 @@ import posixpath import re import sys import threading +from Bcfg2.Bcfg2Py3k import ConfigParser from lxml.etree import XML, XMLSyntaxError @@ -1133,3 +1134,51 @@ class GroupSpool(Plugin, Generator): return reqid = self.core.fam.AddMonitor(name, self) self.handles[reqid] = relative + +class SimpleConfig(FileBacked, + ConfigParser.SafeConfigParser): + ''' a simple plugin config using ConfigParser ''' + _required = True + + def __init__(self, plugin): + filename = os.path.join(plugin.data, plugin.name.lower() + ".conf") + self.plugin = plugin + self.fam = self.plugin.core.fam + Bcfg2.Server.Plugin.FileBacked.__init__(self, filename) + ConfigParser.SafeConfigParser.__init__(self) + + if (self._required or + (not self._required and os.path.exists(self.name))): + self.fam.AddMonitor(self.name, self) + + def Index(self): + """ Build local data structures """ + for section in self.sections(): + self.remove_section(section) + self.read(self.name) + + def get(self, section, option, default=None): + """ convenience method for getting config items """ + try: + return ConfigParser.SafeConfigParser.get(self, section, option) + except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): + if default is not None: + return default + else: + raise + + def getboolean(self, section, option, default=None): + """ convenience method for getting boolean config items """ + try: + return ConfigParser.SafeConfigParser.getboolean(self, + section, option) + except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): + if default is not None: + return default + else: + raise + except ValueError: + if default is not None: + return default + else: + raise |