diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2011-04-14 11:20:58 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2011-04-14 11:20:58 -0400 |
commit | 6e7ba79340635aba26ee7f1980ce91714b853188 (patch) | |
tree | 29573ac22b5d48eb9da5520df8417a2b7fff607d | |
parent | e861c6134e556a90feda1c3681c12e68398daf5e (diff) | |
download | bcfg2-6e7ba79340635aba26ee7f1980ce91714b853188.tar.gz bcfg2-6e7ba79340635aba26ee7f1980ce91714b853188.tar.bz2 bcfg2-6e7ba79340635aba26ee7f1980ce91714b853188.zip |
fixed PropertyFile.Index() to populate .data as a side effect
-rw-r--r-- | src/lib/Server/Plugins/Properties.py | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/src/lib/Server/Plugins/Properties.py b/src/lib/Server/Plugins/Properties.py index c5d2acc44..b34bde998 100644 --- a/src/lib/Server/Plugins/Properties.py +++ b/src/lib/Server/Plugins/Properties.py @@ -6,7 +6,43 @@ import Bcfg2.Server.Plugin class PropertyFile(Bcfg2.Server.Plugin.StructFile): """Class for properties files.""" - pass + def Index(self): + """Build internal data structures.""" + if type(self.data) is not lxml.etree._Element: + try: + self.data = lxml.etree.XML(self.data) + except lxml.etree.XMLSyntaxError: + Bcfg2.Server.Plugin.logger.error("Failed to parse %s" % + self.name) + + self.fragments = {} + work = {lambda x: True: self.data.getchildren()} + while work: + (predicate, worklist) = work.popitem() + self.fragments[predicate] = \ + [item for item in worklist + if (item.tag != 'Group' and + item.tag != 'Client' and + not isinstance(item, + lxml.etree._Comment))] + for item in worklist: + cmd = None + if item.tag == 'Group': + if item.get('negate', 'false').lower() == 'true': + cmd = "lambda x:'%s' not in x.groups and predicate(x)" + else: + cmd = "lambda x:'%s' in x.groups and predicate(x)" + elif item.tag == 'Client': + if item.get('negate', 'false').lower() == 'true': + cmd = "lambda x:x.hostname != '%s' and predicate(x)" + else: + cmd = "lambda x:x.hostname == '%s' and predicate(x)" + # else, ignore item + if cmd is not None: + newpred = eval(cmd % item.get('name'), + {'predicate':predicate}) + work[newpred] = item.getchildren() + class PropDirectoryBacked(Bcfg2.Server.Plugin.DirectoryBacked): |