From 8b7136ddd9c085ed67231f5216571b57c04b3415 Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Wed, 19 Dec 2007 09:28:43 +0000 Subject: [PATCH] 2007-12-17 Benny Malengier * src/RelLib/_Person.py: sources in attributes of eventref are not seen in ref tables * src/RelLib/_EventRef.py: can contain sources, add methods for that * src/plugins/Check.py: low level check of repo table, add check to clean up referenced but not existing repos svn: r9531 --- ChangeLog | 7 ++++++ src/RelLib/_EventRef.py | 54 +++++++++++++++++++++++++++++++++++++++-- src/RelLib/_Person.py | 5 ++-- src/plugins/Check.py | 24 +++++++++++++++--- 4 files changed, 82 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index bef9a4a29..6b54b7caa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-12-17 Benny Malengier + * src/RelLib/_Person.py: sources in attributes of eventref are not seen + in ref tables + * src/RelLib/_EventRef.py: can contain sources, add methods for that + * src/plugins/Check.py: low level check of repo table, add check to + clean up referenced but not existing repos + 2007-12-15 Gary Burton * src/Editors/_EditFamily.py: emit family-update signal #1416 diff --git a/src/RelLib/_EventRef.py b/src/RelLib/_EventRef.py index 6b84b16bb..9b758242a 100644 --- a/src/RelLib/_EventRef.py +++ b/src/RelLib/_EventRef.py @@ -105,7 +105,7 @@ class EventRef(SecondaryObject, PrivacyBase, NoteBase, AttributeBase, RefBase): @return: Returns the list of child objects that may carry textual data. @rtype: list """ - check_list = self.attribute_list[:] + check_list = self.attribute_list if self.note: check_list.append(self.note) return check_list @@ -117,7 +117,7 @@ class EventRef(SecondaryObject, PrivacyBase, NoteBase, AttributeBase, RefBase): @return: Returns the list of child secondary child objects that may refer sources. @rtype: list """ - return self.attribute_list[:] + return self.attribute_list def get_referenced_handles(self): """ @@ -132,6 +132,56 @@ class EventRef(SecondaryObject, PrivacyBase, NoteBase, AttributeBase, RefBase): else: return [] + def get_handle_referents(self): + """ + Returns the list of child objects which may, directly or through + their children, reference primary objects.. + + @return: Returns the list of objects refereincing primary objects. + @rtype: list + """ + return self.get_sourcref_child_list() + + def has_source_reference(self, src_handle) : + """ + Returns True if any of the child objects has reference + to this source handle. + + @param src_handle: The source handle to be checked. + @type src_handle: str + @return: Returns whether any of it's child objects has reference to this source handle. + @rtype: bool + """ + for item in self.get_sourcref_child_list(): + if item.has_source_reference(src_handle): + return True + + return False + + def remove_source_references(self, src_handle_list): + """ + Removes references to all source handles in the list + in all child objects. + + @param src_handle_list: The list of source handles to be removed. + @type src_handle_list: list + """ + for item in self.get_sourcref_child_list(): + item.remove_source_references(src_handle_list) + + def replace_source_references(self, old_handle, new_handle): + """ + Replaces references to source handles in the list + in this object and all child objects. + + @param old_handle: The source handle to be replaced. + @type old_handle: str + @param new_handle: The source handle to replace the old one with. + @type new_handle: str + """ + for item in self.get_sourcref_child_list(): + item.replace_source_references(old_handle, new_handle) + def get_role(self): """ Returns the tuple corresponding to the preset role. diff --git a/src/RelLib/_Person.py b/src/RelLib/_Person.py index 93d04a789..88c1df862 100644 --- a/src/RelLib/_Person.py +++ b/src/RelLib/_Person.py @@ -324,7 +324,7 @@ class Person(SourceBase, NoteBase, AttributeBase, MediaBase, return [self.primary_name] + self.media_list + \ self.alternate_names + self.address_list + \ self.attribute_list + self.lds_ord_list + \ - self.person_ref_list + self.person_ref_list + self.event_ref_list def get_referenced_handles(self): """ @@ -345,8 +345,7 @@ class Person(SourceBase, NoteBase, AttributeBase, MediaBase, @return: Returns the list of objects refereincing primary objects. @rtype: list """ - return self.get_sourcref_child_list() + self.source_list \ - + self.event_ref_list + return self.get_sourcref_child_list() + self.source_list def set_primary_name(self, name): """ diff --git a/src/plugins/Check.py b/src/plugins/Check.py index 658d9a431..df2d22539 100644 --- a/src/plugins/Check.py +++ b/src/plugins/Check.py @@ -83,7 +83,8 @@ def low_level(db): ('Event',db.event_map), ('Place',db.place_map), ('Source',db.source_map), - ('Media',db.media_map)]: + ('Media',db.media_map), + ('Repository', db.repository_map)]: print "Low-level repair: table: %s" % the_map[0] if _table_low_level(db,the_map[1]): @@ -887,7 +888,8 @@ class CheckIntegrity: total = self.db.get_number_of_people() + self.db.get_number_of_families() + \ self.db.get_number_of_events() + self.db.get_number_of_places() + \ self.db.get_number_of_media_objects() + \ - self.db.get_number_of_sources() + self.db.get_number_of_sources() + \ + self.db.get_number_of_repositories() self.progress.set_pass(_('Looking for source reference problems'), total) @@ -988,7 +990,23 @@ class CheckIntegrity: new_bad_handles = [handle for handle in bad_handles if handle not in self.invalid_source_references] self.invalid_source_references += new_bad_handles - + + for handle in self.db.repository_map.keys(): + self.progress.step() + info = self.db.repository_map[handle] + repo = RelLib.Repository() + repo.unserialize(info) + handle_list = repo.get_referenced_handles_recursively() + bad_handles = [ item[1] for item in handle_list + if item[0] == 'Source' and + item[1] not in known_handles ] + if bad_handles: + repo.remove_source_references(bad_handles) + self.db.commit_repository(repo,self.trans) + new_bad_handles = [handle for handle in bad_handles if handle + not in self.invalid_source_references] + self.invalid_source_references += new_bad_handles + def check_media_references(self): known_handles = self.db.get_media_object_handles(False)