blob: a6a1a4dafdf23567e50a4013e311cafcc8d3d4aa [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 Jansen25b361f1996-08-20 16:35:30 +000029 ("Menu.ppc.slb", "toolboxmodules.ppc.slb"),
30 ("List.ppc.slb", "toolboxmodules.ppc.slb"),
31 ("Qd.ppc.slb", "toolboxmodules.ppc.slb"),
32 ("Res.ppc.slb", "toolboxmodules.ppc.slb"),
33 ("Scrap.ppc.slb", "toolboxmodules.ppc.slb"),
34 ("Snd.ppc.slb", "toolboxmodules.ppc.slb"),
Jack Jansenae3407a1998-04-15 14:06:17 +000035 ("Sndihooks.ppc.slb", "toolboxmodules.ppc.slb"),
Jack Jansen25b361f1996-08-20 16:35:30 +000036 ("TE.ppc.slb", "toolboxmodules.ppc.slb"),
37 ("Win.ppc.slb", "toolboxmodules.ppc.slb"),
38
39 ("Cm.ppc.slb", "qtmodules.ppc.slb"),
40 ("Qt.ppc.slb", "qtmodules.ppc.slb"),
41
42 ("imgcolormap.ppc.slb", "imgmodules.ppc.slb"),
43 ("imgformat.ppc.slb", "imgmodules.ppc.slb"),
44 ("imggif.ppc.slb", "imgmodules.ppc.slb"),
45 ("imgjpeg.ppc.slb", "imgmodules.ppc.slb"),
46 ("imgop.ppc.slb", "imgmodules.ppc.slb"),
47 ("imgpbm.ppc.slb", "imgmodules.ppc.slb"),
48 ("imgpgm.ppc.slb", "imgmodules.ppc.slb"),
49 ("imgppm.ppc.slb", "imgmodules.ppc.slb"),
50 ("imgtiff.ppc.slb", "imgmodules.ppc.slb"),
51 ("imgsgi.ppc.slb", "imgmodules.ppc.slb")
52]
53
54cfm68k_goals = [
55 ("AE.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
56 ("Ctl.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
57 ("Dlg.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
58 ("Evt.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
59 ("Fm.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
Jack Jansen80b53291997-09-09 13:57:59 +000060 ("Help.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
Jack Jansen25b361f1996-08-20 16:35:30 +000061 ("Menu.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
62 ("List.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
63 ("Qd.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
64 ("Res.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
65 ("Scrap.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
66 ("Snd.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
Jack Jansenae3407a1998-04-15 14:06:17 +000067 ("Sndihooks.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
Jack Jansen25b361f1996-08-20 16:35:30 +000068 ("TE.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
69 ("Win.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
70
71 ("Cm.CFM68K.slb", "qtmodules.CFM68K.slb"),
72 ("Qt.CFM68K.slb", "qtmodules.CFM68K.slb"),
Jack Jansen3c7739a1996-10-08 09:25:02 +000073
74 ("imgcolormap.CFM68K.slb", "imgmodules.CFM68K.slb"),
75 ("imgformat.CFM68K.slb", "imgmodules.CFM68K.slb"),
76 ("imggif.CFM68K.slb", "imgmodules.CFM68K.slb"),
77 ("imgjpeg.CFM68K.slb", "imgmodules.CFM68K.slb"),
78 ("imgop.CFM68K.slb", "imgmodules.CFM68K.slb"),
79 ("imgpbm.CFM68K.slb", "imgmodules.CFM68K.slb"),
80 ("imgpgm.CFM68K.slb", "imgmodules.CFM68K.slb"),
81 ("imgppm.CFM68K.slb", "imgmodules.CFM68K.slb"),
82 ("imgtiff.CFM68K.slb", "imgmodules.CFM68K.slb"),
83 ("imgsgi.CFM68K.slb", "imgmodules.CFM68K.slb")
Jack Jansend8eb8a71995-08-09 15:16:58 +000084]
85
Jack Jansene3c90a41996-08-28 14:19:53 +000086def gotopluginfolder():
87 """Go to the plugin folder, assuming we are somewhere in the Python tree"""
88 import os
89
90 while not os.path.isdir(":Plugins"):
91 os.chdir("::")
92 os.chdir(":Plugins")
Jack Jansen09dcff71997-08-27 14:11:15 +000093 if verbose: print "current directory is", os.getcwd()
Jack Jansene3c90a41996-08-28 14:19:53 +000094
95def loadtoolboxmodules():
96 """Attempt to load the Res module"""
97 try:
98 import Res
99 except ImportError, arg:
100 err1 = arg
101 pass
102 else:
Jack Jansen09dcff71997-08-27 14:11:15 +0000103 if verbose: print 'imported Res the standard way.'
Jack Jansene3c90a41996-08-28 14:19:53 +0000104 return
105
106 # We cannot import it. First attempt to load the cfm68k version
107 import imp
108 try:
109 dummy = imp.load_dynamic('Res', 'toolboxmodules.CFM68K.slb')
110 except ImportError, arg:
111 err2 = arg
112 pass
113 else:
Jack Jansen09dcff71997-08-27 14:11:15 +0000114 if verbose: print 'Loaded Res from toolboxmodules.CFM68K.slb.'
Jack Jansene3c90a41996-08-28 14:19:53 +0000115 return
116
117 # Ok, try the ppc version
118 try:
119 dummy = imp.load_dynamic('Res', 'toolboxmodules.ppc.slb')
120 except ImportError, arg:
121 err3 = arg
122 pass
123 else:
Jack Jansen09dcff71997-08-27 14:11:15 +0000124 if verbose: print 'Loaded Res from toolboxmodules.ppc.slb.'
Jack Jansene3c90a41996-08-28 14:19:53 +0000125 return
126
127 # Tough luck....
128 print "I cannot import the Res module, nor load it from either of"
129 print "toolboxmodules shared libraries. The errors encountered were:"
130 print "import Res:", err1
131 print "load from toolboxmodules.CFM68K.slb:", err2
132 print "load from toolboxmodules.ppc.slb:", err3
133 sys.exit(1)
134
Jack Jansend09deac1996-10-22 15:32:06 +0000135def getextensiondirfile(fname):
136 import macfs
137 import MACFS
138 vrefnum, dirid = macfs.FindFolder(MACFS.kOnSystemDisk, MACFS.kExtensionFolderType, 0)
139 fss = macfs.FSSpec((vrefnum, dirid, fname))
140 return fss.as_pathname()
141
142def mkcorealias(src, altsrc):
143 import string
144 import macostools
145 version = string.split(sys.version)[0]
146 dst = getextensiondirfile(src+ ' ' + version)
147 if not os.path.exists(src):
148 if not os.path.exists(altsrc):
Jack Jansen09dcff71997-08-27 14:11:15 +0000149 if verbose: print '*', src, 'not found'
Jack Jansend09deac1996-10-22 15:32:06 +0000150 return 0
151 src = altsrc
152 try:
153 os.unlink(dst)
154 except os.error:
155 pass
156 macostools.mkalias(src, dst)
Jack Jansen09dcff71997-08-27 14:11:15 +0000157 if verbose: print ' ', dst, '->', src
Jack Jansend09deac1996-10-22 15:32:06 +0000158 return 1
159
Jack Jansend8eb8a71995-08-09 15:16:58 +0000160
161def main():
Jack Jansend0240831997-09-08 13:16:29 +0000162 MacOS.splash(SPLASH_LOCATE)
Jack Jansene3c90a41996-08-28 14:19:53 +0000163 gotopluginfolder()
Jack Jansend8eb8a71995-08-09 15:16:58 +0000164
Jack Jansene3c90a41996-08-28 14:19:53 +0000165 loadtoolboxmodules()
166
Jack Jansenbb748621997-10-10 15:49:36 +0000167 sys.path.append('::Mac:Lib')
Jack Jansene3c90a41996-08-28 14:19:53 +0000168 import macostools
169
Jack Jansend8eb8a71995-08-09 15:16:58 +0000170 # Remove old .slb aliases and collect a list of .slb files
Jack Jansend0240831997-09-08 13:16:29 +0000171 didsplash = 0
Jack Jansend8eb8a71995-08-09 15:16:58 +0000172 LibFiles = []
173 allfiles = os.listdir(':')
Jack Jansen09dcff71997-08-27 14:11:15 +0000174 if verbose: print 'Removing old aliases...'
Jack Jansend8eb8a71995-08-09 15:16:58 +0000175 for f in allfiles:
176 if f[-4:] == '.slb':
177 finfo = macfs.FSSpec(f).GetFInfo()
178 if finfo.Flags & 0x8000:
Jack Jansend0240831997-09-08 13:16:29 +0000179 if not didsplash:
180 MacOS.splash(SPLASH_REMOVE)
181 didsplash = 1
Jack Jansen09dcff71997-08-27 14:11:15 +0000182 if verbose: print ' Removing', f
Jack Jansend8eb8a71995-08-09 15:16:58 +0000183 os.unlink(f)
184 else:
185 LibFiles.append(f)
Jack Jansen09dcff71997-08-27 14:11:15 +0000186 if verbose: print ' Found', f
187 if verbose: print
Jack Jansend8eb8a71995-08-09 15:16:58 +0000188
Jack Jansene3c90a41996-08-28 14:19:53 +0000189 # Create the new PPC aliases.
Jack Jansend0240831997-09-08 13:16:29 +0000190 didsplash = 0
Jack Jansen09dcff71997-08-27 14:11:15 +0000191 if verbose: print 'Creating PPC aliases...'
Jack Jansene3c90a41996-08-28 14:19:53 +0000192 for dst, src in ppc_goals:
193 if src in LibFiles:
Jack Jansend0240831997-09-08 13:16:29 +0000194 if not didsplash:
195 MacOS.splash(SPLASH_PPC)
196 didsplash = 1
Jack Jansene3c90a41996-08-28 14:19:53 +0000197 macostools.mkalias(src, dst)
Jack Jansen09dcff71997-08-27 14:11:15 +0000198 if verbose: print ' ', dst, '->', src
Jack Jansene3c90a41996-08-28 14:19:53 +0000199 else:
Jack Jansen09dcff71997-08-27 14:11:15 +0000200 if verbose: print '*', dst, 'not created:', src, 'not found'
201 if verbose: print
Jack Jansene3c90a41996-08-28 14:19:53 +0000202
203 # Create the CFM68K aliases.
Jack Jansend0240831997-09-08 13:16:29 +0000204 didsplash = 0
Jack Jansen09dcff71997-08-27 14:11:15 +0000205 if verbose: print 'Creating CFM68K aliases...'
Jack Jansene3c90a41996-08-28 14:19:53 +0000206 for dst, src in cfm68k_goals:
207 if src in LibFiles:
Jack Jansend0240831997-09-08 13:16:29 +0000208 if not didsplash:
209 MacOS.splash(SPLASH_CFM68K)
210 didsplash = 1
Jack Jansene3c90a41996-08-28 14:19:53 +0000211 macostools.mkalias(src, dst)
Jack Jansen09dcff71997-08-27 14:11:15 +0000212 if verbose: print ' ', dst, '->', src
Jack Jansene3c90a41996-08-28 14:19:53 +0000213 else:
Jack Jansen09dcff71997-08-27 14:11:15 +0000214 if verbose: print '*', dst, 'not created:', src, 'not found'
215 if verbose: print
Jack Jansend09deac1996-10-22 15:32:06 +0000216
217 # Create the PythonCore alias(es)
Jack Jansen09dcff71997-08-27 14:11:15 +0000218 if verbose: print 'Creating PythonCore aliases in Extensions folder...'
Jack Jansend09deac1996-10-22 15:32:06 +0000219 os.chdir('::')
220 n = 0
Jack Jansen78c3cc41997-08-19 13:58:57 +0000221 n = n + mkcorealias('PythonCore', 'PythonCore')
Jack Jansend09deac1996-10-22 15:32:06 +0000222 n = n + mkcorealias('PythonCorePPC', ':build.macppc.shared:PythonCorePPC')
223 n = n + mkcorealias('PythonCoreCFM68K', ':build.mac68k.shared:PythonCoreCFM68K')
Jack Jansend0240831997-09-08 13:16:29 +0000224
225 # Install NumPy
226 if os.path.exists(':Extensions:NumPy:macmkaliases.py'):
227 MacOS.splash(SPLASH_NUMPY)
228 os.chdir(':Extensions:NumPy')
229 import macmkaliases
230 err = macmkaliases.main()
Jack Jansen09dcff71997-08-27 14:11:15 +0000231 if verbose and n == 0:
Jack Jansend09deac1996-10-22 15:32:06 +0000232 sys.exit(1)
Jack Jansend8eb8a71995-08-09 15:16:58 +0000233
234if __name__ == '__main__':
Jack Jansen09dcff71997-08-27 14:11:15 +0000235 if len(sys.argv) > 1 and sys.argv[1] == '-v':
236 verbose = 1
Jack Jansend8eb8a71995-08-09 15:16:58 +0000237 main()