1 # This python script creates Finder aliases for all the
2 # dynamically-loaded modules that "live in" in a single
5 # This is sort-of a merger between Jack's MkPluginAliases
6 # and Guido's mkaliases.
8 # Jack Jansen, CWI, August 1996
23 ## ("AE.ppc.slb", "toolboxmodules.ppc.slb"),
24 ## ("Ctl.ppc.slb", "toolboxmodules.ppc.slb"),
25 ## ("Dlg.ppc.slb", "toolboxmodules.ppc.slb"),
26 ## ("Evt.ppc.slb", "toolboxmodules.ppc.slb"),
27 ## ("Fm.ppc.slb", "toolboxmodules.ppc.slb"),
28 ## ("Help.ppc.slb", "toolboxmodules.ppc.slb"),
29 ## ("Icn.ppc.slb", "toolboxmodules.ppc.slb"),
30 ## ("Menu.ppc.slb", "toolboxmodules.ppc.slb"),
31 ## ("List.ppc.slb", "toolboxmodules.ppc.slb"),
32 ## ("Qd.ppc.slb", "toolboxmodules.ppc.slb"),
33 ## ("Res.ppc.slb", "toolboxmodules.ppc.slb"),
34 ## ("Scrap.ppc.slb", "toolboxmodules.ppc.slb"),
35 ## ("Snd.ppc.slb", "toolboxmodules.ppc.slb"),
36 ## ("Sndihooks.ppc.slb", "toolboxmodules.ppc.slb"),
37 ## ("TE.ppc.slb", "toolboxmodules.ppc.slb"),
38 ## ("Win.ppc.slb", "toolboxmodules.ppc.slb"),
40 ## ("Cm.ppc.slb", "qtmodules.ppc.slb"),
41 ## ("Qt.ppc.slb", "qtmodules.ppc.slb"),
46 ## ("AE.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
47 ## ("Ctl.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
48 ## ("Dlg.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
49 ## ("Evt.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
50 ## ("Fm.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
51 ## ("Help.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
52 ## ("Icn.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
53 ## ("Menu.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
54 ## ("List.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
55 ## ("Qd.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
56 ## ("Res.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
57 ## ("Scrap.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
58 ## ("Snd.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
59 ## ("Sndihooks.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
60 ## ("TE.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
61 ## ("Win.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
63 ## ("Cm.CFM68K.slb", "qtmodules.CFM68K.slb"),
64 ## ("Qt.CFM68K.slb", "qtmodules.CFM68K.slb"),
67 def gotopluginfolder():
68 """Go to the plugin folder, assuming we are somewhere in the Python tree"""
71 while not os
.path
.isdir(":Mac:PlugIns"):
73 os
.chdir(":Mac:PlugIns")
74 if verbose
: print "current directory is", os
.getcwd()
76 def loadtoolboxmodules():
77 """Attempt to load the Res module"""
80 except ImportError, arg
:
84 if verbose
: print 'imported Res the standard way.'
87 # We cannot import it. First attempt to load the cfm68k version
90 dummy
= imp
.load_dynamic('Res', 'toolboxmodules.CFM68K.slb')
91 except ImportError, arg
:
95 if verbose
: print 'Loaded Res from toolboxmodules.CFM68K.slb.'
98 # Ok, try the ppc version
100 dummy
= imp
.load_dynamic('Res', 'toolboxmodules.ppc.slb')
101 except ImportError, arg
:
105 if verbose
: print 'Loaded Res from toolboxmodules.ppc.slb.'
109 print "I cannot import the Res module, nor load it from either of"
110 print "toolboxmodules shared libraries. The errors encountered were:"
111 print "import Res:", err1
112 print "load from toolboxmodules.CFM68K.slb:", err2
113 print "load from toolboxmodules.ppc.slb:", err3
116 def getextensiondirfile(fname
):
119 vrefnum
, dirid
= macfs
.FindFolder(MACFS
.kOnSystemDisk
, MACFS
.kExtensionFolderType
, 0)
120 fss
= macfs
.FSSpec((vrefnum
, dirid
, fname
))
121 return fss
.as_pathname()
123 def mkcorealias(src
, altsrc
):
126 version
= string
.split(sys
.version
)[0]
127 dst
= getextensiondirfile(src
+ ' ' + version
)
128 if not os
.path
.exists(os
.path
.join(sys
.exec_prefix
, src
)):
129 if not os
.path
.exists(os
.path
.join(sys
.exec_prefix
, altsrc
)):
130 if verbose
: print '*', src
, 'not found'
137 macostools
.mkalias(os
.path
.join(sys
.exec_prefix
, src
), dst
)
138 if verbose
: print ' ', dst
, '->', src
143 MacOS
.splash(SPLASH_LOCATE
)
148 sys
.path
.append('::Mac:Lib')
151 # Remove old .slb aliases and collect a list of .slb files
154 allfiles
= os
.listdir(':')
155 if verbose
: print 'Removing old aliases...'
158 finfo
= macfs
.FSSpec(f
).GetFInfo()
159 if finfo
.Flags
& 0x8000:
161 MacOS
.splash(SPLASH_REMOVE
)
163 if verbose
: print ' Removing', f
167 if verbose
: print ' Found', f
170 # Create the new PPC aliases.
172 if verbose
: print 'Creating PPC aliases...'
173 for dst
, src
in ppc_goals
:
176 MacOS
.splash(SPLASH_PPC
)
178 macostools
.mkalias(src
, dst
)
179 if verbose
: print ' ', dst
, '->', src
181 if verbose
: print '*', dst
, 'not created:', src
, 'not found'
184 # Create the CFM68K aliases.
186 if verbose
: print 'Creating CFM68K aliases...'
187 for dst
, src
in cfm68k_goals
:
190 MacOS
.splash(SPLASH_CFM68K
)
192 macostools
.mkalias(src
, dst
)
193 if verbose
: print ' ', dst
, '->', src
195 if verbose
: print '*', dst
, 'not created:', src
, 'not found'
198 # Create the PythonCore alias(es)
199 if verbose
: print 'Creating PythonCore aliases in Extensions folder...'
202 n
= n
+ mkcorealias('PythonCore', 'PythonCore')
203 n
= n
+ mkcorealias('PythonCorePPC', ':build.macppc.shared:PythonCorePPC')
204 n
= n
+ mkcorealias('PythonCoreCFM68K', ':build.mac68k.shared:PythonCoreCFM68K')
206 if verbose
and n
== 0:
209 if __name__
== '__main__':
210 if len(sys
.argv
) > 1 and sys
.argv
[1] == '-v':