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 | |
| 4 | # First, see if this is the Mac or UNIX |
| 5 | try: |
| 6 | import posix |
| 7 | os = posix |
| 8 | import path |
| 9 | except NameError: |
| 10 | import mac |
| 11 | os = mac |
| 12 | import macpath |
| 13 | path = macpath |
| 14 | |
| 15 | import sys |
| 16 | |
| 17 | exceptions = ['importall'] |
| 18 | |
| 19 | for dir in sys.path: |
| 20 | print 'Listing', dir |
| 21 | try: |
| 22 | names = os.listdir(dir) |
| 23 | except os.error: |
| 24 | print 'Can\'t list', dir |
| 25 | names = [] |
| 26 | names.sort() |
| 27 | for name in names: |
| 28 | head, tail = name[:-3], name[-3:] |
| 29 | if tail = '.py' and head not in exceptions: |
| 30 | s = 'import ' + head |
| 31 | print s |
| 32 | try: |
| 33 | exec(s + '\n') |
| 34 | except: |
| 35 | print 'Sorry:', sys.exc_type, sys.exc_value |