mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	When in MacPython-OSX use bundlebuilder to create .app bundles.
This commit is contained in:
		
							parent
							
								
									53b341ff67
								
							
						
					
					
						commit
						f59c6fa125
					
				
					 4 changed files with 52 additions and 180 deletions
				
			
		| 
						 | 
					@ -88,6 +88,8 @@ def pack(x, forcetype = None):
 | 
				
			||||||
		return x
 | 
							return x
 | 
				
			||||||
	if isinstance(x, FSSType):
 | 
						if isinstance(x, FSSType):
 | 
				
			||||||
		return AE.AECreateDesc('fss ', x.data)
 | 
							return AE.AECreateDesc('fss ', x.data)
 | 
				
			||||||
 | 
						if isinstance(x, FSRefType):
 | 
				
			||||||
 | 
							return AE.AECreateDesc('fsrf', x.data)
 | 
				
			||||||
	if isinstance(x, AliasType):
 | 
						if isinstance(x, AliasType):
 | 
				
			||||||
		return AE.AECreateDesc('alis', x.data)
 | 
							return AE.AECreateDesc('alis', x.data)
 | 
				
			||||||
	if isinstance(x, IntType):
 | 
						if isinstance(x, IntType):
 | 
				
			||||||
| 
						 | 
					@ -166,6 +168,8 @@ def unpack(desc, formodulename=""):
 | 
				
			||||||
		return struct.unpack('d', data)[0]
 | 
							return struct.unpack('d', data)[0]
 | 
				
			||||||
	if t == typeFSS:
 | 
						if t == typeFSS:
 | 
				
			||||||
		return Carbon.File.FSSpec(rawdata=desc.data)
 | 
							return Carbon.File.FSSpec(rawdata=desc.data)
 | 
				
			||||||
 | 
						if t == typeFSRef:
 | 
				
			||||||
 | 
							return Carbon.File.FSRef(rawdata=desc.data)
 | 
				
			||||||
	if t == typeInsertionLoc:
 | 
						if t == typeInsertionLoc:
 | 
				
			||||||
		record = desc.AECoerceDesc('reco')
 | 
							record = desc.AECoerceDesc('reco')
 | 
				
			||||||
		return mkinsertionloc(unpack(record, formodulename))
 | 
							return mkinsertionloc(unpack(record, formodulename))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,23 +11,7 @@
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
def pack(*args, **kwargs):
 | 
					def pack(*args, **kwargs):
 | 
				
			||||||
	from aepack import pack
 | 
						from aepack import pack
 | 
				
			||||||
	return apply(pack, args, kwargs)
 | 
						return 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):
 | 
					def nice(s):
 | 
				
			||||||
	"""'nice' representation of an object"""
 | 
						"""'nice' representation of an object"""
 | 
				
			||||||
| 
						 | 
					@ -63,7 +47,7 @@ def __aepack__(self):
 | 
				
			||||||
		return pack(self.enum, typeEnumeration)
 | 
							return pack(self.enum, typeEnumeration)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def IsEnum(x):
 | 
					def IsEnum(x):
 | 
				
			||||||
	return IsInstance(x, Enum)
 | 
						return isinstance(x, Enum)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def mkenum(enum):
 | 
					def mkenum(enum):
 | 
				
			||||||
	if IsEnum(enum): return enum
 | 
						if IsEnum(enum): return enum
 | 
				
			||||||
| 
						 | 
					@ -108,7 +92,7 @@ def __aepack__(self):
 | 
				
			||||||
		return pack(struct.pack('b', self.bool), 'bool')
 | 
							return pack(struct.pack('b', self.bool), 'bool')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def IsBoolean(x):
 | 
					def IsBoolean(x):
 | 
				
			||||||
	return IsInstance(x, Boolean)
 | 
						return isinstance(x, Boolean)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def mkboolean(bool):
 | 
					def mkboolean(bool):
 | 
				
			||||||
	if IsBoolean(bool): return bool
 | 
						if IsBoolean(bool): return bool
 | 
				
			||||||
