Another batch of updates...
[python/dscho.git] / Mac / scripts / ConfigurePython.py
blobd6bc49e5ee4ff7a1f6a58d4e13d9987e29d4d1a7
1 # 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 # but you can run it in a shared python as long as you can point
6 # it to toolboxmodules.slb
8 # Jack Jansen, CWI, August 1995
10 import sys
12 def help():
13 print"""
14 Try the following:
15 1. Remove any old "Python Preferences" files from the system folder.
16 2. Remove any old "PythonCore" or "PythonCoreCFM68K" files from the system folder.
17 3. Make sure this script, your interpreter and your PythonCore are all located in the
18 same folder.
19 4. Run this script again, by dropping it on your interpreter.
21 If this fails try removing starting afresh from the distribution archive.
22 """
23 sys.exit(1)
25 try:
26 import os
27 except ImportError:
28 print """
29 I cannot import the 'os' module, so something is wrong with sys.path
30 """
31 help()
33 try:
34 import Res
35 except ImportError:
36 import macfs
38 # Check that we are actually in the main python directory
40 fss, ok = macfs.StandardGetFile('Where are the toolbox modules?', 'shlb')
41 tblibname = fss.as_pathname()
42 try:
43 for wtd in ["Ctl", "Dlg", "Evt", "Qd", "Res", "Win"]:
44 imp.load_dynamic(wtd, tblibname)
45 except ImportError:
46 print """
47 I cannot load the toolbox modules by hand. Are you sure you are
48 using a PowerPC mac?
49 """
50 sys.exit(1)
53 import macfs
54 import EasyDialogs
55 import macostools
57 ppc_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"),
72 ("Cm.ppc.slb", "qtmodules.ppc.slb"),
73 ("Qt.ppc.slb", "qtmodules.ppc.slb"),
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")
87 cfm68k_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"),
102 ("Cm.CFM68K.slb", "qtmodules.CFM68K.slb"),
103 ("Qt.CFM68K.slb", "qtmodules.CFM68K.slb"),
107 def main():
108 # Ask the user for the plugins directory
109 dir, ok = macfs.GetDirectory('Where is the PlugIns folder?')
110 if not ok: sys.exit(0)
111 os.chdir(dir.as_pathname())
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)
126 print LibFiles
127 # Create the new aliases.
128 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')
141 EasyDialogs.Message('All done!')
143 if __name__ == '__main__':
144 main()