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/Plugins/Rules.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/Plugins/Rules.py')
-rw-r--r-- | src/lib/Server/Plugins/Rules.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/lib/Server/Plugins/Rules.py b/src/lib/Server/Plugins/Rules.py index a146dca6a..fde0f3d59 100644 --- a/src/lib/Server/Plugins/Rules.py +++ b/src/lib/Server/Plugins/Rules.py @@ -4,12 +4,20 @@ __revision__ = '$Revision$' import re import Bcfg2.Server.Plugin +class RulesConfig(Bcfg2.Server.Plugin.SimpleConfig): + _required = False + class Rules(Bcfg2.Server.Plugin.PrioDir): """This is a generator that handles service assignments.""" name = 'Rules' __version__ = '$Id$' __author__ = 'bcfg-dev@mcs.anl.gov' + def __init__(self, core, datastore): + Bcfg2.Server.Plugin.PrioDir.__init__(self, core, datastore) + self.config = RulesConfig(self) + self._regex_cache = dict() + def HandlesEntry(self, entry, metadata): if entry.tag in self.Entries: return self._matches(entry, metadata, @@ -28,10 +36,14 @@ class Rules(Bcfg2.Server.Plugin.PrioDir): def _matches(self, entry, metadata, rules): if Bcfg2.Server.Plugin.PrioDir._matches(self, entry, metadata, rules): return True - else: + elif self._regex_enabled: # attempt regular expression matching for rule in rules: - if re.match("%s$" % rule, entry.get('name')): + if rule not in self._regex_cache: + self._regex_cache[rule] = re.compile("%s$" % rule) + if self._regex_cache[rule].match(entry.get('name')): return True return False + def _regex_enabled(self): + return self.config.getboolean("rules", "regex", default=False) |