| 
						 | 
					@ -130,7 +114,7 @@ def __aepack__(self):
 | 
				
			||||||
		return pack(self.type, typeType)
 | 
							return pack(self.type, typeType)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def IsType(x):
 | 
					def IsType(x):
 | 
				
			||||||
	return IsInstance(x, Type)
 | 
						return isinstance(x, Type)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def mktype(type):
 | 
					def mktype(type):
 | 
				
			||||||
	if IsType(type): return type
 | 
						if IsType(type): return type
 | 
				
			||||||
| 
						 | 
					@ -153,7 +137,7 @@ def __aepack__(self):
 | 
				
			||||||
		return pack(self.keyword, typeKeyword)
 | 
							return pack(self.keyword, typeKeyword)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def IsKeyword(x):
 | 
					def IsKeyword(x):
 | 
				
			||||||
	return IsInstance(x, Keyword)
 | 
						return isinstance(x, Keyword)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Range:
 | 
					class Range:
 | 
				
			||||||
	"""An AE range object"""
 | 
						"""An AE range object"""
 | 
				
			||||||
| 
						 | 
					@ -172,7 +156,7 @@ def __aepack__(self):
 | 
				
			||||||
		return pack({'star': self.start, 'stop': self.stop}, 'rang')
 | 
							return pack({'star': self.start, 'stop': self.stop}, 'rang')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def IsRange(x):
 | 
					def IsRange(x):
 | 
				
			||||||
	return IsInstance(x, Range)
 | 
						return isinstance(x, Range)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Comparison:
 | 
					class Comparison:
 | 
				
			||||||
	"""An AE Comparison"""
 | 
						"""An AE Comparison"""
 | 
				
			||||||
| 
						 | 
					@ -195,7 +179,7 @@ def __aepack__(self):
 | 
				
			||||||
			    'cmpd')
 | 
								    'cmpd')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def IsComparison(x):
 | 
					def IsComparison(x):
 | 
				
			||||||
	return IsInstance(x, Comparison)
 | 
						return isinstance(x, Comparison)
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
class NComparison(Comparison):
 | 
					class NComparison(Comparison):
 | 
				
			||||||
	# The class attribute 'relo' must be set in a subclass
 | 
						# The class attribute 'relo' must be set in a subclass
 | 
				
			||||||
| 
						 | 
					@ -220,7 +204,7 @@ def __aepack__(self):
 | 
				
			||||||
		return pack(self.abso, 'abso')
 | 
							return pack(self.abso, 'abso')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def IsOrdinal(x):
 | 
					def IsOrdinal(x):
 | 
				
			||||||
	return IsInstance(x, Ordinal)
 | 
						return isinstance(x, Ordinal)
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
class NOrdinal(Ordinal):
 | 
					class NOrdinal(Ordinal):
 | 
				
			||||||
	# The class attribute 'abso' must be set in a subclass
 | 
						# The class attribute 'abso' must be set in a subclass
 | 
				
			||||||
| 
						 | 
					@ -250,7 +234,7 @@ def __aepack__(self):
 | 
				
			||||||
		return pack({'logc': mkenum(self.logc), 'term': self.term}, 'logi')
 | 
							return pack({'logc': mkenum(self.logc), 'term': self.term}, 'logi')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def IsLogical(x):
 | 
					def IsLogical(x):
 | 
				
			||||||
	return IsInstance(x, Logical)
 | 
						return isinstance(x, Logical)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class StyledText:
 | 
					class StyledText:
 | 
				
			||||||
	"""An AE object respresenting text in a certain style"""
 | 
						"""An AE object respresenting text in a certain style"""
 | 
				
			||||||
| 
						 | 
					@ -269,7 +253,7 @@ def __aepack__(self):
 | 
				
			||||||
		return pack({'ksty': self.style, 'ktxt': self.text}, 'STXT')
 | 
							return pack({'ksty': self.style, 'ktxt': self.text}, 'STXT')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def IsStyledText(x):
 | 
					def IsStyledText(x):
 | 
				
			||||||
	return IsInstance(x, StyledText)
 | 
						return isinstance(x, StyledText)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class AEText:
 | 
					class AEText:
 | 
				
			||||||
	"""An AE text object with style, script and language specified"""
 | 
						"""An AE text object with style, script and language specified"""
 | 
				
			||||||
