summaryrefslogtreecommitdiffstats
path: root/src/lib/Server
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2011-09-19 11:14:20 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2011-09-19 11:14:20 -0400
commit56ad9881e7472e695357a630dccb4f5a989209f2 (patch)
treec769baacf9f7d6f8c49a16e1b6eebe588efd805e /src/lib/Server
parentfe9b75662276326898458a68744b920ebd9d46b8 (diff)
downloadbcfg2-56ad9881e7472e695357a630dccb4f5a989209f2.tar.gz
bcfg2-56ad9881e7472e695357a630dccb4f5a989209f2.tar.bz2
bcfg2-56ad9881e7472e695357a630dccb4f5a989209f2.zip
made all XMLFileBacked plugins (e.g., GroupPatterns) support XInclude
Diffstat (limited to 'src/lib/Server')
-rw-r--r--src/lib/Server/Plugin.py29
-rw-r--r--src/lib/Server/Plugins/GroupPatterns.py13
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