1995-08-09 12:16:58 -03:00
|
|
|
# This python script creates Finder aliases for all the
|
|
|
|
# dynamically-loaded modules that "live in" in a single
|
|
|
|
# shared library.
|
|
|
|
#
|
1996-08-28 11:19:53 -03:00
|
|
|
# This is sort-of a merger between Jack's MkPluginAliases
|
|
|
|
# and Guido's mkaliases.
|
|
|
|
#
|
|
|
|
# Jack Jansen, CWI, August 1996
|
1995-08-09 12:16:58 -03:00
|
|
|
|
|
|
|
import sys
|
1996-08-28 11:19:53 -03:00
|
|
|
import os
|
1995-09-24 18:06:50 -03:00
|
|
|
import macfs
|
1997-09-08 10:16:29 -03:00
|
|
|
import MacOS
|
2001-02-27 19:22:02 -04:00
|
|
|
import gestalt
|
2001-02-28 07:23:04 -04:00
|
|
|
import string
|
2001-02-28 11:53:18 -04:00
|
|
|
import Res
|
1995-08-09 12:16:58 -03:00
|
|
|
|
2001-02-17 19:31:48 -04:00
|
|
|
SPLASH_COPYCORE=512
|
|
|
|
SPLASH_COPYCARBON=513
|
|
|
|
SPLASH_COPYCLASSIC=514
|
|
|
|
SPLASH_BUILDAPPLETS=515
|
|
|
|
|
|
|
|
ALERT_NOCORE=516
|
2000-10-13 20:33:34 -03:00
|
|
|
ALERT_NONBOOT=517
|
|
|
|
ALERT_NONBOOT_COPY=1
|
|
|
|
ALERT_NONBOOT_ALIAS=2
|
1997-09-08 10:16:29 -03:00
|
|
|
|
2001-03-08 19:07:57 -04:00
|
|
|
ALERT_NOTPYTHONFOLDER=518
|
|
|
|
ALERT_NOTPYTHONFOLDER_REMOVE_QUIT=1
|
|
|
|
ALERT_NOTPYTHONFOLDER_QUIT=2
|
|
|
|
ALERT_NOTPYTHONFOLDER_CONTINUE=3
|
|
|
|
|
2001-02-17 19:31:48 -04:00
|
|
|
APPLET_LIST=[
|
|
|
|
(":Mac:scripts:EditPythonPrefs.py", "EditPythonPrefs", None),
|
|
|
|
(":Mac:scripts:BuildApplet.py", "BuildApplet", None),
|
|
|
|
(":Mac:scripts:BuildApplication.py", "BuildApplication", None),
|
|
|
|
## (":Mac:scripts:ConfigurePython.py", "ConfigurePython", None),
|
|
|
|
## (":Mac:scripts:ConfigurePython.py", "ConfigurePythonCarbon", "PythonInterpreterCarbon"),
|
|
|
|
## (":Mac:scripts:ConfigurePython.py", "ConfigurePythonClassic", "PythonInterpreterClassic"),
|
|
|
|
(":Mac:Tools:IDE:PythonIDE.py", "Python IDE", None),
|
|
|
|
(":Mac:Tools:CGI:PythonCGISlave.py", ":Mac:Tools:CGI:PythonCGISlave", None),
|
|
|
|
(":Mac:Tools:CGI:BuildCGIApplet.py", ":Mac:Tools:CGI:BuildCGIApplet", None),
|
1995-08-09 12:16:58 -03:00
|
|
|
]
|
|
|
|
|
1996-10-22 12:32:06 -03:00
|
|
|
def getextensiondirfile(fname):
|
|
|
|
import macfs
|
|
|
|
import MACFS
|
2001-02-27 19:22:02 -04:00
|
|
|
try:
|
2001-03-15 10:28:40 -04:00
|
|
|
vrefnum, dirid = macfs.FindFolder(MACFS.kLocalDomain, MACFS.kSharedLibrariesFolderType, 1)
|
2001-02-27 19:22:02 -04:00
|
|
|
except macfs.error:
|
2001-03-15 10:28:40 -04:00
|
|
|
try:
|
|
|
|
vrefnum, dirid = macfs.FindFolder(MACFS.kOnSystemDisk, MACFS.kSharedLibrariesFolderType, 1)
|
|
|
|
except macfs.error:
|
|
|
|
return None
|
|
|
|
fss = macfs.FSSpec((vrefnum, dirid, fname))
|
1996-10-22 12:32:06 -03:00
|
|
|
return fss.as_pathname()
|
|
|
|
|
|
|
|
def mkcorealias(src, altsrc):
|
|
|
|
import string
|
|
|
|
import macostools
|
|
|
|
version = string.split(sys.version)[0]
|
|
|
|
dst = getextensiondirfile(src+ ' ' + version)
|
2001-02-27 19:22:02 -04:00
|
|
|
if not dst:
|
|
|
|
return 0
|
1999-01-30 13:46:34 -04:00
|
|
|
if not os.path.exists(os.path.join(sys.exec_prefix, src)):
|
|
|
|
if not os.path.exists(os.path.join(sys.exec_prefix, altsrc)):
|
1996-10-22 12:32:06 -03:00
|
|
|
return 0
|
|
|
|
src = altsrc
|
|
|
|
try:
|
|
|
|
os.unlink(dst)
|
|
|
|
except os.error:
|
|
|
|
pass
|
2001-03-29 09:53:19 -04:00
|
|
|
do_copy = ask_copy()
|
|
|
|
if do_copy:
|
|
|
|
macostools.copy(os.path.join(sys.exec_prefix, src), dst)
|
|
|
|
else:
|
|
|
|
macostools.mkalias(os.path.join(sys.exec_prefix, src), dst)
|
|
|
|
return 1
|
|
|
|
|
|
|
|
do_copy = None
|
|
|
|
def ask_copy():
|
|
|
|
global do_copy
|
|
|
|
if do_copy != None:
|
|
|
|
return do_copy
|
|
|
|
# On OSX always copy
|
|
|
|
if gestalt.gestalt('sysv') > 0x9ff:
|
|
|
|
do_copy = 1
|
|
|
|
return do_copy
|
2000-10-13 20:33:34 -03:00
|
|
|
do_copy = 0
|
|
|
|
if macfs.FSSpec(sys.exec_prefix).as_tuple()[0] != -1: # XXXX
|
|
|
|
try:
|
|
|
|
import Dlg
|
|
|
|
rv = Dlg.CautionAlert(ALERT_NONBOOT, None)
|
|
|
|
if rv == ALERT_NONBOOT_COPY:
|
|
|
|
do_copy = 1
|
|
|
|
except ImportError:
|
|
|
|
pass
|
2001-03-29 09:53:19 -04:00
|
|
|
return do_copy
|
|
|
|
|
2001-02-17 19:31:48 -04:00
|
|
|
|
|
|
|
# Copied from fullbuild, should probably go to buildtools
|
|
|
|
def buildapplet(top, dummy, list):
|
|
|
|
"""Create python applets"""
|
|
|
|
import buildtools
|
|
|
|
for src, dst, tmpl in list:
|
|
|
|
template = buildtools.findtemplate(tmpl)
|
|
|
|
if src[-3:] != '.py':
|
|
|
|
raise 'Should end in .py', src
|
|
|
|
base = os.path.basename(src)
|
|
|
|
src = os.path.join(top, src)
|
|
|
|
dst = os.path.join(top, dst)
|
|
|
|
try:
|
|
|
|
os.unlink(dst)
|
|
|
|
except os.error:
|
|
|
|
pass
|
|
|
|
try:
|
|
|
|
buildtools.process(template, src, dst, 1)
|
|
|
|
except buildtools.BuildError, arg:
|
|
|
|
print '**', dst, arg
|
|
|
|
|
|
|
|
def buildcopy(top, dummy, list):
|
|
|
|
import macostools
|
|
|
|
for src, dst in list:
|
|
|
|
src = os.path.join(top, src)
|
|
|
|
dst = os.path.join(top, dst)
|
2001-03-06 18:46:25 -04:00
|
|
|
macostools.copy(src, dst, forcetype="APPL")
|
1995-08-09 12:16:58 -03:00
|
|
|
|
|
|
|
def main():
|
2001-02-28 07:23:04 -04:00
|
|
|
verbose = 0
|
|
|
|
try:
|
|
|
|
h = Res.GetResource('DLOG', SPLASH_COPYCORE)
|
|
|
|
del h
|
2001-02-28 11:53:18 -04:00
|
|
|
except Res.Error:
|
2001-02-28 07:23:04 -04:00
|
|
|
verbose = 1
|
2001-02-28 11:53:18 -04:00
|
|
|
print "Not running as applet: verbose on"
|
2001-03-08 19:07:57 -04:00
|
|
|
oldcwd = os.getcwd()
|
2001-02-17 19:31:48 -04:00
|
|
|
os.chdir(sys.prefix)
|
2001-03-08 19:07:57 -04:00
|
|
|
newcwd = os.getcwd()
|
2001-03-15 10:28:40 -04:00
|
|
|
if verbose:
|
|
|
|
print "Not running as applet: Skipping check for preference file correctness."
|
|
|
|
elif oldcwd != newcwd:
|
|
|
|
# Hack to make sure we get the new MACFS
|
|
|
|
sys.path.insert(0, os.path.join(oldcwd, ':Mac:Lib'))
|
2001-03-08 19:07:57 -04:00
|
|
|
import Dlg
|
|
|
|
rv = Dlg.CautionAlert(ALERT_NOTPYTHONFOLDER, None)
|
|
|
|
if rv == ALERT_NOTPYTHONFOLDER_REMOVE_QUIT:
|
2001-03-09 19:15:27 -04:00
|
|
|
import pythonprefs, preferences
|
|
|
|
prefpathname = pythonprefs.pref_fss.as_pathname()
|
|
|
|
os.remove(prefpathname)
|
2001-03-08 19:07:57 -04:00
|
|
|
sys.exit(0)
|
|
|
|
elif rv == ALERT_NOTPYTHONFOLDER_QUIT:
|
|
|
|
sys.exit(0)
|
1995-08-09 12:16:58 -03:00
|
|
|
|
1997-10-10 12:49:36 -03:00
|
|
|
sys.path.append('::Mac:Lib')
|
1996-08-28 11:19:53 -03:00
|
|
|
import macostools
|
2001-02-14 13:04:51 -04:00
|
|
|
|
1996-10-22 12:32:06 -03:00
|
|
|
# Create the PythonCore alias(es)
|
2001-02-17 19:31:48 -04:00
|
|
|
MacOS.splash(SPLASH_COPYCORE)
|
2001-02-28 07:23:04 -04:00
|
|
|
if verbose:
|
|
|
|
print "Copying PythonCore..."
|
1996-10-22 12:32:06 -03:00
|
|
|
n = 0
|
1997-08-19 10:58:57 -03:00
|
|
|
n = n + mkcorealias('PythonCore', 'PythonCore')
|
2001-02-14 13:04:51 -04:00
|
|
|
n = n + mkcorealias('PythonCoreCarbon', 'PythonCoreCarbon')
|
2001-02-17 19:31:48 -04:00
|
|
|
if n == 0:
|
2001-02-27 19:22:02 -04:00
|
|
|
import Dlg
|
2001-02-17 19:31:48 -04:00
|
|
|
Dlg.CautionAlert(ALERT_NOCORE, None)
|
2001-02-28 07:23:04 -04:00
|
|
|
if verbose:
|
|
|
|
print "Warning: PythonCore not copied to Extensions folder"
|
2001-02-17 19:31:48 -04:00
|
|
|
if sys.argv[0][-7:] == 'Classic':
|
|
|
|
do_classic = 1
|
|
|
|
elif sys.argv[0][-6:] == 'Carbon':
|
|
|
|
do_classic = 0
|
|
|
|
else:
|
|
|
|
print "I don't know the sys.argv[0] function", sys.argv[0]
|
2001-02-28 07:23:04 -04:00
|
|
|
if verbose:
|
|
|
|
print "Configure classic or carbon - ",
|
|
|
|
rv = string.strip(sys.stdin.readline())
|
|
|
|
while rv and rv != "classic" and rv != "carbon":
|
|
|
|
print "Configure classic or carbon - ",
|
|
|
|
rv = string.strip(sys.stdin.readline())
|
|
|
|
if rv == "classic":
|
|
|
|
do_classic = 1
|
|
|
|
elif rv == "carbon":
|
|
|
|
do_classic = 0
|
|
|
|
else:
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
sys.exit(1)
|
2001-02-17 19:31:48 -04:00
|
|
|
if do_classic:
|
|
|
|
MacOS.splash(SPLASH_COPYCLASSIC)
|
|
|
|
buildcopy(sys.prefix, None, [("PythonInterpreterClassic", "PythonInterpreter")])
|
|
|
|
else:
|
|
|
|
MacOS.splash(SPLASH_COPYCARBON)
|
|
|
|
buildcopy(sys.prefix, None, [("PythonInterpreterCarbon", "PythonInterpreter")])
|
|
|
|
MacOS.splash(SPLASH_BUILDAPPLETS)
|
|
|
|
buildapplet(sys.prefix, None, APPLET_LIST)
|
|
|
|
|
1995-08-09 12:16:58 -03:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|
2001-02-28 11:53:18 -04:00
|
|
|
MacOS.splash()
|