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 | |
| 13 | import os |
| 14 | import macfs |
| 15 | import sys |
| 16 | |
| 17 | try: |
| 18 | import Res |
| 19 | except ImportError: |
| 20 | print """ |
| 21 | Res module not found, which probably means that you are trying |
| 22 | to execute this script with a dynamically-linked python. This will |
| 23 | not work, since the whole point of the script is to create aliases |
| 24 | for dynamically-linked python to use. Do one of the following: |
| 25 | - Run this script using a non-dynamic python |
| 26 | - Use MkPluginAliases.as (an AppleScript) |
| 27 | - Create the aliases by hand (see the source for a list).""" |
| 28 | sys.exit(1) |
| 29 | |
| 30 | import EasyDialogs |
Jack Jansen | ad16927 | 1995-08-14 12:20:22 +0000 | [diff] [blame] | 31 | import macostools |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 32 | |
| 33 | goals = [ |
| 34 | ("mactcp.slb", "mactcpmodules.slb"), |
| 35 | ("macdnr.slb", "mactcpmodules.slb"), |
| 36 | ("AE.slb", "toolboxmodules.slb"), |
| 37 | ("Ctl.slb", "toolboxmodules.slb"), |
| 38 | ("Dlg.slb", "toolboxmodules.slb"), |
| 39 | ("Evt.slb", "toolboxmodules.slb"), |
| 40 | ("Menu.slb", "toolboxmodules.slb"), |
Jack Jansen | ad16927 | 1995-08-14 12:20:22 +0000 | [diff] [blame] | 41 | ("List.slb", "toolboxmodules.slb"), |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 42 | ("Qd.slb", "toolboxmodules.slb"), |
| 43 | ("Res.slb", "toolboxmodules.slb"), |
| 44 | ("Snd.slb", "toolboxmodules.slb"), |
| 45 | ("Win.slb", "toolboxmodules.slb"), |
| 46 | ("imgcolormap.slb", "imgmodules.slb"), |
| 47 | ("imgformat.slb", "imgmodules.slb"), |
| 48 | ("imggif.slb", "imgmodules.slb"), |
| 49 | ("imgjpeg.slb", "imgmodules.slb"), |
| 50 | ("imgop.slb", "imgmodules.slb"), |
| 51 | ("imgpgm.slb", "imgmodules.slb"), |
| 52 | ("imgppm.slb", "imgmodules.slb"), |
| 53 | ("imgtiff.slb", "imgmodules.slb") |
| 54 | ] |
| 55 | |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 56 | |
| 57 | def main(): |
| 58 | # Ask the user for the plugins directory |
Jack Jansen | ad16927 | 1995-08-14 12:20:22 +0000 | [diff] [blame] | 59 | dir, ok = macfs.GetDirectory('Where is the PlugIns folder?') |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 60 | if not ok: sys.exit(0) |
| 61 | os.chdir(dir.as_pathname()) |
| 62 | |
| 63 | # Remove old .slb aliases and collect a list of .slb files |
| 64 | if EasyDialogs.AskYesNoCancel('Proceed with removing old aliases?') <= 0: |
| 65 | sys.exit(0) |
| 66 | LibFiles = [] |
| 67 | allfiles = os.listdir(':') |
| 68 | for f in allfiles: |
| 69 | if f[-4:] == '.slb': |
| 70 | finfo = macfs.FSSpec(f).GetFInfo() |
| 71 | if finfo.Flags & 0x8000: |
| 72 | os.unlink(f) |
| 73 | else: |
| 74 | LibFiles.append(f) |
| 75 | |
| 76 | print LibFiles |
| 77 | # Create the new aliases. |
| 78 | if EasyDialogs.AskYesNoCancel('Proceed with creating new ones?') <= 0: |
| 79 | sys.exit(0) |
| 80 | for dst, src in goals: |
| 81 | if src in LibFiles: |
Jack Jansen | ad16927 | 1995-08-14 12:20:22 +0000 | [diff] [blame] | 82 | macostools.mkalias(src, dst) |
Jack Jansen | d8eb8a7 | 1995-08-09 15:16:58 +0000 | [diff] [blame] | 83 | else: |
| 84 | EasyDialogs.Message(dst+' not created: '+src+' not found') |
| 85 | |
| 86 | EasyDialogs.Message('All done!') |
| 87 | |
| 88 | if __name__ == '__main__': |
| 89 | main() |