Add a stub compat/_scon_dbm.py module and copy whichdb.whichdb() to
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Wed, 14 Apr 2010 04:38:34 +0000 (04:38 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Wed, 14 Apr 2010 04:38:34 +0000 (04:38 +0000)
dbm.whichdb() if necessary.

git-svn-id: http://scons.tigris.org/svn/scons/trunk@4783 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/MANIFEST.in
src/engine/SCons/compat/__init__.py
src/engine/SCons/compat/_scons_dbm.py [new file with mode: 0644]
src/script/sconsign.py

index 6ed0dd785e42546ba10e75b9f117cb69eecc3905..e6deb6dc57485f7773cecf4ee2ccc024474b991f 100644 (file)
@@ -4,6 +4,7 @@ SCons/Builder.py
 SCons/compat/__init__.py
 SCons/compat/_scons_builtins.py
 SCons/compat/_scons_collections.py
+SCons/compat/_scons_dbm.py
 SCons/compat/_scons_hashlib.py
 SCons/compat/_scons_io.py
 SCons/compat/_scons_itertools.py
index 67d47eedb62bbbe2e67a1b7fb98decfc04da7a7e..1792dc48a244685ac2e04766704c034f02b0e2b0 100644 (file)
@@ -65,13 +65,13 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 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:
@@ -139,6 +139,19 @@ else:
         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:
     fnmatch.filter
diff --git a/src/engine/SCons/compat/_scons_dbm.py b/src/engine/SCons/compat/_scons_dbm.py
new file mode 100644 (file)
index 0000000..edfe6fd
--- /dev/null
@@ -0,0 +1,45 @@
+#
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__doc__ = """
+dbm compatibility module for Python versions that don't have dbm.
+
+This does not not NOT (repeat, *NOT*) provide complete dbm functionality.
+It's just a stub on which to hang just enough pieces of dbm functionality
+that the whichdb.whichdb() implementstation in the various 2.X versions of
+Python won't blow up even if dbm wasn't compiled in.
+"""
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+class error(Exception):
+    pass
+
+def open(*args, **kw):
+    raise error()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
index e119a51f65a242ff2e4d353464db77c1ce208a1b..cfba945300361fbe7ce8180a78d15f557c1ff0ba 100644 (file)
@@ -172,12 +172,16 @@ sys.path = libs + sys.path
 # END STANDARD SCons SCRIPT HEADER
 ##############################################################################
 
-import cPickle
+import SCons.compat
+
+import dbm
 import imp
-import whichdb
+import pickle
 
 import SCons.SConsign
 
+# Monkey-patch in a whichdb()-like function so any use of dbm.whichdb()
+# can detect our internal .dblite format,
 def my_whichdb(filename):
     if filename[-7:] == ".dblite":
         return "SCons.dblite"
@@ -189,8 +193,8 @@ def my_whichdb(filename):
         pass
     return _orig_whichdb(filename)
 
-_orig_whichdb = whichdb.whichdb
-whichdb.whichdb = my_whichdb
+_orig_whichdb = dbm.whichdb
+dbm.whichdb = my_whichdb
 
 def my_import(mname):
     if '.' in mname:
@@ -383,7 +387,7 @@ class Do_SConsignDB:
                 return
         except KeyboardInterrupt:
             raise
-        except cPickle.UnpicklingError:
+        except pickle.UnpicklingError:
             sys.stderr.write("sconsign: ignoring invalid `%s' file `%s'\n" % (self.dbm_name, fname))
             return
         except Exception, e:
@@ -404,7 +408,7 @@ class Do_SConsignDB:
 
     def printentries(self, dir, val):
         print '=== ' + dir + ':'
-        printentries(cPickle.loads(val), dir)
+        printentries(pickle.loads(val), dir)
 
 def Do_SConsignDir(name):
     try:
@@ -416,7 +420,7 @@ def Do_SConsignDir(name):
         sconsign = SCons.SConsign.Dir(fp)
     except KeyboardInterrupt:
         raise
-    except cPickle.UnpicklingError:
+    except pickle.UnpicklingError:
         sys.stderr.write("sconsign: ignoring invalid .sconsign file `%s'\n" % (name))
         return
     except Exception, e:
@@ -497,7 +501,7 @@ if Do_Call:
         Do_Call(a)
 else:
     for a in args:
-        dbm_name = whichdb.whichdb(a)
+        dbm_name = dbm.whichdb(a)
         if dbm_name:
             Map_Module = {'SCons.dblite' : 'dblite'}
             dbm = my_import(dbm_name)