[Python-checkins] python/dist/src/Lib/plat-mac aepack.py,1.3,1.4 aetypes.py,1.2,1.3 bgenlocations.py,1.2,1.3 buildtools.py,1.4,1.5

jackjansen@users.sourceforge.net jackjansen@users.sourceforge.net
Wed, 12 Feb 2003 07:37:30 -0800


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

Modified Files:
	aepack.py aetypes.py bgenlocations.py buildtools.py 
Log Message:
When in MacPython-OSX use bundlebuilder to create .app bundles.


Index: aepack.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/aepack.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** aepack.py	29 Jan 2003 10:41:18 -0000	1.3
--- aepack.py	12 Feb 2003 15:37:25 -0000	1.4
***************
*** 89,92 ****
--- 89,94 ----
  	if isinstance(x, FSSType):
  		return AE.AECreateDesc('fss ', x.data)
+ 	if isinstance(x, FSRefType):
+ 		return AE.AECreateDesc('fsrf', x.data)
  	if isinstance(x, AliasType):
  		return AE.AECreateDesc('alis', x.data)
***************
*** 167,170 ****
--- 169,174 ----
  	if t == typeFSS:
  		return Carbon.File.FSSpec(rawdata=desc.data)
+ 	if t == typeFSRef:
+ 		return Carbon.File.FSRef(rawdata=desc.data)
  	if t == typeInsertionLoc:
  		record = desc.AECoerceDesc('reco')

Index: aetypes.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/aetypes.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** aetypes.py	29 Jan 2003 10:39:19 -0000	1.2
--- aetypes.py	12 Feb 2003 15:37:25 -0000	1.3
***************
*** 12,33 ****
  def pack(*args, **kwargs):
  	from aepack import pack
! 	return apply(pack, args, kwargs)
  	
- def IsSubclass(cls, base):
- 	"""Test whether CLASS1 is the same as or a subclass of CLASS2"""
- 	# Loop to optimize for single inheritance
- 	while 1:
- 		if cls is base: return 1
- 		if len(cls.__bases__) <> 1: break
- 		cls = cls.__bases__[0]
- 	# Recurse to cope with multiple inheritance
- 	for c in cls.__bases__:
- 		if IsSubclass(c, base): return 1
- 	return 0
- 
- def IsInstance(x, cls):
- 	"""Test whether OBJECT is an instance of (a subclass of) CLASS"""
- 	return type(x) is InstanceType and IsSubclass(x.__class__, cls)
- 
  def nice(s):
  	"""'nice' representation of an object"""
--- 12,17 ----
  def pack(*args, **kwargs):
  	from aepack import pack
! 	return pack( *args, **kwargs)
  	
  def nice(s):
  	"""'nice' representation of an object"""
***************
*** 64,68 ****
  
  def IsEnum(x):
! 	return IsInstance(x, Enum)
  
  def mkenum(enum):
--- 48,52 ----
  
  def IsEnum(x):
! 	return isinstance(x, Enum)
  
  def mkenum(enum):
***************
*** 109,113 ****
  
  def IsBoolean(x):
! 	return IsInstance(x, Boolean)
  
  def mkboolean(bool):
--- 93,97 ----
  
  def IsBoolean(x):
! 	return isinstance(x, Boolean)
  
  def mkboolean(bool):
***************
*** 131,135 ****
  
  def IsType(x):
! 	return IsInstance(x, Type)
  
  def mktype(type):
--- 115,119 ----
  
  def IsType(x):
! 	return isinstance(x, Type)
  
  def mktype(type):
***************
*** 154,158 ****
  
  def IsKeyword(x):
! 	return IsInstance(x, Keyword)
  
  class Range:
--- 138,142 ----
  
  def IsKeyword(x):
! 	return isinstance(x, Keyword)
  
  class Range:
***************
*** 173,177 ****
  
  def IsRange(x):
! 	return IsInstance(x, Range)
  
  class Comparison:
--- 157,161 ----
  
  def IsRange(x):
! 	return isinstance(x, Range)
  
  class Comparison:
***************
*** 196,200 ****
  
  def IsComparison(x):
! 	return IsInstance(x, Comparison)
  	
  class NComparison(Comparison):
--- 180,184 ----
  
  def IsComparison(x):
! 	return isinstance(x, Comparison)
  	
  class NComparison(Comparison):
***************
*** 221,225 ****
  
  def IsOrdinal(x):
! 	return IsInstance(x, Ordinal)
  	
  class NOrdinal(Ordinal):
--- 205,209 ----
  
  def IsOrdinal(x):
! 	return isinstance(x, Ordinal)
  	
  class NOrdinal(Ordinal):
***************
*** 251,255 ****
  
  def IsLogical(x):
! 	return IsInstance(x, Logical)
  
  class StyledText:
--- 235,239 ----
  
  def IsLogical(x):
! 	return isinstance(x, Logical)
  
  class StyledText:
***************
*** 270,274 ****
  
  def IsStyledText(x):
! 	return IsInstance(x, StyledText)
  
  class AEText:
--- 254,258 ----
  
  def IsStyledText(x):
! 	return isinstance(x, StyledText)
  
  class AEText:
***************
*** 291,295 ****
  
  def IsAEText(x):
! 	return IsInstance(x, AEText)
  
  class IntlText:
--- 275,279 ----
  
  def IsAEText(x):
! 	return isinstance(x, AEText)
  
  class IntlText:
***************
*** 312,316 ****
  
  def IsIntlText(x):
! 	return IsInstance(x, IntlText)
  
  class IntlWritingCode:
--- 296,300 ----
  
  def IsIntlText(x):
! 	return isinstance(x, IntlText)
  
  class IntlWritingCode:
***************
*** 332,336 ****
  
  def IsIntlWritingCode(x):
! 	return IsInstance(x, IntlWritingCode)
  
  class QDPoint:
--- 316,320 ----
  
  def IsIntlWritingCode(x):
! 	return isinstance(x, IntlWritingCode)
  
  class QDPoint:
***************
*** 352,356 ****
  
  def IsQDPoint(x):
! 	return IsInstance(x, QDPoint)
  
  class QDRectangle:
--- 336,340 ----
  
  def IsQDPoint(x):
! 	return isinstance(x, QDPoint)
  
  class QDRectangle:
***************
*** 375,379 ****
  
  def IsQDRectangle(x):
! 	return IsInstance(x, QDRectangle)
  
  class RGBColor:
--- 359,363 ----
  
  def IsQDRectangle(x):
! 	return isinstance(x, QDRectangle)
  
  class RGBColor:
***************
*** 396,400 ****
  
  def IsRGBColor(x):
! 	return IsInstance(x, RGBColor)
  
  class ObjectSpecifier:
--- 380,384 ----
  
  def IsRGBColor(x):
! 	return isinstance(x, RGBColor)
  
  class ObjectSpecifier:
***************
*** 445,449 ****
  
  def IsObjectSpecifier(x):
! 	return IsInstance(x, ObjectSpecifier)
  
  
--- 429,433 ----
  
  def IsObjectSpecifier(x):
! 	return isinstance(x, ObjectSpecifier)
  
  

Index: bgenlocations.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/bgenlocations.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** bgenlocations.py	26 Jan 2003 20:33:46 -0000	1.2
--- bgenlocations.py	12 Feb 2003 15:37:26 -0000	1.3
***************
*** 27,33 ****
  #
  if sys.platform == 'mac':
! 	_MWERKSDIR="Moes:Applications (Mac OS 9):Metrowerks CodeWarrior 7.0:Metrowerks CodeWarrior"
  else:
! 	_MWERKSDIR="/Volumes/Moes/Applications (Mac OS 9)/Metrowerks CodeWarrior 7.0/Metrowerks CodeWarrior/"
  INCLUDEDIR=os.path.join(_MWERKSDIR, "MacOS Support", "Universal", "Interfaces", "CIncludes")
  
--- 27,33 ----
  #
  if sys.platform == 'mac':
! 	_MWERKSDIR="Sap:Applications (Mac OS 9):Metrowerks CodeWarrior 7.0:Metrowerks CodeWarrior"
  else:
! 	_MWERKSDIR="/Volumes/Sap/Applications (Mac OS 9)/Metrowerks CodeWarrior 7.0/Metrowerks CodeWarrior/"
  INCLUDEDIR=os.path.join(_MWERKSDIR, "MacOS Support", "Universal", "Interfaces", "CIncludes")
  

Index: buildtools.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/buildtools.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** buildtools.py	5 Feb 2003 13:39:04 -0000	1.4
--- buildtools.py	12 Feb 2003 15:37:26 -0000	1.5
***************
*** 45,51 ****
  	"""Locate the applet template along sys.path"""
  	if MacOS.runtimemodel == 'macho':
! 		if template:
! 			return template
! 		return findtemplate_macho()
  	if not template:
  		template=TEMPLATE
--- 45,49 ----
  	"""Locate the applet template along sys.path"""
  	if MacOS.runtimemodel == 'macho':
! 		return None
  	if not template:
  		template=TEMPLATE
***************
*** 62,74 ****
  	return file
  	
! def findtemplate_macho():
! 	execpath = sys.executable.split('/')
! 	if not 'Contents' in execpath:
! 		raise BuildError, "Not running from a .app bundle: %s" % sys.executable
! 	i = execpath.index('Contents')
! 	return '/'.join(execpath[:i])
! 
! 
! def process(template, filename, destname, copy_codefragment, 
  		rsrcname=None, others=[], raw=0, progress="default"):
  	
--- 60,64 ----
  	return file
  	
! def process(template, filename, destname, copy_codefragment=0, 
  		rsrcname=None, others=[], raw=0, progress="default"):
  	
***************
*** 119,123 ****
  		pass
  	process_common(template, progress, code, rsrcname, destname, 0, 
! 		copy_codefragment, raw, others)
  	
  
--- 109,113 ----
  		pass
  	process_common(template, progress, code, rsrcname, destname, 0, 
! 		copy_codefragment, raw, others, filename)
  	
  
***************
*** 141,148 ****
  
  def process_common(template, progress, code, rsrcname, destname, is_update, 
! 		copy_codefragment, raw=0, others=[]):
  	if MacOS.runtimemodel == 'macho':
  		return process_common_macho(template, progress, code, rsrcname, destname,
! 			is_update, raw, others)
  	if others:
  		raise BuildError, "Extra files only allowed for MachoPython applets"
--- 131,138 ----
  
  def process_common(template, progress, code, rsrcname, destname, is_update, 
! 		copy_codefragment, raw=0, others=[], filename=None):
  	if MacOS.runtimemodel == 'macho':
  		return process_common_macho(template, progress, code, rsrcname, destname,
! 			is_update, raw, others, filename)
  	if others:
  		raise BuildError, "Extra files only allowed for MachoPython applets"
***************
*** 275,284 ****
  		progress.inc(0)
  
! def process_common_macho(template, progress, code, rsrcname, destname, is_update, raw=0, others=[]):
  	# First make sure the name ends in ".app"
  	if destname[-4:] != '.app':
  		destname = destname + '.app'
  	# Now deduce the short name
! 	shortname = os.path.split(destname)[1]
  	if shortname[-4:] == '.app':
  		# Strip the .app suffix
--- 265,278 ----
  		progress.inc(0)
  
! def process_common_macho(template, progress, code, rsrcname, destname, is_update, 
! 		raw=0, others=[], filename=None):
! 	# Check that we have a filename
! 	if filename is None:
! 		raise BuildError, "Need source filename on MacOSX"
  	# First make sure the name ends in ".app"
  	if destname[-4:] != '.app':
  		destname = destname + '.app'
  	# Now deduce the short name
! 	destdir, shortname = os.path.split(destname)
  	if shortname[-4:] == '.app':
  		# Strip the .app suffix
***************
*** 296,429 ****
  		else:
  			plistname = None
! 	# Start with copying the .app framework
! 	if not is_update:
! 		exceptlist = ["Contents/Info.plist", 
! 				"Contents/Resources/English.lproj/InfoPlist.strings", 
! 				"Contents/Resources/English.lproj/Documentation", 
! 				"Contents/Resources/python.rsrc",
! 				]
! 		copyapptree(template, destname, exceptlist, progress)
! 		# SERIOUS HACK. If we've just copied a symlink as the
! 		# executable we assume we're running from the MacPython addon
! 		# to 10.2 python. We remove the symlink again and install
! 		# the appletrunner script.
! 		executable = os.path.join(destname, "Contents/MacOS/python")
! 		if os.path.islink(executable):
! 			os.remove(executable)
! 			dummyfp, appletrunner, d2 = imp.find_module('appletrunner')
! 			del dummyfp
! 			shutil.copy2(appletrunner, executable)
! 			os.chmod(executable, 0775)
! 	# Now either use the .plist file or the default
  	if progress:
! 		progress.label('Create info.plist')
! 		progress.inc(0)
  	if plistname:
