+
+def unzip_pybundle(from_zip,to_dir,exclude_re):
+ import zipfile
+
+ zip= zipfile.ZipFile(from_zip, mode='r')
+ exclude_re= list(exclude_re) #single re object or list of re objects
+ debug= 0 #list files instead of unpacking
+ good= []
+ if debug: print '\nFiles not being unpacked:\n'
+ for name in zip.namelist():
+ is_bad= 0
+ for r in exclude_re:
+ if r.match(name):
+ is_bad=1
+ if debug: print name
+ break
+ if not is_bad:
+ good.append(name)
+ if debug:
+ print '\nFiles being unpacked:\n'
+ for g in good:
+ print g
+ else:
+ zip.extractall(to_dir, good)
+
+def my_winpybundle_print(target, source, env):
+ pass
+
+def WinPyBundle(target=None, source=None, env=None):
+ import shutil, re
+ py_zip= env.subst( env['LCGDIR'] )
+ if py_zip[0]=='#':
+ py_zip= py_zip[1:]
+ py_zip+= '/release/python' + env['BF_PYTHON_VERSION'].replace('.','') + '.zip'
+
+ py_target = env.subst( env['BF_INSTALLDIR'] )
+ if py_target[0]=='#':
+ py_target=py_target[1:]
+ py_target+= '/.blender/python/lib/'
+ def printexception(func,path,ex):
+ if os.path.exists(path): #do not report if path does not exist. eg on a fresh build.
+ print str(func) + ' failed on ' + str(path)
+ print "Trying to remove existing py bundle."
+ shutil.rmtree(py_target, False, printexception)
+ exclude_re=[re.compile('.*/test/.*'),
+ re.compile('^config/.*'),
+ re.compile('^distutils/.*'),
+ re.compile('^idlelib/.*'),
+ re.compile('^lib2to3/.*'),
+ re.compile('^tkinter/.*')]
+ print "Unpacking '" + py_zip + "' to '" + py_target + "'"
+ unzip_pybundle(py_zip,py_target,exclude_re)
+