Mercurial > cpython-lru_cache-weakref
comparison Mac/scripts/ConfigurePython.py @ 16653:b9fe8bd9e5f4 legacy-trunk
ConfigurePython now comes in two flavors: ConfigurePythonClassic and ConfigurePythonCarbon, which copy the respective interpreters to PythonInterpreter and rebuild all the applets. This allows MacOS9 users to switch back and forth.
| author | Jack Jansen <jack.jansen@cwi.nl> |
|---|---|
| date | Sat, 17 Feb 2001 23:31:48 +0000 |
| parents | 07ffb0c3bd5e |
| children | 5921b129f350 |
comparison
equal
deleted
inserted
replaced
| 16652:da9a4a1698f1 | 16653:b9fe8bd9e5f4 |
|---|---|
| 9 | 9 |
| 10 import sys | 10 import sys |
| 11 import os | 11 import os |
| 12 import macfs | 12 import macfs |
| 13 import MacOS | 13 import MacOS |
| 14 verbose=0 | |
| 15 | 14 |
| 16 SPLASH_LOCATE=512 | 15 SPLASH_COPYCORE=512 |
| 17 SPLASH_REMOVE=513 | 16 SPLASH_COPYCARBON=513 |
| 18 SPLASH_CFM68K=514 | 17 SPLASH_COPYCLASSIC=514 |
| 19 SPLASH_PPC=515 | 18 SPLASH_BUILDAPPLETS=515 |
| 20 SPLASH_NUMPY=516 | 19 |
| 20 ALERT_NOCORE=516 | |
| 21 ALERT_NONBOOT=517 | 21 ALERT_NONBOOT=517 |
| 22 ALERT_NONBOOT_COPY=1 | 22 ALERT_NONBOOT_COPY=1 |
| 23 ALERT_NONBOOT_ALIAS=2 | 23 ALERT_NONBOOT_ALIAS=2 |
| 24 | 24 |
| 25 ppc_goals = [ | 25 APPLET_LIST=[ |
| 26 (":Mac:scripts:EditPythonPrefs.py", "EditPythonPrefs", None), | |
| 27 (":Mac:scripts:BuildApplet.py", "BuildApplet", None), | |
| 28 (":Mac:scripts:BuildApplication.py", "BuildApplication", None), | |
| 29 ## (":Mac:scripts:ConfigurePython.py", "ConfigurePython", None), | |
| 30 ## (":Mac:scripts:ConfigurePython.py", "ConfigurePythonCarbon", "PythonInterpreterCarbon"), | |
| 31 ## (":Mac:scripts:ConfigurePython.py", "ConfigurePythonClassic", "PythonInterpreterClassic"), | |
| 32 (":Mac:Tools:IDE:PythonIDE.py", "Python IDE", None), | |
| 33 (":Mac:Tools:CGI:PythonCGISlave.py", ":Mac:Tools:CGI:PythonCGISlave", None), | |
| 34 (":Mac:Tools:CGI:BuildCGIApplet.py", ":Mac:Tools:CGI:BuildCGIApplet", None), | |
| 26 ] | 35 ] |
| 27 | 36 |
| 28 def gotopluginfolder(): | |
| 29 """Go to the plugin folder, assuming we are somewhere in the Python tree""" | |
| 30 import os | |
| 31 | |
| 32 while not os.path.isdir(":Mac:PlugIns"): | |
| 33 os.chdir("::") | |
| 34 os.chdir(":Mac:PlugIns") | |
| 35 if verbose: print "current directory is", os.getcwd() | |
| 36 | |
| 37 def loadtoolboxmodules(): | |
| 38 """Attempt to load the Res module""" | |
| 39 try: | |
| 40 import Res | |
| 41 except ImportError, arg: | |
| 42 err1 = arg | |
| 43 pass | |
| 44 else: | |
| 45 if verbose: print 'imported Res the standard way.' | |
| 46 return | |
| 47 | |
| 48 # We cannot import it. Try a manual load | |
| 49 try: | |
| 50 dummy = imp.load_dynamic('Res', 'toolboxmodules.ppc.slb') | |
| 51 except ImportError, arg: | |
| 52 err3 = arg | |
| 53 pass | |
| 54 else: | |
| 55 if verbose: print 'Loaded Res from toolboxmodules.ppc.slb.' | |
| 56 return | |
| 57 | |
| 58 # Tough luck.... | |
| 59 print "I cannot import the Res module, nor load it from either of" | |
| 60 print "toolboxmodules shared libraries. The errors encountered were:" | |
| 61 print "import Res:", err1 | |
| 62 print "load from toolboxmodules.ppc.slb:", err3 | |
| 63 sys.exit(1) | |
| 64 | |
| 65 def getextensiondirfile(fname): | 37 def getextensiondirfile(fname): |
| 66 import macfs | 38 import macfs |
| 67 import MACFS | 39 import MACFS |
| 68 vrefnum, dirid = macfs.FindFolder(MACFS.kOnSystemDisk, MACFS.kExtensionFolderType, 0) | 40 vrefnum, dirid = macfs.FindFolder(MACFS.kOnSystemDisk, MACFS.kExtensionFolderType, 0) |
| 69 fss = macfs.FSSpec((vrefnum, dirid, fname)) | 41 fss = macfs.FSSpec((vrefnum, dirid, fname)) |
| 74 import macostools | 46 import macostools |
| 75 version = string.split(sys.version)[0] | 47 version = string.split(sys.version)[0] |
| 76 dst = getextensiondirfile(src+ ' ' + version) | 48 dst = getextensiondirfile(src+ ' ' + version) |
| 77 if not os.path.exists(os.path.join(sys.exec_prefix, src)): | 49 if not os.path.exists(os.path.join(sys.exec_prefix, src)): |
| 78 if not os.path.exists(os.path.join(sys.exec_prefix, altsrc)): | 50 if not os.path.exists(os.path.join(sys.exec_prefix, altsrc)): |
| 79 if verbose: print '*', src, 'not found' | |
| 80 return 0 | 51 return 0 |
| 81 src = altsrc | 52 src = altsrc |
| 82 try: | 53 try: |
| 83 os.unlink(dst) | 54 os.unlink(dst) |
| 84 except os.error: | 55 except os.error: |
| 94 pass | 65 pass |
| 95 if do_copy: | 66 if do_copy: |
| 96 macostools.copy(os.path.join(sys.exec_prefix, src), dst) | 67 macostools.copy(os.path.join(sys.exec_prefix, src), dst) |
| 97 else: | 68 else: |
| 98 macostools.mkalias(os.path.join(sys.exec_prefix, src), dst) | 69 macostools.mkalias(os.path.join(sys.exec_prefix, src), dst) |
| 99 if verbose: print ' ', dst, '->', src | |
| 100 return 1 | 70 return 1 |
| 101 | 71 |
| 72 # Copied from fullbuild, should probably go to buildtools | |
| 73 def buildapplet(top, dummy, list): | |
| 74 """Create python applets""" | |
| 75 import buildtools | |
| 76 for src, dst, tmpl in list: | |
| 77 template = buildtools.findtemplate(tmpl) | |
| 78 if src[-3:] != '.py': | |
| 79 raise 'Should end in .py', src | |
| 80 base = os.path.basename(src) | |
| 81 src = os.path.join(top, src) | |
| 82 dst = os.path.join(top, dst) | |
| 83 try: | |
| 84 os.unlink(dst) | |
| 85 except os.error: | |
| 86 pass | |
| 87 try: | |
| 88 buildtools.process(template, src, dst, 1) | |
| 89 except buildtools.BuildError, arg: | |
| 90 print '**', dst, arg | |
| 91 | |
| 92 def buildcopy(top, dummy, list): | |
| 93 import macostools | |
| 94 for src, dst in list: | |
| 95 src = os.path.join(top, src) | |
| 96 dst = os.path.join(top, dst) | |
| 97 import pdb ; pdb.set_trace() | |
| 98 macostools.copy(src, dst) | |
| 102 | 99 |
| 103 def main(): | 100 def main(): |
| 104 MacOS.splash(SPLASH_LOCATE) | 101 os.chdir(sys.prefix) |
| 105 gotopluginfolder() | |
| 106 | |
| 107 loadtoolboxmodules() | |
| 108 | 102 |
| 109 sys.path.append('::Mac:Lib') | 103 sys.path.append('::Mac:Lib') |
| 110 import macostools | 104 import macostools |
| 111 | |
| 112 # Remove old .slb aliases and collect a list of .slb files | |
| 113 didsplash = 0 | |
| 114 LibFiles = [] | |
| 115 allfiles = os.listdir(':') | |
| 116 if verbose: print 'Removing old aliases...' | |
| 117 for f in allfiles: | |
| 118 if f[-4:] == '.slb': | |
| 119 finfo = macfs.FSSpec(f).GetFInfo() | |
| 120 if finfo.Flags & 0x8000: | |
| 121 if not didsplash: | |
| 122 MacOS.splash(SPLASH_REMOVE) | |
| 123 didsplash = 1 | |
| 124 if verbose: print ' Removing', f | |
| 125 os.unlink(f) | |
| 126 else: | |
| 127 LibFiles.append(f) | |
| 128 if verbose: print ' Found', f | |
| 129 if verbose: print | |
| 130 | |
| 131 # Create the new PPC aliases. | |
| 132 didsplash = 0 | |
| 133 if verbose: print 'Creating PPC aliases...' | |
| 134 for dst, src in ppc_goals: | |
| 135 if src in LibFiles: | |
| 136 if not didsplash: | |
| 137 MacOS.splash(SPLASH_PPC) | |
| 138 didsplash = 1 | |
| 139 macostools.mkalias(src, dst) | |
| 140 if verbose: print ' ', dst, '->', src | |
| 141 else: | |
| 142 if verbose: print '*', dst, 'not created:', src, 'not found' | |
| 143 if verbose: print | |
| 144 | 105 |
| 145 # Create the PythonCore alias(es) | 106 # Create the PythonCore alias(es) |
| 146 if verbose: print 'Creating PythonCore aliases in Extensions folder...' | 107 MacOS.splash(SPLASH_COPYCORE) |
| 147 os.chdir('::') | |
| 148 n = 0 | 108 n = 0 |
| 149 n = n + mkcorealias('PythonCore', 'PythonCore') | 109 n = n + mkcorealias('PythonCore', 'PythonCore') |
| 150 n = n + mkcorealias('PythonCoreCarbon', 'PythonCoreCarbon') | 110 n = n + mkcorealias('PythonCoreCarbon', 'PythonCoreCarbon') |
| 151 | 111 if n == 0: |
| 152 if verbose and n == 0: | 112 Dlg.CautionAlert(ALERT_NOCORE, None) |
| 113 return | |
| 114 if sys.argv[0][-7:] == 'Classic': | |
| 115 do_classic = 1 | |
| 116 elif sys.argv[0][-6:] == 'Carbon': | |
| 117 do_classic = 0 | |
| 118 elif sys.argv[0][-15:] == 'ConfigurePython' or sys.argv[0][-18:] == 'ConfigurePython.py': | |
| 119 return | |
| 120 else: | |
| 121 print "I don't know the sys.argv[0] function", sys.argv[0] | |
| 153 sys.exit(1) | 122 sys.exit(1) |
| 154 | 123 if do_classic: |
| 124 MacOS.splash(SPLASH_COPYCLASSIC) | |
| 125 buildcopy(sys.prefix, None, [("PythonInterpreterClassic", "PythonInterpreter")]) | |
| 126 else: | |
| 127 MacOS.splash(SPLASH_COPYCARBON) | |
| 128 buildcopy(sys.prefix, None, [("PythonInterpreterCarbon", "PythonInterpreter")]) | |
| 129 MacOS.splash(SPLASH_BUILDAPPLETS) | |
| 130 buildapplet(sys.prefix, None, APPLET_LIST) | |
| 131 | |
| 155 if __name__ == '__main__': | 132 if __name__ == '__main__': |
| 156 if len(sys.argv) > 1 and sys.argv[1] == '-v': | |
| 157 verbose = 1 | |
| 158 main() | 133 main() |