| 
						 | 
					@ -290,7 +274,7 @@ def __aepack__(self):
 | 
				
			||||||
				 keyAEText: self.text}, typeAEText)
 | 
									 keyAEText: self.text}, typeAEText)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def IsAEText(x):
 | 
					def IsAEText(x):
 | 
				
			||||||
	return IsInstance(x, AEText)
 | 
						return isinstance(x, AEText)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class IntlText:
 | 
					class IntlText:
 | 
				
			||||||
	"""A text object with script and language specified"""
 | 
						"""A text object with script and language specified"""
 | 
				
			||||||
| 
						 | 
					@ -311,7 +295,7 @@ def __aepack__(self):
 | 
				
			||||||
			typeIntlText)
 | 
								typeIntlText)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def IsIntlText(x):
 | 
					def IsIntlText(x):
 | 
				
			||||||
	return IsInstance(x, IntlText)
 | 
						return isinstance(x, IntlText)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class IntlWritingCode:
 | 
					class IntlWritingCode:
 | 
				
			||||||
	"""An object representing script and language"""
 | 
						"""An object representing script and language"""
 | 
				
			||||||
| 
						 | 
					@ -331,7 +315,7 @@ def __aepack__(self):
 | 
				
			||||||
			typeIntlWritingCode)
 | 
								typeIntlWritingCode)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def IsIntlWritingCode(x):
 | 
					def IsIntlWritingCode(x):
 | 
				
			||||||
	return IsInstance(x, IntlWritingCode)
 | 
						return isinstance(x, IntlWritingCode)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class QDPoint:
 | 
					class QDPoint:
 | 
				
			||||||
	"""A point"""
 | 
						"""A point"""
 | 
				
			||||||
| 
						 | 
					@ -351,7 +335,7 @@ def __aepack__(self):
 | 
				
			||||||
			typeQDPoint)
 | 
								typeQDPoint)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def IsQDPoint(x):
 | 
					def IsQDPoint(x):
 | 
				
			||||||
	return IsInstance(x, QDPoint)
 | 
						return isinstance(x, QDPoint)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class QDRectangle:
 | 
					class QDRectangle:
 | 
				
			||||||
	"""A rectangle"""
 | 
						"""A rectangle"""
 | 
				
			||||||
| 
						 | 
					@ -374,7 +358,7 @@ def __aepack__(self):
 | 
				
			||||||
			typeQDRectangle)
 | 
								typeQDRectangle)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def IsQDRectangle(x):
 | 
					def IsQDRectangle(x):
 | 
				
			||||||
	return IsInstance(x, QDRectangle)
 | 
						return isinstance(x, QDRectangle)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class RGBColor:
 | 
					class RGBColor:
 | 
				
			||||||
	"""An RGB color"""
 | 
						"""An RGB color"""
 | 
				
			||||||
| 
						 | 
					@ -395,7 +379,7 @@ def __aepack__(self):
 | 
				
			||||||
			typeRGBColor)
 | 
								typeRGBColor)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def IsRGBColor(x):
 | 
					def IsRGBColor(x):
 | 
				
			||||||
	return IsInstance(x, RGBColor)
 | 
						return isinstance(x, RGBColor)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ObjectSpecifier:
 | 
					class ObjectSpecifier:
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
| 
						 | 
					@ -444,7 +428,7 @@ def __aepack__(self):
 | 
				
			||||||
			    'obj ')
 | 
								    'obj ')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def IsObjectSpecifier(x):
 | 
					def IsObjectSpecifier(x):
 | 
				
			||||||
	return IsInstance(x, ObjectSpecifier)
 | 
						return isinstance(x, ObjectSpecifier)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Backwards compatability, sigh...
 | 
					# Backwards compatability, sigh...
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,9 +26,9 @@ def _pardir(p): return os.path.split(p)[0]
 | 
				
			||||||
