blob: 11b93ddf54ebaa552e0fe07919cff02e49b50dbd [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 Jansend8eb8a71995-08-09 15:16:58 +000061]
62
Jack Jansene3c90a41996-08-28 14:19:53 +000063def gotopluginfolder():
64 """Go to the plugin folder, assuming we are somewhere in the Python tree"""
65 import os
66
67 while not os.path.isdir(":Plugins"):
68 os.chdir("::")
69 os.chdir(":Plugins")
70 print "current directory is", os.getcwd()
71
72def loadtoolboxmodules():
73 """Attempt to load the Res module"""
74 try:
75 import Res
76 except ImportError, arg:
77 err1 = arg
78 pass
79 else:
80 print 'imported Res the standard way.'
81 return
82
83 # We cannot import it. First attempt to load the cfm68k version
84 import imp
85 try:
86 dummy = imp.load_dynamic('Res', 'toolboxmodules.CFM68K.slb')
87 except ImportError, arg:
88 err2 = arg
89 pass
90 else:
91 print 'Loaded Res from toolboxmodules.CFM68K.slb.'
92 return
93
94 # Ok, try the ppc version
95 try:
96 dummy = imp.load_dynamic('Res', 'toolboxmodules.ppc.slb')
97 except ImportError, arg:
98 err3 = arg
99 pass
100 else:
101 print 'Loaded Res from toolboxmodules.ppc.slb.'
102 return
103
104 # Tough luck....
105 print "I cannot import the Res module, nor load it from either of"
106 print "toolboxmodules shared libraries. The errors encountered were:"
107 print "import Res:", err1
108 print "load from toolboxmodules.CFM68K.slb:", err2
109 print "load from toolboxmodules.ppc.slb:", err3
110 sys.exit(1)
111
112
Jack Jansend8eb8a71995-08-09 15:16:58 +0000113
114def main():
Jack Jansene3c90a41996-08-28 14:19:53 +0000115 gotopluginfolder()
Jack Jansend8eb8a71995-08-09 15:16:58 +0000116
Jack Jansene3c90a41996-08-28 14:19:53 +0000117 loadtoolboxmodules()
118
119 import macostools
120
Jack Jansend8eb8a71995-08-09 15:16:58 +0000121 # Remove old .slb aliases and collect a list of .slb files
Jack Jansend8eb8a71995-08-09 15:16:58 +0000122 LibFiles = []
123 allfiles = os.listdir(':')
Jack Jansene3c90a41996-08-28 14:19:53 +0000124 print 'Removing old aliases...'
Jack Jansend8eb8a71995-08-09 15:16:58 +0000125 for f in allfiles:
126 if f[-4:] == '.slb':
127 finfo = macfs.FSSpec(f).GetFInfo()
128 if finfo.Flags & 0x8000:
Jack Jansene3c90a41996-08-28 14:19:53 +0000129 print ' Removing', f
Jack Jansend8eb8a71995-08-09 15:16:58 +0000130 os.unlink(f)
131 else:
132 LibFiles.append(f)
Jack Jansene3c90a41996-08-28 14:19:53 +0000133 print ' Found', f
134 print
Jack Jansend8eb8a71995-08-09 15:16:58 +0000135
Jack Jansene3c90a41996-08-28 14:19:53 +0000136 # Create the new PPC aliases.
137 print 'Creating PPC aliases...'
138 for dst, src in ppc_goals:
139 if src in LibFiles:
140 macostools.mkalias(src, dst)
141 print ' ', dst, '->', src
142 else:
143 print '*', dst, 'not created:', src, 'not found'
144 print
145
146 # Create the CFM68K aliases.
147 print 'Creating CFM68K aliases...'
148 for dst, src in cfm68k_goals:
149 if src in LibFiles:
150 macostools.mkalias(src, dst)
151 print ' ', dst, '->', src
152 else:
153 print '*', dst, 'not created:', src, 'not found'
Jack Jansend8eb8a71995-08-09 15:16:58 +0000154
155if __name__ == '__main__':
156 main()