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
20 SPLASH_COPYCLASSIC
=514
21 SPLASH_BUILDAPPLETS
=515
28 ALERT_NOTPYTHONFOLDER
=518
29 ALERT_NOTPYTHONFOLDER_REMOVE_QUIT
=1
30 ALERT_NOTPYTHONFOLDER_QUIT
=2
31 ALERT_NOTPYTHONFOLDER_CONTINUE
=3
34 (":Mac:scripts:EditPythonPrefs.py", "EditPythonPrefs", None),
35 (":Mac:scripts:BuildApplet.py", "BuildApplet", None),
36 (":Mac:scripts:BuildApplication.py", "BuildApplication", None),
37 ## (":Mac:scripts:ConfigurePython.py", "ConfigurePython", None),
38 ## (":Mac:scripts:ConfigurePython.py", "ConfigurePythonCarbon", "PythonInterpreterCarbon"),
39 ## (":Mac:scripts:ConfigurePython.py", "ConfigurePythonClassic", "PythonInterpreterClassic"),
40 (":Mac:Tools:IDE:PythonIDE.py", "Python IDE", None),
41 (":Mac:Tools:CGI:PythonCGISlave.py", ":Mac:Tools:CGI:PythonCGISlave", None),
42 (":Mac:Tools:CGI:BuildCGIApplet.py", ":Mac:Tools:CGI:BuildCGIApplet", None),
45 def getextensiondirfile(fname
):
49 vrefnum
, dirid
= macfs
.FindFolder(MACFS
.kLocalDomain
, MACFS
.kSharedLibrariesFolderType
, 1)
52 vrefnum
, dirid
= macfs
.FindFolder(MACFS
.kOnSystemDisk
, MACFS
.kSharedLibrariesFolderType
, 1)
55 fss
= macfs
.FSSpec((vrefnum
, dirid
, fname
))
56 return fss
.as_pathname()
58 def mkcorealias(src
, altsrc
):
61 version
= string
.split(sys
.version
)[0]
62 dst
= getextensiondirfile(src
+ ' ' + version
)
65 if not os
.path
.exists(os
.path
.join(sys
.exec_prefix
, src
)):
66 if not os
.path
.exists(os
.path
.join(sys
.exec_prefix
, altsrc
)):
75 macostools
.copy(os
.path
.join(sys
.exec_prefix
, src
), dst
)
77 macostools
.mkalias(os
.path
.join(sys
.exec_prefix
, src
), dst
)
86 if gestalt
.gestalt('sysv') > 0x9ff:
90 if macfs
.FSSpec(sys
.exec_prefix
).as_tuple()[0] != -1: # XXXX
93 rv
= Dlg
.CautionAlert(ALERT_NONBOOT
, None)
94 if rv
== ALERT_NONBOOT_COPY
:
101 # Copied from fullbuild, should probably go to buildtools
102 def buildapplet(top
, dummy
, list):
103 """Create python applets"""
105 for src
, dst
, tmpl
in list:
106 template
= buildtools
.findtemplate(tmpl
)
107 if src
[-3:] != '.py':
108 raise 'Should end in .py', src
109 base
= os
.path
.basename(src
)
110 src
= os
.path
.join(top
, src
)
111 dst
= os
.path
.join(top
, dst
)
117 buildtools
.process(template
, src
, dst
, 1)
118 except buildtools
.BuildError
, arg
:
121 def buildcopy(top
, dummy
, list):
123 for src
, dst
in list:
124 src
= os
.path
.join(top
, src
)
125 dst
= os
.path
.join(top
, dst
)
126 macostools
.copy(src
, dst
, forcetype
="APPL")
131 h
= Res
.GetResource('DLOG', SPLASH_COPYCORE
)
135 print "Not running as applet: verbose on"
140 print "Not running as applet: Skipping check for preference file correctness."
141 elif oldcwd
!= newcwd
:
142 # Hack to make sure we get the new MACFS
143 sys
.path
.insert(0, os
.path
.join(oldcwd
, ':Mac:Lib'))
145 rv
= Dlg
.CautionAlert(ALERT_NOTPYTHONFOLDER
, None)
146 if rv
== ALERT_NOTPYTHONFOLDER_REMOVE_QUIT
:
147 import pythonprefs
, preferences
148 prefpathname
= pythonprefs
.pref_fss
.as_pathname()
149 os
.remove(prefpathname
)
151 elif rv
== ALERT_NOTPYTHONFOLDER_QUIT
:
154 sys
.path
.append('::Mac:Lib')
157 # Create the PythonCore alias(es)
158 MacOS
.splash(SPLASH_COPYCORE
)
160 print "Copying PythonCore..."
162 n
= n
+ mkcorealias('PythonCore', 'PythonCore')
163 n
= n
+ mkcorealias('PythonCoreCarbon', 'PythonCoreCarbon')
166 Dlg
.CautionAlert(ALERT_NOCORE
, None)
168 print "Warning: PythonCore not copied to Extensions folder"
169 if sys
.argv
[0][-7:] == 'Classic':
171 elif sys
.argv
[0][-6:] == 'Carbon':
174 print "I don't know the sys.argv[0] function", sys
.argv
[0]
176 print "Configure classic or carbon - ",
177 rv
= string
.strip(sys
.stdin
.readline())
178 while rv
and rv
!= "classic" and rv
!= "carbon":
179 print "Configure classic or carbon - ",
180 rv
= string
.strip(sys
.stdin
.readline())
190 MacOS
.splash(SPLASH_COPYCLASSIC
)
191 buildcopy(sys
.prefix
, None, [("PythonInterpreterClassic", "PythonInterpreter")])
193 MacOS
.splash(SPLASH_COPYCARBON
)
194 buildcopy(sys
.prefix
, None, [("PythonInterpreterCarbon", "PythonInterpreter")])
195 MacOS
.splash(SPLASH_BUILDAPPLETS
)
196 buildapplet(sys
.prefix
, None, APPLET_LIST
)
198 if __name__
== '__main__':