2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2007-06-18 06:21:04 +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-05-08 08:59:21 +05:30
|
|
|
# $Id$
|
|
|
|
|
2006-05-27 01:48:33 +05:30
|
|
|
"""
|
2008-02-29 02:09:24 +05:30
|
|
|
A plugin to verify the data against user-adjusted tests.
|
2006-05-27 01:48:33 +05:30
|
|
|
This is the research tool, not the low-level data ingerity check.
|
|
|
|
"""
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# standard python modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import os
|
2006-05-26 05:29:51 +05:30
|
|
|
import cPickle
|
2008-12-05 03:14:12 +05:30
|
|
|
try:
|
|
|
|
from hashlib import md5
|
|
|
|
except ImportError:
|
|
|
|
from md5 import md5
|
2006-09-05 23:41:40 +05:30
|
|
|
import Errors
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GNOME/GTK modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import gtk
|
2008-01-22 03:33:43 +05:30
|
|
|
import gobject
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2006-05-27 04:41:37 +05:30
|
|
|
import const
|
2007-10-08 22:11:39 +05:30
|
|
|
import gen.lib
|
2002-10-20 19:55:16 +05:30
|
|
|
import Utils
|
2006-04-10 04:23:53 +05:30
|
|
|
import GrampsDisplay
|
2006-05-26 05:29:51 +05:30
|
|
|
from ManagedWindow import ManagedWindow
|
|
|
|
from BasicUtils import UpdateCallback
|
2008-10-02 09:32:10 +05:30
|
|
|
from PluginUtils import Tool
|
|
|
|
from gen.plug import PluginManager
|
2008-02-29 02:09:24 +05:30
|
|
|
from TransUtils import sgettext as _
|
2009-05-15 01:45:59 +05:30
|
|
|
from glade import Glade
|
|
|
|
|
2008-02-29 02:09:24 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-02-26 15:38:38 +05:30
|
|
|
WIKI_HELP_PAGE = '%s_-_Tools' % const.URL_MANUAL_PAGE
|
2008-02-29 02:09:24 +05:30
|
|
|
WIKI_HELP_SEC = _('manual|Verify_the_Data...')
|
2004-05-08 08:59:21 +05:30
|
|
|
|
2006-05-25 10:48:03 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# temp storage and related functions
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-05-27 01:48:33 +05:30
|
|
|
_person_cache = {}
|
|
|
|
_family_cache = {}
|
|
|
|
_event_cache = {}
|
2006-05-25 10:48:03 +05:30
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def find_event(db, handle):
|
2008-04-27 02:03:25 +05:30
|
|
|
if handle in _event_cache:
|
2006-05-27 01:48:33 +05:30
|
|
|
obj = _event_cache[handle]
|
2008-04-27 02:03:25 +05:30
|
|
|
else:
|
2006-05-25 10:48:03 +05:30
|
|
|
obj = db.get_event_from_handle(handle)
|
2006-05-27 01:48:33 +05:30
|
|
|
_event_cache[handle] = obj
|
2006-05-25 10:48:03 +05:30
|
|
|
return obj
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def find_person(db, handle):
|
2008-04-27 02:03:25 +05:30
|
|
|
if handle in _person_cache:
|
2006-05-27 01:48:33 +05:30
|
|
|
obj = _person_cache[handle]
|
2008-04-27 02:03:25 +05:30
|
|
|
else:
|
2006-05-25 10:48:03 +05:30
|
|
|
obj = db.get_person_from_handle(handle)
|
2006-05-27 01:48:33 +05:30
|
|
|
_person_cache[handle] = obj
|
2006-05-25 10:48:03 +05:30
|
|
|
return obj
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def find_family(db, handle):
|
2008-04-27 02:03:25 +05:30
|
|
|
if handle in _family_cache:
|
2006-05-27 01:48:33 +05:30
|
|
|
obj = _family_cache[handle]
|
2008-04-27 02:03:25 +05:30
|
|
|
else:
|
2006-05-25 10:48:03 +05:30
|
|
|
obj = db.get_family_from_handle(handle)
|
2006-05-27 01:48:33 +05:30
|
|
|
_family_cache[handle] = obj
|
2006-05-25 10:48:03 +05:30
|
|
|
return obj
|
|
|
|
|
2006-05-27 01:48:33 +05:30
|
|
|
def clear_cache():
|
|
|
|
_person_cache.clear()
|
|
|
|
_family_cache.clear()
|
|
|
|
_event_cache.clear()
|
2006-05-26 05:29:51 +05:30
|
|
|
|
2006-05-25 10:48:03 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# helper functions
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def get_date_from_event_handle(db,event_handle):
|
|
|
|
if not event_handle:
|
|
|
|
return 0
|
|
|
|
event = find_event(db,event_handle)
|
|
|
|
date_obj = event.get_date_object()
|
2007-03-19 00:36:22 +05:30
|
|
|
if date_obj.get_day() == 0 or date_obj.get_month() == 0:
|
|
|
|
return 0
|
2006-05-25 10:48:03 +05:30
|
|
|
return date_obj.get_sort_value()
|
|
|
|
|
|
|
|
def get_date_from_event_type(db,person,event_type):
|
|
|
|
if not person:
|
|
|
|
return 0
|
|
|
|
for event_ref in person.get_event_ref_list():
|
|
|
|
event = find_event(db,event_ref.ref)
|
|
|
|
if event.get_type() == event_type:
|
|
|
|
date_obj = event.get_date_object()
|
2007-03-19 00:36:22 +05:30
|
|
|
if date_obj.get_day() == 0 or date_obj.get_month() == 0:
|
|
|
|
return 0
|
2006-05-25 10:48:03 +05:30
|
|
|
return date_obj.get_sort_value()
|
|
|
|
return 0
|
|
|
|
|
2006-05-26 05:29:51 +05:30
|
|
|
def get_bapt_date(db,person):
|
2007-10-08 22:11:39 +05:30
|
|
|
return get_date_from_event_type(db,person,gen.lib.EventType.BAPTISM)
|
2006-05-26 05:29:51 +05:30
|
|
|
|
|
|
|
def get_bury_date(db,person):
|
2007-10-08 22:11:39 +05:30
|
|
|
return get_date_from_event_type(db,person,gen.lib.EventType.BURIAL)
|
2006-05-26 05:29:51 +05:30
|
|
|
|
|
|
|
def get_birth_date(db,person,estimate=False):
|
2006-05-25 10:48:03 +05:30
|
|
|
if not person:
|
|
|
|
return 0
|
|
|
|
birth_ref = person.get_birth_ref()
|
|
|
|
if not birth_ref:
|
2006-05-26 05:29:51 +05:30
|
|
|
ret = 0
|
|
|
|
else:
|
|
|
|
ret = get_date_from_event_handle(db,birth_ref.ref)
|
|
|
|
if estimate and (ret == 0):
|
|
|
|
ret = get_bapt_date(db,person)
|
|
|
|
return ret
|
|
|
|
|
|
|
|
def get_death_date(db,person,estimate=False):
|
2006-05-25 10:48:03 +05:30
|
|
|
if not person:
|
|
|
|
return 0
|
|
|
|
death_ref = person.get_death_ref()
|
|
|
|
if not death_ref:
|
2006-05-26 05:29:51 +05:30
|
|
|
ret = 0
|
|
|
|
else:
|
|
|
|
ret = get_date_from_event_handle(db,death_ref.ref)
|
|
|
|
if estimate and (ret == 0):
|
|
|
|
ret = get_bury_date(db,person)
|
|
|
|
return ret
|
|
|
|
|
|
|
|
def get_age_at_death(db,person,estimate):
|
|
|
|
birth_date = get_birth_date(db,person,estimate)
|
|
|
|
death_date = get_death_date(db,person,estimate)
|
2006-05-25 10:48:03 +05:30
|
|
|
if (birth_date > 0) and (death_date > 0):
|
|
|
|
return death_date - birth_date
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def get_father(db,family):
|
|
|
|
if not family:
|
|
|
|
return None
|
|
|
|
father_handle = family.get_father_handle()
|
|
|
|
if father_handle:
|
|
|
|
return find_person(db,father_handle)
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_mother(db,family):
|
|
|
|
if not family:
|
|
|
|
return None
|
|
|
|
mother_handle = family.get_mother_handle()
|
|
|
|
if mother_handle:
|
|
|
|
return find_person(db,mother_handle)
|
|
|
|
return None
|
|
|
|
|
2006-05-26 05:29:51 +05:30
|
|
|
def get_child_birth_dates(db,family,estimate):
|
2006-05-25 10:48:03 +05:30
|
|
|
dates = []
|
|
|
|
for child_ref in family.get_child_ref_list():
|
|
|
|
child = find_person(db,child_ref.ref)
|
2006-05-26 05:29:51 +05:30
|
|
|
child_birth_date = get_birth_date(db,child,estimate)
|
2006-05-25 10:48:03 +05:30
|
|
|
if child_birth_date > 0:
|
|
|
|
dates.append(child_birth_date)
|
|
|
|
return dates
|
|
|
|
|
|
|
|
def get_n_children(db,person):
|
|
|
|
n = 0
|
|
|
|
for family_handle in person.get_family_handle_list():
|
|
|
|
family = find_family(db,family_handle)
|
2008-04-27 02:03:25 +05:30
|
|
|
if family:
|
|
|
|
n += len(family.get_child_ref_list())
|
2008-02-21 09:34:37 +05:30
|
|
|
return n
|
2006-05-25 10:48:03 +05:30
|
|
|
|
2006-05-26 05:29:51 +05:30
|
|
|
def get_marriage_date(db,family):
|
|
|
|
if not family:
|
|
|
|
return 0
|
|
|
|
for event_ref in family.get_event_ref_list():
|
|
|
|
event = find_event(db,event_ref.ref)
|
2007-10-08 22:11:39 +05:30
|
|
|
if event.get_type() == gen.lib.EventType.MARRIAGE:
|
2006-05-26 05:29:51 +05:30
|
|
|
date_obj = event.get_date_object()
|
|
|
|
return date_obj.get_sort_value()
|
|
|
|
return 0
|
|
|
|
|
2004-05-08 08:59:21 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2005-03-24 08:57:02 +05:30
|
|
|
# Actual tool
|
2004-05-08 08:59:21 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-05-26 05:29:51 +05:30
|
|
|
class Verify(Tool.Tool, ManagedWindow, UpdateCallback):
|
2006-04-10 04:23:53 +05:30
|
|
|
|
|
|
|
def __init__(self, dbstate, uistate, options_class, name,callback=None):
|
2006-04-27 08:05:47 +05:30
|
|
|
self.label = _('Database Verify tool')
|
2006-04-10 04:23:53 +05:30
|
|
|
Tool.Tool.__init__(self, dbstate, options_class, name)
|
2006-05-26 05:29:51 +05:30
|
|
|
ManagedWindow.__init__(self,uistate,[],self.__class__)
|
|
|
|
UpdateCallback.__init__(self,self.uistate.pulse_progressbar)
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2006-05-29 07:08:44 +05:30
|
|
|
self.dbstate = dbstate
|
2006-04-10 04:23:53 +05:30
|
|
|
if uistate:
|
|
|
|
self.init_gui()
|
2005-12-06 12:08:09 +05:30
|
|
|
else:
|
2006-05-26 05:29:51 +05:30
|
|
|
self.add_results = self.add_results_cli
|
|
|
|
self.run_tool(cli=True)
|
|
|
|
|
|
|
|
def add_results_cli(self,results):
|
|
|
|
# print data for the user, no GUI
|
2008-02-24 19:25:55 +05:30
|
|
|
(msg,gramps_id, name,the_type,rule_id,severity, handle) = results
|
2006-05-27 01:48:33 +05:30
|
|
|
if severity == Rule.WARNING:
|
2008-02-24 19:25:55 +05:30
|
|
|
print "W: %s, %s: %s, %s" % (msg,the_type,gramps_id, name)
|
2006-05-27 01:48:33 +05:30
|
|
|
elif severity == Rule.ERROR:
|
2008-02-24 19:25:55 +05:30
|
|
|
print "E: %s, %s: %s, %s" % (msg,the_type,gramps_id, name)
|
2007-03-19 00:50:09 +05:30
|
|
|
else:
|
2008-02-24 19:25:55 +05:30
|
|
|
print "S: %s, %s: %s, %s" % (msg,the_type,gramps_id, name)
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2006-04-10 04:23:53 +05:30
|
|
|
def init_gui(self):
|
2005-12-06 12:08:09 +05:30
|
|
|
# Draw dialog and make it handle everything
|
2008-01-05 04:54:51 +05:30
|
|
|
self.vr = None
|
2009-05-15 01:45:59 +05:30
|
|
|
self.top = Glade()
|
2009-04-12 02:42:14 +05:30
|
|
|
self.top.connect_signals({
|
2005-03-24 08:57:02 +05:30
|
|
|
"destroy_passed_object" : self.close,
|
|
|
|
"on_help_clicked" : self.on_help_clicked,
|
|
|
|
"on_verify_ok_clicked" : self.on_apply_clicked
|
2002-10-20 19:55:16 +05:30
|
|
|
})
|
|
|
|
|
2009-05-15 01:45:59 +05:30
|
|
|
window = self.top.toplevel
|
2009-04-12 02:42:14 +05:30
|
|
|
self.set_window(window,self.top.get_object('title'),self.label)
|
|
|
|
|
|
|
|
for option in self.options.handler.options_dict:
|
|
|
|
if option in ['estimate_age', 'invdate']:
|
|
|
|
self.top.get_object(option).set_active(
|
|
|
|
self.options.handler.options_dict[option]
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
self.top.get_object(option).set_value(
|
|
|
|
self.options.handler.options_dict[option]
|
|
|
|
)
|
2009-04-12 23:59:28 +05:30
|
|
|
self.window.show()
|
2004-05-11 07:21:56 +05:30
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def build_menu_names(self, obj):
|
2006-04-27 08:05:47 +05:30
|
|
|
return (_("Tool settings"),self.label)
|
2004-05-11 07:21:56 +05:30
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def on_help_clicked(self, obj):
|
2005-03-24 08:57:02 +05:30
|
|
|
"""Display the relevant portion of GRAMPS manual"""
|
2008-04-05 19:47:15 +05:30
|
|
|
GrampsDisplay.help(webpage=WIKI_HELP_PAGE, section=WIKI_HELP_SEC)
|
2005-03-24 08:57:02 +05:30
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def on_apply_clicked(self, obj):
|
2009-04-12 02:42:14 +05:30
|
|
|
for option in self.options.handler.options_dict:
|
|
|
|
if option in ['estimate_age', 'invdate']:
|
|
|
|
self.options.handler.options_dict[option] = \
|
|
|
|
self.top.get_object(option).get_active()
|
|
|
|
else:
|
|
|
|
self.options.handler.options_dict[option] = \
|
|
|
|
self.top.get_object(option).get_value_as_int()
|
|
|
|
|
2008-01-05 04:54:51 +05:30
|
|
|
try:
|
|
|
|
self.vr = VerifyResults(self.dbstate, self.uistate, self.track)
|
|
|
|
self.add_results = self.vr.add_results
|
|
|
|
self.vr.load_ignored(self.db.full_name)
|
|
|
|
except Errors.WindowActiveError:
|
|
|
|
pass
|
|
|
|
|
2006-05-26 05:29:51 +05:30
|
|
|
self.uistate.window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
|
|
|
|
self.uistate.progress.show()
|
2006-05-26 05:49:20 +05:30
|
|
|
self.window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
|
2007-05-15 09:47:12 +05:30
|
|
|
try:
|
2008-01-05 04:54:51 +05:30
|
|
|
self.vr.window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
|
2007-05-15 09:47:12 +05:30
|
|
|
except AttributeError:
|
|
|
|
pass
|
2006-05-26 05:29:51 +05:30
|
|
|
|
|
|
|
self.run_tool(cli=False)
|
|
|
|
|
|
|
|
self.uistate.progress.hide()
|
|
|
|
self.uistate.window.window.set_cursor(None)
|
2006-05-26 05:49:20 +05:30
|
|
|
self.window.window.set_cursor(None)
|
2007-05-15 09:47:12 +05:30
|
|
|
try:
|
2008-01-05 04:54:51 +05:30
|
|
|
self.vr.window.window.set_cursor(None)
|
2007-05-15 09:47:12 +05:30
|
|
|
except AttributeError:
|
|
|
|
pass
|
2006-05-27 05:08:21 +05:30
|
|
|
self.reset()
|
2006-05-26 05:29:51 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
# Save options
|
|
|
|
self.options.handler.save_options()
|
2006-05-26 05:29:51 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
def run_tool(self,cli=False):
|
2004-05-08 08:59:21 +05:30
|
|
|
|
2009-07-04 01:53:41 +05:30
|
|
|
person_handles = self.db.iter_person_handles()
|
2009-04-12 02:42:14 +05:30
|
|
|
|
|
|
|
for option, value in \
|
|
|
|
self.options.handler.options_dict.iteritems():
|
|
|
|
exec '%s = %s' % (option, value)
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2008-01-05 04:54:51 +05:30
|
|
|
self.vr.real_model.clear()
|
2004-05-08 08:59:21 +05:30
|
|
|
|
2006-05-26 05:29:51 +05:30
|
|
|
self.set_total(self.db.get_number_of_people() +
|
|
|
|
self.db.get_number_of_families())
|
2006-05-25 10:48:03 +05:30
|
|
|
|
|
|
|
for person_handle in person_handles:
|
|
|
|
person = find_person(self.db,person_handle)
|
|
|
|
|
2006-05-27 01:48:33 +05:30
|
|
|
rule_list = [
|
|
|
|
BirthAfterBapt(self.db,person),
|
|
|
|
DeathBeforeBapt(self.db,person),
|
|
|
|
BirthAfterBury(self.db,person),
|
|
|
|
DeathAfterBury(self.db,person),
|
|
|
|
BirthAfterDeath(self.db,person),
|
|
|
|
BaptAfterBury(self.db,person),
|
2008-02-24 19:25:55 +05:30
|
|
|
OldAge(self.db,person, oldage,estimate_age),
|
2006-05-27 01:48:33 +05:30
|
|
|
UnknownGender(self.db,person),
|
|
|
|
MultipleParents(self.db,person),
|
|
|
|
MarriedOften(self.db,person,wedder),
|
2008-02-24 19:25:55 +05:30
|
|
|
OldUnmarried(self.db,person, oldunm,estimate_age),
|
2006-05-27 01:48:33 +05:30
|
|
|
TooManyChildren(self.db,person,mxchilddad,mxchildmom),
|
2006-08-17 00:10:10 +05:30
|
|
|
Disconnected(self.db,person),
|
2008-04-20 19:06:28 +05:30
|
|
|
InvalidBirthDate(self.db,person,invdate),
|
|
|
|
InvalidDeathDate(self.db,person,invdate),
|
2006-05-27 01:48:33 +05:30
|
|
|
]
|
|
|
|
|
|
|
|
for rule in rule_list:
|
|
|
|
if rule.broken():
|
2006-05-27 04:41:37 +05:30
|
|
|
self.add_results(rule.report_itself())
|
|
|
|
|
2006-05-27 01:48:33 +05:30
|
|
|
clear_cache()
|
2007-03-19 00:50:09 +05:30
|
|
|
if not cli:
|
|
|
|
self.update()
|
2006-05-26 05:29:51 +05:30
|
|
|
|
|
|
|
# Family-based rules
|
2009-07-08 21:41:20 +05:30
|
|
|
for family_handle in self.db.iter_family_handles():
|
2006-05-26 05:29:51 +05:30
|
|
|
family = find_family(self.db,family_handle)
|
|
|
|
|
2006-05-27 01:48:33 +05:30
|
|
|
rule_list = [
|
|
|
|
SameSexFamily(self.db,family),
|
|
|
|
FemaleHusband(self.db,family),
|
|
|
|
MaleWife(self.db,family),
|
|
|
|
SameSurnameFamily(self.db,family),
|
2008-02-24 19:25:55 +05:30
|
|
|
LargeAgeGapFamily(self.db,family, hwdif,estimate_age),
|
2006-05-27 01:48:33 +05:30
|
|
|
MarriageBeforeBirth(self.db,family,estimate_age),
|
|
|
|
MarriageAfterDeath(self.db,family,estimate_age),
|
|
|
|
EarlyMarriage(self.db,family,yngmar,estimate_age),
|
2008-02-24 19:25:55 +05:30
|
|
|
LateMarriage(self.db,family, oldmar,estimate_age),
|
|
|
|
OldParent(self.db,family, oldmom, olddad,estimate_age),
|
2006-05-27 01:48:33 +05:30
|
|
|
YoungParent(self.db,family,yngmom,yngdad,estimate_age),
|
|
|
|
UnbornParent(self.db,family,estimate_age),
|
|
|
|
DeadParent(self.db,family,estimate_age),
|
|
|
|
LargeChildrenSpan(self.db,family,cbspan,estimate_age),
|
|
|
|
LargeChildrenAgeDiff(self.db,family,cspace,estimate_age),
|
|
|
|
]
|
|
|
|
|
|
|
|
for rule in rule_list:
|
|
|
|
if rule.broken():
|
2006-05-27 04:41:37 +05:30
|
|
|
self.add_results(rule.report_itself())
|
2006-05-27 01:48:33 +05:30
|
|
|
|
|
|
|
clear_cache()
|
2007-03-19 00:50:09 +05:30
|
|
|
if not cli:
|
|
|
|
self.update()
|
2006-05-26 05:29:51 +05:30
|
|
|
|
2005-03-24 08:57:02 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Display the results
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-05-26 05:29:51 +05:30
|
|
|
class VerifyResults(ManagedWindow):
|
2006-05-29 07:41:37 +05:30
|
|
|
IGNORE_COL = 0
|
|
|
|
WARNING_COL = 1
|
|
|
|
OBJ_ID_COL = 2
|
|
|
|
OBJ_NAME_COL = 3
|
|
|
|
OBJ_TYPE_COL = 4
|
|
|
|
RULE_ID_COL = 5
|
|
|
|
OBJ_HANDLE_COL = 6
|
|
|
|
FG_COLOR_COL = 7
|
|
|
|
TRUE_COL = 8
|
|
|
|
SHOW_COL = 9
|
|
|
|
|
2006-05-29 07:08:44 +05:30
|
|
|
def __init__(self,dbstate,uistate,track):
|
2006-04-27 08:05:47 +05:30
|
|
|
self.title = _('Database Verification Results')
|
2006-04-10 04:23:53 +05:30
|
|
|
|
2006-05-26 05:29:51 +05:30
|
|
|
ManagedWindow.__init__(self,uistate,track,self.__class__)
|
2005-03-24 08:57:02 +05:30
|
|
|
|
2006-05-29 07:08:44 +05:30
|
|
|
self.dbstate = dbstate
|
2009-05-15 01:45:59 +05:30
|
|
|
self.top = Glade(toplevel="verify_result")
|
|
|
|
window = self.top.toplevel
|
2009-04-12 02:42:14 +05:30
|
|
|
self.set_window(window,self.top.get_object('title'),self.title)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2009-04-12 02:42:14 +05:30
|
|
|
self.top.connect_signals({
|
2006-04-27 08:05:47 +05:30
|
|
|
"destroy_passed_object" : self.close,
|
|
|
|
})
|
|
|
|
|
2009-04-12 02:42:14 +05:30
|
|
|
self.warn_tree = self.top.get_object('warn_tree')
|
2006-05-29 07:08:44 +05:30
|
|
|
self.warn_tree.connect('button_press_event', self.double_click)
|
|
|
|
|
|
|
|
self.selection = self.warn_tree.get_selection()
|
|
|
|
|
2009-04-12 02:42:14 +05:30
|
|
|
self.hide_button = self.top.get_object('hide_button')
|
2006-05-27 04:41:37 +05:30
|
|
|
self.hide_button.connect('toggled',self.hide_toggled)
|
|
|
|
|
2009-04-12 02:42:14 +05:30
|
|
|
self.mark_button = self.top.get_object('mark_all')
|
2006-05-29 07:08:44 +05:30
|
|
|
self.mark_button.connect('clicked',self.mark_clicked)
|
|
|
|
|
2009-04-12 02:42:14 +05:30
|
|
|
self.unmark_button = self.top.get_object('unmark_all')
|
2006-05-29 07:08:44 +05:30
|
|
|
self.unmark_button.connect('clicked',self.unmark_clicked)
|
|
|
|
|
2009-04-12 02:42:14 +05:30
|
|
|
self.invert_button = self.top.get_object('invert_all')
|
2006-05-29 07:08:44 +05:30
|
|
|
self.invert_button.connect('clicked',self.invert_clicked)
|
|
|
|
|
2008-01-22 03:33:43 +05:30
|
|
|
self.real_model = gtk.ListStore(gobject.TYPE_BOOLEAN,
|
|
|
|
gobject.TYPE_STRING,
|
|
|
|
gobject.TYPE_STRING,
|
|
|
|
gobject.TYPE_STRING,
|
|
|
|
gobject.TYPE_STRING, object,
|
|
|
|
gobject.TYPE_STRING,
|
|
|
|
gobject.TYPE_STRING,
|
|
|
|
gobject.TYPE_BOOLEAN,
|
|
|
|
gobject.TYPE_BOOLEAN)
|
2006-05-28 14:06:29 +05:30
|
|
|
self.filt_model = self.real_model.filter_new()
|
2006-05-29 09:04:26 +05:30
|
|
|
self.filt_model.set_visible_column(VerifyResults.TRUE_COL)
|
2006-05-28 14:06:29 +05:30
|
|
|
self.sort_model = gtk.TreeModelSort(self.filt_model)
|
|
|
|
self.warn_tree.set_model(self.sort_model)
|
2006-05-26 05:29:51 +05:30
|
|
|
|
|
|
|
self.renderer = gtk.CellRendererText()
|
|
|
|
self.img_renderer = gtk.CellRendererPixbuf()
|
2006-05-27 04:41:37 +05:30
|
|
|
self.bool_renderer = gtk.CellRendererToggle()
|
|
|
|
self.bool_renderer.connect('toggled',self.selection_toggled)
|
|
|
|
|
2006-05-29 09:04:26 +05:30
|
|
|
# Add ignore column
|
|
|
|
ignore_column = gtk.TreeViewColumn(_('Mark'),self.bool_renderer,
|
|
|
|
active=VerifyResults.IGNORE_COL)
|
|
|
|
ignore_column.set_sort_column_id(VerifyResults.IGNORE_COL)
|
|
|
|
self.warn_tree.append_column(ignore_column)
|
2004-05-11 07:21:56 +05:30
|
|
|
|
2006-05-29 09:04:26 +05:30
|
|
|
# Add image column
|
2006-05-27 04:41:37 +05:30
|
|
|
img_column = gtk.TreeViewColumn(None, self.img_renderer )
|
|
|
|
img_column.set_cell_data_func(self.img_renderer,self.get_image)
|
2006-05-29 09:04:26 +05:30
|
|
|
self.warn_tree.append_column(img_column)
|
2006-05-26 05:29:51 +05:30
|
|
|
|
2006-05-29 09:04:26 +05:30
|
|
|
# Add column with the warning text
|
2006-05-28 09:47:46 +05:30
|
|
|
warn_column = gtk.TreeViewColumn(_('Warning'), self.renderer,
|
2006-05-29 09:04:26 +05:30
|
|
|
text=VerifyResults.WARNING_COL,
|
|
|
|
foreground=VerifyResults.FG_COLOR_COL)
|
|
|
|
warn_column.set_sort_column_id(VerifyResults.WARNING_COL)
|
2006-05-28 09:47:46 +05:30
|
|
|
self.warn_tree.append_column(warn_column)
|
|
|
|
|
2006-05-29 09:04:26 +05:30
|
|
|
# Add column with object gramps_id
|
2006-05-28 09:47:46 +05:30
|
|
|
id_column = gtk.TreeViewColumn(_('ID'), self.renderer,
|
2006-05-29 09:04:26 +05:30
|
|
|
text=VerifyResults.OBJ_ID_COL,
|
|
|
|
foreground=VerifyResults.FG_COLOR_COL)
|
|
|
|
id_column.set_sort_column_id(VerifyResults.OBJ_ID_COL)
|
2006-05-28 09:47:46 +05:30
|
|
|
self.warn_tree.append_column(id_column)
|
|
|
|
|
2006-05-29 09:04:26 +05:30
|
|
|
# Add column with object name
|
2006-05-28 09:47:46 +05:30
|
|
|
name_column = gtk.TreeViewColumn(_('Name'), self.renderer,
|
2006-05-29 09:04:26 +05:30
|
|
|
text=VerifyResults.OBJ_NAME_COL,
|
|
|
|
foreground=VerifyResults.FG_COLOR_COL)
|
2006-05-29 09:11:14 +05:30
|
|
|
name_column.set_sort_column_id(VerifyResults.OBJ_NAME_COL)
|
2006-05-28 09:47:46 +05:30
|
|
|
self.warn_tree.append_column(name_column)
|
2006-05-27 04:41:37 +05:30
|
|
|
|
2009-04-12 23:59:28 +05:30
|
|
|
self.window.show()
|
2006-05-26 05:29:51 +05:30
|
|
|
self.window_shown = False
|
|
|
|
|
2006-05-27 04:41:37 +05:30
|
|
|
def load_ignored(self,db_filename):
|
2008-12-05 03:14:12 +05:30
|
|
|
md5sum = md5(db_filename)
|
2006-05-27 04:41:37 +05:30
|
|
|
self.ignores_filename = os.path.join(
|
2007-09-08 11:24:02 +05:30
|
|
|
const.HOME_DIR,md5sum.hexdigest() + os.path.extsep + 'vfm')
|
2006-05-27 04:41:37 +05:30
|
|
|
if not self._load_ignored(self.ignores_filename):
|
|
|
|
self.ignores = {}
|
|
|
|
|
|
|
|
def _load_ignored(self,filename):
|
|
|
|
try:
|
|
|
|
f = open(filename)
|
|
|
|
self.ignores = cPickle.load(f)
|
|
|
|
f.close()
|
|
|
|
return True
|
|
|
|
except IOError:
|
|
|
|
return False
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def save_ignored(self, new_ignores):
|
2006-05-27 04:41:37 +05:30
|
|
|
self.ignores = new_ignores
|
|
|
|
self._save_ignored(self.ignores_filename)
|
|
|
|
|
|
|
|
def _save_ignored(self,filename):
|
|
|
|
try:
|
|
|
|
f = open(filename,'w')
|
|
|
|
cPickle.dump(self.ignores,f,1)
|
|
|
|
f.close()
|
|
|
|
return True
|
|
|
|
except IOError:
|
|
|
|
return False
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def get_marking(self, handle,rule_id):
|
2008-04-27 02:03:25 +05:30
|
|
|
if handle in self.ignores:
|
2006-05-27 04:41:37 +05:30
|
|
|
return (rule_id in self.ignores[handle])
|
2008-04-27 02:03:25 +05:30
|
|
|
else:
|
2006-05-27 04:41:37 +05:30
|
|
|
return False
|
|
|
|
|
|
|
|
def get_new_marking(self):
|
|
|
|
new_ignores = {}
|
2006-05-28 14:06:29 +05:30
|
|
|
for row_num in range(len(self.real_model)):
|
2006-05-27 04:41:37 +05:30
|
|
|
path = (row_num,)
|
2006-05-28 14:06:29 +05:30
|
|
|
row = self.real_model[path]
|
2006-05-29 07:41:37 +05:30
|
|
|
ignore = row[VerifyResults.IGNORE_COL]
|
2006-05-27 04:41:37 +05:30
|
|
|
if ignore:
|
2006-05-29 07:41:37 +05:30
|
|
|
handle = row[VerifyResults.OBJ_HANDLE_COL]
|
|
|
|
rule_id = row[VerifyResults.RULE_ID_COL]
|
2008-07-17 23:40:32 +05:30
|
|
|
if handle not in new_ignores:
|
2006-05-27 04:41:37 +05:30
|
|
|
new_ignores[handle] = set()
|
|
|
|
new_ignores[handle].add(rule_id)
|
|
|
|
return new_ignores
|
|
|
|
|
|
|
|
def close(self,*obj):
|
|
|
|
new_ignores = self.get_new_marking()
|
|
|
|
self.save_ignored(new_ignores)
|
|
|
|
|
|
|
|
ManagedWindow.close(self,*obj)
|
|
|
|
|
|
|
|
def hide_toggled(self,button):
|
|
|
|
if button.get_active():
|
2006-05-28 14:06:29 +05:30
|
|
|
button.set_label(_("_Show all"))
|
|
|
|
self.filt_model = self.real_model.filter_new()
|
2006-05-29 09:04:26 +05:30
|
|
|
self.filt_model.set_visible_column(VerifyResults.SHOW_COL)
|
2006-05-28 14:06:29 +05:30
|
|
|
self.sort_model = gtk.TreeModelSort(self.filt_model)
|
|
|
|
self.warn_tree.set_model(self.sort_model)
|
2006-05-27 04:41:37 +05:30
|
|
|
else:
|
2006-05-28 14:06:29 +05:30
|
|
|
self.filt_model = self.real_model.filter_new()
|
2006-05-29 09:04:26 +05:30
|
|
|
self.filt_model.set_visible_column(VerifyResults.TRUE_COL)
|
2006-05-28 14:06:29 +05:30
|
|
|
self.sort_model = gtk.TreeModelSort(self.filt_model)
|
|
|
|
self.warn_tree.set_model(self.sort_model)
|
2006-05-29 07:08:44 +05:30
|
|
|
button.set_label(_("_Hide marked"))
|
2006-05-27 04:41:37 +05:30
|
|
|
|
|
|
|
def selection_toggled(self,cell,path_string):
|
2006-05-28 14:06:29 +05:30
|
|
|
sort_path = tuple([int (i) for i in path_string.split(':')])
|
|
|
|
filt_path = self.sort_model.convert_path_to_child_path(sort_path)
|
|
|
|
real_path = self.filt_model.convert_path_to_child_path(filt_path)
|
|
|
|
row = self.real_model[real_path]
|
2006-05-29 07:41:37 +05:30
|
|
|
row[VerifyResults.IGNORE_COL] = not row[VerifyResults.IGNORE_COL]
|
|
|
|
row[VerifyResults.SHOW_COL] = not row[VerifyResults.IGNORE_COL]
|
2006-05-28 14:06:29 +05:30
|
|
|
self.real_model.row_changed(real_path,row.iter)
|
2006-05-27 04:41:37 +05:30
|
|
|
|
2006-05-29 07:08:44 +05:30
|
|
|
def mark_clicked(self,mark_button):
|
|
|
|
for row_num in range(len(self.real_model)):
|
|
|
|
path = (row_num,)
|
|
|
|
row = self.real_model[path]
|
2006-05-29 07:41:37 +05:30
|
|
|
row[VerifyResults.IGNORE_COL] = True
|
|
|
|
row[VerifyResults.SHOW_COL] = False
|
2006-05-29 07:08:44 +05:30
|
|
|
self.filt_model.refilter()
|
|
|
|
|
|
|
|
def unmark_clicked(self,unmark_button):
|
|
|
|
for row_num in range(len(self.real_model)):
|
|
|
|
path = (row_num,)
|
|
|
|
row = self.real_model[path]
|
2006-05-29 07:41:37 +05:30
|
|
|
row[VerifyResults.IGNORE_COL] = False
|
|
|
|
row[VerifyResults.SHOW_COL] = True
|
2006-05-29 07:08:44 +05:30
|
|
|
self.filt_model.refilter()
|
|
|
|
|
|
|
|
def invert_clicked(self,invert_button):
|
|
|
|
for row_num in range(len(self.real_model)):
|
|
|
|
path = (row_num,)
|
|
|
|
row = self.real_model[path]
|
2006-05-29 07:41:37 +05:30
|
|
|
row[VerifyResults.IGNORE_COL] = not row[VerifyResults.IGNORE_COL]
|
|
|
|
row[VerifyResults.SHOW_COL] = not row[VerifyResults.SHOW_COL]
|
2006-05-29 07:08:44 +05:30
|
|
|
self.filt_model.refilter()
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def double_click(self, obj,event):
|
2006-05-29 07:08:44 +05:30
|
|
|
if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1:
|
2008-02-24 19:25:55 +05:30
|
|
|
(model, node) = self.selection.get_selected()
|
2006-05-29 07:08:44 +05:30
|
|
|
if not node:
|
|
|
|
return
|
|
|
|
sort_path = self.sort_model.get_path(node)
|
|
|
|
filt_path = self.sort_model.convert_path_to_child_path(sort_path)
|
|
|
|
real_path = self.filt_model.convert_path_to_child_path(filt_path)
|
|
|
|
row = self.real_model[real_path]
|
2006-05-29 07:41:37 +05:30
|
|
|
the_type = row[VerifyResults.OBJ_TYPE_COL]
|
|
|
|
handle = row[VerifyResults.OBJ_HANDLE_COL]
|
2006-05-29 07:08:44 +05:30
|
|
|
if the_type == 'Person':
|
|
|
|
try:
|
|
|
|
from Editors import EditPerson
|
|
|
|
person = self.dbstate.db.get_person_from_handle(handle)
|
|
|
|
EditPerson(self.dbstate, self.uistate, [], person)
|
|
|
|
except Errors.WindowActiveError:
|
|
|
|
pass
|
|
|
|
elif the_type == 'Family':
|
|
|
|
try:
|
|
|
|
from Editors import EditFamily
|
|
|
|
family = self.dbstate.db.get_family_from_handle(handle)
|
|
|
|
EditFamily(self.dbstate, self.uistate, [], family)
|
|
|
|
except Errors.WindowActiveError:
|
|
|
|
pass
|
|
|
|
|
2006-05-26 05:29:51 +05:30
|
|
|
def get_image(self, column, cell, model, iter, user_data=None):
|
2006-05-29 07:41:37 +05:30
|
|
|
the_type = model.get_value(iter, VerifyResults.OBJ_TYPE_COL)
|
2006-05-26 05:29:51 +05:30
|
|
|
if the_type == 'Person':
|
|
|
|
cell.set_property('stock-id', 'gramps-person' )
|
|
|
|
elif the_type == 'Family':
|
|
|
|
cell.set_property('stock-id', 'gramps-family' )
|
|
|
|
|
|
|
|
def add_results(self,results):
|
2008-02-24 19:25:55 +05:30
|
|
|
(msg,gramps_id, name,the_type,rule_id,severity, handle) = results
|
2006-05-27 04:41:37 +05:30
|
|
|
ignore = self.get_marking(handle,rule_id)
|
2006-05-27 01:48:33 +05:30
|
|
|
if severity == Rule.ERROR:
|
|
|
|
fg = 'red'
|
2006-05-29 07:41:37 +05:30
|
|
|
# fg = '#8b008b' # purple
|
|
|
|
# elif severity == Rule.WARNING:
|
|
|
|
# fg = '#008b00' # green
|
2006-05-27 01:48:33 +05:30
|
|
|
else:
|
|
|
|
fg = None
|
2008-02-24 19:25:55 +05:30
|
|
|
self.real_model.append(row=[ignore,msg,gramps_id, name,
|
|
|
|
the_type,rule_id, handle,fg,
|
2006-05-28 09:47:46 +05:30
|
|
|
True, not ignore])
|
2006-05-26 05:29:51 +05:30
|
|
|
|
|
|
|
if not self.window_shown:
|
2009-04-12 23:59:28 +05:30
|
|
|
self.window.show()
|
2006-05-26 05:29:51 +05:30
|
|
|
self.window_shown = True
|
2006-04-27 08:05:47 +05:30
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def build_menu_names(self, obj):
|
2006-04-27 08:05:47 +05:30
|
|
|
return (self.title,None)
|
2004-05-11 07:21:56 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class VerifyOptions(Tool.ToolOptions):
|
|
|
|
"""
|
|
|
|
Defines options and provides handling interface.
|
|
|
|
"""
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def __init__(self, name,person_id=None):
|
|
|
|
Tool.ToolOptions.__init__(self, name,person_id)
|
2005-12-06 12:08:09 +05:30
|
|
|
|
|
|
|
# Options specific for this report
|
|
|
|
self.options_dict = {
|
|
|
|
'oldage' : 90,
|
|
|
|
'hwdif' : 30,
|
|
|
|
'cspace' : 8,
|
|
|
|
'cbspan' : 25,
|
|
|
|
'yngmar' : 17,
|
|
|
|
'oldmar' : 50,
|
|
|
|
'oldmom' : 48,
|
|
|
|
'yngmom' : 17,
|
|
|
|
'yngdad' : 18,
|
|
|
|
'olddad' : 65,
|
|
|
|
'wedder' : 3,
|
|
|
|
'mxchildmom' : 12,
|
|
|
|
'mxchilddad' : 15,
|
|
|
|
'lngwdw' : 30,
|
2006-05-26 05:29:51 +05:30
|
|
|
'oldunm' : 99,
|
2005-12-06 12:08:09 +05:30
|
|
|
'estimate_age' : 0,
|
2008-04-20 19:06:28 +05:30
|
|
|
'invdate' : 1,
|
2005-12-06 12:08:09 +05:30
|
|
|
}
|
|
|
|
self.options_help = {
|
|
|
|
'oldage' : ("=num","Maximum age","Age in years"),
|
|
|
|
'hwdif' : ("=num","Maximum husband-wife age difference",
|
|
|
|
"Age difference in years"),
|
|
|
|
'cspace' : ("=num",
|
|
|
|
"Maximum number of years between children",
|
|
|
|
"Number of years"),
|
|
|
|
'cbspan' : ("=num",
|
|
|
|
"Maximum span of years for all children",
|
|
|
|
"Span in years"),
|
|
|
|
'yngmar' : ("=num","Minimum age to marry","Age in years"),
|
|
|
|
'oldmar' : ("=num","Maximum age to marry","Age in years"),
|
|
|
|
'oldmom' : ("=num","Maximum age to bear a child",
|
|
|
|
"Age in years"),
|
|
|
|
'yngmom' : ("=num","Minimum age to bear a child",
|
|
|
|
"Age in years"),
|
|
|
|
'yngdad' : ("=num","Minimum age to father a child",
|
|
|
|
"Age in years"),
|
|
|
|
'olddad' : ("=num","Maximum age to father a child",
|
|
|
|
"Age in years"),
|
|
|
|
'wedder' : ("=num","Maximum number of spouses for a person",
|
|
|
|
"Number of spouses"),
|
|
|
|
'mxchildmom' : ("=num","Maximum number of children for a woman",
|
|
|
|
"Number of children"),
|
|
|
|
'mxchilddad' : ("=num","Maximum number of children for a man",
|
|
|
|
"Number of chidlren"),
|
|
|
|
'lngwdw' : ("=num","Maximum number of consecutive years "
|
2006-05-26 05:29:51 +05:30
|
|
|
"of widowhood before next marriage",
|
|
|
|
"Number of years"),
|
|
|
|
'oldunm' : ("=num","Maximum age for an unmarried person"
|
|
|
|
"Number of years"),
|
2005-12-06 12:08:09 +05:30
|
|
|
'estimate_age' : ("=0/1","Whether to estimate missing dates",
|
|
|
|
["Do not estimate","Estimate dates"],
|
|
|
|
True),
|
2008-04-20 19:06:28 +05:30
|
|
|
'invdate' : ("=0/1","Whether to check for invalid dates"
|
|
|
|
"Do not identify invalid dates",
|
|
|
|
"Identify invalid dates", True),
|
2005-12-06 12:08:09 +05:30
|
|
|
}
|
|
|
|
|
2006-05-25 10:48:03 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Base classes for different tests -- the rules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-05-21 22:49:50 +05:30
|
|
|
class Rule(object):
|
2006-05-25 10:48:03 +05:30
|
|
|
"""
|
|
|
|
Basic class for use in this tool.
|
|
|
|
|
|
|
|
Other rules must inherit from this.
|
|
|
|
"""
|
2006-05-26 05:29:51 +05:30
|
|
|
ID = 0
|
|
|
|
TYPE = ''
|
|
|
|
|
2006-05-25 10:48:03 +05:30
|
|
|
ERROR = 1
|
|
|
|
WARNING = 2
|
|
|
|
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = WARNING
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def __init__(self,db, obj):
|
2006-05-25 10:48:03 +05:30
|
|
|
self.db = db
|
2006-05-26 05:29:51 +05:30
|
|
|
self.obj = obj
|
2006-05-25 10:48:03 +05:30
|
|
|
|
|
|
|
def broken(self):
|
|
|
|
"""
|
|
|
|
Return boolean indicating whether this rule is violated.
|
|
|
|
"""
|
|
|
|
return False
|
|
|
|
|
|
|
|
def get_message(self):
|
|
|
|
assert False, "Need to be overriden in the derived class"
|
|
|
|
|
2006-05-26 05:29:51 +05:30
|
|
|
def get_name(self):
|
2006-05-25 10:48:03 +05:30
|
|
|
assert False, "Need to be overriden in the derived class"
|
|
|
|
|
2006-05-26 05:29:51 +05:30
|
|
|
def get_handle(self):
|
|
|
|
return self.obj.handle
|
|
|
|
|
|
|
|
def get_id(self):
|
|
|
|
return self.obj.gramps_id
|
|
|
|
|
2006-05-25 10:48:03 +05:30
|
|
|
def get_level(self):
|
|
|
|
return Rule.WARNING
|
|
|
|
|
2006-05-29 07:41:37 +05:30
|
|
|
def get_rule_id(self):
|
|
|
|
params = self._get_params()
|
|
|
|
return (self.ID,params)
|
|
|
|
|
|
|
|
def _get_params(self):
|
|
|
|
return tuple()
|
|
|
|
|
2006-05-26 05:29:51 +05:30
|
|
|
def report_itself(self):
|
|
|
|
handle = self.get_handle()
|
|
|
|
the_type = self.TYPE
|
2006-05-29 07:41:37 +05:30
|
|
|
rule_id = self.get_rule_id()
|
2006-05-27 01:48:33 +05:30
|
|
|
severity = self.SEVERITY
|
2006-05-26 05:29:51 +05:30
|
|
|
name = self.get_name()
|
|
|
|
gramps_id = self.get_id()
|
|
|
|
msg = self.get_message()
|
2008-02-24 19:25:55 +05:30
|
|
|
return (msg,gramps_id, name,the_type,rule_id,severity, handle)
|
2006-05-26 05:29:51 +05:30
|
|
|
|
2006-05-25 10:48:03 +05:30
|
|
|
class PersonRule(Rule):
|
|
|
|
"""
|
|
|
|
Person-based class.
|
|
|
|
"""
|
2006-05-26 05:29:51 +05:30
|
|
|
TYPE = 'Person'
|
|
|
|
def get_name(self):
|
|
|
|
return self.obj.get_primary_name().get_name()
|
2006-05-25 10:48:03 +05:30
|
|
|
|
|
|
|
class FamilyRule(Rule):
|
|
|
|
"""
|
|
|
|
Family-based class.
|
|
|
|
"""
|
2006-05-26 05:29:51 +05:30
|
|
|
TYPE = 'Family'
|
|
|
|
def get_name(self):
|
|
|
|
return Utils.family_name(self.obj,self.db)
|
2006-05-25 10:48:03 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Actual rules for testing
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class BirthAfterBapt(PersonRule):
|
2006-05-26 05:29:51 +05:30
|
|
|
ID = 1
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = Rule.ERROR
|
2006-05-25 10:48:03 +05:30
|
|
|
def broken(self):
|
|
|
|
birth_date = get_birth_date(self.db,self.obj)
|
|
|
|
bapt_date = get_bapt_date(self.db,self.obj)
|
|
|
|
birth_ok = birth_date > 0
|
|
|
|
bapt_ok = bapt_date > 0
|
|
|
|
birth_after_death = birth_date > bapt_date
|
|
|
|
return (birth_ok and bapt_ok and birth_after_death)
|
|
|
|
|
|
|
|
def get_message(self):
|
|
|
|
return _("Baptism before birth")
|
|
|
|
|
|
|
|
class DeathBeforeBapt(PersonRule):
|
2006-05-26 05:29:51 +05:30
|
|
|
ID = 2
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = Rule.ERROR
|
2006-05-25 10:48:03 +05:30
|
|
|
def broken(self):
|
|
|
|
death_date = get_death_date(self.db,self.obj)
|
|
|
|
bapt_date = get_bapt_date(self.db,self.obj)
|
|
|
|
bapt_ok = bapt_date > 0
|
|
|
|
death_ok = death_date > 0
|
|
|
|
death_before_bapt = bapt_date > death_date
|
|
|
|
return (death_ok and bapt_ok and death_before_bapt)
|
|
|
|
|
|
|
|
def get_message(self):
|
|
|
|
return _("Death before baptism")
|
|
|
|
|
|
|
|
class BirthAfterBury(PersonRule):
|
2006-05-26 05:29:51 +05:30
|
|
|
ID = 3
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = Rule.ERROR
|
2006-05-25 10:48:03 +05:30
|
|
|
def broken(self):
|
|
|
|
birth_date = get_birth_date(self.db,self.obj)
|
|
|
|
bury_date = get_bury_date(self.db,self.obj)
|
|
|
|
birth_ok = birth_date > 0
|
|
|
|
bury_ok = bury_date > 0
|
|
|
|
birth_after_bury = birth_date > bury_date
|
|
|
|
return (birth_ok and bury_ok and birth_after_bury)
|
|
|
|
|
|
|
|
def get_message(self):
|
|
|
|
return _("Burial before birth")
|
|
|
|
|
|
|
|
class DeathAfterBury(PersonRule):
|
2006-05-26 05:29:51 +05:30
|
|
|
ID = 4
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = Rule.ERROR
|
2006-05-25 10:48:03 +05:30
|
|
|
def broken(self):
|
|
|
|
death_date = get_death_date(self.db,self.obj)
|
|
|
|
bury_date = get_bury_date(self.db,self.obj)
|
|
|
|
death_ok = death_date > 0
|
|
|
|
bury_ok = bury_date > 0
|
|
|
|
death_after_bury = death_date > bury_date
|
|
|
|
return (death_ok and bury_ok and death_after_bury)
|
|
|
|
|
|
|
|
def get_message(self):
|
|
|
|
return _("Burial before death")
|
|
|
|
|
|
|
|
class BirthAfterDeath(PersonRule):
|
2006-05-26 05:29:51 +05:30
|
|
|
ID = 5
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = Rule.ERROR
|
2006-05-25 10:48:03 +05:30
|
|
|
def broken(self):
|
|
|
|
birth_date = get_birth_date(self.db,self.obj)
|
|
|
|
death_date = get_death_date(self.db,self.obj)
|
|
|
|
birth_ok = birth_date > 0
|
|
|
|
death_ok = death_date > 0
|
|
|
|
birth_after_death = birth_date > death_date
|
|
|
|
return (birth_ok and death_ok and birth_after_death)
|
|
|
|
|
|
|
|
def get_message(self):
|
|
|
|
return _("Death before birth")
|
|
|
|
|
|
|
|
class BaptAfterBury(PersonRule):
|
2006-05-26 05:29:51 +05:30
|
|
|
ID = 6
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = Rule.ERROR
|
2006-05-25 10:48:03 +05:30
|
|
|
def broken(self):
|
|
|
|
bapt_date = get_bapt_date(self.db,self.obj)
|
|
|
|
bury_date = get_bury_date(self.db,self.obj)
|
|
|
|
bapt_ok = bapt_date > 0
|
|
|
|
bury_ok = bury_date > 0
|
|
|
|
bapt_after_bury = bapt_date > bury_date
|
|
|
|
return (bapt_ok and bury_ok and bapt_after_bury)
|
|
|
|
|
|
|
|
def get_message(self):
|
|
|
|
return _("Burial before baptism")
|
|
|
|
|
|
|
|
class OldAge(PersonRule):
|
2006-05-26 05:29:51 +05:30
|
|
|
ID = 7
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = Rule.WARNING
|
2008-02-24 19:25:55 +05:30
|
|
|
def __init__(self,db,person, old_age,est):
|
2006-05-25 10:48:03 +05:30
|
|
|
PersonRule.__init__(self,db,person)
|
|
|
|
self.old_age = old_age
|
2006-05-26 05:29:51 +05:30
|
|
|
self.est = est
|
2006-05-25 10:48:03 +05:30
|
|
|
|
2006-05-29 07:41:37 +05:30
|
|
|
def _get_params(self):
|
|
|
|
return (self.old_age,self.est)
|
|
|
|
|
2006-05-25 10:48:03 +05:30
|
|
|
def broken(self):
|
2006-05-26 05:29:51 +05:30
|
|
|
age_at_death = get_age_at_death(self.db,self.obj,self.est)
|
2006-05-29 07:08:44 +05:30
|
|
|
return (age_at_death/365 > self.old_age)
|
2006-05-25 10:48:03 +05:30
|
|
|
|
|
|
|
def get_message(self):
|
|
|
|
return _("Old age at death")
|
|
|
|
|
|
|
|
class UnknownGender(PersonRule):
|
2006-05-26 05:29:51 +05:30
|
|
|
ID = 8
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = Rule.WARNING
|
2006-05-25 10:48:03 +05:30
|
|
|
def broken(self):
|
2007-10-08 22:11:39 +05:30
|
|
|
female = self.obj.get_gender() == gen.lib.Person.FEMALE
|
|
|
|
male = self.obj.get_gender() == gen.lib.Person.MALE
|
2006-05-27 04:48:36 +05:30
|
|
|
return not (male or female)
|
2006-05-25 10:48:03 +05:30
|
|
|
|
|
|
|
def get_message(self):
|
|
|
|
return _("Unknown gender")
|
|
|
|
|
|
|
|
class MultipleParents(PersonRule):
|
2006-05-26 05:29:51 +05:30
|
|
|
ID = 9
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = Rule.WARNING
|
2006-05-25 10:48:03 +05:30
|
|
|
def broken(self):
|
|
|
|
n_parent_sets = len(self.obj.get_parent_family_handle_list())
|
|
|
|
return (n_parent_sets>1)
|
|
|
|
|
|
|
|
def get_message(self):
|
|
|
|
return _("Multiple parents")
|
|
|
|
|
|
|
|
class MarriedOften(PersonRule):
|
2006-05-26 05:29:51 +05:30
|
|
|
ID = 10
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = Rule.WARNING
|
2006-05-25 10:48:03 +05:30
|
|
|
def __init__(self,db,person,wedder):
|
|
|
|
PersonRule.__init__(self,db,person)
|
|
|
|
self.wedder = wedder
|
|
|
|
|
2006-05-29 07:41:37 +05:30
|
|
|
def _get_params(self):
|
|
|
|
return (self.wedder,)
|
|
|
|
|
2006-05-25 10:48:03 +05:30
|
|
|
def broken(self):
|
|
|
|
n_spouses = len(self.obj.get_family_handle_list())
|
|
|
|
return (n_spouses>self.wedder)
|
|
|
|
|
|
|
|
def get_message(self):
|
|
|
|
return _("Married often")
|
|
|
|
|
|
|
|
class OldUnmarried(PersonRule):
|
2006-05-26 05:29:51 +05:30
|
|
|
ID = 11
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = Rule.WARNING
|
2008-02-24 19:25:55 +05:30
|
|
|
def __init__(self,db,person, old_unm,est):
|
2006-05-25 10:48:03 +05:30
|
|
|
PersonRule.__init__(self,db,person)
|
|
|
|
self.old_unm = old_unm
|
2006-05-26 05:29:51 +05:30
|
|
|
self.est = est
|
2006-05-25 10:48:03 +05:30
|
|
|
|
2006-05-29 07:41:37 +05:30
|
|
|
def _get_params(self):
|
|
|
|
return (self.old_unm,self.est)
|
|
|
|
|
2006-05-25 10:48:03 +05:30
|
|
|
def broken(self):
|
2006-05-26 05:29:51 +05:30
|
|
|
age_at_death = get_age_at_death(self.db,self.obj,self.est)
|
2006-05-25 10:48:03 +05:30
|
|
|
n_spouses = len(self.obj.get_family_handle_list())
|
2006-05-29 07:08:44 +05:30
|
|
|
return (age_at_death/365>self.old_unm and n_spouses==0)
|
2006-05-25 10:48:03 +05:30
|
|
|
|
|
|
|
def get_message(self):
|
|
|
|
return _("Old and unmarried")
|
|
|
|
|
2006-05-26 05:29:51 +05:30
|
|
|
class TooManyChildren(PersonRule):
|
|
|
|
ID = 12
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = Rule.WARNING
|
2008-02-24 19:25:55 +05:30
|
|
|
def __init__(self,db, obj,mx_child_dad,mx_child_mom):
|
|
|
|
PersonRule.__init__(self,db, obj)
|
2006-05-26 05:29:51 +05:30
|
|
|
self.mx_child_dad = mx_child_dad
|
|
|
|
self.mx_child_mom = mx_child_mom
|
|
|
|
|
2006-05-29 07:41:37 +05:30
|
|
|
def _get_params(self):
|
|
|
|
return (self.mx_child_dad,self.mx_child_mom)
|
|
|
|
|
2006-05-26 05:29:51 +05:30
|
|
|
def broken(self):
|
|
|
|
n_child = get_n_children(self.db,self.obj)
|
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if (self.obj.get_gender == gen.lib.Person.MALE) \
|
2006-05-26 05:29:51 +05:30
|
|
|
and (n_child > self.mx_child_dad):
|
|
|
|
return True
|
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
if (self.obj.get_gender == gen.lib.Person.FEMALE) \
|
2006-05-26 05:29:51 +05:30
|
|
|
and (n_child > self.mx_child_mom):
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
def get_message(self):
|
|
|
|
return _("Too many children")
|
|
|
|
|
2006-05-25 10:48:03 +05:30
|
|
|
class SameSexFamily(FamilyRule):
|
2006-05-26 05:29:51 +05:30
|
|
|
ID = 13
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = Rule.WARNING
|
2006-05-25 10:48:03 +05:30
|
|
|
def broken(self):
|
|
|
|
mother = get_mother(self.db,self.obj)
|
|
|
|
father = get_father(self.db,self.obj)
|
2006-05-26 05:40:45 +05:30
|
|
|
same_sex = (mother and father and
|
|
|
|
(mother.get_gender() == father.get_gender()))
|
2006-05-26 05:49:20 +05:30
|
|
|
unknown_sex = (mother and
|
2007-10-08 22:11:39 +05:30
|
|
|
(mother.get_gender() == gen.lib.Person.UNKNOWN))
|
2006-05-25 10:48:03 +05:30
|
|
|
return (same_sex and not unknown_sex)
|
|
|
|
|
|
|
|
def get_message(self):
|
|
|
|
return _("Same sex marriage")
|
|
|
|
|
|
|
|
class FemaleHusband(FamilyRule):
|
2006-05-26 05:29:51 +05:30
|
|
|
ID = 14
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = Rule.WARNING
|
2006-05-25 10:48:03 +05:30
|
|
|
def broken(self):
|
|
|
|
father = get_father(self.db,self.obj)
|
2007-10-08 22:11:39 +05:30
|
|
|
return (father and (father.get_gender() == gen.lib.Person.FEMALE))
|
2006-05-25 10:48:03 +05:30
|
|
|
|
|
|
|
def get_message(self):
|
|
|
|
return _("Female husband")
|
|
|
|
|
|
|
|
class MaleWife(FamilyRule):
|
2006-05-26 05:29:51 +05:30
|
|
|
ID = 15
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = Rule.WARNING
|
2006-05-25 10:48:03 +05:30
|
|
|
def broken(self):
|
|
|
|
mother = get_mother(self.db,self.obj)
|
2007-10-08 22:11:39 +05:30
|
|
|
return (mother and (mother.get_gender() == gen.lib.Person.MALE))
|
2006-05-25 10:48:03 +05:30
|
|
|
|
|
|
|
def get_message(self):
|
|
|
|
return _("Male wife")
|
|
|
|
|
|
|
|
class SameSurnameFamily(FamilyRule):
|
2006-05-26 05:29:51 +05:30
|
|
|
ID = 16
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = Rule.WARNING
|
2006-05-25 10:48:03 +05:30
|
|
|
def broken(self):
|
2008-02-21 09:34:37 +05:30
|
|
|
mother = get_mother(self.db, self.obj)
|
|
|
|
father = get_father(self.db, self.obj)
|
|
|
|
_broken = False
|
|
|
|
|
|
|
|
# Make sure both mother and father exist.
|
|
|
|
if mother and father:
|
|
|
|
mname = mother.get_primary_name()
|
|
|
|
fname = father.get_primary_name()
|
|
|
|
# Only compare birth names (not married names).
|
|
|
|
if mname.get_type() == gen.lib.NameType.BIRTH and \
|
|
|
|
fname.get_type() == gen.lib.NameType.BIRTH:
|
|
|
|
# Empty names don't count.
|
|
|
|
if len(mname.get_surname()) != 0 and \
|
|
|
|
len(fname.get_surname()) != 0:
|
|
|
|
# Finally, check if the names are the same.
|
|
|
|
if mname.get_surname() == fname.get_surname():
|
|
|
|
_broken = True
|
|
|
|
|
|
|
|
return _broken
|
2006-05-25 10:48:03 +05:30
|
|
|
|
|
|
|
def get_message(self):
|
|
|
|
return _("Husband and wife with the same surname")
|
|
|
|
|
|
|
|
class LargeAgeGapFamily(FamilyRule):
|
2006-05-26 05:29:51 +05:30
|
|
|
ID = 17
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = Rule.WARNING
|
2008-02-24 19:25:55 +05:30
|
|
|
def __init__(self,db, obj, hw_diff,est):
|
|
|
|
FamilyRule.__init__(self,db, obj)
|
2006-05-25 10:48:03 +05:30
|
|
|
self.hw_diff = hw_diff
|
2006-05-26 05:29:51 +05:30
|
|
|
self.est = est
|
2006-05-25 10:48:03 +05:30
|
|
|
|
2006-05-29 07:41:37 +05:30
|
|
|
def _get_params(self):
|
|
|
|
return (self.hw_diff,self.est)
|
|
|
|
|
2006-05-25 10:48:03 +05:30
|
|
|
def broken(self):
|
|
|
|
mother = get_mother(self.db,self.obj)
|
|
|
|
father = get_father(self.db,self.obj)
|
2006-05-26 05:29:51 +05:30
|
|
|
mother_birth_date = get_birth_date(self.db,mother,self.est)
|
|
|
|
father_birth_date = get_birth_date(self.db,father,self.est)
|
2006-05-25 10:48:03 +05:30
|
|
|
mother_birth_date_ok = mother_birth_date > 0
|
|
|
|
father_birth_date_ok = father_birth_date > 0
|
2006-05-29 07:08:44 +05:30
|
|
|
large_diff = \
|
|
|
|
abs(father_birth_date-mother_birth_date)/365 > self.hw_diff
|
2006-05-25 10:48:03 +05:30
|
|
|
return (mother_birth_date_ok and father_birth_date_ok and large_diff)
|
|
|
|
|
|
|
|
def get_message(self):
|
2006-05-26 05:29:51 +05:30
|
|
|
return _("Large age difference between spouses")
|
2006-05-25 10:48:03 +05:30
|
|
|
|
|
|
|
class MarriageBeforeBirth(FamilyRule):
|
2006-05-26 05:29:51 +05:30
|
|
|
ID = 18
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = Rule.ERROR
|
2008-02-24 19:25:55 +05:30
|
|
|
def __init__(self,db, obj,est):
|
|
|
|
FamilyRule.__init__(self,db, obj)
|
2006-05-26 05:29:51 +05:30
|
|
|
self.est = est
|
|
|
|
|
2006-05-29 07:41:37 +05:30
|
|
|
def _get_params(self):
|
|
|
|
return (self.est,)
|
|
|
|
|
2006-05-25 10:48:03 +05:30
|
|
|
def broken(self):
|
|
|
|
marr_date = get_marriage_date(self.db,self.obj)
|
|
|
|
marr_date_ok = marr_date > 0
|
|
|
|
|
|
|
|
mother = get_mother(self.db,self.obj)
|
|
|
|
father = get_father(self.db,self.obj)
|
2006-05-26 05:29:51 +05:30
|
|
|
mother_birth_date = get_birth_date(self.db,mother,self.est)
|
|
|
|
father_birth_date = get_birth_date(self.db,father,self.est)
|
2006-05-25 10:48:03 +05:30
|
|
|
mother_birth_date_ok = mother_birth_date > 0
|
|
|
|
father_birth_date_ok = father_birth_date > 0
|
|
|
|
|
|
|
|
father_broken = (father_birth_date_ok and marr_date_ok
|
|
|
|
and (father_birth_date > marr_date))
|
|
|
|
mother_broken = (mother_birth_date_ok and marr_date_ok
|
|
|
|
and (mother_birth_date > marr_date))
|
|
|
|
|
|
|
|
return (father_broken or mother_broken)
|
|
|
|
|
|
|
|
def get_message(self):
|
|
|
|
return _("Marriage before birth")
|
|
|
|
|
|
|
|
class MarriageAfterDeath(FamilyRule):
|
2006-05-26 05:29:51 +05:30
|
|
|
ID = 19
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = Rule.ERROR
|
2008-02-24 19:25:55 +05:30
|
|
|
def __init__(self,db, obj,est):
|
|
|
|
FamilyRule.__init__(self,db, obj)
|
2006-05-26 05:29:51 +05:30
|
|
|
self.est = est
|
|
|
|
|
2006-05-29 07:41:37 +05:30
|
|
|
def _get_params(self):
|
|
|
|
return (self.est,)
|
|
|
|
|
2006-05-25 10:48:03 +05:30
|
|
|
def broken(self):
|
|
|
|
marr_date = get_marriage_date(self.db,self.obj)
|
|
|
|
marr_date_ok = marr_date > 0
|
|
|
|
|
|
|
|
mother = get_mother(self.db,self.obj)
|
|
|
|
father = get_father(self.db,self.obj)
|
2006-05-26 05:29:51 +05:30
|
|
|
mother_death_date = get_death_date(self.db,mother,self.est)
|
|
|
|
father_death_date = get_death_date(self.db,father,self.est)
|
2006-05-25 10:48:03 +05:30
|
|
|
mother_death_date_ok = mother_death_date > 0
|
|
|
|
father_death_date_ok = father_death_date > 0
|
|
|
|
|
|
|
|
father_broken = (father_death_date_ok and marr_date_ok
|
2006-05-29 07:08:44 +05:30
|
|
|
and (father_death_date < marr_date))
|
2006-05-25 10:48:03 +05:30
|
|
|
mother_broken = (mother_death_date_ok and marr_date_ok
|
2006-05-29 07:08:44 +05:30
|
|
|
and (mother_death_date < marr_date))
|
2006-05-25 10:48:03 +05:30
|
|
|
|
|
|
|
return (father_broken or mother_broken)
|
|
|
|
|
|
|
|
def get_message(self):
|
|
|
|
return _("Marriage after death")
|
|
|
|
|
|
|
|
class EarlyMarriage(FamilyRule):
|
2006-05-26 05:29:51 +05:30
|
|
|
ID = 20
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = Rule.WARNING
|
2008-02-24 19:25:55 +05:30
|
|
|
def __init__(self,db, obj,yng_mar,est):
|
|
|
|
FamilyRule.__init__(self,db, obj)
|
2006-05-25 10:48:03 +05:30
|
|
|
self.yng_mar = yng_mar
|
2006-05-26 05:29:51 +05:30
|
|
|
self.est = est
|
2006-05-25 10:48:03 +05:30
|
|
|
|
2006-05-29 07:41:37 +05:30
|
|
|
def _get_params(self):
|
|
|
|
return (self.yng_mar,self.est,)
|
|
|
|
|
2006-05-25 10:48:03 +05:30
|
|
|
def broken(self):
|
|
|
|
marr_date = get_marriage_date(self.db,self.obj)
|
|
|
|
marr_date_ok = marr_date > 0
|
|
|
|
|
|
|
|
mother = get_mother(self.db,self.obj)
|
|
|
|
father = get_father(self.db,self.obj)
|
2006-05-26 05:29:51 +05:30
|
|
|
mother_birth_date = get_birth_date(self.db,mother,self.est)
|
|
|
|
father_birth_date = get_birth_date(self.db,father,self.est)
|
2006-05-25 10:48:03 +05:30
|
|
|
mother_birth_date_ok = mother_birth_date > 0
|
|
|
|
father_birth_date_ok = father_birth_date > 0
|
|
|
|
|
2006-05-29 07:08:44 +05:30
|
|
|
father_broken = (father_birth_date_ok and marr_date_ok and
|
2007-03-19 00:36:22 +05:30
|
|
|
father_birth_date < marr_date and
|
2006-05-29 07:08:44 +05:30
|
|
|
((marr_date - father_birth_date)/365 < self.yng_mar))
|
|
|
|
mother_broken = (mother_birth_date_ok and marr_date_ok and
|
2007-03-19 00:36:22 +05:30
|
|
|
mother_birth_date < marr_date and
|
2006-05-29 07:08:44 +05:30
|
|
|
((marr_date - mother_birth_date)/365 < self.yng_mar))
|
2006-05-25 10:48:03 +05:30
|
|
|
|
|
|
|
return (father_broken or mother_broken)
|
|
|
|
|
|
|
|
def get_message(self):
|
|
|
|
return _("Early marriage")
|
|
|
|
|
|
|
|
class LateMarriage(FamilyRule):
|
2006-05-26 05:29:51 +05:30
|
|
|
ID = 21
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = Rule.WARNING
|
2008-02-24 19:25:55 +05:30
|
|
|
def __init__(self,db, obj, old_mar,est):
|
|
|
|
FamilyRule.__init__(self,db, obj)
|
2006-05-25 10:48:03 +05:30
|
|
|
self.old_mar = old_mar
|
2006-05-26 05:29:51 +05:30
|
|
|
self.est = est
|
2006-05-25 10:48:03 +05:30
|
|
|
|
2006-05-29 07:41:37 +05:30
|
|
|
def _get_params(self):
|
|
|
|
return (self.old_mar,self.est)
|
|
|
|
|
2006-05-25 10:48:03 +05:30
|
|
|
def broken(self):
|
|
|
|
marr_date = get_marriage_date(self.db,self.obj)
|
|
|
|
marr_date_ok = marr_date > 0
|
|
|
|
|
|
|
|
mother = get_mother(self.db,self.obj)
|
|
|
|
father = get_father(self.db,self.obj)
|
2006-05-26 05:29:51 +05:30
|
|
|
mother_birth_date = get_birth_date(self.db,mother,self.est)
|
|
|
|
father_birth_date = get_birth_date(self.db,father,self.est)
|
2006-05-25 10:48:03 +05:30
|
|
|
mother_birth_date_ok = mother_birth_date > 0
|
|
|
|
father_birth_date_ok = father_birth_date > 0
|
|
|
|
|
2006-05-29 07:08:44 +05:30
|
|
|
father_broken = (father_birth_date_ok and marr_date_ok and
|
|
|
|
((marr_date - father_birth_date)/365 > self.old_mar))
|
|
|
|
mother_broken = (mother_birth_date_ok and marr_date_ok and
|
|
|
|
((marr_date - mother_birth_date)/365 > self.old_mar))
|
2006-05-25 10:48:03 +05:30
|
|
|
|
|
|
|
return (father_broken or mother_broken)
|
|
|
|
|
|
|
|
def get_message(self):
|
|
|
|
return _("Late marriage")
|
|
|
|
|
|
|
|
## class MarriageBeforePrefiousMarrChild(PersonRule):
|
|
|
|
## def broken(self):
|
|
|
|
## marr_date = get_marriage_date(self.obj)
|
|
|
|
## prev_marr_child_date = get_prev_marr_child_date(self.obj)
|
|
|
|
## return (prev_marr_child_date>marr_date)
|
|
|
|
|
|
|
|
## def get_message(self):
|
|
|
|
## return _("Marriage before having a child from previous marriage")
|
|
|
|
|
|
|
|
## class LongWidowhood(FamilyRule):
|
|
|
|
## def broken(self):
|
|
|
|
## marr_date = get_marriage_date(self.obj)
|
|
|
|
## prev_marr_spouse_death_date = get_prev_marr_spouse_death_date(self.obj)
|
|
|
|
## birth_date = get_birth_date(self.obj)
|
|
|
|
## return (marr_date-prev_marr_spouse_death_date>lngwdw)
|
|
|
|
|
|
|
|
## def get_message(self):
|
|
|
|
## return _("Long Windowhood")
|
|
|
|
|
|
|
|
class OldParent(FamilyRule):
|
2006-05-26 05:29:51 +05:30
|
|
|
ID = 22
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = Rule.WARNING
|
2008-02-24 19:25:55 +05:30
|
|
|
def __init__(self,db, obj, old_mom, old_dad,est):
|
|
|
|
FamilyRule.__init__(self,db, obj)
|
2006-05-26 05:29:51 +05:30
|
|
|
self.old_mom = old_mom
|
|
|
|
self.old_dad = old_dad
|
|
|
|
self.est = est
|
2006-05-25 10:48:03 +05:30
|
|
|
|
2006-05-29 07:41:37 +05:30
|
|
|
def _get_params(self):
|
|
|
|
return (self.old_mom,self.old_dad,self.est)
|
|
|
|
|
2006-05-25 10:48:03 +05:30
|
|
|
def broken(self):
|
|
|
|
mother = get_mother(self.db,self.obj)
|
|
|
|
father = get_father(self.db,self.obj)
|
2006-05-26 05:29:51 +05:30
|
|
|
mother_birth_date = get_birth_date(self.db,mother,self.est)
|
|
|
|
father_birth_date = get_birth_date(self.db,father,self.est)
|
2006-05-25 10:48:03 +05:30
|
|
|
mother_birth_date_ok = mother_birth_date > 0
|
|
|
|
father_birth_date_ok = father_birth_date > 0
|
|
|
|
|
|
|
|
for child_ref in self.obj.get_child_ref_list():
|
|
|
|
child = find_person(self.db,child_ref.ref)
|
2006-05-26 05:29:51 +05:30
|
|
|
child_birth_date = get_birth_date(self.db,child,self.est)
|
2006-05-25 10:48:03 +05:30
|
|
|
child_birth_date_ok = child_birth_date > 0
|
|
|
|
if not child_birth_date_ok:
|
|
|
|
continue
|
2006-05-29 07:08:44 +05:30
|
|
|
father_broken = (father_birth_date_ok and
|
|
|
|
((child_birth_date - father_birth_date)/365 > self.old_dad))
|
2006-05-25 10:48:03 +05:30
|
|
|
if father_broken:
|
|
|
|
self.get_message = self.father_message
|
|
|
|
return True
|
|
|
|
|
2006-05-29 07:08:44 +05:30
|
|
|
mother_broken = (mother_birth_date_ok and
|
|
|
|
((child_birth_date - mother_birth_date)/365 > self.old_mom))
|
2006-05-25 10:48:03 +05:30
|
|
|
if mother_broken:
|
|
|
|
self.get_message = self.mother_message
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def father_message(self):
|
|
|
|
return _("Old father")
|
|
|
|
|
|
|
|
def mother_message(self):
|
|
|
|
return _("Old mother")
|
|
|
|
|
|
|
|
class YoungParent(FamilyRule):
|
2006-05-26 05:29:51 +05:30
|
|
|
ID = 23
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = Rule.WARNING
|
2008-02-24 19:25:55 +05:30
|
|
|
def __init__(self,db, obj,yng_mom,yng_dad,est):
|
|
|
|
FamilyRule.__init__(self,db, obj)
|
2006-05-26 05:29:51 +05:30
|
|
|
self.yng_dad = yng_dad
|
|
|
|
self.yng_mom = yng_mom
|
|
|
|
self.est = est
|
2006-05-25 10:48:03 +05:30
|
|
|
|
2006-05-29 07:41:37 +05:30
|
|
|
def _get_params(self):
|
|
|
|
return (self.yng_mom,self.yng_dad,self.est)
|
|
|
|
|
2006-05-25 10:48:03 +05:30
|
|
|
def broken(self):
|
|
|
|
mother = get_mother(self.db,self.obj)
|
|
|
|
father = get_father(self.db,self.obj)
|
2006-05-26 05:29:51 +05:30
|
|
|
mother_birth_date = get_birth_date(self.db,mother,self.est)
|
|
|
|
father_birth_date = get_birth_date(self.db,father,self.est)
|
2006-05-25 10:48:03 +05:30
|
|
|
mother_birth_date_ok = mother_birth_date > 0
|
|
|
|
father_birth_date_ok = father_birth_date > 0
|
|
|
|
|
|
|
|
for child_ref in self.obj.get_child_ref_list():
|
|
|
|
child = find_person(self.db,child_ref.ref)
|
2006-05-26 05:29:51 +05:30
|
|
|
child_birth_date = get_birth_date(self.db,child,self.est)
|
2006-05-25 10:48:03 +05:30
|
|
|
child_birth_date_ok = child_birth_date > 0
|
|
|
|
if not child_birth_date_ok:
|
|
|
|
continue
|
2006-05-29 07:08:44 +05:30
|
|
|
father_broken = (father_birth_date_ok and
|
|
|
|
((child_birth_date - father_birth_date)/365 < self.yng_dad))
|
2006-05-25 10:48:03 +05:30
|
|
|
if father_broken:
|
|
|
|
self.get_message = self.father_message
|
|
|
|
return True
|
|
|
|
|
2006-05-29 07:08:44 +05:30
|
|
|
mother_broken = (mother_birth_date_ok and
|
|
|
|
((child_birth_date - mother_birth_date)/365 < self.yng_mom))
|
2006-05-25 10:48:03 +05:30
|
|
|
if mother_broken:
|
|
|
|
self.get_message = self.mother_message
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def father_message(self):
|
|
|
|
return _("Young father")
|
|
|
|
|
|
|
|
def mother_message(self):
|
|
|
|
return _("Young mother")
|
|
|
|
|
|
|
|
class UnbornParent(FamilyRule):
|
2006-05-26 05:29:51 +05:30
|
|
|
ID = 24
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = Rule.ERROR
|
2008-02-24 19:25:55 +05:30
|
|
|
def __init__(self,db, obj,est):
|
|
|
|
FamilyRule.__init__(self,db, obj)
|
2006-05-26 05:29:51 +05:30
|
|
|
self.est = est
|
|
|
|
|
2006-05-29 07:41:37 +05:30
|
|
|
def _get_params(self):
|
|
|
|
return (self.est,)
|
|
|
|
|
2006-05-25 10:48:03 +05:30
|
|
|
def broken(self):
|
|
|
|
mother = get_mother(self.db,self.obj)
|
|
|
|
father = get_father(self.db,self.obj)
|
2006-05-26 05:29:51 +05:30
|
|
|
mother_birth_date = get_birth_date(self.db,mother,self.est)
|
|
|
|
father_birth_date = get_birth_date(self.db,father,self.est)
|
2006-05-25 10:48:03 +05:30
|
|
|
mother_birth_date_ok = mother_birth_date > 0
|
|
|
|
father_birth_date_ok = father_birth_date > 0
|
|
|
|
|
|
|
|
for child_ref in self.obj.get_child_ref_list():
|
|
|
|
child = find_person(self.db,child_ref.ref)
|
2006-05-26 05:29:51 +05:30
|
|
|
child_birth_date = get_birth_date(self.db,child,self.est)
|
2006-05-25 10:48:03 +05:30
|
|
|
child_birth_date_ok = child_birth_date > 0
|
|
|
|
if not child_birth_date_ok:
|
|
|
|
continue
|
|
|
|
father_broken = (father_birth_date_ok
|
|
|
|
and (father_birth_date > child_birth_date))
|
|
|
|
if father_broken:
|
|
|
|
self.get_message = self.father_message
|
|
|
|
return True
|
|
|
|
|
|
|
|
mother_broken = (mother_birth_date_ok
|
|
|
|
and (mother_birth_date > child_birth_date))
|
|
|
|
if mother_broken:
|
|
|
|
self.get_message = self.mother_message
|
|
|
|
return True
|
|
|
|
|
|
|
|
def father_message(self):
|
|
|
|
return _("Unborn father")
|
|
|
|
|
|
|
|
def mother_message(self):
|
|
|
|
return _("Unborn mother")
|
|
|
|
|
|
|
|
class DeadParent(FamilyRule):
|
2006-05-26 05:29:51 +05:30
|
|
|
ID = 25
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = Rule.ERROR
|
2008-02-24 19:25:55 +05:30
|
|
|
def __init__(self,db, obj,est):
|
|
|
|
FamilyRule.__init__(self,db, obj)
|
2006-05-26 05:29:51 +05:30
|
|
|
self.est = est
|
|
|
|
|
2006-05-29 07:41:37 +05:30
|
|
|
def _get_params(self):
|
|
|
|
return (self.est,)
|
|
|
|
|
2006-05-25 10:48:03 +05:30
|
|
|
def broken(self):
|
|
|
|
mother = get_mother(self.db,self.obj)
|
|
|
|
father = get_father(self.db,self.obj)
|
2006-05-26 05:29:51 +05:30
|
|
|
mother_death_date = get_death_date(self.db,mother,self.est)
|
|
|
|
father_death_date = get_death_date(self.db,father,self.est)
|
2006-05-25 10:48:03 +05:30
|
|
|
mother_death_date_ok = mother_death_date > 0
|
|
|
|
father_death_date_ok = father_death_date > 0
|
|
|
|
|
|
|
|
for child_ref in self.obj.get_child_ref_list():
|
|
|
|
child = find_person(self.db,child_ref.ref)
|
2006-05-26 05:29:51 +05:30
|
|
|
child_birth_date = get_birth_date(self.db,child,self.est)
|
2006-05-25 10:48:03 +05:30
|
|
|
child_birth_date_ok = child_birth_date > 0
|
|
|
|
if not child_birth_date_ok:
|
|
|
|
continue
|
2008-01-06 03:11:38 +05:30
|
|
|
|
|
|
|
hasBirthRelToMother = child_ref.mrel == gen.lib.ChildRefType.BIRTH
|
|
|
|
hasBirthRelToFather = child_ref.frel == gen.lib.ChildRefType.BIRTH
|
|
|
|
|
|
|
|
father_broken = (hasBirthRelToFather
|
|
|
|
and father_death_date_ok
|
2007-03-19 00:36:22 +05:30
|
|
|
and ((father_death_date + 294) < child_birth_date))
|
2006-05-25 10:48:03 +05:30
|
|
|
if father_broken:
|
|
|
|
self.get_message = self.father_message
|
|
|
|
return True
|
|
|
|
|
2008-01-06 03:11:38 +05:30
|
|
|
mother_broken = (hasBirthRelToMother
|
|
|
|
and mother_death_date_ok
|
2006-05-25 10:48:03 +05:30
|
|
|
and (mother_death_date < child_birth_date))
|
|
|
|
if mother_broken:
|
|
|
|
self.get_message = self.mother_message
|
|
|
|
return True
|
|
|
|
|
|
|
|
def father_message(self):
|
|
|
|
return _("Dead father")
|
|
|
|
|
|
|
|
def mother_message(self):
|
|
|
|
return _("Dead mother")
|
|
|
|
|
|
|
|
class LargeChildrenSpan(FamilyRule):
|
2006-05-26 05:29:51 +05:30
|
|
|
ID = 26
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = Rule.WARNING
|
2008-02-24 19:25:55 +05:30
|
|
|
def __init__(self,db, obj,cb_span,est):
|
|
|
|
FamilyRule.__init__(self,db, obj)
|
2006-05-25 10:48:03 +05:30
|
|
|
self.cb_span = cb_span
|
2006-05-26 05:29:51 +05:30
|
|
|
self.est = est
|
2006-05-25 10:48:03 +05:30
|
|
|
|
2006-05-29 07:41:37 +05:30
|
|
|
def _get_params(self):
|
|
|
|
return (self.cb_span,self.est)
|
|
|
|
|
2006-05-25 10:48:03 +05:30
|
|
|
def broken(self):
|
2006-05-26 05:29:51 +05:30
|
|
|
child_birh_dates = get_child_birth_dates(self.db,self.obj,self.est)
|
2006-05-25 10:48:03 +05:30
|
|
|
child_birh_dates.sort()
|
|
|
|
|
2006-05-29 07:08:44 +05:30
|
|
|
return (child_birh_dates and ((child_birh_dates[-1]
|
|
|
|
- child_birh_dates[0])/365
|
|
|
|
> self.cb_span))
|
2006-05-25 10:48:03 +05:30
|
|
|
|
|
|
|
def get_message(self):
|
|
|
|
return _("Large year span for all children")
|
|
|
|
|
|
|
|
class LargeChildrenAgeDiff(FamilyRule):
|
2006-05-26 05:29:51 +05:30
|
|
|
ID = 27
|
2006-05-27 01:48:33 +05:30
|
|
|
SEVERITY = Rule.WARNING
|
2008-02-24 19:25:55 +05:30
|
|
|
def __init__(self,db, obj,c_space,est):
|
|
|
|
FamilyRule.__init__(self,db, obj)
|
2006-05-25 10:48:03 +05:30
|
|
|
self.c_space = c_space
|
2006-05-26 05:29:51 +05:30
|
|
|
self.est = est
|
2006-05-25 10:48:03 +05:30
|
|
|
|
2006-05-29 07:41:37 +05:30
|
|
|
def _get_params(self):
|
|
|
|
return (self.c_space,self.est)
|
|
|
|
|
2006-05-25 10:48:03 +05:30
|
|
|
def broken(self):
|
2006-05-26 05:29:51 +05:30
|
|
|
child_birh_dates = get_child_birth_dates(self.db,self.obj,self.est)
|
2006-05-25 10:48:03 +05:30
|
|
|
child_birh_dates_diff = [child_birh_dates[i+1] - child_birh_dates[i]
|
|
|
|
for i in range(len(child_birh_dates)-1) ]
|
|
|
|
|
2006-05-26 05:29:51 +05:30
|
|
|
return (child_birh_dates_diff and
|
2006-05-29 07:08:44 +05:30
|
|
|
max(child_birh_dates_diff)/365 > self.c_space)
|
2006-05-25 10:48:03 +05:30
|
|
|
|
|
|
|
def get_message(self):
|
|
|
|
return _("Large age differences between children")
|
|
|
|
|
2006-08-17 00:10:10 +05:30
|
|
|
class Disconnected(PersonRule):
|
|
|
|
ID = 28
|
|
|
|
SEVERITY = Rule.WARNING
|
|
|
|
def broken(self):
|
|
|
|
return (len(self.obj.get_parent_family_handle_list())
|
|
|
|
+ len(self.obj.get_family_handle_list()) == 0)
|
|
|
|
|
|
|
|
def get_message(self):
|
|
|
|
return _("Disconnected individual")
|
|
|
|
|
2008-04-20 19:06:28 +05:30
|
|
|
class InvalidBirthDate(PersonRule):
|
|
|
|
ID = 29
|
|
|
|
SEVERITY = Rule.ERROR
|
|
|
|
def __init__(self, db, person, invdate):
|
|
|
|
PersonRule.__init__(self, db, person)
|
|
|
|
self._invdate = invdate
|
|
|
|
|
|
|
|
def broken(self):
|
|
|
|
if not self._invdate: return False # should we check?
|
|
|
|
# if so, let's get the birth date
|
|
|
|
person = self.obj
|
|
|
|
birth_ref = person.get_birth_ref()
|
|
|
|
if birth_ref:
|
|
|
|
birth_event = self.db.get_event_from_handle(birth_ref.ref)
|
|
|
|
birth_date = birth_event.get_date_object()
|
|
|
|
if birth_date and not birth_date.get_valid():
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def get_message(self):
|
|
|
|
return _("Invalid birth date")
|
|
|
|
|
|
|
|
class InvalidDeathDate(PersonRule):
|
|
|
|
ID = 30
|
|
|
|
SEVERITY = Rule.ERROR
|
|
|
|
def __init__(self, db, person, invdate):
|
|
|
|
PersonRule.__init__(self, db, person)
|
|
|
|
self._invdate = invdate
|
|
|
|
|
|
|
|
def broken(self):
|
|
|
|
if not self._invdate: return False # should we check?
|
|
|
|
# if so, let's get the death date
|
|
|
|
person = self.obj
|
|
|
|
death_ref = person.get_death_ref()
|
|
|
|
if death_ref:
|
|
|
|
death_event = self.db.get_event_from_handle(death_ref.ref)
|
|
|
|
death_date = death_event.get_date_object()
|
|
|
|
if death_date and not death_date.get_valid():
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def get_message(self):
|
|
|
|
return _("Invalid death date")
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2008-05-19 00:54:28 +05:30
|
|
|
pmgr = PluginManager.get_instance()
|
|
|
|
pmgr.register_tool(
|
2005-12-06 12:08:09 +05:30
|
|
|
name = 'verify',
|
|
|
|
category = Tool.TOOL_UTILS,
|
|
|
|
tool_class = Verify,
|
|
|
|
options_class = VerifyOptions,
|
2008-10-02 09:32:10 +05:30
|
|
|
modes = PluginManager.TOOL_MODE_GUI | PluginManager.TOOL_MODE_CLI,
|
2008-03-02 04:17:48 +05:30
|
|
|
translated_name = _("Verify the Data"),
|
2008-03-03 01:10:34 +05:30
|
|
|
status=(_("Stable")),
|
|
|
|
author_name = "Alex Roitman",
|
|
|
|
author_email = "shura@gramps-project.org",
|
2007-06-18 06:21:04 +05:30
|
|
|
description = _("Verifies the data against user-defined tests")
|
2002-10-20 19:55:16 +05:30
|
|
|
)
|