Remove write_version method from the database API

This is specific to the BSDDB backend.
This commit is contained in:
Nick Hall 2017-12-12 21:35:13 +00:00
parent 46eb72d002
commit efabb77567
9 changed files with 11 additions and 28 deletions

View File

@ -504,7 +504,6 @@ class ArgHandler:
self.imp_db_path = get_empty_tempdir("import_dbdir")
dbid = config.get('database.backend')
newdb = make_database(dbid)
newdb.write_version(self.imp_db_path)
try:
self.smgr.open_activate(self.imp_db_path, self.username, self.password)

View File

@ -68,6 +68,7 @@ _LOG = logging.getLogger(DBLOGNAME)
#-------------------------------------------------------------------------
DEFAULT_TITLE = _("Family Tree")
NAME_FILE = "name.txt"
BACKEND_FILE = "database.txt"
META_NAME = "meta_data.db"
#-------------------------------------------------------------------------
@ -306,8 +307,10 @@ class CLIDbManager:
if dbid is None:
dbid = config.get('database.backend')
newdb = make_database(dbid)
# write the version number into metadata
newdb.write_version(new_path)
backend_path = os.path.join(new_path, BACKEND_FILE)
with open(backend_path, "w", encoding='utf8') as backend_file:
backend_file.write(dbid)
(tval, last) = time_val(new_path)

View File

@ -1797,12 +1797,6 @@ class DbWriteBase(DbReadBase):
"""
raise NotImplementedError
def write_version(self, name):
"""
Write version number for a newly created DB.
"""
raise NotImplementedError
def add_child_to_family(self, family, child,
mrel=ChildRefType(),
frel=ChildRefType(),

View File

@ -60,7 +60,6 @@ class FileTest(unittest.TestCase):
# Create database
db = make_database("bsddb")
path = get_empty_tempdir("utils_file_test")
db.write_version(path)
db.load(path)
# Test without db.mediapath set

View File

@ -929,9 +929,6 @@ class DbManager(CLIDbManager, ManagedWindow):
fname = os.path.join(dirname, filename)
os.unlink(fname)
newdb = make_database("bsddb")
newdb.write_version(dirname)
dbase = make_database("bsddb")
dbase.load(dirname, None)

View File

@ -62,7 +62,6 @@ class TestEditReference(unittest.TestCase):
os.mkdir(path)
except:
pass
db.write_version(path)
db.load(path)
dbstate.change_database(db)
source = Place()

View File

@ -207,7 +207,6 @@ class DbTest(unittest.TestCase):
"set_name_group_mapping",
"transaction_begin",
"transaction_commit",
"write_version",
]
def _verify_readonly(self, db):

View File

@ -562,6 +562,11 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
self.path = self.full_name
self.brief_name = os.path.basename(name)
# We use the existence of the person table as a proxy for the database
# being new
if not os.path.exists(os.path.join(self.path, 'person.db')):
self._write_version(name)
# If we re-enter load with force_python_upgrade True, then we have
# already checked the bsddb version, and then checked python version,
# and are agreeing on the upgrade
@ -2200,7 +2205,7 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
else:
_LOG.debug("Failed to set autoremove flag")
def write_version(self, name):
def _write_version(self, name):
"""Write version number for a newly created DB."""
full_name = os.path.abspath(name)
@ -2258,11 +2263,6 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
version = str(_DBVERSION)
version_file.write(version)
versionpath = os.path.join(name, str(DBBACKEND))
_LOG.debug("Write database backend file to 'bsddb'")
with open(versionpath, "w") as version_file:
version_file.write("bsddb")
self.metadata.close()
self.env.close()

View File

@ -53,13 +53,6 @@ class DBAPI(DbGeneric):
"""
Database backends class for DB-API 2.0 databases
"""
def write_version(self, directory):
"""Write files for a newly created DB."""
versionpath = os.path.join(directory, str(DBBACKEND))
_LOG.debug("Write database backend file")
with open(versionpath, "w") as version_file:
version_file.write(self.__class__.__name__.lower())
def _initialize(self, directory, username, password):
raise NotImplementedError