def import_as(module, name):
"""
Imports the specified module (from our local directory) as the
- specified name.
+ specified name, returning the loaded module object.
"""
import imp
import os.path
dir = os.path.split(__file__)[0]
file, filename, suffix_mode_type = imp.find_module(module, [dir])
- imp.load_module(name, file, filename, suffix_mode_type)
+ return imp.load_module(name, file, filename, suffix_mode_type)
try:
# Use the "imp" module to protect the import from fixers.
import imp
import sys
- __builtin__ = imp.load_module('__builtin__',
- *imp.find_module('__builtin__'))
- sys.modules['builtins'] = __builtin__
- del __builtin__
+ _builtin = imp.load_module('__builtin__',
+ *imp.find_module('__builtin__'))
+ sys.modules['builtins'] = _builtin
+ del _builtin
import _scons_builtins
# Pre-2.4 Python has no collections module.
import_as('_scons_collections', 'collections')
else:
+ # Use the "imp" module to protect the imports below from fixers.
+ import imp
try:
collections.UserDict
except AttributeError:
- import UserDict
- collections.UserDict = UserDict.UserDict
- del UserDict
+ _UserDict = imp.load_module('UserDict', *imp.find_module('UserDict'))
+ collections.UserDict = _UserDict.UserDict
+ del _UserDict
try:
collections.UserList
except AttributeError:
- import UserList
- collections.UserList = UserList.UserList
- del UserList
+ _UserList = imp.load_module('UserList', *imp.find_module('UserList'))
+ collections.UserList = _UserList.UserList
+ del _UserList
try:
collections.UserString
except AttributeError:
- import UserString
- collections.UserString = UserString.UserString
- del UserString
+ _UserString = imp.load_module('UserString',
+ *imp.find_module('UserString'))
+ collections.UserString = _UserString.UserString
+ del _UserString
+
+
+try:
+ import dbm
+except ImportError:
+ dbm = import_as('_scons_dbm', 'dbm')
+try:
+ dbm.whichdb
+except AttributeError:
+ # Pre-3.0 Python has no dbm.whichdb function.
+ import whichdb
+ dbm.whichdb = whichdb.whichdb
+ del whichdb
import fnmatch
try:
# Use the "imp" module to protect the import from fixers.
import imp
- cPickle = imp.load_module('cPickle', *imp.find_module('cPickle'))
+ _cPickle = imp.load_module('cPickle', *imp.find_module('cPickle'))
except ImportError, e:
# The "cPickle" module has already been eliminated in favor of
# having "import pickle" import the fast version when available.
pass
else:
import sys
- sys.modules['pickle'] = cPickle
- del cPickle
+ sys.modules['pickle'] = _cPickle
+ del _cPickle
try:
# Use the "imp" module to protect the import from fixers.
import imp
- cProfile = imp.load_module('cProfile', *imp.find_module('cProfile'))
+ _cProfile = imp.load_module('cProfile', *imp.find_module('cProfile'))
except ImportError:
# The "cProfile" module has already been eliminated in favor of
# having "import profile" import the fast version when available.
pass
else:
import sys
- sys.modules['profile'] = cProfile
- del cProfile
+ sys.modules['profile'] = _cProfile
+ del _cProfile
try:
except OSError:
if os.path.isdir(src):
if shutil.destinsrc(src, dst):
- raise Error, "Cannot move a directory '%s' into itself '%s'." % (src, dst)
+ raise Error("Cannot move a directory '%s' into itself '%s'." % (src, dst))
shutil.copytree(src, dst, symlinks=True)
shutil.rmtree(src)
else: