diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2011-08-31 14:28:12 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2011-08-31 14:28:12 -0400 |
commit | acdbf137595b45de2dda5b9ba3b33a1bb836e075 (patch) | |
tree | 650d64241c1e57941ba54d673a76686dc43ba488 /src/lib/Server/Plugin.py | |
parent | 5b542f5d57ed6c7fdb7f9dc41427491eab5e7a45 (diff) | |
download | bcfg2-acdbf137595b45de2dda5b9ba3b33a1bb836e075.tar.gz bcfg2-acdbf137595b45de2dda5b9ba3b33a1bb836e075.tar.bz2 bcfg2-acdbf137595b45de2dda5b9ba3b33a1bb836e075.zip |
added regex support to Rules
Diffstat (limited to 'src/lib/Server/Plugin.py')
-rw-r--r-- | src/lib/Server/Plugin.py | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/src/lib/Server/Plugin.py b/src/lib/Server/Plugin.py index 11d026c11..1e34b9ca4 100644 --- a/src/lib/Server/Plugin.py +++ b/src/lib/Server/Plugin.py @@ -728,7 +728,8 @@ class XMLSrc(XMLFileBacked): self.priority = int(xdata.get('priority')) except (ValueError, TypeError): if not self.noprio: - logger.error("Got bogus priority %s for file %s" % (xdata.get('priority'), self.name)) + logger.error("Got bogus priority %s for file %s" % + (xdata.get('priority'), self.name)) del xdata, data def Cache(self, metadata): @@ -778,16 +779,25 @@ class PrioDir(Plugin, Generator, XMLDirectoryBacked): except KeyError: self.Entries[itype] = {child: self.BindEntry} + def _matches(self, entry, metadata, rules): + return entry.get('name') in rules + def BindEntry(self, entry, metadata): - """Check package lists of package entries.""" - name = entry.get('name') - if False in [src.Cache(metadata) for src in - list(self.entries.values())]: + attrs = self.get_attrs(entry, metadata) + for key, val in list(attrs.items()): + entry.attrib[key] = val + + def get_attrs(self, entry, metadata): + """ get a list of attributes to add to the entry during the bind """ + if False in [src.Cache(metadata) + for src in list(self.entries.values())]: self.logger.error("Called before data loaded") raise PluginExecutionError matching = [src for src in list(self.entries.values()) - if src.cache and entry.tag in src.cache[1] - and name in src.cache[1][entry.tag]] + if (src.cache and + entry.tag in src.cache[1] and + self._matches(entry, metadata, + src.cache[1][entry.tag]))] if len(matching) == 0: raise PluginExecutionError elif len(matching) == 1: @@ -804,13 +814,18 @@ class PrioDir(Plugin, Generator, XMLDirectoryBacked): raise PluginExecutionError index = prio.index(max(prio)) - data = matching[index].cache[1][entry.tag][name] + for rname in matching[index].cache[1][entry.tag]: + if self._matches(entry, metadata, rname): + data = matching[index].cache[1][entry.tag][rname] + break if '__text__' in data: entry.text = data['__text__'] if '__children__' in data: [entry.append(copy.deepcopy(item)) for item in data['__children__']] - [entry.attrib.__setitem__(key, data[key]) for key in list(data.keys()) \ - if not key.startswith('__')] + + return dict([(key, data[key]) + for key in list(data.keys()) + if not key.startswith('__')]) # new unified EntrySet backend |