* 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? svn: r4613
This commit is contained in:
@ -1,3 +1,8 @@
|
|||||||
|
2005-05-18 Martin Hawlisch <Martin.Hawlisch@gmx.de>
|
||||||
|
* 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 <shura@gramps-project.org>
|
2005-05-17 Alex Roitman <shura@gramps-project.org>
|
||||||
* src/GenericFilter.py: Change filter rule names to make them consistent.
|
* src/GenericFilter.py: Change filter rule names to make them consistent.
|
||||||
* src/gramps_main.py: Change filter names to make them consistent.
|
* src/gramps_main.py: Change filter names to make them consistent.
|
||||||
|
@ -275,7 +275,7 @@ class GrampsBSDDB(GrampsDbBase):
|
|||||||
return vals
|
return vals
|
||||||
|
|
||||||
def remove_person(self,handle,transaction):
|
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)
|
person = self.get_person_from_handle(handle)
|
||||||
self.genderStats.uncount_person (person)
|
self.genderStats.uncount_person (person)
|
||||||
if transaction != None:
|
if transaction != None:
|
||||||
@ -284,7 +284,7 @@ class GrampsBSDDB(GrampsDbBase):
|
|||||||
self.person_map.delete(str(handle))
|
self.person_map.delete(str(handle))
|
||||||
|
|
||||||
def remove_source(self,handle,transaction):
|
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:
|
if transaction != None:
|
||||||
old_data = self.source_map.get(str(handle))
|
old_data = self.source_map.get(str(handle))
|
||||||
transaction.add(SOURCE_KEY,handle,old_data)
|
transaction.add(SOURCE_KEY,handle,old_data)
|
||||||
@ -292,7 +292,7 @@ class GrampsBSDDB(GrampsDbBase):
|
|||||||
self.source_map.delete(str(handle))
|
self.source_map.delete(str(handle))
|
||||||
|
|
||||||
def remove_family(self,handle,transaction):
|
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:
|
if transaction != None:
|
||||||
old_data = self.family_map.get(str(handle))
|
old_data = self.family_map.get(str(handle))
|
||||||
transaction.add(FAMILY_KEY,handle,old_data)
|
transaction.add(FAMILY_KEY,handle,old_data)
|
||||||
@ -300,14 +300,14 @@ class GrampsBSDDB(GrampsDbBase):
|
|||||||
self.family_map.delete(str(handle))
|
self.family_map.delete(str(handle))
|
||||||
|
|
||||||
def remove_event(self,handle,transaction):
|
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:
|
if transaction != None:
|
||||||
old_data = self.event_map.get(str(handle))
|
old_data = self.event_map.get(str(handle))
|
||||||
transaction.add(EVENT_KEY,handle,old_data)
|
transaction.add(EVENT_KEY,handle,old_data)
|
||||||
self.event_map.delete(str(handle))
|
self.event_map.delete(str(handle))
|
||||||
|
|
||||||
def remove_place(self,handle,transaction):
|
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:
|
if transaction != None:
|
||||||
old_data = self.place_map.get(handle)
|
old_data = self.place_map.get(handle)
|
||||||
transaction.add(PLACE_KEY,handle,old_data)
|
transaction.add(PLACE_KEY,handle,old_data)
|
||||||
@ -315,7 +315,7 @@ class GrampsBSDDB(GrampsDbBase):
|
|||||||
self.place_map.delete(str(handle))
|
self.place_map.delete(str(handle))
|
||||||
|
|
||||||
def remove_object(self,handle,transaction):
|
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:
|
if transaction != None:
|
||||||
old_data = self.media_map.get(handle)
|
old_data = self.media_map.get(handle)
|
||||||
transaction.add(PLACE_KEY,handle,old_data)
|
transaction.add(PLACE_KEY,handle,old_data)
|
||||||
|
@ -265,7 +265,7 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback):
|
|||||||
Commits the specified Person to the database, storing the changes
|
Commits the specified Person to the database, storing the changes
|
||||||
as part of the transaction.
|
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
|
return
|
||||||
if change_time:
|
if change_time:
|
||||||
person.change = int(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
|
Commits the specified MediaObject to the database, storing the changes
|
||||||
as part of the transaction.
|
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
|
return
|
||||||
if change_time:
|
if change_time:
|
||||||
obj.change = int(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
|
Commits the specified Source to the database, storing the changes
|
||||||
as part of the transaction.
|
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
|
return
|
||||||
if change_time:
|
if change_time:
|
||||||
source.change = int(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
|
Commits the specified Place to the database, storing the changes
|
||||||
as part of the transaction.
|
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
|
return
|
||||||
if change_time:
|
if change_time:
|
||||||
place.change = int(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
|
Commits the specified Event to the database, storing the changes
|
||||||
as part of the transaction.
|
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
|
return
|
||||||
if change_time:
|
if change_time:
|
||||||
event.change = int(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
|
Commits the specified Family to the database, storing the changes
|
||||||
as part of the transaction.
|
as part of the transaction.
|
||||||
"""
|
"""
|
||||||
if self.readonly or not family.handle:
|
if self.readonly or not family or not family.handle:
|
||||||
return
|
return
|
||||||
if change_time:
|
if change_time:
|
||||||
family.change = int(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
|
Adds a Person to the database, assigning internal IDs if they have
|
||||||
not already been defined.
|
not already been defined.
|
||||||
"""
|
"""
|
||||||
|
if not person:
|
||||||
|
return None
|
||||||
if not person.get_gramps_id():
|
if not person.get_gramps_id():
|
||||||
person.set_gramps_id(self.find_next_person_gramps_id())
|
person.set_gramps_id(self.find_next_person_gramps_id())
|
||||||
if not person.get_handle():
|
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
|
Adds a Family to the database, assigning internal IDs if they have
|
||||||
not already been defined.
|
not already been defined.
|
||||||
"""
|
"""
|
||||||
|
if not family:
|
||||||
|
return None
|
||||||
if family.get_gramps_id() == None:
|
if family.get_gramps_id() == None:
|
||||||
family.set_gramps_id(self.find_next_family_gramps_id())
|
family.set_gramps_id(self.find_next_family_gramps_id())
|
||||||
if family.get_handle() == None:
|
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
|
Adds a Source to the database, assigning internal IDs if they have
|
||||||
not already been defined.
|
not already been defined.
|
||||||
"""
|
"""
|
||||||
|
if not source:
|
||||||
|
return None
|
||||||
if source.get_handle() == None:
|
if source.get_handle() == None:
|
||||||
source.set_handle(self.create_id())
|
source.set_handle(self.create_id())
|
||||||
if source.get_gramps_id() == None:
|
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
|
Adds an Event to the database, assigning internal IDs if they have
|
||||||
not already been defined.
|
not already been defined.
|
||||||
"""
|
"""
|
||||||
|
if not event:
|
||||||
|
return None
|
||||||
if event.get_handle() == None:
|
if event.get_handle() == None:
|
||||||
event.set_handle(self.create_id())
|
event.set_handle(self.create_id())
|
||||||
if event.get_gramps_id() == None:
|
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
|
Adds a Place to the database, assigning internal IDs if they have
|
||||||
not already been defined.
|
not already been defined.
|
||||||
"""
|
"""
|
||||||
|
if not place:
|
||||||
|
return None
|
||||||
if place.get_handle() == None:
|
if place.get_handle() == None:
|
||||||
index = self.create_id()
|
index = self.create_id()
|
||||||
place.set_handle(index)
|
place.set_handle(index)
|
||||||
@ -710,6 +720,8 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback):
|
|||||||
Adds a MediaObject to the database, assigning internal IDs if they have
|
Adds a MediaObject to the database, assigning internal IDs if they have
|
||||||
not already been defined.
|
not already been defined.
|
||||||
"""
|
"""
|
||||||
|
if not obj:
|
||||||
|
return None
|
||||||
index = obj.get_handle()
|
index = obj.get_handle()
|
||||||
if index == None:
|
if index == None:
|
||||||
index = self.create_id()
|
index = self.create_id()
|
||||||
|
@ -135,7 +135,7 @@ class GrampsInMemDB(GrampsDbBase):
|
|||||||
return vals
|
return vals
|
||||||
|
|
||||||
def remove_person(self,handle,transaction):
|
def remove_person(self,handle,transaction):
|
||||||
if self.readonly:
|
if self.readonly or not handle or str(handle) not in self.person_map:
|
||||||
return
|
return
|
||||||
person = self.get_person_from_handle(handle)
|
person = self.get_person_from_handle(handle)
|
||||||
self.genderStats.uncount_person (person)
|
self.genderStats.uncount_person (person)
|
||||||
@ -147,7 +147,7 @@ class GrampsInMemDB(GrampsDbBase):
|
|||||||
del self.person_map[handle]
|
del self.person_map[handle]
|
||||||
|
|
||||||
def remove_source(self,handle,transaction):
|
def remove_source(self,handle,transaction):
|
||||||
if self.readonly:
|
if self.readonly or not handle or str(handle) not in self.source_map:
|
||||||
return
|
return
|
||||||
source = self.get_source_from_handle(handle)
|
source = self.get_source_from_handle(handle)
|
||||||
if transaction != None:
|
if transaction != None:
|
||||||
@ -158,7 +158,7 @@ class GrampsInMemDB(GrampsDbBase):
|
|||||||
del self.source_map[str(handle)]
|
del self.source_map[str(handle)]
|
||||||
|
|
||||||
def remove_place(self,handle,transaction):
|
def remove_place(self,handle,transaction):
|
||||||
if self.readonly:
|
if self.readonly or not handle or str(handle) not in self.place_map:
|
||||||
return
|
return
|
||||||
place = self.get_place_from_handle(handle)
|
place = self.get_place_from_handle(handle)
|
||||||
if transaction != None:
|
if transaction != None:
|
||||||
@ -169,7 +169,7 @@ class GrampsInMemDB(GrampsDbBase):
|
|||||||
del self.place_map[str(handle)]
|
del self.place_map[str(handle)]
|
||||||
|
|
||||||
def remove_object(self,handle,transaction):
|
def remove_object(self,handle,transaction):
|
||||||
if self.readonly:
|
if self.readonly or not handle or str(handle) not in self.media_map:
|
||||||
return
|
return
|
||||||
obj = self.get_object_from_handle(handle)
|
obj = self.get_object_from_handle(handle)
|
||||||
if transaction != None:
|
if transaction != None:
|
||||||
@ -179,7 +179,7 @@ class GrampsInMemDB(GrampsDbBase):
|
|||||||
del self.media_map[str(handle)]
|
del self.media_map[str(handle)]
|
||||||
|
|
||||||
def remove_family(self,handle,transaction):
|
def remove_family(self,handle,transaction):
|
||||||
if self.readonly:
|
if self.readonly or not handle or str(handle) not in self.family_map:
|
||||||
return
|
return
|
||||||
family = self.get_family_from_handle(handle)
|
family = self.get_family_from_handle(handle)
|
||||||
if transaction != None:
|
if transaction != None:
|
||||||
@ -190,7 +190,7 @@ class GrampsInMemDB(GrampsDbBase):
|
|||||||
del self.family_map[str(handle)]
|
del self.family_map[str(handle)]
|
||||||
|
|
||||||
def remove_event(self,handle,transaction):
|
def remove_event(self,handle,transaction):
|
||||||
if self.readonly:
|
if self.readonly or not handle or str(handle) not in self.event_map:
|
||||||
return
|
return
|
||||||
if transaction != None:
|
if transaction != None:
|
||||||
old_data = self.event_map.get(str(handle))
|
old_data = self.event_map.get(str(handle))
|
||||||
@ -198,35 +198,35 @@ class GrampsInMemDB(GrampsDbBase):
|
|||||||
del self.event_map[str(handle)]
|
del self.event_map[str(handle)]
|
||||||
|
|
||||||
def commit_person(self,person,transaction,change_time=None):
|
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
|
return
|
||||||
gid = person.get_gramps_id()
|
gid = person.get_gramps_id()
|
||||||
self.id_trans[gid] = person.get_handle()
|
self.id_trans[gid] = person.get_handle()
|
||||||
GrampsDbBase.commit_person(self,person,transaction,change_time)
|
GrampsDbBase.commit_person(self,person,transaction,change_time)
|
||||||
|
|
||||||
def commit_place(self,place,transaction,change_time=None):
|
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
|
return
|
||||||
gid = place.get_gramps_id()
|
gid = place.get_gramps_id()
|
||||||
self.pid_trans[gid] = place.get_handle()
|
self.pid_trans[gid] = place.get_handle()
|
||||||
GrampsDbBase.commit_place(self,place,transaction,change_time)
|
GrampsDbBase.commit_place(self,place,transaction,change_time)
|
||||||
|
|
||||||
def commit_family(self,family,transaction,change_time=None):
|
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
|
return
|
||||||
gid = family.get_gramps_id()
|
gid = family.get_gramps_id()
|
||||||
self.fid_trans[gid] = family.get_handle()
|
self.fid_trans[gid] = family.get_handle()
|
||||||
GrampsDbBase.commit_family(self,family,transaction,change_time)
|
GrampsDbBase.commit_family(self,family,transaction,change_time)
|
||||||
|
|
||||||
def commit_media_object(self,obj,transaction,change_time=None):
|
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
|
return
|
||||||
gid = obj.get_gramps_id()
|
gid = obj.get_gramps_id()
|
||||||
self.oid_trans[gid] = obj.get_handle()
|
self.oid_trans[gid] = obj.get_handle()
|
||||||
GrampsDbBase.commit_media_object(self,obj,transaction,change_time)
|
GrampsDbBase.commit_media_object(self,obj,transaction,change_time)
|
||||||
|
|
||||||
def commit_source(self,source,transaction,change_time=None):
|
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
|
return
|
||||||
gid = source.get_gramps_id()
|
gid = source.get_gramps_id()
|
||||||
self.sid_trans[gid] = source.get_handle()
|
self.sid_trans[gid] = source.get_handle()
|
||||||
|
@ -4046,6 +4046,8 @@ class GenderStats:
|
|||||||
return (0, 0, 0)
|
return (0, 0, 0)
|
||||||
|
|
||||||
def count_person (self, person, db, undo = 0):
|
def count_person (self, person, db, undo = 0):
|
||||||
|
if not person:
|
||||||
|
return
|
||||||
# Let the Person do their own counting later
|
# Let the Person do their own counting later
|
||||||
person.db = db
|
person.db = db
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user