Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 1 | # This python script creates Finder aliases for all the |
| 2 | # dynamically-loaded modules that "live in" in a single |
| 3 | # shared library. |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 4 | # |
Jack Jansen | e3c90a4 | 1996-08-28 14:19:53 +0000 | [diff] [blame] | 5 | # This is sort-of a merger between Jack's MkPluginAliases |
| 6 | # and Guido's mkaliases. |
| 7 | # |
| 8 | # Jack Jansen, CWI, August 1996 |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 9 | |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 10 | import sys |
Jack Jansen | e3c90a4 | 1996-08-28 14:19:53 +0000 | [diff] [blame] | 11 | import os |
Jack Jansen | bc12873 | 1995-09-24 21:06:50 +0000 | [diff] [blame] | 12 | import macfs |
Jack Jansen | d024083 | 1997-09-08 13:16:29 +0000 | [diff] [blame] | 13 | import MacOS |
Jack Jansen | 64700c9 | 2001-02-27 23:22:02 +0000 | [diff] [blame] | 14 | import gestalt |
Jack Jansen | 72b97ae | 2001-02-28 11:23:04 +0000 | [diff] [blame] | 15 | import string |
Jack Jansen | f7fb3e6 | 2001-02-28 15:53:18 +0000 | [diff] [blame] | 16 | import Res |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 17 | |
Jack Jansen | cbb5d49 | 2001-02-17 23:31:48 +0000 | [diff] [blame] | 18 | SPLASH_COPYCORE=512 |
| 19 | SPLASH_COPYCARBON=513 |
| 20 | SPLASH_COPYCLASSIC=514 |
| 21 | SPLASH_BUILDAPPLETS=515 |
| 22 | |
| 23 | ALERT_NOCORE=516 |
Jack Jansen | 52b5b02 | 2000-10-13 23:33:34 +0000 | [diff] [blame] | 24 | ALERT_NONBOOT=517 |
| 25 | ALERT_NONBOOT_COPY=1 |
| 26 | ALERT_NONBOOT_ALIAS=2 |
Jack Jansen | d024083 | 1997-09-08 13:16:29 +0000 | [diff] [blame] | 27 | |
Jack Jansen | 54f3bdb | 2001-03-08 23:07:57 +0000 | [diff] [blame] | 28 | ALERT_NOTPYTHONFOLDER=518 |
| 29 | ALERT_NOTPYTHONFOLDER_REMOVE_QUIT=1 |
| 30 | ALERT_NOTPYTHONFOLDER_QUIT=2 |
| 31 | ALERT_NOTPYTHONFOLDER_CONTINUE=3 |
| 32 | |
Jack Jansen | cbb5d49 | 2001-02-17 23:31:48 +0000 | [diff] [blame] | 33 | APPLET_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 Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 43 | ] |
| 44 | |
Jack Jansen | d09deac | 1996-10-22 15:32:06 +0000 | [diff] [blame] | 45 | def getextensiondirfile(fname): |
| 46 | import macfs |
| 47 | import MACFS |
Jack Jansen | 64700c9 | 2001-02-27 23:22:02 +0000 | [diff] [blame] | 48 | try: |
Jack Jansen | 54f3bdb | 2001-03-08 23:07:57 +0000 | [diff] [blame] | 49 | vrefnum, dirid = macfs.FindFolder(MACFS.kOnSystemDisk, MACFS.kSharedLibrariesFolderType, 0) |
Jack Jansen | 64700c9 | 2001-02-27 23:22:02 +0000 | [diff] [blame] | 50 | fss = macfs.FSSpec((vrefnum, dirid, fname)) |
| 51 | except macfs.error: |
| 52 | return None |
Jack Jansen | d09deac | 1996-10-22 15:32:06 +0000 | [diff] [blame] | 53 | return fss.as_pathname() |
| 54 | |
| 55 | def mkcorealias(src, altsrc): |
| 56 | import string |
| 57 | import macostools |
| 58 | version = string.split(sys.version)[0] |
| 59 | dst = getextensiondirfile(src+ ' ' + version) |
Jack Jansen | 64700c9 | 2001-02-27 23:22:02 +0000 | [diff] [blame] | 60 | if not dst: |
| 61 | return 0 |
Just van Rossum | 786cb11 | 1999-01-30 17:46:34 +0000 | [diff] [blame] | 62 | if not os.path.exists(os.path.join(sys.exec_prefix, src)): |
| 63 | if not os.path.exists(os.path.join(sys.exec_prefix, altsrc)): |
Jack Jansen | d09deac | 1996-10-22 15:32:06 +0000 | [diff] [blame] | 64 | return 0 |
| 65 | src = altsrc |
| 66 | try: |
| 67 | os.unlink(dst) |
| 68 | except os.error: |
| 69 | pass |
Jack Jansen | 52b5b02 | 2000-10-13 23:33:34 +0000 | [diff] [blame] | 70 | do_copy = 0 |
| 71 | if macfs.FSSpec(sys.exec_prefix).as_tuple()[0] != -1: # XXXX |
| 72 | try: |
| 73 | import Dlg |
| 74 | rv = Dlg.CautionAlert(ALERT_NONBOOT, None) |
| 75 | if rv == ALERT_NONBOOT_COPY: |
| 76 | do_copy = 1 |
| 77 | except ImportError: |
| 78 | pass |
| 79 | if do_copy: |
| 80 | macostools.copy(os.path.join(sys.exec_prefix, src), dst) |
| 81 | else: |
| 82 | macostools.mkalias(os.path.join(sys.exec_prefix, src), dst) |
Jack Jansen | d09deac | 1996-10-22 15:32:06 +0000 | [diff] [blame] | 83 | return 1 |
Jack Jansen | cbb5d49 | 2001-02-17 23:31:48 +0000 | [diff] [blame] | 84 | |
| 85 | # Copied from fullbuild, should probably go to buildtools |
| 86 | def buildapplet(top, dummy, list): |
| 87 | """Create python applets""" |
| 88 | import buildtools |
| 89 | for src, dst, tmpl in list: |
| 90 | template = buildtools.findtemplate(tmpl) |
| 91 | if src[-3:] != '.py': |
| 92 | raise 'Should end in .py', src |
| 93 | base = os.path.basename(src) |
| 94 | src = os.path.join(top, src) |
| 95 | dst = os.path.join(top, dst) |
| 96 | try: |
| 97 | os.unlink(dst) |
| 98 | except os.error: |
| 99 | pass |
| 100 | try: |
| 101 | buildtools.process(template, src, dst, 1) |
| 102 | except buildtools.BuildError, arg: |
| 103 | print '**', dst, arg |
| 104 | |
| 105 | def buildcopy(top, dummy, list): |
| 106 | import macostools |
| 107 | for src, dst in list: |
| 108 | src = os.path.join(top, src) |
| 109 | dst = os.path.join(top, dst) |
Jack Jansen | c1463c98 | 2001-03-06 22:46:25 +0000 | [diff] [blame] | 110 | macostools.copy(src, dst, forcetype="APPL") |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 111 | |
| 112 | def main(): |
Jack Jansen | 72b97ae | 2001-02-28 11:23:04 +0000 | [diff] [blame] | 113 | verbose = 0 |
| 114 | try: |
| 115 | h = Res.GetResource('DLOG', SPLASH_COPYCORE) |
| 116 | del h |
Jack Jansen | f7fb3e6 | 2001-02-28 15:53:18 +0000 | [diff] [blame] | 117 | except Res.Error: |
Jack Jansen | 72b97ae | 2001-02-28 11:23:04 +0000 | [diff] [blame] | 118 | verbose = 1 |
Jack Jansen | f7fb3e6 | 2001-02-28 15:53:18 +0000 | [diff] [blame] | 119 | print "Not running as applet: verbose on" |
Jack Jansen | 54f3bdb | 2001-03-08 23:07:57 +0000 | [diff] [blame] | 120 | oldcwd = os.getcwd() |
Jack Jansen | cbb5d49 | 2001-02-17 23:31:48 +0000 | [diff] [blame] | 121 | os.chdir(sys.prefix) |
Jack Jansen | 54f3bdb | 2001-03-08 23:07:57 +0000 | [diff] [blame] | 122 | newcwd = os.getcwd() |
| 123 | if oldcwd != newcwd: |
| 124 | import Dlg |
| 125 | rv = Dlg.CautionAlert(ALERT_NOTPYTHONFOLDER, None) |
| 126 | if rv == ALERT_NOTPYTHONFOLDER_REMOVE_QUIT: |
Jack Jansen | 0a3939f | 2001-03-09 23:15:27 +0000 | [diff] [blame^] | 127 | import pythonprefs, preferences |
| 128 | prefpathname = pythonprefs.pref_fss.as_pathname() |
| 129 | os.remove(prefpathname) |
Jack Jansen | 54f3bdb | 2001-03-08 23:07:57 +0000 | [diff] [blame] | 130 | sys.exit(0) |
| 131 | elif rv == ALERT_NOTPYTHONFOLDER_QUIT: |
| 132 | sys.exit(0) |
Jack Jansen | e3c90a4 | 1996-08-28 14:19:53 +0000 | [diff] [blame] | 133 | |
Jack Jansen | bb74862 | 1997-10-10 15:49:36 +0000 | [diff] [blame] | 134 | sys.path.append('::Mac:Lib') |
Jack Jansen | e3c90a4 | 1996-08-28 14:19:53 +0000 | [diff] [blame] | 135 | import macostools |
Jack Jansen | 3112bc1 | 2001-02-14 17:04:51 +0000 | [diff] [blame] | 136 | |
Jack Jansen | d09deac | 1996-10-22 15:32:06 +0000 | [diff] [blame] | 137 | # Create the PythonCore alias(es) |
Jack Jansen | cbb5d49 | 2001-02-17 23:31:48 +0000 | [diff] [blame] | 138 | MacOS.splash(SPLASH_COPYCORE) |
Jack Jansen | 72b97ae | 2001-02-28 11:23:04 +0000 | [diff] [blame] | 139 | if verbose: |
| 140 | print "Copying PythonCore..." |
Jack Jansen | d09deac | 1996-10-22 15:32:06 +0000 | [diff] [blame] | 141 | n = 0 |
Jack Jansen | 78c3cc4 | 1997-08-19 13:58:57 +0000 | [diff] [blame] | 142 | n = n + mkcorealias('PythonCore', 'PythonCore') |
Jack Jansen | 3112bc1 | 2001-02-14 17:04:51 +0000 | [diff] [blame] | 143 | n = n + mkcorealias('PythonCoreCarbon', 'PythonCoreCarbon') |
Jack Jansen | cbb5d49 | 2001-02-17 23:31:48 +0000 | [diff] [blame] | 144 | if n == 0: |
Jack Jansen | 64700c9 | 2001-02-27 23:22:02 +0000 | [diff] [blame] | 145 | import Dlg |
Jack Jansen | cbb5d49 | 2001-02-17 23:31:48 +0000 | [diff] [blame] | 146 | Dlg.CautionAlert(ALERT_NOCORE, None) |
Jack Jansen | 72b97ae | 2001-02-28 11:23:04 +0000 | [diff] [blame] | 147 | if verbose: |
| 148 | print "Warning: PythonCore not copied to Extensions folder" |
Jack Jansen | cbb5d49 | 2001-02-17 23:31:48 +0000 | [diff] [blame] | 149 | if sys.argv[0][-7:] == 'Classic': |
| 150 | do_classic = 1 |
| 151 | elif sys.argv[0][-6:] == 'Carbon': |
| 152 | do_classic = 0 |
Jack Jansen | cbb5d49 | 2001-02-17 23:31:48 +0000 | [diff] [blame] | 153 | else: |
| 154 | print "I don't know the sys.argv[0] function", sys.argv[0] |
Jack Jansen | 72b97ae | 2001-02-28 11:23:04 +0000 | [diff] [blame] | 155 | if verbose: |
| 156 | print "Configure classic or carbon - ", |
| 157 | rv = string.strip(sys.stdin.readline()) |
| 158 | while rv and rv != "classic" and rv != "carbon": |
| 159 | print "Configure classic or carbon - ", |
| 160 | rv = string.strip(sys.stdin.readline()) |
| 161 | if rv == "classic": |
| 162 | do_classic = 1 |
| 163 | elif rv == "carbon": |
| 164 | do_classic = 0 |
| 165 | else: |
| 166 | return |
| 167 | else: |
| 168 | sys.exit(1) |
Jack Jansen | cbb5d49 | 2001-02-17 23:31:48 +0000 | [diff] [blame] | 169 | if do_classic: |
| 170 | MacOS.splash(SPLASH_COPYCLASSIC) |
| 171 | buildcopy(sys.prefix, None, [("PythonInterpreterClassic", "PythonInterpreter")]) |
| 172 | else: |
| 173 | MacOS.splash(SPLASH_COPYCARBON) |
| 174 | buildcopy(sys.prefix, None, [("PythonInterpreterCarbon", "PythonInterpreter")]) |
| 175 | MacOS.splash(SPLASH_BUILDAPPLETS) |
| 176 | buildapplet(sys.prefix, None, APPLET_LIST) |
| 177 | |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 178 | if __name__ == '__main__': |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 179 | main() |
Jack Jansen | f7fb3e6 | 2001-02-28 15:53:18 +0000 | [diff] [blame] | 180 | MacOS.splash() |