From 8a690810fcfb578ca5682e6018e0fff07ed4417a Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Sat, 29 Nov 2008 12:53:00 +0000 Subject: [PATCH] Continued attempted fix for BSDDB new methods and attributes svn: r11360 --- src/gen/db/dbdir.py | 50 +++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/src/gen/db/dbdir.py b/src/gen/db/dbdir.py index 4e54ee775..ef5c1b5a0 100644 --- a/src/gen/db/dbdir.py +++ b/src/gen/db/dbdir.py @@ -483,17 +483,7 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback): self.env.set_lk_max_locks(25000) self.env.set_lk_max_objects(25000) - if sys.version_info < (2, 6): - if db.version() < (4, 7): - # Python 2.5 log settings - # clean up unused logs - self.env.set_flags(db.DB_LOG_AUTOREMOVE, 1) - else: - # Python 2.5.2, DB 4.7.25 uses set_flags, too - self.env.set_flags(db.DB_LOG_AUTO_REMOVE, 1) - else: - # Python 2.6 log settings (db version 4.7.25) - self.env.log_set_config(db.DB_LOG_AUTO_REMOVE, 1) + self.set_auto_remove() # The DB_PRIVATE flag must go if we ever move to multi-user setup env_flags = db.DB_CREATE | db.DB_PRIVATE |\ @@ -1905,6 +1895,30 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback): name_type, prefix, patronymic, group_as, sort_as, display_as, call) + def set_auto_remove(self): + """ + BSDDB change log settings using new method with renamed attributes + """ + if db.version() < (4, 7): + # by the book: old method with old attribute + self.env.set_flags(db.DB_LOG_AUTOREMOVE, 1) + else: # look at python interface + # TODO test with new version of pybsddb + try: + # try numeric compare, just first 2 digits + # this won't work with something like "4.10a", but + # hopefully they won't do that + old_version = map(int, db.__version__.split(".",2)[:2]) < (4, 7) + except: + # fallback, weak string compare + old_version = db.__version__ < "4.7" + if old_version: + # undocumented: old method with new attribute + self.env.set_flags(db.DB_LOG_AUTO_REMOVE, 1) + else: + # by the book: new method with new attribute + self.env.log_set_config(db.DB_LOG_AUTO_REMOVE, 1) + def write_version(self, name): """Write version number for a newly created DB.""" full_name = os.path.abspath(name) @@ -1915,17 +1929,9 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback): # These env settings are only needed for Txn environment self.env.set_lk_max_locks(25000) self.env.set_lk_max_objects(25000) - if sys.version_info < (2, 6): - if db.version() < (4, 7): - # Python 2.5 log settings - # clean up unused logs - self.env.set_flags(db.DB_LOG_AUTOREMOVE, 1) - else: - # Python 2.5.2, DB 4.7.25 uses set_flags, too - self.env.set_flags(db.DB_LOG_AUTO_REMOVE, 1) - else: - # Python 2.6 log settings (db version 4.7.25) - self.env.log_set_config(db.DB_LOG_AUTO_REMOVE, 1) + + # clean up unused logs + self.set_auto_remove() # The DB_PRIVATE flag must go if we ever move to multi-user setup env_flags = db.DB_CREATE | db.DB_PRIVATE |\