Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e3c90a4

Browse files
committed
Merged Guido's mkaliases and Jack's MkPluginAliases
1 parent 8628897 commit e3c90a4

1 file changed

Lines changed: 82 additions & 70 deletions

File tree

Mac/scripts/ConfigurePython.py

Lines changed: 82 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,15 @@
11
# This python script creates Finder aliases for all the
22
# dynamically-loaded modules that "live in" in a single
33
# 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
74
#
8-
# Jack Jansen, CWI, August 1995
5+
# This is sort-of a merger between Jack's MkPluginAliases
6+
# and Guido's mkaliases.
7+
#
8+
# Jack Jansen, CWI, August 1996
99

1010
import sys
11-
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.
20-
21-
If this fails try removing starting afresh from the distribution archive.
22-
"""
23-
sys.exit(1)
24-
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()
32-
33-
try:
34-
import Res
35-
except ImportError:
36-
import macfs
37-
#
38-
# Check that we are actually in the main python directory
39-
#
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)
51-
52-
11+
import os
5312
import macfs
54-
import EasyDialogs
55-
import macostools
5613

5714
ppc_goals = [
5815
("AE.ppc.slb", "toolboxmodules.ppc.slb"),
@@ -103,42 +60,97 @@ def help():
10360
("Qt.CFM68K.slb", "qtmodules.CFM68K.slb"),
10461
]
10562

63+
def gotopluginfolder():
64+
"""Go to the plugin folder, assuming we are somewhere in the Python tree"""
65+
import os
66+
67+
while not os.path.isdir(":Plugins"):
68+
os.chdir("::")
69+
os.chdir(":Plugins")
70+
print "current directory is", os.getcwd()
71+
72+
def loadtoolboxmodules():
73+
"""Attempt to load the Res module"""
74+
try:
75+
import Res
76+
except ImportError, arg:
77+
err1 = arg
78+
pass
79+
else:
80+
print 'imported Res the standard way.'
81+
return
82+
83+
# We cannot import it. First attempt to load the cfm68k version
84+
import imp
85+
try:
86+
dummy = imp.load_dynamic('Res', 'toolboxmodules.CFM68K.slb')
87+
except ImportError, arg:
88+
err2 = arg
89+
pass
90+
else:
91+
print 'Loaded Res from toolboxmodules.CFM68K.slb.'
92+
return
93+
94+
# Ok, try the ppc version
95+
try:
96+
dummy = imp.load_dynamic('Res', 'toolboxmodules.ppc.slb')
97+
except ImportError, arg:
98+
err3 = arg
99+
pass
100+
else:
101+
print 'Loaded Res from toolboxmodules.ppc.slb.'
102+
return
103+
104+
# Tough luck....
105+
print "I cannot import the Res module, nor load it from either of"
106+
print "toolboxmodules shared libraries. The errors encountered were:"
107+
print "import Res:", err1
108+
print "load from toolboxmodules.CFM68K.slb:", err2
109+
print "load from toolboxmodules.ppc.slb:", err3
110+
sys.exit(1)
111+
112+
106113

107114
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())
115+
gotopluginfolder()
116+
117+
loadtoolboxmodules()
112118

119+
import macostools
120+
113121
# 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)
116122
LibFiles = []
117123
allfiles = os.listdir(':')
124+
print 'Removing old aliases...'
118125
for f in allfiles:
119126
if f[-4:] == '.slb':
120127
finfo = macfs.FSSpec(f).GetFInfo()
121128
if finfo.Flags & 0x8000:
129+
print ' Removing', f
122130
os.unlink(f)
123131
else:
124132
LibFiles.append(f)
133+
print ' Found', f
134+
print
125135

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')
140-
141-
EasyDialogs.Message('All done!')
136+
# Create the new PPC aliases.
137+
print 'Creating PPC aliases...'
138+
for dst, src in ppc_goals:
139+
if src in LibFiles:
140+
macostools.mkalias(src, dst)
141+
print ' ', dst, '->', src
142+
else:
143+
print '*', dst, 'not created:', src, 'not found'
144+
print
145+
146+
# Create the CFM68K aliases.
147+
print 'Creating CFM68K aliases...'
148+
for dst, src in cfm68k_goals:
149+
if src in LibFiles:
150+
macostools.mkalias(src, dst)
151+
print ' ', dst, '->', src
152+
else:
153+
print '*', dst, 'not created:', src, 'not found'
142154

143155
if __name__ == '__main__':
144156
main()

0 commit comments

Comments
 (0)