Mercurial > cpython-lru_cache-weakref
comparison Mac/scripts/ConfigurePython.py @ 4169:687899c563e3 legacy-trunk
Merged Guido's mkaliases and Jack's MkPluginAliases
| author | Jack Jansen <jack.jansen@cwi.nl> |
|---|---|
| date | Wed, 28 Aug 1996 14:19:53 +0000 |
| parents | 21b28dcfa865 |
| children | 383611bda9e6 |
comparison
equal
deleted
inserted
replaced
| 4168:74b8aa7f1114 | 4169:687899c563e3 |
|---|---|
| 1 # This python script creates Finder aliases for all the | 1 # This python script creates Finder aliases for all the |
| 2 # dynamically-loaded modules that "live in" in a single | 2 # dynamically-loaded modules that "live in" in a single |
| 3 # shared library. | 3 # shared library. |
| 4 # It needs a fully functional non-dynamic python to work | |
| 5 # but you can run it in a shared python as long as you can point | |
| 6 # it to toolboxmodules.slb | |
| 7 # | 4 # |
| 8 # Jack Jansen, CWI, August 1995 | 5 # This is sort-of a merger between Jack's MkPluginAliases |
| 6 # and Guido's mkaliases. | |
| 7 # | |
| 8 # Jack Jansen, CWI, August 1996 | |
| 9 | 9 |
| 10 import sys | 10 import sys |
| 11 | 11 import os |
| 12 def help(): | |
| 13 print""" | |
| 14 Try the following: | |
| 15 1. Remove any old "Python Preferences" files from the system folder. | |
| 16 2. Remove any old "PythonCore" or "PythonCoreCFM68K" files from the system folder. | |
| 17 3. Make sure this script, your interpreter and your PythonCore are all located in the | |
| 18 same folder. | |
| 19 4. Run this script again, by dropping it on your interpreter. | |
| 20 | |
| 21 If this fails try removing starting afresh from the distribution archive. | |
| 22 """ | |
| 23 sys.exit(1) | |
| 24 | |
| 25 try: | |
| 26 import os | |
| 27 except ImportError: | |
| 28 print """ | |
| 29 I cannot import the 'os' module, so something is wrong with sys.path | |
| 30 """ | |
| 31 help() | |
| 32 | |
| 33 try: | |
| 34 import Res | |
| 35 except ImportError: | |
| 36 import macfs | |
| 37 # | |
| 38 # Check that we are actually in the main python directory | |
| 39 # | |
| 40 fss, ok = macfs.StandardGetFile('Where are the toolbox modules?', 'shlb') | |
| 41 tblibname = fss.as_pathname() | |
| 42 try: | |
| 43 for wtd in ["Ctl", "Dlg", "Evt", "Qd", "Res", "Win"]: | |
| 44 imp.load_dynamic(wtd, tblibname) | |
| 45 except ImportError: | |
| 46 print """ | |
| 47 I cannot load the toolbox modules by hand. Are you sure you are | |
| 48 using a PowerPC mac? | |
| 49 """ | |
| 50 sys.exit(1) | |
| 51 | |
| 52 | |
| 53 import macfs | 12 import macfs |
| 54 import EasyDialogs | |
| 55 import macostools | |
| 56 | 13 |
| 57 ppc_goals = [ | 14 ppc_goals = [ |
| 58 ("AE.ppc.slb", "toolboxmodules.ppc.slb"), | 15 ("AE.ppc.slb", "toolboxmodules.ppc.slb"), |
| 59 ("Ctl.ppc.slb", "toolboxmodules.ppc.slb"), | 16 ("Ctl.ppc.slb", "toolboxmodules.ppc.slb"), |
| 60 ("Dlg.ppc.slb", "toolboxmodules.ppc.slb"), | 17 ("Dlg.ppc.slb", "toolboxmodules.ppc.slb"), |
| 101 | 58 |
| 102 ("Cm.CFM68K.slb", "qtmodules.CFM68K.slb"), | 59 ("Cm.CFM68K.slb", "qtmodules.CFM68K.slb"), |
| 103 ("Qt.CFM68K.slb", "qtmodules.CFM68K.slb"), | 60 ("Qt.CFM68K.slb", "qtmodules.CFM68K.slb"), |
| 104 ] | 61 ] |
| 105 | 62 |
| 63 def gotopluginfolder(): | |
| 64 """Go to the plugin folder, assuming we are somewhere in the Python tree""" | |
| 65 import os | |
| 66 | |
| 67 while not os.path.isdir(":Plugins"): | |
| 68 os.chdir("::") | |
| 69 os.chdir(":Plugins") | |
| 70 print "current directory is", os.getcwd() | |
| 71 | |
| 72 def loadtoolboxmodules(): | |
| 73 """Attempt to load the Res module""" | |
| 74 try: | |
| 75 import Res | |
| 76 except ImportError, arg: | |
| 77 err1 = arg | |
| 78 pass | |
| 79 else: | |
| 80 print 'imported Res the standard way.' | |
| 81 return | |
| 82 | |
| 83 # We cannot import it. First attempt to load the cfm68k version | |
| 84 import imp | |
| 85 try: | |
| 86 dummy = imp.load_dynamic('Res', 'toolboxmodules.CFM68K.slb') | |
| 87 except ImportError, arg: | |
| 88 err2 = arg | |
| 89 pass | |
| 90 else: | |
| 91 print 'Loaded Res from toolboxmodules.CFM68K.slb.' | |
| 92 return | |
| 93 | |
| 94 # Ok, try the ppc version | |
| 95 try: | |
| 96 dummy = imp.load_dynamic('Res', 'toolboxmodules.ppc.slb') | |
| 97 except ImportError, arg: | |
| 98 err3 = arg | |
| 99 pass | |
| 100 else: | |
| 101 print 'Loaded Res from toolboxmodules.ppc.slb.' | |
| 102 return | |
| 103 | |
| 104 # Tough luck.... | |
| 105 print "I cannot import the Res module, nor load it from either of" | |
| 106 print "toolboxmodules shared libraries. The errors encountered were:" | |
| 107 print "import Res:", err1 | |
| 108 print "load from toolboxmodules.CFM68K.slb:", err2 | |
| 109 print "load from toolboxmodules.ppc.slb:", err3 | |
| 110 sys.exit(1) | |
| 111 | |
| 112 | |
| 106 | 113 |
| 107 def main(): | 114 def main(): |
| 108 # Ask the user for the plugins directory | 115 gotopluginfolder() |
| 109 dir, ok = macfs.GetDirectory('Where is the PlugIns folder?') | |
| 110 if not ok: sys.exit(0) | |
| 111 os.chdir(dir.as_pathname()) | |
| 112 | 116 |
| 117 loadtoolboxmodules() | |
| 118 | |
| 119 import macostools | |
| 120 | |
| 113 # Remove old .slb aliases and collect a list of .slb files | 121 # Remove old .slb aliases and collect a list of .slb files |
| 114 if EasyDialogs.AskYesNoCancel('Proceed with removing old aliases?') <= 0: | |
| 115 sys.exit(0) | |
| 116 LibFiles = [] | 122 LibFiles = [] |
| 117 allfiles = os.listdir(':') | 123 allfiles = os.listdir(':') |
| 124 print 'Removing old aliases...' | |
| 118 for f in allfiles: | 125 for f in allfiles: |
| 119 if f[-4:] == '.slb': | 126 if f[-4:] == '.slb': |
| 120 finfo = macfs.FSSpec(f).GetFInfo() | 127 finfo = macfs.FSSpec(f).GetFInfo() |
| 121 if finfo.Flags & 0x8000: | 128 if finfo.Flags & 0x8000: |
| 129 print ' Removing', f | |
| 122 os.unlink(f) | 130 os.unlink(f) |
| 123 else: | 131 else: |
| 124 LibFiles.append(f) | 132 LibFiles.append(f) |
| 133 print ' Found', f | |
| 134 print | |
| 125 | 135 |
| 126 print LibFiles | 136 # Create the new PPC aliases. |
| 127 # Create the new aliases. | 137 print 'Creating PPC aliases...' |
| 128 if EasyDialogs.AskYesNoCancel('Proceed with creating PPC aliases?') > 0: | 138 for dst, src in ppc_goals: |
| 129 for dst, src in ppc_goals: | 139 if src in LibFiles: |
| 130 if src in LibFiles: | 140 macostools.mkalias(src, dst) |
| 131 macostools.mkalias(src, dst) | 141 print ' ', dst, '->', src |
| 132 else: | 142 else: |
| 133 EasyDialogs.Message(dst+' not created: '+src+' not found') | 143 print '*', dst, 'not created:', src, 'not found' |
| 134 if EasyDialogs.AskYesNoCancel('Proceed with creating CFM68K aliases?') > 0: | 144 print |
| 135 for dst, src in cfm68k_goals: | 145 |
| 136 if src in LibFiles: | 146 # Create the CFM68K aliases. |
| 137 macostools.mkalias(src, dst) | 147 print 'Creating CFM68K aliases...' |
| 138 else: | 148 for dst, src in cfm68k_goals: |
| 139 EasyDialogs.Message(dst+' not created: '+src+' not found') | 149 if src in LibFiles: |
| 140 | 150 macostools.mkalias(src, dst) |
| 141 EasyDialogs.Message('All done!') | 151 print ' ', dst, '->', src |
| 152 else: | |
| 153 print '*', dst, 'not created:', src, 'not found' | |
| 142 | 154 |
| 143 if __name__ == '__main__': | 155 if __name__ == '__main__': |
| 144 main() | 156 main() |
