home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Mac / Tools / macfreeze / macmodulefinder.pyc (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2000-06-23  |  3.5 KB  |  103 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 1.5)
  3.  
  4. '''macmodulefinder - Find modules used in a script. Only slightly
  5. mac-specific, really.'''
  6. import sys
  7. import os
  8. import directives
  9.  
  10. try:
  11.     import modulefinder
  12. except ImportError:
  13.     _FREEZEDIR = os.path.join(sys.prefix, ':Tools:freeze')
  14.     sys.path.insert(0, _FREEZEDIR)
  15.     import modulefinder
  16.  
  17. MAC_INCLUDE_MODULES = [
  18.     'site',
  19.     'exceptions']
  20. MAC_MAYMISS_MODULES = [
  21.     'posix',
  22.     'os2',
  23.     'nt',
  24.     'ntpath',
  25.     'dos',
  26.     'dospath',
  27.     'win32api',
  28.     'nturl2path',
  29.     'pwd',
  30.     'sitecustomize']
  31. Missing = 'macmodulefinder.Missing'
  32.  
  33. class Module(modulefinder.Module):
  34.     
  35.     def gettype(self):
  36.         '''Return type of module'''
  37.         if self.__path__:
  38.             return 'package'
  39.         
  40.         if self.__code__:
  41.             return 'module'
  42.         
  43.         if self.__file__:
  44.             return 'dynamic'
  45.         
  46.         return 'builtin'
  47.  
  48.  
  49.  
  50. class ModuleFinder(modulefinder.ModuleFinder):
  51.     
  52.     def add_module(self, fqname):
  53.         if self.modules.has_key(fqname):
  54.             return self.modules[fqname]
  55.         
  56.         self.modules[fqname] = m = Module(fqname)
  57.         return m
  58.  
  59.  
  60.  
  61. def process(program, modules = [], module_files = [], debug = 0):
  62.     error = []
  63.     modules = modules + MAC_INCLUDE_MODULES
  64.     (extra_modules, exclude_modules, extra_path) = directives.findfreezedirectives(program)
  65.     for m in extra_modules:
  66.         pass
  67.     
  68.     path = sys.path[:]
  69.     dir = os.path.dirname(program)
  70.     path[0] = dir
  71.     path = extra_path + path
  72.     modfinder = ModuleFinder(path, excludes = exclude_modules, debug = debug)
  73.     for m in modules:
  74.         modfinder.import_hook(m)
  75.     
  76.     for m in module_files:
  77.         modfinder.load_file(m)
  78.     
  79.     modfinder.run_script(program)
  80.     module_dict = modfinder.modules
  81.     maymiss = exclude_modules + MAC_MAYMISS_MODULES
  82.     for m in modfinder.badmodules.keys():
  83.         pass
  84.     
  85.     for m in sys.builtin_module_names:
  86.         if m in ('__main__', '__builtin__'):
  87.             pass
  88.         elif not module_dict.has_key(m):
  89.             if debug > 0:
  90.                 print 'Unused', m
  91.             
  92.         elif module_dict[m].gettype() != 'builtin':
  93.             if debug > 0:
  94.                 print 'Conflict', m
  95.             
  96.         
  97.     
  98.     if error:
  99.         raise Missing, error
  100.     
  101.     return module_dict
  102.  
  103.