#159: do not fail if sys.stdout has no isatty() method.

This commit is contained in:
Georg Brandl 2009-05-10 21:06:34 +02:00
parent ef01782f42
commit 64d2c2c795
4 changed files with 9 additions and 4 deletions

View File

@ -56,7 +56,7 @@ Modi:
def main(argv):
if not sys.stdout.isatty() or not color_terminal():
if not color_terminal():
# Windows' poor cmd box doesn't understand ANSI sequences
nocolor()

View File

@ -532,7 +532,7 @@ def inner_main(args):
d = {}
texescape.init()
if not sys.stdout.isatty() or not color_terminal():
if not color_terminal():
nocolor()
print bold('Welcome to the Sphinx quickstart utility.')

View File

@ -18,7 +18,7 @@ from StringIO import StringIO
from distutils.cmd import Command
from sphinx.application import Sphinx
from sphinx.util.console import darkred, nocolor
from sphinx.util.console import darkred, nocolor, color_terminal
class BuildDoc(Command):
@ -63,7 +63,7 @@ class BuildDoc(Command):
self.mkpath(self.builder_target_dir)
def run(self):
if not sys.stdout.isatty() or sys.platform == 'win32':
if not color_terminal():
# Windows' poor cmd box doesn't understand ANSI sequences
nocolor()
if not self.verbose:

View File

@ -10,6 +10,7 @@
"""
import os
import sys
codes = {}
@ -38,6 +39,10 @@ def term_width_line(text):
return text.ljust(_tw) + '\r'
def color_terminal():
if not hasattr(sys.stdout, 'isatty'):
return False
if not sys.stdout.isatty():
return False
if 'COLORTERM' in os.environ:
return True
term = os.environ.get('TERM', 'dumb').lower()