0002041: show dialog if db version too high; ask question to upgrade the db version

svn: r10535
This commit is contained in:
Doug Blank 2008-04-10 01:15:12 +00:00
parent ae80457fb7
commit dbf925c63e
3 changed files with 30 additions and 8 deletions

View File

@ -271,6 +271,11 @@ class DbLoader:
try: try:
self.dbstate.db.load(filename, self.uistate.pulse_progressbar, mode) self.dbstate.db.load(filename, self.uistate.pulse_progressbar, mode)
self.dbstate.db.set_save_path(filename) self.dbstate.db.set_save_path(filename)
except gen.db.FileVersionDeclineToUpgrade:
self.dbstate.no_database()
except gen.db.exceptions.FileVersionError, msg:
ErrorDialog( _("Cannot open database"), str(msg))
self.dbstate.no_database()
except OSError, msg: except OSError, msg:
ErrorDialog( ErrorDialog(
_("Could not open file: %s") % filename, str(msg)) _("Could not open file: %s") % filename, str(msg))
@ -281,8 +286,6 @@ class DbLoader:
_LOG.error("Failed to open database.", exc_info=True) _LOG.error("Failed to open database.", exc_info=True)
return True return True
def do_import(self, dialog, importer, filename): def do_import(self, dialog, importer, filename):
self.import_info = None self.import_info = None
dialog.destroy() dialog.destroy()

View File

@ -50,10 +50,11 @@ from gen.lib import (GenderStats, Person, Family, Event, Place, Source,
MediaObject, Repository, Note) MediaObject, Repository, Note)
from gen.db import (GrampsDbBase, KEY_TO_CLASS_MAP, CLASS_TO_KEY_MAP, from gen.db import (GrampsDbBase, KEY_TO_CLASS_MAP, CLASS_TO_KEY_MAP,
REFERENCE_KEY, Transaction) REFERENCE_KEY, Transaction)
from gen.db.exceptions import FileVersionError
from BasicUtils import UpdateCallback from BasicUtils import UpdateCallback
from gen.db.cursor import GrampsCursor from gen.db.cursor import GrampsCursor
from gen.db.exceptions import FileVersionError, FileVersionDeclineToUpgrade
import Errors import Errors
from QuestionDialog import QuestionDialog2
_MINVERSION = 9 _MINVERSION = 9
_DBVERSION = 14 _DBVERSION = 14
@ -505,6 +506,7 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
# it makes no sense to go further # it makes no sense to go further
if not self.version_supported(): if not self.version_supported():
self.__close_early() self.__close_early()
return 0
self.family_map = self.__open_table(self.full_name, FAMILY_TBL) self.family_map = self.__open_table(self.full_name, FAMILY_TBL)
self.place_map = self.__open_table(self.full_name, PLACES_TBL) self.place_map = self.__open_table(self.full_name, PLACES_TBL)
@ -554,7 +556,18 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
# self.secondary_connected flag should be set accordingly. # self.secondary_connected flag should be set accordingly.
if self.need_upgrade(): if self.need_upgrade():
self.gramps_upgrade(callback) if QuestionDialog2(_("Need to upgrade database!"),
_("You cannot open this database "
"without upgrading it.\n"
"If you upgrade then you won't be able "
"to use previous versions of GRAMPS.\n"
"You might want to make a backup copy "
"first."),
_("Upgrade now"),
_("Cancel")).run():
self.gramps_upgrade(callback)
else:
raise FileVersionDeclineToUpgrade()
if callback: if callback:
callback(50) callback(50)
@ -1198,10 +1211,10 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
self.env = None self.env = None
self.db_is_open = False self.db_is_open = False
raise FileVersionError( raise FileVersionError(
"The database version is not supported by this " _("The database version is not supported by this "
"version of GRAMPS.\nPlease upgrade to the " "version of GRAMPS.\nPlease upgrade to the "
"corresponding version or use XML for porting " "corresponding version or use XML for porting "
"data between different database versions.") "data between different database versions."))
def close(self): def close(self):
try: try:

View File

@ -58,3 +58,9 @@ class FileVersionError(Exception):
def __str__(self): def __str__(self):
return self.value return self.value
class FileVersionDeclineToUpgrade(Exception):
"""
Error raised when user decides not to upgrade a necessary upgrade.
"""
pass