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