summaryrefslogtreecommitdiffstats
path: root/Mac/scripts/ConfigurePython.py
blob: 135dc19e448552d8162c920596d20d9d85ac1ef3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# This python script creates Finder aliases for all the
# dynamically-loaded modules that "live in" in a single
# shared library.
# It needs a fully functional non-dynamic python to work
# (since it creates aliases to stuff it needs itself),
# you should probably drag it onto your non-dynamic python.
# 
# If you compare it to MkPluginAliases.as it also serves
# as a comparison between python and AppleScript:-)
#
# Jack Jansen, CWI, August 1995

import sys

def help():
	print"""
Try the following:
1. Remove any old "Python Preferences" files from the system folder.
2. Remove any old "PythonCore" files from the system folder.
3. Make sure this script, PythonPPC and PythonCore are all located in the
   python home folder (where the Lib and PlugIns folders are)
4. Run this script again, by dropping it on PythonPPC.

If this fails try removing starting afresh from the distribution archive.
"""
	sys.exit(1)
	
try:
	import os
except ImportError:
	print """
I cannot import the 'os' module, so something is wrong with sys.path
"""
	help()
	
try:
	import Res
except ImportError:
	#
	# Check that we are actually in the main python directory
	#
	try:
		os.chdir(':PlugIns')
	except IOError:
		print """
I cannot find the 'PlugIns' folder, so I am obviously not run from the Python
home folder.
"""
		help()
	import imp
	cwd = os.getcwd()
	tblibname = os.path.join(cwd, "toolboxmodules.slb")
	if not os.path.exists(tblibname):
		print """
I cannot find the 'toolboxmodules.slb' file in the PlugIns directory.
Start afresh from a clean distribution. 
"""
		sys.exit(1)
	try:
		for wtd in ["Ctl", "Dlg", "Evt", "Qd", "Res", "Win"]:
			imp.load_dynamic(wtd, tblibname)
	except ImportError:
		print """
I cannot load the toolbox modules by hand. Are you sure you are
using a PowerPC mac?
"""
		sys.exit(1)
		

import macfs
import EasyDialogs
import macostools

goals = [
	("mactcp.slb", "mactcpmodules.slb"),
	("macdnr.slb", "mactcpmodules.slb"),
	("AE.slb", "toolboxmodules.slb"),
	("Cm.slb", "toolboxmodules.slb"),
	("Ctl.slb", "toolboxmodules.slb"),
	("Dlg.slb", "toolboxmodules.slb"),
	("Evt.slb", "toolboxmodules.slb"),
	("Fm.slb", "toolboxmodules.slb"),
	("Menu.slb", "toolboxmodules.slb"),
	("List.slb", "toolboxmodules.slb"),
	("Qd.slb", "toolboxmodules.slb"),
	("Qt.slb", "toolboxmodules.slb"),
	("Res.slb", "toolboxmodules.slb"),
	("Snd.slb", "toolboxmodules.slb"),
	("Win.slb", "toolboxmodules.slb"),
	("imgcolormap.slb", "imgmodules.slb"),
	("imgformat.slb", "imgmodules.slb"),
	("imggif.slb", "imgmodules.slb"),
	("imgjpeg.slb", "imgmodules.slb"),
	("imgop.slb", "imgmodules.slb"),
	("imgpbm.slb", "imgmodules.slb"),
	("imgpgm.slb", "imgmodules.slb"),
	("imgppm.slb", "imgmodules.slb"),
	("imgtiff.slb", "imgmodules.slb"),
	("imgsgi.slb", "imgmodules.slb")
]


def main():
	# Ask the user for the plugins directory
	dir, ok = macfs.GetDirectory('Where is the PlugIns folder?')
	if not ok: sys.exit(0)
	os.chdir(dir.as_pathname())
	
	# Remove old .slb aliases and collect a list of .slb files
	if EasyDialogs.AskYesNoCancel('Proceed with removing old aliases?') <= 0:
		sys.exit(0)
	LibFiles = []
	allfiles = os.listdir(':')
	for f in allfiles:
		if f[-4:] == '.slb':
			finfo = macfs.FSSpec(f).GetFInfo()
			if finfo.Flags & 0x8000:
				os.unlink(f)
			else:
				LibFiles.append(f)
	
	print LibFiles
	# Create the new aliases.
	if EasyDialogs.AskYesNoCancel('Proceed with creating new ones?') <= 0:
		sys.exit(0)
	for dst, src in goals:
		if src in LibFiles:
			macostools.mkalias(src, dst)
		else:
			EasyDialogs.Message(dst+' not created: '+src+' not found')
			
	EasyDialogs.Message('All done!')
			
if __name__ == '__main__':
	main()