summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Lint/__init__.py
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 /src/lib/Server/Lint/__init__.py
parentd7a7b2088255eba51b8dc34b47325ee76747f349 (diff)
downloadbcfg2-9e8e92a6ff91d2e1a90e33b698208f9df68ea283.tar.gz
bcfg2-9e8e92a6ff91d2e1a90e33b698208f9df68ea283.tar.bz2
bcfg2-9e8e92a6ff91d2e1a90e33b698208f9df68ea283.zip
added Genshi template syntax checker, other misc. bcfg2-lint cleanup
Diffstat (limited to 'src/lib/Server/Lint/__init__.py')
-rw-r--r--src/lib/Server/Lint/__init__.py43
1 files changed, 35 insertions, 8 deletions
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: