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. |
| 4 | # It needs a fully functional non-dynamic python to work |
| 5 | # (since it creates aliases to stuff it needs itself), |
| 6 | # you should probably drag it onto your non-dynamic python. |
| 7 | # |
| 8 | # If you compare it to MkPluginAliases.as it also serves |
| 9 | # as a comparison between python and AppleScript:-) |
| 10 | # |
| 11 | # Jack Jansen, CWI, August 1995 |
| 12 | |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 13 | import sys |
| 14 | |
Jack Jansen | bc12873 | 1995-09-24 21:06:50 +0000 | [diff] [blame] | 15 | def help(): |
| 16 | print""" |
| 17 | Try the following: |
| 18 | 1. Remove any old "Python Preferences" files from the system folder. |
| 19 | 2. Remove any old "PythonCore" files from the system folder. |
| 20 | 3. Make sure this script, PythonPPC and PythonCore are all located in the |
| 21 | python home folder (where the Lib and PlugIns folders are) |
| 22 | 4. Run this script again, by dropping it on PythonPPC. |
| 23 | |
| 24 | If this fails try removing starting afresh from the distribution archive. |
| 25 | """ |
| 26 | sys.exit(1) |
| 27 | |
| 28 | try: |
| 29 | import os |
| 30 | except ImportError: |
| 31 | print """ |
| 32 | I cannot import the 'os' module, so something is wrong with sys.path |
| 33 | """ |
| 34 | help() |
| 35 | |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 36 | try: |
| 37 | import Res |
| 38 | except ImportError: |
Jack Jansen | bc12873 | 1995-09-24 21:06:50 +0000 | [diff] [blame] | 39 | # |
| 40 | # Check that we are actually in the main python directory |
| 41 | # |
| 42 | try: |
| 43 | os.chdir(':PlugIns') |
| 44 | except IOError: |
| 45 | print """ |
| 46 | I cannot find the 'PlugIns' folder, so I am obviously not run from the Python |
| 47 | home folder. |
| 48 | """ |
| 49 | help() |
| 50 | import imp |
| 51 | cwd = os.getcwd() |
| 52 | tblibname = os.path.join(cwd, "toolboxmodules.slb") |
Jack Jansen | 316ba5d | 1995-10-09 23:17:18 +0000 | [diff] [blame] | 53 | if not os.path.exists(tblibname): |
Jack Jansen | bc12873 | 1995-09-24 21:06:50 +0000 | [diff] [blame] | 54 | print """ |
| 55 | I cannot find the 'toolboxmodules.slb' file in the PlugIns directory. |
| 56 | Start afresh from a clean distribution. |
| 57 | """ |
| 58 | sys.exit(1) |
| 59 | try: |
| 60 | for wtd in ["Ctl", "Dlg", "Evt", "Qd", "Res", "Win"]: |
Jack Jansen | 316ba5d | 1995-10-09 23:17:18 +0000 | [diff] [blame] | 61 | imp.load_dynamic(wtd, tblibname) |
Jack Jansen | bc12873 | 1995-09-24 21:06:50 +0000 | [diff] [blame] | 62 | except ImportError: |
| 63 | print """ |
| 64 | I cannot load the toolbox modules by hand. Are you sure you are |
| 65 | using a PowerPC mac? |
| 66 | """ |
| 67 | sys.exit(1) |
| 68 | |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 69 | |
Jack Jansen | bc12873 | 1995-09-24 21:06:50 +0000 | [diff] [blame] | 70 | import macfs |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 71 | import EasyDialogs |
Jack Jansen | ad16927 | 1995-08-14 12:20:22 +0000 | [diff] [blame] | 72 | import macostools |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 73 | |
| 74 | goals = [ |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 75 | ("AE.slb", "toolboxmodules.slb"), |
Jack Jansen | 8b13703 | 1995-11-30 15:16:42 +0000 | [diff] [blame] | 76 | ("Cm.slb", "toolboxmodules.slb"), |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 77 | ("Ctl.slb", "toolboxmodules.slb"), |
| 78 | ("Dlg.slb", "toolboxmodules.slb"), |
| 79 | ("Evt.slb", "toolboxmodules.slb"), |
Jack Jansen | bf220a1 | 1996-01-09 17:16:52 +0000 | [diff] [blame] | 80 | ("Fm.slb", "toolboxmodules.slb"), |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 81 | ("Menu.slb", "toolboxmodules.slb"), |
Jack Jansen | ad16927 | 1995-08-14 12:20:22 +0000 | [diff] [blame] | 82 | ("List.slb", "toolboxmodules.slb"), |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 83 | ("Qd.slb", "toolboxmodules.slb"), |
Jack Jansen | cbc0358 | 1995-12-09 14:01:28 +0000 | [diff] [blame] | 84 | ("Qt.slb", "toolboxmodules.slb"), |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 85 | ("Res.slb", "toolboxmodules.slb"), |
Jack Jansen | eba8856 | 1996-04-12 16:34:58 +0000 | [diff] [blame] | 86 | ("Scrap.slb", "toolboxmodules.slb"), |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 87 | ("Snd.slb", "toolboxmodules.slb"), |
Jack Jansen | 822a30b | 1996-04-10 14:52:18 +0000 | [diff] [blame] | 88 | ("TE.slb", "toolboxmodules.slb"), |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 89 | ("Win.slb", "toolboxmodules.slb"), |
| 90 | ("imgcolormap.slb", "imgmodules.slb"), |
| 91 | ("imgformat.slb", "imgmodules.slb"), |
| 92 | ("imggif.slb", "imgmodules.slb"), |
| 93 | ("imgjpeg.slb", "imgmodules.slb"), |
| 94 | ("imgop.slb", "imgmodules.slb"), |
Jack Jansen | 0638b60 | 1995-10-12 10:34:31 +0000 | [diff] [blame] | 95 | ("imgpbm.slb", "imgmodules.slb"), |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 96 | ("imgpgm.slb", "imgmodules.slb"), |
| 97 | ("imgppm.slb", "imgmodules.slb"), |
Jack Jansen | 0638b60 | 1995-10-12 10:34:31 +0000 | [diff] [blame] | 98 | ("imgtiff.slb", "imgmodules.slb"), |
| 99 | ("imgsgi.slb", "imgmodules.slb") |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 100 | ] |
| 101 | |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 102 | |
| 103 | def main(): |
| 104 | # Ask the user for the plugins directory |
Jack Jansen | ad16927 | 1995-08-14 12:20:22 +0000 | [diff] [blame] | 105 | dir, ok = macfs.GetDirectory('Where is the PlugIns folder?') |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 106 | if not ok: sys.exit(0) |
| 107 | os.chdir(dir.as_pathname()) |
| 108 | |
| 109 | # Remove old .slb aliases and collect a list of .slb files |
| 110 | if EasyDialogs.AskYesNoCancel('Proceed with removing old aliases?') <= 0: |
| 111 | sys.exit(0) |
| 112 | LibFiles = [] |
| 113 | allfiles = os.listdir(':') |
| 114 | for f in allfiles: |
| 115 | if f[-4:] == '.slb': |
| 116 | finfo = macfs.FSSpec(f).GetFInfo() |
| 117 | if finfo.Flags & 0x8000: |
| 118 | os.unlink(f) |
| 119 | else: |
| 120 | LibFiles.append(f) |
| 121 | |
| 122 | print LibFiles |
| 123 | # Create the new aliases. |
| 124 | if EasyDialogs.AskYesNoCancel('Proceed with creating new ones?') <= 0: |
| 125 | sys.exit(0) |
| 126 | for dst, src in goals: |
| 127 | if src in LibFiles: |
Jack Jansen | ad16927 | 1995-08-14 12:20:22 +0000 | [diff] [blame] | 128 | macostools.mkalias(src, dst) |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 129 | else: |
| 130 | EasyDialogs.Message(dst+' not created: '+src+' not found') |
| 131 | |
| 132 | EasyDialogs.Message('All done!') |
| 133 | |
| 134 | if __name__ == '__main__': |
| 135 | main() |