diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2011-09-19 12:36:24 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2011-09-19 12:36:24 -0400 |
commit | 88c99b4af0840bccba5f2284a904c4034f7351bd (patch) | |
tree | fe2f6214d6222cc01d34a73d41f78e4ed636cc87 /src | |
parent | 56ad9881e7472e695357a630dccb4f5a989209f2 (diff) | |
download | bcfg2-88c99b4af0840bccba5f2284a904c4034f7351bd.tar.gz bcfg2-88c99b4af0840bccba5f2284a904c4034f7351bd.tar.bz2 bcfg2-88c99b4af0840bccba5f2284a904c4034f7351bd.zip |
fixed previous commit so that SingleXMLFileBacked plugins use xinclude, and GroupPatterns uses SingleXMLFileBacked correctly
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/Server/Plugin.py | 45 | ||||
-rw-r--r-- | src/lib/Server/Plugins/GroupPatterns.py | 10 |
2 files changed, 31 insertions, 24 deletions
diff --git a/src/lib/Server/Plugin.py b/src/lib/Server/Plugin.py index 0038632e4..414713793 100644 --- a/src/lib/Server/Plugin.py +++ b/src/lib/Server/Plugin.py @@ -551,12 +551,34 @@ class XMLFileBacked(FileBacked): def __init__(self, filename): self.label = "dummy" self.entries = [] - self.extras = [] FileBacked.__init__(self, filename) def Index(self): """Build local data structures.""" try: + self.xdata = XML(self.data) + except XMLSyntaxError: + logger.error("Failed to parse %s" % (self.name)) + return + self.entries = self.xdata.getchildren() + if self.__identifier__ is not None: + self.label = self.xdata.attrib[self.__identifier__] + + def __iter__(self): + return iter(self.entries) + + +class SingleXMLFileBacked(XMLFileBacked): + """This object is a coherent cache for an independent XML file.""" + def __init__(self, filename, fam): + XMLFileBacked.__init__(self, filename) + self.extras = [] + self.fam = fam + self.fam.AddMonitor(filename, self) + + def Index(self): + """Build local data structures.""" + try: self.xdata = lxml.etree.XML(self.data, base_url=self.name) except lxml.etree.XMLSyntaxError: err = sys.exc_info()[1] @@ -568,7 +590,10 @@ class XMLFileBacked(FileBacked): if included: for name in included: if name not in self.extras: - self.add_monitor(name) + self.fam.AddMonitor(os.path.join(os.path.dirname(self.name), + name), + self) + self.extras.append(name) try: self.xdata.getroottree().xinclude() except lxml.etree.XIncludeError: @@ -579,22 +604,6 @@ class XMLFileBacked(FileBacked): if self.__identifier__ is not None: self.label = self.xdata.attrib[self.__identifier__] - def add_monitor(self, fname): - """Add a fam monitor for an included file""" - self.fam.AddMonitor(os.path.join(os.path.dirname(self.name), fname), - self) - self.extras.append(fname) - - def __iter__(self): - return iter(self.entries) - - -class SingleXMLFileBacked(XMLFileBacked): - """This object is a coherent cache for an independent XML file.""" - def __init__(self, filename, fam): - XMLFileBacked.__init__(self, filename) - fam.AddMonitor(filename, self) - class StructFile(XMLFileBacked): """This file contains a set of structure file formatting logic.""" diff --git a/src/lib/Server/Plugins/GroupPatterns.py b/src/lib/Server/Plugins/GroupPatterns.py index 16b619c51..76a628931 100644 --- a/src/lib/Server/Plugins/GroupPatterns.py +++ b/src/lib/Server/Plugins/GroupPatterns.py @@ -70,18 +70,16 @@ class PatternMap(object): class PatternFile(Bcfg2.Server.Plugin.SingleXMLFileBacked): + __identifier__ = None + def __init__(self, filename, fam): Bcfg2.Server.Plugin.SingleXMLFileBacked.__init__(self, filename, fam) self.patterns = [] def Index(self): + Bcfg2.Server.Plugin.SingleXMLFileBacked.Index(self) self.patterns = [] - try: - parsed = lxml.etree.XML(self.data) - except: - self.logger.error("Failed to read file %s" % self.name) - return - for entry in parsed.findall('GroupPattern'): + for entry in self.xdata.xpath('//GroupPattern'): try: groups = [g.text for g in entry.findall('Group')] for pat_ent in entry.findall('NamePattern'): |