From 73864c588ec46497dd4d57129b85a1ebb9d0cba5 Mon Sep 17 00:00:00 2001 From: Martin Hawlisch Date: Fri, 1 Apr 2005 09:59:18 +0000 Subject: [PATCH] * src/plugins/TestcaseGenerator.py: Added generation of invalid event references of persons * src/plugins/Check.py: Check for invalid event references of persons svn: r4269 --- gramps2/ChangeLog | 4 ++ gramps2/src/plugins/Check.py | 65 +++++++++++++++++++++++- gramps2/src/plugins/TestcaseGenerator.py | 48 ++++++++++++++++- 3 files changed, 114 insertions(+), 3 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 203eb3b27..55f2c3dd8 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -3,6 +3,10 @@ * src/plugins/ChangeNames.py: new database callback scheme * src/plugins/TestcaseGenerator.py: new database callback scheme + * src/plugins/TestcaseGenerator.py: Added generation of invalid + event references of persons + * src/plugins/Check.py: Check for invalid event references of persons + 2005-03-31 Don Allingham * src/AddSpouse.py: new database callback scheme. This scheme provides a registration mechanism to signal interested objects diff --git a/gramps2/src/plugins/Check.py b/gramps2/src/plugins/Check.py index 9bd66ecfd..a2381ae85 100644 --- a/gramps2/src/plugins/Check.py +++ b/gramps2/src/plugins/Check.py @@ -58,12 +58,13 @@ def runTool(database,active_person,callback,parent=None): try: trans = database.transaction_begin() - self.trans.set_batch(True) + trans.set_batch(True) checker = CheckIntegrity(database,parent,trans) checker.check_for_broken_family_links() checker.cleanup_missing_photos(0) checker.check_parent_relationships() checker.cleanup_empty_families(0) + checker.check_events() database.transaction_commit(trans, _("Check Integrity")) errs = checker.build_report(0) @@ -91,6 +92,9 @@ class CheckIntegrity: self.broken_links = [] self.broken_parent_links = [] self.fam_rel = [] + self.invalid_events = [] + self.invalid_birth_events = [] + self.invalid_death_events = [] def check_for_broken_family_links(self): self.broken_links = [] @@ -328,6 +332,47 @@ class CheckIntegrity: family.set_mother_handle(father_handle) self.db.commit_family(family,self.trans) + def check_events(self): + for key in self.db.get_person_handles(sort_handles=False): + person = self.db.get_person_from_handle(key) + birth_handle = person.get_birth_handle() + if birth_handle: + birth = self.db.get_event_from_handle(birth_handle) + if not birth: + # The birth event referenced by the birth handle does not exist in the database + person.set_birth_handle("") + self.db.commit_person(person,self.trans) + self.invalid_events.append(key) + else: + if not birth.get_name() == "Birth": + # Birth event was not of the type "Birth" + birth.set_name("Birth"); + self.db.commit_event(birth,self.trans) + self.invalid_birth_events.append(key) + death_handle = person.get_death_handle() + if death_handle: + death = self.db.get_event_from_handle(death_handle) + if not death: + # The death event referenced by the death handle does not exist in the database + person.set_death_handle("") + self.db.commit_person(person,self.trans) + self.invalid_events.append(key) + else: + if not death.get_name() == "Death": + # Death event was not of the type "Death" + death.set_name("Death"); + self.db.commit_event(death,self.trans) + self.invalid_death_events.append(key) + if person.get_event_list(): + for event_handle in person.get_event_list(): + event = self.db.get_event_from_handle(event_handle) + if not event: + # The event referenced by the person does not exist in the database + #TODO: There is no better way? + person.set_event_list( person.get_event_list().remove(event_handle)) + self.db.commit_person(person,self.trans) + self.invalid_events.append(key) + def build_report(self,cl=0): bad_photos = len(self.bad_photo) replaced_photos = len(self.replaced_photo) @@ -337,8 +382,12 @@ class CheckIntegrity: blink = len(self.broken_links) plink = len(self.broken_parent_links) rel = len(self.fam_rel) + 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 - errors = blink + efam + photos + rel + errors = blink + efam + photos + rel + person + event_invalid if errors == 0: if cl: @@ -406,6 +455,18 @@ class CheckIntegrity: self.text.write(_("1 missing media object was removed\n")) elif removed_photos > 1: self.text.write(_("%d missing media objects were removed\n") % removed_photos) + if event_invalid == 1: + self.text.write(_("1 invalid event reference was removed\n")) + elif event_invalid > 1: + self.text.write(_("%d invalid event references were removed\n") % event_invalid) + if birth_invalid == 1: + self.text.write(_("1 invalid birth event name was fixed\n")) + elif birth_invalid > 1: + self.text.write(_("%d invalid birth event names were fixed\n") % birth_invalid) + if death_invalid == 1: + self.text.write(_("1 invalid death event name was fixed\n")) + elif death_invalid > 1: + self.text.write(_("%d invalid death event names were fixed\n") % death_invalid) return errors diff --git a/gramps2/src/plugins/TestcaseGenerator.py b/gramps2/src/plugins/TestcaseGenerator.py index 59519f7e3..c48bbc4dc 100644 --- a/gramps2/src/plugins/TestcaseGenerator.py +++ b/gramps2/src/plugins/TestcaseGenerator.py @@ -305,6 +305,52 @@ class TestcaseGenerator: person.add_event_handle(event_h) self.db.commit_person(person,self.trans) + # Creates a person having a non existing birth event handle set + person_h = self.generate_person(None,"Broken11",None) + person = self.db.get_person_from_handle(person_h) + person.set_birth_handle("InvalidHandle4") + self.db.commit_person(person,self.trans) + + # Creates a person having a non existing death event handle set + person_h = self.generate_person(None,"Broken12",None) + person = self.db.get_person_from_handle(person_h) + person.set_death_handle("InvalidHandle5") + self.db.commit_person(person,self.trans) + + # Creates a person having a non existing event handle set + person_h = self.generate_person(None,"Broken13",None) + person = self.db.get_person_from_handle(person_h) + person.add_event_handle("InvalidHandle6") + self.db.commit_person(person,self.trans) + + # Creates a person with a birth event having an empty type + person_h = self.generate_person(None,"Broken14",None) + event = RelLib.Event() + event.set_description("Test for Broken14") + event_h = self.db.add_event(event,self.trans) + person = self.db.get_person_from_handle(person_h) + person.set_birth_handle(event_h) + self.db.commit_person(person,self.trans) + + # Creates a person with a death event having an empty type + person_h = self.generate_person(None,"Broken15",None) + event = RelLib.Event() + event.set_description("Test for Broken15") + event_h = self.db.add_event(event,self.trans) + person = self.db.get_person_from_handle(person_h) + person.set_death_handle(event_h) + self.db.commit_person(person,self.trans) + + # Creates a person with an event having an empty type + person_h = self.generate_person(None,"Broken16",None) + event = RelLib.Event() + event.set_description("Test for Broken16") + event_h = self.db.add_event(event,self.trans) + person = self.db.get_person_from_handle(person_h) + person.add_event_handle(event_h) + self.db.commit_person(person,self.trans) + + def generate_person(self,gender=None,lastname=None,note=None): self.progress.set_fraction(min(1.0,max(0.0, 1.0*self.person_count/self.max_person_count))) @@ -331,7 +377,7 @@ class TestcaseGenerator: name = RelLib.Name() firstname = "" for i in range(0,randint(1,5)): - for i in range(0,randint(2,5)): + for j in range(0,randint(2,5)): firstname = firstname + choice(syllables2) if gender == RelLib.Person.FEMALE: firstname = firstname + choice(("a","e","i","o","u"))