From 916a73ad0cc04da634e58ea2a3bfa05ccd4718d3 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Tue, 12 Jul 2005 04:08:37 +0000 Subject: [PATCH] * src/GrampsBSDDB.py: add repair_secondary task to rebuild secondary indices * src/GrampsDbBase.py: add repair_secondary task * src/plugins/Check.py: move to "Repair Database" category * src/plugins/Rebuild.py: new plugin to repair secondary indices svn: r4918 --- gramps2/ChangeLog | 7 +++ gramps2/src/GrampsBSDDB.py | 98 ++++++++++++++++++++++++++++++++++ gramps2/src/GrampsDbBase.py | 3 ++ gramps2/src/plugins/Check.py | 2 +- gramps2/src/plugins/Rebuild.py | 86 +++++++++++++++++++++++++++++ 5 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 gramps2/src/plugins/Rebuild.py diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 0545736e5..23d0c37ce 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,10 @@ +2005-07-11 Don Allingham + * src/GrampsBSDDB.py: add repair_secondary task to rebuild + secondary indices + * src/GrampsDbBase.py: add repair_secondary task + * src/plugins/Check.py: move to "Repair Database" category + * src/plugins/Rebuild.py: new plugin to repair secondary indices + 2005-07-11 Alex Roitman * src/plugins/GraphViz.py (GraphViz.__init__): Define nominal and reduced margins; (write_report): Use nominal margin to compute diff --git a/gramps2/src/GrampsBSDDB.py b/gramps2/src/GrampsBSDDB.py index fbc47caba..6fb169da9 100644 --- a/gramps2/src/GrampsBSDDB.py +++ b/gramps2/src/GrampsBSDDB.py @@ -131,6 +131,7 @@ class GrampsBSDDB(GrampsDbBase): self.env.open(os.path.dirname(name), flags) name = os.path.basename(name) + self.save_name = name self.family_map = self.dbopen(name, "family") self.place_map = self.dbopen(name, "places") @@ -205,6 +206,103 @@ class GrampsBSDDB(GrampsDbBase): self.genderStats = GenderStats(gstats) return 1 + def rebuild_secondary(self): + + # Repair secondary indices related to person_map + + self.id_trans.close() + self.surnames.close() + + self.id_trans = db.DB(self.env) + self.id_trans.set_flags(db.DB_DUP) + self.id_trans.open(self.save_name, "idtrans", db.DB_HASH, + flags=db.DB_CREATE) + self.id_trans.truncate() + + self.surnames = db.DB(self.env) + self.surnames.set_flags(db.DB_DUP) + self.surnames.open(self.save_name, "surnames", db.DB_HASH, + flags=db.DB_CREATE) + self.surnames.truncate() + + self.person_map.associate(self.surnames, find_surname, db.DB_CREATE) + self.person_map.associate(self.id_trans, find_idmap, db.DB_CREATE) + + for key in self.person_map.keys(): + self.person_map[key] = self.person_map[key] + + self.person_map.sync() + + # Repair secondary indices related to family_map + + self.fid_trans.close() + self.fid_trans = db.DB(self.env) + self.fid_trans.set_flags(db.DB_DUP) + self.fid_trans.open(self.save_name, "fidtrans", db.DB_HASH, + flags=db.DB_CREATE) + self.fid_trans.truncate() + self.family_map.associate(self.fid_trans, find_idmap, db.DB_CREATE) + + for key in self.family_map.keys(): + self.family_map[key] = self.family_map[key] + self.family_map.sync() + + # Repair secondary indices related to place_map + + self.pid_trans.close() + self.pid_trans = db.DB(self.env) + self.pid_trans.set_flags(db.DB_DUP) + self.pid_trans.open(self.save_name, "pidtrans", db.DB_HASH, + flags=db.DB_CREATE) + self.pid_trans.truncate() + self.place_map.associate(self.pid_trans, find_idmap, db.DB_CREATE) + + for key in self.place_map.keys(): + self.place_map[key] = self.place_map[key] + self.place_map.sync() + + # Repair secondary indices related to media_map + + self.oid_trans.close() + self.oid_trans = db.DB(self.env) + self.oid_trans.set_flags(db.DB_DUP) + self.oid_trans.open(self.save_name, "oidtrans", db.DB_HASH, + flags=db.DB_CREATE) + self.oid_trans.truncate() + self.media_map.associate(self.oid_trans, find_idmap, db.DB_CREATE) + + for key in self.media_map.keys(): + self.media_map[key] = self.media_map[key] + self.media_map.sync() + + # Repair secondary indices related to source_map + + self.sid_trans.close() + self.sid_trans = db.DB(self.env) + self.sid_trans.set_flags(db.DB_DUP) + self.sid_trans.open(self.save_name, "sidtrans", db.DB_HASH, + flags=db.DB_CREATE) + self.sid_trans.truncate() + self.source_map.associate(self.sid_trans, find_idmap, db.DB_CREATE) + + for key in self.source_map.keys(): + self.source_map[key] = self.source_map[key] + self.source_map.sync() + + # Repair secondary indices related to event_map + + self.eventnames.close() + self.eventnames = db.DB(self.env) + self.eventnames.set_flags(db.DB_DUP) + self.eventnames.open(self.save_name, "eventnames", db.DB_HASH, + flags=db.DB_CREATE) + self.eventnames.truncate() + self.event_map.associate(self.eventnames, find_eventname, db.DB_CREATE) + + for key in self.event_map.keys(): + self.event_map[key] = self.event_map[key] + self.event_map.sync() + def abort_changes(self): while self.undo(): pass diff --git a/gramps2/src/GrampsDbBase.py b/gramps2/src/GrampsDbBase.py index 932d0b14d..92ce806cc 100644 --- a/gramps2/src/GrampsDbBase.py +++ b/gramps2/src/GrampsDbBase.py @@ -191,6 +191,9 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback): self.place2title = {} self.name_group = {} + def rebuild_secondary(self): + pass + def version_supported(self): """ Returns True when the file has a supported version""" return True diff --git a/gramps2/src/plugins/Check.py b/gramps2/src/plugins/Check.py index 1ed2cdd5c..7949b30c2 100644 --- a/gramps2/src/plugins/Check.py +++ b/gramps2/src/plugins/Check.py @@ -727,6 +727,6 @@ from PluginMgr import register_tool register_tool( runTool, _("Check and repair database"), - category=_("Database Processing"), + category=_("Database Repair"), description=_("Checks the database for integrity problems, fixing the problems that it can") ) diff --git a/gramps2/src/plugins/Rebuild.py b/gramps2/src/plugins/Rebuild.py new file mode 100644 index 000000000..404bf2bdc --- /dev/null +++ b/gramps2/src/plugins/Rebuild.py @@ -0,0 +1,86 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2005 Donald N. Allingham +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +# $Id$ + +"Database Processing/Check and repair database" + +#------------------------------------------------------------------------- +# +# python modules +# +#------------------------------------------------------------------------- +import os +import cStringIO +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# gtk modules +# +#------------------------------------------------------------------------- +import gtk +import gtk.glade + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +import RelLib +import Utils +import const +from QuestionDialog import OkDialog + +#------------------------------------------------------------------------- +# +# runTool +# +#------------------------------------------------------------------------- +def runTool(database,active_person,callback,parent=None): + + try: + if database.readonly: + # TODO: split plugin in a check and repair part to support + # checking of a read only database + return + + database.disable_signals() + database.rebuild_secondary() + database.enable_signals() + OkDialog(_("Secondary indices rebuilt"), + _('All secondary indices have been rebuilt.')) + except: + import DisplayTrace + DisplayTrace.DisplayTrace() + +#------------------------------------------------------------------------ +# +# +# +#------------------------------------------------------------------------ +from PluginMgr import register_tool + +register_tool( + runTool, + _("Rebuild secondary indices"), + category=_("Database Repair"), + description=_("Rebuilds secondary indices") + )