Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/mingw32/Python27/Lib/site-packages/numpy/distutils/log.py @ 87:2a2c65a20a8b
Add Python libs and headers
author | Chris Cannam |
---|---|
date | Wed, 25 Feb 2015 14:05:22 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
86:413a9d26189e | 87:2a2c65a20a8b |
---|---|
1 # Colored log, requires Python 2.3 or up. | |
2 from __future__ import division, absolute_import, print_function | |
3 | |
4 import sys | |
5 from distutils.log import * | |
6 from distutils.log import Log as old_Log | |
7 from distutils.log import _global_log | |
8 | |
9 if sys.version_info[0] < 3: | |
10 from .misc_util import (red_text, default_text, cyan_text, green_text, | |
11 is_sequence, is_string) | |
12 else: | |
13 from numpy.distutils.misc_util import (red_text, default_text, cyan_text, | |
14 green_text, is_sequence, is_string) | |
15 | |
16 | |
17 def _fix_args(args,flag=1): | |
18 if is_string(args): | |
19 return args.replace('%', '%%') | |
20 if flag and is_sequence(args): | |
21 return tuple([_fix_args(a, flag=0) for a in args]) | |
22 return args | |
23 | |
24 | |
25 class Log(old_Log): | |
26 def _log(self, level, msg, args): | |
27 if level >= self.threshold: | |
28 if args: | |
29 msg = msg % _fix_args(args) | |
30 if 0: | |
31 if msg.startswith('copying ') and msg.find(' -> ') != -1: | |
32 return | |
33 if msg.startswith('byte-compiling '): | |
34 return | |
35 print(_global_color_map[level](msg)) | |
36 sys.stdout.flush() | |
37 | |
38 def good(self, msg, *args): | |
39 """ | |
40 If we log WARN messages, log this message as a 'nice' anti-warn | |
41 message. | |
42 | |
43 """ | |
44 if WARN >= self.threshold: | |
45 if args: | |
46 print(green_text(msg % _fix_args(args))) | |
47 else: | |
48 print(green_text(msg)) | |
49 sys.stdout.flush() | |
50 | |
51 | |
52 _global_log.__class__ = Log | |
53 | |
54 good = _global_log.good | |
55 | |
56 def set_threshold(level, force=False): | |
57 prev_level = _global_log.threshold | |
58 if prev_level > DEBUG or force: | |
59 # If we're running at DEBUG, don't change the threshold, as there's | |
60 # likely a good reason why we're running at this level. | |
61 _global_log.threshold = level | |
62 if level <= DEBUG: | |
63 info('set_threshold: setting threshold to DEBUG level,' | |
64 ' it can be changed only with force argument') | |
65 else: | |
66 info('set_threshold: not changing threshold from DEBUG level' | |
67 ' %s to %s' % (prev_level, level)) | |
68 return prev_level | |
69 | |
70 | |
71 def set_verbosity(v, force=False): | |
72 prev_level = _global_log.threshold | |
73 if v < 0: | |
74 set_threshold(ERROR, force) | |
75 elif v == 0: | |
76 set_threshold(WARN, force) | |
77 elif v == 1: | |
78 set_threshold(INFO, force) | |
79 elif v >= 2: | |
80 set_threshold(DEBUG, force) | |
81 return {FATAL:-2,ERROR:-1,WARN:0,INFO:1,DEBUG:2}.get(prev_level, 1) | |
82 | |
83 | |
84 _global_color_map = { | |
85 DEBUG:cyan_text, | |
86 INFO:default_text, | |
87 WARN:red_text, | |
88 ERROR:red_text, | |
89 FATAL:red_text | |
90 } | |
91 | |
92 # don't use INFO,.. flags in set_verbosity, these flags are for set_threshold. | |
93 set_verbosity(0, force=True) |