summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2011-07-14 11:27:04 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2011-07-14 11:27:04 -0400
commit9e8e92a6ff91d2e1a90e33b698208f9df68ea283 (patch)
treec30844d0aa61dd05ad2e1d00aa6d1fd0ba49a271
parentd7a7b2088255eba51b8dc34b47325ee76747f349 (diff)
downloadbcfg2-9e8e92a6ff91d2e1a90e33b698208f9df68ea283.tar.gz
bcfg2-9e8e92a6ff91d2e1a90e33b698208f9df68ea283.tar.bz2
bcfg2-9e8e92a6ff91d2e1a90e33b698208f9df68ea283.zip
added Genshi template syntax checker, other misc. bcfg2-lint cleanup
-rw-r--r--src/lib/Server/Lint/Bundles.py1
-rw-r--r--src/lib/Server/Lint/Comments.py1
-rw-r--r--src/lib/Server/Lint/Duplicates.py1
-rwxr-xr-xsrc/lib/Server/Lint/Genshi.py27
-rw-r--r--src/lib/Server/Lint/InfoXML.py1
-rw-r--r--src/lib/Server/Lint/MergeFiles.py1
-rw-r--r--src/lib/Server/Lint/Pkgmgr.py1
-rw-r--r--src/lib/Server/Lint/RequiredAttrs.py1
-rw-r--r--src/lib/Server/Lint/Validate.py1
-rw-r--r--src/lib/Server/Lint/__init__.py43
10 files changed, 62 insertions, 16 deletions
diff --git a/src/lib/Server/Lint/Bundles.py b/src/lib/Server/Lint/Bundles.py
index e90159f7c..67ae14fbd 100644
--- a/src/lib/Server/Lint/Bundles.py
+++ b/src/lib/Server/Lint/Bundles.py
@@ -4,7 +4,6 @@ import Bcfg2.Server.Lint
class Bundles(Bcfg2.Server.Lint.ServerPlugin):
""" Perform various bundle checks """
- @Bcfg2.Server.Lint.returnErrors
def Run(self):
""" run plugin """
if 'Bundler' in self.core.plugins:
diff --git a/src/lib/Server/Lint/Comments.py b/src/lib/Server/Lint/Comments.py
index 09443d4c0..1ea5f295e 100644
--- a/src/lib/Server/Lint/Comments.py
+++ b/src/lib/Server/Lint/Comments.py
@@ -8,7 +8,6 @@ class Comments(Bcfg2.Server.Lint.ServerPlugin):
Bcfg2.Server.Lint.ServerPlugin.__init__(self, *args, **kwargs)
self.config_cache = {}
- @Bcfg2.Server.Lint.returnErrors
def Run(self):
self.check_bundles()
self.check_properties()
diff --git a/src/lib/Server/Lint/Duplicates.py b/src/lib/Server/Lint/Duplicates.py
index 517f0dd7b..75f620603 100644
--- a/src/lib/Server/Lint/Duplicates.py
+++ b/src/lib/Server/Lint/Duplicates.py
@@ -10,7 +10,6 @@ class Duplicates(Bcfg2.Server.Lint.ServerPlugin):
self.clients_xdata = None
self.load_xdata()
- @Bcfg2.Server.Lint.returnErrors
def Run(self):
""" run plugin """
# only run this plugin if we were not given a list of files.
diff --git a/src/lib/Server/Lint/Genshi.py b/src/lib/Server/Lint/Genshi.py
new file mode 100755
index 000000000..552c495b2
--- /dev/null
+++ b/src/lib/Server/Lint/Genshi.py
@@ -0,0 +1,27 @@
+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)
+
+ 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 fname.endswith(".genshi") or fname.endswith(".newtxt"):
+ try:
+ loader.load(sdata.name,
+ cls=genshi.template.NewTextTemplate)
+ except genshi.template.TemplateSyntaxError, err:
+ self.LintError("genshi-syntax-error",
+ "Genshi syntax error: %s" % err)
diff --git a/src/lib/Server/Lint/InfoXML.py b/src/lib/Server/Lint/InfoXML.py
index c88e54e95..2054e23bf 100644
--- a/src/lib/Server/Lint/InfoXML.py
+++ b/src/lib/Server/Lint/InfoXML.py
@@ -5,7 +5,6 @@ import Bcfg2.Server.Lint
class InfoXML(Bcfg2.Server.Lint.ServerPlugin):
""" ensure that all config files have an info.xml file"""
- @Bcfg2.Server.Lint.returnErrors
def Run(self):
if 'Cfg' in self.core.plugins:
for filename, entryset in self.core.plugins['Cfg'].entries.items():
diff --git a/src/lib/Server/Lint/MergeFiles.py b/src/lib/Server/Lint/MergeFiles.py
index 1e177acff..27e7aa99a 100644
--- a/src/lib/Server/Lint/MergeFiles.py
+++ b/src/lib/Server/Lint/MergeFiles.py
@@ -8,7 +8,6 @@ class MergeFiles(Bcfg2.Server.Lint.ServerPlugin):
""" find Probes or Cfg files with multiple similar files that
might be merged into one """
- @Bcfg2.Server.Lint.returnErrors
def Run(self):
if 'Cfg' in self.core.plugins:
self.check_cfg()
diff --git a/src/lib/Server/Lint/Pkgmgr.py b/src/lib/Server/Lint/Pkgmgr.py
index 39c601617..3960a8cf9 100644
--- a/src/lib/Server/Lint/Pkgmgr.py
+++ b/src/lib/Server/Lint/Pkgmgr.py
@@ -3,7 +3,6 @@ import Bcfg2.Server.Lint
class Pkgmgr(Bcfg2.Server.Lint.ServerPlugin):
""" find duplicate Pkgmgr entries with the same priority """
- @Bcfg2.Server.Lint.returnErrors
def Run(self):
if 'Pkgmgr' not in self.core.plugins:
self.logger.info("Pkgmgr server plugin is not enabled, skipping Pkgmgr lint checks")
diff --git a/src/lib/Server/Lint/RequiredAttrs.py b/src/lib/Server/Lint/RequiredAttrs.py
index cbb4395c4..cb69149b5 100644
--- a/src/lib/Server/Lint/RequiredAttrs.py
+++ b/src/lib/Server/Lint/RequiredAttrs.py
@@ -18,7 +18,6 @@ class RequiredAttrs(Bcfg2.Server.Lint.ServerPlugin):
'nonexistent': ['name'],
'permissions': ['name', 'owner', 'group', 'perms']}
- @Bcfg2.Server.Lint.returnErrors
def Run(self):
self.check_rules()
self.check_bundles()
diff --git a/src/lib/Server/Lint/Validate.py b/src/lib/Server/Lint/Validate.py
index 8a8406e73..8331fc02d 100644
--- a/src/lib/Server/Lint/Validate.py
+++ b/src/lib/Server/Lint/Validate.py
@@ -34,7 +34,6 @@ class Validate(Bcfg2.Server.Lint.ServerlessPlugin):
self.filelists = {}
self.get_filelists()
- @Bcfg2.Server.Lint.returnErrors
def Run(self):
schemadir = self.config['schema']
diff --git a/src/lib/Server/Lint/__init__.py b/src/lib/Server/Lint/__init__.py
index 63cb2463b..888f57d87 100644
--- a/src/lib/Server/Lint/__init__.py
+++ b/src/lib/Server/Lint/__init__.py
@@ -7,7 +7,8 @@ __all__ = ['Bundles',
'MergeFiles',
'Pkgmgr',
'RequiredAttrs',
- 'Validate']
+ 'Validate',
+ 'Genshi']
import logging
import os.path
@@ -15,10 +16,33 @@ from copy import copy
import textwrap
import lxml.etree
import Bcfg2.Logger
-
-def returnErrors(fn):
- """ Decorator for Run method that returns error counts """
- return fn
+import fcntl
+import termios
+import struct
+
+def _ioctl_GWINSZ(fd):
+ try:
+ cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
+ except:
+ return None
+ return cr
+
+def get_termsize():
+ """ get a tuple of (width, height) giving the size of the terminal """
+ cr = _ioctl_GWINSZ(0) or _ioctl_GWINSZ(1) or _ioctl_GWINSZ(2)
+ if not cr:
+ try:
+ fd = os.open(os.ctermid(), os.O_RDONLY)
+ cr = _ioctl_GWINSZ(fd)
+ os.close(fd)
+ except:
+ pass
+ if not cr:
+ try:
+ cr = (os.environ['LINES'], os.environ['COLUMNS'])
+ except KeyError:
+ cr = (25, 80)
+ return int(cr[1]), int(cr[0])
class Plugin (object):
""" base class for ServerlessPlugin and ServerPlugin """
@@ -89,7 +113,8 @@ class ErrorHandler (object):
"xml-failed-to-verify":"error",
"merge-cfg":"warning",
"merge-probes":"warning",
- "input-output-error": "error"}
+ "input-output-error": "error",
+ "genshi-syntax-error": "error"}
def __init__(self, config=None):
self.errors = 0
@@ -97,8 +122,10 @@ class ErrorHandler (object):
self.logger = logging.getLogger('bcfg2-lint')
- self._wrapper = textwrap.TextWrapper(initial_indent = " ",
- subsequent_indent = " ")
+ termsize = get_termsize()
+ self._wrapper = textwrap.TextWrapper(initial_indent=" ",
+ subsequent_indent=" ",
+ width=termsize[0])
self._handlers = {}
if config is not None: