diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 0a224bba2..9bf135ccb 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,8 @@ +2005-05-18 Martin Hawlisch + * src/GrampsBSDDB.py, src/GrampsDbBase.py, src/GrampsInMemDB.py, + src/RelLib.py: Catch invalid arguments instead of crashing. + TODO: raise TypeError or HandleError instead of simply returning? + 2005-05-17 Alex Roitman * src/GenericFilter.py: Change filter rule names to make them consistent. * src/gramps_main.py: Change filter names to make them consistent. diff --git a/gramps2/src/GrampsBSDDB.py b/gramps2/src/GrampsBSDDB.py index 77773810a..bfb6f205d 100644 --- a/gramps2/src/GrampsBSDDB.py +++ b/gramps2/src/GrampsBSDDB.py @@ -275,7 +275,7 @@ class GrampsBSDDB(GrampsDbBase): return vals def remove_person(self,handle,transaction): - if not self.readonly: + if not self.readonly and handle and str(handle) in self.person_map: person = self.get_person_from_handle(handle) self.genderStats.uncount_person (person) if transaction != None: @@ -284,7 +284,7 @@ class GrampsBSDDB(GrampsDbBase): self.person_map.delete(str(handle)) def remove_source(self,handle,transaction): - if not self.readonly: + if not self.readonly and handle and str(handle) in self.source_map: if transaction != None: old_data = self.source_map.get(str(handle)) transaction.add(SOURCE_KEY,handle,old_data) @@ -292,7 +292,7 @@ class GrampsBSDDB(GrampsDbBase): self.source_map.delete(str(handle)) def remove_family(self,handle,transaction): - if not self.readonly: + if not self.readonly and handle and str(handle) in self.family_map: if transaction != None: old_data = self.family_map.get(str(handle)) transaction.add(FAMILY_KEY,handle,old_data) @@ -300,14 +300,14 @@ class GrampsBSDDB(GrampsDbBase): self.family_map.delete(str(handle)) def remove_event(self,handle,transaction): - if not self.readonly: + if not self.readonly and handle and str(handle) in self.event_map: if transaction != None: old_data = self.event_map.get(str(handle)) transaction.add(EVENT_KEY,handle,old_data) self.event_map.delete(str(handle)) def remove_place(self,handle,transaction): - if not self.readonly: + if not self.readonly and handle and str(handle) in self.place_map: if transaction != None: old_data = self.place_map.get(handle) transaction.add(PLACE_KEY,handle,old_data) @@ -315,7 +315,7 @@ class GrampsBSDDB(GrampsDbBase): self.place_map.delete(str(handle)) def remove_object(self,handle,transaction): - if not self.readonly: + if not self.readonly and handle and str(handle) in self.media_map: if transaction != None: old_data = self.media_map.get(handle) transaction.add(PLACE_KEY,handle,old_data) diff --git a/gramps2/src/GrampsDbBase.py b/gramps2/src/GrampsDbBase.py index 35a20dbf2..293e6cf44 100644 --- a/gramps2/src/GrampsDbBase.py +++ b/gramps2/src/GrampsDbBase.py @@ -265,7 +265,7 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback): Commits the specified Person to the database, storing the changes as part of the transaction. """ - if self.readonly or not person.get_handle(): + if self.readonly or not person or not person.get_handle(): return if change_time: person.change = int(change_time) @@ -287,7 +287,7 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback): Commits the specified MediaObject to the database, storing the changes as part of the transaction. """ - if self.readonly or not obj.get_handle(): + if self.readonly or not obj or not obj.get_handle(): return if change_time: obj.change = int(change_time) @@ -308,7 +308,7 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback): Commits the specified Source to the database, storing the changes as part of the transaction. """ - if self.readonly or not source.get_handle(): + if self.readonly or not source or not source.get_handle(): return if change_time: source.change = int(change_time) @@ -329,7 +329,7 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback): Commits the specified Place to the database, storing the changes as part of the transaction. """ - if self.readonly or not place.get_handle(): + if self.readonly or not place or not place.get_handle(): return if change_time: place.change = int(change_time) @@ -350,7 +350,7 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback): Commits the specified Event to the database, storing the changes as part of the transaction. """ - if self.readonly or not event.get_handle(): + if self.readonly or not event or not event.get_handle(): return if change_time: event.change = int(change_time) @@ -367,7 +367,7 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback): Commits the specified Family to the database, storing the changes as part of the transaction. """ - if self.readonly or not family.handle: + if self.readonly or not family or not family.handle: return if change_time: family.change = int(change_time) @@ -648,6 +648,8 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback): Adds a Person to the database, assigning internal IDs if they have not already been defined. """ + if not person: + return None if not person.get_gramps_id(): person.set_gramps_id(self.find_next_person_gramps_id()) if not person.get_handle(): @@ -661,6 +663,8 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback): Adds a Family to the database, assigning internal IDs if they have not already been defined. """ + if not family: + return None if family.get_gramps_id() == None: family.set_gramps_id(self.find_next_family_gramps_id()) if family.get_handle() == None: @@ -673,6 +677,8 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback): Adds a Source to the database, assigning internal IDs if they have not already been defined. """ + if not source: + return None if source.get_handle() == None: source.set_handle(self.create_id()) if source.get_gramps_id() == None: @@ -685,6 +691,8 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback): Adds an Event to the database, assigning internal IDs if they have not already been defined. """ + if not event: + return None if event.get_handle() == None: event.set_handle(self.create_id()) if event.get_gramps_id() == None: @@ -697,6 +705,8 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback): Adds a Place to the database, assigning internal IDs if they have not already been defined. """ + if not place: + return None if place.get_handle() == None: index = self.create_id() place.set_handle(index) @@ -710,6 +720,8 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback): Adds a MediaObject to the database, assigning internal IDs if they have not already been defined. """ + if not obj: + return None index = obj.get_handle() if index == None: index = self.create_id() diff --git a/gramps2/src/GrampsInMemDB.py b/gramps2/src/GrampsInMemDB.py index 392b060f0..409e955c4 100644 --- a/gramps2/src/GrampsInMemDB.py +++ b/gramps2/src/GrampsInMemDB.py @@ -135,7 +135,7 @@ class GrampsInMemDB(GrampsDbBase): return vals def remove_person(self,handle,transaction): - if self.readonly: + if self.readonly or not handle or str(handle) not in self.person_map: return person = self.get_person_from_handle(handle) self.genderStats.uncount_person (person) @@ -147,7 +147,7 @@ class GrampsInMemDB(GrampsDbBase): del self.person_map[handle] def remove_source(self,handle,transaction): - if self.readonly: + if self.readonly or not handle or str(handle) not in self.source_map: return source = self.get_source_from_handle(handle) if transaction != None: @@ -158,7 +158,7 @@ class GrampsInMemDB(GrampsDbBase): del self.source_map[str(handle)] def remove_place(self,handle,transaction): - if self.readonly: + if self.readonly or not handle or str(handle) not in self.place_map: return place = self.get_place_from_handle(handle) if transaction != None: @@ -169,7 +169,7 @@ class GrampsInMemDB(GrampsDbBase): del self.place_map[str(handle)] def remove_object(self,handle,transaction): - if self.readonly: + if self.readonly or not handle or str(handle) not in self.media_map: return obj = self.get_object_from_handle(handle) if transaction != None: @@ -179,7 +179,7 @@ class GrampsInMemDB(GrampsDbBase): del self.media_map[str(handle)] def remove_family(self,handle,transaction): - if self.readonly: + if self.readonly or not handle or str(handle) not in self.family_map: return family = self.get_family_from_handle(handle) if transaction != None: @@ -190,7 +190,7 @@ class GrampsInMemDB(GrampsDbBase): del self.family_map[str(handle)] def remove_event(self,handle,transaction): - if self.readonly: + if self.readonly or not handle or str(handle) not in self.event_map: return if transaction != None: old_data = self.event_map.get(str(handle)) @@ -198,35 +198,35 @@ class GrampsInMemDB(GrampsDbBase): del self.event_map[str(handle)] def commit_person(self,person,transaction,change_time=None): - if self.readonly or not person.get_handle(): + if self.readonly or not person or not person.get_handle(): return gid = person.get_gramps_id() self.id_trans[gid] = person.get_handle() GrampsDbBase.commit_person(self,person,transaction,change_time) def commit_place(self,place,transaction,change_time=None): - if self.readonly or not place.get_handle(): + if self.readonly or not place or not place.get_handle(): return gid = place.get_gramps_id() self.pid_trans[gid] = place.get_handle() GrampsDbBase.commit_place(self,place,transaction,change_time) def commit_family(self,family,transaction,change_time=None): - if self.readonly or not family.get_handle(): + if self.readonly or not family or not family.get_handle(): return gid = family.get_gramps_id() self.fid_trans[gid] = family.get_handle() GrampsDbBase.commit_family(self,family,transaction,change_time) def commit_media_object(self,obj,transaction,change_time=None): - if self.readonly or not obj.get_handle(): + if self.readonly or not obj or not obj.get_handle(): return gid = obj.get_gramps_id() self.oid_trans[gid] = obj.get_handle() GrampsDbBase.commit_media_object(self,obj,transaction,change_time) def commit_source(self,source,transaction,change_time=None): - if self.readonly or not source.get_handle(): + if self.readonly or not source or not source.get_handle(): return gid = source.get_gramps_id() self.sid_trans[gid] = source.get_handle() diff --git a/gramps2/src/RelLib.py b/gramps2/src/RelLib.py index 8cb00fd09..73fb1fd32 100644 --- a/gramps2/src/RelLib.py +++ b/gramps2/src/RelLib.py @@ -4046,6 +4046,8 @@ class GenderStats: return (0, 0, 0) def count_person (self, person, db, undo = 0): + if not person: + return # Let the Person do their own counting later person.db = db