Method 'write_version' is created instead of loading the db after creation.

svn: r10484
This commit is contained in:
Zsolt Foldvari 2008-04-05 21:47:49 +00:00
parent e27422e243
commit 311278e6a8
2 changed files with 59 additions and 3 deletions

View File

@ -192,10 +192,9 @@ class CLIDbManager:
name_file.write(title)
name_file.close()
# open and close the db to write version number in metadata
# write the version number into metadata
newdb = gen.db.GrampsDBDir()
newdb.load(new_path, None)
newdb.close()
newdb.write_version(new_path)
self.current_names.append((title, new_path, path_name, _("Never"), 0,
False, ""))

View File

@ -104,6 +104,11 @@ def find_primary_handle(key, data):
def find_referenced_handle(key, data):
return str((data)[1][1])
#-------------------------------------------------------------------------
#
# GrampsDBDirCursor
#
#-------------------------------------------------------------------------
class GrampsDBDirCursor(GrampsCursor):
def __init__(self, source, txn=None):
@ -131,6 +136,11 @@ class GrampsDBDirCursor(GrampsCursor):
def get_length(self):
return self.source.stat()['ndata']
#-------------------------------------------------------------------------
#
# GrampsDBDirAssocCursor
#
#-------------------------------------------------------------------------
class GrampsDBDirAssocCursor(GrampsCursor):
def __init__(self, source, txn=None):
@ -158,6 +168,11 @@ class GrampsDBDirAssocCursor(GrampsCursor):
def get_length(self):
return self.source.stat()['ndata']
#-------------------------------------------------------------------------
#
# GrampsDBDirDupCursor
#
#-------------------------------------------------------------------------
class GrampsDBDirDupCursor(GrampsDBDirAssocCursor):
"""Cursor that includes handling for duplicate keys."""
@ -1701,7 +1716,49 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
the_txn = self.env.txn_begin()
self.metadata.put('version', 14, txn=the_txn)
the_txn.commit()
def write_version(self, name):
"""Write version number for a newly created DB."""
full_name = os.path.abspath(name)
self.env = db.DBEnv()
self.env.set_cachesize(0, 0x4000000) # 32MB
# These env settings are only needed for Txn environment
self.env.set_lk_max_locks(25000)
self.env.set_lk_max_objects(25000)
self.env.set_flags(db.DB_LOG_AUTOREMOVE, 1) # clean up unused logs
# The DB_PRIVATE flag must go if we ever move to multi-user setup
env_flags = db.DB_CREATE | db.DB_PRIVATE |\
db.DB_INIT_MPOOL | db.DB_INIT_LOCK |\
db.DB_INIT_LOG | db.DB_INIT_TXN | db.DB_THREAD
# As opposed to before, we always try recovery on databases
# in _GrampsBSDDB.py we only do that on existing filenames
env_flags = env_flags | db.DB_RECOVER
# Environment name is now based on the filename
env_name = name
self.env.open(env_name, env_flags)
self.env.txn_checkpoint()
self.metadata = self.__open_table(full_name, META)
the_txn = self.env.txn_begin()
self.metadata.put('version', _DBVERSION, txn=the_txn)
the_txn.commit()
self.metadata.close()
self.env.close()
#-------------------------------------------------------------------------
#
# BdbTransaction
#
#-------------------------------------------------------------------------
class BdbTransaction(Transaction):
def __init__(self, msg, db, batch=False, no_magic=False):
Transaction.__init__(self, msg, db, batch, no_magic)