2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2007-06-28 11:11:40 +05:30
|
|
|
# Copyright (C) 2000-2007 Donald N. Allingham
|
2008-05-19 00:54:28 +05:30
|
|
|
# Copyright (C) 2008 Brian G. Matherly
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
|
2004-01-18 07:29:30 +05:30
|
|
|
# $Id$
|
|
|
|
|
2008-01-29 13:10:35 +05:30
|
|
|
"""Tools/Database Repair/Check and Repair Database"""
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-06-16 10:27:25 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-06-16 21:19:17 +05:30
|
|
|
from __future__ import with_statement
|
2002-10-20 19:55:16 +05:30
|
|
|
import os
|
2003-04-16 11:55:38 +05:30
|
|
|
import cStringIO
|
2006-12-03 10:50:15 +05:30
|
|
|
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2009-01-31 16:59:44 +05:30
|
|
|
from gettext import ngettext
|
2003-06-16 10:27:25 +05:30
|
|
|
|
2006-03-05 10:01:24 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Set up logging
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger(".CheckRepair")
|
|
|
|
|
2003-06-16 10:27:25 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gtk modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
import gtk
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2004-08-22 07:11:53 +05:30
|
|
|
# GRAMPS modules
|
2003-06-16 10:27:25 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-10-08 22:11:39 +05:30
|
|
|
import gen.lib
|
2003-06-16 10:27:25 +05:30
|
|
|
import Utils
|
2009-06-19 20:53:58 +05:30
|
|
|
from gui.utils import ProgressMeter
|
2008-02-19 01:37:09 +05:30
|
|
|
#import const
|
2006-04-10 04:23:53 +05:30
|
|
|
import ManagedWindow
|
|
|
|
|
2008-10-02 09:32:10 +05:30
|
|
|
from PluginUtils import Tool
|
2003-06-16 10:27:25 +05:30
|
|
|
from QuestionDialog import OkDialog, MissingMediaDialog
|
2007-06-28 11:11:40 +05:30
|
|
|
from BasicUtils import name_displayer as _nd
|
2009-05-15 01:45:59 +05:30
|
|
|
from glade import Glade
|
2003-06-16 10:27:25 +05:30
|
|
|
|
2006-03-01 01:24:35 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Low Level repair
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def low_level(db):
|
|
|
|
"""
|
|
|
|
This is a low-level repair routine.
|
|
|
|
|
|
|
|
It is fixing DB inconsistencies such as duplicates.
|
2008-02-24 19:25:55 +05:30
|
|
|
Returns a (status, name) tuple.
|
2006-03-01 01:24:35 +05:30
|
|
|
The boolean status indicates the success of the procedure.
|
|
|
|
The name indicates the problematic table (empty if status is True).
|
|
|
|
"""
|
|
|
|
|
2007-12-15 03:48:19 +05:30
|
|
|
for the_map in [('Person', db.person_map),
|
|
|
|
('Family', db.family_map),
|
|
|
|
('Event', db.event_map),
|
|
|
|
('Place', db.place_map),
|
|
|
|
('Source', db.source_map),
|
|
|
|
('Media', db.media_map),
|
|
|
|
('Repository', db.repository_map),
|
|
|
|
('Note', db.note_map)]:
|
2006-03-01 01:24:35 +05:30
|
|
|
|
|
|
|
print "Low-level repair: table: %s" % the_map[0]
|
2009-08-15 20:07:14 +05:30
|
|
|
if _table_low_level(db, the_map[1]):
|
2006-03-01 01:24:35 +05:30
|
|
|
print "Done."
|
|
|
|
else:
|
|
|
|
print "Low-level repair: Problem with table: %s" % the_map[0]
|
2009-08-15 20:07:14 +05:30
|
|
|
return (False, the_map[0])
|
|
|
|
return (True, '')
|
2006-03-01 01:24:35 +05:30
|
|
|
|
|
|
|
|
|
|
|
def _table_low_level(db,table):
|
|
|
|
"""
|
|
|
|
Low level repair for a given db table.
|
|
|
|
"""
|
|
|
|
handle_list = table.keys()
|
2006-12-03 10:50:15 +05:30
|
|
|
dup_handles = set(
|
2006-03-01 01:24:35 +05:30
|
|
|
[ handle for handle in handle_list if handle_list.count(handle) > 1 ]
|
|
|
|
)
|
|
|
|
|
|
|
|
if not dup_handles:
|
2009-08-15 20:07:14 +05:30
|
|
|
print " No duplicates found for this table"
|
2006-03-01 01:24:35 +05:30
|
|
|
return True
|
|
|
|
|
2008-02-19 01:37:09 +05:30
|
|
|
# import gen.db
|
2009-09-01 00:12:29 +05:30
|
|
|
from gen.db import GrampsDBDirAssocCursor
|
|
|
|
table_cursor = GrampsDBDirAssocCursor(table)
|
2006-03-01 01:24:35 +05:30
|
|
|
for handle in dup_handles:
|
|
|
|
print " Duplicates found for handle: %s" % handle
|
|
|
|
try:
|
|
|
|
ret = table_cursor.set(handle)
|
|
|
|
except:
|
|
|
|
print " Failed setting initial cursor."
|
|
|
|
return False
|
|
|
|
|
|
|
|
for count in range(handle_list.count(handle)-1):
|
|
|
|
try:
|
|
|
|
table_cursor.delete()
|
2009-08-15 20:07:14 +05:30
|
|
|
print " Successfully deleted duplicate #%d" % (count+1)
|
2006-03-01 01:24:35 +05:30
|
|
|
except:
|
2009-08-15 20:07:14 +05:30
|
|
|
print " Failed deleting duplicate."
|
2006-03-01 01:24:35 +05:30
|
|
|
return False
|
|
|
|
|
|
|
|
try:
|
|
|
|
ret = table_cursor.next_dup()
|
|
|
|
except:
|
|
|
|
print " Failed moving the cursor."
|
|
|
|
return False
|
|
|
|
|
|
|
|
table_cursor.close()
|
|
|
|
table.sync()
|
|
|
|
return True
|
|
|
|
|
2003-06-16 10:27:25 +05:30
|
|
|
#-------------------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
2003-06-16 10:27:25 +05:30
|
|
|
# runTool
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-05-04 07:35:50 +05:30
|
|
|
class Check(Tool.BatchTool):
|
2006-04-10 04:23:53 +05:30
|
|
|
def __init__(self, dbstate, uistate, options_class, name, callback=None):
|
|
|
|
|
2006-05-04 07:35:50 +05:30
|
|
|
Tool.BatchTool.__init__(self, dbstate, options_class, name)
|
|
|
|
if self.fail:
|
|
|
|
return
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2008-06-16 20:31:46 +05:30
|
|
|
cli = uistate is None
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2006-04-10 04:23:53 +05:30
|
|
|
if self.db.readonly:
|
2006-03-05 10:01:24 +05:30
|
|
|
# TODO: split plugin in a check and repair part to support
|
|
|
|
# checking of a read only database
|
|
|
|
return
|
|
|
|
|
|
|
|
# The low-level repair is bypassing the transaction mechanism.
|
|
|
|
# As such, we run it before starting the transaction.
|
2007-12-15 03:48:19 +05:30
|
|
|
# We only do this for the dbdir backend.
|
|
|
|
if self.db.__class__.__name__ == 'GrampsDBDir':
|
2006-04-10 04:23:53 +05:30
|
|
|
low_level(self.db)
|
2005-05-11 19:34:47 +05:30
|
|
|
|
2009-08-15 20:07:14 +05:30
|
|
|
trans = self.db.transaction_begin("", batch=True)
|
2006-04-10 04:23:53 +05:30
|
|
|
self.db.disable_signals()
|
|
|
|
checker = CheckIntegrity(dbstate, uistate, trans)
|
2006-03-05 10:01:24 +05:30
|
|
|
checker.fix_encoding()
|
2009-03-10 01:22:17 +05:30
|
|
|
checker.check_dates()
|
2006-03-05 10:01:24 +05:30
|
|
|
checker.cleanup_missing_photos(cli)
|
2006-07-27 16:18:16 +05:30
|
|
|
checker.cleanup_deleted_name_formats()
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2006-03-05 10:01:24 +05:30
|
|
|
prev_total = -1
|
|
|
|
total = 0
|
2005-04-15 10:20:15 +05:30
|
|
|
|
2007-10-06 14:38:29 +05:30
|
|
|
#start with empty objects, broken links can be corrected below then
|
|
|
|
checker.cleanup_empty_objects()
|
2006-03-05 10:01:24 +05:30
|
|
|
while prev_total != total:
|
|
|
|
prev_total = total
|
2005-05-11 19:34:47 +05:30
|
|
|
|
2006-03-05 10:01:24 +05:30
|
|
|
checker.check_for_broken_family_links()
|
|
|
|
checker.check_parent_relationships()
|
|
|
|
checker.cleanup_empty_families(cli)
|
|
|
|
checker.cleanup_duplicate_spouses()
|
|
|
|
|
|
|
|
total = checker.family_errors()
|
|
|
|
|
|
|
|
checker.check_events()
|
2006-11-09 18:03:10 +05:30
|
|
|
checker.check_person_references()
|
2006-03-05 10:01:24 +05:30
|
|
|
checker.check_place_references()
|
|
|
|
checker.check_source_references()
|
2007-10-06 18:28:11 +05:30
|
|
|
checker.check_media_references()
|
2006-12-03 05:14:38 +05:30
|
|
|
checker.check_repo_references()
|
2007-12-15 03:48:19 +05:30
|
|
|
checker.check_note_references()
|
2006-04-10 04:23:53 +05:30
|
|
|
self.db.transaction_commit(trans, _("Check Integrity"))
|
|
|
|
self.db.enable_signals()
|
|
|
|
self.db.request_rebuild()
|
2006-03-05 10:01:24 +05:30
|
|
|
|
|
|
|
errs = checker.build_report(cli)
|
|
|
|
if errs:
|
2009-08-15 20:07:14 +05:30
|
|
|
Report(uistate, checker.text.getvalue(), cli)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-05-21 22:49:50 +05:30
|
|
|
class CheckIntegrity(object):
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-04-10 04:23:53 +05:30
|
|
|
def __init__(self, dbstate, uistate, trans):
|
|
|
|
self.db = dbstate.db
|
2004-05-13 09:48:47 +05:30
|
|
|
self.trans = trans
|
2002-10-20 19:55:16 +05:30
|
|
|
self.bad_photo = []
|
2003-05-14 08:16:59 +05:30
|
|
|
self.replaced_photo = []
|
|
|
|
self.removed_photo = []
|
2002-10-20 19:55:16 +05:30
|
|
|
self.empty_family = []
|
|
|
|
self.broken_links = []
|
2005-08-18 11:28:28 +05:30
|
|
|
self.duplicate_links = []
|
2002-10-20 19:55:16 +05:30
|
|
|
self.broken_parent_links = []
|
|
|
|
self.fam_rel = []
|
2005-04-01 15:29:18 +05:30
|
|
|
self.invalid_events = []
|
|
|
|
self.invalid_birth_events = []
|
|
|
|
self.invalid_death_events = []
|
2006-11-09 18:03:10 +05:30
|
|
|
self.invalid_person_references = []
|
2005-04-11 15:41:04 +05:30
|
|
|
self.invalid_place_references = []
|
2005-07-09 01:54:54 +05:30
|
|
|
self.invalid_source_references = []
|
2006-12-03 05:14:38 +05:30
|
|
|
self.invalid_repo_references = []
|
2007-10-06 18:28:11 +05:30
|
|
|
self.invalid_media_references = []
|
2007-12-15 03:48:19 +05:30
|
|
|
self.invalid_note_references = []
|
2009-03-10 01:22:17 +05:30
|
|
|
self.invalid_dates = []
|
2006-07-27 16:18:16 +05:30
|
|
|
self.removed_name_format = []
|
2007-10-06 14:38:29 +05:30
|
|
|
self.empty_objects = {'persons' : [],
|
|
|
|
'families': [],
|
|
|
|
'events' : [],
|
|
|
|
'sources' : [],
|
|
|
|
'media' : [],
|
|
|
|
'places' : [],
|
|
|
|
'repos' : [],
|
|
|
|
'notes' : [],
|
|
|
|
}
|
2009-06-19 20:53:58 +05:30
|
|
|
self.progress = ProgressMeter(_('Checking Database'),'')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-04-15 10:20:15 +05:30
|
|
|
def family_errors(self):
|
2006-04-13 21:46:00 +05:30
|
|
|
return len(self.broken_parent_links) + \
|
|
|
|
len(self.broken_links) + \
|
|
|
|
len(self.empty_family) + \
|
|
|
|
len(self.duplicate_links)
|
2005-08-18 11:28:28 +05:30
|
|
|
|
2006-07-27 16:18:16 +05:30
|
|
|
def cleanup_deleted_name_formats(self):
|
|
|
|
"""
|
2009-08-15 20:07:14 +05:30
|
|
|
Permanently remove deleted name formats from db.
|
2006-07-27 16:18:16 +05:30
|
|
|
|
|
|
|
When user deletes custom name format those are not removed only marked
|
|
|
|
as "inactive". This method does the cleanup of the name format table,
|
|
|
|
as well as fixes the display_as, sort_as values for each Name in the db.
|
|
|
|
|
|
|
|
"""
|
|
|
|
self.progress.set_pass(_('Looking for invalid name format references'),
|
|
|
|
self.db.get_number_of_people())
|
|
|
|
|
2009-08-15 20:07:14 +05:30
|
|
|
deleted_name_formats = [number for (number, name, fmt_str,act)
|
2006-07-27 16:18:16 +05:30
|
|
|
in self.db.name_formats if not act]
|
|
|
|
|
2006-07-31 16:38:44 +05:30
|
|
|
# remove the invalid references from all Name objects
|
2009-06-16 21:19:17 +05:30
|
|
|
for person_handle in self.db.get_person_handles():
|
2006-07-27 16:18:16 +05:30
|
|
|
person = self.db.get_person_from_handle(person_handle)
|
|
|
|
|
|
|
|
p_changed = False
|
|
|
|
name = person.get_primary_name()
|
|
|
|
if name.get_sort_as() in deleted_name_formats:
|
2007-10-08 22:11:39 +05:30
|
|
|
name.set_sort_as(gen.lib.Name.DEF)
|
2006-07-27 16:18:16 +05:30
|
|
|
p_changed = True
|
|
|
|
if name.get_display_as() in deleted_name_formats:
|
2007-10-08 22:11:39 +05:30
|
|
|
name.set_display_as(gen.lib.Name.DEF)
|
2006-07-27 16:18:16 +05:30
|
|
|
p_changed = True
|
|
|
|
if p_changed:
|
|
|
|
person.set_primary_name(name)
|
|
|
|
|
|
|
|
a_changed = False
|
|
|
|
name_list = []
|
|
|
|
for name in person.get_alternate_names():
|
|
|
|
if name.get_sort_as() in deleted_name_formats:
|
2007-10-08 22:11:39 +05:30
|
|
|
name.set_sort_as(gen.lib.Name.DEF)
|
2006-07-27 16:18:16 +05:30
|
|
|
a_changed = True
|
|
|
|
if name.get_display_as() in deleted_name_formats:
|
2007-10-08 22:11:39 +05:30
|
|
|
name.set_display_as(gen.lib.Name.DEF)
|
2006-07-27 16:18:16 +05:30
|
|
|
a_changed = True
|
|
|
|
name_list.append(name)
|
|
|
|
if a_changed:
|
|
|
|
person.set_alternate_names(name_list)
|
|
|
|
|
|
|
|
if p_changed or a_changed:
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_person(person, self.trans)
|
2006-07-27 16:18:16 +05:30
|
|
|
self.removed_name_format.append(person_handle)
|
|
|
|
|
|
|
|
self.progress.step()
|
2006-07-31 16:38:44 +05:30
|
|
|
|
|
|
|
# update the custom name name format table
|
|
|
|
for number in deleted_name_formats:
|
|
|
|
_nd.del_name_format(number)
|
|
|
|
self.db.name_formats = _nd.get_name_format(only_custom=True,
|
|
|
|
only_active=False)
|
2006-07-27 16:18:16 +05:30
|
|
|
|
2005-08-18 11:28:28 +05:30
|
|
|
def cleanup_duplicate_spouses(self):
|
|
|
|
|
|
|
|
self.progress.set_pass(_('Looking for duplicate spouses'),
|
|
|
|
self.db.get_number_of_people())
|
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
for handle in self.db.person_map.keys():
|
2006-03-01 01:24:35 +05:30
|
|
|
value = self.db.person_map[handle]
|
2007-10-08 22:11:39 +05:30
|
|
|
p = gen.lib.Person(value)
|
2005-08-18 11:28:28 +05:30
|
|
|
splist = p.get_family_handle_list()
|
2006-12-03 10:50:15 +05:30
|
|
|
if len(splist) != len(set(splist)):
|
2005-08-18 11:28:28 +05:30
|
|
|
new_list = []
|
|
|
|
for value in splist:
|
|
|
|
if value not in new_list:
|
|
|
|
new_list.append(value)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.duplicate_links.append((handle, value))
|
2005-08-18 11:28:28 +05:30
|
|
|
p.set_family_handle_list(new_list)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_person(p, self.trans)
|
2005-08-18 11:28:28 +05:30
|
|
|
self.progress.step()
|
2005-04-15 10:20:15 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
def fix_encoding(self):
|
|
|
|
self.progress.set_pass(_('Looking for character encoding errors'),
|
|
|
|
self.db.get_number_of_media_objects())
|
2009-06-16 21:19:17 +05:30
|
|
|
for handle in self.db.media_map.keys():
|
2006-03-01 01:24:35 +05:30
|
|
|
data = self.db.media_map[handle]
|
2008-05-26 01:25:47 +05:30
|
|
|
if not isinstance(data[2], unicode) or not isinstance(data[4], unicode):
|
2005-12-06 12:08:09 +05:30
|
|
|
obj = self.db.get_object_from_handle(handle)
|
|
|
|
obj.path = Utils.fix_encoding( obj.path)
|
|
|
|
obj.desc = Utils.fix_encoding( obj.desc)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_media_object(obj, self.trans)
|
2006-12-02 13:00:15 +05:30
|
|
|
# Once we are here, fix the mime string if not str
|
2008-05-26 01:25:47 +05:30
|
|
|
if not isinstance(data[3], str):
|
2006-12-03 05:14:38 +05:30
|
|
|
obj = self.db.get_object_from_handle(handle)
|
2006-12-02 13:00:15 +05:30
|
|
|
try:
|
2006-12-03 05:14:38 +05:30
|
|
|
if data[3] == str(data[3]):
|
|
|
|
obj.mime = str(data[3])
|
|
|
|
else:
|
|
|
|
obj.mime = ""
|
2006-12-02 13:00:15 +05:30
|
|
|
except:
|
2006-12-03 05:14:38 +05:30
|
|
|
obj.mime = ""
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_media_object(obj, self.trans)
|
2005-12-06 12:08:09 +05:30
|
|
|
self.progress.step()
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def check_for_broken_family_links(self):
|
2005-03-30 16:07:40 +05:30
|
|
|
# Check persons referenced by the family objects
|
2005-08-18 11:28:28 +05:30
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
fhandle_list = self.db.get_family_handles()
|
2005-08-18 11:28:28 +05:30
|
|
|
self.progress.set_pass(_('Looking for broken family links'),
|
2009-06-16 21:19:17 +05:30
|
|
|
len(fhandle_list) + self.db.get_number_of_people())
|
2005-08-18 11:28:28 +05:30
|
|
|
|
|
|
|
for family_handle in fhandle_list:
|
2004-08-20 03:05:16 +05:30
|
|
|
family = self.db.get_family_from_handle(family_handle)
|
2004-07-28 07:59:07 +05:30
|
|
|
father_handle = family.get_father_handle()
|
|
|
|
mother_handle = family.get_mother_handle()
|
|
|
|
if father_handle:
|
2004-08-07 10:46:57 +05:30
|
|
|
father = self.db.get_person_from_handle(father_handle)
|
2005-03-27 03:29:15 +05:30
|
|
|
if not father:
|
2005-03-30 16:07:40 +05:30
|
|
|
# The person referenced by the father handle does not exist in the database
|
2005-03-27 03:29:15 +05:30
|
|
|
family.set_father_handle(None)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_family(family, self.trans)
|
|
|
|
self.broken_parent_links.append((father_handle, family_handle))
|
2005-03-27 03:29:15 +05:30
|
|
|
father_handle = None
|
2004-07-28 07:59:07 +05:30
|
|
|
if mother_handle:
|
2004-08-07 10:46:57 +05:30
|
|
|
mother = self.db.get_person_from_handle(mother_handle)
|
2005-03-27 03:29:15 +05:30
|
|
|
if not mother:
|
2005-03-30 16:07:40 +05:30
|
|
|
# The person referenced by the mother handle does not exist in the database
|
2005-04-01 10:04:31 +05:30
|
|
|
family.set_mother_handle(None)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_family(family, self.trans)
|
|
|
|
self.broken_parent_links.append((mother_handle, family_handle))
|
2005-03-27 03:29:15 +05:30
|
|
|
mother_handle = None
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2009-04-09 01:11:22 +05:30
|
|
|
if father_handle and father and \
|
|
|
|
family_handle not in father.get_family_handle_list():
|
2005-03-30 16:07:40 +05:30
|
|
|
# The referenced father has no reference back to the family
|
2009-08-15 20:07:14 +05:30
|
|
|
self.broken_parent_links.append((father_handle, family_handle))
|
2004-07-28 07:59:07 +05:30
|
|
|
father.add_family_handle(family_handle)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_person(father, self.trans)
|
2009-04-09 01:11:22 +05:30
|
|
|
|
|
|
|
if mother_handle and mother and \
|
|
|
|
family_handle not in mother.get_family_handle_list():
|
2005-03-30 16:07:40 +05:30
|
|
|
# The referenced mother has no reference back to the family
|
2009-08-15 20:07:14 +05:30
|
|
|
self.broken_parent_links.append((mother_handle, family_handle))
|
2004-07-28 07:59:07 +05:30
|
|
|
mother.add_family_handle(family_handle)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_person(mother, self.trans)
|
2006-04-14 01:04:07 +05:30
|
|
|
for child_ref in family.get_child_ref_list():
|
|
|
|
child_handle = child_ref.ref
|
2004-08-07 10:46:57 +05:30
|
|
|
child = self.db.get_person_from_handle(child_handle)
|
2005-03-26 16:23:27 +05:30
|
|
|
if child:
|
2009-08-15 20:07:14 +05:30
|
|
|
if child_handle in [father_handle, mother_handle]:
|
2006-11-27 08:25:40 +05:30
|
|
|
# The child is one of the parents: impossible
|
|
|
|
# Remove such child from the family
|
|
|
|
family.remove_child_ref(child_ref)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_family(family, self.trans)
|
|
|
|
self.broken_links.append((child_handle, family_handle))
|
2006-11-27 08:25:40 +05:30
|
|
|
continue
|
2005-03-26 16:23:27 +05:30
|
|
|
if family_handle == child.get_main_parents_family_handle():
|
2006-06-08 09:56:48 +05:30
|
|
|
continue
|
|
|
|
if family_handle not in \
|
|
|
|
child.get_parent_family_handle_list():
|
|
|
|
# The referenced child has no reference to the family
|
2006-04-14 01:04:07 +05:30
|
|
|
family.remove_child_ref(child_ref)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_family(family, self.trans)
|
|
|
|
self.broken_links.append((child_handle, family_handle))
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2006-06-08 09:56:48 +05:30
|
|
|
# The person referenced by the child handle
|
|
|
|
# does not exist in the database
|
2006-04-14 01:04:07 +05:30
|
|
|
family.remove_child_ref(child_ref)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_family(family, self.trans)
|
|
|
|
self.broken_links.append((child_handle, family_handle))
|
2006-12-03 10:50:15 +05:30
|
|
|
|
|
|
|
new_ref_list = []
|
|
|
|
new_ref_handles = []
|
|
|
|
replace = False
|
|
|
|
for child_ref in family.get_child_ref_list():
|
|
|
|
child_handle = child_ref.ref
|
|
|
|
if child_handle in new_ref_handles:
|
|
|
|
replace = True
|
|
|
|
else:
|
|
|
|
new_ref_list.append(child_ref)
|
|
|
|
new_ref_handles.append(child_handle)
|
|
|
|
|
|
|
|
if replace:
|
|
|
|
family.set_child_ref_list(new_ref_list)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_family(family, self.trans)
|
2006-12-03 10:50:15 +05:30
|
|
|
|
2005-08-18 11:28:28 +05:30
|
|
|
self.progress.step()
|
|
|
|
|
2005-03-30 16:07:40 +05:30
|
|
|
# Check persons membership in referenced families
|
2009-06-16 21:19:17 +05:30
|
|
|
for person_handle in self.db.get_person_handles():
|
2005-03-30 16:07:40 +05:30
|
|
|
person = self.db.get_person_from_handle(person_handle)
|
2006-12-03 10:50:15 +05:30
|
|
|
|
|
|
|
phandle_list = person.get_parent_family_handle_list()
|
|
|
|
new_list = list(set(phandle_list))
|
|
|
|
if len(phandle_list) != len(new_list):
|
|
|
|
person.set_parent_family_handle_list(new_list)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_person(person, self.trans)
|
2006-12-03 10:50:15 +05:30
|
|
|
|
2006-06-08 09:56:48 +05:30
|
|
|
for par_family_handle in person.get_parent_family_handle_list():
|
|
|
|
family = self.db.get_family_from_handle(par_family_handle)
|
2005-04-11 02:51:58 +05:30
|
|
|
if not family:
|
2006-06-08 09:56:48 +05:30
|
|
|
person.remove_parent_family_handle(par_family_handle)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_person(person, self.trans)
|
2005-04-11 02:51:58 +05:30
|
|
|
continue
|
2006-06-08 09:56:48 +05:30
|
|
|
for child_handle in [child_ref.ref for child_ref
|
|
|
|
in family.get_child_ref_list()]:
|
2005-03-30 16:07:40 +05:30
|
|
|
if child_handle == person_handle:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
# Person is not a child in the referenced parent family
|
2006-06-08 09:56:48 +05:30
|
|
|
person.remove_parent_family_handle(par_family_handle)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_person(person, self.trans)
|
2005-03-30 16:07:40 +05:30
|
|
|
self.broken_links.append((person_handle,family_handle))
|
|
|
|
for family_handle in person.get_family_handle_list():
|
|
|
|
family = self.db.get_family_from_handle(family_handle)
|
|
|
|
if not family:
|
|
|
|
# The referenced family does not exist in database
|
|
|
|
person.remove_family_handle(family_handle)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_person(person, self.trans)
|
|
|
|
self.broken_links.append((person_handle, family_handle))
|
2005-03-30 16:07:40 +05:30
|
|
|
continue
|
|
|
|
if family.get_father_handle() == person_handle:
|
|
|
|
continue
|
|
|
|
if family.get_mother_handle() == person_handle:
|
|
|
|
continue
|
|
|
|
# The person is not a member of the referenced family
|
|
|
|
person.remove_family_handle(family_handle)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_person(person, self.trans)
|
|
|
|
self.broken_links.append((person_handle, family_handle))
|
2005-08-18 11:28:28 +05:30
|
|
|
self.progress.step()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2009-08-15 20:07:14 +05:30
|
|
|
def cleanup_missing_photos(self, cl=0):
|
2005-08-18 11:28:28 +05:30
|
|
|
|
|
|
|
self.progress.set_pass(_('Looking for unused objects'),
|
2009-06-16 21:19:17 +05:30
|
|
|
len(self.db.get_media_object_handles()))
|
2005-08-18 11:28:28 +05:30
|
|
|
|
2004-01-18 07:29:30 +05:30
|
|
|
missmedia_action = 0
|
2003-05-14 08:16:59 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def remove_clicked():
|
|
|
|
# File is lost => remove all references and the object itself
|
2005-03-24 22:47:01 +05:30
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
for handle in self.db.get_person_handles(sort_handles=False):
|
2005-03-24 22:47:01 +05:30
|
|
|
person = self.db.get_person_from_handle(handle)
|
|
|
|
if person.has_media_reference(ObjectId):
|
|
|
|
person.remove_media_references([ObjectId])
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_person(person, self.trans)
|
2005-03-24 22:47:01 +05:30
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
for handle in self.db.get_family_handles():
|
2005-03-24 22:47:01 +05:30
|
|
|
family = self.db.get_family_from_handle(handle)
|
|
|
|
if family.has_media_reference(ObjectId):
|
|
|
|
family.remove_media_references([ObjectId])
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_family(family, self.trans)
|
2004-04-17 00:45:02 +05:30
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
for handle in self.db.get_event_handles():
|
2005-03-24 22:47:01 +05:30
|
|
|
event = self.db.get_event_from_handle(handle)
|
|
|
|
if event.has_media_reference(ObjectId):
|
|
|
|
event.remove_media_references([ObjectId])
|
|
|
|
self.db.commit_event(event,self.trans)
|
2004-04-17 00:45:02 +05:30
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
for handle in self.db.get_source_handles():
|
2005-03-24 22:47:01 +05:30
|
|
|
source = self.db.get_source_from_handle(handle)
|
|
|
|
if source.has_media_reference(ObjectId):
|
|
|
|
source.remove_media_references([ObjectId])
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_source(source, self.trans)
|
2005-03-24 22:47:01 +05:30
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
for handle in self.db.get_place_handles():
|
2005-03-24 22:47:01 +05:30
|
|
|
place = self.db.get_place_from_handle(handle)
|
|
|
|
if place.has_media_reference(ObjectId):
|
|
|
|
place.remove_media_references([ObjectId])
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_place(place, self.trans)
|
2005-03-24 22:47:01 +05:30
|
|
|
|
2004-02-25 08:55:57 +05:30
|
|
|
self.removed_photo.append(ObjectId)
|
2004-05-13 09:48:47 +05:30
|
|
|
self.db.remove_object(ObjectId,self.trans)
|
2003-05-14 08:16:59 +05:30
|
|
|
|
|
|
|
def leave_clicked():
|
2004-04-17 00:45:02 +05:30
|
|
|
self.bad_photo.append(ObjectId)
|
2003-05-14 08:16:59 +05:30
|
|
|
|
|
|
|
def select_clicked():
|
|
|
|
# File is lost => select a file to replace the lost one
|
|
|
|
def fs_close_window(obj):
|
2004-04-17 00:45:02 +05:30
|
|
|
self.bad_photo.append(ObjectId)
|
2003-05-14 08:16:59 +05:30
|
|
|
|
|
|
|
def fs_ok_clicked(obj):
|
2009-02-24 10:11:23 +05:30
|
|
|
name = Utils.get_unicode_path(fs_top.get_filename())
|
2003-05-14 08:16:59 +05:30
|
|
|
if os.path.isfile(name):
|
2005-03-24 22:47:01 +05:30
|
|
|
obj = self.db.get_object_from_handle(ObjectId)
|
|
|
|
obj.set_path(name)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_media_object(obj, self.trans)
|
2004-04-17 00:45:02 +05:30
|
|
|
self.replaced_photo.append(ObjectId)
|
2003-05-14 08:16:59 +05:30
|
|
|
else:
|
2004-04-17 00:45:02 +05:30
|
|
|
self.bad_photo.append(ObjectId)
|
2003-05-14 08:16:59 +05:30
|
|
|
|
2009-05-15 23:42:10 +05:30
|
|
|
fs_top = gtk.FileChooserDialog("%s - GRAMPS" % _("Select file"),
|
|
|
|
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
|
|
|
|
gtk.STOCK_OK, gtk.RESPONSE_OK)
|
|
|
|
)
|
|
|
|
response = fs_top.run()
|
|
|
|
if response == gtk.RESPONSE_OK:
|
|
|
|
fs_ok_clicked(fs_top)
|
|
|
|
elif response == gtk.RESPONSE_CANCEL:
|
|
|
|
fs_close_window(fs_top)
|
2003-06-10 05:30:05 +05:30
|
|
|
fs_top.destroy()
|
2003-05-14 08:16:59 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
2004-04-17 00:45:02 +05:30
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
for ObjectId in self.db.get_media_object_handles():
|
2004-08-07 10:46:57 +05:30
|
|
|
obj = self.db.get_object_from_handle(ObjectId)
|
2008-02-18 19:36:41 +05:30
|
|
|
photo_name = Utils.media_path_full(self.db, obj.get_path())
|
2005-12-06 12:08:09 +05:30
|
|
|
if photo_name is not None and photo_name != "" and not Utils.find_file(photo_name):
|
2003-05-21 23:36:41 +05:30
|
|
|
if cl:
|
|
|
|
print "Warning: media file %s was not found." \
|
|
|
|
% os.path.basename(photo_name)
|
2004-04-17 00:45:02 +05:30
|
|
|
self.bad_photo.append(ObjectId)
|
2003-05-21 23:36:41 +05:30
|
|
|
else:
|
2004-01-18 07:29:30 +05:30
|
|
|
if missmedia_action == 0:
|
|
|
|
mmd = MissingMediaDialog(_("Media object could not be found"),
|
2005-03-24 22:47:01 +05:30
|
|
|
_("The file:\n %(file_name)s \nis referenced in the database, but no longer exists. "
|
2003-05-21 23:36:41 +05:30
|
|
|
"The file may have been deleted or moved to a different location. "
|
|
|
|
"You may choose to either remove the reference from the database, "
|
|
|
|
"keep the reference to the missing file, or select a new file."
|
2005-03-24 22:47:01 +05:30
|
|
|
) % { 'file_name' : '<b>%s</b>' % photo_name },
|
2004-01-18 07:29:30 +05:30
|
|
|
remove_clicked, leave_clicked, select_clicked)
|
|
|
|
missmedia_action = mmd.default_action
|
|
|
|
elif missmedia_action == 1:
|
|
|
|
remove_clicked()
|
|
|
|
elif missmedia_action == 2:
|
|
|
|
leave_clicked()
|
|
|
|
elif missmedia_action == 3:
|
|
|
|
select_clicked()
|
2005-08-18 11:28:28 +05:30
|
|
|
self.progress.step()
|
2007-10-06 14:38:29 +05:30
|
|
|
|
|
|
|
def cleanup_empty_objects(self):
|
|
|
|
#the position of the change column in the primary objects
|
|
|
|
CHANGE_PERSON = 17
|
|
|
|
CHANGE_FAMILY = 12
|
|
|
|
CHANGE_EVENT = 10
|
|
|
|
CHANGE_SOURCE = 8
|
|
|
|
CHANGE_PLACE = 11
|
|
|
|
CHANGE_MEDIA = 8
|
|
|
|
CHANGE_REPOS = 7
|
|
|
|
CHANGE_NOTE = 5
|
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
empty_person_data = gen.lib.Person().serialize()
|
|
|
|
empty_family_data = gen.lib.Family().serialize()
|
|
|
|
empty_event_data = gen.lib.Event().serialize()
|
|
|
|
empty_source_data = gen.lib.Source().serialize()
|
|
|
|
empty_place_data = gen.lib.Place().serialize()
|
|
|
|
empty_media_data = gen.lib.MediaObject().serialize()
|
|
|
|
empty_repos_data = gen.lib.Repository().serialize()
|
|
|
|
empty_note_data = gen.lib.Note().serialize()
|
2007-10-06 14:38:29 +05:30
|
|
|
|
|
|
|
tables = {
|
|
|
|
'persons' : {'get_func': self.db.get_person_from_handle,
|
|
|
|
'cursor_func': self.db.get_person_cursor,
|
|
|
|
'total_func' : self.db.get_number_of_people,
|
|
|
|
'progress' : _('Looking for empty people records'),
|
|
|
|
'check_func' : lambda x : self._check_empty(x,
|
|
|
|
empty_person_data,
|
|
|
|
CHANGE_PERSON),
|
|
|
|
'remove' : self.db.remove_person},
|
|
|
|
'families': {'get_func': self.db.get_family_from_handle,
|
|
|
|
'cursor_func': self.db.get_family_cursor,
|
|
|
|
'total_func' : self.db.get_number_of_families,
|
|
|
|
'progress' : _('Looking for empty family records'),
|
|
|
|
'check_func' : lambda x : self._check_empty(x,
|
|
|
|
empty_family_data,
|
|
|
|
CHANGE_FAMILY),
|
|
|
|
'remove' : self.db.remove_family},
|
|
|
|
'events' : {'get_func': self.db.get_event_from_handle,
|
|
|
|
'cursor_func': self.db.get_event_cursor,
|
|
|
|
'total_func' : self.db.get_number_of_events,
|
|
|
|
'progress' : _('Looking for empty event records'),
|
|
|
|
'check_func' : lambda x : self._check_empty(x,
|
|
|
|
empty_event_data,
|
|
|
|
CHANGE_EVENT),
|
|
|
|
'remove' : self.db.remove_event},
|
|
|
|
'sources' : {'get_func': self.db.get_source_from_handle,
|
|
|
|
'cursor_func': self.db.get_source_cursor,
|
|
|
|
'total_func' : self.db.get_number_of_sources,
|
|
|
|
'progress' : _('Looking for empty source records'),
|
|
|
|
'check_func' : lambda x : self._check_empty(x,
|
|
|
|
empty_source_data,
|
|
|
|
CHANGE_SOURCE),
|
|
|
|
'remove' : self.db.remove_source},
|
|
|
|
'places' : {'get_func': self.db.get_place_from_handle,
|
|
|
|
'cursor_func': self.db.get_place_cursor,
|
|
|
|
'total_func' : self.db.get_number_of_places,
|
|
|
|
'progress' : _('Looking for empty place records'),
|
|
|
|
'check_func' : lambda x : self._check_empty(x,
|
|
|
|
empty_place_data,
|
|
|
|
CHANGE_PLACE),
|
|
|
|
'remove' : self.db.remove_place},
|
|
|
|
'media' : {'get_func': self.db.get_object_from_handle,
|
|
|
|
'cursor_func': self.db.get_media_cursor,
|
|
|
|
'progress' : _('Looking for empty media records'),
|
|
|
|
'total_func' : self.db.get_number_of_media_objects,
|
|
|
|
'check_func' : lambda x : self._check_empty(x,
|
|
|
|
empty_media_data,
|
|
|
|
CHANGE_MEDIA),
|
|
|
|
'remove' : self.db.remove_object},
|
|
|
|
'repos' : {'get_func': self.db.get_repository_from_handle,
|
|
|
|
'cursor_func': self.db.get_repository_cursor,
|
|
|
|
'total_func' : self.db.get_number_of_repositories,
|
|
|
|
'progress' : _('Looking for empty repository records'),
|
|
|
|
'check_func' : lambda x : self._check_empty(x,
|
|
|
|
empty_repos_data,
|
|
|
|
CHANGE_REPOS),
|
|
|
|
'remove' : self.db.remove_repository},
|
|
|
|
'notes' : {'get_func': self.db.get_note_from_handle,
|
|
|
|
'cursor_func': self.db.get_note_cursor,
|
|
|
|
'total_func' : self.db.get_number_of_notes,
|
|
|
|
'progress' : _('Looking for empty note records'),
|
|
|
|
'check_func' : lambda x : self._check_empty(x,
|
|
|
|
empty_note_data,
|
|
|
|
CHANGE_NOTE),
|
|
|
|
'remove' : self.db.remove_note},
|
|
|
|
}
|
2009-04-09 01:11:22 +05:30
|
|
|
for the_type, the_func in tables.iteritems():
|
2009-06-16 21:19:17 +05:30
|
|
|
with the_func['cursor_func']() as cursor:
|
|
|
|
total = the_func['total_func']()
|
|
|
|
check = the_func['check_func']
|
|
|
|
remove_func = the_func['remove']
|
|
|
|
|
|
|
|
self.progress.set_pass(the_func['progress'],total)
|
|
|
|
for handle, data in cursor:
|
|
|
|
self.progress.step()
|
|
|
|
if check(data):
|
|
|
|
self.empty_objects[the_type].append(handle)
|
|
|
|
#we cannot remove here as that would destroy cursor
|
|
|
|
|
2007-10-06 14:38:29 +05:30
|
|
|
#now remove
|
|
|
|
for handle in self.empty_objects[the_type]:
|
|
|
|
remove_func(handle, self.trans)
|
|
|
|
|
|
|
|
def _check_empty(self, data, empty_data, changepos):
|
|
|
|
"""compare the data with the data of an empty object
|
|
|
|
change, handle and gramps_id are not compared """
|
|
|
|
if changepos is not None:
|
|
|
|
return (data[2:changepos] == empty_data[2:changepos] and
|
|
|
|
data[changepos+1:] == empty_data[changepos+1:]
|
|
|
|
)
|
|
|
|
else :
|
|
|
|
return data[2:] == empty_data[2:]
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2009-08-15 20:07:14 +05:30
|
|
|
def cleanup_empty_families(self, automatic):
|
2005-08-18 11:28:28 +05:30
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
fhandle_list = self.db.get_family_handles()
|
2005-08-18 11:28:28 +05:30
|
|
|
|
|
|
|
self.progress.set_pass(_('Looking for empty families'),
|
2009-06-16 21:19:17 +05:30
|
|
|
len(fhandle_list))
|
2005-08-18 11:28:28 +05:30
|
|
|
for family_handle in fhandle_list:
|
|
|
|
self.progress.step()
|
|
|
|
|
2004-08-20 03:05:16 +05:30
|
|
|
family = self.db.get_family_from_handle(family_handle)
|
2006-08-30 10:40:50 +05:30
|
|
|
family_id = family.get_gramps_id()
|
2005-05-11 19:34:47 +05:30
|
|
|
father_handle = family.get_father_handle()
|
|
|
|
mother_handle = family.get_mother_handle()
|
|
|
|
|
2006-09-13 08:27:45 +05:30
|
|
|
if not father_handle and not mother_handle and \
|
|
|
|
len(family.get_child_ref_list()) == 0:
|
2006-08-30 10:40:50 +05:30
|
|
|
self.empty_family.append(family_id)
|
2004-07-28 07:59:07 +05:30
|
|
|
self.delete_empty_family(family_handle)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2009-08-15 20:07:14 +05:30
|
|
|
def delete_empty_family(self, family_handle):
|
2009-06-16 21:19:17 +05:30
|
|
|
for key in self.db.get_person_handles(sort_handles=False):
|
2004-08-07 10:46:57 +05:30
|
|
|
child = self.db.get_person_from_handle(key)
|
2004-07-28 07:59:07 +05:30
|
|
|
child.remove_parent_family_handle(family_handle)
|
|
|
|
child.remove_family_handle(family_handle)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.remove_family(family_handle, self.trans)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def check_parent_relationships(self):
|
2007-09-26 13:40:19 +05:30
|
|
|
"""Repair father=female or mother=male in hetero families
|
|
|
|
"""
|
2005-08-18 11:28:28 +05:30
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
fhandle_list = self.db.get_family_handles()
|
2005-08-18 11:28:28 +05:30
|
|
|
self.progress.set_pass(_('Looking for broken parent relationships'),
|
2009-06-16 21:19:17 +05:30
|
|
|
len(fhandle_list))
|
2007-09-26 13:40:19 +05:30
|
|
|
|
2005-08-18 11:28:28 +05:30
|
|
|
for family_handle in fhandle_list:
|
2005-12-06 12:08:09 +05:30
|
|
|
self.progress.step()
|
2005-03-26 20:30:05 +05:30
|
|
|
family = self.db.get_family_from_handle(family_handle)
|
2007-09-26 13:40:19 +05:30
|
|
|
|
2004-07-28 07:59:07 +05:30
|
|
|
father_handle = family.get_father_handle()
|
|
|
|
if father_handle:
|
2007-09-26 13:40:19 +05:30
|
|
|
fgender = self.db.get_person_from_handle(father_handle
|
|
|
|
).get_gender()
|
|
|
|
else:
|
|
|
|
fgender = None
|
|
|
|
|
|
|
|
mother_handle = family.get_mother_handle()
|
2004-07-28 07:59:07 +05:30
|
|
|
if mother_handle:
|
2007-09-26 13:40:19 +05:30
|
|
|
mgender = self.db.get_person_from_handle(mother_handle
|
|
|
|
).get_gender()
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2007-09-26 13:40:19 +05:30
|
|
|
mgender = None
|
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if (fgender == gen.lib.Person.FEMALE \
|
|
|
|
or mgender == gen.lib.Person.MALE) \
|
2007-09-26 13:40:19 +05:30
|
|
|
and fgender != mgender:
|
|
|
|
# swap. note: (at most) one handle may be None
|
|
|
|
family.set_father_handle(mother_handle)
|
|
|
|
family.set_mother_handle(father_handle)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_family(family, self.trans)
|
2007-09-26 13:40:19 +05:30
|
|
|
self.fam_rel.append(family_handle)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-04-01 15:29:18 +05:30
|
|
|
def check_events(self):
|
2005-08-18 11:28:28 +05:30
|
|
|
self.progress.set_pass(_('Looking for event problems'),
|
|
|
|
self.db.get_number_of_people()
|
|
|
|
+self.db.get_number_of_families())
|
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
for key in self.db.get_person_handles(sort_handles=False):
|
2005-08-18 11:28:28 +05:30
|
|
|
self.progress.step()
|
|
|
|
|
2005-04-01 15:29:18 +05:30
|
|
|
person = self.db.get_person_from_handle(key)
|
2006-03-30 22:59:30 +05:30
|
|
|
birth_ref = person.get_birth_ref()
|
|
|
|
if birth_ref:
|
|
|
|
birth_handle = birth_ref.ref
|
2005-04-01 15:29:18 +05:30
|
|
|
birth = self.db.get_event_from_handle(birth_handle)
|
|
|
|
if not birth:
|
2005-08-18 11:28:28 +05:30
|
|
|
# The birth event referenced by the birth handle
|
|
|
|
# does not exist in the database
|
2006-03-30 22:59:30 +05:30
|
|
|
person.set_birth_ref(None)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_person(person, self.trans)
|
2005-04-01 15:29:18 +05:30
|
|
|
self.invalid_events.append(key)
|
|
|
|
else:
|
2007-10-08 22:11:39 +05:30
|
|
|
if int(birth.get_type()) != gen.lib.EventType.BIRTH:
|
2005-04-01 15:29:18 +05:30
|
|
|
# Birth event was not of the type "Birth"
|
2007-10-08 22:11:39 +05:30
|
|
|
birth.set_type(gen.lib.EventType(gen.lib.EventType.BIRTH))
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_event(birth, self.trans)
|
2005-04-01 15:29:18 +05:30
|
|
|
self.invalid_birth_events.append(key)
|
2006-03-30 22:59:30 +05:30
|
|
|
death_ref = person.get_death_ref()
|
|
|
|
if death_ref:
|
|
|
|
death_handle = death_ref.ref
|
2005-04-01 15:29:18 +05:30
|
|
|
death = self.db.get_event_from_handle(death_handle)
|
|
|
|
if not death:
|
2005-08-18 11:28:28 +05:30
|
|
|
# The death event referenced by the death handle
|
|
|
|
# does not exist in the database
|
2006-03-30 22:59:30 +05:30
|
|
|
person.set_death_ref(None)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_person(person, self.trans)
|
2005-04-01 15:29:18 +05:30
|
|
|
self.invalid_events.append(key)
|
|
|
|
else:
|
2007-10-08 22:11:39 +05:30
|
|
|
if int(death.get_type()) != gen.lib.EventType.DEATH:
|
2005-04-01 15:29:18 +05:30
|
|
|
# Death event was not of the type "Death"
|
2007-10-08 22:11:39 +05:30
|
|
|
death.set_type(gen.lib.EventType(gen.lib.EventType.DEATH))
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_event(death, self.trans)
|
2005-04-01 15:29:18 +05:30
|
|
|
self.invalid_death_events.append(key)
|
2005-08-18 11:28:28 +05:30
|
|
|
|
2006-03-30 22:59:30 +05:30
|
|
|
if person.get_event_ref_list():
|
|
|
|
for event_ref in person.get_event_ref_list():
|
|
|
|
event_handle = event_ref.ref
|
2005-04-01 15:29:18 +05:30
|
|
|
event = self.db.get_event_from_handle(event_handle)
|
|
|
|
if not event:
|
2005-08-18 11:28:28 +05:30
|
|
|
# The event referenced by the person
|
|
|
|
# does not exist in the database
|
2005-04-01 15:29:18 +05:30
|
|
|
#TODO: There is no better way?
|
2006-03-30 22:59:30 +05:30
|
|
|
person.get_event_ref_list().remove(event_ref)
|
2005-04-01 15:29:18 +05:30
|
|
|
self.db.commit_person(person,self.trans)
|
|
|
|
self.invalid_events.append(key)
|
2008-05-26 01:25:47 +05:30
|
|
|
elif not isinstance(person.get_event_ref_list(), list):
|
2005-08-18 11:28:28 +05:30
|
|
|
# event_list is None or other garbage
|
2006-03-30 22:59:30 +05:30
|
|
|
person.set_event_ref_list([])
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_person(person, self.trans)
|
2005-08-18 11:28:28 +05:30
|
|
|
self.invalid_events.append(key)
|
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
for key in self.db.get_family_handles():
|
2005-08-18 11:28:28 +05:30
|
|
|
self.progress.step()
|
|
|
|
family = self.db.get_family_from_handle(key)
|
2006-03-30 22:59:30 +05:30
|
|
|
if family.get_event_ref_list():
|
|
|
|
for event_ref in family.get_event_ref_list():
|
|
|
|
event_handle = event_ref.ref
|
2005-08-18 11:28:28 +05:30
|
|
|
event = self.db.get_event_from_handle(event_handle)
|
|
|
|
if not event:
|
|
|
|
# The event referenced by the family
|
|
|
|
# does not exist in the database
|
2007-02-10 04:46:57 +05:30
|
|
|
print family.gramps_id
|
|
|
|
nlist = [ x for x in family.get_event_ref_list() \
|
|
|
|
if x.ref != event_handle]
|
|
|
|
family.set_event_ref_list(nlist)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_family(family, self.trans)
|
2005-08-18 11:28:28 +05:30
|
|
|
self.invalid_events.append(key)
|
2008-05-26 01:25:47 +05:30
|
|
|
elif not isinstance(family.get_event_ref_list(), list):
|
2005-08-18 11:28:28 +05:30
|
|
|
# event_list is None or other garbage
|
2006-03-30 22:59:30 +05:30
|
|
|
family.set_event_ref_list([])
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_family(family, self.trans)
|
2005-08-18 11:28:28 +05:30
|
|
|
self.invalid_events.append(key)
|
2005-04-01 15:29:18 +05:30
|
|
|
|
2006-11-09 18:03:10 +05:30
|
|
|
def check_person_references(self):
|
2009-06-16 21:19:17 +05:30
|
|
|
plist = self.db.get_person_handles()
|
2006-11-09 18:03:10 +05:30
|
|
|
|
|
|
|
self.progress.set_pass(_('Looking for person reference problems'),
|
2009-06-16 21:19:17 +05:30
|
|
|
len(plist))
|
2006-11-09 18:03:10 +05:30
|
|
|
|
|
|
|
for key in plist:
|
|
|
|
person = self.db.get_person_from_handle(key)
|
|
|
|
for pref in person.get_person_ref_list():
|
|
|
|
p = self.db.get_person_from_handle( pref.ref)
|
|
|
|
if not p:
|
|
|
|
# The referenced person does not exist in the database
|
|
|
|
person.get_person_ref_list().remove(pref)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_person(person, self.trans)
|
2006-11-09 18:03:10 +05:30
|
|
|
self.invalid_person_references.append(key)
|
|
|
|
|
2009-03-10 01:22:17 +05:30
|
|
|
def check_dates(self):
|
|
|
|
"""
|
|
|
|
Fix issues in 3.1.0 upgrade: missed some dates on associated people
|
|
|
|
source dates.
|
|
|
|
"""
|
2009-06-16 21:19:17 +05:30
|
|
|
plist = self.db.get_person_handles()
|
2009-03-10 01:22:17 +05:30
|
|
|
self.progress.set_pass(_('Checking people for proper date formats'),
|
2009-06-16 21:19:17 +05:30
|
|
|
len(plist))
|
2009-03-10 01:22:17 +05:30
|
|
|
# First, decode all of a person:
|
|
|
|
for handle in plist:
|
|
|
|
need_to_fix = False
|
|
|
|
person = self.db.person_map[handle]
|
|
|
|
(phandle, # 0
|
|
|
|
gramps_id, # 1
|
|
|
|
gender, # 2
|
|
|
|
primary_name, # 3
|
|
|
|
alternate_names, # 4
|
|
|
|
death_ref_index, # 5
|
|
|
|
birth_ref_index, # 6
|
|
|
|
event_ref_list, # 7
|
|
|
|
family_list, # 8
|
|
|
|
parent_family_list, # 9
|
|
|
|
media_list, # 10
|
|
|
|
address_list, # 11
|
|
|
|
attribute_list, # 12
|
|
|
|
urls, # 13
|
|
|
|
lds_ord_list, # 14
|
|
|
|
psource_list, # 15
|
|
|
|
pnote_list, # 16
|
|
|
|
change, # 17
|
|
|
|
marker, # 18
|
|
|
|
pprivate, # 19
|
|
|
|
person_ref_list, # 20
|
|
|
|
) = person
|
|
|
|
# Take apart person reference list:
|
|
|
|
new_person_ref_list = []
|
|
|
|
for person_ref in person_ref_list:
|
|
|
|
(private, source_list, note_list, pref, rel) = person_ref
|
|
|
|
new_source_list = []
|
|
|
|
# Check dates to see if correct format:
|
|
|
|
for source in source_list:
|
|
|
|
(date, private, note_list, confidence, sref, page) = source
|
2009-03-10 18:26:16 +05:30
|
|
|
if date is None:
|
|
|
|
new_date = None
|
2009-03-10 01:22:17 +05:30
|
|
|
else:
|
2009-03-10 18:26:16 +05:30
|
|
|
if len(date) == 7:
|
|
|
|
# This is correct:
|
|
|
|
(calendar, modifier, quality, dateval, text, sortval,
|
|
|
|
newyear) = date
|
|
|
|
elif len(date) == 6:
|
|
|
|
# This is necessary to fix 3.1.0 bug:
|
|
|
|
(calendar, modifier, quality, dateval, text, sortval) = date
|
|
|
|
newyear = 0
|
|
|
|
need_to_fix = True
|
|
|
|
else:
|
|
|
|
# FIXME: What to do with an invalid date?
|
|
|
|
# Make a new one?
|
|
|
|
(calendar, modifier, quality, dateval, text, sortval,
|
|
|
|
newyear) = gen.lib.Date().serialize()
|
|
|
|
need_to_fix = True
|
|
|
|
# Put date back together:
|
|
|
|
new_date = (calendar, modifier, quality, dateval, text, sortval,
|
|
|
|
newyear)
|
2009-03-10 01:22:17 +05:30
|
|
|
# Put source_list together:
|
|
|
|
new_source_list.append((new_date, private, note_list, confidence, sref, page))
|
|
|
|
# Put new_person_ref together:
|
|
|
|
new_person_ref_list.append((private, new_source_list, note_list, pref, rel))
|
|
|
|
# Put person back together:
|
|
|
|
if need_to_fix:
|
|
|
|
new_person = (phandle, # 0
|
|
|
|
gramps_id, # 1
|
|
|
|
gender, # 2
|
|
|
|
primary_name, # 3
|
|
|
|
alternate_names, # 4
|
|
|
|
death_ref_index, # 5
|
|
|
|
birth_ref_index, # 6
|
|
|
|
event_ref_list, # 7
|
|
|
|
family_list, # 8
|
|
|
|
parent_family_list, # 9
|
|
|
|
media_list, # 10
|
|
|
|
address_list, # 11
|
|
|
|
attribute_list, # 12
|
|
|
|
urls, # 13
|
|
|
|
lds_ord_list, # 14
|
|
|
|
psource_list, # 15
|
|
|
|
pnote_list, # 16
|
|
|
|
change, # 17
|
|
|
|
marker, # 18
|
|
|
|
pprivate, # 19
|
|
|
|
new_person_ref_list, # 20
|
|
|
|
)
|
|
|
|
p = gen.lib.Person(new_person)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_person(p, self.trans)
|
2009-03-10 01:22:17 +05:30
|
|
|
self.invalid_dates.append(handle)
|
|
|
|
self.progress.step()
|
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
flist = self.db.get_family_handles()
|
2009-03-10 01:22:17 +05:30
|
|
|
self.progress.set_pass(_('Checking families for proper date formats'),
|
2009-06-16 21:19:17 +05:30
|
|
|
len(flist))
|
2009-03-10 01:22:17 +05:30
|
|
|
# First, decode all of a person:
|
|
|
|
for handle in flist:
|
|
|
|
need_to_fix = False
|
|
|
|
family = self.db.family_map[handle]
|
|
|
|
(fhandle, gramps_id, father_handle, mother_handle,
|
|
|
|
child_ref_list, the_type, event_ref_list, media_list,
|
|
|
|
attribute_list, lds_seal_list, source_list, note_list,
|
|
|
|
change, marker, private) = family
|
|
|
|
|
|
|
|
new_child_ref_list = []
|
|
|
|
for data in child_ref_list:
|
|
|
|
(private, source_list, note_list, ref, frel, mrel) = data
|
|
|
|
new_source_list = []
|
|
|
|
# Check dates to see if correct format:
|
|
|
|
for source in source_list:
|
|
|
|
(date, private, note_list, confidence, sref, page) = source
|
2009-03-10 17:55:17 +05:30
|
|
|
if date is None:
|
|
|
|
new_date = None
|
2009-03-10 01:22:17 +05:30
|
|
|
else:
|
2009-03-10 17:55:17 +05:30
|
|
|
if len(date) == 7:
|
|
|
|
# This is correct:
|
|
|
|
(calendar, modifier, quality, dateval, text, sortval,
|
|
|
|
newyear) = date
|
|
|
|
elif len(date) == 6:
|
|
|
|
# This is necessary to fix 3.1.0 bug:
|
|
|
|
(calendar, modifier, quality, dateval, text, sortval) = date
|
|
|
|
newyear = 0
|
|
|
|
need_to_fix = True
|
|
|
|
else:
|
|
|
|
# FIXME: What to do with an invalid date?
|
|
|
|
# Make a new one?
|
|
|
|
(calendar, modifier, quality, dateval, text, sortval,
|
|
|
|
newyear) = gen.lib.Date().serialize()
|
|
|
|
need_to_fix = True
|
|
|
|
# Put date back together:
|
|
|
|
new_date = (calendar, modifier, quality, dateval, text, sortval,
|
|
|
|
newyear)
|
2009-03-10 01:22:17 +05:30
|
|
|
# Put source_list together:
|
|
|
|
new_source_list.append((new_date, private, note_list, confidence, sref, page))
|
|
|
|
# Put child ref list together:
|
|
|
|
new_child_ref_list.append((private, new_source_list, note_list, ref, frel, mrel))
|
|
|
|
if need_to_fix:
|
|
|
|
new_family = (fhandle, gramps_id, father_handle, mother_handle,
|
|
|
|
new_child_ref_list, the_type, event_ref_list, media_list,
|
|
|
|
attribute_list, lds_seal_list, source_list, note_list,
|
|
|
|
change, marker, private)
|
|
|
|
f = gen.lib.Family()
|
|
|
|
f.unserialize(new_family)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_family(f, self.trans)
|
2009-03-10 01:22:17 +05:30
|
|
|
self.invalid_dates.append(handle)
|
|
|
|
self.progress.step()
|
|
|
|
|
2006-12-03 05:14:38 +05:30
|
|
|
def check_repo_references(self):
|
2009-06-16 21:19:17 +05:30
|
|
|
slist = self.db.get_source_handles()
|
2006-12-03 05:14:38 +05:30
|
|
|
|
|
|
|
self.progress.set_pass(_('Looking for repository reference problems'),
|
2009-06-16 21:19:17 +05:30
|
|
|
len(slist))
|
2006-12-03 05:14:38 +05:30
|
|
|
|
|
|
|
for key in slist:
|
|
|
|
source = self.db.get_source_from_handle(key)
|
|
|
|
for reporef in source.get_reporef_list():
|
|
|
|
r = self.db.get_repository_from_handle(reporef.ref)
|
|
|
|
if not r:
|
|
|
|
# The referenced repository does not exist in the database
|
|
|
|
source.get_reporef_list().remove(reporef)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_source(source, self.trans)
|
2006-12-03 05:14:38 +05:30
|
|
|
self.invalid_repo_references.append(key)
|
|
|
|
|
2005-04-11 15:41:04 +05:30
|
|
|
def check_place_references(self):
|
2009-06-16 21:19:17 +05:30
|
|
|
plist = self.db.get_person_handles()
|
|
|
|
flist = self.db.get_family_handles()
|
|
|
|
elist = self.db.get_event_handles()
|
2005-08-18 11:28:28 +05:30
|
|
|
self.progress.set_pass(_('Looking for place reference problems'),
|
2009-06-16 21:19:17 +05:30
|
|
|
len(elist)+len(plist)+len(flist))
|
2006-11-20 20:56:38 +05:30
|
|
|
# check persons -> the LdsOrd references a place
|
|
|
|
for key in plist:
|
|
|
|
person = self.db.get_person_from_handle(key)
|
|
|
|
for ordinance in person.lds_ord_list:
|
|
|
|
place_handle = ordinance.get_place_handle()
|
|
|
|
if place_handle:
|
|
|
|
place = self.db.get_place_from_handle(place_handle)
|
|
|
|
if not place:
|
|
|
|
# The referenced place does not exist in the database
|
|
|
|
ordinance.set_place_handle("")
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_person(person, self.trans)
|
2006-11-20 20:56:38 +05:30
|
|
|
self.invalid_place_references.append(key)
|
|
|
|
# check families -> the LdsOrd references a place
|
|
|
|
for key in flist:
|
|
|
|
family = self.db.get_family_from_handle(key)
|
|
|
|
for ordinance in family.lds_ord_list:
|
|
|
|
place_handle = ordinance.get_place_handle()
|
|
|
|
if place_handle:
|
|
|
|
place = self.db.get_place_from_handle(place_handle)
|
|
|
|
if not place:
|
|
|
|
# The referenced place does not exist in the database
|
|
|
|
ordinance.set_place_handle("")
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_family(family, self.trans)
|
2006-11-20 20:56:38 +05:30
|
|
|
self.invalid_place_references.append(key)
|
|
|
|
# check events
|
2005-08-18 11:28:28 +05:30
|
|
|
for key in elist:
|
2005-04-11 15:41:04 +05:30
|
|
|
event = self.db.get_event_from_handle(key)
|
|
|
|
place_handle = event.get_place_handle()
|
|
|
|
if place_handle:
|
|
|
|
place = self.db.get_place_from_handle(place_handle)
|
|
|
|
if not place:
|
|
|
|
# The referenced place does not exist in the database
|
|
|
|
event.set_place_handle("")
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_event(event, self.trans)
|
2005-04-11 15:41:04 +05:30
|
|
|
self.invalid_place_references.append(key)
|
|
|
|
|
2005-07-09 01:54:54 +05:30
|
|
|
def check_source_references(self):
|
|
|
|
known_handles = self.db.get_source_handles()
|
2005-08-18 11:28:28 +05:30
|
|
|
|
2009-04-09 01:11:22 +05:30
|
|
|
total = (
|
|
|
|
self.db.get_number_of_people() +
|
|
|
|
self.db.get_number_of_families() +
|
|
|
|
self.db.get_number_of_events() +
|
|
|
|
self.db.get_number_of_places() +
|
|
|
|
self.db.get_number_of_media_objects() +
|
|
|
|
self.db.get_number_of_sources() +
|
2007-12-15 03:48:19 +05:30
|
|
|
self.db.get_number_of_repositories()
|
2009-04-09 01:11:22 +05:30
|
|
|
)
|
2005-08-18 11:28:28 +05:30
|
|
|
|
|
|
|
self.progress.set_pass(_('Looking for source reference problems'),
|
|
|
|
total)
|
2005-07-09 01:54:54 +05:30
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
for handle in self.db.person_map.keys():
|
2005-08-18 11:28:28 +05:30
|
|
|
self.progress.step()
|
2006-03-01 01:24:35 +05:30
|
|
|
info = self.db.person_map[handle]
|
2007-10-08 22:11:39 +05:30
|
|
|
person = gen.lib.Person()
|
2005-07-09 01:54:54 +05:30
|
|
|
person.unserialize(info)
|
|
|
|
handle_list = person.get_referenced_handles_recursively()
|
|
|
|
bad_handles = [ item[1] for item in handle_list
|
|
|
|
if item[0] == 'Source' and
|
|
|
|
item[1] not in known_handles ]
|
|
|
|
if bad_handles:
|
|
|
|
person.remove_source_references(bad_handles)
|
|
|
|
self.db.commit_person(person,self.trans)
|
|
|
|
new_bad_handles = [handle for handle in bad_handles if handle
|
|
|
|
not in self.invalid_source_references]
|
|
|
|
self.invalid_source_references += new_bad_handles
|
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
for handle in self.db.family_map.keys():
|
2005-08-18 11:28:28 +05:30
|
|
|
self.progress.step()
|
2006-03-01 01:24:35 +05:30
|
|
|
info = self.db.family_map[handle]
|
2007-10-08 22:11:39 +05:30
|
|
|
family = gen.lib.Family()
|
2005-07-09 01:54:54 +05:30
|
|
|
family.unserialize(info)
|
|
|
|
handle_list = family.get_referenced_handles_recursively()
|
|
|
|
bad_handles = [ item[1] for item in handle_list
|
|
|
|
if item[0] == 'Source' and
|
|
|
|
item[1] not in known_handles ]
|
|
|
|
if bad_handles:
|
|
|
|
family.remove_source_references(bad_handles)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_family(family, self.trans)
|
2005-07-09 01:54:54 +05:30
|
|
|
new_bad_handles = [handle for handle in bad_handles if handle
|
|
|
|
not in self.invalid_source_references]
|
|
|
|
self.invalid_source_references += new_bad_handles
|
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
for handle in self.db.place_map.keys():
|
2005-08-18 11:28:28 +05:30
|
|
|
self.progress.step()
|
2006-03-01 01:24:35 +05:30
|
|
|
info = self.db.place_map[handle]
|
2007-10-08 22:11:39 +05:30
|
|
|
place = gen.lib.Place()
|
2005-07-09 01:54:54 +05:30
|
|
|
place.unserialize(info)
|
|
|
|
handle_list = place.get_referenced_handles_recursively()
|
|
|
|
bad_handles = [ item[1] for item in handle_list
|
|
|
|
if item[0] == 'Source' and
|
|
|
|
item[1] not in known_handles ]
|
|
|
|
if bad_handles:
|
|
|
|
place.remove_source_references(bad_handles)
|
2006-03-01 01:24:35 +05:30
|
|
|
self.db.commit_place(place,self.trans)
|
2005-07-09 01:54:54 +05:30
|
|
|
new_bad_handles = [handle for handle in bad_handles if handle
|
|
|
|
not in self.invalid_source_references]
|
|
|
|
self.invalid_source_references += new_bad_handles
|
2007-12-15 03:48:19 +05:30
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
for handle in self.db.repository_map.keys():
|
2007-12-15 03:48:19 +05:30
|
|
|
self.progress.step()
|
|
|
|
info = self.db.repository_map[handle]
|
|
|
|
repo = gen.lib.Repository()
|
|
|
|
repo.unserialize(info)
|
|
|
|
handle_list = repo.get_referenced_handles_recursively()
|
|
|
|
bad_handles = [ item[1] for item in handle_list
|
|
|
|
if item[0] == 'Source' and
|
|
|
|
item[1] not in known_handles ]
|
|
|
|
if bad_handles:
|
|
|
|
repo.remove_source_references(bad_handles)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_repository(repo, self.trans)
|
2007-12-15 03:48:19 +05:30
|
|
|
new_bad_handles = [handle for handle in bad_handles if handle
|
|
|
|
not in self.invalid_source_references]
|
|
|
|
self.invalid_source_references += new_bad_handles
|
|
|
|
|
2007-10-06 18:28:11 +05:30
|
|
|
#I think this for loop is useless! sources in sources map exist...
|
2006-03-01 01:24:35 +05:30
|
|
|
for handle in known_handles:
|
2005-08-18 11:28:28 +05:30
|
|
|
self.progress.step()
|
2006-03-01 01:24:35 +05:30
|
|
|
info = self.db.source_map[handle]
|
2007-10-08 22:11:39 +05:30
|
|
|
source = gen.lib.Source()
|
2005-07-09 01:54:54 +05:30
|
|
|
source.unserialize(info)
|
|
|
|
handle_list = source.get_referenced_handles_recursively()
|
|
|
|
bad_handles = [ item[1] for item in handle_list
|
|
|
|
if item[0] == 'Source' and
|
|
|
|
item[1] not in known_handles ]
|
|
|
|
if bad_handles:
|
|
|
|
source.remove_source_references(bad_handles)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_source(source, self.trans)
|
2005-07-09 01:54:54 +05:30
|
|
|
new_bad_handles = [handle for handle in bad_handles if handle
|
|
|
|
not in self.invalid_source_references]
|
|
|
|
self.invalid_source_references += new_bad_handles
|
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
for handle in self.db.media_map.keys():
|
2005-08-18 11:28:28 +05:30
|
|
|
self.progress.step()
|
2006-03-01 01:24:35 +05:30
|
|
|
info = self.db.media_map[handle]
|
2007-10-08 22:11:39 +05:30
|
|
|
obj = gen.lib.MediaObject()
|
2005-07-09 01:54:54 +05:30
|
|
|
obj.unserialize(info)
|
|
|
|
handle_list = obj.get_referenced_handles_recursively()
|
|
|
|
bad_handles = [ item[1] for item in handle_list
|
|
|
|
if item[0] == 'Source' and
|
|
|
|
item[1] not in known_handles ]
|
|
|
|
if bad_handles:
|
|
|
|
obj.remove_source_references(bad_handles)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_media_object(obj, self.trans)
|
2005-07-09 01:54:54 +05:30
|
|
|
new_bad_handles = [handle for handle in bad_handles if handle
|
|
|
|
not in self.invalid_source_references]
|
|
|
|
self.invalid_source_references += new_bad_handles
|
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
for handle in self.db.event_map.keys():
|
2005-08-18 11:28:28 +05:30
|
|
|
self.progress.step()
|
2006-03-01 01:24:35 +05:30
|
|
|
info = self.db.event_map[handle]
|
2007-10-08 22:11:39 +05:30
|
|
|
event = gen.lib.Event()
|
2005-07-09 01:54:54 +05:30
|
|
|
event.unserialize(info)
|
|
|
|
handle_list = event.get_referenced_handles_recursively()
|
|
|
|
bad_handles = [ item[1] for item in handle_list
|
|
|
|
if item[0] == 'Source' and
|
|
|
|
item[1] not in known_handles ]
|
|
|
|
if bad_handles:
|
|
|
|
event.remove_source_references(bad_handles)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_event(event, self.trans)
|
2005-07-09 01:54:54 +05:30
|
|
|
new_bad_handles = [handle for handle in bad_handles if handle
|
|
|
|
not in self.invalid_source_references]
|
|
|
|
self.invalid_source_references += new_bad_handles
|
|
|
|
|
2007-10-06 18:28:11 +05:30
|
|
|
def check_media_references(self):
|
|
|
|
known_handles = self.db.get_media_object_handles(False)
|
|
|
|
|
2009-04-09 01:11:22 +05:30
|
|
|
total = (
|
|
|
|
self.db.get_number_of_people() +
|
|
|
|
self.db.get_number_of_families() +
|
|
|
|
self.db.get_number_of_events() +
|
|
|
|
self.db.get_number_of_places() +
|
2007-10-06 18:28:11 +05:30
|
|
|
self.db.get_number_of_sources()
|
2009-04-09 01:11:22 +05:30
|
|
|
)
|
2007-10-06 18:28:11 +05:30
|
|
|
|
|
|
|
self.progress.set_pass(_('Looking for media object reference problems'),
|
|
|
|
total)
|
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
for handle in self.db.person_map.keys():
|
2007-10-06 18:28:11 +05:30
|
|
|
self.progress.step()
|
|
|
|
info = self.db.person_map[handle]
|
2007-10-08 22:11:39 +05:30
|
|
|
person = gen.lib.Person()
|
2007-10-06 18:28:11 +05:30
|
|
|
person.unserialize(info)
|
|
|
|
handle_list = person.get_referenced_handles_recursively()
|
|
|
|
bad_handles = [ item[1] for item in handle_list
|
|
|
|
if item[0] == 'MediaObject' and
|
|
|
|
item[1] not in known_handles ]
|
|
|
|
if bad_handles:
|
|
|
|
person.remove_media_references(bad_handles)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_person(person, self.trans)
|
2007-10-06 18:28:11 +05:30
|
|
|
new_bad_handles = [handle for handle in bad_handles if handle
|
|
|
|
not in self.invalid_media_references]
|
|
|
|
self.invalid_media_references += new_bad_handles
|
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
for handle in self.db.family_map.keys():
|
2007-10-06 18:28:11 +05:30
|
|
|
self.progress.step()
|
|
|
|
info = self.db.family_map[handle]
|
2007-10-08 22:11:39 +05:30
|
|
|
family = gen.lib.Family()
|
2007-10-06 18:28:11 +05:30
|
|
|
family.unserialize(info)
|
|
|
|
handle_list = family.get_referenced_handles_recursively()
|
|
|
|
bad_handles = [ item[1] for item in handle_list
|
|
|
|
if item[0] == 'MediaObject' and
|
|
|
|
item[1] not in known_handles ]
|
|
|
|
if bad_handles:
|
|
|
|
family.remove_media_references(bad_handles)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_family(family, self.trans)
|
2007-10-06 18:28:11 +05:30
|
|
|
new_bad_handles = [handle for handle in bad_handles if handle
|
|
|
|
not in self.invalid_media_references]
|
|
|
|
self.invalid_media_references += new_bad_handles
|
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
for handle in self.db.place_map.keys():
|
2007-10-06 18:28:11 +05:30
|
|
|
self.progress.step()
|
|
|
|
info = self.db.place_map[handle]
|
2007-10-08 22:11:39 +05:30
|
|
|
place = gen.lib.Place()
|
2007-10-06 18:28:11 +05:30
|
|
|
place.unserialize(info)
|
|
|
|
handle_list = place.get_referenced_handles_recursively()
|
|
|
|
bad_handles = [ item[1] for item in handle_list
|
|
|
|
if item[0] == 'MediaObject' and
|
|
|
|
item[1] not in known_handles ]
|
|
|
|
if bad_handles:
|
|
|
|
place.remove_media_references(bad_handles)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_place(place, self.trans)
|
2007-10-06 18:28:11 +05:30
|
|
|
new_bad_handles = [handle for handle in bad_handles if handle
|
|
|
|
not in self.invalid_media_references]
|
|
|
|
self.invalid_media_references += new_bad_handles
|
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
for handle in self.db.event_map.keys():
|
2007-10-06 18:28:11 +05:30
|
|
|
self.progress.step()
|
|
|
|
info = self.db.event_map[handle]
|
2007-10-08 22:11:39 +05:30
|
|
|
event = gen.lib.Event()
|
2007-10-06 18:28:11 +05:30
|
|
|
event.unserialize(info)
|
|
|
|
handle_list = event.get_referenced_handles_recursively()
|
|
|
|
bad_handles = [ item[1] for item in handle_list
|
|
|
|
if item[0] == 'MediaObject' and
|
|
|
|
item[1] not in known_handles ]
|
|
|
|
if bad_handles:
|
|
|
|
event.remove_media_references(bad_handles)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_event(event, self.trans)
|
2007-10-06 18:28:11 +05:30
|
|
|
new_bad_handles = [handle for handle in bad_handles if handle
|
|
|
|
not in self.invalid_media_references]
|
|
|
|
self.invalid_media_references += new_bad_handles
|
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
for handle in self.db.source_map.keys():
|
2007-10-06 18:28:11 +05:30
|
|
|
self.progress.step()
|
|
|
|
info = self.db.source_map[handle]
|
2007-10-08 22:11:39 +05:30
|
|
|
source = gen.lib.Source()
|
2007-10-06 18:28:11 +05:30
|
|
|
source.unserialize(info)
|
|
|
|
handle_list = source.get_referenced_handles_recursively()
|
|
|
|
bad_handles = [ item[1] for item in handle_list
|
|
|
|
if item[0] == 'MediaObject' and
|
|
|
|
item[1] not in known_handles ]
|
|
|
|
if bad_handles:
|
|
|
|
source.remove_media_references(bad_handles)
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_source(source, self.trans)
|
2007-10-06 18:28:11 +05:30
|
|
|
new_bad_handles = [handle for handle in bad_handles if handle
|
|
|
|
not in self.invalid_media_references]
|
|
|
|
self.invalid_media_references += new_bad_handles
|
|
|
|
|
2007-12-15 03:48:19 +05:30
|
|
|
def check_note_references(self):
|
|
|
|
known_handles = self.db.get_note_handles()
|
|
|
|
|
2009-04-09 01:11:22 +05:30
|
|
|
total = (
|
|
|
|
self.db.get_number_of_people() +
|
|
|
|
self.db.get_number_of_families() +
|
|
|
|
self.db.get_number_of_events() +
|
|
|
|
self.db.get_number_of_places() +
|
|
|
|
self.db.get_number_of_media_objects() +
|
|
|
|
self.db.get_number_of_sources() +
|
2007-12-15 03:48:19 +05:30
|
|
|
self.db.get_number_of_repositories()
|
2009-04-09 01:11:22 +05:30
|
|
|
)
|
2007-12-15 03:48:19 +05:30
|
|
|
|
|
|
|
self.progress.set_pass(_('Looking for note reference problems'),
|
|
|
|
total)
|
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
for handle in self.db.person_map.keys():
|
2007-12-15 03:48:19 +05:30
|
|
|
self.progress.step()
|
|
|
|
info = self.db.person_map[handle]
|
|
|
|
person = gen.lib.Person()
|
|
|
|
person.unserialize(info)
|
|
|
|
handle_list = person.get_referenced_handles_recursively()
|
|
|
|
bad_handles = [ item[1] for item in handle_list
|
|
|
|
if item[0] == 'Note' and
|
|
|
|
item[1] not in known_handles ]
|
|
|
|
for bad_handle in bad_handles:
|
|
|
|
person.remove_note(bad_handle)
|
|
|
|
if bad_handles:
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_person(person, self.trans)
|
2007-12-15 03:48:19 +05:30
|
|
|
new_bad_handles = [handle for handle in bad_handles if handle
|
|
|
|
not in self.invalid_note_references]
|
|
|
|
self.invalid_note_references += new_bad_handles
|
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
for handle in self.db.family_map.keys():
|
2007-12-15 03:48:19 +05:30
|
|
|
self.progress.step()
|
|
|
|
info = self.db.family_map[handle]
|
|
|
|
family = gen.lib.Family()
|
|
|
|
family.unserialize(info)
|
|
|
|
handle_list = family.get_referenced_handles_recursively()
|
|
|
|
bad_handles = [ item[1] for item in handle_list
|
|
|
|
if item[0] == 'Note' and
|
|
|
|
item[1] not in known_handles ]
|
|
|
|
for bad_handle in bad_handles:
|
|
|
|
family.remove_note(bad_handle)
|
|
|
|
if bad_handles:
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_family(family, self.trans)
|
2007-12-15 03:48:19 +05:30
|
|
|
new_bad_handles = [handle for handle in bad_handles if handle
|
|
|
|
not in self.invalid_note_references]
|
|
|
|
self.invalid_note_references += new_bad_handles
|
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
for handle in self.db.place_map.keys():
|
2007-12-15 03:48:19 +05:30
|
|
|
self.progress.step()
|
|
|
|
info = self.db.place_map[handle]
|
|
|
|
place = gen.lib.Place()
|
|
|
|
place.unserialize(info)
|
|
|
|
handle_list = place.get_referenced_handles_recursively()
|
|
|
|
bad_handles = [ item[1] for item in handle_list
|
|
|
|
if item[0] == 'Note' and
|
|
|
|
item[1] not in known_handles ]
|
|
|
|
for bad_handle in bad_handles:
|
|
|
|
place.remove_note(bad_handle)
|
|
|
|
if bad_handles:
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_place(place, self.trans)
|
2007-12-15 03:48:19 +05:30
|
|
|
new_bad_handles = [handle for handle in bad_handles if handle
|
|
|
|
not in self.invalid_note_references]
|
|
|
|
self.invalid_note_references += new_bad_handles
|
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
for handle in self.db.source_map.keys():
|
2007-12-15 03:48:19 +05:30
|
|
|
self.progress.step()
|
|
|
|
info = self.db.source_map[handle]
|
|
|
|
source = gen.lib.Source()
|
|
|
|
source.unserialize(info)
|
|
|
|
handle_list = source.get_referenced_handles_recursively()
|
|
|
|
bad_handles = [ item[1] for item in handle_list
|
|
|
|
if item[0] == 'Note' and
|
|
|
|
item[1] not in known_handles ]
|
|
|
|
for bad_handle in bad_handles:
|
|
|
|
source.remove_note(bad_handle)
|
|
|
|
if bad_handles:
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_source(source, self.trans)
|
2007-12-15 03:48:19 +05:30
|
|
|
new_bad_handles = [handle for handle in bad_handles if handle
|
|
|
|
not in self.invalid_note_references]
|
|
|
|
self.invalid_note_references += new_bad_handles
|
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
for handle in self.db.media_map.keys():
|
2007-12-15 03:48:19 +05:30
|
|
|
self.progress.step()
|
|
|
|
info = self.db.media_map[handle]
|
|
|
|
obj = gen.lib.MediaObject()
|
|
|
|
obj.unserialize(info)
|
|
|
|
handle_list = obj.get_referenced_handles_recursively()
|
|
|
|
bad_handles = [ item[1] for item in handle_list
|
|
|
|
if item[0] == 'Note' and
|
|
|
|
item[1] not in known_handles ]
|
|
|
|
for bad_handle in bad_handles:
|
|
|
|
obj.remove_note(bad_handle)
|
|
|
|
if bad_handles:
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_media_object(obj, self.trans)
|
2007-12-15 03:48:19 +05:30
|
|
|
new_bad_handles = [handle for handle in bad_handles if handle
|
|
|
|
not in self.invalid_note_references]
|
|
|
|
self.invalid_note_references += new_bad_handles
|
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
for handle in self.db.event_map.keys():
|
2007-12-15 03:48:19 +05:30
|
|
|
self.progress.step()
|
|
|
|
info = self.db.event_map[handle]
|
|
|
|
event = gen.lib.Event()
|
|
|
|
event.unserialize(info)
|
|
|
|
handle_list = event.get_referenced_handles_recursively()
|
|
|
|
bad_handles = [ item[1] for item in handle_list
|
|
|
|
if item[0] == 'Note' and
|
|
|
|
item[1] not in known_handles ]
|
|
|
|
for bad_handle in bad_handles:
|
|
|
|
event.remove_note(bad_handle)
|
|
|
|
if bad_handles:
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_event(event, self.trans)
|
2007-12-15 03:48:19 +05:30
|
|
|
new_bad_handles = [handle for handle in bad_handles if handle
|
|
|
|
not in self.invalid_note_references]
|
|
|
|
self.invalid_note_references += new_bad_handles
|
|
|
|
|
2009-06-16 21:19:17 +05:30
|
|
|
for handle in self.db.repository_map.keys():
|
2007-12-15 03:48:19 +05:30
|
|
|
self.progress.step()
|
|
|
|
info = self.db.repository_map[handle]
|
|
|
|
repo = gen.lib.Repository()
|
|
|
|
repo.unserialize(info)
|
|
|
|
handle_list = repo.get_referenced_handles_recursively()
|
|
|
|
bad_handles = [ item[1] for item in handle_list
|
|
|
|
if item[0] == 'Note' and
|
|
|
|
item[1] not in known_handles ]
|
|
|
|
for bad_handle in bad_handles:
|
|
|
|
repo.remove_note(bad_handle)
|
|
|
|
if bad_handles:
|
2009-08-15 20:07:14 +05:30
|
|
|
self.db.commit_repository(repo, self.trans)
|
2007-12-15 03:48:19 +05:30
|
|
|
new_bad_handles = [handle for handle in bad_handles if handle
|
|
|
|
not in self.invalid_note_references]
|
|
|
|
self.invalid_note_references += new_bad_handles
|
|
|
|
|
2009-08-15 20:07:14 +05:30
|
|
|
def build_report(self, cl=0):
|
2005-08-18 11:28:28 +05:30
|
|
|
self.progress.close()
|
2003-05-14 08:16:59 +05:30
|
|
|
bad_photos = len(self.bad_photo)
|
|
|
|
replaced_photos = len(self.replaced_photo)
|
|
|
|
removed_photos = len(self.removed_photo)
|
|
|
|
photos = bad_photos + replaced_photos + removed_photos
|
2002-10-20 19:55:16 +05:30
|
|
|
efam = len(self.empty_family)
|
|
|
|
blink = len(self.broken_links)
|
|
|
|
plink = len(self.broken_parent_links)
|
2005-08-18 11:28:28 +05:30
|
|
|
slink = len(self.duplicate_links)
|
2002-10-20 19:55:16 +05:30
|
|
|
rel = len(self.fam_rel)
|
2005-04-01 15:29:18 +05:30
|
|
|
event_invalid = len(self.invalid_events)
|
|
|
|
birth_invalid = len(self.invalid_birth_events)
|
|
|
|
death_invalid = len(self.invalid_death_events)
|
|
|
|
person = birth_invalid + death_invalid
|
2006-11-09 18:03:10 +05:30
|
|
|
person_references = len(self.invalid_person_references)
|
2009-03-10 01:22:17 +05:30
|
|
|
invalid_dates = len(self.invalid_dates)
|
2005-04-11 15:41:04 +05:30
|
|
|
place_references = len(self.invalid_place_references)
|
2005-07-09 01:54:54 +05:30
|
|
|
source_references = len(self.invalid_source_references)
|
2006-12-03 05:14:38 +05:30
|
|
|
repo_references = len(self.invalid_repo_references)
|
2007-10-06 18:28:11 +05:30
|
|
|
media_references = len(self.invalid_media_references)
|
2007-12-15 03:48:19 +05:30
|
|
|
note_references = len(self.invalid_note_references)
|
2006-07-27 16:18:16 +05:30
|
|
|
name_format = len(self.removed_name_format)
|
2009-04-09 01:11:22 +05:30
|
|
|
empty_objs = (
|
|
|
|
len(self.empty_objects['persons']) +
|
|
|
|
len(self.empty_objects['families']) +
|
|
|
|
len(self.empty_objects['events']) +
|
|
|
|
len(self.empty_objects['sources']) +
|
|
|
|
len(self.empty_objects['media']) +
|
|
|
|
len(self.empty_objects['places']) +
|
|
|
|
len(self.empty_objects['repos']) +
|
|
|
|
len(self.empty_objects['notes'])
|
2007-10-06 14:38:29 +05:30
|
|
|
)
|
|
|
|
|
2009-04-09 01:11:22 +05:30
|
|
|
errors = (photos + efam + blink + plink + slink + rel +
|
|
|
|
event_invalid + person +
|
|
|
|
person_references + place_references + source_references +
|
|
|
|
repo_references + media_references + note_references +
|
|
|
|
name_format + empty_objs + invalid_dates
|
2007-10-06 14:38:29 +05:30
|
|
|
)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
if errors == 0:
|
2003-05-19 10:24:14 +05:30
|
|
|
if cl:
|
|
|
|
print "No errors were found: the database has passed internal checks."
|
|
|
|
else:
|
|
|
|
OkDialog(_("No errors were found"),
|
2006-04-10 04:23:53 +05:30
|
|
|
_('The database has passed internal checks'))
|
2003-05-19 10:24:14 +05:30
|
|
|
return 0
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-05-19 10:24:14 +05:30
|
|
|
self.text = cStringIO.StringIO()
|
2002-10-20 19:55:16 +05:30
|
|
|
if blink > 0:
|
2009-02-03 16:03:19 +05:30
|
|
|
self.text.write(ngettext("%d broken child/family link was fixed\n", \
|
2009-01-31 16:59:44 +05:30
|
|
|
"%d broken child-family links were found\n", blink) % blink)
|
2009-08-15 20:07:14 +05:30
|
|
|
for (person_handle, family_handle) in self.broken_links:
|
2004-08-07 10:46:57 +05:30
|
|
|
person = self.db.get_person_from_handle(person_handle)
|
2005-03-26 16:23:27 +05:30
|
|
|
if person:
|
|
|
|
cn = person.get_primary_name().get_name()
|
|
|
|
else:
|
|
|
|
cn = _("Non existing child")
|
2005-04-11 02:51:58 +05:30
|
|
|
try:
|
|
|
|
family = self.db.get_family_from_handle(family_handle)
|
2009-08-15 20:07:14 +05:30
|
|
|
pn = Utils.family_name(family, self.db)
|
2005-04-11 02:51:58 +05:30
|
|
|
except:
|
|
|
|
pn = _("Unknown")
|
2003-05-19 10:24:14 +05:30
|
|
|
self.text.write('\t')
|
2009-08-15 20:07:14 +05:30
|
|
|
self.text.write(_("%s was removed from the family of %s\n") % (cn, pn))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
if plink > 0:
|
2009-02-03 16:03:19 +05:30
|
|
|
self.text.write(ngettext("%d broken spouse/family link was fixed\n", \
|
2009-01-31 16:59:44 +05:30
|
|
|
"%d broken spouse/family links were found\n", plink) % plink)
|
2009-08-15 20:07:14 +05:30
|
|
|
for (person_handle, family_handle) in self.broken_parent_links:
|
2004-08-07 10:46:57 +05:30
|
|
|
person = self.db.get_person_from_handle(person_handle)
|
2005-03-27 03:29:15 +05:30
|
|
|
if person:
|
|
|
|
cn = person.get_primary_name().get_name()
|
|
|
|
else:
|
|
|
|
cn = _("Non existing person")
|
2005-04-01 13:09:21 +05:30
|
|
|
family = self.db.get_family_from_handle(family_handle)
|
2005-05-11 19:34:47 +05:30
|
|
|
if family:
|
2009-08-15 20:07:14 +05:30
|
|
|
pn = Utils.family_name(family, self.db)
|
2005-05-11 19:34:47 +05:30
|
|
|
else:
|
|
|
|
pn = family_handle
|
2005-03-27 03:29:15 +05:30
|
|
|
self.text.write('\t')
|
2009-08-15 20:07:14 +05:30
|
|
|
self.text.write(_("%s was restored to the family of %s\n") % (cn, pn))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-08-18 11:28:28 +05:30
|
|
|
if slink > 0:
|
2009-02-03 16:03:19 +05:30
|
|
|
self.text.write(ngettext("%d duplicate spouse/family link was found\n", \
|
2009-01-31 16:59:44 +05:30
|
|
|
"%d duplicate spouse/family links were found\n", slink) % slink)
|
2009-08-15 20:07:14 +05:30
|
|
|
for (person_handle, family_handle) in self.broken_parent_links:
|
2005-08-18 11:28:28 +05:30
|
|
|
person = self.db.get_person_from_handle(person_handle)
|
|
|
|
if person:
|
|
|
|
cn = person.get_primary_name().get_name()
|
|
|
|
else:
|
|
|
|
cn = _("Non existing person")
|
|
|
|
family = self.db.get_family_from_handle(family_handle)
|
|
|
|
if family:
|
2009-08-15 20:07:14 +05:30
|
|
|
pn = Utils.family_name(family, self.db)
|
2005-08-18 11:28:28 +05:30
|
|
|
else:
|
2005-12-06 12:08:09 +05:30
|
|
|
pn = _("None")
|
2005-08-18 11:28:28 +05:30
|
|
|
self.text.write('\t')
|
2009-08-15 20:07:14 +05:30
|
|
|
self.text.write(_("%s was restored to the family of %s\n") % (cn, pn))
|
2005-08-18 11:28:28 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
if efam == 1:
|
2009-02-03 16:03:19 +05:30
|
|
|
self.text.write(_("%d family with no parents or children found, removed.\n"))
|
2005-12-06 12:08:09 +05:30
|
|
|
self.text.write("\t%s\n" % self.empty_family[0])
|
2002-10-20 19:55:16 +05:30
|
|
|
elif efam > 1:
|
2007-10-06 14:38:29 +05:30
|
|
|
self.text.write(_("%d families with no parents or children, removed.\n") % efam)
|
|
|
|
|
2009-01-31 16:59:44 +05:30
|
|
|
if rel:
|
2009-02-03 16:03:19 +05:30
|
|
|
self.text.write(ngettext("%d corrupted family relationship fixed\n", \
|
2009-01-31 16:59:44 +05:30
|
|
|
"%d corrupted family relationship fixed\n", rel) % rel )
|
2007-10-06 14:38:29 +05:30
|
|
|
|
2009-01-31 16:59:44 +05:30
|
|
|
if person_references:
|
2009-02-03 16:03:19 +05:30
|
|
|
self.text.write(ngettext("%d person was referenced but not found\n", \
|
2009-01-31 16:59:44 +05:30
|
|
|
"%d persons were referenced, but not found\n", person_references) % person_references)
|
2006-12-03 05:14:38 +05:30
|
|
|
|
2009-03-10 01:22:17 +05:30
|
|
|
if invalid_dates:
|
|
|
|
self.text.write(ngettext("%d date was corrected\n", \
|
|
|
|
"%d dates were corrected\n", invalid_dates) % invalid_dates)
|
|
|
|
|
2009-01-31 16:59:44 +05:30
|
|
|
if repo_references:
|
2009-02-03 16:03:19 +05:30
|
|
|
self.text.write(ngettext("%d repository was referenced but not found\n", \
|
2009-01-31 16:59:44 +05:30
|
|
|
"%d repositories were referenced, but not found\n", repo_references) % repo_references)
|
|
|
|
|
|
|
|
if photos:
|
2009-02-03 16:03:19 +05:30
|
|
|
self.text.write(ngettext("%d media object was referenced, but not found\n", \
|
2009-01-31 16:59:44 +05:30
|
|
|
"%d media objects were referenced, but not found\n", photos) % photos)
|
|
|
|
|
|
|
|
if bad_photos:
|
2009-02-03 16:03:19 +05:30
|
|
|
self.text.write(ngettext("Reference to %d missing media object was kept\n", \
|
2009-01-31 16:59:44 +05:30
|
|
|
"References to %d media objects were kept\n", bad_photos) % bad_photos)
|
|
|
|
|
|
|
|
if replaced_photos:
|
2009-02-03 16:03:19 +05:30
|
|
|
self.text.write(ngettext("%d missing media object was replaced\n", \
|
2009-01-31 16:59:44 +05:30
|
|
|
"%d missing media objects were replaced\n", replaced_photos) % replaced_photos)
|
|
|
|
|
|
|
|
if removed_photos:
|
2009-02-03 16:03:19 +05:30
|
|
|
self.text.write(ngettext("%d missing media object was removed\n", \
|
2009-01-31 16:59:44 +05:30
|
|
|
"%d missing media objects were removed\n", removed_photos) % removed_photos)
|
|
|
|
|
|
|
|
if event_invalid:
|
2009-02-03 16:03:19 +05:30
|
|
|
self.text.write(ngettext("%d invalid event reference was removed\n", \
|
2009-01-31 16:59:44 +05:30
|
|
|
"%d invalid event references were removed\n", event_invalid) % event_invalid)
|
|
|
|
|
|
|
|
if birth_invalid:
|
2009-02-03 16:03:19 +05:30
|
|
|
self.text.write(ngettext("%d invalid birth event name was fixed\n", \
|
2009-01-31 16:59:44 +05:30
|
|
|
"%d invalid birth event names were fixed\n", birth_invalid) % birth_invalid)
|
|
|
|
|
|
|
|
if death_invalid:
|
2009-02-03 16:03:19 +05:30
|
|
|
self.text.write(ngettext("%d invalid death event name was fixed\n", \
|
2009-01-31 16:59:44 +05:30
|
|
|
"%d invalid death event names were fixed\n", death_invalid) % death_invalid)
|
|
|
|
|
|
|
|
if place_references:
|
2009-02-03 16:03:19 +05:30
|
|
|
self.text.write(ngettext("%d place was referenced but not found\n", \
|
2009-01-31 16:59:44 +05:30
|
|
|
"%d places were referenced, but not found\n", place_references) % place_references)
|
|
|
|
|
|
|
|
if source_references:
|
2009-02-03 16:03:19 +05:30
|
|
|
self.text.write(ngettext("%d source was referenced but not found\n", \
|
2009-01-31 16:59:44 +05:30
|
|
|
"%d sources were referenced, but not found\n", source_references) % source_references)
|
|
|
|
|
|
|
|
if media_references:
|
2009-02-03 16:03:19 +05:30
|
|
|
self.text.write(ngettext("%d media object was referenced but not found\n", \
|
2009-01-31 16:59:44 +05:30
|
|
|
"%d media objects were referenced but not found\n", media_references) % media_references)
|
|
|
|
|
|
|
|
if note_references:
|
2009-02-03 16:03:19 +05:30
|
|
|
self.text.write(ngettext("%d note object was referenced but not found\n", \
|
2009-01-31 16:59:44 +05:30
|
|
|
"%d note objects were referenced but not found\n", note_references) % note_references)
|
|
|
|
|
|
|
|
if name_format:
|
2009-02-03 16:03:19 +05:30
|
|
|
self.text.write(ngettext("%d invalid name format reference was removed\n", \
|
2009-01-31 16:59:44 +05:30
|
|
|
"%d invalid name format references were removed\n", name_format) % name_format)
|
2003-05-19 10:24:14 +05:30
|
|
|
|
2007-10-06 14:38:29 +05:30
|
|
|
if empty_objs > 0 :
|
|
|
|
self.text.write(_("%d empty objects removed:\n"
|
|
|
|
" %d person objects\n"
|
|
|
|
" %d family objects\n"
|
|
|
|
" %d event objects\n"
|
|
|
|
" %d source objects\n"
|
|
|
|
" %d media objects\n"
|
|
|
|
" %d place objects\n"
|
|
|
|
" %d repository objects\n"
|
|
|
|
" %d note objects\n"
|
|
|
|
) % (empty_objs,
|
|
|
|
len(self.empty_objects['persons']),
|
|
|
|
len(self.empty_objects['families']),
|
|
|
|
len(self.empty_objects['events']),
|
|
|
|
len(self.empty_objects['sources']),
|
|
|
|
len(self.empty_objects['media']),
|
|
|
|
len(self.empty_objects['places']),
|
|
|
|
len(self.empty_objects['repos']),
|
|
|
|
len(self.empty_objects['notes'])
|
|
|
|
) )
|
|
|
|
|
2003-05-19 10:24:14 +05:30
|
|
|
return errors
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-03-24 22:47:01 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Display the results
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-04-10 04:23:53 +05:30
|
|
|
class Report(ManagedWindow.ManagedWindow):
|
|
|
|
|
|
|
|
def __init__(self, uistate, text, cl=0):
|
2004-05-09 09:32:26 +05:30
|
|
|
if cl:
|
2005-03-24 22:47:01 +05:30
|
|
|
print text
|
|
|
|
return
|
|
|
|
|
2006-04-10 04:23:53 +05:30
|
|
|
ManagedWindow.ManagedWindow.__init__(self, uistate, [], self)
|
|
|
|
|
2009-05-15 01:45:59 +05:30
|
|
|
topDialog = Glade()
|
2009-08-15 20:07:14 +05:30
|
|
|
topDialog.get_object("close").connect('clicked', self.close)
|
2009-05-15 01:45:59 +05:30
|
|
|
window = topDialog.toplevel
|
2009-04-09 01:11:22 +05:30
|
|
|
textwindow = topDialog.get_object("textwindow")
|
2006-04-10 04:23:53 +05:30
|
|
|
textwindow.get_buffer().set_text(text)
|
2005-03-24 22:47:01 +05:30
|
|
|
|
2006-04-27 04:13:18 +05:30
|
|
|
self.set_window(window,
|
2009-04-09 01:11:22 +05:30
|
|
|
#topDialog.get_widget("title"),
|
|
|
|
topDialog.get_object("title"),
|
2006-04-27 04:13:18 +05:30
|
|
|
_("Integrity Check Results"))
|
2005-03-24 22:47:01 +05:30
|
|
|
|
2006-04-10 04:23:53 +05:30
|
|
|
self.show()
|
2005-03-24 22:47:01 +05:30
|
|
|
|
2006-04-10 04:23:53 +05:30
|
|
|
def build_menu_names(self, obj):
|
2009-08-15 20:07:14 +05:30
|
|
|
return (_('Check and Repair'), None)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class CheckOptions(Tool.ToolOptions):
|
|
|
|
"""
|
|
|
|
Defines options and provides handling interface.
|
|
|
|
"""
|
|
|
|
|
2009-08-15 20:07:14 +05:30
|
|
|
def __init__(self, name, person_id=None):
|
|
|
|
Tool.ToolOptions.__init__(self, name, person_id)
|