* plugins/TestcaseGenerator.py: Added some more testcases of invalid relations

* plugins/Check.py: Added some comments an handling for some more invalid references


svn: r4256
This commit is contained in:
Martin Hawlisch 2005-03-30 10:37:40 +00:00
parent 94d4aa7288
commit a8a02b241e
3 changed files with 109 additions and 10 deletions

View File

@ -1,3 +1,7 @@
2005-03-30 Martin Hawlisch <Martin.Hawlisch@gmx.de>
* plugins/TestcaseGenerator.py: Added some more testcases of invalid relations
* plugins/Check.py: Added some comments an handling for some more invalid references
2005-03-29 Don Allingham <don@gramps-project.org>
* src/ReadXML.py: handle date object on names
* src/gramps.glade: add menu items for merging

View File

@ -93,6 +93,7 @@ class CheckIntegrity:
def check_for_broken_family_links(self):
self.broken_links = []
# Check persons referenced by the family objects
for family_handle in self.db.get_family_handles():
family = self.db.get_family_from_handle(family_handle)
father_handle = family.get_father_handle()
@ -100,6 +101,7 @@ class CheckIntegrity:
if father_handle:
father = self.db.get_person_from_handle(father_handle)
if not father:
# The person referenced by the father handle does not exist in the database
family.set_father_handle(None)
self.db.commit_family(family,self.trans)
self.broken_parent_links.append((father_handle,family_handle))
@ -107,16 +109,19 @@ class CheckIntegrity:
if mother_handle:
mother = self.db.get_person_from_handle(mother_handle)
if not mother:
# The person referenced by the mother handle does not exist in the database
family.set_father_handle(None)
self.db.commit_family(family,self.trans)
self.broken_parent_links.append((mother_handle,family_handle))
mother_handle = None
if father_handle and father and family_handle not in father.get_family_handle_list():
# The referenced father has no reference back to the family
self.broken_parent_links.append((father_handle,family_handle))
father.add_family_handle(family_handle)
self.db.commit_person(father,self.trans)
if mother_handle and mother and family_handle not in mother.get_family_handle_list():
# The referenced mother has no reference back to the family
self.broken_parent_links.append((mother_handle,family_handle))
mother.add_family_handle(family_handle)
self.db.commit_person(mother,self.trans)
@ -129,14 +134,45 @@ class CheckIntegrity:
if family_type[0] == family_handle:
break
else:
# The referenced child has no reference back to the family
family.remove_child_handle(child_handle)
self.db.commit_family(family,self.trans)
self.broken_links.append((child_handle,family_handle))
else:
# The person referenced by the child handle does not exist in the database
family.remove_child_handle(child_handle)
self.db.commit_family(family,self.trans)
self.broken_links.append((child_handle,family_handle))
# Check persons membership in referenced families
for person_handle in self.db.get_person_handles():
person = self.db.get_person_from_handle(person_handle)
for family_type in person.get_parent_family_handle_list():
family = self.db.get_family_from_handle(family_type[0])
for child_handle in family.get_child_handle_list():
if child_handle == person_handle:
break
else:
# Person is not a child in the referenced parent family
person.remove_parent_family_handle(family_type[0])
self.db.commit_person(person,self.trans)
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)
self.db.commit_person(person,self.trans)
self.broken_links.append((person_handle,family_handle))
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)
self.db.commit_person(person,self.trans)
self.broken_links.append((person_handle,family_handle))
def cleanup_missing_photos(self,cl=0):
missmedia_action = 0
@ -260,11 +296,13 @@ class CheckIntegrity:
continue
elif not father_handle:
if mother and mother.get_gender() == RelLib.Person.MALE:
# No father set and mother is male
family.set_father_handle(mother_handle)
family.set_mother_handle(None)
self.db.commit_family(family,self.trans)
elif not mother_handle:
if father and father.get_gender() == RelLib.Person.FEMALE:
# No mother set and father is female
family.set_mother_handle(father_handle)
family.set_father_handle(None)
self.db.commit_family(family,self.trans)
@ -323,17 +361,20 @@ class CheckIntegrity:
cn = person.get_primary_name().get_name()
else:
cn = _("Non existing child")
f = self.db.get_person_from_handle(family.get_father_handle())
m = self.db.get_person_from_handle(family.get_mother_handle())
if f and m:
pn = _("%s and %s") % (f.get_primary_name().get_name(),\
if family:
f = self.db.get_person_from_handle(family.get_father_handle())
m = self.db.get_person_from_handle(family.get_mother_handle())
if f and m:
pn = _("%s and %s") % (f.get_primary_name().get_name(),\
m.get_primary_name().get_name())
elif f:
pn = f.get_primary_name().get_name()
elif m:
pn = m.get_primary_name().get_name()
elif f:
pn = f.get_primary_name().get_name()
elif m:
pn = m.get_primary_name().get_name()
else:
pn = _("unknown")
else:
pn = _("unknown")
pn = _("Non existing family")
self.text.write('\t')
self.text.write(_("%s was removed from the family of %s\n") % (cn,pn))

View File

@ -173,6 +173,60 @@ class TestcaseGenerator:
#self.db.commit_person(person2,self.trans)
# Creates a family where the child does not link back to the family
person1_h = self.generate_person(RelLib.Person.MALE,"Broken8",None)
person2_h = self.generate_person(RelLib.Person.FEMALE,"Broken8",None)
child_h = self.generate_person(None,"Broken8",None)
fam = RelLib.Family()
fam.set_father_handle(person1_h)
fam.set_mother_handle(person2_h)
fam.set_relationship(RelLib.Family.MARRIED)
fam.add_child_handle(child_h)
fam_h = self.db.add_family(fam,self.trans)
person1 = self.db.get_person_from_handle(person1_h)
person1.add_family_handle(fam_h)
self.db.commit_person(person1,self.trans)
person2 = self.db.get_person_from_handle(person2_h)
person2.add_family_handle(fam_h)
self.db.commit_person(person2,self.trans)
#child = self.db.get_person_from_handle(child_h)
#person2.add_parent_family_handle(fam_h)
#self.db.commit_person(child,self.trans)
# Creates a family where the child is not linked, but the child links to the family
person1_h = self.generate_person(RelLib.Person.MALE,"Broken9",None)
person2_h = self.generate_person(RelLib.Person.FEMALE,"Broken9",None)
child_h = self.generate_person(None,"Broken9",None)
fam = RelLib.Family()
fam.set_father_handle(person1_h)
fam.set_mother_handle(person2_h)
fam.set_relationship(RelLib.Family.MARRIED)
#fam.add_child_handle(child_h)
fam_h = self.db.add_family(fam,self.trans)
person1 = self.db.get_person_from_handle(person1_h)
person1.add_family_handle(fam_h)
self.db.commit_person(person1,self.trans)
person2 = self.db.get_person_from_handle(person2_h)
person2.add_family_handle(fam_h)
self.db.commit_person(person2,self.trans)
child = self.db.get_person_from_handle(child_h)
person2.add_parent_family_handle(fam_h,RelLib.Person.CHILD_REL_BIRTH,RelLib.Person.CHILD_REL_BIRTH)
self.db.commit_person(child,self.trans)
# Creates a person with an event having a witness reference to a nonexisting person
person_h = self.generate_person(None,"Broken10",None)
witness = RelLib.Witness()
witness.set_type(RelLib.Event.ID)
witness.set_value("InvalidHandle3")
witness.set_comment("Pointing to non existing person");
event = RelLib.Event()
event.add_witness(witness)
event.set_name("Christening")
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):
print "generate_person"