home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Python 1.4 / Python 1.4 source / Mac / scripts / MkPluginAliases.py < prev    next >
Encoding:
Text File  |  1996-10-22  |  5.6 KB  |  202 lines  |  [TEXT/Pyth]

  1. # This python script creates Finder aliases for all the
  2. # dynamically-loaded modules that "live in" in a single
  3. # shared library.
  4. #
  5. # This is sort-of a merger between Jack's MkPluginAliases
  6. # and Guido's mkaliases.
  7. #
  8. # Jack Jansen, CWI, August 1996
  9.  
  10. import sys
  11. import os
  12. import macfs
  13.  
  14. ppc_goals = [
  15.     ("AE.ppc.slb", "toolboxmodules.ppc.slb"),
  16.     ("Ctl.ppc.slb", "toolboxmodules.ppc.slb"),
  17.     ("Dlg.ppc.slb", "toolboxmodules.ppc.slb"),
  18.     ("Evt.ppc.slb", "toolboxmodules.ppc.slb"),
  19.     ("Fm.ppc.slb", "toolboxmodules.ppc.slb"),
  20.     ("Menu.ppc.slb", "toolboxmodules.ppc.slb"),
  21.     ("List.ppc.slb", "toolboxmodules.ppc.slb"),
  22.     ("Qd.ppc.slb", "toolboxmodules.ppc.slb"),
  23.     ("Res.ppc.slb", "toolboxmodules.ppc.slb"),
  24.     ("Scrap.ppc.slb", "toolboxmodules.ppc.slb"),
  25.     ("Snd.ppc.slb", "toolboxmodules.ppc.slb"),
  26.     ("TE.ppc.slb", "toolboxmodules.ppc.slb"),
  27.     ("Win.ppc.slb", "toolboxmodules.ppc.slb"),
  28.  
  29.     ("Cm.ppc.slb", "qtmodules.ppc.slb"),
  30.     ("Qt.ppc.slb", "qtmodules.ppc.slb"),
  31.  
  32.     ("imgcolormap.ppc.slb", "imgmodules.ppc.slb"),
  33.     ("imgformat.ppc.slb", "imgmodules.ppc.slb"),
  34.     ("imggif.ppc.slb", "imgmodules.ppc.slb"),
  35.     ("imgjpeg.ppc.slb", "imgmodules.ppc.slb"),
  36.     ("imgop.ppc.slb", "imgmodules.ppc.slb"),
  37.     ("imgpbm.ppc.slb", "imgmodules.ppc.slb"),
  38.     ("imgpgm.ppc.slb", "imgmodules.ppc.slb"),
  39.     ("imgppm.ppc.slb", "imgmodules.ppc.slb"),
  40.     ("imgtiff.ppc.slb", "imgmodules.ppc.slb"),
  41.     ("imgsgi.ppc.slb", "imgmodules.ppc.slb")
  42. ]
  43.  
  44. cfm68k_goals = [
  45.     ("AE.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
  46.     ("Ctl.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
  47.     ("Dlg.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
  48.     ("Evt.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
  49.     ("Fm.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
  50.     ("Menu.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
  51.     ("List.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
  52.     ("Qd.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
  53.     ("Res.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
  54.     ("Scrap.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
  55.     ("Snd.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
  56.     ("TE.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
  57.     ("Win.CFM68K.slb", "toolboxmodules.CFM68K.slb"),
  58.  
  59.     ("Cm.CFM68K.slb", "qtmodules.CFM68K.slb"),
  60.     ("Qt.CFM68K.slb", "qtmodules.CFM68K.slb"),
  61.  
  62.     ("imgcolormap.CFM68K.slb", "imgmodules.CFM68K.slb"),
  63.     ("imgformat.CFM68K.slb", "imgmodules.CFM68K.slb"),
  64.     ("imggif.CFM68K.slb", "imgmodules.CFM68K.slb"),
  65.     ("imgjpeg.CFM68K.slb", "imgmodules.CFM68K.slb"),
  66.     ("imgop.CFM68K.slb", "imgmodules.CFM68K.slb"),
  67.     ("imgpbm.CFM68K.slb", "imgmodules.CFM68K.slb"),
  68.     ("imgpgm.CFM68K.slb", "imgmodules.CFM68K.slb"),
  69.     ("imgppm.CFM68K.slb", "imgmodules.CFM68K.slb"),
  70.     ("imgtiff.CFM68K.slb", "imgmodules.CFM68K.slb"),
  71.     ("imgsgi.CFM68K.slb", "imgmodules.CFM68K.slb")
  72. ]
  73.  
  74. def gotopluginfolder():
  75.     """Go to the plugin folder, assuming we are somewhere in the Python tree"""
  76.     import os
  77.     
  78.     while not os.path.isdir(":Plugins"):
  79.         os.chdir("::")
  80.     os.chdir(":Plugins")
  81.     print "current directory is", os.getcwd()
  82.     
  83. def loadtoolboxmodules():
  84.     """Attempt to load the Res module"""
  85.     try:
  86.         import Res
  87.     except ImportError, arg:
  88.         err1 = arg
  89.         pass
  90.     else:
  91.         print 'imported Res the standard way.'
  92.         return
  93.     
  94.     # We cannot import it. First attempt to load the cfm68k version
  95.     import imp
  96.     try:
  97.         dummy = imp.load_dynamic('Res', 'toolboxmodules.CFM68K.slb')
  98.     except ImportError, arg:
  99.         err2 = arg
  100.         pass
  101.     else:
  102.         print 'Loaded Res from toolboxmodules.CFM68K.slb.'
  103.         return
  104.         
  105.     # Ok, try the ppc version
  106.     try:
  107.         dummy = imp.load_dynamic('Res', 'toolboxmodules.ppc.slb')
  108.     except ImportError, arg:
  109.         err3 = arg
  110.         pass
  111.     else:
  112.         print 'Loaded Res from toolboxmodules.ppc.slb.'
  113.         return
  114.     
  115.     # Tough luck....
  116.     print "I cannot import the Res module, nor load it from either of"
  117.     print "toolboxmodules shared libraries. The errors encountered were:"
  118.     print "import Res:", err1
  119.     print "load from toolboxmodules.CFM68K.slb:", err2
  120.     print "load from toolboxmodules.ppc.slb:", err3
  121.     sys.exit(1)
  122.     
  123. def getextensiondirfile(fname):
  124.     import macfs
  125.     import MACFS
  126.     vrefnum, dirid = macfs.FindFolder(MACFS.kOnSystemDisk, MACFS.kExtensionFolderType, 0)
  127.     fss = macfs.FSSpec((vrefnum, dirid, fname))
  128.     return fss.as_pathname()
  129.     
  130. def mkcorealias(src, altsrc):
  131.     import string
  132.     import macostools
  133.     version = string.split(sys.version)[0]
  134.     dst = getextensiondirfile(src+ ' ' + version)
  135.     if not os.path.exists(src):
  136.         if not os.path.exists(altsrc):
  137.             print '*', src, 'not found'
  138.             return 0
  139.         src = altsrc
  140.     try:
  141.         os.unlink(dst)
  142.     except os.error:
  143.         pass
  144.     macostools.mkalias(src, dst)
  145.     print ' ', dst, '->', src
  146.     return 1
  147.     
  148.  
  149. def main():
  150.     gotopluginfolder()
  151.     
  152.     loadtoolboxmodules()
  153.     
  154.     import macostools
  155.         
  156.     # Remove old .slb aliases and collect a list of .slb files
  157.     LibFiles = []
  158.     allfiles = os.listdir(':')
  159.     print 'Removing old aliases...'
  160.     for f in allfiles:
  161.         if f[-4:] == '.slb':
  162.             finfo = macfs.FSSpec(f).GetFInfo()
  163.             if finfo.Flags & 0x8000:
  164.                 print '  Removing', f
  165.                 os.unlink(f)
  166.             else:
  167.                 LibFiles.append(f)
  168.                 print '  Found', f
  169.     print
  170.     
  171.     # Create the new PPC aliases.
  172.     print 'Creating PPC aliases...'
  173.     for dst, src in ppc_goals:
  174.         if src in LibFiles:
  175.             macostools.mkalias(src, dst)
  176.             print ' ', dst, '->', src
  177.         else:
  178.             print '*', dst, 'not created:', src, 'not found'
  179.     print
  180.     
  181.     # Create the CFM68K aliases.
  182.     print 'Creating CFM68K aliases...'
  183.     for dst, src in cfm68k_goals:
  184.         if src in LibFiles:
  185.             macostools.mkalias(src, dst)
  186.             print ' ', dst, '->', src
  187.         else:
  188.             print '*', dst, 'not created:', src, 'not found'
  189.     print
  190.             
  191.     # Create the PythonCore alias(es)
  192.     print 'Creating PythonCore aliases in Extensions folder...'
  193.     os.chdir('::')
  194.     n = 0
  195.     n = n + mkcorealias('PythonCorePPC', ':build.macppc.shared:PythonCorePPC')
  196.     n = n + mkcorealias('PythonCoreCFM68K', ':build.mac68k.shared:PythonCoreCFM68K')
  197.     if n == 0:
  198.         sys.exit(1)
  199.             
  200. if __name__ == '__main__':
  201.     main()
  202.