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