summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Lint/Bundles.py
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2011-04-25 10:45:41 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2011-04-25 10:45:41 -0400
commit17b8ceb17e0ee775a667d2f92b2b192e567b2df6 (patch)
tree103ade296f16fa1457abcb7f97fd5d158b435385 /src/lib/Server/Lint/Bundles.py
parent66642f84fd71e9230245b11718bf9a7e96ba0c7f (diff)
downloadbcfg2-17b8ceb17e0ee775a667d2f92b2b192e567b2df6.tar.gz
bcfg2-17b8ceb17e0ee775a667d2f92b2b192e567b2df6.tar.bz2
bcfg2-17b8ceb17e0ee775a667d2f92b2b192e567b2df6.zip
Various bcfg2-lint fixes:
* check for all plugins before referencing them, since in --stdin mode even plugins like Bundler may not be instantiated * formatting fixes * made Bundles plugin work with or without genshi installed * fixed name of plugin in example bcfg2-lint.conf
Diffstat (limited to 'src/lib/Server/Lint/Bundles.py')
-rw-r--r--src/lib/Server/Lint/Bundles.py81
1 files changed, 43 insertions, 38 deletions
diff --git a/src/lib/Server/Lint/Bundles.py b/src/lib/Server/Lint/Bundles.py
index b242239ae..417f76c2d 100644
--- a/src/lib/Server/Lint/Bundles.py
+++ b/src/lib/Server/Lint/Bundles.py
@@ -1,56 +1,61 @@
import lxml.etree
import Bcfg2.Server.Lint
-
+
class Bundles(Bcfg2.Server.Lint.ServerPlugin):
""" Perform various bundle checks """
@Bcfg2.Server.Lint.returnErrors
def Run(self):
""" run plugin """
- self.missing_bundles()
- self.bundle_names()
- self.sgenshi_groups()
+ if 'Bundler' in self.core.plugins:
+ self.missing_bundles()
+ for bundle in self.core.plugins['Bundler'].entries.values():
+ if self.HandlesFile(bundle.name):
+ if (Bcfg2.Server.Plugins.Bundler.have_genshi and
+ type(bundle) is
+ Bcfg2.Server.Plugins.SGenshi.SGenshiTemplateFile):
+ self.sgenshi_groups(bundle)
+ else:
+ self.bundle_names(bundle)
def missing_bundles(self):
""" find bundles listed in Metadata but not implemented in Bundler """
- groupdata = self.metadata.groups_xml.xdata
- ref_bundles = set([b.get("name")
- for b in groupdata.findall("//Bundle")])
+ if self.files is None:
+ # when given a list of files on stdin, this check is
+ # useless, so skip it
+ groupdata = self.metadata.groups_xml.xdata
+ ref_bundles = set([b.get("name")
+ for b in groupdata.findall("//Bundle")])
- allbundles = self.core.plugins['Bundler'].entries.keys()
- for bundle in ref_bundles:
- xmlbundle = "%s.xml" % bundle
- genshibundle = "%s.genshi" % bundle
- if xmlbundle not in allbundles and genshibundle not in allbundles:
- self.LintError("Bundle %s referenced, but does not exist" %
- bundle)
+ allbundles = self.core.plugins['Bundler'].entries.keys()
+ for bundle in ref_bundles:
+ xmlbundle = "%s.xml" % bundle
+ genshibundle = "%s.genshi" % bundle
+ if (xmlbundle not in allbundles and
+ genshibundle not in allbundles):
+ self.LintError("Bundle %s referenced, but does not exist" %
+ bundle)
- def bundle_names(self):
+ def bundle_names(self, bundle):
""" verify bundle name attribute matches filename """
- for bundle in self.core.plugins['Bundler'].entries.values():
- if self.HandlesFile(bundle.name):
- try:
- xdata = lxml.etree.XML(bundle.data)
- except AttributeError:
- # genshi template
- xdata = lxml.etree.parse(bundle.template.filepath).getroot()
+ try:
+ xdata = lxml.etree.XML(bundle.data)
+ except AttributeError:
+ # genshi template
+ xdata = lxml.etree.parse(bundle.template.filepath).getroot()
- fname = bundle.name.split('Bundler/')[1].split('.')[0]
- bname = xdata.get('name')
- if fname != bname:
- self.LintWarning("Inconsistent bundle name: filename is %s, bundle name is %s" %
- (fname, bname))
+ fname = bundle.name.split('Bundler/')[1].split('.')[0]
+ bname = xdata.get('name')
+ if fname != bname:
+ self.LintWarning("Inconsistent bundle name: filename is %s, bundle name is %s" %
+ (fname, bname))
- def sgenshi_groups(self):
+ def sgenshi_groups(self, bundle):
""" ensure that Genshi Bundles do not include <Group> tags,
which are not supported """
- for bundle in self.core.plugins['Bundler'].entries.values():
- if self.HandlesFile(bundle.name):
- if (type(bundle) is
- Bcfg2.Server.Plugins.SGenshi.SGenshiTemplateFile):
- xdata = lxml.etree.parse(bundle.name)
- groups = [self.RenderXML(g)
- for g in xdata.getroottree().findall("//Group")]
- if groups:
- self.LintWarning("<Group> tag is not allowed in SGenshi Bundle:\n%s" %
- "\n".join(groups))
+ xdata = lxml.etree.parse(bundle.name)
+ groups = [self.RenderXML(g)
+ for g in xdata.getroottree().findall("//Group")]
+ if groups:
+ self.LintWarning("<Group> tag is not allowed in SGenshi Bundle:\n%s" %
+ "\n".join(groups))