3
# WARNING! All changes made to this file will be lost!
5
import os,re,logging,traceback,sys
7
if'NOCOLOR'not in os.environ:
11
LOG_FORMAT="%(asctime)s %(c1)s%(zone)s%(c2)s %(message)s"
12
HOUR_FORMAT="%H:%M:%S"
15
colors_lst={'USE':True,'BOLD':'\x1b[01;1m','RED':'\x1b[01;31m','GREEN':'\x1b[32m','YELLOW':'\x1b[33m','PINK':'\x1b[35m','BLUE':'\x1b[01;34m','CYAN':'\x1b[36m','NORMAL':'\x1b[0m','cursor_on':'\x1b[?25h','cursor_off':'\x1b[?25l',}
16
got_tty=not os.environ.get('TERM','dumb')in['dumb','emacs']
19
got_tty=sys.stderr.isatty()
20
except AttributeError:
22
if not got_tty or'NOCOLOR'in os.environ:
23
colors_lst['USE']=False
27
import struct,fcntl,termios
32
def get_term_cols_real():
33
dummy_lines,cols=struct.unpack("HHHH",fcntl.ioctl(sys.stderr.fileno(),termios.TIOCGWINSZ,struct.pack("HHHH",0,0,0,0)))[:2]
40
get_term_cols=get_term_cols_real
41
get_term_cols.__doc__="""
42
Get the console width in characters.
44
:return: the number of characters per line
48
if not colors_lst['USE']:return''
49
return colors_lst.get(cl,'')
50
class color_dict(object):
51
def __getattr__(self,a):
56
re_log=re.compile(r'(\w+): (.*)',re.M)
57
class log_filter(logging.Filter):
58
def __init__(self,name=None):
64
if rec.levelno>=logging.INFO:
65
if rec.levelno>=logging.ERROR:
67
elif rec.levelno>=logging.WARNING:
73
m=re_log.match(rec.msg)
75
zone=rec.zone=m.group(1)
78
return getattr(rec,'zone','')in zones or'*'in zones
82
class formatter(logging.Formatter):
84
logging.Formatter.__init__(self,LOG_FORMAT,HOUR_FORMAT)
86
if rec.levelno>=logging.WARNING or rec.levelno==logging.INFO:
88
return'%s%s%s'%(rec.c1,rec.msg,rec.c2)
90
return rec.c1+rec.msg+rec.c2
91
return logging.Formatter.format(self,rec)
96
k[0]=k[0].replace('\n',' ')
103
st=traceback.extract_stack()
107
for filename,lineno,name,line in st:
108
buf.append(' File "%s", line %d, in %s'%(filename,lineno,name))
110
buf.append(' %s'%line.strip())
111
if buf:log.error("\n".join(buf))
120
log=logging.getLogger('waflib')
123
hdlr=logging.StreamHandler()
124
hdlr.setFormatter(formatter())
126
log.addFilter(log_filter())
127
log.setLevel(logging.DEBUG)
128
def make_logger(path,name):
129
logger=logging.getLogger(name)
130
hdlr=logging.FileHandler(path,'w')
131
formatter=logging.Formatter('%(message)s')
132
hdlr.setFormatter(formatter)
133
logger.addHandler(hdlr)
134
logger.setLevel(logging.DEBUG)
136
def make_mem_logger(name,to_log,size=10000):
137
from logging.handlers import MemoryHandler
138
logger=logging.getLogger(name)
139
hdlr=MemoryHandler(size,target=to_log)
140
formatter=logging.Formatter('%(message)s')
141
hdlr.setFormatter(formatter)
142
logger.addHandler(hdlr)
143
logger.memhandler=hdlr
144
logger.setLevel(logging.DEBUG)
146
def pprint(col,str,label='',sep='\n'):
147
sys.stderr.write("%s%s%s %s%s"%(colors(col),str,colors.NORMAL,label,sep))