diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2011-08-05 14:00:59 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2011-08-05 14:00:59 -0400 |
commit | ca4029ea2186979604725428193a15fe22ca1b3c (patch) | |
tree | f9060aaabe396884e50d23bcf2f168ae51658d2c /src | |
parent | 97fe17f4709a0d7c83e1be0a4c65995fa5845a10 (diff) | |
download | bcfg2-ca4029ea2186979604725428193a15fe22ca1b3c.tar.gz bcfg2-ca4029ea2186979604725428193a15fe22ca1b3c.tar.bz2 bcfg2-ca4029ea2186979604725428193a15fe22ca1b3c.zip |
don't try to wrap bcfg2-lint output if it's not connected to a tty
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/Server/Lint/__init__.py | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/lib/Server/Lint/__init__.py b/src/lib/Server/Lint/__init__.py index 05a824991..f15c90557 100644 --- a/src/lib/Server/Lint/__init__.py +++ b/src/lib/Server/Lint/__init__.py @@ -11,7 +11,8 @@ __all__ = ['Bundles', 'Genshi'] import logging -import os.path +import os +import sys from copy import copy import textwrap import lxml.etree @@ -29,6 +30,8 @@ def _ioctl_GWINSZ(fd): def get_termsize(): """ get a tuple of (width, height) giving the size of the terminal """ + if not sys.stdout.isatty(): + return None cr = _ioctl_GWINSZ(0) or _ioctl_GWINSZ(1) or _ioctl_GWINSZ(2) if not cr: try: @@ -41,7 +44,7 @@ def get_termsize(): try: cr = (os.environ['LINES'], os.environ['COLUMNS']) except KeyError: - cr = (25, 80) + return None return int(cr[1]), int(cr[0]) class Plugin (object): @@ -124,9 +127,12 @@ class ErrorHandler (object): self.logger = logging.getLogger('bcfg2-lint') termsize = get_termsize() - self._wrapper = textwrap.TextWrapper(initial_indent=" ", - subsequent_indent=" ", - width=termsize[0]) + if termsize is not None: + self._wrapper = textwrap.TextWrapper(initial_indent=" ", + subsequent_indent=" ", + width=termsize[0]) + else: + self._wrapper = None self._handlers = {} if config is not None: @@ -181,7 +187,10 @@ class ErrorHandler (object): rawlines = msg.splitlines() firstline = True for rawline in rawlines: - lines = self._wrapper.wrap(rawline) + if self._wrapper: + lines = self._wrapper.wrap(rawline) + else: + lines = [rawline] for line in lines: if firstline: logfunc("%s%s" % (prefix, line.lstrip())) |