[0fa325b] | 1 | #! /usr/bin/env python |
---|
| 2 | # encoding: utf-8 |
---|
| 3 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file |
---|
| 4 | |
---|
| 5 | import os,re,traceback,sys |
---|
[c101fe1] | 6 | _nocolor=os.environ.get('NOCOLOR','no')not in('no','0','false') |
---|
[0fa325b] | 7 | try: |
---|
[c101fe1] | 8 | if not _nocolor: |
---|
| 9 | import waflib.ansiterm |
---|
[0fa325b] | 10 | except ImportError: |
---|
| 11 | pass |
---|
[c101fe1] | 12 | try: |
---|
| 13 | import threading |
---|
| 14 | except ImportError: |
---|
| 15 | if not'JOBS'in os.environ: |
---|
| 16 | os.environ['JOBS']='1' |
---|
[0fa325b] | 17 | else: |
---|
| 18 | wlock=threading.Lock() |
---|
| 19 | class sync_stream(object): |
---|
| 20 | def __init__(self,stream): |
---|
| 21 | self.stream=stream |
---|
| 22 | self.encoding=self.stream.encoding |
---|
| 23 | def write(self,txt): |
---|
| 24 | try: |
---|
| 25 | wlock.acquire() |
---|
| 26 | self.stream.write(txt) |
---|
| 27 | self.stream.flush() |
---|
| 28 | finally: |
---|
| 29 | wlock.release() |
---|
| 30 | def fileno(self): |
---|
| 31 | return self.stream.fileno() |
---|
| 32 | def flush(self): |
---|
| 33 | self.stream.flush() |
---|
| 34 | def isatty(self): |
---|
| 35 | return self.stream.isatty() |
---|
| 36 | if not os.environ.get('NOSYNC',False): |
---|
| 37 | if id(sys.stdout)==id(sys.__stdout__): |
---|
| 38 | sys.stdout=sync_stream(sys.stdout) |
---|
| 39 | sys.stderr=sync_stream(sys.stderr) |
---|
| 40 | import logging |
---|
| 41 | LOG_FORMAT="%(asctime)s %(c1)s%(zone)s%(c2)s %(message)s" |
---|
| 42 | HOUR_FORMAT="%H:%M:%S" |
---|
| 43 | zones='' |
---|
| 44 | verbose=0 |
---|
| 45 | 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',} |
---|
| 46 | got_tty=not os.environ.get('TERM','dumb')in['dumb','emacs'] |
---|
| 47 | if got_tty: |
---|
| 48 | try: |
---|
| 49 | got_tty=sys.stderr.isatty()and sys.stdout.isatty() |
---|
| 50 | except AttributeError: |
---|
| 51 | got_tty=False |
---|
| 52 | if(not got_tty and os.environ.get('TERM','dumb')!='msys')or _nocolor: |
---|
| 53 | colors_lst['USE']=False |
---|
| 54 | def get_term_cols(): |
---|
| 55 | return 80 |
---|
| 56 | try: |
---|
| 57 | import struct,fcntl,termios |
---|
| 58 | except ImportError: |
---|
| 59 | pass |
---|
| 60 | else: |
---|
| 61 | if got_tty: |
---|
| 62 | def get_term_cols_real(): |
---|
| 63 | dummy_lines,cols=struct.unpack("HHHH",fcntl.ioctl(sys.stderr.fileno(),termios.TIOCGWINSZ,struct.pack("HHHH",0,0,0,0)))[:2] |
---|
| 64 | return cols |
---|
| 65 | try: |
---|
| 66 | get_term_cols_real() |
---|
| 67 | except Exception: |
---|
| 68 | pass |
---|
| 69 | else: |
---|
| 70 | get_term_cols=get_term_cols_real |
---|
| 71 | get_term_cols.__doc__=""" |
---|
| 72 | Get the console width in characters. |
---|
| 73 | |
---|
| 74 | :return: the number of characters per line |
---|
| 75 | :rtype: int |
---|
| 76 | """ |
---|
| 77 | def get_color(cl): |
---|
| 78 | if not colors_lst['USE']:return'' |
---|
| 79 | return colors_lst.get(cl,'') |
---|
| 80 | class color_dict(object): |
---|
| 81 | def __getattr__(self,a): |
---|
| 82 | return get_color(a) |
---|
| 83 | def __call__(self,a): |
---|
| 84 | return get_color(a) |
---|
| 85 | colors=color_dict() |
---|
| 86 | re_log=re.compile(r'(\w+): (.*)',re.M) |
---|
| 87 | class log_filter(logging.Filter): |
---|
| 88 | def __init__(self,name=None): |
---|
| 89 | pass |
---|
| 90 | def filter(self,rec): |
---|
| 91 | rec.c1=colors.PINK |
---|
| 92 | rec.c2=colors.NORMAL |
---|
| 93 | rec.zone=rec.module |
---|
| 94 | if rec.levelno>=logging.INFO: |
---|
| 95 | if rec.levelno>=logging.ERROR: |
---|
| 96 | rec.c1=colors.RED |
---|
| 97 | elif rec.levelno>=logging.WARNING: |
---|
| 98 | rec.c1=colors.YELLOW |
---|
| 99 | else: |
---|
| 100 | rec.c1=colors.GREEN |
---|
| 101 | return True |
---|
| 102 | m=re_log.match(rec.msg) |
---|
| 103 | if m: |
---|
| 104 | rec.zone=m.group(1) |
---|
| 105 | rec.msg=m.group(2) |
---|
| 106 | if zones: |
---|
| 107 | return getattr(rec,'zone','')in zones or'*'in zones |
---|
| 108 | elif not verbose>2: |
---|
| 109 | return False |
---|
| 110 | return True |
---|
| 111 | class formatter(logging.Formatter): |
---|
| 112 | def __init__(self): |
---|
| 113 | logging.Formatter.__init__(self,LOG_FORMAT,HOUR_FORMAT) |
---|
| 114 | def format(self,rec): |
---|
| 115 | if rec.levelno>=logging.WARNING or rec.levelno==logging.INFO: |
---|
| 116 | try: |
---|
| 117 | msg=rec.msg.decode('utf-8') |
---|
| 118 | except Exception: |
---|
| 119 | msg=rec.msg |
---|
| 120 | return'%s%s%s'%(rec.c1,msg,rec.c2) |
---|
| 121 | return logging.Formatter.format(self,rec) |
---|
| 122 | log=None |
---|
| 123 | def debug(*k,**kw): |
---|
| 124 | if verbose: |
---|
| 125 | k=list(k) |
---|
| 126 | k[0]=k[0].replace('\n',' ') |
---|
| 127 | global log |
---|
| 128 | log.debug(*k,**kw) |
---|
| 129 | def error(*k,**kw): |
---|
| 130 | global log |
---|
| 131 | log.error(*k,**kw) |
---|
| 132 | if verbose>2: |
---|
| 133 | st=traceback.extract_stack() |
---|
| 134 | if st: |
---|
| 135 | st=st[:-1] |
---|
| 136 | buf=[] |
---|
| 137 | for filename,lineno,name,line in st: |
---|
| 138 | buf.append(' File "%s", line %d, in %s'%(filename,lineno,name)) |
---|
| 139 | if line: |
---|
| 140 | buf.append(' %s'%line.strip()) |
---|
| 141 | if buf:log.error("\n".join(buf)) |
---|
| 142 | def warn(*k,**kw): |
---|
| 143 | global log |
---|
| 144 | log.warn(*k,**kw) |
---|
| 145 | def info(*k,**kw): |
---|
| 146 | global log |
---|
| 147 | log.info(*k,**kw) |
---|
| 148 | def init_log(): |
---|
| 149 | global log |
---|
| 150 | log=logging.getLogger('waflib') |
---|
| 151 | log.handlers=[] |
---|
| 152 | log.filters=[] |
---|
| 153 | hdlr=logging.StreamHandler() |
---|
| 154 | hdlr.setFormatter(formatter()) |
---|
| 155 | log.addHandler(hdlr) |
---|
| 156 | log.addFilter(log_filter()) |
---|
| 157 | log.setLevel(logging.DEBUG) |
---|
| 158 | def make_logger(path,name): |
---|
| 159 | logger=logging.getLogger(name) |
---|
| 160 | hdlr=logging.FileHandler(path,'w') |
---|
| 161 | formatter=logging.Formatter('%(message)s') |
---|
| 162 | hdlr.setFormatter(formatter) |
---|
| 163 | logger.addHandler(hdlr) |
---|
| 164 | logger.setLevel(logging.DEBUG) |
---|
| 165 | return logger |
---|
| 166 | def make_mem_logger(name,to_log,size=10000): |
---|
| 167 | from logging.handlers import MemoryHandler |
---|
| 168 | logger=logging.getLogger(name) |
---|
| 169 | hdlr=MemoryHandler(size,target=to_log) |
---|
| 170 | formatter=logging.Formatter('%(message)s') |
---|
| 171 | hdlr.setFormatter(formatter) |
---|
| 172 | logger.addHandler(hdlr) |
---|
| 173 | logger.memhandler=hdlr |
---|
| 174 | logger.setLevel(logging.DEBUG) |
---|
| 175 | return logger |
---|
| 176 | def pprint(col,str,label='',sep='\n'): |
---|
| 177 | sys.stderr.write("%s%s%s %s%s"%(colors(col),str,colors.NORMAL,label,sep)) |
---|