Mercurial > cpython-lru_cache-weakref
comparison Mac/scripts/ConfigurePython.py @ 2939:4dfdf234cda8 legacy-trunk
MkPluginAliases - Scripts (AppleScript and Python) to create aliases
to PPC plugin libraries
fixfiletypes.py - Script to recursively set mac creator/type based on
extension
| author | Jack Jansen <jack.jansen@cwi.nl> |
|---|---|
| date | Wed, 09 Aug 1995 15:16:58 +0000 |
| parents | |
| children | 7a67dbcb6d83 |
comparison
equal
deleted
inserted
replaced
| 2938:f017f5cdb4bd | 2939:4dfdf234cda8 |
|---|---|
| 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 | |
| 31 | |
| 32 goals = [ | |
| 33 ("mactcp.slb", "mactcpmodules.slb"), | |
| 34 ("macdnr.slb", "mactcpmodules.slb"), | |
| 35 ("AE.slb", "toolboxmodules.slb"), | |
| 36 ("Ctl.slb", "toolboxmodules.slb"), | |
| 37 ("Dlg.slb", "toolboxmodules.slb"), | |
| 38 ("Evt.slb", "toolboxmodules.slb"), | |
| 39 ("Menu.slb", "toolboxmodules.slb"), | |
| 40 ("Qd.slb", "toolboxmodules.slb"), | |
| 41 ("Res.slb", "toolboxmodules.slb"), | |
| 42 ("Snd.slb", "toolboxmodules.slb"), | |
| 43 ("Win.slb", "toolboxmodules.slb"), | |
| 44 ("imgcolormap.slb", "imgmodules.slb"), | |
| 45 ("imgformat.slb", "imgmodules.slb"), | |
| 46 ("imggif.slb", "imgmodules.slb"), | |
| 47 ("imgjpeg.slb", "imgmodules.slb"), | |
| 48 ("imgop.slb", "imgmodules.slb"), | |
| 49 ("imgpgm.slb", "imgmodules.slb"), | |
| 50 ("imgppm.slb", "imgmodules.slb"), | |
| 51 ("imgtiff.slb", "imgmodules.slb") | |
| 52 ] | |
| 53 | |
| 54 # | |
| 55 # Not guaranteed to be correct or stay correct (Apple doesn't tell you | |
| 56 # how to do this), but it seems to work. | |
| 57 # | |
| 58 def mkalias(src, dst): | |
| 59 """Create a finder alias""" | |
| 60 srcfss = macfs.FSSpec(src) | |
| 61 dstfss = macfs.FSSpec(dst) | |
| 62 alias = srcfss.NewAlias() | |
| 63 srcfinfo = srcfss.GetFInfo() | |
| 64 | |
| 65 Res.FSpCreateResFile(dstfss, srcfinfo.Creator, srcfinfo.Type, -1) | |
| 66 h = Res.FSpOpenResFile(dstfss, 3) | |
| 67 resource = Res.Resource(alias.data) | |
| 68 resource.AddResource('alis', 0, '') | |
| 69 Res.CloseResFile(h) | |
| 70 | |
| 71 dstfinfo = dstfss.GetFInfo() | |
| 72 dstfinfo.Flags = dstfinfo.Flags|0x8000 # Alias flag | |
| 73 dstfss.SetFInfo(dstfinfo) | |
| 74 | |
| 75 def main(): | |
| 76 # Ask the user for the plugins directory | |
| 77 dir, ok = macfs.GetDirectory() | |
| 78 if not ok: sys.exit(0) | |
| 79 os.chdir(dir.as_pathname()) | |
| 80 | |
| 81 # Remove old .slb aliases and collect a list of .slb files | |
| 82 if EasyDialogs.AskYesNoCancel('Proceed with removing old aliases?') <= 0: | |
| 83 sys.exit(0) | |
| 84 LibFiles = [] | |
| 85 allfiles = os.listdir(':') | |
| 86 for f in allfiles: | |
| 87 if f[-4:] == '.slb': | |
| 88 finfo = macfs.FSSpec(f).GetFInfo() | |
| 89 if finfo.Flags & 0x8000: | |
| 90 os.unlink(f) | |
| 91 else: | |
| 92 LibFiles.append(f) | |
| 93 | |
| 94 print LibFiles | |
| 95 # Create the new aliases. | |
| 96 if EasyDialogs.AskYesNoCancel('Proceed with creating new ones?') <= 0: | |
| 97 sys.exit(0) | |
| 98 for dst, src in goals: | |
| 99 if src in LibFiles: | |
| 100 mkalias(src, dst) | |
| 101 else: | |
| 102 EasyDialogs.Message(dst+' not created: '+src+' not found') | |
| 103 | |
| 104 EasyDialogs.Message('All done!') | |
| 105 | |
| 106 if __name__ == '__main__': | |
| 107 main() |