# end of lines, so don't worry about that.
 | 
					# end of lines, so don't worry about that.
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
if sys.platform == 'mac':
 | 
					if sys.platform == 'mac':
 | 
				
			||||||
	_MWERKSDIR="Moes:Applications (Mac OS 9):Metrowerks CodeWarrior 7.0:Metrowerks CodeWarrior"
 | 
						_MWERKSDIR="Sap:Applications (Mac OS 9):Metrowerks CodeWarrior 7.0:Metrowerks CodeWarrior"
 | 
				
			||||||
else:
 | 
					else:
 | 
				
			||||||
	_MWERKSDIR="/Volumes/Moes/Applications (Mac OS 9)/Metrowerks CodeWarrior 7.0/Metrowerks CodeWarrior/"
 | 
						_MWERKSDIR="/Volumes/Sap/Applications (Mac OS 9)/Metrowerks CodeWarrior 7.0/Metrowerks CodeWarrior/"
 | 
				
			||||||
INCLUDEDIR=os.path.join(_MWERKSDIR, "MacOS Support", "Universal", "Interfaces", "CIncludes")
 | 
					INCLUDEDIR=os.path.join(_MWERKSDIR, "MacOS Support", "Universal", "Interfaces", "CIncludes")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -44,9 +44,7 @@
 | 
				
			||||||
def findtemplate(template=None):
 | 
					def findtemplate(template=None):
 | 
				
			||||||
	"""Locate the applet template along sys.path"""
 | 
						"""Locate the applet template along sys.path"""
 | 
				
			||||||
	if MacOS.runtimemodel == 'macho':
 | 
						if MacOS.runtimemodel == 'macho':
 | 
				
			||||||
		if template:
 | 
							return None
 | 
				
			||||||
			return template
 | 
					 | 
				
			||||||
		return findtemplate_macho()
 | 
					 | 
				
			||||||
	if not template:
 | 
						if not template:
 | 
				
			||||||
		template=TEMPLATE
 | 
							template=TEMPLATE
 | 
				
			||||||
	for p in sys.path:
 | 
						for p in sys.path:
 | 
				
			||||||
| 
						 | 
					@ -61,15 +59,7 @@ def findtemplate(template=None):
 | 
				
			||||||
	file = file.as_pathname()
 | 
						file = file.as_pathname()
 | 
				
			||||||
	return file
 | 
						return file
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
def findtemplate_macho():
 | 
					def process(template, filename, destname, copy_codefragment=0, 
 | 
				
			||||||
	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"):
 | 
							rsrcname=None, others=[], raw=0, progress="default"):
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	if progress == "default":
 | 
						if progress == "default":
 | 
				
			||||||
