diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2011-04-14 08:47:24 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2011-04-14 08:47:24 -0400 |
commit | 7cebd3f47926453bdac2b3f2c41804ac83358388 (patch) | |
tree | f14e680147454ef735ba99942f4e2519fe3be415 /src/lib | |
parent | 5819d7182ac703c9f830df1ea2b940fbfa976db7 (diff) | |
download | bcfg2-7cebd3f47926453bdac2b3f2c41804ac83358388.tar.gz bcfg2-7cebd3f47926453bdac2b3f2c41804ac83358388.tar.bz2 bcfg2-7cebd3f47926453bdac2b3f2c41804ac83358388.zip |
added Client tag to StructFile; made PropertyFile inherit from StructFile
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Server/Plugin.py | 34 | ||||
-rw-r--r-- | src/lib/Server/Plugins/Properties.py | 10 |
2 files changed, 25 insertions, 19 deletions
diff --git a/src/lib/Server/Plugin.py b/src/lib/Server/Plugin.py index ac9479d44..69b38c4ff 100644 --- a/src/lib/Server/Plugin.py +++ b/src/lib/Server/Plugin.py @@ -457,17 +457,29 @@ class StructFile(XMLFileBacked): work = {lambda x: True: xdata.getchildren()} while work: (predicate, worklist) = work.popitem() - self.fragments[predicate] = [item for item in worklist if item.tag != 'Group' - and not isinstance(item, lxml.etree._Comment)] - for group in [item for item in worklist if item.tag == 'Group']: - # if only python had forceable early-binding - if group.get('negate', 'false') in ['true', 'True']: - cmd = "lambda x:'%s' not in x.groups and predicate(x)" - else: - cmd = "lambda x:'%s' in x.groups and predicate(x)" - - newpred = eval(cmd % (group.get('name')), {'predicate': predicate}) - work[newpred] = group.getchildren() + 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() def Match(self, metadata): """Return matching fragments of independent.""" diff --git a/src/lib/Server/Plugins/Properties.py b/src/lib/Server/Plugins/Properties.py index 2888ef1d1..c5d2acc44 100644 --- a/src/lib/Server/Plugins/Properties.py +++ b/src/lib/Server/Plugins/Properties.py @@ -4,15 +4,9 @@ import lxml.etree import Bcfg2.Server.Plugin -class PropertyFile(Bcfg2.Server.Plugin.XMLFileBacked): +class PropertyFile(Bcfg2.Server.Plugin.StructFile): """Class for properties files.""" - - def Index(self): - """Build data into an xml object.""" - try: - self.data = lxml.etree.XML(self.data) - except lxml.etree.XMLSyntaxError: - Bcfg2.Server.Plugin.logger.error("Failed to parse %s" % self.name) + pass class PropDirectoryBacked(Bcfg2.Server.Plugin.DirectoryBacked): |