* 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
This commit is contained in:
Don Allingham
2005-07-12 04:08:37 +00:00
parent 051eaecfc3
commit 916a73ad0c
5 changed files with 195 additions and 1 deletions

View File

@@ -1,3 +1,10 @@
2005-07-11 Don Allingham <don@gramps-project.org>
* 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 <shura@gramps-project.org>
* src/plugins/GraphViz.py (GraphViz.__init__): Define nominal and
reduced margins; (write_report): Use nominal margin to compute

View File

@@ -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

View File

@@ -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

View File

@@ -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")
)

View File

@@ -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")
)