* src/plugins/Check.py: Clean up conversion to db.

svn: r3146
This commit is contained in:
Alex Roitman 2004-05-09 04:02:26 +00:00
parent 3b246d35be
commit babd135df0
2 changed files with 45 additions and 35 deletions

View File

@ -1,6 +1,7 @@
2004-05-08 Alex Roitman <shura@alex.neuro.umn.edu> 2004-05-08 Alex Roitman <shura@alex.neuro.umn.edu>
* src/plugins/EventCmp.py: Convert to db. * src/plugins/EventCmp.py: Convert to db.
* src/plugins/eventcmp.glade: HIGify dialogs. * src/plugins/eventcmp.glade: HIGify dialogs.
* src/plugins/Check.py: Clean up conversion to db.
2004-05-07 Don Allingham <donaldallingham@users.sourceforge.net> 2004-05-07 Don Allingham <donaldallingham@users.sourceforge.net>
* src/DbPrompter.py: handle open dialog in a clean manner * src/DbPrompter.py: handle open dialog in a clean manner

View File

@ -91,22 +91,26 @@ class CheckIntegrity:
self.broken_links = [] self.broken_links = []
for family_id in self.db.get_family_keys(): for family_id in self.db.get_family_keys():
family = self.db.find_family_from_id(family_id) family = self.db.find_family_from_id(family_id)
father = self.db.find_family_from_id(family.get_father_id()) father_id = family.get_father_id()
mother = self.db.find_family_from_id(family.get_mother_id()) mother_id = family.get_mother_id()
if father_id:
father = self.db.find_person_from_id(father_id)
if mother_id:
mother = self.db.find_person_from_id(mother_id)
if father and family_id not in father.get_family_id_list(): if father_id and family_id not in father.get_family_id_list():
Utils.modified() Utils.modified()
self.broken_parent_links.append((father,family)) self.broken_parent_links.append((father_id,family_id))
father.add_family_id(family_id) father.add_family_id(family_id)
self.db.commit_person(father) self.db.commit_person(father)
if mother and family_id not in mother.get_family_id_list(): if mother_id and family_id not in mother.get_family_id_list():
Utils.modified() Utils.modified()
self.broken_parent_links.append((mother,family)) self.broken_parent_links.append((mother_id,family_id))
mother.add_family_id(family_id) mother.add_family_id(family_id)
self.db.commit_person(mother) self.db.commit_person(mother)
for child_id in family.get_child_id_list(): for child_id in family.get_child_id_list():
child = self.db.find_person_from_id(child_id) child = self.db.find_person_from_id(child_id)
if family == child.get_main_parents_family_id(): if family_id == child.get_main_parents_family_id():
continue continue
for family_type in child.get_parent_family_id_list(): for family_type in child.get_parent_family_id_list():
if family_type[0] == family_id: if family_type[0] == family_id:
@ -115,7 +119,7 @@ class CheckIntegrity:
family.remove_child_id(child_id) family.remove_child_id(child_id)
self.db.commit_family(family) self.db.commit_family(family)
Utils.modified() Utils.modified()
self.broken_links.append((child,family)) self.broken_links.append((child_id,family_id))
def cleanup_missing_photos(self,cl=0): def cleanup_missing_photos(self,cl=0):
missmedia_action = 0 missmedia_action = 0
@ -230,35 +234,37 @@ class CheckIntegrity:
def cleanup_empty_families(self,automatic): def cleanup_empty_families(self,automatic):
for key in self.db.get_family_keys(): for key in self.db.get_family_keys():
family = self.db.find_family_from_id(key) family = self.db.find_family_from_id(key)
if family.get_father_id() == None and family.get_mother_id() == None: if not family.get_father_id() and not family.get_mother_id():
Utils.modified() Utils.modified()
self.empty_family.append(family) self.empty_family.append(family_id)
self.delete_empty_family(family) self.delete_empty_family(family_id)
def delete_empty_family(self,family): def delete_empty_family(self,family_id):
for key in self.db.get_person_keys(): for key in self.db.get_person_keys():
child = self.db.find_person_from_id(key) child = self.db.find_person_from_id(key)
child.remove_parent_family_id(family.get_id()) child.remove_parent_family_id(family_id)
child.remove_family_id(family.get_id()) child.remove_family_id(family_id)
self.db.delete_family(family.get_id()) self.db.delete_family(family_id)
def check_parent_relationships(self): def check_parent_relationships(self):
for key in self.db.get_family_keys(): for key in self.db.get_family_keys():
family = self.db.find_family_from_id(key) family = self.db.find_family_from_id(key)
mother_id = family.get_mother_id() mother_id = family.get_mother_id()
father_id = family.get_father_id() father_id = family.get_father_id()
father = self.db.find_family_from_id(father_id) if father_id:
mother = self.db.find_family_from_id(mother_id) father = self.db.find_person_from_id(father_id)
if mother_id:
mother = self.db.find_person_from_id(mother_id)
type = family.get_relationship() type = family.get_relationship()
if not father and not mother: if not father_id and not mother_id:
continue continue
elif father == None: elif not father_id:
if mother.get_gender() == RelLib.Person.male: if mother.get_gender() == RelLib.Person.male:
family.set_father_id(mother_id) family.set_father_id(mother_id)
family.set_mother_id(None) family.set_mother_id(None)
self.db.commit_family(family) self.db.commit_family(family)
elif mother == None: elif not mother_id:
if father.get_gender() == RelLib.Person.female: if father.get_gender() == RelLib.Person.female:
family.set_mother_id(father_id) family.set_mother_id(father_id)
family.set_father_id(None) family.set_father_id(None)
@ -269,16 +275,16 @@ class CheckIntegrity:
if type != "Partners": if type != "Partners":
if fgender == mgender and fgender != RelLib.Person.unknown: if fgender == mgender and fgender != RelLib.Person.unknown:
family.set_relationship("Partners") family.set_relationship("Partners")
self.fam_rel.append(family) self.fam_rel.append(family_id)
self.db.commit_family(family) self.db.commit_family(family)
elif fgender == RelLib.Person.female or mgender == RelLib.Person.male: elif fgender == RelLib.Person.female or mgender == RelLib.Person.male:
family.set_father_id(mother_id) family.set_father_id(mother_id)
family.set_mother_id(father_id) family.set_mother_id(father_id)
self.fam_rel.append(family) self.fam_rel.append(family_id)
self.db.commit_family(family) self.db.commit_family(family)
elif fgender != mgender: elif fgender != mgender:
family.set_relationship("Unknown") family.set_relationship("Unknown")
self.fam_rel.append(family) self.fam_rel.append(family_id)
if fgender == RelLib.Person.female or mgender == RelLib.Person.male: if fgender == RelLib.Person.female or mgender == RelLib.Person.male:
family.set_father_id(mother_id) family.set_father_id(mother_id)
family.set_mother_id(father_id) family.set_mother_id(father_id)
@ -310,10 +316,12 @@ class CheckIntegrity:
self.text.write(_("1 broken child/family link was fixed\n")) self.text.write(_("1 broken child/family link was fixed\n"))
else: else:
self.text.write(_("%d broken child/family links were found\n") % blink) self.text.write(_("%d broken child/family links were found\n") % blink)
for c in self.broken_links: for (person_id,family_id) in self.broken_links:
cn = c[0].get_primary_name().get_name() person = self.db.find_person_from_id(person_id)
f = self.db.find_person_from_id(c[1].get_father_id()) family = self.db.find_family_from_id(family_id)
m = self.db.find_person_from_id(c[1].get_mother_id()) cn = person.get_primary_name().get_name()
f = self.db.find_person_from_id(family.get_father_id())
m = self.db.find_person_from_id(family.get_mother_id())
if f and m: if f and m:
pn = _("%s and %s") % (f.get_primary_name().get_name(),\ pn = _("%s and %s") % (f.get_primary_name().get_name(),\
m.get_primary_name().get_name()) m.get_primary_name().get_name())
@ -331,10 +339,12 @@ class CheckIntegrity:
self.text.write(_("1 broken spouse/family link was fixed\n")) self.text.write(_("1 broken spouse/family link was fixed\n"))
else: else:
self.text.write(_("%d broken spouse/family links were found\n") % plink) self.text.write(_("%d broken spouse/family links were found\n") % plink)
for c in self.broken_parent_links: for (person_id,family_id) in self.broken_parent_links:
cn = c[0].get_primary_name().get_name() person = self.db.find_person_from_id(person_id)
f = self.db.find_person_from_id(c[1].get_father_id()) family = self.db.find_family_from_id(family_id)
m = self.db.find_person_from_id(c[1].get_mother_id()) cn = person.get_primary_name().get_name()
f = self.db.find_person_from_id(family.get_father_id())
m = self.db.find_person_from_id(family.get_mother_id())
if f and m: if f and m:
pn = _("%s and %s") % (f.get_primary_name().get_name(),\ pn = _("%s and %s") % (f.get_primary_name().get_name(),\
m.get_primary_name().get_name()) m.get_primary_name().get_name())
@ -373,9 +383,9 @@ class CheckIntegrity:
return errors return errors
def report(self,cl=0): def report(self,cl=0):
if cl: if cl:
print self.text.getvalue() print self.text.getvalue()
else: else:
base = os.path.dirname(__file__) base = os.path.dirname(__file__)
glade_file = base + os.sep + "summary.glade" glade_file = base + os.sep + "summary.glade"
topDialog = gtk.glade.XML(glade_file,"summary","gramps") topDialog = gtk.glade.XML(glade_file,"summary","gramps")
@ -387,7 +397,7 @@ class CheckIntegrity:
textwindow = topDialog.get_widget("textwindow") textwindow = topDialog.get_widget("textwindow")
Utils.set_titles(top,topDialog.get_widget("title"),title) Utils.set_titles(top,topDialog.get_widget("title"),title)
textwindow.get_buffer().set_text(self.text.getvalue()) textwindow.get_buffer().set_text(self.text.getvalue())
self.text.close() self.text.close()
top.show() top.show()
@ -404,4 +414,3 @@ register_tool(
category=_("Database Processing"), category=_("Database Processing"),
description=_("Checks the database for integrity problems, fixing the problems that it can") description=_("Checks the database for integrity problems, fixing the problems that it can")
) )