cpython/Lib/importall.py

37 lines
806 B
Python
Raw Normal View History

# THIS IS OBSOLETE -- USE MODULE 'compileall' INSTEAD!
1991-08-16 10:28:28 -03:00
# Utility module to import all modules in the path, in the hope
# that this will update their ".pyc" files.
1992-03-31 15:06:54 -04:00
import os
1991-08-16 10:28:28 -03:00
import sys
# Sabotage 'gl' and 'stdwin' to prevent windows popping up...
for m in 'gl', 'stdwin', 'fl', 'fm':
sys.modules[m] = sys
1991-08-16 10:28:28 -03:00
exceptions = ['importall']
for dir in sys.path:
print 'Listing', dir
try:
names = os.listdir(dir)
except os.error:
print 'Can\'t list', dir
names = []
names.sort()
for name in names:
head, tail = name[:-3], name[-3:]
if tail == '.py' and head not in exceptions:
1991-08-16 10:28:28 -03:00
s = 'import ' + head
print s
try:
exec(s + '\n')
except KeyboardInterrupt:
del names[:]
print '\n[interrupt]'
break
1991-08-16 10:28:28 -03:00
except:
print 'Sorry:', sys.exc_type + ':',
print sys.exc_value