Minor changes in the logging system

This commit is contained in:
Thomas Nagy 2014-01-05 10:51:24 +01:00
parent 3deaeb241a
commit 85bfd3eded
No known key found for this signature in database
GPG Key ID: 67A565EDFDF90E64
3 changed files with 27 additions and 31 deletions

View File

@ -7,16 +7,14 @@ logging, colors, terminal width and pretty-print
"""
import os, re, traceback, sys
from waflib import ansiterm
from waflib import Utils, ansiterm
if not os.environ.get('NOSYNC', False):
# synchronized output is nearly mandatory to prevent garbled output
if sys.stdout.isatty() and id(sys.stdout) == id(sys.__stdout__):
sys.stdout = ansiterm.AnsiTerm(sys.stdout)
os.environ['TERM'] = 'vt100' # <- not sure about this
if sys.stderr.isatty() and id(sys.stderr) == id(sys.__stderr__):
sys.stderr = ansiterm.AnsiTerm(sys.stderr)
os.environ['TERM'] = 'vt100' # <- not sure about this
import logging # the logging module keeps holds reference on sys.stderr
@ -40,17 +38,24 @@ colors_lst = {
'cursor_off' :'\x1b[?25l',
}
def enable_colors(level):
if level == 0:
colors_lst['USE'] = False
elif level == 1:
# and here we guess
term = os.environ.get('TERM', '')
if term in ['dumb', 'emacs']:
colors_lst['USE'] = False
pass
else:
colors_lst['USE'] = True
def enable_colors(use):
if use == 1:
if os.environ.get('NOCOLOR', ''):
use = 0
if not (sys.stderr.isatty() or sys.stdout.isatty()):
use = 0
if Utils.is_win32:
term = os.environ.get('TERM', '') # has ansiterm
else:
term = os.environ.get('TERM', 'dumb')
if term in ('dumb', 'emacs'):
use = 0
if use >= 1:
os.environ['TERM'] = 'vt100'
colors_lst['USE'] = use
def get_term_cols():
return 80

View File

@ -14,13 +14,6 @@ as well as custom ones, used by the ``options`` wscript function.
import os, tempfile, optparse, sys, re
from waflib import Logs, Utils, Context
try:
import threading
except ImportError:
if not 'JOBS' in os.environ:
# no threading :-(
os.environ['JOBS'] = '1'
cmds = 'distclean configure build install clean uninstall check dist distcheck'.split()
"""
Constant representing the default waf commands displayed in::
@ -58,7 +51,7 @@ class opt_parser(optparse.OptionParser):
self.ctx = ctx
jobs = ctx.jobs()
p('-c', '--color', dest='colors', default='auto', action='store', help='whether to use colors (always/auto/never) [default: auto]')
p('-c', '--color', dest='colors', default='auto', action='store', help='whether to use colors (yes/no/auto) [default: auto]', choices=('yes', 'no', 'auto'))
p('-j', '--jobs', dest='jobs', default=jobs, type='int', help='amount of parallel jobs (%r)' % jobs)
p('-k', '--keep', dest='keep', default=0, action='count', help='keep running happily even if errors are found')
p('-v', '--verbose', dest='verbose', default=0, action='count', help='verbosity level -v -vv or -vvv [default: 0]')
@ -250,14 +243,8 @@ class OptionsContext(Context.Context):
if options.verbose >= 1:
self.load('errcheck')
try:
colors = {'always' : 2, 'auto' : 1, 'never' : 0}[options.colors]
except KeyError:
self.parser.error('Bad option "%s" for --color option' % options.colors)
else:
if os.environ.get('NOCOLOR', ''):
colors = 0
Logs.enable_colors(colors)
colors = {'always' : 2, 'auto' : 1, 'never' : 0}[options.colors]
Logs.enable_colors(colors)
def execute(self):
"""

View File

@ -48,6 +48,10 @@ except ImportError:
try:
import threading
except ImportError:
if not 'JOBS' in os.environ:
# no threading :-(
os.environ['JOBS'] = '1'
class threading(object):
"""
A fake threading class for platforms lacking the threading module.
@ -602,7 +606,7 @@ def unversioned_sys_platform():
elif s in ('SunOS', 'Solaris'):
return 'sunos'
else: s = s.lower()
# powerpc == darwin for our purposes
if s == 'powerpc':
return 'darwin'