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 | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 16 | |
Jack Jansen | cbb5d49 | 2001-02-17 23:31:48 +0000 | [diff] [blame] | 17 | SPLASH_COPYCORE=512 |
| 18 | SPLASH_COPYCARBON=513 |
| 19 | SPLASH_COPYCLASSIC=514 |
| 20 | SPLASH_BUILDAPPLETS=515 |
| 21 | |
| 22 | ALERT_NOCORE=516 |
Jack Jansen | 52b5b02 | 2000-10-13 23:33:34 +0000 | [diff] [blame] | 23 | ALERT_NONBOOT=517 |
| 24 | ALERT_NONBOOT_COPY=1 |
| 25 | ALERT_NONBOOT_ALIAS=2 |
Jack Jansen | d024083 | 1997-09-08 13:16:29 +0000 | [diff] [blame] | 26 | |
Jack Jansen | cbb5d49 | 2001-02-17 23:31:48 +0000 | [diff] [blame] | 27 | APPLET_LIST=[ |
| 28 | (":Mac:scripts:EditPythonPrefs.py", "EditPythonPrefs", None), |
| 29 | (":Mac:scripts:BuildApplet.py", "BuildApplet", None), |
| 30 | (":Mac:scripts:BuildApplication.py", "BuildApplication", None), |
| 31 | ## (":Mac:scripts:ConfigurePython.py", "ConfigurePython", None), |
| 32 | ## (":Mac:scripts:ConfigurePython.py", "ConfigurePythonCarbon", "PythonInterpreterCarbon"), |
| 33 | ## (":Mac:scripts:ConfigurePython.py", "ConfigurePythonClassic", "PythonInterpreterClassic"), |
| 34 | (":Mac:Tools:IDE:PythonIDE.py", "Python IDE", None), |
| 35 | (":Mac:Tools:CGI:PythonCGISlave.py", ":Mac:Tools:CGI:PythonCGISlave", None), |
| 36 | (":Mac:Tools:CGI:BuildCGIApplet.py", ":Mac:Tools:CGI:BuildCGIApplet", None), |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 37 | ] |
| 38 | |
Jack Jansen | d09deac | 1996-10-22 15:32:06 +0000 | [diff] [blame] | 39 | def getextensiondirfile(fname): |
| 40 | import macfs |
| 41 | import MACFS |
Jack Jansen | 64700c9 | 2001-02-27 23:22:02 +0000 | [diff] [blame] | 42 | try: |
| 43 | vrefnum, dirid = macfs.FindFolder(MACFS.kOnSystemDisk, MACFS.kExtensionFolderType, 0) |
| 44 | fss = macfs.FSSpec((vrefnum, dirid, fname)) |
| 45 | except macfs.error: |
| 46 | return None |
Jack Jansen | d09deac | 1996-10-22 15:32:06 +0000 | [diff] [blame] | 47 | return fss.as_pathname() |
| 48 | |
| 49 | def mkcorealias(src, altsrc): |
| 50 | import string |
| 51 | import macostools |
| 52 | version = string.split(sys.version)[0] |
| 53 | dst = getextensiondirfile(src+ ' ' + version) |
Jack Jansen | 64700c9 | 2001-02-27 23:22:02 +0000 | [diff] [blame] | 54 | if not dst: |
| 55 | return 0 |
Just van Rossum | 786cb11 | 1999-01-30 17:46:34 +0000 | [diff] [blame] | 56 | if not os.path.exists(os.path.join(sys.exec_prefix, src)): |
| 57 | if not os.path.exists(os.path.join(sys.exec_prefix, altsrc)): |
Jack Jansen | d09deac | 1996-10-22 15:32:06 +0000 | [diff] [blame] | 58 | return 0 |
| 59 | src = altsrc |
| 60 | try: |
| 61 | os.unlink(dst) |
| 62 | except os.error: |
| 63 | pass |
Jack Jansen | 52b5b02 | 2000-10-13 23:33:34 +0000 | [diff] [blame] | 64 | do_copy = 0 |
| 65 | if macfs.FSSpec(sys.exec_prefix).as_tuple()[0] != -1: # XXXX |
| 66 | try: |
| 67 | import Dlg |
| 68 | rv = Dlg.CautionAlert(ALERT_NONBOOT, None) |
| 69 | if rv == ALERT_NONBOOT_COPY: |
| 70 | do_copy = 1 |
| 71 | except ImportError: |
| 72 | pass |
| 73 | if do_copy: |
| 74 | macostools.copy(os.path.join(sys.exec_prefix, src), dst) |
| 75 | else: |
| 76 | macostools.mkalias(os.path.join(sys.exec_prefix, src), dst) |
Jack Jansen | d09deac | 1996-10-22 15:32:06 +0000 | [diff] [blame] | 77 | return 1 |
Jack Jansen | cbb5d49 | 2001-02-17 23:31:48 +0000 | [diff] [blame] | 78 | |
| 79 | # Copied from fullbuild, should probably go to buildtools |
| 80 | def buildapplet(top, dummy, list): |
| 81 | """Create python applets""" |
| 82 | import buildtools |
| 83 | for src, dst, tmpl in list: |
| 84 | template = buildtools.findtemplate(tmpl) |
| 85 | if src[-3:] != '.py': |
| 86 | raise 'Should end in .py', src |
| 87 | base = os.path.basename(src) |
| 88 | src = os.path.join(top, src) |
| 89 | dst = os.path.join(top, dst) |
| 90 | try: |
| 91 | os.unlink(dst) |
| 92 | except os.error: |
| 93 | pass |
| 94 | try: |
| 95 | buildtools.process(template, src, dst, 1) |
| 96 | except buildtools.BuildError, arg: |
| 97 | print '**', dst, arg |
| 98 | |
| 99 | def buildcopy(top, dummy, list): |
| 100 | import macostools |
| 101 | for src, dst in list: |
| 102 | src = os.path.join(top, src) |
| 103 | dst = os.path.join(top, dst) |
Jack Jansen | cbb5d49 | 2001-02-17 23:31:48 +0000 | [diff] [blame] | 104 | macostools.copy(src, dst) |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 105 | |
| 106 | def main(): |
Jack Jansen | 72b97ae | 2001-02-28 11:23:04 +0000 | [diff] [blame^] | 107 | verbose = 0 |
| 108 | try: |
| 109 | h = Res.GetResource('DLOG', SPLASH_COPYCORE) |
| 110 | del h |
| 111 | except: |
| 112 | verbose = 1 |
Jack Jansen | cbb5d49 | 2001-02-17 23:31:48 +0000 | [diff] [blame] | 113 | os.chdir(sys.prefix) |
Jack Jansen | e3c90a4 | 1996-08-28 14:19:53 +0000 | [diff] [blame] | 114 | |
Jack Jansen | bb74862 | 1997-10-10 15:49:36 +0000 | [diff] [blame] | 115 | sys.path.append('::Mac:Lib') |
Jack Jansen | e3c90a4 | 1996-08-28 14:19:53 +0000 | [diff] [blame] | 116 | import macostools |
Jack Jansen | 3112bc1 | 2001-02-14 17:04:51 +0000 | [diff] [blame] | 117 | |
Jack Jansen | d09deac | 1996-10-22 15:32:06 +0000 | [diff] [blame] | 118 | # Create the PythonCore alias(es) |
Jack Jansen | cbb5d49 | 2001-02-17 23:31:48 +0000 | [diff] [blame] | 119 | MacOS.splash(SPLASH_COPYCORE) |
Jack Jansen | 72b97ae | 2001-02-28 11:23:04 +0000 | [diff] [blame^] | 120 | if verbose: |
| 121 | print "Copying PythonCore..." |
Jack Jansen | d09deac | 1996-10-22 15:32:06 +0000 | [diff] [blame] | 122 | n = 0 |
Jack Jansen | 78c3cc4 | 1997-08-19 13:58:57 +0000 | [diff] [blame] | 123 | n = n + mkcorealias('PythonCore', 'PythonCore') |
Jack Jansen | 3112bc1 | 2001-02-14 17:04:51 +0000 | [diff] [blame] | 124 | n = n + mkcorealias('PythonCoreCarbon', 'PythonCoreCarbon') |
Jack Jansen | cbb5d49 | 2001-02-17 23:31:48 +0000 | [diff] [blame] | 125 | if n == 0: |
Jack Jansen | 64700c9 | 2001-02-27 23:22:02 +0000 | [diff] [blame] | 126 | import Dlg |
Jack Jansen | cbb5d49 | 2001-02-17 23:31:48 +0000 | [diff] [blame] | 127 | Dlg.CautionAlert(ALERT_NOCORE, None) |
Jack Jansen | 72b97ae | 2001-02-28 11:23:04 +0000 | [diff] [blame^] | 128 | if verbose: |
| 129 | print "Warning: PythonCore not copied to Extensions folder" |
Jack Jansen | cbb5d49 | 2001-02-17 23:31:48 +0000 | [diff] [blame] | 130 | if sys.argv[0][-7:] == 'Classic': |
| 131 | do_classic = 1 |
| 132 | elif sys.argv[0][-6:] == 'Carbon': |
| 133 | do_classic = 0 |
Jack Jansen | cbb5d49 | 2001-02-17 23:31:48 +0000 | [diff] [blame] | 134 | else: |
| 135 | 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^] | 136 | if verbose: |
| 137 | print "Configure classic or carbon - ", |
| 138 | rv = string.strip(sys.stdin.readline()) |
| 139 | while rv and rv != "classic" and rv != "carbon": |
| 140 | print "Configure classic or carbon - ", |
| 141 | rv = string.strip(sys.stdin.readline()) |
| 142 | if rv == "classic": |
| 143 | do_classic = 1 |
| 144 | elif rv == "carbon": |
| 145 | do_classic = 0 |
| 146 | else: |
| 147 | return |
| 148 | else: |
| 149 | sys.exit(1) |
Jack Jansen | cbb5d49 | 2001-02-17 23:31:48 +0000 | [diff] [blame] | 150 | if do_classic: |
| 151 | MacOS.splash(SPLASH_COPYCLASSIC) |
| 152 | buildcopy(sys.prefix, None, [("PythonInterpreterClassic", "PythonInterpreter")]) |
| 153 | else: |
| 154 | MacOS.splash(SPLASH_COPYCARBON) |
| 155 | buildcopy(sys.prefix, None, [("PythonInterpreterCarbon", "PythonInterpreter")]) |
| 156 | MacOS.splash(SPLASH_BUILDAPPLETS) |
| 157 | buildapplet(sys.prefix, None, APPLET_LIST) |
| 158 | |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 159 | if __name__ == '__main__': |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 160 | main() |