diff options
Diffstat (limited to 'src/lib/Server/Plugin.py')
-rw-r--r-- | src/lib/Server/Plugin.py | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/src/lib/Server/Plugin.py b/src/lib/Server/Plugin.py index bf55ad271..1a6399d48 100644 --- a/src/lib/Server/Plugin.py +++ b/src/lib/Server/Plugin.py @@ -365,7 +365,8 @@ class FileBacked(object): self.data = BUILTIN_FILE_TYPE(self.name).read() self.Index() except IOError: - logger.error("Failed to read file %s" % (self.name)) + err = sys.exc_info()[1] + logger.error("Failed to read file %s: %s" % (self.name, err)) def Index(self): """Update local data structures based on current file state""" @@ -518,11 +519,10 @@ class DirectoryBacked(object): if ((event.filename[-1] == '~') or (event.filename[:2] == '.#') or (event.filename[-4:] == '.swp') or - (event.filename in ['SCCS', '.svn', '4913'])): + (event.filename in ['SCCS', '.svn', '4913']) or + (not self.patterns.match(event.filename))): return if action in ['exists', 'created']: - if not self.patterns.match(event.filename): - return self.add_entry(relpath, event) elif action == 'changed': if relpath in self.entries: @@ -572,7 +572,38 @@ 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) + 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] + logger.error("Failed to parse %s: %s" % (self.name, 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.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: + err = sys.exc_info()[1] + logger.error("XInclude failed on %s: %s" % (self.name, err)) + + + self.entries = self.xdata.getchildren() + if self.__identifier__ is not None: + self.label = self.xdata.attrib[self.__identifier__] class StructFile(XMLFileBacked): @@ -789,10 +820,10 @@ class PrioDir(Plugin, Generator, XMLDirectoryBacked): 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 + for src in list(self.entries.values()): + if src.Cache(metadata) == False: + 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 |