blob: ba76ee4f121643847f6ad8fd2564c3dfd7ad854a [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
13import os
14import macfs
15import sys
16
17try:
18 import Res
19except ImportError:
20 print """
21Res module not found, which probably means that you are trying
22to execute this script with a dynamically-linked python. This will
23not work, since the whole point of the script is to create aliases
24for dynamically-linked python to use. Do one of the following:
25- Run this script using a non-dynamic python
26- Use MkPluginAliases.as (an AppleScript)
27- Create the aliases by hand (see the source for a list)."""
28 sys.exit(1)
29
30import EasyDialogs
Jack Jansenad169271995-08-14 12:20:22 +000031import macostools
Jack Jansend8eb8a71995-08-09 15:16:58 +000032
33goals = [
34 ("mactcp.slb", "mactcpmodules.slb"),
35 ("macdnr.slb", "mactcpmodules.slb"),
36 ("AE.slb", "toolboxmodules.slb"),
37 ("Ctl.slb", "toolboxmodules.slb"),
38 ("Dlg.slb", "toolboxmodules.slb"),
39 ("Evt.slb", "toolboxmodules.slb"),
40 ("Menu.slb", "toolboxmodules.slb"),
Jack Jansenad169271995-08-14 12:20:22 +000041 ("List.slb", "toolboxmodules.slb"),
Jack Jansend8eb8a71995-08-09 15:16:58 +000042 ("Qd.slb", "toolboxmodules.slb"),
43 ("Res.slb", "toolboxmodules.slb"),
44 ("Snd.slb", "toolboxmodules.slb"),
45 ("Win.slb", "toolboxmodules.slb"),
46 ("imgcolormap.slb", "imgmodules.slb"),
47 ("imgformat.slb", "imgmodules.slb"),
48 ("imggif.slb", "imgmodules.slb"),
49 ("imgjpeg.slb", "imgmodules.slb"),
50 ("imgop.slb", "imgmodules.slb"),
51 ("imgpgm.slb", "imgmodules.slb"),
52 ("imgppm.slb", "imgmodules.slb"),
53 ("imgtiff.slb", "imgmodules.slb")
54]
55
Jack Jansend8eb8a71995-08-09 15:16:58 +000056
57def main():
58 # Ask the user for the plugins directory
Jack Jansenad169271995-08-14 12:20:22 +000059 dir, ok = macfs.GetDirectory('Where is the PlugIns folder?')
Jack Jansend8eb8a71995-08-09 15:16:58 +000060 if not ok: sys.exit(0)
61 os.chdir(dir.as_pathname())
62
63 # Remove old .slb aliases and collect a list of .slb files
64 if EasyDialogs.AskYesNoCancel('Proceed with removing old aliases?') <= 0:
65 sys.exit(0)
66 LibFiles = []
67 allfiles = os.listdir(':')
68 for f in allfiles:
69 if f[-4:] == '.slb':
70 finfo = macfs.FSSpec(f).GetFInfo()
71 if finfo.Flags & 0x8000:
72 os.unlink(f)
73 else:
74 LibFiles.append(f)
75
76 print LibFiles
77 # Create the new aliases.
78 if EasyDialogs.AskYesNoCancel('Proceed with creating new ones?') <= 0:
79 sys.exit(0)
80 for dst, src in goals:
81 if src in LibFiles:
Jack Jansenad169271995-08-14 12:20:22 +000082 macostools.mkalias(src, dst)
Jack Jansend8eb8a71995-08-09 15:16:58 +000083 else:
84 EasyDialogs.Message(dst+' not created: '+src+' not found')
85
86 EasyDialogs.Message('All done!')
87
88if __name__ == '__main__':
89 main()