From 76e590472fe522934db55f9dad6033ed58f9fa49 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Wed, 13 Jun 2007 22:48:28 +0000 Subject: [PATCH] 2007-06-13 Don Allingham * src/DbManager.py: handle broken dbs that have been opened * src/DbState.py: handle broken dbs that have been opened * src/GrampsDbUtils/_Backup.py: write intermediate file firs to make sure no errors occur when writing, then replace old backups * src/ViewManager.py: better rebuild recovery * src/GrampsDb/_GrampsDbConst.py: better rebuild recovery * src/GrampsDb/_GrampsDBCallback.py: better rebuild recovery * src/DbManager.py: better rebuild recovery * src/glade/gramps.glade: better rebuild recovery * src/const.py.in: better rebuild recovery * src/QuestionDialog.py: better rebuild recovery * src/GrampsDbUtils/_ReadGedcom.py: better rebuild recovery * src/ArgHandler.py: better rebuild recovery * src/DbLoader.py: better rebuild recovery 2007-06-12 Don Allingham svn: r8546 --- ChangeLog | 18 ++++++++++++++++++ src/DbManager.py | 9 +++++---- src/DbState.py | 1 + src/GrampsDbUtils/_Backup.py | 29 +++++++++++++++++++---------- 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index ec6558443..afa701d9b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-06-13 Don Allingham + * src/DbManager.py: handle broken dbs that have been opened + * src/DbState.py: handle broken dbs that have been opened + * src/GrampsDbUtils/_Backup.py: write intermediate file firs to make + sure no errors occur when writing, then replace old backups + 2007-06-13 Brian Matherly * src/plugins/GraphViz.py: Improve tooltip for latin-1 option. @@ -15,6 +21,18 @@ * src/plugins/DetAncestralReport.py: Enhance the source endnotes in some text reports. +2007-06-12 Don Allingham + * src/ViewManager.py: better rebuild recovery + * src/GrampsDb/_GrampsDbConst.py: better rebuild recovery + * src/GrampsDb/_GrampsDBCallback.py: better rebuild recovery + * src/DbManager.py: better rebuild recovery + * src/glade/gramps.glade: better rebuild recovery + * src/const.py.in: better rebuild recovery + * src/QuestionDialog.py: better rebuild recovery + * src/GrampsDbUtils/_ReadGedcom.py: better rebuild recovery + * src/ArgHandler.py: better rebuild recovery + * src/DbLoader.py: better rebuild recovery + 2007-06-12 Don Allingham * src/ViewManager.py: detection and recovery from db errors * src/GrampsDb/_GrampsDBDir.py: detection and recovery from db errors diff --git a/src/DbManager.py b/src/DbManager.py index 2176aadd0..5fbcdbb75 100644 --- a/src/DbManager.py +++ b/src/DbManager.py @@ -239,7 +239,8 @@ class DbManager: name = file(path_name).readline().strip() (tval, last) = time_val(dirpath) - (enable, stock_id) = icon_values(dirpath, self.active) + (enable, stock_id) = icon_values(dirpath, self.active, + self.dbstate.db.is_open()) self.current_names.append( (name, os.path.join(DEFAULT_DIR, dpath), path_name, @@ -444,15 +445,15 @@ def time_val(dirpath): last = _("Never") return (tval, last) -def icon_values(dirpath, active): +def icon_values(dirpath, active, open): """ If the directory path is the active path, then return values that indicate to use the icon, and which icon to use. """ - if dirpath == active: - return (True, gtk.STOCK_OPEN) if os.path.isfile(os.path.join(dirpath,"need_recover")): return (True, gtk.STOCK_DIALOG_ERROR) + elif dirpath == active and open: + return (True, gtk.STOCK_OPEN) else: return (False, "") diff --git a/src/DbState.py b/src/DbState.py index 213f3fdf3..59932c682 100644 --- a/src/DbState.py +++ b/src/DbState.py @@ -114,6 +114,7 @@ class DbState(GrampsDBCallback): """ self.db.close() self.db = GrampsDbBase() + self.db.db_is_open = False self.active = None self.open = False self.emit('database-changed', (self.db, )) diff --git a/src/GrampsDbUtils/_Backup.py b/src/GrampsDbUtils/_Backup.py index 4fb179673..035359958 100644 --- a/src/GrampsDbUtils/_Backup.py +++ b/src/GrampsDbUtils/_Backup.py @@ -72,17 +72,26 @@ def __do_export(database): @param database: database instance to backup @type database: GrampsDbDir """ - for (base, tbl) in __build_tbl_map(database): - backup_name = os.path.join(database.get_save_path(), base + ".gbkp") - backup_table = open(backup_name, 'wb') + try: + for (base, tbl) in __build_tbl_map(database): + backup_name = os.path.join(database.get_save_path(), base + ".gbkp.new") + backup_table = open(backup_name, 'wb') - cursor = tbl.cursor() - data = cursor.first() - while data: - pickle.dump(data, backup_table, 2) - data = cursor.next() - cursor.close() - backup_table.close() + cursor = tbl.cursor() + data = cursor.first() + while data: + pickle.dump(data, backup_table, 2) + data = cursor.next() + cursor.close() + backup_table.close() + except (IOError,OSError): + return + + for (base, tbl) in __build_tbl_map(database): + new_name = os.path.join(database.get_save_path(), base + ".gbkp") + old_name = new_name + ".new" + os.unlink(new_name) + os.rename(old_name, new_name) def restore(database): """