home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyth_os2.zip / python-1.0.2 / Lib / importall.py < prev    next >
Text File  |  1993-12-29  |  750b  |  35 lines

  1. # Utility module to import all modules in the path, in the hope
  2. # that this will update their ".pyc" files.
  3.  
  4. import os
  5. import sys
  6.  
  7. # Sabotage 'gl' and 'stdwin' to prevent windows popping up...
  8. for m in 'gl', 'stdwin', 'fl', 'fm':
  9.     sys.modules[m] = sys
  10.  
  11. exceptions = ['importall']
  12.  
  13. for dir in sys.path:
  14.     print 'Listing', dir
  15.     try:
  16.         names = os.listdir(dir)
  17.     except os.error:
  18.         print 'Can\'t list', dir
  19.         names = []
  20.     names.sort()
  21.     for name in names:
  22.         head, tail = name[:-3], name[-3:]
  23.         if tail == '.py' and head not in exceptions:
  24.             s = 'import ' + head
  25.             print s
  26.             try:
  27.                 exec(s + '\n')
  28.             except KeyboardInterrupt:
  29.                 del names[:]
  30.                 print '\n[interrupt]'
  31.                 break
  32.             except:
  33.                 print 'Sorry:', sys.exc_type + ':',
  34.                 print sys.exc_value
  35.