[Python-checkins] python/dist/src/Lib/plat-mac bundlebuilder.py,1.7,1.8 macresource.py,1.2,1.3

jackjansen@users.sourceforge.net jackjansen@users.sourceforge.net
Mon, 17 Feb 2003 08:47:18 -0800


Update of /cvsroot/python/python/dist/src/Lib/plat-mac
In directory sc8-pr-cvs1:/tmp/cvs-serv29649

Modified Files:
	bundlebuilder.py macresource.py 
Log Message:
When installing resource files whose name ends in .rsrc use the
"copy anything to a data fork based resource file" trick of macresource.
Fixes #688007.


Index: bundlebuilder.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/bundlebuilder.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** bundlebuilder.py	12 Feb 2003 16:19:39 -0000	1.7
--- bundlebuilder.py	17 Feb 2003 16:47:12 -0000	1.8
***************
*** 37,40 ****
--- 37,41 ----
  from plistlib import Plist
  from types import FunctionType as function
+ import macresource
  
  
***************
*** 189,192 ****
--- 190,195 ----
  			if self.symlink:
  				symlink(src, dst, mkdirs=1)
+ 			elif os.path.splitext(src)[1] == '.rsrc':
+ 				macresource.install(src, dst, mkdirs=1)
  			else:
  				copy(src, dst, mkdirs=1)

Index: macresource.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/macresource.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** macresource.py	6 Jan 2003 11:15:05 -0000	1.2
--- macresource.py	17 Feb 2003 16:47:12 -0000	1.3
***************
*** 4,7 ****
--- 4,9 ----
  import os
  import sys
+ import MacOS
+ import macostools
  
  class ArgumentError(TypeError): pass
***************
*** 100,109 ****
  	need('Estr', 1, filename="errors.rsrc", modname=__name__)
  	
! def _decode(pathname, verbose=0):
  	# Decode an AppleSingle resource file, return the new pathname.
! 	newpathname = pathname + '.df.rsrc'
! 	if os.path.exists(newpathname) and \
  			os.stat(newpathname).st_mtime >= os.stat(pathname).st_mtime:
! 		return newpathname
  	if verbose:
  		print 'Decoding', pathname
--- 102,112 ----
  	need('Estr', 1, filename="errors.rsrc", modname=__name__)
  	
! def _decode(pathname, verbose=0, newpathname=None):
  	# Decode an AppleSingle resource file, return the new pathname.
! 	if not newpathname:
! 		newpathname = pathname + '.df.rsrc'
! 		if os.path.exists(newpathname) and \
  			os.stat(newpathname).st_mtime >= os.stat(pathname).st_mtime:
! 			return newpathname
  	if verbose:
  		print 'Decoding', pathname
***************
*** 112,114 ****
  	return newpathname
  	
! 	
\ No newline at end of file
--- 115,151 ----
  	return newpathname
  	
! def install(src, dst, mkdirs=0):
! 	"""Copy a resource file. The result will always be a datafork-based
! 	resource file, whether the source is datafork-based, resource-fork
! 	based or AppleSingle-encoded."""
! 	if mkdirs:
! 		macostools.mkdirs(os.path.split(dst)[0])
! 	try:
! 		refno = Res.FSOpenResourceFile(src, u'', 1)
! 	except Res.Error, arg:
! 		if arg[0] != -199:
! 			# -199 is "bad resource map"
! 			raise
! 	else:
! 		# Resource-fork based. Simply copy.
! 		Res.CloseResFile(refno)
! 		macostools.copy(src, dst)
! 		
! 	try:
! 		refno = Res.FSpOpenResFile(src, 1)
! 	except Res.Error, arg:
! 		if not arg[0] in (-37, -39):
! 			raise
! 	else:
! 		Res.CloseResFile(refno)
! 		BUFSIZ=0x80000      # Copy in 0.5Mb chunks
! 		ifp = MacOS.openrf(src, '*rb')
! 		ofp = open(dst, 'wb')
! 		d = ifp.read(BUFSIZ)
! 		while d:
! 			ofp.write(d)
! 			d = ifp.read(BUFSIZ)
! 		ifp.close()
! 		ofp.close()
! 		
! 	_decode(src, newpathname=dst)