3 # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
5 import os,sys,errno,traceback,inspect,re,shutil,datetime,gc
8 from collections import deque
14 import _winreg as winreg
20 from waflib import Errors
22 from collections import UserDict
24 from UserDict import UserDict
26 from hashlib import md5
35 class threading(object):
42 threading.Lock=threading.Thread=Lock
44 run_old=threading.Thread.run
45 def run(*args,**kwargs):
47 run_old(*args,**kwargs)
48 except(KeyboardInterrupt,SystemExit):
51 sys.excepthook(*sys.exc_info())
52 threading.Thread.run=run
53 SIG_NIL='iluvcuteoverload'
56 rot_chr=['\\','|','/','-']
59 from collections import defaultdict
61 class defaultdict(dict):
62 def __init__(self,default_factory):
63 super(defaultdict,self).__init__()
64 self.default_factory=default_factory
65 def __getitem__(self,key):
67 return super(defaultdict,self).__getitem__(key)
69 value=self.default_factory()
72 is_win32=sys.platform in('win32','cli')
73 indicator='\x1b[K%s%s%s\r'
74 if is_win32 and'NOCOLOR'in os.environ:
76 def readf(fname,m='r',encoding='ISO8859-1'):
77 if sys.hexversion>0x3000000 and not'b'in m:
84 txt=txt.decode(encoding)
92 def writef(fname,data,m='w',encoding='ISO8859-1'):
93 if sys.hexversion>0x3000000 and not'b'in m:
94 data=data.encode(encoding)
111 if hasattr(os,'O_NOINHERIT'):
112 def readf_win32(f,m='r',encoding='ISO8859-1'):
113 flags=os.O_NOINHERIT|os.O_RDONLY
121 raise IOError('Cannot read from %r'%f)
122 if sys.hexversion>0x3000000 and not'b'in m:
129 txt=txt.decode(encoding)
137 def writef_win32(f,data,m='w',encoding='ISO8859-1'):
138 if sys.hexversion>0x3000000 and not'b'in m:
139 data=data.encode(encoding)
141 flags=os.O_CREAT|os.O_TRUNC|os.O_WRONLY|os.O_NOINHERIT
149 raise IOError('Cannot write to %r'%f)
155 def h_file_win32(fname):
157 fd=os.open(fname,os.O_BINARY|os.O_RDONLY|os.O_NOINHERIT)
159 raise IOError('Cannot read from %r'%fname)
180 ret=binascii.hexlify(s)
181 if not isinstance(ret,str):
182 ret=ret.decode('utf-8')
186 return s.encode('hex')
188 Return the hexadecimal representation of a string
190 :param s: string to convert
195 def listdir_win32(s):
200 return[x+':\\'for x in list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')]
204 buf=ctypes.create_string_buffer(maxdrives*dlen)
205 ndrives=ctypes.windll.kernel32.GetLogicalDriveStringsA(maxdrives*dlen,ctypes.byref(buf))
206 return[str(buf.raw[4*i:4*i+2].decode('ascii'))for i in range(int(ndrives/dlen))]
207 if len(s)==2 and s[1]==":":
209 if not os.path.isdir(s):
210 e=OSError('%s is not a directory'%s)
214 listdir=listdir_win32
216 if isinstance(ver,str):
217 ver=tuple(ver.split('.'))
218 if isinstance(ver,tuple):
222 ret+=256**(3-i)*int(ver[i])
226 exc_type,exc_value,tb=sys.exc_info()
227 exc_lines=traceback.format_exception(exc_type,exc_value,tb)
228 return''.join(exc_lines)
230 if isinstance(sth,str):
234 re_nl=re.compile('\r*\n',re.M)
235 def str_to_dict(txt):
237 lines=re_nl.split(txt)
240 if not x or x.startswith('#')or x.find('=')<0:
243 tbl[tmp[0].strip()]='='.join(tmp[1:]).strip()
245 def split_path(path):
246 return path.split('/')
247 def split_path_cygwin(path):
248 if path.startswith('//'):
249 ret=path.split('/')[2:]
252 return path.split('/')
253 re_sp=re.compile('[/\\\\]')
254 def split_path_win32(path):
255 if path.startswith('\\\\'):
256 ret=re.split(re_sp,path)[2:]
259 return re.split(re_sp,path)
260 if sys.platform=='cygwin':
261 split_path=split_path_cygwin
263 split_path=split_path_win32
264 split_path.__doc__="""
265 Split a path by / or \\. This function is not like os.path.split
268 :param path: path to split
269 :return: list of strings
272 if not os.path.isdir(path):
276 if not os.path.isdir(path):
277 raise Errors.WafError('Cannot create the folder %r'%path,ex=e)
278 def def_attrs(cls,**kw):
279 for k,v in kw.items():
280 if not hasattr(cls,k):
282 def quote_define_name(s):
283 fu=re.compile("[^a-zA-Z0-9]").sub("_",s)
293 except AttributeError:
295 h=inspect.getsource(fun)
300 except AttributeError:
303 reg_subst=re.compile(r"(\\\\)|(\$\$)|\$\{([^}]+)\}")
304 def subst_vars(expr,params):
311 return params.get_flat(m.group(3))
312 except AttributeError:
313 return params[m.group(3)]
314 return reg_subst.sub(repl_var,expr)
315 def destos_to_binfmt(key):
318 elif key in('win32','cygwin','uwin','msys'):
321 def unversioned_sys_platform():
324 from java.lang import System
325 s=System.getProperty('os.name')
328 elif s.startswith('Windows '):
334 elif s in('SunOS','Solaris'):
339 if s=='win32'or s.endswith('os2')and s!='sunos2':return s
340 return re.split('\d+$',s)[0]
345 self.start_time=datetime.datetime.utcnow()
347 delta=datetime.datetime.utcnow()-self.start_time
349 hours=delta.seconds//3600
350 minutes=(delta.seconds-hours*3600)//60
351 seconds=delta.seconds-hours*3600-minutes*60+float(delta.microseconds)/1000/1000
357 if days or hours or minutes:
358 result+='%dm'%minutes
359 return'%s%.3fs'%(result,seconds)
364 shutil.copystat(src,dst)
365 setattr(shutil,'copy2',copy2)
370 except NotImplementedError:
372 def read_la_file(path):
373 sp=re.compile(r'^([^=]+)=\'(.*)\'$')
375 for line in readf(path).splitlines():
377 _,left,right,_=sp.split(line.strip())
390 f.__doc__=fun.__doc__
403 def get_registry_app_path(key,filename):
407 result=winreg.QueryValue(key,"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\%s.exe"%filename[0])
411 if os.path.isfile(result):