From f8f510d5f189163293ea329f810ffde0ba633741 Mon Sep 17 00:00:00 2001 From: Tim G L Lyons Date: Fri, 11 Nov 2011 17:12:43 +0000 Subject: [PATCH] Delete remove_source_references and replace_source_references as they are no longer needed. Rename remove_citation to remove_citation_refs and make it apply to a citation_handle_list. Updated tool/Check.py to change check_source_references into check_citation_references svn: r18433 --- src/Merge/mergesource.py | 2 +- src/gen/lib/citation.py | 43 ------------- src/gen/lib/citationbase.py | 22 +++---- src/gen/lib/eventref.py | 24 ------- src/gen/lib/primaryobj.py | 19 +++--- src/gen/lib/repo.py | 24 ------- src/gen/lib/src.py | 24 ------- src/gen/lib/test/merge_test.py | 2 +- src/gui/editors/editcitation.py | 16 ++--- src/gui/editors/editsource.py | 16 ++--- src/plugins/tool/Check.py | 91 ++++++++++++++------------- src/plugins/tool/TestcaseGenerator.py | 24 +++++++ 12 files changed, 109 insertions(+), 198 deletions(-) diff --git a/src/Merge/mergesource.py b/src/Merge/mergesource.py index 44784e1d9..f1fe88061 100644 --- a/src/Merge/mergesource.py +++ b/src/Merge/mergesource.py @@ -210,7 +210,7 @@ class MergeSourceQuery(object): if class_name == Citation.__name__: citation = self.database.get_citation_from_handle(handle) assert(citation.get_reference_handle() == old_handle) - citation.replace_source_references(old_handle, new_handle) + citation.set_reference_handle(new_handle) self.database.commit_citation(citation, trans) else: raise MergeError("Encounter an object of type %s that has " diff --git a/src/gen/lib/citation.py b/src/gen/lib/citation.py index 91cb2183f..214315f45 100644 --- a/src/gen/lib/citation.py +++ b/src/gen/lib/citation.py @@ -181,20 +181,6 @@ class Citation(MediaBase, NoteBase, PrimaryObject, DateBase): """ return self.media_list -# FIXME: get_sourceRef_child_list needs to be removed - -# def get_sourcref_child_list(self): -# """ -# Return the list of child secondary objects that may refer sources. -# Only the Citation Primary object refers to sources, none of the -# child objects do. -# -# :returns: Returns the list of child secondary child objects that may -# refer sources. -# :rtype: list -# """ -# return [] - def get_note_child_list(self): """ Return the list of child secondary objects that may refer notes. @@ -228,35 +214,6 @@ class Citation(MediaBase, NoteBase, PrimaryObject, DateBase): ret += [('Source', self.get_reference_handle())] return ret -# FIXME: Remove all has_source_refernce and consequently all -# get_sourceref_child_list, because these seem to be only used in the filter -# _HasSourceOf and mergesource, and it is better to make the test directly, -# because, only citations refer to sources, and they have only one reference. -# need to check remove and replace source reference. - def remove_source_references(self, src_handle_list): - """ - Remove 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 - """ - if self.get_reference_handle() in src_handle_list: - self.set_reference_handle(None) - - def replace_source_references(self, old_handle, new_handle): - """ - Replace references to source_handles in the list in this object and - all child objects and merge equivalent entries. - - :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 - """ - if old_handle == self.get_reference_handle(): - self.set_reference_handle(new_handle) - def merge(self, acquisition): """ Merge the content of acquisition into this source. diff --git a/src/gen/lib/citationbase.py b/src/gen/lib/citationbase.py index c1cd1350b..c600f0092 100644 --- a/src/gen/lib/citationbase.py +++ b/src/gen/lib/citationbase.py @@ -93,25 +93,25 @@ class CitationBase(object): self.citation_list.append(handle) return True - def remove_citation(self, handle): + def remove_citation_refs(self, citation_handle_list): """ - Remove the specified handle from the list of citation handles, and all + Remove the specified handles from the list of citation handles, and all secondary child objects. - :param handle: :class:`~gen.lib.citation.Citation` handle to remove - from the list of citations - :type handle: str + :param citation_handle_list: The list of citation handles to be removed + :type handle: list """ LOG.debug('enter remove_citation handle: %s self: %s citation_list: %s' - % (handle, self, self.citation_list)) - if handle in self.citation_list: - LOG.debug('remove handle %s from citation_list %s' % - (handle, self.citation_list)) - self.citation_list.remove(handle) + % (citation_handle_list, self, self.citation_list)) + for handle in citation_handle_list: + if handle in self.citation_list: + LOG.debug('remove handle %s from citation_list %s' % + (handle, self.citation_list)) + self.citation_list.remove(handle) LOG.debug('get_citation_child_list %s' % self.get_citation_child_list()) for item in self.get_citation_child_list(): - item.remove_citation(handle) + item.remove_citation_refs(citation_handle_list) def get_citation_child_list(self): """ diff --git a/src/gen/lib/eventref.py b/src/gen/lib/eventref.py index 3a48bff79..46cb364c2 100644 --- a/src/gen/lib/eventref.py +++ b/src/gen/lib/eventref.py @@ -152,30 +152,6 @@ class EventRef(SecondaryObject, PrivacyBase, NoteBase, AttributeBase, RefBase): """ return self.get_citation_child_list() - def remove_source_references(self, src_handle_list): - """ - Remove 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): - """ - Replace references to source handles in the list in this object and - all child objects and merge equivalent entries. - - :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 is_equivalent(self, other): """ Return if this eventref is equivalent, that is agrees in handle and diff --git a/src/gen/lib/primaryobj.py b/src/gen/lib/primaryobj.py index 0981d317d..99dd691a6 100644 --- a/src/gen/lib/primaryobj.py +++ b/src/gen/lib/primaryobj.py @@ -32,7 +32,7 @@ Basic Primary Object class for GRAMPS. #------------------------------------------------------------------------- from gen.lib.tableobj import TableObject from gen.lib.privacybase import PrivacyBase -from gen.lib.srcbase import SourceBase +from gen.lib.citationbase import CitationBase from gen.lib.mediabase import MediaBase #------------------------------------------------------------------------- @@ -140,7 +140,7 @@ class BasicPrimaryObject(TableObject, PrivacyBase): """ return False - def remove_source_references(self, handle_list): + def remove_citation_references(self, handle_list): """ Remove the specified source references from the object. @@ -158,7 +158,7 @@ class BasicPrimaryObject(TableObject, PrivacyBase): """ pass - def replace_source_references(self, old_handle, new_handle): + def replace_citation_references(self, old_handle, new_handle): pass def replace_media_references(self, old_handle, new_handle): @@ -206,9 +206,8 @@ class PrimaryObject(BasicPrimaryObject): of this object type. :rtype: bool """ - # FIXME: SourceBase is no longer used so this needs to be changed - if classname == 'Source' and isinstance(self, SourceBase): - return self.has_source_reference(handle) + if classname == 'Citation' and isinstance(self, CitationBase): + return self.has_citation_reference(handle) elif classname == 'MediaObject' and isinstance(self, MediaBase): return self.has_media_reference(handle) else: @@ -223,8 +222,8 @@ class PrimaryObject(BasicPrimaryObject): :param handle_list: The list of handles to be removed. :type handle_list: str """ - if classname == 'Source' and isinstance(self, SourceBase): - self.remove_source_references(handle_list) + if classname == 'Citation' and isinstance(self, CitationBase): + self.remove_citation_references(handle_list) elif classname == 'MediaObject' and isinstance(self, MediaBase): self.remove_media_references(handle_list) else: @@ -241,8 +240,8 @@ class PrimaryObject(BasicPrimaryObject): :param new_handle: The handle to replace the old one with. :type new_handle: str """ - if classname == 'Source' and isinstance(self, SourceBase): - self.replace_source_references(old_handle, new_handle) + if classname == 'Citation' and isinstance(self, CitationBase): + self.replace_citation_references(old_handle, new_handle) elif classname == 'MediaObject' and isinstance(self, MediaBase): self.replace_media_references(old_handle, new_handle) else: diff --git a/src/gen/lib/repo.py b/src/gen/lib/repo.py index 228d7b21d..1125f1803 100644 --- a/src/gen/lib/repo.py +++ b/src/gen/lib/repo.py @@ -179,30 +179,6 @@ class Repository(NoteBase, AddressBase, UrlBase, PrimaryObject): for item in self.get_citation_child_list(): item.replace_citation_references(old_handle, new_handle) - def remove_source_references(self, src_handle_list): - """ - Remove 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): - """ - Replace references to source handles in the list in this object and - all child objects and merge equivalent entries. - - :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 merge(self, acquisition): """ Merge the content of acquisition into this repository. diff --git a/src/gen/lib/src.py b/src/gen/lib/src.py index 894e1630e..957149e54 100644 --- a/src/gen/lib/src.py +++ b/src/gen/lib/src.py @@ -192,30 +192,6 @@ class Source(MediaBase, NoteBase, PrimaryObject): """ return self.get_referenced_note_handles() - def remove_source_references(self, src_handle_list): - """ - Remove 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): - """ - Replace references to source_handles in the list in this object and - all child objects and merge equivalent entries. - - :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 merge(self, acquisition): """ Merge the content of acquisition into this source. diff --git a/src/gen/lib/test/merge_test.py b/src/gen/lib/test/merge_test.py index 04ff50934..bf96b6467 100644 --- a/src/gen/lib/test/merge_test.py +++ b/src/gen/lib/test/merge_test.py @@ -21,7 +21,7 @@ # $Id$ """ Unittest that tests the code involved in merging """ - +# FIXME: CITATION: this needs to be updated for citations. import unittest import sys import os diff --git a/src/gui/editors/editcitation.py b/src/gui/editors/editcitation.py index a59d5f575..2fecf76a9 100644 --- a/src/gui/editors/editcitation.py +++ b/src/gui/editors/editcitation.py @@ -449,41 +449,41 @@ class DeleteCitationQuery(object): (person_list, family_list, event_list, place_list, source_list, media_list, repo_list) = self.the_lists - ctn_handle = self.citation.get_handle() + ctn_handle_list = [self.citation.get_handle()] for handle in person_list: person = self.db.get_person_from_handle(handle) - person.remove_citation(ctn_handle) + person.remove_citation_refs(ctn_handle_list) self.db.commit_person(person, trans) for handle in family_list: family = self.db.get_family_from_handle(handle) - family.remove_citation(ctn_handle) + family.remove_citation_refs(ctn_handle_list) self.db.commit_family(family, trans) for handle in event_list: event = self.db.get_event_from_handle(handle) - event.remove_citation(ctn_handle) + event.remove_citation_refs(ctn_handle_list) self.db.commit_event(event, trans) for handle in place_list: place = self.db.get_place_from_handle(handle) - place.remove_citation(ctn_handle) + place.remove_citation_refs(ctn_handle_list) self.db.commit_place(place, trans) for handle in source_list: source = self.db.get_source_from_handle(handle) - source.remove_citation(ctn_handle) + source.remove_citation_refs(ctn_handle_list) self.db.commit_source(source, trans) for handle in media_list: media = self.db.get_object_from_handle(handle) - media.remove_citation(ctn_handle) + media.remove_citation_refs(ctn_handle_list) self.db.commit_media_object(media, trans) for handle in repo_list: repo = self.db.get_repository_from_handle(handle) - repo.remove_citation(ctn_handle) + repo.remove_citation_refs(ctn_handle_list) self.db.commit_repository(repo, trans) self.db.enable_signals() diff --git a/src/gui/editors/editsource.py b/src/gui/editors/editsource.py index e1c5101c1..b5dbfed8f 100644 --- a/src/gui/editors/editsource.py +++ b/src/gui/editors/editsource.py @@ -241,40 +241,42 @@ class DeleteSrcQuery(object): (citation_handle, refs)) (person_list, family_list, event_list, place_list, source_list, media_list, repo_list) = refs + + ctn_handle_list = [citation_handle] for handle in person_list: person = self.db.get_person_from_handle(handle) - person.remove_citation(citation_handle) + person.remove_citation_refs(ctn_handle_list) self.db.commit_person(person, trans) for handle in family_list: family = self.db.get_family_from_handle(handle) - family.remove_citation(citation_handle) + family.remove_citation_refs(ctn_handle_list) self.db.commit_family(family, trans) for handle in event_list: event = self.db.get_event_from_handle(handle) - event.remove_citation(citation_handle) + event.remove_citation_refs(ctn_handle_list) self.db.commit_event(event, trans) for handle in place_list: place = self.db.get_place_from_handle(handle) - place.remove_citation(citation_handle) + place.remove_citation_refs(ctn_handle_list) self.db.commit_place(place, trans) for handle in source_list: source = self.db.get_source_from_handle(handle) - source.remove_citation(citation_handle) + source.remove_citation_refs(ctn_handle_list) self.db.commit_source(source, trans) for handle in media_list: media = self.db.get_object_from_handle(handle) - media.remove_citation(citation_handle) + media.remove_citation_refs(ctn_handle_list) self.db.commit_media_object(media, trans) for handle in repo_list: repo = self.db.get_repository_from_handle(handle) - repo.remove_citation(citation_handle) + repo.remove_citation_refs(ctn_handle_list) self.db.commit_repository(repo, trans) # (2) delete the actual citations diff --git a/src/plugins/tool/Check.py b/src/plugins/tool/Check.py index 0a8d1ef87..1b627dfbb 100644 --- a/src/plugins/tool/Check.py +++ b/src/plugins/tool/Check.py @@ -231,7 +231,8 @@ class Check(tool.BatchTool): checker.check_person_references() checker.check_family_references() checker.check_place_references() - checker.check_source_references() + checker.check_citation_references() + # FIXME: CITATION should also check source references checker.check_media_references() checker.check_repo_references() checker.check_note_references() @@ -266,7 +267,7 @@ class CheckIntegrity(object): self.invalid_person_references = [] self.invalid_family_references = [] self.invalid_place_references = [] - self.invalid_source_references = [] + self.invalid_citation_references = [] self.invalid_repo_references = [] self.invalid_media_references = [] self.invalid_note_references = [] @@ -995,8 +996,8 @@ class CheckIntegrity(object): self.db.commit_event(event, self.trans) self.invalid_place_references.append(key) - def check_source_references(self): - known_handles = self.db.get_source_handles() + def check_citation_references(self): + known_handles = self.db.get_citation_handles() total = ( self.db.get_number_of_people() + @@ -1008,7 +1009,7 @@ class CheckIntegrity(object): self.db.get_number_of_repositories() ) - self.progress.set_pass(_('Looking for source reference problems'), + self.progress.set_pass(_('Looking for citation reference problems'), total) for handle in self.db.person_map.keys(): @@ -1018,14 +1019,14 @@ class CheckIntegrity(object): person.unserialize(info) handle_list = person.get_referenced_handles_recursively() bad_handles = [ item[1] for item in handle_list - if item[0] == 'Source' and + if item[0] == 'Citation' and item[1] not in known_handles ] if bad_handles: - person.remove_source_references(bad_handles) + person.remove_citation_refs(bad_handles) self.db.commit_person(person,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 + not in self.invalid_citation_references] + self.invalid_citation_references += new_bad_handles for handle in self.db.family_map.keys(): self.progress.step() @@ -1034,14 +1035,14 @@ class CheckIntegrity(object): family.unserialize(info) handle_list = family.get_referenced_handles_recursively() bad_handles = [ item[1] for item in handle_list - if item[0] == 'Source' and + if item[0] == 'Citation' and item[1] not in known_handles ] if bad_handles: - family.remove_source_references(bad_handles) + family.remove_citation_refs(bad_handles) self.db.commit_family(family, 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 + not in self.invalid_citation_references] + self.invalid_citation_references += new_bad_handles for handle in self.db.place_map.keys(): self.progress.step() @@ -1050,14 +1051,14 @@ class CheckIntegrity(object): place.unserialize(info) handle_list = place.get_referenced_handles_recursively() bad_handles = [ item[1] for item in handle_list - if item[0] == 'Source' and + if item[0] == 'Citation' and item[1] not in known_handles ] if bad_handles: - place.remove_source_references(bad_handles) + place.remove_citation_refs(bad_handles) self.db.commit_place(place,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 + not in self.invalid_citation_references] + self.invalid_citation_references += new_bad_handles for handle in self.db.repository_map.keys(): self.progress.step() @@ -1066,31 +1067,31 @@ class CheckIntegrity(object): repo.unserialize(info) handle_list = repo.get_referenced_handles_recursively() bad_handles = [ item[1] for item in handle_list - if item[0] == 'Source' and + if item[0] == 'Citation' and item[1] not in known_handles ] if bad_handles: - repo.remove_source_references(bad_handles) + repo.remove_citation_refs(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 + not in self.invalid_citation_references] + self.invalid_citation_references += new_bad_handles - #I think this for loop is useless! sources in sources map exist... + #I think this for loop is useless! citations in citations map exist... for handle in known_handles: self.progress.step() - info = self.db.source_map[handle] - source = gen.lib.Source() - source.unserialize(info) - handle_list = source.get_referenced_handles_recursively() + info = self.db.citation_map[handle] + citation = gen.lib.Citation() + citation.unserialize(info) + handle_list = citation.get_referenced_handles_recursively() bad_handles = [ item[1] for item in handle_list - if item[0] == 'Source' and + if item[0] == 'Citation' and item[1] not in known_handles ] if bad_handles: - source.remove_source_references(bad_handles) - self.db.commit_source(source, self.trans) + citation.remove_citation_refs(bad_handles) + self.db.commit_citation(citation, 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 + not in self.invalid_citation_references] + self.invalid_citation_references += new_bad_handles for handle in self.db.media_map.keys(): self.progress.step() @@ -1099,14 +1100,14 @@ class CheckIntegrity(object): obj.unserialize(info) handle_list = obj.get_referenced_handles_recursively() bad_handles = [ item[1] for item in handle_list - if item[0] == 'Source' and + if item[0] == 'Citation' and item[1] not in known_handles ] if bad_handles: - obj.remove_source_references(bad_handles) + obj.remove_citation_refs(bad_handles) self.db.commit_media_object(obj, 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 + not in self.invalid_citation_references] + self.invalid_citation_references += new_bad_handles for handle in self.db.event_map.keys(): self.progress.step() @@ -1115,14 +1116,14 @@ class CheckIntegrity(object): event.unserialize(info) handle_list = event.get_referenced_handles_recursively() bad_handles = [ item[1] for item in handle_list - if item[0] == 'Source' and + if item[0] == 'Citation' and item[1] not in known_handles ] if bad_handles: - event.remove_source_references(bad_handles) + event.remove_citation_refs(bad_handles) self.db.commit_event(event, 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 + not in self.invalid_citation_references] + self.invalid_citation_references += new_bad_handles def check_media_references(self): known_handles = self.db.get_media_object_handles(False) @@ -1367,7 +1368,7 @@ class CheckIntegrity(object): family_references = len(self.invalid_family_references) invalid_dates = len(self.invalid_dates) place_references = len(self.invalid_place_references) - source_references = len(self.invalid_source_references) + citation_references = len(self.invalid_citation_references) repo_references = len(self.invalid_repo_references) media_references = len(self.invalid_media_references) note_references = len(self.invalid_note_references) @@ -1377,7 +1378,7 @@ class CheckIntegrity(object): errors = (photos + efam + blink + plink + slink + rel + event_invalid + person + person_references + family_references + place_references + - source_references + repo_references + media_references + + citation_references + repo_references + media_references + note_references + name_format + empty_objs + invalid_dates ) @@ -1559,11 +1560,11 @@ class CheckIntegrity(object): place_references) % {'quantity': place_references} ) - if source_references: + if citation_references: self.text.write( - ngettext("%(quantity)d source was referenced but not found\n", - "%(quantity)d sources were referenced, but not found\n", - source_references) % {'quantity': source_references} + ngettext("%(quantity)d citation was referenced but not found\n", + "%(quantity)d citations were referenced, but not found\n", + citation_references) % {'quantity': citation_references} ) if media_references: diff --git a/src/plugins/tool/TestcaseGenerator.py b/src/plugins/tool/TestcaseGenerator.py index 5bf780719..4fcd60ac2 100644 --- a/src/plugins/tool/TestcaseGenerator.py +++ b/src/plugins/tool/TestcaseGenerator.py @@ -336,6 +336,30 @@ class TestcaseGenerator(tool.BatchTool): # self.rand_media() + # FIXME: generate_tags needs to be run before generate_broken_relations + # otherwise you get + +# File "/Users/tim/gramps/gramps33/src/plugins/tool/TestcaseGenerator.py", line 1404, in rand_tags +# tag = choice(self.generated_tags) +# File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/random.py", line 261, in choice +# return seq[int(self.random() * len(seq))] # raises IndexError if seq is empty +#IndexError: list index out of range + + # FIXME: If tags have arbitrary forms, then you can get errors because + # add_ui_from_string parses the tag as part of parsing + + +# Traceback (most recent call last): +# File "/Users/tim/gramps/gramps33/src/gui/viewmanager.py", line 1265, in view_changed +# self.__change_page(page_num) +# File "/Users/tim/gramps/gramps33/src/gui/viewmanager.py", line 1278, in __change_page +# self.active_page.set_active() +# File "/Users/tim/gramps/gramps33/src/plugins/lib/libpersonview.py", line 399, in set_active +# self.uistate.viewmanager.tags.tag_enable() +# File "/Users/tim/gramps/gramps33/src/gui/views/tags.py", line 122, in tag_enable +# self.tag_id = self.uistate.uimanager.add_ui_from_string(self.tag_ui) +#GError: Error on line 6 char 470: '#+#000001#-#' is not a valid name + if self.options.handler.options_dict['bugs']: self.generate_broken_relations()