blob: 74142b4468849c4c84e92da9fcc511959a848330 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
import sys
import genshi.template
import Bcfg2.Server.Lint
class Genshi(Bcfg2.Server.Lint.ServerPlugin):
""" Check Genshi templates for syntax errors """
def Run(self):
""" run plugin """
loader = genshi.template.TemplateLoader()
for plugin in ['Cfg', 'TGenshi']:
if plugin in self.core.plugins:
self.check_files(self.core.plugins[plugin].entries,
loader=loader)
@classmethod
def Errors(cls):
return {"genshi-syntax-error":"error"}
def check_files(self, entries, loader=None):
if loader is None:
loader = genshi.template.TemplateLoader()
for eset in entries.values():
for fname, sdata in list(eset.entries.items()):
if (self.HandlesFile(fname) and
(fname.endswith(".genshi") or fname.endswith(".newtxt"))):
try:
loader.load(sdata.name,
cls=genshi.template.NewTextTemplate)
except genshi.template.TemplateSyntaxError:
err = sys.exc_info()[1]
self.LintError("genshi-syntax-error",
"Genshi syntax error: %s" % err)
|