diff options
author | Nathan Letwory <nathan@letworyinteractive.com> | 2009-10-06 19:01:46 +0400 |
---|---|---|
committer | Nathan Letwory <nathan@letworyinteractive.com> | 2009-10-06 19:01:46 +0400 |
commit | 86307b58c0991472b25bd0c24ba8d2cdbf332bc3 (patch) | |
tree | 48a404bbcdf9ec6b7ad28f2e029afe4bd0354c15 /tools/Blender.py | |
parent | 6282b7998b212ae5ecda8bf26f4adebd747ba918 (diff) |
== SCons ==
* Unzip of python31.zip now works also for Python 2.5. Patch by b333rt (thanks again!)
Diffstat (limited to 'tools/Blender.py')
-rw-r--r-- | tools/Blender.py | 78 |
1 files changed, 75 insertions, 3 deletions
diff --git a/tools/Blender.py b/tools/Blender.py index 04f2676deb3..fec11685525 100644 --- a/tools/Blender.py +++ b/tools/Blender.py @@ -20,6 +20,9 @@ import string import glob import time import sys +import zipfile +import shutil +import cStringIO from SCons.Script.SConscript import SConsEnvironment import SCons.Action @@ -327,11 +330,80 @@ def set_quiet_output(env): env['BUILDERS']['Library'] = static_lib env['BUILDERS']['Program'] = program + +class CompZipFile(zipfile.ZipFile): + """Partial copy of python2.6's zipfile.ZipFile (see http://www.python.org) + to get a extractall() that works on py2.5 and probably earlier distributions.""" + def __init__(self, file, mode="r", compression=zipfile.ZIP_STORED, allowZip64=False): + zipfile.ZipFile.__init__(self, file, mode, compression, allowZip64) + if not hasattr(self,"extractall"): # use our method + print "Debug: Using comp_extractall!" + self.extractall= self.comp_extractall + + def comp_extractall(self, path=None, members=None, pwd=None): #renamed method + """Extract all members from the archive to the current working + directory. `path' specifies a different directory to extract to. + `members' is optional and must be a subset of the list returned + by namelist(). + """ + if members is None: + members = self.namelist() + + for zipinfo in members: + self.comp_extract(zipinfo, path, pwd) # use our method + + def comp_extract(self, member, path=None, pwd=None): #renamed method + """Extract a member from the archive to the current working directory, + using its full name. Its file information is extracted as accurately + as possible. `member' may be a filename or a ZipInfo object. You can + specify a different directory using `path'. + """ + if not isinstance(member, zipfile.ZipInfo): + member = self.getinfo(member) + + if path is None: + path = os.getcwd() + + return self.comp_extract_member(member, path, pwd) # use our method + + def comp_extract_member(self, member, targetpath, pwd): #renamed method + """Extract the ZipInfo object 'member' to a physical + file on the path targetpath. + """ + # build the destination pathname, replacing + # forward slashes to platform specific separators. + if targetpath[-1:] in (os.path.sep, os.path.altsep): + targetpath = targetpath[:-1] + + # don't include leading "/" from file name if present + if member.filename[0] == '/': + targetpath = os.path.join(targetpath, member.filename[1:]) + else: + targetpath = os.path.join(targetpath, member.filename) + + targetpath = os.path.normpath(targetpath) + + # Create all upper directories if necessary. + upperdirs = os.path.dirname(targetpath) + if upperdirs and not os.path.exists(upperdirs): + os.makedirs(upperdirs) + + if member.filename[-1] == '/': + os.mkdir(targetpath) + return targetpath + + #use StrinIO instead so we don't have to reproduce more functionality. + source = cStringIO.StringIO(self.read(member.filename)) + target = file(targetpath, "wb") + shutil.copyfileobj(source, target) + source.close() + target.close() + + return targetpath def unzip_pybundle(from_zip,to_dir,exclude_re): - import zipfile - zip= zipfile.ZipFile(from_zip, mode='r') + zip= CompZipFile(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= [] @@ -356,7 +428,7 @@ def my_winpybundle_print(target, source, env): pass def WinPyBundle(target=None, source=None, env=None): - import shutil, re + import re py_zip= env.subst( env['LCGDIR'] ) if py_zip[0]=='#': py_zip= py_zip[1:] |