blob: 88d66a416f6569346bcaff787bdcd3ce209cb60a [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 = [
Jack Jansenfa155a11999-02-07 13:59:06 +000023## ("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"),
28## ("Help.ppc.slb", "toolboxmodules.ppc.slb"),
29## ("Icn.ppc.slb", "toolboxmodules.ppc.slb"),
30## ("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"),
36## ("Sndihooks.ppc.slb", "toolboxmodules.ppc.slb"),
37## ("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"),
Jack Jansen25b361f1996-08-20 16:35:30 +000042
Jack Jansen25b361f1996-08-20 16:35:30 +000043]
44
45cfm68k_goals = [
Jack Jansenfa155a11999-02-07 13:59:06 +000046## ("AE.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
47## ("Ctl.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
48## ("Dlg.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
49## ("Evt.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
50## ("Fm.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
51## ("Help.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
52## ("Icn.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
53## ("Menu.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
54## ("List.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
55## ("Qd.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
56## ("Res.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
57## ("Scrap.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
58## ("Snd.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
59## ("Sndihooks.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
60## ("TE.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
61## ("Win.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
62##
63## ("Cm.CFM68K.slb", "qtmodules.CFM68K.slb"),
64## ("Qt.CFM68K.slb", "qtmodules.CFM68K.slb"),
Jack Jansend8eb8a71995-08-09 15:16:58 +000065]
66
Jack Jansene3c90a41996-08-28 14:19:53 +000067def gotopluginfolder():
68 """Go to the plugin folder, assuming we are somewhere in the Python tree"""
69 import os
70
Just van Rossum786cb111999-01-30 17:46:34 +000071 while not os.path.isdir(":Mac:PlugIns"):
Jack Jansene3c90a41996-08-28 14:19:53 +000072 os.chdir("::")
Just van Rossum786cb111999-01-30 17:46:34 +000073 os.chdir(":Mac:PlugIns")
Jack Jansen09dcff71997-08-27 14:11:15 +000074 if verbose: print "current directory is", os.getcwd()
Jack Jansene3c90a41996-08-28 14:19:53 +000075
76def loadtoolboxmodules():
77 """Attempt to load the Res module"""
78 try:
79 import Res
80 except ImportError, arg:
81 err1 = arg
82 pass
83 else:
Jack Jansen09dcff71997-08-27 14:11:15 +000084 if verbose: print 'imported Res the standard way.'
Jack Jansene3c90a41996-08-28 14:19:53 +000085 return
86
87 # We cannot import it. First attempt to load the cfm68k version
88 import imp
89 try:
90 dummy = imp.load_dynamic('Res', 'toolboxmodules.CFM68K.slb')
91 except ImportError, arg:
92 err2 = arg
93 pass
94 else:
Jack Jansen09dcff71997-08-27 14:11:15 +000095 if verbose: print 'Loaded Res from toolboxmodules.CFM68K.slb.'
Jack Jansene3c90a41996-08-28 14:19:53 +000096 return
97
98 # Ok, try the ppc version
99 try:
100 dummy = imp.load_dynamic('Res', 'toolboxmodules.ppc.slb')
101 except ImportError, arg:
102 err3 = arg
103 pass
104 else:
Jack Jansen09dcff71997-08-27 14:11:15 +0000105 if verbose: print 'Loaded Res from toolboxmodules.ppc.slb.'
Jack Jansene3c90a41996-08-28 14:19:53 +0000106 return
107
108 # Tough luck....
109 print "I cannot import the Res module, nor load it from either of"
110 print "toolboxmodules shared libraries. The errors encountered were:"
111 print "import Res:", err1
112 print "load from toolboxmodules.CFM68K.slb:", err2
113 print "load from toolboxmodules.ppc.slb:", err3
114 sys.exit(1)
115
Jack Jansend09deac1996-10-22 15:32:06 +0000116def getextensiondirfile(fname):
117 import macfs
118 import MACFS
119 vrefnum, dirid = macfs.FindFolder(MACFS.kOnSystemDisk, MACFS.kExtensionFolderType, 0)
120 fss = macfs.FSSpec((vrefnum, dirid, fname))
121 return fss.as_pathname()
122
123def mkcorealias(src, altsrc):
124 import string
125 import macostools
126 version = string.split(sys.version)[0]
127 dst = getextensiondirfile(src+ ' ' + version)
Just van Rossum786cb111999-01-30 17:46:34 +0000128 if not os.path.exists(os.path.join(sys.exec_prefix, src)):
129 if not os.path.exists(os.path.join(sys.exec_prefix, altsrc)):
Jack Jansen09dcff71997-08-27 14:11:15 +0000130 if verbose: print '*', src, 'not found'
Jack Jansend09deac1996-10-22 15:32:06 +0000131 return 0
132 src = altsrc
133 try:
134 os.unlink(dst)
135 except os.error:
136 pass
Just van Rossum786cb111999-01-30 17:46:34 +0000137 macostools.mkalias(os.path.join(sys.exec_prefix, src), dst)
Jack Jansen09dcff71997-08-27 14:11:15 +0000138 if verbose: print ' ', dst, '->', src
Jack Jansend09deac1996-10-22 15:32:06 +0000139 return 1
140
Jack Jansend8eb8a71995-08-09 15:16:58 +0000141
142def main():
Jack Jansend0240831997-09-08 13:16:29 +0000143 MacOS.splash(SPLASH_LOCATE)
Jack Jansene3c90a41996-08-28 14:19:53 +0000144 gotopluginfolder()
Jack Jansend8eb8a71995-08-09 15:16:58 +0000145
Jack Jansene3c90a41996-08-28 14:19:53 +0000146 loadtoolboxmodules()
147
Jack Jansenbb748621997-10-10 15:49:36 +0000148 sys.path.append('::Mac:Lib')
Jack Jansene3c90a41996-08-28 14:19:53 +0000149 import macostools
150
Jack Jansend8eb8a71995-08-09 15:16:58 +0000151 # Remove old .slb aliases and collect a list of .slb files
Jack Jansend0240831997-09-08 13:16:29 +0000152 didsplash = 0
Jack Jansend8eb8a71995-08-09 15:16:58 +0000153 LibFiles = []
154 allfiles = os.listdir(':')
Jack Jansen09dcff71997-08-27 14:11:15 +0000155 if verbose: print 'Removing old aliases...'
Jack Jansend8eb8a71995-08-09 15:16:58 +0000156 for f in allfiles:
157 if f[-4:] == '.slb':
158 finfo = macfs.FSSpec(f).GetFInfo()
159 if finfo.Flags & 0x8000:
Jack Jansend0240831997-09-08 13:16:29 +0000160 if not didsplash:
161 MacOS.splash(SPLASH_REMOVE)
162 didsplash = 1
Jack Jansen09dcff71997-08-27 14:11:15 +0000163 if verbose: print ' Removing', f
Jack Jansend8eb8a71995-08-09 15:16:58 +0000164 os.unlink(f)
165 else:
166 LibFiles.append(f)
Jack Jansen09dcff71997-08-27 14:11:15 +0000167 if verbose: print ' Found', f
168 if verbose: print
Jack Jansend8eb8a71995-08-09 15:16:58 +0000169
Jack Jansene3c90a41996-08-28 14:19:53 +0000170 # Create the new PPC aliases.
Jack Jansend0240831997-09-08 13:16:29 +0000171 didsplash = 0
Jack Jansen09dcff71997-08-27 14:11:15 +0000172 if verbose: print 'Creating PPC aliases...'
Jack Jansene3c90a41996-08-28 14:19:53 +0000173 for dst, src in ppc_goals:
174 if src in LibFiles:
Jack Jansend0240831997-09-08 13:16:29 +0000175 if not didsplash:
176 MacOS.splash(SPLASH_PPC)
177 didsplash = 1
Jack Jansene3c90a41996-08-28 14:19:53 +0000178 macostools.mkalias(src, dst)
Jack Jansen09dcff71997-08-27 14:11:15 +0000179 if verbose: print ' ', dst, '->', src
Jack Jansene3c90a41996-08-28 14:19:53 +0000180 else:
Jack Jansen09dcff71997-08-27 14:11:15 +0000181 if verbose: print '*', dst, 'not created:', src, 'not found'
182 if verbose: print
Jack Jansene3c90a41996-08-28 14:19:53 +0000183
184 # Create the CFM68K aliases.
Jack Jansend0240831997-09-08 13:16:29 +0000185 didsplash = 0
Jack Jansen09dcff71997-08-27 14:11:15 +0000186 if verbose: print 'Creating CFM68K aliases...'
Jack Jansene3c90a41996-08-28 14:19:53 +0000187 for dst, src in cfm68k_goals:
188 if src in LibFiles:
Jack Jansend0240831997-09-08 13:16:29 +0000189 if not didsplash:
190 MacOS.splash(SPLASH_CFM68K)
191 didsplash = 1
Jack Jansene3c90a41996-08-28 14:19:53 +0000192 macostools.mkalias(src, dst)
Jack Jansen09dcff71997-08-27 14:11:15 +0000193 if verbose: print ' ', dst, '->', src
Jack Jansene3c90a41996-08-28 14:19:53 +0000194 else:
Jack Jansen09dcff71997-08-27 14:11:15 +0000195 if verbose: print '*', dst, 'not created:', src, 'not found'
196 if verbose: print
Jack Jansend09deac1996-10-22 15:32:06 +0000197
198 # Create the PythonCore alias(es)
Jack Jansen09dcff71997-08-27 14:11:15 +0000199 if verbose: print 'Creating PythonCore aliases in Extensions folder...'
Jack Jansend09deac1996-10-22 15:32:06 +0000200 os.chdir('::')
201 n = 0
Jack Jansen78c3cc41997-08-19 13:58:57 +0000202 n = n + mkcorealias('PythonCore', 'PythonCore')
Jack Jansend09deac1996-10-22 15:32:06 +0000203 n = n + mkcorealias('PythonCorePPC', ':build.macppc.shared:PythonCorePPC')
204 n = n + mkcorealias('PythonCoreCFM68K', ':build.mac68k.shared:PythonCoreCFM68K')
Jack Jansend0240831997-09-08 13:16:29 +0000205
Jack Jansen09dcff71997-08-27 14:11:15 +0000206 if verbose and n == 0:
Jack Jansend09deac1996-10-22 15:32:06 +0000207 sys.exit(1)
Jack Jansend8eb8a71995-08-09 15:16:58 +0000208
209if __name__ == '__main__':
Jack Jansen09dcff71997-08-27 14:11:15 +0000210 if len(sys.argv) > 1 and sys.argv[1] == '-v':
211 verbose = 1
Jack Jansend8eb8a71995-08-09 15:16:58 +0000212 main()