diff options
Diffstat (limited to 'src/lib/Server')
-rw-r--r-- | src/lib/Server/Plugin.py | 29 | ||||
-rw-r--r-- | src/lib/Server/Plugins/GroupPatterns.py | 13 |
2 files changed, 31 insertions, 11 deletions
diff --git a/src/lib/Server/Plugin.py b/src/lib/Server/Plugin.py index 36423e5cd..0038632e4 100644 --- a/src/lib/Server/Plugin.py +++ b/src/lib/Server/Plugin.py @@ -551,19 +551,40 @@ 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.xdata = lxml.etree.XML(self.data, base_url=self.name) + except lxml.etree.XMLSyntaxError: + err = sys.exc_info()[1] + logger.error("Failed to parse %s" % err) + raise Bcfg2.Server.Plugin.PluginInitError + + included = [ent.get('href') + for ent in self.xdata.findall('./{http://www.w3.org/2001/XInclude}include')] + if included: + for name in included: + if name not in self.extras: + self.add_monitor(name) + try: + self.xdata.getroottree().xinclude() + except lxml.etree.XIncludeError: + err = sys.exc_info()[1] + logger.error("Failed to parse %s" % err) + self.entries = self.xdata.getchildren() 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) diff --git a/src/lib/Server/Plugins/GroupPatterns.py b/src/lib/Server/Plugins/GroupPatterns.py index 7faead39a..16b619c51 100644 --- a/src/lib/Server/Plugins/GroupPatterns.py +++ b/src/lib/Server/Plugins/GroupPatterns.py @@ -79,7 +79,7 @@ class PatternFile(Bcfg2.Server.Plugin.SingleXMLFileBacked): try: parsed = lxml.etree.XML(self.data) except: - Bcfg2.Server.Plugin.logger.error("Failed to read file %s" % self.name) + self.logger.error("Failed to read file %s" % self.name) return for entry in parsed.findall('GroupPattern'): try: @@ -91,9 +91,8 @@ class PatternFile(Bcfg2.Server.Plugin.SingleXMLFileBacked): rng = range_ent.text self.patterns.append(PatternMap(None, rng, groups)) except: - Bcfg2.Server.Plugin.logger.error(\ - "GroupPatterns: Failed to initialize pattern %s" % \ - (entry.get('pattern'))) + self.logger.error("GroupPatterns: Failed to initialize pattern " + "%s" % entry.get('pattern')) def process_patterns(self, hostname): ret = [] @@ -103,9 +102,9 @@ class PatternFile(Bcfg2.Server.Plugin.SingleXMLFileBacked): if gn is not None: ret.extend(gn) except: - Bcfg2.Server.Plugin.logger.error(\ - "GroupPatterns: Failed to process pattern %s for %s" % \ - (pattern.pattern, hostname), exc_info=1) + self.logger.error("GroupPatterns: Failed to process pattern %s " + "for %s" % (pattern.pattern, hostname), + exc_info=1) return ret |