diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 3ff2e46e6..03adfca40 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,12 @@ +2005-05-30 Martin Hawlisch + * src/ArgHandler.py (handle_args) Exit if opening a file failed + * src/Errors.py: New exception type "FileVersionError" + * src/GrampsDbBase.py (version_supported): New method + * src/GrampsBSDDB.py (version_supported): New method + * src/gramps_main.py (read_file) catch FileVersionError; + (post_load): only load if version_supported() + * src/ReadGrdb.py (importData): only load if version_supported() + 2005-05-30 Matt Brubeck * src/DbPrompter.py: fix handling of spaces when creating a new file - use open instead of "touch" diff --git a/gramps2/src/ArgHandler.py b/gramps2/src/ArgHandler.py index 08e4dba86..8cade7600 100644 --- a/gramps2/src/ArgHandler.py +++ b/gramps2/src/ArgHandler.py @@ -304,6 +304,8 @@ class ArgHandler: # Add the file to the recent items RecentFiles.recent_files(filename,filetype) self.parent.build_recent_menu() + else: + os._exit(1) return if self.open: diff --git a/gramps2/src/Errors.py b/gramps2/src/Errors.py index 0763e555c..cc890f35f 100644 --- a/gramps2/src/Errors.py +++ b/gramps2/src/Errors.py @@ -90,3 +90,15 @@ class GConfSchemaError(Exception): def __str__(self): return self.value + +class FileVersionError(Exception): + """ + Error used to report that a file could not be read because + it is written in an unsupported version of the file format. + """ + def __init__(self,value): + Exception.__init__(self) + self.value = value + + def __str__(self): + return self.value diff --git a/gramps2/src/GrampsBSDDB.py b/gramps2/src/GrampsBSDDB.py index 1605d2828..4f49ba817 100644 --- a/gramps2/src/GrampsBSDDB.py +++ b/gramps2/src/GrampsBSDDB.py @@ -111,6 +111,9 @@ class GrampsBSDDB(GrampsDbBase): def get_media_cursor(self): return GrampsBSDDBCursor(self.media_map) + def version_supported(self): + return self.metadata.get('version',0) <= _DBVERSION + def need_upgrade(self): return not self.readonly and self.metadata.get('version',0) < _DBVERSION @@ -407,6 +410,7 @@ class GrampsBSDDB(GrampsDbBase): "Sponsored", "Foster", "Unknown", "Other", ] version = self.metadata.get('version',0) + if version < 2: self.upgrade_2(child_rel_notrans) if version < 3: diff --git a/gramps2/src/GrampsDbBase.py b/gramps2/src/GrampsDbBase.py index 618559e82..3e3b465f7 100644 --- a/gramps2/src/GrampsDbBase.py +++ b/gramps2/src/GrampsDbBase.py @@ -191,6 +191,10 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback): self.place2title = {} self.name_group = {} + def version_supported(self): + """ Returns True when the file has a supported version""" + return True + def need_upgrade(self): return False diff --git a/gramps2/src/ReadGrdb.py b/gramps2/src/ReadGrdb.py index 11e1cf44a..e3a001545 100644 --- a/gramps2/src/ReadGrdb.py +++ b/gramps2/src/ReadGrdb.py @@ -59,7 +59,16 @@ def importData(database, filename, callback=None,cl=0,use_trans=True): else: ErrorDialog(_("%s could not be opened") % filename) return - + if not other_database.version_supported(): + if cl: + print "Error: %s could not be opened.\n%s Exiting." % (filename,\ + _("The database version is not supported by this version of GRAMPS.\n"\ + "Please upgrade to the corresponding version or use XML for porting data between different database versions.")) + else: + ErrorDialog(_("%s could not be opened") % filename, + _("The Database version is not supported by this version of GRAMPS.")) + return + # Check for duplicate handles. At the moment we simply exit here, # before modifying any data. In the future we will need to handle # this better. diff --git a/gramps2/src/gramps_main.py b/gramps2/src/gramps_main.py index cc1972cfe..8ca3d0665 100755 --- a/gramps2/src/gramps_main.py +++ b/gramps2/src/gramps_main.py @@ -1291,7 +1291,7 @@ class Gramps(GrampsDBCallback.GrampsDBCallback): ErrorDialog(_('Cannot open database'), _('The database file specified could not be opened.')) return 0 - except ( IOError, OSError ), msg: + except ( IOError, OSError, Errors.FileVersionError), msg: ErrorDialog(_('Cannot open database'),str(msg)) return 0 except (db.DBAccessError,db.DBError), msg: @@ -1743,6 +1743,11 @@ class Gramps(GrampsDBCallback.GrampsDBCallback): gtk.main_iteration() def post_load(self,name,callback=None): + if not self.db.version_supported(): + raise Errors.FileVersionError( + "The database version is not supported by this version of GRAMPS.\n" + "Please upgrade to the corresponding version or use XML for porting data between different database versions.") + self.db.set_save_path(name) res = self.db.get_researcher() owner = GrampsCfg.get_researcher()