[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [23663] trunk/blender/tools/Blender.py: == SCons ==

Nathan Letwory jesterking at letwory.net
Tue Oct 6 17:01:49 CEST 2009


Revision: 23663
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23663
Author:   jesterking
Date:     2009-10-06 17:01:46 +0200 (Tue, 06 Oct 2009)

Log Message:
-----------
== SCons ==

* Unzip of python31.zip now works also for Python 2.5. Patch by b333rt (thanks again!)

Modified Paths:
--------------
    trunk/blender/tools/Blender.py

Modified: trunk/blender/tools/Blender.py
===================================================================
--- trunk/blender/tools/Blender.py	2009-10-06 14:25:55 UTC (rev 23662)
+++ trunk/blender/tools/Blender.py	2009-10-06 15:01:46 UTC (rev 23663)
@@ -20,6 +20,9 @@
 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 @@
 	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 @@
 	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:]





More information about the Bf-blender-cvs mailing list