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