| 
									
										
										
										
											1995-08-09 15:16:58 +00:00
										 |  |  | # This python script creates Finder aliases for all the | 
					
						
							|  |  |  | # dynamically-loaded modules that "live in" in a single | 
					
						
							|  |  |  | # shared library. | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											1996-08-28 14:19:53 +00:00
										 |  |  | # This is sort-of a merger between Jack's MkPluginAliases | 
					
						
							|  |  |  | # and Guido's mkaliases. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Jack Jansen, CWI, August 1996 | 
					
						
							| 
									
										
										
										
											1995-08-09 15:16:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | import sys | 
					
						
							| 
									
										
										
										
											1996-08-28 14:19:53 +00:00
										 |  |  | import os | 
					
						
							| 
									
										
										
										
											1995-09-24 21:06:50 +00:00
										 |  |  | import macfs | 
					
						
							| 
									
										
										
										
											1997-09-08 13:16:29 +00:00
										 |  |  | import MacOS | 
					
						
							| 
									
										
										
										
											1997-08-27 14:11:15 +00:00
										 |  |  | verbose=0 | 
					
						
							| 
									
										
										
										
											1995-08-09 15:16:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-09-08 13:16:29 +00:00
										 |  |  | SPLASH_LOCATE=512 | 
					
						
							|  |  |  | SPLASH_REMOVE=513 | 
					
						
							|  |  |  | SPLASH_CFM68K=514 | 
					
						
							|  |  |  | SPLASH_PPC=515 | 
					
						
							|  |  |  | SPLASH_NUMPY=516 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-08-20 16:35:30 +00:00
										 |  |  | ppc_goals = [ | 
					
						
							|  |  |  | 	("AE.ppc.slb", "toolboxmodules.ppc.slb"), | 
					
						
							|  |  |  | 	("Ctl.ppc.slb", "toolboxmodules.ppc.slb"), | 
					
						
							|  |  |  | 	("Dlg.ppc.slb", "toolboxmodules.ppc.slb"), | 
					
						
							|  |  |  | 	("Evt.ppc.slb", "toolboxmodules.ppc.slb"), | 
					
						
							|  |  |  | 	("Fm.ppc.slb", "toolboxmodules.ppc.slb"), | 
					
						
							| 
									
										
										
										
											1997-09-09 13:57:59 +00:00
										 |  |  | 	("Help.ppc.slb", "toolboxmodules.ppc.slb"), | 
					
						
							| 
									
										
										
										
											1999-01-25 12:39:39 +00:00
										 |  |  | 	("Icn.ppc.slb", "toolboxmodules.ppc.slb"), | 
					
						
							| 
									
										
										
										
											1996-08-20 16:35:30 +00:00
										 |  |  | 	("Menu.ppc.slb", "toolboxmodules.ppc.slb"), | 
					
						
							|  |  |  | 	("List.ppc.slb", "toolboxmodules.ppc.slb"), | 
					
						
							|  |  |  | 	("Qd.ppc.slb", "toolboxmodules.ppc.slb"), | 
					
						
							|  |  |  | 	("Res.ppc.slb", "toolboxmodules.ppc.slb"), | 
					
						
							|  |  |  | 	("Scrap.ppc.slb", "toolboxmodules.ppc.slb"), | 
					
						
							|  |  |  | 	("Snd.ppc.slb", "toolboxmodules.ppc.slb"), | 
					
						
							| 
									
										
										
										
											1998-04-15 14:06:17 +00:00
										 |  |  | 	("Sndihooks.ppc.slb", "toolboxmodules.ppc.slb"), | 
					
						
							| 
									
										
										
										
											1996-08-20 16:35:30 +00:00
										 |  |  | 	("TE.ppc.slb", "toolboxmodules.ppc.slb"), | 
					
						
							|  |  |  | 	("Win.ppc.slb", "toolboxmodules.ppc.slb"), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	("Cm.ppc.slb", "qtmodules.ppc.slb"), | 
					
						
							|  |  |  | 	("Qt.ppc.slb", "qtmodules.ppc.slb"), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	("imgcolormap.ppc.slb", "imgmodules.ppc.slb"), | 
					
						
							|  |  |  | 	("imgformat.ppc.slb", "imgmodules.ppc.slb"), | 
					
						
							|  |  |  | 	("imggif.ppc.slb", "imgmodules.ppc.slb"), | 
					
						
							|  |  |  | 	("imgjpeg.ppc.slb", "imgmodules.ppc.slb"), | 
					
						
							|  |  |  | 	("imgop.ppc.slb", "imgmodules.ppc.slb"), | 
					
						
							|  |  |  | 	("imgpbm.ppc.slb", "imgmodules.ppc.slb"), | 
					
						
							|  |  |  | 	("imgpgm.ppc.slb", "imgmodules.ppc.slb"), | 
					
						
							|  |  |  | 	("imgppm.ppc.slb", "imgmodules.ppc.slb"), | 
					
						
							|  |  |  | 	("imgtiff.ppc.slb", "imgmodules.ppc.slb"), | 
					
						
							|  |  |  | 	("imgsgi.ppc.slb", "imgmodules.ppc.slb") | 
					
						
							|  |  |  | ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | cfm68k_goals = [ | 
					
						
							|  |  |  | 	("AE.CFM68K.slb", "toolboxmodules.CFM68K.slb"), | 
					
						
							|  |  |  | 	("Ctl.CFM68K.slb", "toolboxmodules.CFM68K.slb"), | 
					
						
							|  |  |  | 	("Dlg.CFM68K.slb", "toolboxmodules.CFM68K.slb"), | 
					
						
							|  |  |  | 	("Evt.CFM68K.slb", "toolboxmodules.CFM68K.slb"), | 
					
						
							|  |  |  | 	("Fm.CFM68K.slb", "toolboxmodules.CFM68K.slb"), | 
					
						
							| 
									
										
										
										
											1997-09-09 13:57:59 +00:00
										 |  |  | 	("Help.CFM68K.slb", "toolboxmodules.CFM68K.slb"), | 
					
						
							| 
									
										
										
										
											1999-01-25 12:39:39 +00:00
										 |  |  | 	("Icn.CFM68K.slb", "toolboxmodules.CFM68K.slb"), | 
					
						
							| 
									
										
										
										
											1996-08-20 16:35:30 +00:00
										 |  |  | 	("Menu.CFM68K.slb", "toolboxmodules.CFM68K.slb"), | 
					
						
							|  |  |  | 	("List.CFM68K.slb", "toolboxmodules.CFM68K.slb"), | 
					
						
							|  |  |  | 	("Qd.CFM68K.slb", "toolboxmodules.CFM68K.slb"), | 
					
						
							|  |  |  | 	("Res.CFM68K.slb", "toolboxmodules.CFM68K.slb"), | 
					
						
							|  |  |  | 	("Scrap.CFM68K.slb", "toolboxmodules.CFM68K.slb"), | 
					
						
							|  |  |  | 	("Snd.CFM68K.slb", "toolboxmodules.CFM68K.slb"), | 
					
						
							| 
									
										
										
										
											1998-04-15 14:06:17 +00:00
										 |  |  | 	("Sndihooks.CFM68K.slb", "toolboxmodules.CFM68K.slb"), | 
					
						
							| 
									
										
										
										
											1996-08-20 16:35:30 +00:00
										 |  |  | 	("TE.CFM68K.slb", "toolboxmodules.CFM68K.slb"), | 
					
						
							|  |  |  | 	("Win.CFM68K.slb", "toolboxmodules.CFM68K.slb"), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	("Cm.CFM68K.slb", "qtmodules.CFM68K.slb"), | 
					
						
							|  |  |  | 	("Qt.CFM68K.slb", "qtmodules.CFM68K.slb"), | 
					
						
							| 
									
										
										
										
											1996-10-08 09:25:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	("imgcolormap.CFM68K.slb", "imgmodules.CFM68K.slb"), | 
					
						
							|  |  |  | 	("imgformat.CFM68K.slb", "imgmodules.CFM68K.slb"), | 
					
						
							|  |  |  | 	("imggif.CFM68K.slb", "imgmodules.CFM68K.slb"), | 
					
						
							|  |  |  | 	("imgjpeg.CFM68K.slb", "imgmodules.CFM68K.slb"), | 
					
						
							|  |  |  | 	("imgop.CFM68K.slb", "imgmodules.CFM68K.slb"), | 
					
						
							|  |  |  | 	("imgpbm.CFM68K.slb", "imgmodules.CFM68K.slb"), | 
					
						
							|  |  |  | 	("imgpgm.CFM68K.slb", "imgmodules.CFM68K.slb"), | 
					
						
							|  |  |  | 	("imgppm.CFM68K.slb", "imgmodules.CFM68K.slb"), | 
					
						
							|  |  |  | 	("imgtiff.CFM68K.slb", "imgmodules.CFM68K.slb"), | 
					
						
							|  |  |  | 	("imgsgi.CFM68K.slb", "imgmodules.CFM68K.slb") | 
					
						
							| 
									
										
										
										
											1995-08-09 15:16:58 +00:00
										 |  |  | ] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-08-28 14:19:53 +00:00
										 |  |  | def gotopluginfolder(): | 
					
						
							|  |  |  | 	"""Go to the plugin folder, assuming we are somewhere in the Python tree""" | 
					
						
							|  |  |  | 	import os | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	while not os.path.isdir(":Plugins"): | 
					
						
							|  |  |  | 		os.chdir("::") | 
					
						
							|  |  |  | 	os.chdir(":Plugins") | 
					
						
							| 
									
										
										
										
											1997-08-27 14:11:15 +00:00
										 |  |  | 	if verbose: print "current directory is", os.getcwd() | 
					
						
							| 
									
										
										
										
											1996-08-28 14:19:53 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | def loadtoolboxmodules(): | 
					
						
							|  |  |  | 	"""Attempt to load the Res module""" | 
					
						
							|  |  |  | 	try: | 
					
						
							|  |  |  | 		import Res | 
					
						
							|  |  |  | 	except ImportError, arg: | 
					
						
							|  |  |  | 		err1 = arg | 
					
						
							|  |  |  | 		pass | 
					
						
							|  |  |  | 	else: | 
					
						
							| 
									
										
										
										
											1997-08-27 14:11:15 +00:00
										 |  |  | 		if verbose: print 'imported Res the standard way.' | 
					
						
							| 
									
										
										
										
											1996-08-28 14:19:53 +00:00
										 |  |  | 		return | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	# We cannot import it. First attempt to load the cfm68k version | 
					
						
							|  |  |  | 	import imp | 
					
						
							|  |  |  | 	try: | 
					
						
							|  |  |  | 		dummy = imp.load_dynamic('Res', 'toolboxmodules.CFM68K.slb') | 
					
						
							|  |  |  | 	except ImportError, arg: | 
					
						
							|  |  |  | 		err2 = arg | 
					
						
							|  |  |  | 		pass | 
					
						
							|  |  |  | 	else: | 
					
						
							| 
									
										
										
										
											1997-08-27 14:11:15 +00:00
										 |  |  | 		if verbose:  print 'Loaded Res from toolboxmodules.CFM68K.slb.' | 
					
						
							| 
									
										
										
										
											1996-08-28 14:19:53 +00:00
										 |  |  | 		return | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	# Ok, try the ppc version | 
					
						
							|  |  |  | 	try: | 
					
						
							|  |  |  | 		dummy = imp.load_dynamic('Res', 'toolboxmodules.ppc.slb') | 
					
						
							|  |  |  | 	except ImportError, arg: | 
					
						
							|  |  |  | 		err3 = arg | 
					
						
							|  |  |  | 		pass | 
					
						
							|  |  |  | 	else: | 
					
						
							| 
									
										
										
										
											1997-08-27 14:11:15 +00:00
										 |  |  | 		if verbose:  print 'Loaded Res from toolboxmodules.ppc.slb.' | 
					
						
							| 
									
										
										
										
											1996-08-28 14:19:53 +00:00
										 |  |  | 		return | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	# Tough luck.... | 
					
						
							|  |  |  | 	print "I cannot import the Res module, nor load it from either of" | 
					
						
							|  |  |  | 	print "toolboxmodules shared libraries. The errors encountered were:" | 
					
						
							|  |  |  | 	print "import Res:", err1 | 
					
						
							|  |  |  | 	print "load from toolboxmodules.CFM68K.slb:", err2 | 
					
						
							|  |  |  | 	print "load from toolboxmodules.ppc.slb:", err3 | 
					
						
							|  |  |  | 	sys.exit(1) | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1996-10-22 15:32:06 +00:00
										 |  |  | def getextensiondirfile(fname): | 
					
						
							|  |  |  | 	import macfs | 
					
						
							|  |  |  | 	import MACFS | 
					
						
							|  |  |  | 	vrefnum, dirid = macfs.FindFolder(MACFS.kOnSystemDisk, MACFS.kExtensionFolderType, 0) | 
					
						
							|  |  |  | 	fss = macfs.FSSpec((vrefnum, dirid, fname)) | 
					
						
							|  |  |  | 	return fss.as_pathname() | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | def mkcorealias(src, altsrc): | 
					
						
							|  |  |  | 	import string | 
					
						
							|  |  |  | 	import macostools | 
					
						
							|  |  |  | 	version = string.split(sys.version)[0] | 
					
						
							|  |  |  | 	dst = getextensiondirfile(src+ ' ' + version) | 
					
						
							|  |  |  | 	if not os.path.exists(src): | 
					
						
							|  |  |  | 		if not os.path.exists(altsrc): | 
					
						
							| 
									
										
										
										
											1997-08-27 14:11:15 +00:00
										 |  |  | 			if verbose:  print '*', src, 'not found' | 
					
						
							| 
									
										
										
										
											1996-10-22 15:32:06 +00:00
										 |  |  | 			return 0 | 
					
						
							|  |  |  | 		src = altsrc | 
					
						
							|  |  |  | 	try: | 
					
						
							|  |  |  | 		os.unlink(dst) | 
					
						
							|  |  |  | 	except os.error: | 
					
						
							|  |  |  | 		pass | 
					
						
							|  |  |  | 	macostools.mkalias(src, dst) | 
					
						
							| 
									
										
										
										
											1997-08-27 14:11:15 +00:00
										 |  |  | 	if verbose:  print ' ', dst, '->', src | 
					
						
							| 
									
										
										
										
											1996-10-22 15:32:06 +00:00
										 |  |  | 	return 1 | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											1995-08-09 15:16:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | def main(): | 
					
						
							| 
									
										
										
										
											1997-09-08 13:16:29 +00:00
										 |  |  | 	MacOS.splash(SPLASH_LOCATE) | 
					
						
							| 
									
										
										
										
											1996-08-28 14:19:53 +00:00
										 |  |  | 	gotopluginfolder() | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	loadtoolboxmodules() | 
					
						
							| 
									
										
										
										
											1995-08-09 15:16:58 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-10-10 15:49:36 +00:00
										 |  |  | 	sys.path.append('::Mac:Lib') | 
					
						
							| 
									
										
										
										
											1996-08-28 14:19:53 +00:00
										 |  |  | 	import macostools | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											1995-08-09 15:16:58 +00:00
										 |  |  | 	# Remove old .slb aliases and collect a list of .slb files | 
					
						
							| 
									
										
										
										
											1997-09-08 13:16:29 +00:00
										 |  |  | 	didsplash = 0 | 
					
						
							| 
									
										
										
										
											1995-08-09 15:16:58 +00:00
										 |  |  | 	LibFiles = [] | 
					
						
							|  |  |  | 	allfiles = os.listdir(':') | 
					
						
							| 
									
										
										
										
											1997-08-27 14:11:15 +00:00
										 |  |  | 	if verbose:  print 'Removing old aliases...' | 
					
						
							| 
									
										
										
										
											1995-08-09 15:16:58 +00:00
										 |  |  | 	for f in allfiles: | 
					
						
							|  |  |  | 		if f[-4:] == '.slb': | 
					
						
							|  |  |  | 			finfo = macfs.FSSpec(f).GetFInfo() | 
					
						
							|  |  |  | 			if finfo.Flags & 0x8000: | 
					
						
							| 
									
										
										
										
											1997-09-08 13:16:29 +00:00
										 |  |  | 				if not didsplash: | 
					
						
							|  |  |  | 					MacOS.splash(SPLASH_REMOVE) | 
					
						
							|  |  |  | 					didsplash = 1 | 
					
						
							| 
									
										
										
										
											1997-08-27 14:11:15 +00:00
										 |  |  | 				if verbose:  print '  Removing', f | 
					
						
							| 
									
										
										
										
											1995-08-09 15:16:58 +00:00
										 |  |  | 				os.unlink(f) | 
					
						
							|  |  |  | 			else: | 
					
						
							|  |  |  | 				LibFiles.append(f) | 
					
						
							| 
									
										
										
										
											1997-08-27 14:11:15 +00:00
										 |  |  | 				if verbose:  print '  Found', f | 
					
						
							|  |  |  | 	if verbose:  print | 
					
						
							| 
									
										
										
										
											1995-08-09 15:16:58 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											1996-08-28 14:19:53 +00:00
										 |  |  | 	# Create the new PPC aliases. | 
					
						
							| 
									
										
										
										
											1997-09-08 13:16:29 +00:00
										 |  |  | 	didsplash = 0 | 
					
						
							| 
									
										
										
										
											1997-08-27 14:11:15 +00:00
										 |  |  | 	if verbose:  print 'Creating PPC aliases...' | 
					
						
							| 
									
										
										
										
											1996-08-28 14:19:53 +00:00
										 |  |  | 	for dst, src in ppc_goals: | 
					
						
							|  |  |  | 		if src in LibFiles: | 
					
						
							| 
									
										
										
										
											1997-09-08 13:16:29 +00:00
										 |  |  | 			if not didsplash: | 
					
						
							|  |  |  | 				MacOS.splash(SPLASH_PPC) | 
					
						
							|  |  |  | 				didsplash = 1 | 
					
						
							| 
									
										
										
										
											1996-08-28 14:19:53 +00:00
										 |  |  | 			macostools.mkalias(src, dst) | 
					
						
							| 
									
										
										
										
											1997-08-27 14:11:15 +00:00
										 |  |  | 			if verbose:  print ' ', dst, '->', src | 
					
						
							| 
									
										
										
										
											1996-08-28 14:19:53 +00:00
										 |  |  | 		else: | 
					
						
							| 
									
										
										
										
											1997-08-27 14:11:15 +00:00
										 |  |  | 			if verbose:  print '*', dst, 'not created:', src, 'not found' | 
					
						
							|  |  |  | 	if verbose:  print | 
					
						
							| 
									
										
										
										
											1996-08-28 14:19:53 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	# Create the CFM68K aliases. | 
					
						
							| 
									
										
										
										
											1997-09-08 13:16:29 +00:00
										 |  |  | 	didsplash = 0 | 
					
						
							| 
									
										
										
										
											1997-08-27 14:11:15 +00:00
										 |  |  | 	if verbose:  print 'Creating CFM68K aliases...' | 
					
						
							| 
									
										
										
										
											1996-08-28 14:19:53 +00:00
										 |  |  | 	for dst, src in cfm68k_goals: | 
					
						
							|  |  |  | 		if src in LibFiles: | 
					
						
							| 
									
										
										
										
											1997-09-08 13:16:29 +00:00
										 |  |  | 			if not didsplash: | 
					
						
							|  |  |  | 				MacOS.splash(SPLASH_CFM68K) | 
					
						
							|  |  |  | 				didsplash = 1 | 
					
						
							| 
									
										
										
										
											1996-08-28 14:19:53 +00:00
										 |  |  | 			macostools.mkalias(src, dst) | 
					
						
							| 
									
										
										
										
											1997-08-27 14:11:15 +00:00
										 |  |  | 			if verbose:  print ' ', dst, '->', src | 
					
						
							| 
									
										
										
										
											1996-08-28 14:19:53 +00:00
										 |  |  | 		else: | 
					
						
							| 
									
										
										
										
											1997-08-27 14:11:15 +00:00
										 |  |  | 			if verbose:  print '*', dst, 'not created:', src, 'not found' | 
					
						
							|  |  |  | 	if verbose:  print | 
					
						
							| 
									
										
										
										
											1996-10-22 15:32:06 +00:00
										 |  |  | 			 | 
					
						
							|  |  |  | 	# Create the PythonCore alias(es) | 
					
						
							| 
									
										
										
										
											1997-08-27 14:11:15 +00:00
										 |  |  | 	if verbose:  print 'Creating PythonCore aliases in Extensions folder...' | 
					
						
							| 
									
										
										
										
											1996-10-22 15:32:06 +00:00
										 |  |  | 	os.chdir('::') | 
					
						
							|  |  |  | 	n = 0 | 
					
						
							| 
									
										
										
										
											1997-08-19 13:58:57 +00:00
										 |  |  | 	n = n + mkcorealias('PythonCore', 'PythonCore') | 
					
						
							| 
									
										
										
										
											1996-10-22 15:32:06 +00:00
										 |  |  | 	n = n + mkcorealias('PythonCorePPC', ':build.macppc.shared:PythonCorePPC') | 
					
						
							|  |  |  | 	n = n + mkcorealias('PythonCoreCFM68K', ':build.mac68k.shared:PythonCoreCFM68K') | 
					
						
							| 
									
										
										
										
											1997-09-08 13:16:29 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	# Install NumPy | 
					
						
							|  |  |  | 	if os.path.exists(':Extensions:NumPy:macmkaliases.py'): | 
					
						
							|  |  |  | 		MacOS.splash(SPLASH_NUMPY) | 
					
						
							|  |  |  | 		os.chdir(':Extensions:NumPy') | 
					
						
							|  |  |  | 		import macmkaliases | 
					
						
							|  |  |  | 		err = macmkaliases.main() | 
					
						
							| 
									
										
										
										
											1997-08-27 14:11:15 +00:00
										 |  |  | 	if verbose and n == 0: | 
					
						
							| 
									
										
										
										
											1996-10-22 15:32:06 +00:00
										 |  |  | 		sys.exit(1) | 
					
						
							| 
									
										
										
										
											1995-08-09 15:16:58 +00:00
										 |  |  | 			 | 
					
						
							|  |  |  | if __name__ == '__main__': | 
					
						
							| 
									
										
										
										
											1997-08-27 14:11:15 +00:00
										 |  |  | 	if len(sys.argv) > 1 and sys.argv[1] == '-v': | 
					
						
							|  |  |  | 		verbose = 1 | 
					
						
							| 
									
										
										
										
											1995-08-09 15:16:58 +00:00
										 |  |  | 	main() |