blob: d5d6687e28f21d2f3d732323ab625b0b5cb34ef6 [file] [log] [blame]
Jack Jansend8eb8a71995-08-09 15:16:58 +00001# This python script creates Finder aliases for all the
2# dynamically-loaded modules that "live in" in a single
3# shared library.
Jack Jansend8eb8a71995-08-09 15:16:58 +00004#
Jack Jansene3c90a41996-08-28 14:19:53 +00005# This is sort-of a merger between Jack's MkPluginAliases
6# and Guido's mkaliases.
7#
8# Jack Jansen, CWI, August 1996
Jack Jansend8eb8a71995-08-09 15:16:58 +00009
Jack Jansend8eb8a71995-08-09 15:16:58 +000010import sys
Jack Jansene3c90a41996-08-28 14:19:53 +000011import os
Jack Jansenbc128731995-09-24 21:06:50 +000012import macfs
Jack Jansend0240831997-09-08 13:16:29 +000013import MacOS
Jack Jansen64700c92001-02-27 23:22:02 +000014import gestalt
Jack Jansen72b97ae2001-02-28 11:23:04 +000015import string
Jack Jansenf7fb3e62001-02-28 15:53:18 +000016import Res
Jack Jansend8eb8a71995-08-09 15:16:58 +000017
Jack Jansencbb5d492001-02-17 23:31:48 +000018SPLASH_COPYCORE=512
19SPLASH_COPYCARBON=513
20SPLASH_COPYCLASSIC=514
21SPLASH_BUILDAPPLETS=515
22
23ALERT_NOCORE=516
Jack Jansen52b5b022000-10-13 23:33:34 +000024ALERT_NONBOOT=517
25ALERT_NONBOOT_COPY=1
26ALERT_NONBOOT_ALIAS=2
Jack Jansend0240831997-09-08 13:16:29 +000027
Jack Jansen54f3bdb2001-03-08 23:07:57 +000028ALERT_NOTPYTHONFOLDER=518
29ALERT_NOTPYTHONFOLDER_REMOVE_QUIT=1
30ALERT_NOTPYTHONFOLDER_QUIT=2
31ALERT_NOTPYTHONFOLDER_CONTINUE=3
32
Jack Jansencbb5d492001-02-17 23:31:48 +000033APPLET_LIST=[
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),
Jack Jansend8eb8a71995-08-09 15:16:58 +000043]
44
Jack Jansend09deac1996-10-22 15:32:06 +000045def getextensiondirfile(fname):
46 import macfs
47 import MACFS
Jack Jansen64700c92001-02-27 23:22:02 +000048 try:
Jack Jansend11f93c2001-03-15 14:28:40 +000049 vrefnum, dirid = macfs.FindFolder(MACFS.kLocalDomain, MACFS.kSharedLibrariesFolderType, 1)
Jack Jansen64700c92001-02-27 23:22:02 +000050 except macfs.error:
Jack Jansend11f93c2001-03-15 14:28:40 +000051 try:
52 vrefnum, dirid = macfs.FindFolder(MACFS.kOnSystemDisk, MACFS.kSharedLibrariesFolderType, 1)
53 except macfs.error:
54 return None
55 fss = macfs.FSSpec((vrefnum, dirid, fname))
Jack Jansend09deac1996-10-22 15:32:06 +000056 return fss.as_pathname()
57
58def mkcorealias(src, altsrc):
59 import string
60 import macostools
61 version = string.split(sys.version)[0]
62 dst = getextensiondirfile(src+ ' ' + version)
Jack Jansen64700c92001-02-27 23:22:02 +000063 if not dst:
64 return 0
Just van Rossum786cb111999-01-30 17:46:34 +000065 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)):
Jack Jansend09deac1996-10-22 15:32:06 +000067 return 0
68 src = altsrc
69 try:
70 os.unlink(dst)
71 except os.error:
72 pass
Jack Jansen52b5b022000-10-13 23:33:34 +000073 do_copy = 0
74 if macfs.FSSpec(sys.exec_prefix).as_tuple()[0] != -1: # XXXX
75 try:
76 import Dlg
77 rv = Dlg.CautionAlert(ALERT_NONBOOT, None)
78 if rv == ALERT_NONBOOT_COPY:
79 do_copy = 1
80 except ImportError:
81 pass
82 if do_copy:
83 macostools.copy(os.path.join(sys.exec_prefix, src), dst)
84 else:
85 macostools.mkalias(os.path.join(sys.exec_prefix, src), dst)
Jack Jansend09deac1996-10-22 15:32:06 +000086 return 1
Jack Jansencbb5d492001-02-17 23:31:48 +000087
88# Copied from fullbuild, should probably go to buildtools
89def buildapplet(top, dummy, list):
90 """Create python applets"""
91 import buildtools
92 for src, dst, tmpl in list:
93 template = buildtools.findtemplate(tmpl)
94 if src[-3:] != '.py':
95 raise 'Should end in .py', src
96 base = os.path.basename(src)
97 src = os.path.join(top, src)
98 dst = os.path.join(top, dst)
99 try:
100 os.unlink(dst)
101 except os.error:
102 pass
103 try:
104 buildtools.process(template, src, dst, 1)
105 except buildtools.BuildError, arg:
106 print '**', dst, arg
107
108def buildcopy(top, dummy, list):
109 import macostools
110 for src, dst in list:
111 src = os.path.join(top, src)
112 dst = os.path.join(top, dst)
Jack Jansenc1463c982001-03-06 22:46:25 +0000113 macostools.copy(src, dst, forcetype="APPL")
Jack Jansend8eb8a71995-08-09 15:16:58 +0000114
115def main():
Jack Jansen72b97ae2001-02-28 11:23:04 +0000116 verbose = 0
117 try:
118 h = Res.GetResource('DLOG', SPLASH_COPYCORE)
119 del h
Jack Jansenf7fb3e62001-02-28 15:53:18 +0000120 except Res.Error:
Jack Jansen72b97ae2001-02-28 11:23:04 +0000121 verbose = 1
Jack Jansenf7fb3e62001-02-28 15:53:18 +0000122 print "Not running as applet: verbose on"
Jack Jansen54f3bdb2001-03-08 23:07:57 +0000123 oldcwd = os.getcwd()
Jack Jansencbb5d492001-02-17 23:31:48 +0000124 os.chdir(sys.prefix)
Jack Jansen54f3bdb2001-03-08 23:07:57 +0000125 newcwd = os.getcwd()
Jack Jansend11f93c2001-03-15 14:28:40 +0000126 if verbose:
127 print "Not running as applet: Skipping check for preference file correctness."
128 elif oldcwd != newcwd:
129 # Hack to make sure we get the new MACFS
130 sys.path.insert(0, os.path.join(oldcwd, ':Mac:Lib'))
Jack Jansen54f3bdb2001-03-08 23:07:57 +0000131 import Dlg
132 rv = Dlg.CautionAlert(ALERT_NOTPYTHONFOLDER, None)
133 if rv == ALERT_NOTPYTHONFOLDER_REMOVE_QUIT:
Jack Jansen0a3939f2001-03-09 23:15:27 +0000134 import pythonprefs, preferences
135 prefpathname = pythonprefs.pref_fss.as_pathname()
136 os.remove(prefpathname)
Jack Jansen54f3bdb2001-03-08 23:07:57 +0000137 sys.exit(0)
138 elif rv == ALERT_NOTPYTHONFOLDER_QUIT:
139 sys.exit(0)
Jack Jansene3c90a41996-08-28 14:19:53 +0000140
Jack Jansenbb748621997-10-10 15:49:36 +0000141 sys.path.append('::Mac:Lib')
Jack Jansene3c90a41996-08-28 14:19:53 +0000142 import macostools
Jack Jansen3112bc12001-02-14 17:04:51 +0000143
Jack Jansend09deac1996-10-22 15:32:06 +0000144 # Create the PythonCore alias(es)
Jack Jansencbb5d492001-02-17 23:31:48 +0000145 MacOS.splash(SPLASH_COPYCORE)
Jack Jansen72b97ae2001-02-28 11:23:04 +0000146 if verbose:
147 print "Copying PythonCore..."
Jack Jansend09deac1996-10-22 15:32:06 +0000148 n = 0
Jack Jansen78c3cc41997-08-19 13:58:57 +0000149 n = n + mkcorealias('PythonCore', 'PythonCore')
Jack Jansen3112bc12001-02-14 17:04:51 +0000150 n = n + mkcorealias('PythonCoreCarbon', 'PythonCoreCarbon')
Jack Jansencbb5d492001-02-17 23:31:48 +0000151 if n == 0:
Jack Jansen64700c92001-02-27 23:22:02 +0000152 import Dlg
Jack Jansencbb5d492001-02-17 23:31:48 +0000153 Dlg.CautionAlert(ALERT_NOCORE, None)
Jack Jansen72b97ae2001-02-28 11:23:04 +0000154 if verbose:
155 print "Warning: PythonCore not copied to Extensions folder"
Jack Jansencbb5d492001-02-17 23:31:48 +0000156 if sys.argv[0][-7:] == 'Classic':
157 do_classic = 1
158 elif sys.argv[0][-6:] == 'Carbon':
159 do_classic = 0
Jack Jansencbb5d492001-02-17 23:31:48 +0000160 else:
161 print "I don't know the sys.argv[0] function", sys.argv[0]
Jack Jansen72b97ae2001-02-28 11:23:04 +0000162 if verbose:
163 print "Configure classic or carbon - ",
164 rv = string.strip(sys.stdin.readline())
165 while rv and rv != "classic" and rv != "carbon":
166 print "Configure classic or carbon - ",
167 rv = string.strip(sys.stdin.readline())
168 if rv == "classic":
169 do_classic = 1
170 elif rv == "carbon":
171 do_classic = 0
172 else:
173 return
174 else:
175 sys.exit(1)
Jack Jansencbb5d492001-02-17 23:31:48 +0000176 if do_classic:
177 MacOS.splash(SPLASH_COPYCLASSIC)
178 buildcopy(sys.prefix, None, [("PythonInterpreterClassic", "PythonInterpreter")])
179 else:
180 MacOS.splash(SPLASH_COPYCARBON)
181 buildcopy(sys.prefix, None, [("PythonInterpreterCarbon", "PythonInterpreter")])
182 MacOS.splash(SPLASH_BUILDAPPLETS)
183 buildapplet(sys.prefix, None, APPLET_LIST)
184
Jack Jansend8eb8a71995-08-09 15:16:58 +0000185if __name__ == '__main__':
Jack Jansend8eb8a71995-08-09 15:16:58 +0000186 main()
Jack Jansenf7fb3e62001-02-28 15:53:18 +0000187 MacOS.splash()