2004-09-19 09:41:34 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2005-01-09 03:12:40 +05:30
|
|
|
# Copyright (C) 2000-2005 Donald N. Allingham
|
2004-09-19 09:41:34 +05:30
|
|
|
#
|
|
|
|
# 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-12-06 09:43:13 +05:30
|
|
|
"""
|
|
|
|
Provides the common infrastructure for database formats that
|
|
|
|
must hold all of their data in memory.
|
|
|
|
"""
|
|
|
|
|
2005-04-23 21:23:30 +05:30
|
|
|
from bsddb import dbshelve, db
|
|
|
|
|
2005-03-14 03:40:40 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2004-09-19 09:41:34 +05:30
|
|
|
from RelLib import *
|
|
|
|
from GrampsDbBase import *
|
|
|
|
|
2004-12-06 09:43:13 +05:30
|
|
|
class GrampsInMemCursor(GrampsCursor):
|
|
|
|
"""
|
|
|
|
Cursor class for in-memory database classes. Since the in-memory
|
|
|
|
classes use python dictionaries, the python iter class is used
|
|
|
|
to provide the cursor function.
|
|
|
|
"""
|
2004-12-05 09:45:48 +05:30
|
|
|
def __init__(self,src_map):
|
|
|
|
self.src_map = src_map
|
|
|
|
self.current = iter(src_map)
|
|
|
|
|
|
|
|
def first(self):
|
|
|
|
self.current = iter(self.src_map)
|
|
|
|
return self.next()
|
|
|
|
|
|
|
|
def next(self):
|
|
|
|
try:
|
|
|
|
index = self.current.next()
|
|
|
|
return (index,self.src_map[index])
|
|
|
|
except StopIteration:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def close(self):
|
|
|
|
pass
|
|
|
|
|
2004-09-19 09:41:34 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GrampsInMemDB
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class GrampsInMemDB(GrampsDbBase):
|
|
|
|
"""GRAMPS database object. This object is a base class for other
|
|
|
|
objects."""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
"""creates a new GrampsDB"""
|
|
|
|
GrampsDbBase.__init__(self)
|
2005-05-27 23:13:04 +05:30
|
|
|
self.person_map = {}
|
|
|
|
self.name_group = {}
|
|
|
|
self.family_map = {}
|
|
|
|
self.place_map = {}
|
|
|
|
self.source_map = {}
|
|
|
|
self.repository_map = {}
|
|
|
|
self.media_map = {}
|
|
|
|
self.event_map = {}
|
|
|
|
self.metadata = {}
|
|
|
|
self.filename = ""
|
|
|
|
self.id_trans = {}
|
|
|
|
self.pid_trans = {}
|
|
|
|
self.fid_trans = {}
|
2005-06-08 10:10:33 +05:30
|
|
|
self.eid_trans = {}
|
2005-05-27 23:13:04 +05:30
|
|
|
self.sid_trans = {}
|
|
|
|
self.rid_trans = {}
|
|
|
|
self.oid_trans = {}
|
|
|
|
self.eventnames = {}
|
|
|
|
self.repository_types = {}
|
|
|
|
self.undodb = []
|
2004-09-19 09:41:34 +05:30
|
|
|
|
2005-04-23 21:23:30 +05:30
|
|
|
def load(self,name,callback,mode="w"):
|
|
|
|
self.undolog = "%s.log" % name
|
|
|
|
self.undodb = db.DB()
|
|
|
|
self.undodb.open(self.undolog, db.DB_RECNO, db.DB_CREATE)
|
|
|
|
self.filename = name
|
|
|
|
self.readonly = mode == "r"
|
2004-09-19 09:41:34 +05:30
|
|
|
|
2004-12-05 09:45:48 +05:30
|
|
|
def get_person_cursor(self):
|
2004-12-06 09:43:13 +05:30
|
|
|
return GrampsInMemCursor(self.person_map)
|
2004-12-05 09:45:48 +05:30
|
|
|
|
2004-12-10 06:58:43 +05:30
|
|
|
def get_family_cursor(self):
|
|
|
|
return GrampsInMemCursor(self.family_map)
|
|
|
|
|
2005-06-07 10:38:50 +05:30
|
|
|
def get_event_cursor(self):
|
|
|
|
return GrampsInMemCursor(self.event_map)
|
|
|
|
|
2004-12-10 06:58:43 +05:30
|
|
|
def get_place_cursor(self):
|
|
|
|
return GrampsInMemCursor(self.place_map)
|
|
|
|
|
|
|
|
def get_source_cursor(self):
|
|
|
|
return GrampsInMemCursor(self.source_map)
|
|
|
|
|
2005-05-27 23:13:04 +05:30
|
|
|
def get_repository_cursor(self):
|
|
|
|
return GrampsInMemCursor(self.repository_map)
|
|
|
|
|
2004-12-10 06:58:43 +05:30
|
|
|
def get_media_cursor(self):
|
|
|
|
return GrampsInMemCursor(self.media_map)
|
|
|
|
|
2004-09-19 09:41:34 +05:30
|
|
|
def close(self):
|
2005-04-23 21:23:30 +05:30
|
|
|
if not self.readonly:
|
|
|
|
self.undodb.close()
|
|
|
|
try:
|
|
|
|
os.remove(self.undolog)
|
|
|
|
except:
|
|
|
|
pass
|
2004-09-19 09:41:34 +05:30
|
|
|
|
2004-10-13 09:21:27 +05:30
|
|
|
def abort_changes(self):
|
|
|
|
pass
|
|
|
|
|
2004-10-01 00:02:56 +05:30
|
|
|
def set_name_group_mapping(self,name,group):
|
|
|
|
if group == None and self.name_group.has_key(name):
|
|
|
|
del self.name_group[name]
|
|
|
|
else:
|
|
|
|
self.name_group[name] = group
|
|
|
|
|
2004-09-19 09:41:34 +05:30
|
|
|
def get_surname_list(self):
|
|
|
|
a = {}
|
2004-12-05 09:45:48 +05:30
|
|
|
for person_id in iter(self.person_map):
|
2004-09-19 09:41:34 +05:30
|
|
|
p = self.get_person_from_handle(person_id)
|
2004-09-29 08:49:01 +05:30
|
|
|
a[p.get_primary_name().get_group_as()] = 1
|
2004-09-19 09:41:34 +05:30
|
|
|
vals = a.keys()
|
|
|
|
vals.sort()
|
|
|
|
return vals
|
|
|
|
|
|
|
|
def get_person_event_type_list(self):
|
|
|
|
names = self.eventnames.keys()
|
|
|
|
a = {}
|
|
|
|
for name in names:
|
|
|
|
a[unicode(name)] = 1
|
|
|
|
vals = a.keys()
|
|
|
|
vals.sort()
|
|
|
|
return vals
|
|
|
|
|
2005-05-27 23:13:04 +05:30
|
|
|
def get_repository_type_list(self):
|
|
|
|
repos_types = self.repository_types.keys()
|
|
|
|
a = {}
|
|
|
|
for repos_type in repos_types:
|
|
|
|
a[unicode(repos_type)] = 1
|
|
|
|
vals = a.keys()
|
|
|
|
vals.sort()
|
|
|
|
return vals
|
|
|
|
|
2005-04-18 04:04:56 +05:30
|
|
|
def _del_person(self,handle):
|
2005-02-16 19:19:32 +05:30
|
|
|
del self.id_trans[person.get_gramps_id()]
|
2004-09-19 09:41:34 +05:30
|
|
|
del self.person_map[handle]
|
|
|
|
|
2005-04-18 04:04:56 +05:30
|
|
|
def _del_source(self,handle):
|
2005-02-16 19:19:32 +05:30
|
|
|
del self.sid_trans[source.get_gramps_id()]
|
2004-09-19 09:41:34 +05:30
|
|
|
del self.source_map[str(handle)]
|
|
|
|
|
2005-05-27 23:13:04 +05:30
|
|
|
def _del_repository(self,handle):
|
|
|
|
del self.rid_trans[repository.get_gramps_id()]
|
|
|
|
del self.repository_map[str(handle)]
|
|
|
|
|
2005-04-18 04:04:56 +05:30
|
|
|
def _del_place(self,handle):
|
2005-02-16 19:19:32 +05:30
|
|
|
del self.pid_trans[place.get_gramps_id()]
|
|
|
|
del self.place_map[str(handle)]
|
|
|
|
|
2005-04-18 04:04:56 +05:30
|
|
|
def _del_media(self,handle):
|
2005-02-16 19:19:32 +05:30
|
|
|
del self.oid_trans[obj.get_gramps_id()]
|
|
|
|
del self.media_map[str(handle)]
|
|
|
|
|
2005-04-18 04:04:56 +05:30
|
|
|
def _del_family(self,handle):
|
2005-02-16 19:19:32 +05:30
|
|
|
del self.fid_trans[family.get_gramps_id()]
|
2004-09-19 09:41:34 +05:30
|
|
|
del self.family_map[str(handle)]
|
|
|
|
|
2005-04-18 04:04:56 +05:30
|
|
|
def _del_event(self,handle):
|
2005-06-08 10:10:33 +05:30
|
|
|
del self.eid_trans[event.get_gramps_id()]
|
2004-09-19 09:41:34 +05:30
|
|
|
del self.event_map[str(handle)]
|
|
|
|
|
|
|
|
def commit_person(self,person,transaction,change_time=None):
|
2005-05-25 09:28:27 +05:30
|
|
|
if self.readonly or not person.get_handle():
|
2005-02-17 04:19:54 +05:30
|
|
|
return
|
2004-10-08 09:29:55 +05:30
|
|
|
gid = person.get_gramps_id()
|
|
|
|
self.id_trans[gid] = person.get_handle()
|
2004-09-19 09:41:34 +05:30
|
|
|
GrampsDbBase.commit_person(self,person,transaction,change_time)
|
|
|
|
|
|
|
|
def commit_place(self,place,transaction,change_time=None):
|
2005-05-25 09:28:27 +05:30
|
|
|
if self.readonly or not place.get_handle():
|
2005-02-17 04:19:54 +05:30
|
|
|
return
|
2004-10-08 09:29:55 +05:30
|
|
|
gid = place.get_gramps_id()
|
|
|
|
self.pid_trans[gid] = place.get_handle()
|
2004-09-19 09:41:34 +05:30
|
|
|
GrampsDbBase.commit_place(self,place,transaction,change_time)
|
|
|
|
|
|
|
|
def commit_family(self,family,transaction,change_time=None):
|
2005-05-25 09:28:27 +05:30
|
|
|
if self.readonly or not family.get_handle():
|
2005-02-17 04:19:54 +05:30
|
|
|
return
|
2004-10-08 09:29:55 +05:30
|
|
|
gid = family.get_gramps_id()
|
|
|
|
self.fid_trans[gid] = family.get_handle()
|
2004-09-19 09:41:34 +05:30
|
|
|
GrampsDbBase.commit_family(self,family,transaction,change_time)
|
|
|
|
|
2005-06-08 10:10:33 +05:30
|
|
|
def commit_event(self,event,transaction,change_time=None):
|
|
|
|
if self.readonly or not event.get_handle():
|
|
|
|
return
|
|
|
|
gid = event.get_gramps_id()
|
|
|
|
self.eid_trans[gid] = event.get_handle()
|
|
|
|
GrampsDbBase.commit_event(self,event,transaction,change_time)
|
|
|
|
|
2004-09-19 09:41:34 +05:30
|
|
|
def commit_media_object(self,obj,transaction,change_time=None):
|
2005-05-25 09:28:27 +05:30
|
|
|
if self.readonly or not obj.get_handle():
|
2005-02-17 04:19:54 +05:30
|
|
|
return
|
2004-10-08 09:29:55 +05:30
|
|
|
gid = obj.get_gramps_id()
|
|
|
|
self.oid_trans[gid] = obj.get_handle()
|
2004-09-19 09:41:34 +05:30
|
|
|
GrampsDbBase.commit_media_object(self,obj,transaction,change_time)
|
|
|
|
|
|
|
|
def commit_source(self,source,transaction,change_time=None):
|
2005-05-25 09:28:27 +05:30
|
|
|
if self.readonly or not source.get_handle():
|
2005-02-17 04:19:54 +05:30
|
|
|
return
|
2004-10-08 09:29:55 +05:30
|
|
|
gid = source.get_gramps_id()
|
|
|
|
self.sid_trans[gid] = source.get_handle()
|
2004-09-19 09:41:34 +05:30
|
|
|
GrampsDbBase.commit_source(self,source,transaction,change_time)
|
|
|
|
|
2005-05-27 23:13:04 +05:30
|
|
|
def commit_repository(self,repository,transaction,change_time=None):
|
|
|
|
if self.readonly or not repository.get_handle():
|
|
|
|
return
|
|
|
|
gid = repository.get_gramps_id()
|
|
|
|
self.rid_trans[gid] = repository.get_handle()
|
|
|
|
GrampsDbBase.commit_repository(self,repository,transaction,change_time)
|
|
|
|
|
2004-09-19 09:41:34 +05:30
|
|
|
def get_person_from_gramps_id(self,val):
|
|
|
|
handle = self.id_trans.get(str(val))
|
2004-10-11 02:46:44 +05:30
|
|
|
if handle:
|
2005-01-09 03:12:40 +05:30
|
|
|
data = self.person_map[handle]
|
|
|
|
if data:
|
|
|
|
person = Person()
|
|
|
|
person.unserialize(data)
|
|
|
|
return person
|
|
|
|
return None
|
2004-09-19 09:41:34 +05:30
|
|
|
|
|
|
|
def get_family_from_gramps_id(self,val):
|
|
|
|
handle = self.fid_trans.get(str(val))
|
2004-10-16 10:40:35 +05:30
|
|
|
if handle:
|
2005-01-09 03:12:40 +05:30
|
|
|
data = self.family_map[handle]
|
|
|
|
if data:
|
|
|
|
family = Family()
|
|
|
|
family.unserialize(data)
|
|
|
|
return family
|
|
|
|
return None
|
2004-09-19 09:41:34 +05:30
|
|
|
|
2005-06-08 10:10:33 +05:30
|
|
|
def get_event_from_gramps_id(self,val):
|
|
|
|
handle = self.eid_trans.get(str(val))
|
|
|
|
if handle:
|
|
|
|
data = self.event_map[handle]
|
|
|
|
if data:
|
|
|
|
event = Event()
|
|
|
|
event.unserialize(data)
|
|
|
|
return event
|
|
|
|
return None
|
|
|
|
|
2004-09-19 09:41:34 +05:30
|
|
|
def get_place_from_gramps_id(self,val):
|
|
|
|
handle = self.pid_trans.get(str(val))
|
2004-10-16 10:40:35 +05:30
|
|
|
if handle:
|
2005-01-09 03:12:40 +05:30
|
|
|
data = self.place_map[handle]
|
|
|
|
if data:
|
|
|
|
place = Place()
|
|
|
|
place.unserialize(data)
|
|
|
|
return place
|
|
|
|
return None
|
2004-09-19 09:41:34 +05:30
|
|
|
|
|
|
|
def get_source_from_gramps_id(self,val):
|
|
|
|
handle = self.sid_trans.get(str(val))
|
2004-10-16 10:40:35 +05:30
|
|
|
if handle:
|
2005-01-09 03:12:40 +05:30
|
|
|
data = self.source_map[handle]
|
|
|
|
if data:
|
|
|
|
source = Source()
|
|
|
|
source.unserialize(data)
|
|
|
|
return source
|
|
|
|
return None
|
2004-09-19 09:41:34 +05:30
|
|
|
|
2005-05-27 23:13:04 +05:30
|
|
|
def get_repository_from_gramps_id(self,val):
|
|
|
|
handle = self.rid_trans.get(str(val))
|
|
|
|
if handle:
|
|
|
|
data = self.repository_map[handle]
|
|
|
|
if data:
|
|
|
|
repository = Repository()
|
|
|
|
repository.unserialize(data)
|
|
|
|
return repository
|
|
|
|
return None
|
|
|
|
|
2004-09-19 09:41:34 +05:30
|
|
|
def get_object_from_gramps_id(self,val):
|
|
|
|
handle = self.oid_trans.get(str(val))
|
2004-10-16 10:40:35 +05:30
|
|
|
if handle:
|
2005-01-09 03:12:40 +05:30
|
|
|
data = self.media_map[handle]
|
|
|
|
if data:
|
|
|
|
obj = MediaObject()
|
|
|
|
obj.unserialize(data)
|
|
|
|
return obj
|
|
|
|
return None
|