2004-09-29 08:49:01 +05:30
|
|
|
#
|
2004-08-01 09:51:31 +05:30
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2000-2004 Donald N. Allingham
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
|
|
|
# $Id$
|
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Base class for the GRAMPS databases. All database interfaces should inherit
|
|
|
|
from this class.
|
|
|
|
"""
|
|
|
|
|
2004-08-07 10:46:57 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# libraries
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2004-08-01 09:51:31 +05:30
|
|
|
from RelLib import *
|
|
|
|
import cPickle
|
2004-08-24 09:18:15 +05:30
|
|
|
import time
|
2004-08-27 03:24:14 +05:30
|
|
|
import locale
|
2004-10-04 02:34:54 +05:30
|
|
|
import re
|
2004-08-07 10:46:57 +05:30
|
|
|
from gettext import gettext as _
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2004-09-25 10:42:15 +05:30
|
|
|
import GrampsGconfKeys
|
2004-10-04 02:34:54 +05:30
|
|
|
import Utils
|
2004-09-25 10:42:15 +05:30
|
|
|
|
2004-08-01 09:51:31 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2004-08-07 10:46:57 +05:30
|
|
|
# constants
|
2004-08-01 09:51:31 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2004-08-07 10:46:57 +05:30
|
|
|
_UNDO_SIZE = 1000
|
2004-10-04 02:34:54 +05:30
|
|
|
_id_reg = re.compile("%\d+d")
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2004-08-11 21:52:36 +05:30
|
|
|
PERSON_KEY = 0
|
|
|
|
FAMILY_KEY = 1
|
|
|
|
SOURCE_KEY = 2
|
|
|
|
EVENT_KEY = 3
|
|
|
|
MEDIA_KEY = 4
|
|
|
|
PLACE_KEY = 5
|
|
|
|
|
2004-08-01 09:51:31 +05:30
|
|
|
class GrampsDbBase:
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
GRAMPS database object. This object is a base class for all
|
|
|
|
database interfaces.
|
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
|
|
|
|
def __init__(self):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Creates a new GrampsDbBase instance. A new GrampDbBase class should
|
|
|
|
never be directly created. Only classes derived from this class should
|
|
|
|
be created.
|
|
|
|
"""
|
|
|
|
|
|
|
|
self.smap_index = 0
|
|
|
|
self.emap_index = 0
|
|
|
|
self.pmap_index = 0
|
|
|
|
self.fmap_index = 0
|
|
|
|
self.lmap_index = 0
|
|
|
|
self.omap_index = 0
|
|
|
|
|
2004-09-25 10:42:15 +05:30
|
|
|
self.set_person_id_prefix(GrampsGconfKeys.get_person_id_prefix())
|
|
|
|
self.set_object_id_prefix(GrampsGconfKeys.get_object_id_prefix())
|
|
|
|
self.set_family_id_prefix(GrampsGconfKeys.get_family_id_prefix())
|
|
|
|
self.set_source_id_prefix(GrampsGconfKeys.get_source_id_prefix())
|
|
|
|
self.set_place_id_prefix(GrampsGconfKeys.get_place_id_prefix())
|
|
|
|
self.set_event_id_prefix(GrampsGconfKeys.get_event_id_prefix())
|
2004-08-13 10:04:07 +05:30
|
|
|
|
2004-08-01 09:51:31 +05:30
|
|
|
self.open = 0
|
|
|
|
self.genderStats = GenderStats()
|
|
|
|
|
2004-08-24 09:18:15 +05:30
|
|
|
self.id_trans = None
|
|
|
|
self.fid_trans = None
|
|
|
|
self.pid_trans = None
|
|
|
|
self.sid_trans = None
|
|
|
|
self.oid_trans = None
|
2004-08-01 09:51:31 +05:30
|
|
|
self.env = None
|
|
|
|
self.person_map = None
|
|
|
|
self.family_map = None
|
|
|
|
self.place_map = None
|
|
|
|
self.source_map = None
|
|
|
|
self.media_map = None
|
|
|
|
self.event_map = None
|
|
|
|
self.eventnames = None
|
|
|
|
self.metadata = None
|
2004-10-01 00:02:56 +05:30
|
|
|
self.name_group = None
|
2004-08-13 10:04:07 +05:30
|
|
|
self.undo_callback = None
|
|
|
|
self.redo_callback = None
|
2004-08-01 09:51:31 +05:30
|
|
|
self.modified = 0
|
|
|
|
|
2004-08-11 09:12:38 +05:30
|
|
|
self.undoindex = -1
|
|
|
|
self.translist = [None] * _UNDO_SIZE
|
|
|
|
self.default = None
|
|
|
|
self.owner = Researcher()
|
|
|
|
self.bookmarks = []
|
|
|
|
self.path = ""
|
|
|
|
self.place2title = {}
|
2004-10-01 00:02:56 +05:30
|
|
|
self.name_groups = {}
|
2004-08-01 09:51:31 +05:30
|
|
|
|
|
|
|
def load(self,name,callback):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Opens the specified database. The method needs to be overridden
|
|
|
|
in the derived class.
|
|
|
|
"""
|
2004-09-11 04:10:00 +05:30
|
|
|
assert False, "Needs to be overridden in the derived class"
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2004-08-11 09:12:38 +05:30
|
|
|
def close(self):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Closes the specified database. The method needs to be overridden
|
|
|
|
in the derived class.
|
|
|
|
"""
|
2004-09-11 04:10:00 +05:30
|
|
|
assert False, "Needs to be overridden in the derived class"
|
2004-08-11 09:12:38 +05:30
|
|
|
|
|
|
|
def is_open(self):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Returns 1 if the database has been opened.
|
|
|
|
"""
|
2004-08-11 09:12:38 +05:30
|
|
|
return self.person_map != None
|
|
|
|
|
2004-08-24 09:18:15 +05:30
|
|
|
def commit_person(self,person,transaction,change_time=None):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Commits the specified Person to the database, storing the changes
|
|
|
|
as part of the transaction.
|
|
|
|
"""
|
2004-08-24 09:18:15 +05:30
|
|
|
|
|
|
|
if change_time:
|
|
|
|
person.change = int(change_time)
|
|
|
|
else:
|
|
|
|
person.change = int(time.time())
|
2004-08-20 07:50:06 +05:30
|
|
|
handle = str(person.get_handle())
|
2004-08-11 09:12:38 +05:30
|
|
|
if transaction != None:
|
|
|
|
old_data = self.person_map.get(handle)
|
|
|
|
transaction.add(PERSON_KEY,handle,old_data)
|
2004-09-20 08:42:51 +05:30
|
|
|
|
2004-08-11 09:12:38 +05:30
|
|
|
self.person_map[handle] = person.serialize()
|
|
|
|
|
2004-08-24 09:18:15 +05:30
|
|
|
def commit_media_object(self,obj,transaction,change_time=None):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Commits the specified MediaObject to the database, storing the changes
|
|
|
|
as part of the transaction.
|
|
|
|
"""
|
2004-08-24 09:18:15 +05:30
|
|
|
if change_time:
|
|
|
|
obj.change = int(change_time)
|
|
|
|
else:
|
|
|
|
obj.change = int(time.time())
|
2004-08-11 09:12:38 +05:30
|
|
|
handle = str(obj.get_handle())
|
|
|
|
if transaction != None:
|
|
|
|
old_data = self.media_map.get(handle)
|
|
|
|
transaction.add(MEDIA_KEY,handle,old_data)
|
2004-08-20 07:50:06 +05:30
|
|
|
self.media_map[handle] = obj.serialize()
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2004-08-24 09:18:15 +05:30
|
|
|
def commit_source(self,source,transaction,change_time=None):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Commits the specified Source to the database, storing the changes
|
|
|
|
as part of the transaction.
|
|
|
|
"""
|
2004-08-24 09:18:15 +05:30
|
|
|
if change_time:
|
|
|
|
source.change = int(change_time)
|
|
|
|
else:
|
|
|
|
source.change = int(time.time())
|
2004-08-11 09:12:38 +05:30
|
|
|
handle = str(source.get_handle())
|
|
|
|
if transaction != None:
|
|
|
|
old_data = self.source_map.get(handle)
|
|
|
|
transaction.add(SOURCE_KEY,handle,old_data)
|
2004-08-20 07:50:06 +05:30
|
|
|
self.source_map[handle] = source.serialize()
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2004-08-24 09:18:15 +05:30
|
|
|
def commit_place(self,place,transaction,change_time=None):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Commits the specified Place to the database, storing the changes
|
|
|
|
as part of the transaction.
|
|
|
|
"""
|
2004-08-24 09:18:15 +05:30
|
|
|
if change_time:
|
|
|
|
place.change = int(change_time)
|
|
|
|
else:
|
|
|
|
place.change = int(time.time())
|
2004-08-11 09:12:38 +05:30
|
|
|
handle = str(place.get_handle())
|
|
|
|
if transaction != None:
|
|
|
|
old_data = self.place_map.get(handle)
|
|
|
|
transaction.add(PLACE_KEY,handle,old_data)
|
2004-08-20 07:50:06 +05:30
|
|
|
self.place_map[handle] = place.serialize()
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2004-08-24 09:18:15 +05:30
|
|
|
def commit_event(self,event,transaction,change_time=None):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Commits the specified Event to the database, storing the changes
|
|
|
|
as part of the transaction.
|
|
|
|
"""
|
2004-08-24 09:18:15 +05:30
|
|
|
if change_time:
|
|
|
|
event.change = int(change_time)
|
|
|
|
else:
|
|
|
|
event.change = int(time.time())
|
2004-08-11 09:12:38 +05:30
|
|
|
handle = str(event.get_handle())
|
|
|
|
if transaction != None:
|
|
|
|
old_data = self.event_map.get(handle)
|
|
|
|
transaction.add(EVENT_KEY,handle,old_data)
|
2004-08-20 07:50:06 +05:30
|
|
|
self.event_map[handle] = event.serialize()
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2004-08-24 09:18:15 +05:30
|
|
|
def commit_family(self,family,transaction,change_time=None):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Commits the specified Family to the database, storing the changes
|
|
|
|
as part of the transaction.
|
|
|
|
"""
|
2004-08-24 09:18:15 +05:30
|
|
|
if change_time:
|
|
|
|
family.change = int(change_time)
|
|
|
|
else:
|
|
|
|
family.change = int(time.time())
|
2004-08-11 09:12:38 +05:30
|
|
|
handle = str(family.get_handle())
|
|
|
|
if transaction != None:
|
|
|
|
old_data = self.family_map.get(handle)
|
|
|
|
transaction.add(FAMILY_KEY,handle,old_data)
|
2004-08-20 07:50:06 +05:30
|
|
|
self.family_map[handle] = family.serialize()
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def find_next_person_gramps_id(self):
|
|
|
|
"""
|
|
|
|
Returns the next available GRAMPS' ID for a Person object based
|
|
|
|
off the person ID prefix.
|
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
index = self.iprefix % self.pmap_index
|
|
|
|
while self.id_trans.get(str(index)):
|
|
|
|
self.pmap_index += 1
|
|
|
|
index = self.iprefix % self.pmap_index
|
|
|
|
self.pmap_index += 1
|
|
|
|
return index
|
|
|
|
|
2004-08-11 09:12:38 +05:30
|
|
|
def find_next_place_gramps_id(self):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Returns the next available GRAMPS' ID for a Place object based
|
|
|
|
off the person ID prefix.
|
|
|
|
"""
|
2004-08-11 09:12:38 +05:30
|
|
|
index = self.pprefix % self.lmap_index
|
2004-08-24 09:18:15 +05:30
|
|
|
while self.pid_trans.get(str(index)):
|
2004-08-11 09:12:38 +05:30
|
|
|
self.lmap_index += 1
|
|
|
|
index = self.pprefix % self.lmap_index
|
|
|
|
self.lmap_index += 1
|
|
|
|
return index
|
|
|
|
|
|
|
|
def find_next_event_gramps_id(self):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Returns the next available GRAMPS' ID for a Event object based
|
|
|
|
off the person ID prefix.
|
|
|
|
"""
|
2004-08-11 09:12:38 +05:30
|
|
|
index = self.eprefix % self.emap_index
|
|
|
|
self.emap_index += 1
|
|
|
|
return index
|
|
|
|
|
|
|
|
def find_next_object_gramps_id(self):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Returns the next available GRAMPS' ID for a MediaObject object based
|
|
|
|
off the person ID prefix.
|
|
|
|
"""
|
2004-08-11 09:12:38 +05:30
|
|
|
index = self.oprefix % self.omap_index
|
2004-08-24 09:18:15 +05:30
|
|
|
while self.oid_trans.get(str(index)):
|
2004-08-11 09:12:38 +05:30
|
|
|
self.omap_index += 1
|
|
|
|
index = self.oprefix % self.omap_index
|
|
|
|
self.omap_index += 1
|
|
|
|
return index
|
|
|
|
|
|
|
|
def find_next_source_gramps_id(self):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Returns the next available GRAMPS' ID for a Source object based
|
|
|
|
off the person ID prefix.
|
|
|
|
"""
|
2004-08-11 09:12:38 +05:30
|
|
|
index = self.sprefix % self.smap_index
|
2004-08-24 09:18:15 +05:30
|
|
|
while self.sid_trans.get(str(index)):
|
2004-08-11 09:12:38 +05:30
|
|
|
self.smap_index += 1
|
|
|
|
index = self.sprefix % self.smap_index
|
2004-08-24 09:18:15 +05:30
|
|
|
self.smap_index += 1
|
2004-08-11 09:12:38 +05:30
|
|
|
return index
|
|
|
|
|
|
|
|
def find_next_family_gramps_id(self):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Returns the next available GRAMPS' ID for a Family object based
|
|
|
|
off the person ID prefix.
|
|
|
|
"""
|
2004-08-11 09:12:38 +05:30
|
|
|
index = self.fprefix % self.fmap_index
|
2004-08-24 09:18:15 +05:30
|
|
|
while self.fid_trans.get(str(index)):
|
2004-08-11 09:12:38 +05:30
|
|
|
self.fmap_index += 1
|
|
|
|
index = self.fprefix % self.fmap_index
|
|
|
|
self.fmap_index += 1
|
|
|
|
return index
|
|
|
|
|
|
|
|
def get_person_from_handle(self,val):
|
|
|
|
"""finds a Person in the database from the passed gramps' ID.
|
2004-08-21 23:43:18 +05:30
|
|
|
If no such Person exists, None is returned."""
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2004-08-20 07:50:06 +05:30
|
|
|
data = self.person_map.get(str(val))
|
2004-08-11 09:12:38 +05:30
|
|
|
if data:
|
|
|
|
person = Person()
|
|
|
|
person.unserialize(data)
|
|
|
|
return person
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_source_from_handle(self,val):
|
|
|
|
"""finds a Source in the database from the passed gramps' ID.
|
|
|
|
If no such Source exists, None is returned."""
|
|
|
|
|
2004-08-11 21:42:08 +05:30
|
|
|
data = self.source_map.get(str(val))
|
2004-08-11 09:12:38 +05:30
|
|
|
if data:
|
|
|
|
source = Source()
|
|
|
|
source.unserialize(data)
|
|
|
|
return source
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_object_from_handle(self,handle):
|
|
|
|
"""finds an Object in the database from the passed gramps' ID.
|
|
|
|
If no such Object exists, None is returned."""
|
2004-08-11 21:42:08 +05:30
|
|
|
data = self.media_map.get(str(handle))
|
2004-08-11 09:12:38 +05:30
|
|
|
if data:
|
|
|
|
mobject = MediaObject()
|
|
|
|
mobject.unserialize(data)
|
|
|
|
return mobject
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_place_from_handle(self,handle):
|
|
|
|
"""finds a Place in the database from the passed gramps' ID.
|
|
|
|
If no such Place exists, None is returned."""
|
2004-08-11 21:42:08 +05:30
|
|
|
data = self.place_map.get(str(handle))
|
2004-08-11 09:12:38 +05:30
|
|
|
if data:
|
|
|
|
place = Place()
|
|
|
|
place.unserialize(data)
|
|
|
|
return place
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_event_from_handle(self,handle):
|
2004-08-21 23:43:18 +05:30
|
|
|
"""finds a Event in the database from the passed gramps' ID.
|
|
|
|
If no such Event exists, None is returned."""
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2004-08-11 21:42:08 +05:30
|
|
|
data = self.event_map.get(str(handle))
|
2004-08-11 09:12:38 +05:30
|
|
|
if data:
|
|
|
|
event = Event()
|
|
|
|
event.unserialize(data)
|
|
|
|
return event
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_family_from_handle(self,handle):
|
2004-08-21 23:43:18 +05:30
|
|
|
"""finds a Family in the database from the passed gramps' ID.
|
|
|
|
If no such Family exists, None is returned."""
|
2004-08-11 09:12:38 +05:30
|
|
|
|
|
|
|
data = self.family_map.get(str(handle))
|
|
|
|
if data:
|
|
|
|
family = Family()
|
|
|
|
family.unserialize(data)
|
|
|
|
return family
|
|
|
|
return None
|
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def find_person_from_handle(self,val,transaction):
|
|
|
|
"""
|
|
|
|
Finds a Person in the database from the passed GRAMPS ID.
|
|
|
|
If no such Person exists, a new Person is added to the database.
|
|
|
|
"""
|
2004-08-11 09:12:38 +05:30
|
|
|
person = Person()
|
2004-08-11 21:42:08 +05:30
|
|
|
data = self.person_map.get(str(val))
|
2004-08-11 09:12:38 +05:30
|
|
|
if data:
|
|
|
|
person.unserialize(data)
|
|
|
|
else:
|
|
|
|
person.set_handle(val)
|
2004-08-13 10:04:07 +05:30
|
|
|
if transaction != None:
|
|
|
|
transaction.add(PERSON_KEY, val, None)
|
2004-08-20 07:50:06 +05:30
|
|
|
self.person_map[str(val)] = person.serialize()
|
2004-08-11 09:12:38 +05:30
|
|
|
self.genderStats.count_person (person, self)
|
|
|
|
return person
|
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def find_source_from_handle(self,val,transaction):
|
|
|
|
"""
|
|
|
|
Finds a Source in the database from the passed GRAMPS ID.
|
|
|
|
If no such Source exists, a new Source is added to the database.
|
|
|
|
"""
|
2004-08-11 09:12:38 +05:30
|
|
|
source = Source()
|
|
|
|
if self.source_map.get(str(val)):
|
|
|
|
source.unserialize(self.source_map.get(str(val)))
|
|
|
|
else:
|
|
|
|
source.set_handle(val)
|
2004-08-24 09:18:15 +05:30
|
|
|
self.add_source(source,transaction)
|
2004-08-11 09:12:38 +05:30
|
|
|
return source
|
|
|
|
|
2004-08-22 00:28:19 +05:30
|
|
|
def find_event_from_handle(self,val,transaction):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
2004-08-21 23:43:18 +05:30
|
|
|
Finds a Event in the database from the passed GRAMPS ID.
|
|
|
|
If no such Event exists, a new Event is added to the database.
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
2004-08-21 23:43:18 +05:30
|
|
|
event = Event()
|
2004-08-11 09:12:38 +05:30
|
|
|
data = self.event_map.get(str(val))
|
|
|
|
if data:
|
|
|
|
event.unserialize(data)
|
|
|
|
else:
|
2004-08-21 23:43:18 +05:30
|
|
|
event.set_handle(val)
|
2004-08-24 09:18:15 +05:30
|
|
|
self.add_event(event,transaction)
|
2004-08-21 23:43:18 +05:30
|
|
|
return event
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def find_object_from_handle(self,handle,transaction):
|
|
|
|
"""
|
|
|
|
Finds an MediaObject in the database from the passed GRAMPS ID.
|
|
|
|
If no such MediaObject exists, a new Object is added to the database."""
|
2004-08-11 09:12:38 +05:30
|
|
|
|
|
|
|
obj = MediaObject()
|
|
|
|
if self.media_map.get(str(handle)):
|
|
|
|
obj.unserialize(self.media_map.get(str(handle)))
|
|
|
|
else:
|
|
|
|
obj.set_handle(handle)
|
2004-08-13 10:04:07 +05:30
|
|
|
self.add_object(obj,transaction)
|
2004-08-11 09:12:38 +05:30
|
|
|
return obj
|
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def find_place_from_handle(self,handle,transaction):
|
|
|
|
"""
|
|
|
|
Finds a Place in the database from the passed GRAMPS ID.
|
|
|
|
If no such Place exists, a new Place is added to the database.
|
|
|
|
"""
|
2004-08-11 09:12:38 +05:30
|
|
|
place = Place()
|
2004-08-24 09:18:15 +05:30
|
|
|
if self.place_map.get(str(handle)):
|
|
|
|
place.unserialize(self.place_map.get(str(handle)))
|
2004-08-11 09:12:38 +05:30
|
|
|
else:
|
2004-08-24 09:18:15 +05:30
|
|
|
place.set_handle(handle)
|
|
|
|
self.add_place(place,transaction)
|
2004-08-11 09:12:38 +05:30
|
|
|
return place
|
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def find_family_from_handle(self,val,transaction):
|
2004-08-11 09:12:38 +05:30
|
|
|
"""finds a Family in the database from the passed gramps' ID.
|
|
|
|
If no such Family exists, a new Family is added to the database."""
|
|
|
|
|
|
|
|
family = Family()
|
2004-08-24 09:18:15 +05:30
|
|
|
if self.family_map.get(str(val)):
|
|
|
|
family.unserialize(self.family_map.get(str(val)))
|
2004-08-11 09:12:38 +05:30
|
|
|
else:
|
2004-08-20 07:50:06 +05:30
|
|
|
family.set_handle(val)
|
2004-08-24 09:18:15 +05:30
|
|
|
self.add_family(family,transaction)
|
2004-08-11 09:12:38 +05:30
|
|
|
return family
|
|
|
|
|
2004-08-20 07:50:06 +05:30
|
|
|
def get_person_from_gramps_id(self,val):
|
|
|
|
"""
|
|
|
|
Finds a Person in the database from the passed GRAMPS ID.
|
|
|
|
If no such Person exists, None is returned.
|
|
|
|
|
|
|
|
Needs to be overridden by the derrived class.
|
|
|
|
"""
|
2004-09-11 04:10:00 +05:30
|
|
|
assert False, "Needs to be overridden in the derived class"
|
2004-08-20 07:50:06 +05:30
|
|
|
|
|
|
|
def get_family_from_gramps_id(self,val):
|
|
|
|
"""
|
|
|
|
Finds a Family in the database from the passed GRAMPS ID.
|
|
|
|
If no such Family exists, None is returned.
|
|
|
|
|
|
|
|
Needs to be overridden by the derrived class.
|
|
|
|
"""
|
2004-09-11 04:10:00 +05:30
|
|
|
assert False, "Needs to be overridden in the derived class"
|
2004-08-20 07:50:06 +05:30
|
|
|
|
2004-08-24 10:39:50 +05:30
|
|
|
def get_place_from_gramps_id(self,val):
|
|
|
|
"""finds a Place in the database from the passed gramps' ID.
|
|
|
|
If no such Place exists, a new Person is added to the database.
|
|
|
|
|
|
|
|
Needs to be overridden by the derrived class.
|
|
|
|
"""
|
2004-09-11 04:10:00 +05:30
|
|
|
assert False, "Needs to be overridden in the derived class"
|
2004-08-24 10:39:50 +05:30
|
|
|
|
|
|
|
def get_source_from_gramps_id(self,val):
|
|
|
|
"""finds a Source in the database from the passed gramps' ID.
|
|
|
|
If no such Source exists, a new Person is added to the database.
|
|
|
|
|
|
|
|
Needs to be overridden by the derrived class.
|
|
|
|
"""
|
2004-09-11 04:10:00 +05:30
|
|
|
assert False, "Needs to be overridden in the derived class"
|
2004-08-24 10:39:50 +05:30
|
|
|
|
|
|
|
def get_object_from_gramps_id(self,val):
|
|
|
|
"""finds a MediaObject in the database from the passed gramps' ID.
|
|
|
|
If no such MediaObject exists, a new Person is added to the database.
|
|
|
|
|
|
|
|
Needs to be overridden by the derrived class.
|
|
|
|
"""
|
2004-09-11 04:10:00 +05:30
|
|
|
assert False, "Needs to be overridden in the derived class"
|
2004-08-24 10:39:50 +05:30
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def add_person(self,person,transaction):
|
|
|
|
"""
|
|
|
|
Adds a Person to the database, assigning internal IDs if they have
|
|
|
|
not already been defined.
|
|
|
|
"""
|
2004-09-29 08:49:01 +05:30
|
|
|
if not person.get_gramps_id():
|
2004-08-13 10:04:07 +05:30
|
|
|
person.set_gramps_id(self.find_next_person_gramps_id())
|
2004-09-29 08:49:01 +05:30
|
|
|
if not person.get_handle():
|
2004-08-11 09:12:38 +05:30
|
|
|
person.set_handle(Utils.create_id())
|
2004-08-13 10:04:07 +05:30
|
|
|
self.commit_person(person,transaction)
|
2004-08-11 09:12:38 +05:30
|
|
|
self.genderStats.count_person (person, self)
|
|
|
|
return person.get_handle()
|
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def add_family(self,family,transaction):
|
|
|
|
"""
|
|
|
|
Adds a Family to the database, assigning internal IDs if they have
|
|
|
|
not already been defined.
|
|
|
|
"""
|
|
|
|
if family.get_gramps_id() == None:
|
2004-08-11 09:12:38 +05:30
|
|
|
family.set_gramps_id(self.find_next_family_gramps_id())
|
2004-08-13 10:04:07 +05:30
|
|
|
if family.get_handle() == None:
|
2004-08-11 09:12:38 +05:30
|
|
|
family.set_handle(Utils.create_id())
|
2004-08-13 10:04:07 +05:30
|
|
|
self.commit_family(family,transaction)
|
2004-08-11 09:12:38 +05:30
|
|
|
return family.get_handle()
|
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def add_source(self,source,transaction):
|
|
|
|
"""
|
|
|
|
Adds a Source to the database, assigning internal IDs if they have
|
|
|
|
not already been defined.
|
|
|
|
"""
|
|
|
|
if source.get_handle() == None:
|
2004-08-11 09:12:38 +05:30
|
|
|
source.set_handle(Utils.create_id())
|
2004-08-13 10:04:07 +05:30
|
|
|
if source.get_gramps_id() == None:
|
2004-08-11 09:12:38 +05:30
|
|
|
source.set_gramps_id(self.find_next_source_gramps_id())
|
2004-08-13 10:04:07 +05:30
|
|
|
self.commit_source(source,transaction)
|
2004-08-11 09:12:38 +05:30
|
|
|
return source.get_handle()
|
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def add_event(self,event,transaction):
|
|
|
|
"""
|
|
|
|
Adds an Event to the database, assigning internal IDs if they have
|
|
|
|
not already been defined.
|
|
|
|
"""
|
|
|
|
if event.get_handle() == None:
|
2004-08-11 09:12:38 +05:30
|
|
|
event.set_handle(Utils.create_id())
|
2004-08-13 10:04:07 +05:30
|
|
|
if event.get_gramps_id() == None:
|
2004-08-11 09:12:38 +05:30
|
|
|
event.set_gramps_id(self.find_next_event_gramps_id())
|
2004-08-13 10:04:07 +05:30
|
|
|
self.commit_event(event,transaction)
|
2004-08-11 09:12:38 +05:30
|
|
|
return event.get_handle()
|
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def add_place(self,place,transaction):
|
|
|
|
"""
|
|
|
|
Adds a Place to the database, assigning internal IDs if they have
|
|
|
|
not already been defined.
|
|
|
|
"""
|
|
|
|
if place.get_handle() == None:
|
2004-08-11 09:12:38 +05:30
|
|
|
index = Utils.create_id()
|
|
|
|
place.set_handle(index)
|
2004-08-13 10:04:07 +05:30
|
|
|
if place.get_gramps_id() == None:
|
2004-08-11 09:12:38 +05:30
|
|
|
place.set_gramps_id(self.find_next_place_gramps_id())
|
2004-08-13 10:04:07 +05:30
|
|
|
self.commit_place(place,transaction)
|
2004-08-11 09:12:38 +05:30
|
|
|
return place.get_handle()
|
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def add_object(self,obj,transaction):
|
|
|
|
"""
|
|
|
|
Adds a MediaObject to the database, assigning internal IDs if they have
|
|
|
|
not already been defined.
|
|
|
|
"""
|
2004-08-11 09:12:38 +05:30
|
|
|
index = obj.get_handle()
|
2004-08-13 10:04:07 +05:30
|
|
|
if index == None:
|
2004-08-11 09:12:38 +05:30
|
|
|
index = Utils.create_id()
|
|
|
|
obj.set_handle(index)
|
2004-08-13 10:04:07 +05:30
|
|
|
if obj.get_gramps_id() == None:
|
2004-08-11 09:12:38 +05:30
|
|
|
obj.set_gramps_id(self.find_next_object_gramps_id())
|
2004-08-13 10:04:07 +05:30
|
|
|
self.commit_media_object(obj,transaction)
|
2004-08-11 09:12:38 +05:30
|
|
|
return index
|
|
|
|
|
2004-10-01 00:02:56 +05:30
|
|
|
def get_name_group_mapping(self,name):
|
|
|
|
"""
|
|
|
|
Returns the default grouping name for a surname
|
|
|
|
"""
|
|
|
|
return self.name_group.get(str(name),name)
|
|
|
|
|
|
|
|
def get_name_group_keys(self):
|
|
|
|
"""
|
|
|
|
Returns the defined names that have been assigned to a default grouping
|
|
|
|
"""
|
|
|
|
return [unicode(k) for k in self.name_group.keys()]
|
|
|
|
|
|
|
|
def set_name_group_mapping(self,name,group):
|
|
|
|
"""
|
|
|
|
Sets the default grouping name for a surname. Needs to be overridden in the
|
|
|
|
derived class.
|
|
|
|
"""
|
|
|
|
assert False, "Needs to be overridden in the derived class"
|
|
|
|
|
2004-08-01 09:51:31 +05:30
|
|
|
def get_people_view_maps(self):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Allows the saving people display data into the database metadata.
|
|
|
|
This allows faster display of the treeview.
|
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
if self.metadata:
|
2004-09-29 07:36:46 +05:30
|
|
|
return (self.metadata.get('tp_path'),
|
2004-08-01 09:51:31 +05:30
|
|
|
self.metadata.get('p_iter'),
|
|
|
|
self.metadata.get('p_path'),
|
|
|
|
self.metadata.get('sname'))
|
|
|
|
else:
|
2004-09-29 07:36:46 +05:30
|
|
|
return (None,None,None,None)
|
2004-08-01 09:51:31 +05:30
|
|
|
|
|
|
|
def set_people_view_maps(self,maps):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Allows the retreiving people display data into the database metadata.
|
|
|
|
This allows faster display of the treeview.
|
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
if self.metadata:
|
2004-09-29 07:36:46 +05:30
|
|
|
self.metadata['tp_path'] = maps[0]
|
|
|
|
self.metadata['p_iter'] = maps[1]
|
|
|
|
self.metadata['p_path'] = maps[2]
|
|
|
|
self.metadata['sname'] = maps[3]
|
2004-08-01 09:51:31 +05:30
|
|
|
|
|
|
|
def get_number_of_people(self):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Returns the number of people currently in the databse.
|
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
return len(self.person_map)
|
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def get_person_handles(self,sort_handles=True):
|
|
|
|
"""
|
|
|
|
Returns a list of database handles, one handle for each Person in
|
|
|
|
the database. If sort_handles is True, the list is sorted by surnames
|
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
if self.person_map:
|
2004-08-13 10:04:07 +05:30
|
|
|
handle_list = self.person_map.keys()
|
|
|
|
if sort_handles:
|
|
|
|
handle_list.sort(self._sortbyname)
|
|
|
|
return handle_list
|
2004-08-11 09:12:38 +05:30
|
|
|
return []
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def get_place_handles(self,sort_handles=True):
|
|
|
|
"""
|
|
|
|
Returns a list of database handles, one handle for each Place in
|
|
|
|
the database. If sort_handles is True, the list is sorted by
|
|
|
|
Place title.
|
|
|
|
"""
|
|
|
|
if self.place_map:
|
|
|
|
handle_list = self.place_map.keys()
|
|
|
|
if sort_handles:
|
|
|
|
handle_list.sort(self._sortbyplace)
|
|
|
|
return handle_list
|
2004-08-11 09:12:38 +05:30
|
|
|
return []
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def get_source_handles(self,sort_handles=True):
|
|
|
|
"""
|
|
|
|
Returns a list of database handles, one handle for each Source in
|
|
|
|
the database. If sort_handles is True, the list is sorted by
|
|
|
|
Source title.
|
|
|
|
"""
|
|
|
|
if self.source_map:
|
|
|
|
handle_list = self.source_map.keys()
|
|
|
|
if sort_handles:
|
|
|
|
handle_list.sort(self._sortbysource)
|
|
|
|
return handle_list
|
|
|
|
return []
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def get_media_object_handles(self,sort_handles=True):
|
|
|
|
"""
|
|
|
|
Returns a list of database handles, one handle for each MediaObject in
|
|
|
|
the database. If sort_handles is True, the list is sorted by title.
|
|
|
|
"""
|
|
|
|
if self.media_map:
|
|
|
|
handle_list = self.media_map.keys()
|
|
|
|
if sort_handles:
|
|
|
|
handle_list.sort(self._sortbymedia)
|
|
|
|
return handle_list
|
2004-08-11 09:12:38 +05:30
|
|
|
return []
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def get_event_handles(self):
|
|
|
|
"""
|
|
|
|
Returns a list of database handles, one handle for each Event in
|
|
|
|
the database.
|
|
|
|
"""
|
|
|
|
if self.event_map:
|
|
|
|
return self.event_map.keys()
|
|
|
|
return []
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def get_family_handles(self):
|
|
|
|
"""
|
|
|
|
Returns a list of database handles, one handle for each Family in
|
|
|
|
the database.
|
|
|
|
"""
|
|
|
|
if self.family_map:
|
|
|
|
return self.family_map.keys()
|
|
|
|
return []
|
|
|
|
|
|
|
|
def set_person_id_prefix(self,val):
|
|
|
|
"""
|
|
|
|
Sets the naming template for GRAMPS Person ID values. The string is expected
|
|
|
|
to be in the form of a simple text string, or in a format that contains
|
|
|
|
a C/Python style format string using %d, such as I%d or I%04d.
|
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
if val:
|
|
|
|
if _id_reg.search(val):
|
|
|
|
self.iprefix = val
|
|
|
|
else:
|
|
|
|
self.iprefix = val + "%d"
|
|
|
|
else:
|
|
|
|
self.iprefix = "I%04d"
|
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def set_source_id_prefix(self,val):
|
|
|
|
"""
|
|
|
|
Sets the naming template for GRAMPS Source ID values. The string is expected
|
|
|
|
to be in the form of a simple text string, or in a format that contains
|
|
|
|
a C/Python style format string using %d, such as S%d or S%04d.
|
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
if val:
|
|
|
|
if _id_reg.search(val):
|
|
|
|
self.sprefix = val
|
|
|
|
else:
|
|
|
|
self.sprefix = val + "%d"
|
|
|
|
else:
|
|
|
|
self.sprefix = "S%04d"
|
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def set_object_id_prefix(self,val):
|
|
|
|
"""
|
|
|
|
Sets the naming template for GRAMPS MediaObject ID values. The string is expected
|
|
|
|
to be in the form of a simple text string, or in a format that contains
|
|
|
|
a C/Python style format string using %d, such as O%d or O%04d.
|
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
if val:
|
|
|
|
if _id_reg.search(val):
|
|
|
|
self.oprefix = val
|
|
|
|
else:
|
|
|
|
self.oprefix = val + "%d"
|
|
|
|
else:
|
|
|
|
self.oprefix = "O%04d"
|
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def set_place_id_prefix(self,val):
|
|
|
|
"""
|
|
|
|
Sets the naming template for GRAMPS Place ID values. The string is expected
|
|
|
|
to be in the form of a simple text string, or in a format that contains
|
|
|
|
a C/Python style format string using %d, such as P%d or P%04d.
|
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
if val:
|
|
|
|
if _id_reg.search(val):
|
|
|
|
self.pprefix = val
|
|
|
|
else:
|
|
|
|
self.pprefix = val + "%d"
|
|
|
|
else:
|
|
|
|
self.pprefix = "P%04d"
|
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def set_family_id_prefix(self,val):
|
|
|
|
"""
|
|
|
|
Sets the naming template for GRAMPS Family ID values. The string is expected
|
|
|
|
to be in the form of a simple text string, or in a format that contains
|
|
|
|
a C/Python style format string using %d, such as F%d or F%04d.
|
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
if val:
|
|
|
|
if _id_reg.search(val):
|
|
|
|
self.fprefix = val
|
|
|
|
else:
|
|
|
|
self.fprefix = val + "%d"
|
|
|
|
else:
|
|
|
|
self.fprefix = "F%04d"
|
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def set_event_id_prefix(self,val):
|
|
|
|
"""
|
|
|
|
Sets the naming template for GRAMPS Event ID values. The string is expected
|
|
|
|
to be in the form of a simple text string, or in a format that contains
|
|
|
|
a C/Python style format string using %d, such as E%d or E%04d.
|
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
if val:
|
|
|
|
if _id_reg.search(val):
|
|
|
|
self.eprefix = val
|
|
|
|
else:
|
|
|
|
self.eprefix = val + "%d"
|
|
|
|
else:
|
|
|
|
self.eprefix = "E%04d"
|
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def transaction_begin(self,msg=""):
|
|
|
|
"""
|
|
|
|
Creates a new Transaction tied to the current UNDO database. The transaction
|
|
|
|
has no effect until it is committed using the transaction_commit function of
|
|
|
|
the this database object.
|
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
return Transaction(msg,self.undodb)
|
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def transaction_commit(self,transaction,msg):
|
|
|
|
"""
|
|
|
|
Commits the transaction to the assocated UNDO database.
|
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
if not len(transaction):
|
|
|
|
return
|
|
|
|
transaction.set_description(msg)
|
|
|
|
self.undoindex += 1
|
|
|
|
if self.undoindex == _UNDO_SIZE:
|
|
|
|
self.translist = transaction[0:-1] + [ transaction ]
|
|
|
|
else:
|
|
|
|
self.translist[self.undoindex] = transaction
|
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
if self.undo_callback:
|
|
|
|
self.undo_callback(_("_Undo %s") % transaction.get_description())
|
2004-08-01 09:51:31 +05:30
|
|
|
|
|
|
|
def undo(self):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Accesses the last committed transaction, and reverts the data to
|
|
|
|
the state before the transaction was committed.
|
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
if self.undoindex == -1:
|
|
|
|
return
|
|
|
|
transaction = self.translist[self.undoindex]
|
|
|
|
|
|
|
|
self.undoindex -= 1
|
|
|
|
subitems = transaction.get_recnos()
|
|
|
|
subitems.reverse()
|
|
|
|
for record_id in subitems:
|
|
|
|
(key, handle, data) = transaction.get_record(record_id)
|
|
|
|
if key == PERSON_KEY:
|
|
|
|
if data == None:
|
2004-08-11 09:12:38 +05:30
|
|
|
del self.person_map[str(handle)]
|
2004-08-01 09:51:31 +05:30
|
|
|
else:
|
2004-08-11 09:12:38 +05:30
|
|
|
self.person_map[str(handle)] = data
|
2004-08-01 09:51:31 +05:30
|
|
|
elif key == FAMILY_KEY:
|
|
|
|
if data == None:
|
2004-08-11 09:12:38 +05:30
|
|
|
del self.family_map[str(handle)]
|
2004-08-01 09:51:31 +05:30
|
|
|
else:
|
2004-08-11 09:12:38 +05:30
|
|
|
self.family_map[str(handle)] = data
|
2004-08-01 09:51:31 +05:30
|
|
|
elif key == SOURCE_KEY:
|
|
|
|
if data == None:
|
2004-08-11 09:12:38 +05:30
|
|
|
del self.source_map[str(handle)]
|
2004-08-01 09:51:31 +05:30
|
|
|
else:
|
2004-08-11 09:12:38 +05:30
|
|
|
self.source_map[str(handle)] = data
|
2004-08-01 09:51:31 +05:30
|
|
|
elif key == EVENT_KEY:
|
|
|
|
if data == None:
|
2004-08-11 09:12:38 +05:30
|
|
|
del self.event_map[str(handle)]
|
2004-08-01 09:51:31 +05:30
|
|
|
else:
|
2004-08-11 09:12:38 +05:30
|
|
|
self.event_map[str(handle)] = data
|
2004-08-01 09:51:31 +05:30
|
|
|
elif key == PLACE_KEY:
|
|
|
|
if data == None:
|
2004-08-11 09:12:38 +05:30
|
|
|
del self.place_map[str(handle)]
|
2004-08-01 09:51:31 +05:30
|
|
|
else:
|
2004-08-11 09:12:38 +05:30
|
|
|
self.place_map[str(handle)] = data
|
2004-08-01 09:51:31 +05:30
|
|
|
elif key == MEDIA_KEY:
|
|
|
|
if data == None:
|
2004-08-11 09:12:38 +05:30
|
|
|
del self.media_map[str(handle)]
|
2004-08-01 09:51:31 +05:30
|
|
|
else:
|
2004-08-11 09:12:38 +05:30
|
|
|
self.media_map[str(handle)] = data
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
if self.undo_callback:
|
2004-08-01 09:51:31 +05:30
|
|
|
if self.undoindex == -1:
|
2004-08-13 10:04:07 +05:30
|
|
|
self.undo_callback(None)
|
2004-08-01 09:51:31 +05:30
|
|
|
else:
|
|
|
|
transaction = self.translist[self.undoindex]
|
2004-08-13 10:04:07 +05:30
|
|
|
self.undo_callback(_("_Undo %s") % transaction.get_description())
|
|
|
|
|
|
|
|
def set_undo_callback(self,callback):
|
|
|
|
"""
|
|
|
|
Defines the callback function that is called whenever an undo operation
|
|
|
|
is executed. The callback function recieves a single argument that is a
|
|
|
|
text string that defines the operation.
|
|
|
|
"""
|
|
|
|
self.undo_callback = callback
|
|
|
|
|
|
|
|
def set_redo_callback(self,callback):
|
|
|
|
"""
|
|
|
|
Defines the callback function that is called whenever an redo operation
|
|
|
|
is executed. The callback function recieves a single argument that is a
|
|
|
|
text string that defines the operation.
|
|
|
|
"""
|
|
|
|
self.redo_callback = callback
|
|
|
|
|
|
|
|
def get_surname_list(self):
|
|
|
|
"""
|
|
|
|
Returns the list of surnames contained within the database.
|
|
|
|
The function must be overridden in the derived class.
|
|
|
|
"""
|
2004-09-11 04:10:00 +05:30
|
|
|
assert False, "Needs to be overridden in the derived class"
|
2004-08-13 10:04:07 +05:30
|
|
|
|
|
|
|
def get_person_event_type_list(self):
|
|
|
|
"""
|
|
|
|
Returns the list of personal event types contained within the
|
|
|
|
database. The function must be overridden in the derived class.
|
|
|
|
"""
|
2004-09-11 04:10:00 +05:30
|
|
|
assert False, "Needs to be overridden in the derived class"
|
2004-08-01 09:51:31 +05:30
|
|
|
|
|
|
|
def get_bookmarks(self):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""returns the list of Person handles in the bookmarks"""
|
2004-08-01 09:51:31 +05:30
|
|
|
return self.bookmarks
|
|
|
|
|
|
|
|
def set_researcher(self,owner):
|
|
|
|
"""sets the information about the owner of the database"""
|
|
|
|
self.owner.set(owner.get_name(),owner.get_address(),owner.get_city(),
|
|
|
|
owner.get_state(),owner.get_country(),
|
|
|
|
owner.get_postal_code(),owner.get_phone(),owner.get_email())
|
|
|
|
|
|
|
|
def get_researcher(self):
|
|
|
|
"""returns the Researcher instance, providing information about
|
|
|
|
the owner of the database"""
|
|
|
|
return self.owner
|
|
|
|
|
|
|
|
def set_default_person_handle(self,handle):
|
|
|
|
"""sets the default Person to the passed instance"""
|
|
|
|
self.metadata['default'] = handle
|
|
|
|
|
|
|
|
def get_default_person(self):
|
|
|
|
"""returns the default Person of the database"""
|
|
|
|
if self.metadata and self.metadata.has_key('default'):
|
|
|
|
person = Person()
|
|
|
|
handle = self.metadata['default']
|
2004-08-11 09:12:38 +05:30
|
|
|
data = self.person_map.get(str(handle))
|
2004-08-01 09:51:31 +05:30
|
|
|
person.unserialize(data)
|
|
|
|
return person
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_save_path(self):
|
|
|
|
"""returns the save path of the file, or "" if one does not exist"""
|
|
|
|
return self.path
|
|
|
|
|
|
|
|
def set_save_path(self,path):
|
|
|
|
"""sets the save path for the database"""
|
|
|
|
self.path = path
|
|
|
|
|
|
|
|
def get_person_event_types(self):
|
|
|
|
"""returns a list of all Event types assocated with Person
|
|
|
|
instances in the database"""
|
|
|
|
return []
|
|
|
|
|
|
|
|
def get_person_attribute_types(self):
|
|
|
|
"""returns a list of all Attribute types assocated with Person
|
|
|
|
instances in the database"""
|
|
|
|
return []
|
|
|
|
|
|
|
|
def get_family_attribute_types(self):
|
|
|
|
"""returns a list of all Attribute types assocated with Family
|
|
|
|
instances in the database"""
|
|
|
|
return []
|
|
|
|
|
|
|
|
def get_family_event_types(self):
|
|
|
|
"""returns a list of all Event types assocated with Family
|
|
|
|
instances in the database"""
|
|
|
|
return []
|
|
|
|
|
|
|
|
def get_media_attribute_types(self):
|
|
|
|
"""returns a list of all Attribute types assocated with Media
|
|
|
|
instances in the database"""
|
|
|
|
return []
|
|
|
|
|
|
|
|
def get_family_relation_types(self):
|
|
|
|
"""returns a list of all relationship types assocated with Family
|
|
|
|
instances in the database"""
|
|
|
|
return []
|
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def remove_person(self,handle,transaction):
|
|
|
|
"""
|
|
|
|
Removes the Person specified by the database handle from the
|
|
|
|
database, preserving the change in the passed transaction. This
|
|
|
|
method must be overridden in the derived class.
|
|
|
|
"""
|
2004-09-11 04:10:00 +05:30
|
|
|
assert False, "Needs to be overridden in the derived class"
|
2004-08-13 10:04:07 +05:30
|
|
|
|
|
|
|
def remove_source(self,handle,transaction):
|
|
|
|
"""
|
|
|
|
Removes the Source specified by the database handle from the
|
|
|
|
database, preserving the change in the passed transaction. This
|
|
|
|
method must be overridden in the derived class.
|
|
|
|
"""
|
2004-09-11 04:10:00 +05:30
|
|
|
assert False, "Needs to be overridden in the derived class"
|
2004-08-13 10:04:07 +05:30
|
|
|
|
|
|
|
def remove_event(self,handle,transaction):
|
|
|
|
"""
|
|
|
|
Removes the Event specified by the database handle from the
|
|
|
|
database, preserving the change in the passed transaction. This
|
|
|
|
method must be overridden in the derived class.
|
|
|
|
"""
|
2004-09-11 04:10:00 +05:30
|
|
|
assert False, "Needs to be overridden in the derived class"
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def remove_object(self,handle,transaction):
|
|
|
|
"""
|
|
|
|
Removes the MediaObjectPerson specified by the database handle from the
|
|
|
|
database, preserving the change in the passed transaction. This
|
|
|
|
method must be overridden in the derived class.
|
|
|
|
"""
|
2004-09-11 04:10:00 +05:30
|
|
|
assert False, "Needs to be overridden in the derived class"
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def remove_place(self,handle,transaction):
|
|
|
|
"""
|
|
|
|
Removes the Place specified by the database handle from the
|
|
|
|
database, preserving the change in the passed transaction. This
|
|
|
|
method must be overridden in the derived class.
|
|
|
|
"""
|
2004-09-11 04:10:00 +05:30
|
|
|
assert False, "Needs to be overridden in the derived class"
|
2004-08-13 10:04:07 +05:30
|
|
|
|
|
|
|
def has_person_handle(self,handle):
|
|
|
|
"""
|
|
|
|
returns True if the handle exists in the current Person database.
|
|
|
|
"""
|
|
|
|
return self.person_map.has_key(str(handle))
|
|
|
|
|
|
|
|
def has_family_handle(self,handle):
|
|
|
|
"""
|
|
|
|
returns True if the handle exists in the current Family database.
|
|
|
|
"""
|
|
|
|
return self.family_map.has_key(str(handle))
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def has_object_handle(self,handle):
|
|
|
|
"""
|
|
|
|
returns True if the handle exists in the current MediaObjectdatabase.
|
|
|
|
"""
|
|
|
|
return self.media_map.has_key(str(handle)) != None
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def _sortbyname(self,f,s):
|
2004-09-29 07:36:46 +05:30
|
|
|
n1 = self.person_map.get(str(f))[3].sname
|
|
|
|
n2 = self.person_map.get(str(s))[3].sname
|
2004-08-27 03:24:14 +05:30
|
|
|
return locale.strcoll(n1,n2)
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def _sortbyplace(self,f,s):
|
2004-08-27 03:24:14 +05:30
|
|
|
return locale.strcoll(self.place_map.get(str(f))[2].upper(),
|
|
|
|
self.place_map.get(str(s))[2].upper())
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def _sortbysource(self,f,s):
|
2004-08-20 07:50:06 +05:30
|
|
|
fp = self.source_map[str(f)][2].upper()
|
|
|
|
sp = self.source_map[str(s)][2].upper()
|
2004-08-27 03:24:14 +05:30
|
|
|
return locale.strcoll(fp,sp)
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def _sortbymedia(self,f,s):
|
2004-08-20 07:50:06 +05:30
|
|
|
fp = self.media_map[str(f)][4].upper()
|
|
|
|
sp = self.media_map[str(s)][4].upper()
|
2004-08-27 03:24:14 +05:30
|
|
|
return locale.strcoll(fp,sp)
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def set_person_column_order(self,list):
|
|
|
|
"""
|
|
|
|
Stores the Person display common information in the
|
|
|
|
database's metadata.
|
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
if self.metadata != None:
|
|
|
|
self.metadata['columns'] = list
|
|
|
|
|
|
|
|
def set_place_column_order(self,list):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Stores the Place display common information in the
|
|
|
|
database's metadata.
|
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
if self.metadata != None:
|
|
|
|
self.metadata['place_columns'] = list
|
|
|
|
|
|
|
|
def set_source_column_order(self,list):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Stores the Source display common information in the
|
|
|
|
database's metadata.
|
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
if self.metadata != None:
|
|
|
|
self.metadata['source_columns'] = list
|
|
|
|
|
|
|
|
def set_media_column_order(self,list):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Stores the Media display common information in the
|
|
|
|
database's metadata.
|
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
if self.metadata != None:
|
|
|
|
self.metadata['media_columns'] = list
|
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def get_person_column_order(self):
|
|
|
|
"""
|
|
|
|
Returns the Person display common information stored in the
|
|
|
|
database's metadata.
|
|
|
|
"""
|
2004-08-24 09:18:15 +05:30
|
|
|
default = [(1,1),(1,2),(1,3),(0,4),(1,5),(0,6),(0,7),(0,8)]
|
2004-08-01 09:51:31 +05:30
|
|
|
if self.metadata == None:
|
|
|
|
return default
|
|
|
|
else:
|
|
|
|
cols = self.metadata.get('columns',default)
|
|
|
|
if len(cols) != len(default):
|
|
|
|
return cols + default[len(cols):]
|
|
|
|
else:
|
|
|
|
return cols
|
|
|
|
|
|
|
|
def get_place_column_order(self):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Returns the Place display common information stored in the
|
|
|
|
database's metadata.
|
|
|
|
"""
|
2004-08-24 09:18:15 +05:30
|
|
|
default = [(1,1),(1,2),(0,3),(1,4),(0,5),(1,6),(0,7),(0,8),(0,9)]
|
2004-08-01 09:51:31 +05:30
|
|
|
if self.metadata == None:
|
|
|
|
return default
|
|
|
|
else:
|
|
|
|
cols = self.metadata.get('place_columns',default)
|
|
|
|
if len(cols) != len(default):
|
|
|
|
return cols + default[len(cols):]
|
|
|
|
else:
|
|
|
|
return cols
|
|
|
|
|
|
|
|
def get_source_column_order(self):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Returns the Source display common information stored in the
|
|
|
|
database's metadata.
|
|
|
|
"""
|
2004-08-24 09:18:15 +05:30
|
|
|
default = [(1,1),(1,2),(1,3),(0,4),(0,5)]
|
2004-08-01 09:51:31 +05:30
|
|
|
if self.metadata == None:
|
|
|
|
return default
|
|
|
|
else:
|
|
|
|
cols = self.metadata.get('source_columns',default)
|
|
|
|
if len(cols) != len(default):
|
|
|
|
return cols + default[len(cols):]
|
|
|
|
else:
|
|
|
|
return cols
|
|
|
|
|
|
|
|
def get_media_column_order(self):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Returns the MediaObject display common information stored in the
|
|
|
|
database's metadata.
|
|
|
|
"""
|
2004-08-24 09:18:15 +05:30
|
|
|
default = [(1,1),(1,2),(1,3),(0,4)]
|
2004-08-01 09:51:31 +05:30
|
|
|
if self.metadata == None:
|
|
|
|
return default
|
|
|
|
else:
|
2004-08-24 09:18:15 +05:30
|
|
|
cols = self.metadata.get('media_columns',default)
|
2004-08-01 09:51:31 +05:30
|
|
|
if len(cols) != len(default):
|
|
|
|
return cols + default[len(cols):]
|
|
|
|
else:
|
|
|
|
return cols
|
2004-08-13 10:04:07 +05:30
|
|
|
|
2004-08-01 09:51:31 +05:30
|
|
|
class Transaction:
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Defines a group of database commits that define a single logical
|
|
|
|
operation.
|
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
def __init__(self,msg,db):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Creates a new transaction. A Transaction instance should not be created
|
|
|
|
directly, but by the GrampsDbBase class or classes derived from
|
|
|
|
GrampsDbBase. The db parameter is a list-like interface that stores
|
|
|
|
the commit data. This could be a simple list, or a RECNO-style database
|
|
|
|
object.
|
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
self.db = db
|
|
|
|
self.first = None
|
|
|
|
self.last = None
|
|
|
|
|
|
|
|
def get_description(self):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Returns the text string that describes the logical operation
|
|
|
|
performed by the Transaction.
|
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
return self.msg
|
|
|
|
|
|
|
|
def set_description(self,msg):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Sets the text string that describes the logical operation
|
|
|
|
performed by the Transaction.
|
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
self.msg = msg
|
|
|
|
|
|
|
|
def add(self, type, handle, data):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Adds a commit operation to the Transaction. The type is a constant
|
|
|
|
that indicates what type of PrimaryObject is being added. The handle
|
|
|
|
is the object's database handle, and the data is the tuple returned
|
|
|
|
by the object's serialize method.
|
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
self.last = self.db.append(cPickle.dumps((type,handle,data),1))
|
|
|
|
if self.first == None:
|
|
|
|
self.first = self.last
|
|
|
|
|
|
|
|
def get_recnos(self):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Returns a list of record numbers associated with the transaction.
|
|
|
|
While the list is an arbitrary index of integers, it can be used
|
|
|
|
to indicate record numbers for a database.
|
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
return range (self.first, self.last+1)
|
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
def get_record(self,recno):
|
|
|
|
"""
|
|
|
|
Returns a tuple representing the PrimaryObject type, database handle
|
|
|
|
for the PrimaryObject, and a tuple representing the data created by
|
|
|
|
the object's serialize method.
|
|
|
|
"""
|
|
|
|
return cPickle.loads(self.db[recno])
|
2004-08-01 09:51:31 +05:30
|
|
|
|
|
|
|
def __len__(self):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Returns the number of commits associated with the Transaction.
|
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
if self.last and self.first:
|
|
|
|
return self.last - self.first + 1
|
|
|
|
return 0
|
|
|
|
|