blob: 3ecc75bba0f8a7b33c6af60ff5f52ca6d769987d [file] [log] [blame]
Jack Jansend8eb8a71995-08-09 15:16:58 +00001# This python script creates Finder aliases for all the
2# dynamically-loaded modules that "live in" in a single
3# shared library.
Jack Jansend8eb8a71995-08-09 15:16:58 +00004#
Jack Jansene3c90a41996-08-28 14:19:53 +00005# This is sort-of a merger between Jack's MkPluginAliases
6# and Guido's mkaliases.
7#
8# Jack Jansen, CWI, August 1996
Jack Jansend8eb8a71995-08-09 15:16:58 +00009
Jack Jansend8eb8a71995-08-09 15:16:58 +000010import sys
Jack Jansene3c90a41996-08-28 14:19:53 +000011import os
Jack Jansenbc128731995-09-24 21:06:50 +000012import macfs
Jack Jansend0240831997-09-08 13:16:29 +000013import MacOS
Jack Jansen09dcff71997-08-27 14:11:15 +000014verbose=0
Jack Jansend8eb8a71995-08-09 15:16:58 +000015
Jack Jansend0240831997-09-08 13:16:29 +000016SPLASH_LOCATE=512
17SPLASH_REMOVE=513
18SPLASH_CFM68K=514
19SPLASH_PPC=515
20SPLASH_NUMPY=516
21
Jack Jansen25b361f1996-08-20 16:35:30 +000022ppc_goals = [
23 ("AE.ppc.slb", "toolboxmodules.ppc.slb"),
24 ("Ctl.ppc.slb", "toolboxmodules.ppc.slb"),
25 ("Dlg.ppc.slb", "toolboxmodules.ppc.slb"),
26 ("Evt.ppc.slb", "toolboxmodules.ppc.slb"),
27 ("Fm.ppc.slb", "toolboxmodules.ppc.slb"),
Jack Jansen80b53291997-09-09 13:57:59 +000028 ("Help.ppc.slb", "toolboxmodules.ppc.slb"),
Jack Jansenc94e7851999-01-25 12:39:39 +000029 ("Icn.ppc.slb", "toolboxmodules.ppc.slb"),
Jack Jansen25b361f1996-08-20 16:35:30 +000030 ("Menu.ppc.slb", "toolboxmodules.ppc.slb"),
31 ("List.ppc.slb", "toolboxmodules.ppc.slb"),
32 ("Qd.ppc.slb", "toolboxmodules.ppc.slb"),
33 ("Res.ppc.slb", "toolboxmodules.ppc.slb"),
34 ("Scrap.ppc.slb", "toolboxmodules.ppc.slb"),
35 ("Snd.ppc.slb", "toolboxmodules.ppc.slb"),
Jack Jansenae3407a1998-04-15 14:06:17 +000036 ("Sndihooks.ppc.slb", "toolboxmodules.ppc.slb"),
Jack Jansen25b361f1996-08-20 16:35:30 +000037 ("TE.ppc.slb", "toolboxmodules.ppc.slb"),
38 ("Win.ppc.slb", "toolboxmodules.ppc.slb"),
39
40 ("Cm.ppc.slb", "qtmodules.ppc.slb"),
41 ("Qt.ppc.slb", "qtmodules.ppc.slb"),
42
43 ("imgcolormap.ppc.slb", "imgmodules.ppc.slb"),
44 ("imgformat.ppc.slb", "imgmodules.ppc.slb"),
45 ("imggif.ppc.slb", "imgmodules.ppc.slb"),
46 ("imgjpeg.ppc.slb", "imgmodules.ppc.slb"),
47 ("imgop.ppc.slb", "imgmodules.ppc.slb"),
48 ("imgpbm.ppc.slb", "imgmodules.ppc.slb"),
49 ("imgpgm.ppc.slb", "imgmodules.ppc.slb"),
50 ("imgppm.ppc.slb", "imgmodules.ppc.slb"),
51 ("imgtiff.ppc.slb", "imgmodules.ppc.slb"),
52 ("imgsgi.ppc.slb", "imgmodules.ppc.slb")
53]
54
55cfm68k_goals = [
56 ("AE.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
57 ("Ctl.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
58 ("Dlg.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
59 ("Evt.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
60 ("Fm.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
Jack Jansen80b53291997-09-09 13:57:59 +000061 ("Help.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
Jack Jansenc94e7851999-01-25 12:39:39 +000062 ("Icn.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
Jack Jansen25b361f1996-08-20 16:35:30 +000063 ("Menu.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
64 ("List.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
65 ("Qd.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
66 ("Res.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
67 ("Scrap.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
68 ("Snd.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
Jack Jansenae3407a1998-04-15 14:06:17 +000069 ("Sndihooks.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
Jack Jansen25b361f1996-08-20 16:35:30 +000070 ("TE.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
71 ("Win.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
72
73 ("Cm.CFM68K.slb", "qtmodules.CFM68K.slb"),
74 ("Qt.CFM68K.slb", "qtmodules.CFM68K.slb"),
Jack Jansen3c7739a1996-10-08 09:25:02 +000075
76 ("imgcolormap.CFM68K.slb", "imgmodules.CFM68K.slb"),
77 ("imgformat.CFM68K.slb", "imgmodules.CFM68K.slb"),
78 ("imggif.CFM68K.slb", "imgmodules.CFM68K.slb"),
79 ("imgjpeg.CFM68K.slb", "imgmodules.CFM68K.slb"),
80 ("imgop.CFM68K.slb", "imgmodules.CFM68K.slb"),
81 ("imgpbm.CFM68K.slb", "imgmodules.CFM68K.slb"),
82 ("imgpgm.CFM68K.slb", "imgmodules.CFM68K.slb"),
83 ("imgppm.CFM68K.slb", "imgmodules.CFM68K.slb"),
84 ("imgtiff.CFM68K.slb", "imgmodules.CFM68K.slb"),
85 ("imgsgi.CFM68K.slb", "imgmodules.CFM68K.slb")
Jack Jansend8eb8a71995-08-09 15:16:58 +000086]
87
Jack Jansene3c90a41996-08-28 14:19:53 +000088def gotopluginfolder():
89 """Go to the plugin folder, assuming we are somewhere in the Python tree"""
90 import os
91
Just van Rossum786cb111999-01-30 17:46:34 +000092 while not os.path.isdir(":Mac:PlugIns"):
Jack Jansene3c90a41996-08-28 14:19:53 +000093 os.chdir("::")
Just van Rossum786cb111999-01-30 17:46:34 +000094 os.chdir(":Mac:PlugIns")
Jack Jansen09dcff71997-08-27 14:11:15 +000095 if verbose: print "current directory is", os.getcwd()
Jack Jansene3c90a41996-08-28 14:19:53 +000096
97def loadtoolboxmodules():
98 """Attempt to load the Res module"""
99 try:
100 import Res
101 except ImportError, arg:
102 err1 = arg
103 pass
104 else:
Jack Jansen09dcff71997-08-27 14:11:15 +0000105 if verbose: print 'imported Res the standard way.'
Jack Jansene3c90a41996-08-28 14:19:53 +0000106 return
107
108 # We cannot import it. First attempt to load the cfm68k version
109 import imp
110 try:
111 dummy = imp.load_dynamic('Res', 'toolboxmodules.CFM68K.slb')
112 except ImportError, arg:
113 err2 = arg
114 pass
115 else:
Jack Jansen09dcff71997-08-27 14:11:15 +0000116 if verbose: print 'Loaded Res from toolboxmodules.CFM68K.slb.'
Jack Jansene3c90a41996-08-28 14:19:53 +0000117 return
118
119 # Ok, try the ppc version
120 try:
121 dummy = imp.load_dynamic('Res', 'toolboxmodules.ppc.slb')
122 except ImportError, arg:
123 err3 = arg
124 pass
125 else:
Jack Jansen09dcff71997-08-27 14:11:15 +0000126 if verbose: print 'Loaded Res from toolboxmodules.ppc.slb.'
Jack Jansene3c90a41996-08-28 14:19:53 +0000127 return
128
129 # Tough luck....
130 print "I cannot import the Res module, nor load it from either of"
131 print "toolboxmodules shared libraries. The errors encountered were:"
132 print "import Res:", err1
133 print "load from toolboxmodules.CFM68K.slb:", err2
134 print "load from toolboxmodules.ppc.slb:", err3
135 sys.exit(1)
136
Jack Jansend09deac1996-10-22 15:32:06 +0000137def getextensiondirfile(fname):
138 import macfs
139 import MACFS
140 vrefnum, dirid = macfs.FindFolder(MACFS.kOnSystemDisk, MACFS.kExtensionFolderType, 0)
141 fss = macfs.FSSpec((vrefnum, dirid, fname))
142 return fss.as_pathname()
143
144def mkcorealias(src, altsrc):
145 import string
146 import macostools
147 version = string.split(sys.version)[0]
148 dst = getextensiondirfile(src+ ' ' + version)
Just van Rossum786cb111999-01-30 17:46:34 +0000149 if not os.path.exists(os.path.join(sys.exec_prefix, src)):
150 if not os.path.exists(os.path.join(sys.exec_prefix, altsrc)):
Jack Jansen09dcff71997-08-27 14:11:15 +0000151 if verbose: print '*', src, 'not found'
Jack Jansend09deac1996-10-22 15:32:06 +0000152 return 0
153 src = altsrc
154 try:
155 os.unlink(dst)
156 except os.error:
157 pass
Just van Rossum786cb111999-01-30 17:46:34 +0000158 macostools.mkalias(os.path.join(sys.exec_prefix, src), dst)
Jack Jansen09dcff71997-08-27 14:11:15 +0000159 if verbose: print ' ', dst, '->', src
Jack Jansend09deac1996-10-22 15:32:06 +0000160 return 1
161
Jack Jansend8eb8a71995-08-09 15:16:58 +0000162
163def main():
Jack Jansend0240831997-09-08 13:16:29 +0000164 MacOS.splash(SPLASH_LOCATE)
Jack Jansene3c90a41996-08-28 14:19:53 +0000165 gotopluginfolder()
Jack Jansend8eb8a71995-08-09 15:16:58 +0000166
Jack Jansene3c90a41996-08-28 14:19:53 +0000167 loadtoolboxmodules()
168
Jack Jansenbb748621997-10-10 15:49:36 +0000169 sys.path.append('::Mac:Lib')
Jack Jansene3c90a41996-08-28 14:19:53 +0000170 import macostools
171
Jack Jansend8eb8a71995-08-09 15:16:58 +0000172 # Remove old .slb aliases and collect a list of .slb files
Jack Jansend0240831997-09-08 13:16:29 +0000173 didsplash = 0
Jack Jansend8eb8a71995-08-09 15:16:58 +0000174 LibFiles = []
175 allfiles = os.listdir(':')
Jack Jansen09dcff71997-08-27 14:11:15 +0000176 if verbose: print 'Removing old aliases...'
Jack Jansend8eb8a71995-08-09 15:16:58 +0000177 for f in allfiles:
178 if f[-4:] == '.slb':
179 finfo = macfs.FSSpec(f).GetFInfo()
180 if finfo.Flags & 0x8000:
Jack Jansend0240831997-09-08 13:16:29 +0000181 if not didsplash:
182 MacOS.splash(SPLASH_REMOVE)
183 didsplash = 1
Jack Jansen09dcff71997-08-27 14:11:15 +0000184 if verbose: print ' Removing', f
Jack Jansend8eb8a71995-08-09 15:16:58 +0000185 os.unlink(f)
186 else:
187 LibFiles.append(f)
Jack Jansen09dcff71997-08-27 14:11:15 +0000188 if verbose: print ' Found', f
189 if verbose: print
Jack Jansend8eb8a71995-08-09 15:16:58 +0000190
Jack Jansene3c90a41996-08-28 14:19:53 +0000191 # Create the new PPC aliases.
Jack Jansend0240831997-09-08 13:16:29 +0000192 didsplash = 0
Jack Jansen09dcff71997-08-27 14:11:15 +0000193 if verbose: print 'Creating PPC aliases...'
Jack Jansene3c90a41996-08-28 14:19:53 +0000194 for dst, src in ppc_goals:
195 if src in LibFiles:
Jack Jansend0240831997-09-08 13:16:29 +0000196 if not didsplash:
197 MacOS.splash(SPLASH_PPC)
198 didsplash = 1
Jack Jansene3c90a41996-08-28 14:19:53 +0000199 macostools.mkalias(src, dst)
Jack Jansen09dcff71997-08-27 14:11:15 +0000200 if verbose: print ' ', dst, '->', src
Jack Jansene3c90a41996-08-28 14:19:53 +0000201 else:
Jack Jansen09dcff71997-08-27 14:11:15 +0000202 if verbose: print '*', dst, 'not created:', src, 'not found'
203 if verbose: print
Jack Jansene3c90a41996-08-28 14:19:53 +0000204
205 # Create the CFM68K aliases.
Jack Jansend0240831997-09-08 13:16:29 +0000206 didsplash = 0
Jack Jansen09dcff71997-08-27 14:11:15 +0000207 if verbose: print 'Creating CFM68K aliases...'
Jack Jansene3c90a41996-08-28 14:19:53 +0000208 for dst, src in cfm68k_goals:
209 if src in LibFiles:
Jack Jansend0240831997-09-08 13:16:29 +0000210 if not didsplash:
211 MacOS.splash(SPLASH_CFM68K)
212 didsplash = 1
Jack Jansene3c90a41996-08-28 14:19:53 +0000213 macostools.mkalias(src, dst)
Jack Jansen09dcff71997-08-27 14:11:15 +0000214 if verbose: print ' ', dst, '->', src
Jack Jansene3c90a41996-08-28 14:19:53 +0000215 else:
Jack Jansen09dcff71997-08-27 14:11:15 +0000216 if verbose: print '*', dst, 'not created:', src, 'not found'
217 if verbose: print
Jack Jansend09deac1996-10-22 15:32:06 +0000218
219 # Create the PythonCore alias(es)
Jack Jansen09dcff71997-08-27 14:11:15 +0000220 if verbose: print 'Creating PythonCore aliases in Extensions folder...'
Jack Jansend09deac1996-10-22 15:32:06 +0000221 os.chdir('::')
222 n = 0
Jack Jansen78c3cc41997-08-19 13:58:57 +0000223 n = n + mkcorealias('PythonCore', 'PythonCore')
Jack Jansend09deac1996-10-22 15:32:06 +0000224 n = n + mkcorealias('PythonCorePPC', ':build.macppc.shared:PythonCorePPC')
225 n = n + mkcorealias('PythonCoreCFM68K', ':build.mac68k.shared:PythonCoreCFM68K')
Jack Jansend0240831997-09-08 13:16:29 +0000226
227 # Install NumPy
228 if os.path.exists(':Extensions:NumPy:macmkaliases.py'):
229 MacOS.splash(SPLASH_NUMPY)
230 os.chdir(':Extensions:NumPy')
231 import macmkaliases
232 err = macmkaliases.main()
Jack Jansen09dcff71997-08-27 14:11:15 +0000233 if verbose and n == 0:
Jack Jansend09deac1996-10-22 15:32:06 +0000234 sys.exit(1)
Jack Jansend8eb8a71995-08-09 15:16:58 +0000235
236if __name__ == '__main__':
Jack Jansen09dcff71997-08-27 14:11:15 +0000237 if len(sys.argv) > 1 and sys.argv[1] == '-v':
238 verbose = 1
Jack Jansend8eb8a71995-08-09 15:16:58 +0000239 main()