| 
						 | 
					@ -118,7 +108,7 @@ def process(template, filename, destname, copy_codefragment,
 | 
				
			||||||
	except os.error:
 | 
						except os.error:
 | 
				
			||||||
		pass
 | 
							pass
 | 
				
			||||||
	process_common(template, progress, code, rsrcname, destname, 0, 
 | 
						process_common(template, progress, code, rsrcname, destname, 0, 
 | 
				
			||||||
		copy_codefragment, raw, others)
 | 
							copy_codefragment, raw, others, filename)
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def update(template, filename, output):
 | 
					def update(template, filename, output):
 | 
				
			||||||
| 
						 | 
					@ -140,10 +130,10 @@ def update(template, filename, output):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def process_common(template, progress, code, rsrcname, destname, is_update, 
 | 
					def process_common(template, progress, code, rsrcname, destname, is_update, 
 | 
				
			||||||
		copy_codefragment, raw=0, others=[]):
 | 
							copy_codefragment, raw=0, others=[], filename=None):
 | 
				
			||||||
	if MacOS.runtimemodel == 'macho':
 | 
						if MacOS.runtimemodel == 'macho':
 | 
				
			||||||
		return process_common_macho(template, progress, code, rsrcname, destname,
 | 
							return process_common_macho(template, progress, code, rsrcname, destname,
 | 
				
			||||||
			is_update, raw, others)
 | 
								is_update, raw, others, filename)
 | 
				
			||||||
	if others:
 | 
						if others:
 | 
				
			||||||
		raise BuildError, "Extra files only allowed for MachoPython applets"
 | 
							raise BuildError, "Extra files only allowed for MachoPython applets"
 | 
				
			||||||
	# Create FSSpecs for the various files
 | 
						# Create FSSpecs for the various files
 | 
				
			||||||
| 
						 | 
					@ -274,12 +264,16 @@ def process_common(template, progress, code, rsrcname, destname, is_update,
 | 
				
			||||||
		progress.label("Done.")
 | 
							progress.label("Done.")
 | 
				
			||||||
		progress.inc(0)
 | 
							progress.inc(0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def process_common_macho(template, progress, code, rsrcname, destname, is_update, raw=0, others=[]):
 | 
					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"
 | 
						# First make sure the name ends in ".app"
 | 
				
			||||||
	if destname[-4:] != '.app':
 | 
						if destname[-4:] != '.app':
 | 
				
			||||||
		destname = destname + '.app'
 | 
							destname = destname + '.app'
 | 
				
			||||||
	# Now deduce the short name
 | 
						# Now deduce the short name
 | 
				
			||||||
	shortname = os.path.split(destname)[1]
 | 
						destdir, shortname = os.path.split(destname)
 | 
				
			||||||
	if shortname[-4:] == '.app':
 | 
						if shortname[-4:] == '.app':
 | 
				
			||||||
		# Strip the .app suffix
 | 
							# Strip the .app suffix
 | 
				
			||||||
		shortname = shortname[:-4]
 | 
							shortname = shortname[:-4]
 | 
				
			||||||
| 
						 | 
					@ -295,136 +289,26 @@ def process_common_macho(template, progress, code, rsrcname, destname, is_update
 | 
				
			||||||
				icnsname = None
 | 
									icnsname = None
 | 
				
			||||||
		else:
 | 
							else:
 | 
				
			||||||
			plistname = None
 | 
								plistname = None
 | 
				
			||||||
	# Start with copying the .app framework
 | 
						if not os.path.exists(rsrcname):
 | 
				
			||||||
	if not is_update:
 | 
							rsrcname = None
 | 
				
			||||||
		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:
 | 
						if progress:
 | 
				
			||||||
		progress.label('Create info.plist')
 | 
							progress.label('Creating bundle...')
 | 
				
			||||||
		progress.inc(0)
 | 
						import bundlebuilder
 | 
				
			||||||
	if plistname:
 | 
						builder = bundlebuilder.AppBuilder(verbosity=0)
 | 
				
			||||||
		shutil.copy2(plistname, os.path.join(destname, 'Contents', 'Info.plist'))
 | 
						builder.mainprogram = filename
 | 
				
			||||||
		if icnsname:
 | 
						builder.builddir = destdir
 | 
				
			||||||
			icnsdest = os.path.split(icnsname)[1]
 | 
						builder.name = shortname
 | 
				
			||||||
			icnsdest = os.path.join(destname, 
 | 
						if rsrcname:
 | 
				
			||||||
				os.path.join('Contents', 'Resources', icnsdest))
 | 
							builder.resources.append(rsrcname)
 | 
				
			||||||
			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:
 | 
						for o in others:
 | 
				
			||||||
			if o[-4:] == '.nib':
 | 
							builder.resources.append(o)
 | 
				
			||||||
				nibname = os.path.split(o)[1][:-4]
 | 
						if plistname:
 | 
				
			||||||
				cocoainfo = """
 | 
							import Plist
 | 
				
			||||||
        <key>NSMainNibFile</key>
 | 
							builder.plist = Plist.fromFile(plistname)
 | 
				
			||||||
        <string>%s</string>
 | 
						if icnsname:
 | 
				
			||||||
        <key>NSPrincipalClass</key>
 | 
							builder.iconfile = icnsname
 | 
				
			||||||
        <string>NSApplication</string>""" % nibname
 | 
						builder.setup()
 | 
				
			||||||
			elif o[-6:] == '.lproj':
 | 
						builder.build()
 | 
				
			||||||
				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: 
 | 
						if progress: 
 | 
				
			||||||
		progress.label('Done.')
 | 
							progress.label('Done.')
 | 
				
			||||||
		progress.inc(0)
 | 
							progress.inc(0)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue