blob: f23c4352efd4876b2c130ae6fda20086d8caed90 [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
5# (since it creates aliases to stuff it needs itself),
6# you should probably drag it onto your non-dynamic python.
7#
8# If you compare it to MkPluginAliases.as it also serves
9# as a comparison between python and AppleScript:-)
10#
11# Jack Jansen, CWI, August 1995
12
Jack Jansend8eb8a71995-08-09 15:16:58 +000013import sys
14
Jack Jansenbc128731995-09-24 21:06:50 +000015def help():
16 print"""
17Try the following:
181. Remove any old "Python Preferences" files from the system folder.
192. Remove any old "PythonCore" files from the system folder.
203. Make sure this script, PythonPPC and PythonCore are all located in the
21 python home folder (where the Lib and PlugIns folders are)
224. Run this script again, by dropping it on PythonPPC.
23
24If this fails try removing starting afresh from the distribution archive.
25"""
26 sys.exit(1)
27
28try:
29 import os
30except ImportError:
31 print """
32I cannot import the 'os' module, so something is wrong with sys.path
33"""
34 help()
35
Jack Jansend8eb8a71995-08-09 15:16:58 +000036try:
37 import Res
38except ImportError:
Jack Jansenbc128731995-09-24 21:06:50 +000039 #
40 # Check that we are actually in the main python directory
41 #
42 try:
43 os.chdir(':PlugIns')
44 except IOError:
45 print """
46I cannot find the 'PlugIns' folder, so I am obviously not run from the Python
47home folder.
48"""
49 help()
50 import imp
51 cwd = os.getcwd()
52 tblibname = os.path.join(cwd, "toolboxmodules.slb")
Jack Jansen316ba5d1995-10-09 23:17:18 +000053 if not os.path.exists(tblibname):
Jack Jansenbc128731995-09-24 21:06:50 +000054 print """
55I cannot find the 'toolboxmodules.slb' file in the PlugIns directory.
56Start afresh from a clean distribution.
57"""
58 sys.exit(1)
59 try:
60 for wtd in ["Ctl", "Dlg", "Evt", "Qd", "Res", "Win"]:
Jack Jansen316ba5d1995-10-09 23:17:18 +000061 imp.load_dynamic(wtd, tblibname)
Jack Jansenbc128731995-09-24 21:06:50 +000062 except ImportError:
63 print """
64I cannot load the toolbox modules by hand. Are you sure you are
65using a PowerPC mac?
66"""
67 sys.exit(1)
68
Jack Jansend8eb8a71995-08-09 15:16:58 +000069
Jack Jansenbc128731995-09-24 21:06:50 +000070import macfs
Jack Jansend8eb8a71995-08-09 15:16:58 +000071import EasyDialogs
Jack Jansenad169271995-08-14 12:20:22 +000072import macostools
Jack Jansend8eb8a71995-08-09 15:16:58 +000073
74goals = [
75 ("mactcp.slb", "mactcpmodules.slb"),
76 ("macdnr.slb", "mactcpmodules.slb"),
77 ("AE.slb", "toolboxmodules.slb"),
Jack Jansen8b137031995-11-30 15:16:42 +000078 ("Cm.slb", "toolboxmodules.slb"),
Jack Jansend8eb8a71995-08-09 15:16:58 +000079 ("Ctl.slb", "toolboxmodules.slb"),
80 ("Dlg.slb", "toolboxmodules.slb"),
81 ("Evt.slb", "toolboxmodules.slb"),
Jack Jansenbf220a11996-01-09 17:16:52 +000082 ("Fm.slb", "toolboxmodules.slb"),
Jack Jansend8eb8a71995-08-09 15:16:58 +000083 ("Menu.slb", "toolboxmodules.slb"),
Jack Jansenad169271995-08-14 12:20:22 +000084 ("List.slb", "toolboxmodules.slb"),
Jack Jansend8eb8a71995-08-09 15:16:58 +000085 ("Qd.slb", "toolboxmodules.slb"),
Jack Jansencbc03581995-12-09 14:01:28 +000086 ("Qt.slb", "toolboxmodules.slb"),
Jack Jansend8eb8a71995-08-09 15:16:58 +000087 ("Res.slb", "toolboxmodules.slb"),
Jack Janseneba88561996-04-12 16:34:58 +000088 ("Scrap.slb", "toolboxmodules.slb"),
Jack Jansend8eb8a71995-08-09 15:16:58 +000089 ("Snd.slb", "toolboxmodules.slb"),
Jack Jansen822a30b1996-04-10 14:52:18 +000090 ("TE.slb", "toolboxmodules.slb"),
Jack Jansend8eb8a71995-08-09 15:16:58 +000091 ("Win.slb", "toolboxmodules.slb"),
92 ("imgcolormap.slb", "imgmodules.slb"),
93 ("imgformat.slb", "imgmodules.slb"),
94 ("imggif.slb", "imgmodules.slb"),
95 ("imgjpeg.slb", "imgmodules.slb"),
96 ("imgop.slb", "imgmodules.slb"),
Jack Jansen0638b601995-10-12 10:34:31 +000097 ("imgpbm.slb", "imgmodules.slb"),
Jack Jansend8eb8a71995-08-09 15:16:58 +000098 ("imgpgm.slb", "imgmodules.slb"),
99 ("imgppm.slb", "imgmodules.slb"),
Jack Jansen0638b601995-10-12 10:34:31 +0000100 ("imgtiff.slb", "imgmodules.slb"),
101 ("imgsgi.slb", "imgmodules.slb")
Jack Jansend8eb8a71995-08-09 15:16:58 +0000102]
103
Jack Jansend8eb8a71995-08-09 15:16:58 +0000104
105def main():
106 # Ask the user for the plugins directory
Jack Jansenad169271995-08-14 12:20:22 +0000107 dir, ok = macfs.GetDirectory('Where is the PlugIns folder?')
Jack Jansend8eb8a71995-08-09 15:16:58 +0000108 if not ok: sys.exit(0)
109 os.chdir(dir.as_pathname())
110
111 # Remove old .slb aliases and collect a list of .slb files
112 if EasyDialogs.AskYesNoCancel('Proceed with removing old aliases?') <= 0:
113 sys.exit(0)
114 LibFiles = []
115 allfiles = os.listdir(':')
116 for f in allfiles:
117 if f[-4:] == '.slb':
118 finfo = macfs.FSSpec(f).GetFInfo()
119 if finfo.Flags & 0x8000:
120 os.unlink(f)
121 else:
122 LibFiles.append(f)
123
124 print LibFiles
125 # Create the new aliases.
126 if EasyDialogs.AskYesNoCancel('Proceed with creating new ones?') <= 0:
127 sys.exit(0)
128 for dst, src in goals:
129 if src in LibFiles:
Jack Jansenad169271995-08-14 12:20:22 +0000130 macostools.mkalias(src, dst)
Jack Jansend8eb8a71995-08-09 15:16:58 +0000131 else:
132 EasyDialogs.Message(dst+' not created: '+src+' not found')
133
134 EasyDialogs.Message('All done!')
135
136if __name__ == '__main__':
137 main()