Guido van Rossum | 7045dd0 | 1991-08-16 13:28:28 +0000 | [diff] [blame] | 1 | # Utility module to import all modules in the path, in the hope |
| 2 | # that this will update their ".pyc" files. |
| 3 | |
Guido van Rossum | bf1710a | 1992-03-31 19:06:54 +0000 | [diff] [blame] | 4 | import os |
Guido van Rossum | 7045dd0 | 1991-08-16 13:28:28 +0000 | [diff] [blame] | 5 | import sys |
| 6 | |
Guido van Rossum | d4e5a73 | 1992-01-01 19:30:14 +0000 | [diff] [blame] | 7 | # Sabotage 'gl' and 'stdwin' to prevent windows popping up... |
| 8 | for m in 'gl', 'stdwin', 'fl', 'fm': |
| 9 | sys.modules[m] = sys |
| 10 | |
Guido van Rossum | 7045dd0 | 1991-08-16 13:28:28 +0000 | [diff] [blame] | 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:] |
Guido van Rossum | d4e5a73 | 1992-01-01 19:30:14 +0000 | [diff] [blame] | 23 | if tail == '.py' and head not in exceptions: |
Guido van Rossum | 7045dd0 | 1991-08-16 13:28:28 +0000 | [diff] [blame] | 24 | s = 'import ' + head |
| 25 | print s |
| 26 | try: |
| 27 | exec(s + '\n') |
Guido van Rossum | d4e5a73 | 1992-01-01 19:30:14 +0000 | [diff] [blame] | 28 | except KeyboardInterrupt: |
| 29 | del names[:] |
| 30 | print '\n[interrupt]' |
| 31 | break |
Guido van Rossum | 7045dd0 | 1991-08-16 13:28:28 +0000 | [diff] [blame] | 32 | except: |
Guido van Rossum | d4e5a73 | 1992-01-01 19:30:14 +0000 | [diff] [blame] | 33 | print 'Sorry:', sys.exc_type + ':', |
| 34 | print sys.exc_value |