blob: 759c4ee1794be21ffa35e804480851c5bb2995fe [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 Jansend8eb8a71995-08-09 15:16:58 +000013
Jack Jansen25b361f1996-08-20 16:35:30 +000014ppc_goals = [
15 ("AE.ppc.slb", "toolboxmodules.ppc.slb"),
16 ("Ctl.ppc.slb", "toolboxmodules.ppc.slb"),
17 ("Dlg.ppc.slb", "toolboxmodules.ppc.slb"),
18 ("Evt.ppc.slb", "toolboxmodules.ppc.slb"),
19 ("Fm.ppc.slb", "toolboxmodules.ppc.slb"),
20 ("Menu.ppc.slb", "toolboxmodules.ppc.slb"),
21 ("List.ppc.slb", "toolboxmodules.ppc.slb"),
22 ("Qd.ppc.slb", "toolboxmodules.ppc.slb"),
23 ("Res.ppc.slb", "toolboxmodules.ppc.slb"),
24 ("Scrap.ppc.slb", "toolboxmodules.ppc.slb"),
25 ("Snd.ppc.slb", "toolboxmodules.ppc.slb"),
26 ("TE.ppc.slb", "toolboxmodules.ppc.slb"),
27 ("Win.ppc.slb", "toolboxmodules.ppc.slb"),
28
29 ("Cm.ppc.slb", "qtmodules.ppc.slb"),
30 ("Qt.ppc.slb", "qtmodules.ppc.slb"),
31
32 ("imgcolormap.ppc.slb", "imgmodules.ppc.slb"),
33 ("imgformat.ppc.slb", "imgmodules.ppc.slb"),
34 ("imggif.ppc.slb", "imgmodules.ppc.slb"),
35 ("imgjpeg.ppc.slb", "imgmodules.ppc.slb"),
36 ("imgop.ppc.slb", "imgmodules.ppc.slb"),
37 ("imgpbm.ppc.slb", "imgmodules.ppc.slb"),
38 ("imgpgm.ppc.slb", "imgmodules.ppc.slb"),
39 ("imgppm.ppc.slb", "imgmodules.ppc.slb"),
40 ("imgtiff.ppc.slb", "imgmodules.ppc.slb"),
41 ("imgsgi.ppc.slb", "imgmodules.ppc.slb")
42]
43
44cfm68k_goals = [
45 ("AE.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
46 ("Ctl.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
47 ("Dlg.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
48 ("Evt.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
49 ("Fm.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
50 ("Menu.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
51 ("List.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
52 ("Qd.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
53 ("Res.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
54 ("Scrap.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
55 ("Snd.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
56 ("TE.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
57 ("Win.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
58
59 ("Cm.CFM68K.slb", "qtmodules.CFM68K.slb"),
60 ("Qt.CFM68K.slb", "qtmodules.CFM68K.slb"),
Jack Jansen3c7739a1996-10-08 09:25:02 +000061
62 ("imgcolormap.CFM68K.slb", "imgmodules.CFM68K.slb"),
63 ("imgformat.CFM68K.slb", "imgmodules.CFM68K.slb"),
64 ("imggif.CFM68K.slb", "imgmodules.CFM68K.slb"),
65 ("imgjpeg.CFM68K.slb", "imgmodules.CFM68K.slb"),
66 ("imgop.CFM68K.slb", "imgmodules.CFM68K.slb"),
67 ("imgpbm.CFM68K.slb", "imgmodules.CFM68K.slb"),
68 ("imgpgm.CFM68K.slb", "imgmodules.CFM68K.slb"),
69 ("imgppm.CFM68K.slb", "imgmodules.CFM68K.slb"),
70 ("imgtiff.CFM68K.slb", "imgmodules.CFM68K.slb"),
71 ("imgsgi.CFM68K.slb", "imgmodules.CFM68K.slb")
Jack Jansend8eb8a71995-08-09 15:16:58 +000072]
73
Jack Jansene3c90a41996-08-28 14:19:53 +000074def gotopluginfolder():
75 """Go to the plugin folder, assuming we are somewhere in the Python tree"""
76 import os
77
78 while not os.path.isdir(":Plugins"):
79 os.chdir("::")
80 os.chdir(":Plugins")
81 print "current directory is", os.getcwd()
82
83def loadtoolboxmodules():
84 """Attempt to load the Res module"""
85 try:
86 import Res
87 except ImportError, arg:
88 err1 = arg
89 pass
90 else:
91 print 'imported Res the standard way.'
92 return
93
94 # We cannot import it. First attempt to load the cfm68k version
95 import imp
96 try:
97 dummy = imp.load_dynamic('Res', 'toolboxmodules.CFM68K.slb')
98 except ImportError, arg:
99 err2 = arg
100 pass
101 else:
102 print 'Loaded Res from toolboxmodules.CFM68K.slb.'
103 return
104
105 # Ok, try the ppc version
106 try:
107 dummy = imp.load_dynamic('Res', 'toolboxmodules.ppc.slb')
108 except ImportError, arg:
109 err3 = arg
110 pass
111 else:
112 print 'Loaded Res from toolboxmodules.ppc.slb.'
113 return
114
115 # Tough luck....
116 print "I cannot import the Res module, nor load it from either of"
117 print "toolboxmodules shared libraries. The errors encountered were:"
118 print "import Res:", err1
119 print "load from toolboxmodules.CFM68K.slb:", err2
120 print "load from toolboxmodules.ppc.slb:", err3
121 sys.exit(1)
122
Jack Jansend09deac1996-10-22 15:32:06 +0000123def getextensiondirfile(fname):
124 import macfs
125 import MACFS
126 vrefnum, dirid = macfs.FindFolder(MACFS.kOnSystemDisk, MACFS.kExtensionFolderType, 0)
127 fss = macfs.FSSpec((vrefnum, dirid, fname))
128 return fss.as_pathname()
129
130def mkcorealias(src, altsrc):
131 import string
132 import macostools
133 version = string.split(sys.version)[0]
134 dst = getextensiondirfile(src+ ' ' + version)
135 if not os.path.exists(src):
136 if not os.path.exists(altsrc):
137 print '*', src, 'not found'
138 return 0
139 src = altsrc
140 try:
141 os.unlink(dst)
142 except os.error:
143 pass
144 macostools.mkalias(src, dst)
145 print ' ', dst, '->', src
146 return 1
147
Jack Jansend8eb8a71995-08-09 15:16:58 +0000148
149def main():
Jack Jansene3c90a41996-08-28 14:19:53 +0000150 gotopluginfolder()
Jack Jansend8eb8a71995-08-09 15:16:58 +0000151
Jack Jansene3c90a41996-08-28 14:19:53 +0000152 loadtoolboxmodules()
153
154 import macostools
155
Jack Jansend8eb8a71995-08-09 15:16:58 +0000156 # Remove old .slb aliases and collect a list of .slb files
Jack Jansend8eb8a71995-08-09 15:16:58 +0000157 LibFiles = []
158 allfiles = os.listdir(':')
Jack Jansene3c90a41996-08-28 14:19:53 +0000159 print 'Removing old aliases...'
Jack Jansend8eb8a71995-08-09 15:16:58 +0000160 for f in allfiles:
161 if f[-4:] == '.slb':
162 finfo = macfs.FSSpec(f).GetFInfo()
163 if finfo.Flags & 0x8000:
Jack Jansene3c90a41996-08-28 14:19:53 +0000164 print ' Removing', f
Jack Jansend8eb8a71995-08-09 15:16:58 +0000165 os.unlink(f)
166 else:
167 LibFiles.append(f)
Jack Jansene3c90a41996-08-28 14:19:53 +0000168 print ' Found', f
169 print
Jack Jansend8eb8a71995-08-09 15:16:58 +0000170
Jack Jansene3c90a41996-08-28 14:19:53 +0000171 # Create the new PPC aliases.
172 print 'Creating PPC aliases...'
173 for dst, src in ppc_goals:
174 if src in LibFiles:
175 macostools.mkalias(src, dst)
176 print ' ', dst, '->', src
177 else:
178 print '*', dst, 'not created:', src, 'not found'
179 print
180
181 # Create the CFM68K aliases.
182 print 'Creating CFM68K aliases...'
183 for dst, src in cfm68k_goals:
184 if src in LibFiles:
185 macostools.mkalias(src, dst)
186 print ' ', dst, '->', src
187 else:
188 print '*', dst, 'not created:', src, 'not found'
Jack Jansend09deac1996-10-22 15:32:06 +0000189 print
190
191 # Create the PythonCore alias(es)
192 print 'Creating PythonCore aliases in Extensions folder...'
193 os.chdir('::')
194 n = 0
195 n = n + mkcorealias('PythonCorePPC', ':build.macppc.shared:PythonCorePPC')
196 n = n + mkcorealias('PythonCoreCFM68K', ':build.mac68k.shared:PythonCoreCFM68K')
197 if n == 0:
198 sys.exit(1)
Jack Jansend8eb8a71995-08-09 15:16:58 +0000199
200if __name__ == '__main__':
201 main()