diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-01-09 11:54:38 -0500 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-01-09 11:54:38 -0500 |
commit | 82cdfeba16096145c1fc8e6bd800760809e7f580 (patch) | |
tree | a898c5eaf068d74221a738a845b0aa165cf9cb82 /src | |
parent | 0fc73208b80c1e4a158ea02e31c4fb212b6d0b39 (diff) | |
download | bcfg2-82cdfeba16096145c1fc8e6bd800760809e7f580.tar.gz bcfg2-82cdfeba16096145c1fc8e6bd800760809e7f580.tar.bz2 bcfg2-82cdfeba16096145c1fc8e6bd800760809e7f580.zip |
added bcfg2-lint plugin for GroupPatterns
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/Server/Lint/GroupPatterns.py | 31 | ||||
-rw-r--r-- | src/lib/Server/Lint/__init__.py | 5 |
2 files changed, 34 insertions, 2 deletions
diff --git a/src/lib/Server/Lint/GroupPatterns.py b/src/lib/Server/Lint/GroupPatterns.py new file mode 100644 index 000000000..b69d7a5d8 --- /dev/null +++ b/src/lib/Server/Lint/GroupPatterns.py @@ -0,0 +1,31 @@ +import sys +import Bcfg2.Server.Lint +from Bcfg2.Server.Plugins.GroupPatterns import PatternMap + +class GroupPatterns(Bcfg2.Server.Lint.ServerPlugin): + """ Check Genshi templates for syntax errors """ + + def Run(self): + """ run plugin """ + if 'GroupPatterns' in self.core.plugins: + cfg = self.core.plugins['GroupPatterns'].config + for entry in cfg.xdata.xpath('//GroupPattern'): + groups = [g.text for g in entry.findall('Group')] + self.check(entry, groups, ptype='NamePattern') + self.check(entry, groups, ptype='NameRange') + + def check(self, entry, groups, ptype="NamePattern"): + if ptype == "NamePattern": + pmap = lambda p: PatternMap(p, None, groups) + else: + pmap = lambda p: PatternMap(None, p, groups) + + for el in entry.findall(ptype): + pat = el.text + try: + pmap(pat) + except: + err = sys.exc_info()[1] + self.LintError("pattern-fails-to-initialize", + "Failed to initialize %s %s for %s: %s" % + (ptype, pat, entry.get('pattern'), err)) diff --git a/src/lib/Server/Lint/__init__.py b/src/lib/Server/Lint/__init__.py index f47059ac4..a9d57c46c 100644 --- a/src/lib/Server/Lint/__init__.py +++ b/src/lib/Server/Lint/__init__.py @@ -117,8 +117,9 @@ class ErrorHandler (object): "xml-failed-to-verify":"error", "merge-cfg":"warning", "merge-probes":"warning", - "input-output-error": "error", - "genshi-syntax-error": "error"} + "input-output-error":"error", + "genshi-syntax-error":"error", + "pattern-fails-to-initialize":"error"} def __init__(self, config=None): self.errors = 0 |