diff options
author | cookedm <cookedm@localhost> | 2007-05-25 14:47:42 +0000 |
---|---|---|
committer | cookedm <cookedm@localhost> | 2007-05-25 14:47:42 +0000 |
commit | 56e555c305f7d58f0885cac44cd4a7949f5b954d (patch) | |
tree | 7c21ec4dd0db41c38413c65c935a2acc512435eb /numpy | |
parent | f7b399a6f9a299d82dc9490bf81683b0d1693427 (diff) | |
download | numpy-56e555c305f7d58f0885cac44cd4a7949f5b954d.tar.gz |
Add a numpy.distutils.log.good function, which when WARN messages would be
logged, logs a "nice" anti-warn version. Use this for finding executables
to report when we do actually find one.
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/distutils/exec_command.py | 2 | ||||
-rw-r--r-- | numpy/distutils/log.py | 25 | ||||
-rw-r--r-- | numpy/distutils/misc_util.py | 41 |
3 files changed, 54 insertions, 14 deletions
diff --git a/numpy/distutils/exec_command.py b/numpy/distutils/exec_command.py index e00753b9a..029dadecf 100644 --- a/numpy/distutils/exec_command.py +++ b/numpy/distutils/exec_command.py @@ -159,7 +159,7 @@ def find_executable(exe, path=None): if not os.path.islink(f_ext): f_ext = realpath(f_ext) if os.path.isfile(f_ext) and os.access(f_ext, os.X_OK): - log.debug('Found executable %s' % f_ext) + log.good('Found executable %s' % f_ext) return f_ext log.warn('Could not locate executable %s' % orig_exe) diff --git a/numpy/distutils/log.py b/numpy/distutils/log.py index 7484f1f5e..2e5af94a2 100644 --- a/numpy/distutils/log.py +++ b/numpy/distutils/log.py @@ -4,7 +4,7 @@ import sys from distutils.log import * from distutils.log import Log as old_Log from distutils.log import _global_log -from misc_util import red_text, yellow_text, cyan_text, is_sequence, is_string +from misc_util import red_text, yellow_text, cyan_text, green_text, is_sequence, is_string def _fix_args(args,flag=1): @@ -22,8 +22,29 @@ class Log(old_Log): else: print _global_color_map[level](msg) sys.stdout.flush() + + def good(self, msg, *args): + """If we'd log WARN messages, log this message as a 'nice' anti-warn + message. + """ + if WARN >= self.threshold: + if args: + print green_text(msg % _fix_args(args)) + else: + print green_text(msg) + sys.stdout.flush() _global_log.__class__ = Log +good = _global_log.good + +def set_threshold(level): + prev_level = _global_log.threshold + if prev_level > DEBUG: + # If we're running at DEBUG, don't change the threshold, as there's + # likely a good reason why we're running at this level. + _global_log.threshold = level + return prev_level + def set_verbosity(v): prev_level = _global_log.threshold if v < 0: @@ -44,4 +65,4 @@ _global_color_map = { FATAL:red_text } -set_verbosity(1) +set_verbosity(INFO) diff --git a/numpy/distutils/misc_util.py b/numpy/distutils/misc_util.py index 488e0fc8e..48b6dd458 100644 --- a/numpy/distutils/misc_util.py +++ b/numpy/distutils/misc_util.py @@ -65,7 +65,7 @@ def get_path_from_frame(frame, parent_path=None): # (likely we're building an egg) d = os.path.abspath('.') # hmm, should we use sys.argv[0] like in __builtin__ case? - + if parent_path is not None: d = rel_path(d, parent_path) @@ -219,17 +219,36 @@ def terminal_has_colors(): return 0 if terminal_has_colors(): - def red_text(s): return '\x1b[31m%s\x1b[0m'%s - def green_text(s): return '\x1b[32m%s\x1b[0m'%s - def yellow_text(s): return '\x1b[33m%s\x1b[0m'%s - def blue_text(s): return '\x1b[34m%s\x1b[0m'%s - def cyan_text(s): return '\x1b[35m%s\x1b[0m'%s + _colour_codes = dict(black=0, red=1, green=2, yellow=3, + blue=4, magenta=5, cyan=6, white=7) + def colour_text(s, fg=None, bg=None, bold=False): + seq = [] + if bold: + seq.append('1') + if fg: + fgcode = 30 + _colour_codes.get(fg.lower(), 0) + seq.append(str(fgcode)) + if bg: + bgcode = 40 + _colour_codes.get(fg.lower(), 7) + seq.append(str(bgcode)) + if seq: + return '\x1b[%sm%s\x1b[0m' % (';'.join(seq), s) + else: + return s else: - def red_text(s): return s - def green_text(s): return s - def yellow_text(s): return s - def cyan_text(s): return s - def blue_text(s): return s + def colour_text(s, fg=None, bg=None): + return s + +def red_text(s): + return colour_text(s, 'red') +def green_text(s): + return colour_text(s, 'green') +def yellow_text(s): + return colour_text(s, 'yellow') +def cyan_text(s): + return colour_text(s, 'cyan') +def blue_text(s): + return colour_text(s, 'blue') ######################### |