! 		shutil.copy2(plistname, os.path.join(destname, 'Contents', 'Info.plist'))
! 		if icnsname:
! 			icnsdest = os.path.split(icnsname)[1]
! 			icnsdest = os.path.join(destname, 
! 				os.path.join('Contents', 'Resources', icnsdest))
! 			shutil.copy2(icnsname, icnsdest)
! 		# XXXX Wrong. This should be parsed from plist file. Also a big hack:-)
! 		if shortname == 'PythonIDE':
! 			ownertype = 'Pide'
! 		else:
! 			ownertype = 'PytA'
! 		# XXXX Should copy .icns file
! 	else:
! 		cocoainfo = ''
! 		for o in others:
! 			if o[-4:] == '.nib':
! 				nibname = os.path.split(o)[1][:-4]
! 				cocoainfo = """
!         <key>NSMainNibFile</key>
!         <string>%s</string>
!         <key>NSPrincipalClass</key>
!         <string>NSApplication</string>""" % nibname
! 			elif o[-6:] == '.lproj':
! 				files = os.listdir(o)
! 				for f in files:
! 					if f[-4:] == '.nib':
! 						nibname = os.path.split(f)[1][:-4]
! 						cocoainfo = """
!         <key>NSMainNibFile</key>
!         <string>%s</string>
!         <key>NSPrincipalClass</key>
!         <string>NSApplication</string>""" % nibname
! 
! 		plistname = os.path.join(template, 'Contents', 'Resources', 'Applet-Info.plist')
! 		plistdata = open(plistname).read()
! 		plistdata = plistdata % {'appletname':shortname, 'cocoainfo':cocoainfo}
! 		ofp = open(os.path.join(destname, 'Contents', 'Info.plist'), 'w')
! 		ofp.write(plistdata)
! 		ofp.close()
! 		ownertype = 'PytA'
! 	# Create the PkgInfo file
! 	if progress:
! 		progress.label('Create PkgInfo')
! 		progress.inc(0)
! 	ofp = open(os.path.join(destname, 'Contents', 'PkgInfo'), 'wb')
! 	ofp.write('APPL' + ownertype)
! 	ofp.close()
! 		
! 	
! 	# Copy the resources from the target specific resource template, if any
! 	typesfound, ownertype = [], None
! 	try:
! 		input = macresource.open_pathname(rsrcname)
! 	except (MacOS.Error, ValueError):
! 		if progress:
! 			progress.inc(50)
! 	else:
! 		if progress:
! 			progress.label("Copy resources...")
! 			progress.set(20)
! 		resfilename = 'python.rsrc'  # XXXX later: '%s.rsrc' % shortname
! 		try:
! 			output = Res.FSOpenResourceFile(
! 					os.path.join(destname, 'Contents', 'Resources', resfilename), 
! 					u'', WRITE)
! 		except MacOS.Error:
! 			fsr, dummy = Res.FSCreateResourceFile(
! 					os.path.join(destname, 'Contents', 'Resources'), 
! 					unicode(resfilename), '')
! 			output = Res.FSOpenResourceFile(fsr, u'', WRITE)
! 		
! 		typesfound, ownertype = copyres(input, output, [], 0, progress)
! 		Res.CloseResFile(input)
! 		Res.CloseResFile(output)
! 
! 	if code:
! 		if raw:
! 			pycname = '__rawmain__.pyc'
! 		else:
! 			pycname = '__main__.pyc'
! 			# And we also create __rawmain__.pyc
! 			outputfilename = os.path.join(destname, 'Contents', 'Resources', '__rawmain__.pyc')
! 			if progress:
! 				progress.label('Creating __rawmain__.pyc')
! 				progress.inc(0)
! 			rawsourcefp, rawsourcefile, d2 = imp.find_module('appletrawmain')
! 			rawsource = rawsourcefp.read()
! 			rawcode = compile(rawsource, rawsourcefile, 'exec')
! 			writepycfile(rawcode, outputfilename)
! 			
! 		outputfilename = os.path.join(destname, 'Contents', 'Resources', pycname)
! 		if progress:
! 			progress.label('Creating '+pycname)
! 			progress.inc(0)
! 		writepycfile(code, outputfilename)
! 	# Copy other files the user asked for
! 	for osrc in others:
! 		oname = os.path.split(osrc)[1]
! 		odst = os.path.join(destname, 'Contents', 'Resources', oname)
! 		if progress: 
! 			progress.label('Copy ' + oname)
! 			progress.inc(0)
! 		if os.path.isdir(osrc):
! 			copyapptree(osrc, odst)
! 		else:
! 			shutil.copy2(osrc, odst)
  	if progress: 
  		progress.label('Done.')
--- 290,313 ----
  		else:
  			plistname = None
! 	if not os.path.exists(rsrcname):
! 		rsrcname = None
  	if progress:
! 		progress.label('Creating bundle...')
! 	import bundlebuilder
! 	builder = bundlebuilder.AppBuilder(verbosity=0)
! 	builder.mainprogram = filename
! 	builder.builddir = destdir
! 	builder.name = shortname
! 	if rsrcname:
! 		builder.resources.append(rsrcname)
! 	for o in others:
! 		builder.resources.append(o)
  	if plistname:
! 		import Plist
! 		builder.plist = Plist.fromFile(plistname)
! 	if icnsname:
! 		builder.iconfile = icnsname
! 	builder.setup()
! 	builder.build()
  	if progress: 
  		progress.label('Done.')