blob: d6bc49e5ee4ff7a1f6a58d4e13d9987e29d4d1a7 [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.
4# It needs a fully functional non-dynamic python to work
Jack Jansen25b361f1996-08-20 16:35:30 +00005# but you can run it in a shared python as long as you can point
6# it to toolboxmodules.slb
Jack Jansend8eb8a71995-08-09 15:16:58 +00007#
8# Jack Jansen, CWI, August 1995
9
Jack Jansend8eb8a71995-08-09 15:16:58 +000010import sys
11
Jack Jansenbc128731995-09-24 21:06:50 +000012def help():
13 print"""
14Try the following:
151. Remove any old "Python Preferences" files from the system folder.
Jack Jansen25b361f1996-08-20 16:35:30 +0000162. Remove any old "PythonCore" or "PythonCoreCFM68K" files from the system folder.
173. Make sure this script, your interpreter and your PythonCore are all located in the
18 same folder.
194. Run this script again, by dropping it on your interpreter.
Jack Jansenbc128731995-09-24 21:06:50 +000020
21If this fails try removing starting afresh from the distribution archive.
22"""
23 sys.exit(1)
24
25try:
26 import os
27except ImportError:
28 print """
29I cannot import the 'os' module, so something is wrong with sys.path
30"""
31 help()
32
Jack Jansend8eb8a71995-08-09 15:16:58 +000033try:
34 import Res
35except ImportError:
Jack Jansen25b361f1996-08-20 16:35:30 +000036 import macfs
Jack Jansenbc128731995-09-24 21:06:50 +000037 #
38 # Check that we are actually in the main python directory
39 #
Jack Jansen25b361f1996-08-20 16:35:30 +000040 fss, ok = macfs.StandardGetFile('Where are the toolbox modules?', 'shlb')
41 tblibname = fss.as_pathname()
Jack Jansenbc128731995-09-24 21:06:50 +000042 try:
43 for wtd in ["Ctl", "Dlg", "Evt", "Qd", "Res", "Win"]:
Jack Jansen316ba5d1995-10-09 23:17:18 +000044 imp.load_dynamic(wtd, tblibname)
Jack Jansenbc128731995-09-24 21:06:50 +000045 except ImportError:
46 print """
47I cannot load the toolbox modules by hand. Are you sure you are
48using a PowerPC mac?
49"""
50 sys.exit(1)
51
Jack Jansend8eb8a71995-08-09 15:16:58 +000052
Jack Jansenbc128731995-09-24 21:06:50 +000053import macfs
Jack Jansend8eb8a71995-08-09 15:16:58 +000054import EasyDialogs
Jack Jansenad169271995-08-14 12:20:22 +000055import macostools
Jack Jansend8eb8a71995-08-09 15:16:58 +000056
Jack Jansen25b361f1996-08-20 16:35:30 +000057ppc_goals = [
58 ("AE.ppc.slb", "toolboxmodules.ppc.slb"),
59 ("Ctl.ppc.slb", "toolboxmodules.ppc.slb"),
60 ("Dlg.ppc.slb", "toolboxmodules.ppc.slb"),
61 ("Evt.ppc.slb", "toolboxmodules.ppc.slb"),
62 ("Fm.ppc.slb", "toolboxmodules.ppc.slb"),
63 ("Menu.ppc.slb", "toolboxmodules.ppc.slb"),
64 ("List.ppc.slb", "toolboxmodules.ppc.slb"),
65 ("Qd.ppc.slb", "toolboxmodules.ppc.slb"),
66 ("Res.ppc.slb", "toolboxmodules.ppc.slb"),
67 ("Scrap.ppc.slb", "toolboxmodules.ppc.slb"),
68 ("Snd.ppc.slb", "toolboxmodules.ppc.slb"),
69 ("TE.ppc.slb", "toolboxmodules.ppc.slb"),
70 ("Win.ppc.slb", "toolboxmodules.ppc.slb"),
71
72 ("Cm.ppc.slb", "qtmodules.ppc.slb"),
73 ("Qt.ppc.slb", "qtmodules.ppc.slb"),
74
75 ("imgcolormap.ppc.slb", "imgmodules.ppc.slb"),
76 ("imgformat.ppc.slb", "imgmodules.ppc.slb"),
77 ("imggif.ppc.slb", "imgmodules.ppc.slb"),
78 ("imgjpeg.ppc.slb", "imgmodules.ppc.slb"),
79 ("imgop.ppc.slb", "imgmodules.ppc.slb"),
80 ("imgpbm.ppc.slb", "imgmodules.ppc.slb"),
81 ("imgpgm.ppc.slb", "imgmodules.ppc.slb"),
82 ("imgppm.ppc.slb", "imgmodules.ppc.slb"),
83 ("imgtiff.ppc.slb", "imgmodules.ppc.slb"),
84 ("imgsgi.ppc.slb", "imgmodules.ppc.slb")
85]
86
87cfm68k_goals = [
88 ("AE.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
89 ("Ctl.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
90 ("Dlg.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
91 ("Evt.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
92 ("Fm.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
93 ("Menu.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
94 ("List.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
95 ("Qd.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
96 ("Res.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
97 ("Scrap.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
98 ("Snd.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
99 ("TE.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
100 ("Win.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
101
102 ("Cm.CFM68K.slb", "qtmodules.CFM68K.slb"),
103 ("Qt.CFM68K.slb", "qtmodules.CFM68K.slb"),
Jack Jansend8eb8a71995-08-09 15:16:58 +0000104]
105
Jack Jansend8eb8a71995-08-09 15:16:58 +0000106
107def main():
108 # Ask the user for the plugins directory
Jack Jansenad169271995-08-14 12:20:22 +0000109 dir, ok = macfs.GetDirectory('Where is the PlugIns folder?')
Jack Jansend8eb8a71995-08-09 15:16:58 +0000110 if not ok: sys.exit(0)
111 os.chdir(dir.as_pathname())
112
113 # Remove old .slb aliases and collect a list of .slb files
114 if EasyDialogs.AskYesNoCancel('Proceed with removing old aliases?') <= 0:
115 sys.exit(0)
116 LibFiles = []
117 allfiles = os.listdir(':')
118 for f in allfiles:
119 if f[-4:] == '.slb':
120 finfo = macfs.FSSpec(f).GetFInfo()
121 if finfo.Flags & 0x8000:
122 os.unlink(f)
123 else:
124 LibFiles.append(f)
125
126 print LibFiles
127 # Create the new aliases.
Jack Jansen25b361f1996-08-20 16:35:30 +0000128 if EasyDialogs.AskYesNoCancel('Proceed with creating PPC aliases?') > 0:
129 for dst, src in ppc_goals:
130 if src in LibFiles:
131 macostools.mkalias(src, dst)
132 else:
133 EasyDialogs.Message(dst+' not created: '+src+' not found')
134 if EasyDialogs.AskYesNoCancel('Proceed with creating CFM68K aliases?') > 0:
135 for dst, src in cfm68k_goals:
136 if src in LibFiles:
137 macostools.mkalias(src, dst)
138 else:
139 EasyDialogs.Message(dst+' not created: '+src+' not found')
Jack Jansend8eb8a71995-08-09 15:16:58 +0000140
141 EasyDialogs.Message('All done!')
142
143if __name__ == '__main__':
144 main()