blob: 91e0af03d3cea519a451f90115bede884870cf24 [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
Jack Jansen52b5b022000-10-13 23:33:34 +000021ALERT_NONBOOT=517
22ALERT_NONBOOT_COPY=1
23ALERT_NONBOOT_ALIAS=2
Jack Jansend0240831997-09-08 13:16:29 +000024
Jack Jansen25b361f1996-08-20 16:35:30 +000025ppc_goals = [
Jack Jansenfa155a11999-02-07 13:59:06 +000026## ("AE.ppc.slb", "toolboxmodules.ppc.slb"),
27## ("Ctl.ppc.slb", "toolboxmodules.ppc.slb"),
28## ("Dlg.ppc.slb", "toolboxmodules.ppc.slb"),
29## ("Evt.ppc.slb", "toolboxmodules.ppc.slb"),
30## ("Fm.ppc.slb", "toolboxmodules.ppc.slb"),
31## ("Help.ppc.slb", "toolboxmodules.ppc.slb"),
32## ("Icn.ppc.slb", "toolboxmodules.ppc.slb"),
33## ("Menu.ppc.slb", "toolboxmodules.ppc.slb"),
34## ("List.ppc.slb", "toolboxmodules.ppc.slb"),
35## ("Qd.ppc.slb", "toolboxmodules.ppc.slb"),
36## ("Res.ppc.slb", "toolboxmodules.ppc.slb"),
37## ("Scrap.ppc.slb", "toolboxmodules.ppc.slb"),
38## ("Snd.ppc.slb", "toolboxmodules.ppc.slb"),
39## ("Sndihooks.ppc.slb", "toolboxmodules.ppc.slb"),
40## ("TE.ppc.slb", "toolboxmodules.ppc.slb"),
41## ("Win.ppc.slb", "toolboxmodules.ppc.slb"),
42##
43## ("Cm.ppc.slb", "qtmodules.ppc.slb"),
44## ("Qt.ppc.slb", "qtmodules.ppc.slb"),
Jack Jansen25b361f1996-08-20 16:35:30 +000045
Jack Jansen25b361f1996-08-20 16:35:30 +000046]
47
48cfm68k_goals = [
Jack Jansenfa155a11999-02-07 13:59:06 +000049## ("AE.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
50## ("Ctl.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
51## ("Dlg.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
52## ("Evt.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
53## ("Fm.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
54## ("Help.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
55## ("Icn.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
56## ("Menu.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
57## ("List.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
58## ("Qd.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
59## ("Res.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
60## ("Scrap.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
61## ("Snd.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
62## ("Sndihooks.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
63## ("TE.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
64## ("Win.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
65##
66## ("Cm.CFM68K.slb", "qtmodules.CFM68K.slb"),
67## ("Qt.CFM68K.slb", "qtmodules.CFM68K.slb"),
Jack Jansend8eb8a71995-08-09 15:16:58 +000068]
69
Jack Jansene3c90a41996-08-28 14:19:53 +000070def gotopluginfolder():
71 """Go to the plugin folder, assuming we are somewhere in the Python tree"""
72 import os
73
Just van Rossum786cb111999-01-30 17:46:34 +000074 while not os.path.isdir(":Mac:PlugIns"):
Jack Jansene3c90a41996-08-28 14:19:53 +000075 os.chdir("::")
Just van Rossum786cb111999-01-30 17:46:34 +000076 os.chdir(":Mac:PlugIns")
Jack Jansen09dcff71997-08-27 14:11:15 +000077 if verbose: print "current directory is", os.getcwd()
Jack Jansene3c90a41996-08-28 14:19:53 +000078
79def loadtoolboxmodules():
80 """Attempt to load the Res module"""
81 try:
82 import Res
83 except ImportError, arg:
84 err1 = arg
85 pass
86 else:
Jack Jansen09dcff71997-08-27 14:11:15 +000087 if verbose: print 'imported Res the standard way.'
Jack Jansene3c90a41996-08-28 14:19:53 +000088 return
89
90 # We cannot import it. First attempt to load the cfm68k version
91 import imp
92 try:
93 dummy = imp.load_dynamic('Res', 'toolboxmodules.CFM68K.slb')
94 except ImportError, arg:
95 err2 = arg
96 pass
97 else:
Jack Jansen09dcff71997-08-27 14:11:15 +000098 if verbose: print 'Loaded Res from toolboxmodules.CFM68K.slb.'
Jack Jansene3c90a41996-08-28 14:19:53 +000099 return
100
101 # Ok, try the ppc version
102 try:
103 dummy = imp.load_dynamic('Res', 'toolboxmodules.ppc.slb')
104 except ImportError, arg:
105 err3 = arg
106 pass
107 else:
Jack Jansen09dcff71997-08-27 14:11:15 +0000108 if verbose: print 'Loaded Res from toolboxmodules.ppc.slb.'
Jack Jansene3c90a41996-08-28 14:19:53 +0000109 return
110
111 # Tough luck....
112 print "I cannot import the Res module, nor load it from either of"
113 print "toolboxmodules shared libraries. The errors encountered were:"
114 print "import Res:", err1
115 print "load from toolboxmodules.CFM68K.slb:", err2
116 print "load from toolboxmodules.ppc.slb:", err3
117 sys.exit(1)
118
Jack Jansend09deac1996-10-22 15:32:06 +0000119def getextensiondirfile(fname):
120 import macfs
121 import MACFS
122 vrefnum, dirid = macfs.FindFolder(MACFS.kOnSystemDisk, MACFS.kExtensionFolderType, 0)
123 fss = macfs.FSSpec((vrefnum, dirid, fname))
124 return fss.as_pathname()
125
126def mkcorealias(src, altsrc):
127 import string
128 import macostools
129 version = string.split(sys.version)[0]
130 dst = getextensiondirfile(src+ ' ' + version)
Just van Rossum786cb111999-01-30 17:46:34 +0000131 if not os.path.exists(os.path.join(sys.exec_prefix, src)):
132 if not os.path.exists(os.path.join(sys.exec_prefix, altsrc)):
Jack Jansen09dcff71997-08-27 14:11:15 +0000133 if verbose: print '*', src, 'not found'
Jack Jansend09deac1996-10-22 15:32:06 +0000134 return 0
135 src = altsrc
136 try:
137 os.unlink(dst)
138 except os.error:
139 pass
Jack Jansen52b5b022000-10-13 23:33:34 +0000140 do_copy = 0
141 if macfs.FSSpec(sys.exec_prefix).as_tuple()[0] != -1: # XXXX
142 try:
143 import Dlg
144 rv = Dlg.CautionAlert(ALERT_NONBOOT, None)
145 if rv == ALERT_NONBOOT_COPY:
146 do_copy = 1
147 except ImportError:
148 pass
149 if do_copy:
150 macostools.copy(os.path.join(sys.exec_prefix, src), dst)
151 else:
152 macostools.mkalias(os.path.join(sys.exec_prefix, src), dst)
Jack Jansen09dcff71997-08-27 14:11:15 +0000153 if verbose: print ' ', dst, '->', src
Jack Jansend09deac1996-10-22 15:32:06 +0000154 return 1
155
Jack Jansend8eb8a71995-08-09 15:16:58 +0000156
157def main():
Jack Jansend0240831997-09-08 13:16:29 +0000158 MacOS.splash(SPLASH_LOCATE)
Jack Jansene3c90a41996-08-28 14:19:53 +0000159 gotopluginfolder()
Jack Jansend8eb8a71995-08-09 15:16:58 +0000160
Jack Jansene3c90a41996-08-28 14:19:53 +0000161 loadtoolboxmodules()
162
Jack Jansenbb748621997-10-10 15:49:36 +0000163 sys.path.append('::Mac:Lib')
Jack Jansene3c90a41996-08-28 14:19:53 +0000164 import macostools
165
Jack Jansend8eb8a71995-08-09 15:16:58 +0000166 # Remove old .slb aliases and collect a list of .slb files
Jack Jansend0240831997-09-08 13:16:29 +0000167 didsplash = 0
Jack Jansend8eb8a71995-08-09 15:16:58 +0000168 LibFiles = []
169 allfiles = os.listdir(':')
Jack Jansen09dcff71997-08-27 14:11:15 +0000170 if verbose: print 'Removing old aliases...'
Jack Jansend8eb8a71995-08-09 15:16:58 +0000171 for f in allfiles:
172 if f[-4:] == '.slb':
173 finfo = macfs.FSSpec(f).GetFInfo()
174 if finfo.Flags & 0x8000:
Jack Jansend0240831997-09-08 13:16:29 +0000175 if not didsplash:
176 MacOS.splash(SPLASH_REMOVE)
177 didsplash = 1
Jack Jansen09dcff71997-08-27 14:11:15 +0000178 if verbose: print ' Removing', f
Jack Jansend8eb8a71995-08-09 15:16:58 +0000179 os.unlink(f)
180 else:
181 LibFiles.append(f)
Jack Jansen09dcff71997-08-27 14:11:15 +0000182 if verbose: print ' Found', f
183 if verbose: print
Jack Jansend8eb8a71995-08-09 15:16:58 +0000184
Jack Jansene3c90a41996-08-28 14:19:53 +0000185 # Create the new PPC aliases.
Jack Jansend0240831997-09-08 13:16:29 +0000186 didsplash = 0
Jack Jansen09dcff71997-08-27 14:11:15 +0000187 if verbose: print 'Creating PPC aliases...'
Jack Jansene3c90a41996-08-28 14:19:53 +0000188 for dst, src in ppc_goals:
189 if src in LibFiles:
Jack Jansend0240831997-09-08 13:16:29 +0000190 if not didsplash:
191 MacOS.splash(SPLASH_PPC)
192 didsplash = 1
Jack Jansene3c90a41996-08-28 14:19:53 +0000193 macostools.mkalias(src, dst)
Jack Jansen09dcff71997-08-27 14:11:15 +0000194 if verbose: print ' ', dst, '->', src
Jack Jansene3c90a41996-08-28 14:19:53 +0000195 else:
Jack Jansen09dcff71997-08-27 14:11:15 +0000196 if verbose: print '*', dst, 'not created:', src, 'not found'
197 if verbose: print
Jack Jansene3c90a41996-08-28 14:19:53 +0000198
199 # Create the CFM68K aliases.
Jack Jansend0240831997-09-08 13:16:29 +0000200 didsplash = 0
Jack Jansen09dcff71997-08-27 14:11:15 +0000201 if verbose: print 'Creating CFM68K aliases...'
Jack Jansene3c90a41996-08-28 14:19:53 +0000202 for dst, src in cfm68k_goals:
203 if src in LibFiles:
Jack Jansend0240831997-09-08 13:16:29 +0000204 if not didsplash:
205 MacOS.splash(SPLASH_CFM68K)
206 didsplash = 1
Jack Jansene3c90a41996-08-28 14:19:53 +0000207 macostools.mkalias(src, dst)
Jack Jansen09dcff71997-08-27 14:11:15 +0000208 if verbose: print ' ', dst, '->', src
Jack Jansene3c90a41996-08-28 14:19:53 +0000209 else:
Jack Jansen09dcff71997-08-27 14:11:15 +0000210 if verbose: print '*', dst, 'not created:', src, 'not found'
211 if verbose: print
Jack Jansend09deac1996-10-22 15:32:06 +0000212
213 # Create the PythonCore alias(es)
Jack Jansen09dcff71997-08-27 14:11:15 +0000214 if verbose: print 'Creating PythonCore aliases in Extensions folder...'
Jack Jansend09deac1996-10-22 15:32:06 +0000215 os.chdir('::')
216 n = 0
Jack Jansen78c3cc41997-08-19 13:58:57 +0000217 n = n + mkcorealias('PythonCore', 'PythonCore')
Jack Jansend09deac1996-10-22 15:32:06 +0000218 n = n + mkcorealias('PythonCorePPC', ':build.macppc.shared:PythonCorePPC')
219 n = n + mkcorealias('PythonCoreCFM68K', ':build.mac68k.shared:PythonCoreCFM68K')
Jack Jansend0240831997-09-08 13:16:29 +0000220
Jack Jansen09dcff71997-08-27 14:11:15 +0000221 if verbose and n == 0:
Jack Jansend09deac1996-10-22 15:32:06 +0000222 sys.exit(1)
Jack Jansend8eb8a71995-08-09 15:16:58 +0000223
224if __name__ == '__main__':
Jack Jansen09dcff71997-08-27 14:11:15 +0000225 if len(sys.argv) > 1 and sys.argv[1] == '-v':
226 verbose = 1
Jack Jansend8eb8a71995-08-09 15:16:58 +0000227 main()