Changeset 904702d for waflib/Context.py
- Timestamp:
- Mar 14, 2015, 6:06:10 PM (10 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- 6d7acc8
- Parents:
- 5525507
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waflib/Context.py
r5525507 r904702d 3 3 # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file 4 4 5 import os, imp,sys5 import os,re,imp,sys 6 6 from waflib import Utils,Errors,Logs 7 7 import waflib.Node 8 HEXVERSION=0x10 70f009 WAFVERSION="1. 7.15"10 WAFREVISION=" f63ac9793de2d4eaae884e55d4ff70a761dcbab2"8 HEXVERSION=0x1080700 9 WAFVERSION="1.8.7" 10 WAFREVISION="e5056b9ade7bb224f53baab13a0ce136344ab602" 11 11 ABI=98 12 12 DBFILE='.wafpickle-%s-%d-%d'%(sys.platform,sys.hexversion,ABI) … … 72 72 def __hash__(self): 73 73 return id(self) 74 def finalize(self): 75 try: 76 logger=self.logger 77 except AttributeError: 78 pass 79 else: 80 Logs.free_logger(logger) 81 delattr(self,'logger') 74 82 def load(self,tool_list,*k,**kw): 75 83 tools=Utils.to_list(tool_list) … … 91 99 if self.cur_script: 92 100 self.path=self.cur_script.parent 93 def recurse(self,dirs,name=None,mandatory=True,once=True ):101 def recurse(self,dirs,name=None,mandatory=True,once=True,encoding=None): 94 102 try: 95 103 cache=self.recurse_cache … … 106 114 self.pre_recurse(node) 107 115 try: 108 function_code=node.read('rU' )116 function_code=node.read('rU',encoding) 109 117 exec(compile(function_code,node.abspath(),'exec'),self.exec_dict) 110 118 finally: … … 117 125 self.pre_recurse(node) 118 126 try: 119 wscript_module=load_module(node.abspath() )127 wscript_module=load_module(node.abspath(),encoding=encoding) 120 128 user_function=getattr(wscript_module,(name or self.fun),None) 121 129 if not user_function: … … 141 149 if'stderr'not in kw: 142 150 kw['stderr']=subprocess.PIPE 151 if Logs.verbose and not kw['shell']and not Utils.check_exe(cmd[0]): 152 raise Errors.WafError("Program %s not found!"%cmd[0]) 143 153 try: 144 154 if kw['stdout']or kw['stderr']: … … 157 167 self.logger.debug('out: %s'%out) 158 168 else: 159 sys.stdout.write(out)169 Logs.info(out,extra={'stream':sys.stdout,'c1':''}) 160 170 if err: 161 171 if not isinstance(err,str): … … 164 174 self.logger.error('err: %s'%err) 165 175 else: 166 sys.stderr.write(err)176 Logs.info(err,extra={'stream':sys.stderr,'c1':''}) 167 177 return ret 168 178 def cmd_and_log(self,cmd,**kw): … … 180 190 else: 181 191 to_ret=STDOUT 192 if Logs.verbose and not kw['shell']and not Utils.check_exe(cmd[0]): 193 raise Errors.WafError("Program %s not found!"%cmd[0]) 182 194 kw['stdout']=kw['stderr']=subprocess.PIPE 183 195 if quiet is None: … … 223 235 sys.stderr.write(str(msg)) 224 236 sys.stderr.flush() 225 def msg(self,msg,result,color=None): 226 self.start_msg(msg) 237 def msg(self,*k,**kw): 238 try: 239 msg=kw['msg'] 240 except KeyError: 241 msg=k[0] 242 self.start_msg(msg,**kw) 243 try: 244 result=kw['result'] 245 except KeyError: 246 result=k[1] 247 color=kw.get('color',None) 227 248 if not isinstance(color,str): 228 249 color=result and'GREEN'or'YELLOW' 229 self.end_msg(result,color) 230 def start_msg(self,msg): 250 self.end_msg(result,color,**kw) 251 def start_msg(self,*k,**kw): 252 if kw.get('quiet',None): 253 return 254 msg=kw.get('msg',None)or k[0] 231 255 try: 232 256 if self.in_msg: … … 243 267 self.to_log(x) 244 268 Logs.pprint('NORMAL',"%s :"%msg.ljust(self.line_just),sep='') 245 def end_msg(self,result,color=None): 269 def end_msg(self,*k,**kw): 270 if kw.get('quiet',None): 271 return 246 272 self.in_msg-=1 247 273 if self.in_msg: 248 274 return 275 result=kw.get('result',None)or k[0] 249 276 defcolor='GREEN' 250 277 if result==True: … … 256 283 msg=str(result) 257 284 self.to_log(msg) 258 Logs.pprint(color or defcolor,msg) 285 try: 286 color=kw['color'] 287 except KeyError: 288 if len(k)>1 and k[1]in Logs.colors_lst: 289 color=k[1] 290 else: 291 color=defcolor 292 Logs.pprint(color,msg) 259 293 def load_special_tools(self,var,ban=[]): 260 294 global waf_dir 261 lst=self.root.find_node(waf_dir).find_node('waflib/extras').ant_glob(var) 262 for x in lst: 263 if not x.name in ban: 264 load_tool(x.name.replace('.py','')) 295 if os.path.isdir(waf_dir): 296 lst=self.root.find_node(waf_dir).find_node('waflib/extras').ant_glob(var) 297 for x in lst: 298 if not x.name in ban: 299 load_tool(x.name.replace('.py','')) 300 else: 301 from zipfile import PyZipFile 302 waflibs=PyZipFile(waf_dir) 303 lst=waflibs.namelist() 304 for x in lst: 305 if not re.match("waflib/extras/%s"%var.replace("*",".*"),var): 306 continue 307 f=os.path.basename(x) 308 doban=False 309 for b in ban: 310 r=b.replace("*",".*") 311 if re.match(b,f): 312 doban=True 313 if not doban: 314 f=f.replace('.py','') 315 load_tool(f) 265 316 cache_modules={} 266 def load_module(path ):317 def load_module(path,encoding=None): 267 318 try: 268 319 return cache_modules[path] … … 271 322 module=imp.new_module(WSCRIPT_FILE) 272 323 try: 273 code=Utils.readf(path,m='rU' )274 except (IOError,OSError):324 code=Utils.readf(path,m='rU',encoding=encoding) 325 except EnvironmentError: 275 326 raise Errors.WafError('Could not read the file %r'%path) 276 327 module_dir=os.path.dirname(path) … … 280 331 cache_modules[path]=module 281 332 return module 282 def load_tool(tool,tooldir=None ):333 def load_tool(tool,tooldir=None,ctx=None): 283 334 if tool=='java': 284 335 tool='javaw' 285 elif tool=='compiler_cc':286 tool='compiler_c'287 336 else: 288 337 tool=tool.replace('++','xx') … … 299 348 sys.path.remove(d) 300 349 else: 301 global waf_dir 302 try: 303 os.stat(os.path.join(waf_dir,'waflib','extras',tool+'.py')) 304 except OSError: 350 for x in('waflib.Tools.%s','waflib.extras.%s','waflib.%s','%s'): 305 351 try: 306 os.stat(os.path.join(waf_dir,'waflib','Tools',tool+'.py')) 307 except OSError: 308 d=tool 309 else: 310 d='waflib.Tools.%s'%tool 311 else: 312 d='waflib.extras.%s'%tool 313 __import__(d) 314 ret=sys.modules[d] 352 __import__(x%tool) 353 break 354 except ImportError: 355 x=None 356 if x is None: 357 __import__(tool) 358 ret=sys.modules[x%tool] 315 359 Context.tools[tool]=ret 316 360 return ret
Note: See TracChangeset
for help on using the changeset viewer.