2004-09-29 08:49:01 +05:30
|
|
|
#
|
2004-08-01 09:51:31 +05:30
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2007-02-20 06:09:10 +05:30
|
|
|
# Copyright (C) 2000-2007 Donald N. Allingham
|
2004-08-01 09:51:31 +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.
|
|
|
|
#
|
2006-04-08 02:36:20 +05:30
|
|
|
# This program is distributed in the hope that it will be useful,
|
2004-08-01 09:51:31 +05:30
|
|
|
# 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
|
|
|
import cPickle
|
2004-08-24 09:18:15 +05:30
|
|
|
import time
|
2005-01-09 07:48:49 +05:30
|
|
|
import random
|
2004-08-27 03:24:14 +05:30
|
|
|
import locale
|
2006-04-08 02:36:20 +05:30
|
|
|
import os
|
2005-04-19 20:17:02 +05:30
|
|
|
from sys import maxint
|
2006-05-07 10:52:44 +05:30
|
|
|
from bsddb import db
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2006-04-08 02:36:20 +05:30
|
|
|
|
2006-01-07 02:25:49 +05:30
|
|
|
import logging
|
2007-06-04 08:19:31 +05:30
|
|
|
LOG = logging.getLogger(".GrampsDb")
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2005-01-09 07:48:49 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS libraries
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-10-08 22:11:39 +05:30
|
|
|
from gen.lib import *
|
2007-10-11 18:28:16 +05:30
|
|
|
from gen.utils.callback import GrampsDBCallback
|
2007-10-07 08:49:35 +05:30
|
|
|
from iterator import CursorIterator
|
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
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-10-07 08:49:35 +05:30
|
|
|
from dbconst import *
|
|
|
|
from cursor import GrampsCursor
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2007-02-03 22:41:05 +05:30
|
|
|
_UNDO_SIZE = 1000
|
2005-04-18 04:04:56 +05:30
|
|
|
|
2005-12-18 03:32:48 +05:30
|
|
|
|
|
|
|
# The following two dictionaries provide fast translation
|
|
|
|
# between the primary class names and the keys used to reference
|
|
|
|
# these classes in the database tables. Beware that changing
|
|
|
|
# these maps or modifying the values of the keys will break
|
|
|
|
# existing databases.
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
CLASS_TO_KEY_MAP = {Person.__name__: PERSON_KEY,
|
|
|
|
Family.__name__: FAMILY_KEY,
|
|
|
|
Source.__name__: SOURCE_KEY,
|
|
|
|
Event.__name__: EVENT_KEY,
|
|
|
|
MediaObject.__name__: MEDIA_KEY,
|
|
|
|
Place.__name__: PLACE_KEY,
|
2007-02-20 06:09:10 +05:30
|
|
|
Repository.__name__:REPOSITORY_KEY,
|
|
|
|
Note.__name__: NOTE_KEY}
|
2005-12-18 03:32:48 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
KEY_TO_CLASS_MAP = {PERSON_KEY: Person.__name__,
|
|
|
|
FAMILY_KEY: Family.__name__,
|
|
|
|
SOURCE_KEY: Source.__name__,
|
|
|
|
EVENT_KEY: Event.__name__,
|
|
|
|
MEDIA_KEY: MediaObject.__name__,
|
|
|
|
PLACE_KEY: Place.__name__,
|
2007-02-20 06:09:10 +05:30
|
|
|
REPOSITORY_KEY: Repository.__name__,
|
|
|
|
NOTE_KEY: Note.__name__}
|
2005-12-18 03:32:48 +05:30
|
|
|
|
2007-06-14 11:09:03 +05:30
|
|
|
_SIGBASE = ('person', 'family', 'source', 'event',
|
2008-01-01 03:27:54 +05:30
|
|
|
'media', 'place', 'repository', 'reference', 'note')
|
2005-04-18 04:04:56 +05:30
|
|
|
|
2006-12-21 08:58:44 +05:30
|
|
|
class GrampsDbBookmarks:
|
2007-09-29 09:13:40 +05:30
|
|
|
def __init__(self, default=[]):
|
|
|
|
self.bookmarks = list(default) # want a copy (not an alias)
|
2006-12-21 08:58:44 +05:30
|
|
|
|
|
|
|
def set(self, new_list):
|
2007-10-04 03:06:57 +05:30
|
|
|
self.bookmarks = list(new_list)
|
2006-12-21 08:58:44 +05:30
|
|
|
|
|
|
|
def get(self):
|
|
|
|
return self.bookmarks
|
|
|
|
|
|
|
|
def append(self, item):
|
|
|
|
self.bookmarks.append(item)
|
|
|
|
|
2007-01-20 10:36:49 +05:30
|
|
|
def append_list(self, blist):
|
|
|
|
self.bookmarks += blist
|
|
|
|
|
2006-12-21 08:58:44 +05:30
|
|
|
def remove(self, item):
|
|
|
|
self.bookmarks.remove(item)
|
|
|
|
|
|
|
|
def pop(self, item):
|
|
|
|
self.bookmarks.pop(item)
|
|
|
|
|
2007-05-10 08:13:56 +05:30
|
|
|
def insert(self, pos, item):
|
|
|
|
self.bookmarks.insert(pos, item)
|
2006-12-21 08:58:44 +05:30
|
|
|
|
2005-12-21 16:57:05 +05:30
|
|
|
class GrampsDbBase(GrampsDBCallback):
|
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
|
|
|
|
2007-02-03 22:41:05 +05:30
|
|
|
# This holds a reference to the gramps Config module if
|
|
|
|
# it is available, it is setup by the factory methods.
|
|
|
|
__config__ = None
|
|
|
|
|
2005-04-02 01:34:12 +05:30
|
|
|
__signals__ = {
|
2007-06-04 08:19:31 +05:30
|
|
|
'person-add' : (list, ),
|
|
|
|
'person-update' : (list, ),
|
|
|
|
'person-delete' : (list, ),
|
|
|
|
'person-rebuild' : None,
|
|
|
|
'family-add' : (list, ),
|
|
|
|
'family-update' : (list, ),
|
|
|
|
'family-delete' : (list, ),
|
|
|
|
'family-rebuild' : None,
|
|
|
|
'source-add' : (list, ),
|
|
|
|
'source-update' : (list, ),
|
|
|
|
'source-delete' : (list, ),
|
|
|
|
'source-rebuild' : None,
|
|
|
|
'place-add' : (list, ),
|
|
|
|
'place-update' : (list, ),
|
|
|
|
'place-delete' : (list, ),
|
|
|
|
'place-rebuild' : None,
|
|
|
|
'media-add' : (list, ),
|
|
|
|
'media-update' : (list, ),
|
|
|
|
'media-delete' : (list, ),
|
|
|
|
'media-rebuild' : None,
|
|
|
|
'event-add' : (list, ),
|
|
|
|
'event-update' : (list, ),
|
|
|
|
'event-delete' : (list, ),
|
|
|
|
'event-rebuild' : None,
|
|
|
|
'repository-add' : (list, ),
|
|
|
|
'repository-update' : (list, ),
|
|
|
|
'repository-delete' : (list, ),
|
|
|
|
'repository-rebuild' : None,
|
|
|
|
'note-add' : (list, ),
|
|
|
|
'note-update' : (list, ),
|
|
|
|
'note-delete' : (list, ),
|
|
|
|
'note-rebuild' : None,
|
|
|
|
'long-op-start' : (object, ),
|
|
|
|
'long-op-heartbeat' : None,
|
|
|
|
'long-op-end' : None
|
2005-04-02 01:34:12 +05:30
|
|
|
}
|
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
# If this is True logging will be turned on.
|
|
|
|
try:
|
2007-06-14 11:09:03 +05:30
|
|
|
_LOG_ALL = int(os.environ.get('GRAMPS_SIGNAL', "0")) == 1
|
2005-12-06 12:08:09 +05:30
|
|
|
except:
|
2007-06-14 11:09:03 +05:30
|
|
|
_LOG_ALL = False
|
2005-12-06 12:08:09 +05:30
|
|
|
|
|
|
|
|
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.
|
|
|
|
"""
|
|
|
|
|
2005-12-21 16:57:05 +05:30
|
|
|
GrampsDBCallback.__init__(self)
|
2007-02-03 22:41:05 +05:30
|
|
|
|
2007-02-04 06:48:17 +05:30
|
|
|
self.set_person_id_prefix('I%04d')
|
|
|
|
self.set_object_id_prefix('O%04d')
|
|
|
|
self.set_family_id_prefix('F%04d')
|
|
|
|
self.set_source_id_prefix('S%04d')
|
|
|
|
self.set_place_id_prefix('P%04d')
|
|
|
|
self.set_event_id_prefix('E%04d')
|
|
|
|
self.set_repository_id_prefix('R%04d')
|
2007-02-20 06:09:10 +05:30
|
|
|
self.set_note_id_prefix('N%04d')
|
2007-02-03 22:41:05 +05:30
|
|
|
|
2005-02-17 04:19:54 +05:30
|
|
|
self.readonly = False
|
2005-01-09 07:48:49 +05:30
|
|
|
self.rand = random.Random(time.time())
|
2004-08-13 10:04:07 +05:30
|
|
|
self.smap_index = 0
|
|
|
|
self.emap_index = 0
|
|
|
|
self.pmap_index = 0
|
|
|
|
self.fmap_index = 0
|
|
|
|
self.lmap_index = 0
|
|
|
|
self.omap_index = 0
|
2005-05-27 23:13:04 +05:30
|
|
|
self.rmap_index = 0
|
2007-02-20 06:09:10 +05:30
|
|
|
self.nmap_index = 0
|
2006-01-11 03:58:09 +05:30
|
|
|
self.db_is_open = False
|
2004-08-13 10:04:07 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
self.family_event_names = set()
|
|
|
|
self.individual_event_names = set()
|
|
|
|
self.individual_attributes = set()
|
|
|
|
self.family_attributes = set()
|
|
|
|
self.marker_names = set()
|
2006-05-19 05:35:44 +05:30
|
|
|
self.child_ref_types = set()
|
|
|
|
self.family_rel_types = set()
|
|
|
|
self.event_role_names = set()
|
|
|
|
self.name_types = set()
|
|
|
|
self.repository_types = set()
|
2007-02-20 06:09:10 +05:30
|
|
|
self.note_types = set()
|
2006-05-19 05:35:44 +05:30
|
|
|
self.source_media_types = set()
|
|
|
|
self.url_types = set()
|
2006-05-20 01:18:36 +05:30
|
|
|
self.media_attributes = set()
|
2006-05-19 05:35:44 +05:30
|
|
|
|
2004-08-01 09:51:31 +05:30
|
|
|
self.open = 0
|
|
|
|
self.genderStats = GenderStats()
|
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
self.undodb = []
|
|
|
|
self.id_trans = {}
|
|
|
|
self.fid_trans = {}
|
|
|
|
self.pid_trans = {}
|
|
|
|
self.sid_trans = {}
|
|
|
|
self.oid_trans = {}
|
|
|
|
self.rid_trans = {}
|
|
|
|
self.nid_trans = {}
|
|
|
|
self.eid_trans = {}
|
2004-08-01 09:51:31 +05:30
|
|
|
self.env = None
|
2007-06-04 08:19:31 +05:30
|
|
|
self.person_map = {}
|
|
|
|
self.family_map = {}
|
|
|
|
self.place_map = {}
|
|
|
|
self.source_map = {}
|
|
|
|
self.repository_map = {}
|
|
|
|
self.note_map = {}
|
|
|
|
self.media_map = {}
|
|
|
|
self.event_map = {}
|
|
|
|
self.metadata = {}
|
|
|
|
self.name_group = {}
|
2004-08-13 10:04:07 +05:30
|
|
|
self.undo_callback = None
|
|
|
|
self.redo_callback = None
|
2006-05-06 03:25:01 +05:30
|
|
|
self.undo_history_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
|
2006-05-04 04:51:49 +05:30
|
|
|
self.abort_possible = True
|
2006-05-07 10:52:44 +05:30
|
|
|
self.undo_history_timestamp = 0
|
2004-08-11 09:12:38 +05:30
|
|
|
self.default = None
|
|
|
|
self.owner = Researcher()
|
2006-07-06 23:16:46 +05:30
|
|
|
self.name_formats = []
|
2006-12-21 08:58:44 +05:30
|
|
|
self.bookmarks = GrampsDbBookmarks()
|
|
|
|
self.family_bookmarks = GrampsDbBookmarks()
|
|
|
|
self.event_bookmarks = GrampsDbBookmarks()
|
|
|
|
self.place_bookmarks = GrampsDbBookmarks()
|
|
|
|
self.source_bookmarks = GrampsDbBookmarks()
|
|
|
|
self.repo_bookmarks = GrampsDbBookmarks()
|
|
|
|
self.media_bookmarks = GrampsDbBookmarks()
|
2007-03-27 23:58:26 +05:30
|
|
|
self.note_bookmarks = GrampsDbBookmarks()
|
2007-10-10 01:32:02 +05:30
|
|
|
self._bm_changes = 0
|
2004-08-11 09:12:38 +05:30
|
|
|
self.path = ""
|
2007-01-19 22:23:49 +05:30
|
|
|
self.surname_list = []
|
2005-03-31 10:00:44 +05:30
|
|
|
|
2007-02-20 06:09:10 +05:30
|
|
|
def set_prefixes(self, person, media, family, source, place, event,
|
|
|
|
repository, note):
|
2007-02-04 06:48:17 +05:30
|
|
|
self.iprefix = person
|
|
|
|
self.oprefix = media
|
|
|
|
self.fprefix = family
|
|
|
|
self.sprefix = source
|
|
|
|
self.pprefix = place
|
|
|
|
self.eprefix = event
|
|
|
|
self.rprefix = repository
|
2007-02-20 06:09:10 +05:30
|
|
|
self.nprefix = note
|
2007-02-04 06:48:17 +05:30
|
|
|
|
2006-12-01 21:56:34 +05:30
|
|
|
def rebuild_secondary(self, callback):
|
2005-08-18 11:28:28 +05:30
|
|
|
pass
|
|
|
|
|
2005-06-05 09:31:56 +05:30
|
|
|
def version_supported(self):
|
|
|
|
""" Returns True when the file has a supported version"""
|
|
|
|
return True
|
|
|
|
|
2005-03-03 11:03:22 +05:30
|
|
|
def need_upgrade(self):
|
|
|
|
return False
|
|
|
|
|
2005-12-15 11:49:37 +05:30
|
|
|
def gramps_upgrade(self):
|
2005-03-03 11:03:22 +05:30
|
|
|
pass
|
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def del_person(self, handle):
|
2006-01-07 02:25:49 +05:30
|
|
|
pass
|
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def del_source(self, handle):
|
2006-01-07 02:25:49 +05:30
|
|
|
pass
|
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def del_repository(self, handle):
|
2006-01-07 02:25:49 +05:30
|
|
|
pass
|
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def del_note(self, handle):
|
2007-02-20 06:09:10 +05:30
|
|
|
pass
|
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def del_place(self, handle):
|
2006-01-07 02:25:49 +05:30
|
|
|
pass
|
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def del_media(self, handle):
|
2006-01-07 02:25:49 +05:30
|
|
|
pass
|
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def del_family(self, handle):
|
2006-01-07 02:25:49 +05:30
|
|
|
pass
|
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def del_event(self, handle):
|
2006-01-07 02:25:49 +05:30
|
|
|
pass
|
|
|
|
|
2005-01-09 07:48:49 +05:30
|
|
|
def create_id(self):
|
2006-04-08 02:36:20 +05:30
|
|
|
return "%08x%08x" % ( int(time.time()*10000),
|
|
|
|
self.rand.randint(0, maxint))
|
2005-01-09 07:48:49 +05:30
|
|
|
|
2004-12-05 09:45:48 +05:30
|
|
|
def get_person_cursor(self):
|
2007-05-07 09:09:46 +05:30
|
|
|
raise NotImplementedError
|
2004-12-05 09:45:48 +05:30
|
|
|
|
2007-02-18 01:29:21 +05:30
|
|
|
def get_person_cursor_iter(self, msg=_("Processing Person records")):
|
2007-03-27 23:58:26 +05:30
|
|
|
return CursorIterator(self, self.get_person_cursor(), msg)
|
2007-02-05 02:50:46 +05:30
|
|
|
|
2004-12-10 06:58:43 +05:30
|
|
|
def get_family_cursor(self):
|
2007-05-07 09:09:46 +05:30
|
|
|
raise NotImplementedError
|
2004-12-10 06:58:43 +05:30
|
|
|
|
2007-02-18 01:29:21 +05:30
|
|
|
def get_family_cursor_iter(self, msg=_("Processing Family records")):
|
2007-03-27 23:58:26 +05:30
|
|
|
return CursorIterator(self, self.get_family_cursor(), msg)
|
2007-02-05 02:50:46 +05:30
|
|
|
|
2005-06-07 10:38:50 +05:30
|
|
|
def get_event_cursor(self):
|
2007-05-07 09:09:46 +05:30
|
|
|
raise NotImplementedError
|
2005-06-07 10:38:50 +05:30
|
|
|
|
2007-02-18 01:29:21 +05:30
|
|
|
def get_event_cursor_iter(self, msg=_("Processing Event records")):
|
2007-03-27 23:58:26 +05:30
|
|
|
return CursorIterator(self, self.get_event_cursor(), msg)
|
2007-02-05 02:50:46 +05:30
|
|
|
|
2004-12-10 06:58:43 +05:30
|
|
|
def get_place_cursor(self):
|
2007-05-07 09:09:46 +05:30
|
|
|
raise NotImplementedError
|
2004-12-10 06:58:43 +05:30
|
|
|
|
2007-02-18 01:29:21 +05:30
|
|
|
def get_place_cursor_iter(self, msg=_("Processing Place records")):
|
2007-03-27 23:58:26 +05:30
|
|
|
return CursorIterator(self, self.get_place_cursor(), msg)
|
2007-02-05 02:50:46 +05:30
|
|
|
|
2004-12-10 06:58:43 +05:30
|
|
|
def get_source_cursor(self):
|
2007-05-07 09:09:46 +05:30
|
|
|
raise NotImplementedError
|
2004-12-10 06:58:43 +05:30
|
|
|
|
2007-02-18 01:29:21 +05:30
|
|
|
def get_source_cursor_iter(self, msg=_("Processing Source records")):
|
2007-03-27 23:58:26 +05:30
|
|
|
return CursorIterator(self, self.get_source_cursor(), msg)
|
2007-02-05 02:50:46 +05:30
|
|
|
|
2004-12-10 06:58:43 +05:30
|
|
|
def get_media_cursor(self):
|
2007-05-07 09:09:46 +05:30
|
|
|
raise NotImplementedError
|
2004-12-10 06:58:43 +05:30
|
|
|
|
2007-02-18 01:29:21 +05:30
|
|
|
def get_media_cursor_iter(self, msg=_("Processing Media records")):
|
2007-03-27 23:58:26 +05:30
|
|
|
return CursorIterator(self, self.get_media_cursor(), msg)
|
2007-02-05 02:50:46 +05:30
|
|
|
|
2005-05-27 23:13:04 +05:30
|
|
|
def get_repository_cursor(self):
|
2007-05-07 09:09:46 +05:30
|
|
|
raise NotImplementedError
|
2005-05-27 23:13:04 +05:30
|
|
|
|
2007-02-18 01:29:21 +05:30
|
|
|
def get_repository_cursor_iter(self, msg=_("Processing Repository records")):
|
2007-03-27 23:58:26 +05:30
|
|
|
return CursorIterator(self, self.get_repository_cursor(), msg)
|
2007-02-05 02:50:46 +05:30
|
|
|
|
2007-02-20 06:09:10 +05:30
|
|
|
def get_note_cursor(self):
|
2007-05-07 09:09:46 +05:30
|
|
|
raise NotImplementedError
|
2007-02-20 06:09:10 +05:30
|
|
|
|
|
|
|
def get_note_cursor_iter(self, msg=_("Processing Note records")):
|
2007-03-27 23:58:26 +05:30
|
|
|
return CursorIterator(self, self.get_note_cursor(), msg)
|
2007-02-20 06:09:10 +05:30
|
|
|
|
2006-05-07 10:52:44 +05:30
|
|
|
def open_undodb(self):
|
|
|
|
if not self.readonly:
|
|
|
|
self.undolog = "%s.undo" % self.full_name
|
|
|
|
self.undodb = db.DB()
|
|
|
|
self.undodb.open(self.undolog, db.DB_RECNO, db.DB_CREATE)
|
|
|
|
|
|
|
|
def close_undodb(self):
|
|
|
|
if not self.readonly:
|
|
|
|
self.undodb.close()
|
|
|
|
try:
|
|
|
|
os.remove(self.undolog)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def load(self, name, callback, mode="w"):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Opens the specified database. The method needs to be overridden
|
|
|
|
in the derived class.
|
|
|
|
"""
|
2007-05-07 09:09:46 +05:30
|
|
|
raise NotImplementedError
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2006-05-10 11:22:55 +05:30
|
|
|
def load_from(self, other_database, filename, callback):
|
|
|
|
"""
|
|
|
|
Loads data from the other database into itself.
|
|
|
|
The filename is the name of the file for the newly created database.
|
|
|
|
The method needs to be overridden in the derived class.
|
|
|
|
"""
|
2007-05-07 09:09:46 +05:30
|
|
|
raise NotImplementedError
|
2006-05-10 11:22:55 +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.
|
|
|
|
"""
|
2005-12-22 11:43:11 +05:30
|
|
|
pass
|
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.
|
|
|
|
"""
|
2006-01-11 03:58:09 +05:30
|
|
|
return self.db_is_open
|
2005-04-04 22:11:01 +05:30
|
|
|
|
|
|
|
def request_rebuild(self):
|
|
|
|
"""
|
2007-09-29 Benny Malengier <benny.malengier@gramps-project.org>
* src/GrampsDb/_GrampsDbBase.py: documentation string error
* src/Editors/_EditPerson.py: reload image if rectangle changes
* src/glade/gramps.glade: rename in Media editor referencer,
use region and corner as terms, add tooltip
* src/Editors/_EditMediaRef.py: rename to upper/lower to corner1/2,
provide upgrade path, default to (0,0,100,100) not (0,0,0,0)
svn: r9031
2007-09-29 05:56:26 +05:30
|
|
|
Notifies clients that the data has changed significantly, and that all
|
2005-04-04 22:11:01 +05:30
|
|
|
internal data dependent on the database should be rebuilt.
|
|
|
|
"""
|
|
|
|
self.emit('person-rebuild')
|
|
|
|
self.emit('family-rebuild')
|
|
|
|
self.emit('place-rebuild')
|
|
|
|
self.emit('source-rebuild')
|
|
|
|
self.emit('media-rebuild')
|
2005-04-18 04:04:56 +05:30
|
|
|
self.emit('event-rebuild')
|
2005-05-27 23:13:04 +05:30
|
|
|
self.emit('repository-rebuild')
|
2007-02-20 06:09:10 +05:30
|
|
|
self.emit('note-rebuild')
|
2005-12-15 23:02:10 +05:30
|
|
|
|
2007-06-25 21:40:10 +05:30
|
|
|
def commit_base(self, obj, data_map, key, update_list, add_list,
|
2005-04-18 04:04:56 +05:30
|
|
|
transaction, change_time):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Commits the specified Person to the database, storing the changes
|
|
|
|
as part of the transaction.
|
|
|
|
"""
|
2005-05-24 18:38:06 +05:30
|
|
|
if self.readonly or not obj or not obj.handle:
|
2005-02-17 04:19:54 +05:30
|
|
|
return
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2004-08-24 09:18:15 +05:30
|
|
|
if change_time:
|
2005-04-18 04:04:56 +05:30
|
|
|
obj.change = int(change_time)
|
2004-08-24 09:18:15 +05:30
|
|
|
else:
|
2005-04-18 04:04:56 +05:30
|
|
|
obj.change = int(time.time())
|
|
|
|
handle = str(obj.handle)
|
2005-12-15 23:02:10 +05:30
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
self.update_reference_map(obj, transaction)
|
2006-10-09 09:27:41 +05:30
|
|
|
|
2007-10-09 02:49:32 +05:30
|
|
|
if transaction.batch:
|
|
|
|
data_map[handle] = obj.serialize()
|
|
|
|
old_data = None
|
|
|
|
else:
|
|
|
|
old_data = data_map.get(handle)
|
|
|
|
new_data = obj.serialize()
|
|
|
|
transaction.add(key, handle, old_data, new_data)
|
|
|
|
if old_data:
|
|
|
|
update_list.append((handle, new_data))
|
2005-04-18 04:04:56 +05:30
|
|
|
else:
|
2007-10-09 02:49:32 +05:30
|
|
|
add_list.append((handle, new_data))
|
2005-08-11 05:23:24 +05:30
|
|
|
return old_data
|
2005-07-09 01:54:54 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def commit_person(self, person, transaction, change_time=None):
|
2005-04-18 04:04:56 +05:30
|
|
|
"""
|
|
|
|
Commits the specified Person to the database, storing the changes
|
|
|
|
as part of the transaction.
|
|
|
|
"""
|
2005-12-15 23:02:10 +05:30
|
|
|
|
2007-06-25 21:40:10 +05:30
|
|
|
old_data = self.commit_base(
|
2006-04-08 02:36:20 +05:30
|
|
|
person, self.person_map, PERSON_KEY, transaction.person_update,
|
2005-08-11 05:23:24 +05:30
|
|
|
transaction.person_add, transaction, change_time)
|
|
|
|
if old_data:
|
|
|
|
old_person = Person(old_data)
|
|
|
|
if (old_data[2] != person.gender or
|
2007-01-19 22:39:38 +05:30
|
|
|
old_data[3][4]!= person.primary_name.first_name):
|
2005-08-11 05:23:24 +05:30
|
|
|
self.genderStats.uncount_person(old_person)
|
2006-04-23 09:59:14 +05:30
|
|
|
self.genderStats.count_person(person)
|
2007-01-19 22:39:38 +05:30
|
|
|
if (old_data[3][5]!=person.primary_name.surname):
|
2007-01-19 22:23:49 +05:30
|
|
|
self.remove_from_surname_list(old_person)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.add_to_surname_list(person, transaction.batch)
|
2005-08-11 05:23:24 +05:30
|
|
|
else:
|
2006-04-23 09:59:14 +05:30
|
|
|
self.genderStats.count_person(person)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.add_to_surname_list(person, transaction.batch)
|
2005-08-18 11:28:28 +05:30
|
|
|
|
2006-05-19 06:09:22 +05:30
|
|
|
self.individual_attributes.update(
|
|
|
|
[str(attr.type) for attr in person.attribute_list
|
2006-06-16 09:02:51 +05:30
|
|
|
if attr.type.is_custom() and str(attr.type)])
|
2006-05-19 06:09:22 +05:30
|
|
|
|
|
|
|
if person.marker.is_custom():
|
|
|
|
self.marker_names.add(str(person.marker))
|
|
|
|
|
2006-05-24 01:25:35 +05:30
|
|
|
self.event_role_names.update([str(eref.role)
|
|
|
|
for eref in person.event_ref_list
|
|
|
|
if eref.role.is_custom()])
|
2006-05-19 06:09:22 +05:30
|
|
|
|
|
|
|
self.name_types.update([str(name.type)
|
|
|
|
for name in ([person.primary_name]
|
|
|
|
+ person.alternate_names)
|
|
|
|
if name.type.is_custom()])
|
|
|
|
|
|
|
|
self.url_types.update([str(url.type) for url in person.urls
|
|
|
|
if url.type.is_custom()])
|
2006-04-01 05:16:34 +05:30
|
|
|
|
2006-05-20 01:18:36 +05:30
|
|
|
attr_list = []
|
|
|
|
for mref in person.media_list:
|
|
|
|
attr_list += [str(attr.type) for attr in mref.attribute_list
|
2006-06-16 09:02:51 +05:30
|
|
|
if attr.type.is_custom() and str(attr.type)]
|
2006-05-20 01:18:36 +05:30
|
|
|
self.media_attributes.update(attr_list)
|
|
|
|
|
2006-04-08 02:36:20 +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.
|
|
|
|
"""
|
2005-12-15 23:02:10 +05:30
|
|
|
|
2007-06-25 21:40:10 +05:30
|
|
|
self.commit_base(obj, self.media_map, MEDIA_KEY,
|
2006-04-08 02:36:20 +05:30
|
|
|
transaction.media_update, transaction.media_add,
|
2005-04-18 04:04:56 +05:30
|
|
|
transaction, change_time)
|
2006-05-20 01:18:36 +05:30
|
|
|
self.media_attributes.update(
|
|
|
|
[str(attr.type) for attr in obj.attribute_list
|
2006-06-16 09:02:51 +05:30
|
|
|
if attr.type.is_custom() and str(attr.type)])
|
2005-04-05 05:22:46 +05:30
|
|
|
|
2006-04-08 02:36:20 +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.
|
|
|
|
"""
|
2005-12-15 23:02:10 +05:30
|
|
|
|
2007-06-25 21:40:10 +05:30
|
|
|
self.commit_base(source, self.source_map, SOURCE_KEY,
|
2006-04-08 02:36:20 +05:30
|
|
|
transaction.source_update, transaction.source_add,
|
2005-04-18 04:04:56 +05:30
|
|
|
transaction, change_time)
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2006-05-19 06:09:22 +05:30
|
|
|
self.source_media_types.update(
|
|
|
|
[str(ref.media_type) for ref in source.reporef_list
|
2006-05-20 01:18:36 +05:30
|
|
|
if ref.media_type.is_custom()])
|
|
|
|
|
|
|
|
attr_list = []
|
|
|
|
for mref in source.media_list:
|
|
|
|
attr_list += [str(attr.type) for attr in mref.attribute_list
|
2006-06-16 09:02:51 +05:30
|
|
|
if attr.type.is_custom() and str(attr.type)]
|
2006-05-20 01:18:36 +05:30
|
|
|
self.media_attributes.update(attr_list)
|
2006-05-19 06:09:22 +05:30
|
|
|
|
2006-04-08 02:36:20 +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.
|
|
|
|
"""
|
2005-12-15 23:02:10 +05:30
|
|
|
|
2007-06-25 21:40:10 +05:30
|
|
|
self.commit_base(place, self.place_map, PLACE_KEY,
|
2006-04-08 02:36:20 +05:30
|
|
|
transaction.place_update, transaction.place_add,
|
2005-04-18 04:04:56 +05:30
|
|
|
transaction, change_time)
|
|
|
|
|
2006-05-19 06:09:22 +05:30
|
|
|
self.url_types.update([str(url.type) for url in place.urls
|
|
|
|
if url.type.is_custom()])
|
|
|
|
|
2006-05-20 01:18:36 +05:30
|
|
|
attr_list = []
|
|
|
|
for mref in place.media_list:
|
|
|
|
attr_list += [str(attr.type) for attr in mref.attribute_list
|
2006-06-16 09:02:51 +05:30
|
|
|
if attr.type.is_custom() and str(attr.type)]
|
2006-05-20 01:18:36 +05:30
|
|
|
self.media_attributes.update(attr_list)
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def commit_personal_event(self, event, transaction, change_time=None):
|
2006-04-20 04:29:33 +05:30
|
|
|
if event.type.is_custom():
|
|
|
|
self.individual_event_names.add(str(event.type))
|
2006-04-08 02:36:20 +05:30
|
|
|
self.commit_event(event, transaction, change_time)
|
2005-08-18 11:28:28 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def commit_family_event(self, event, transaction, change_time=None):
|
2006-04-20 04:29:33 +05:30
|
|
|
if event.type.is_custom():
|
|
|
|
self.family_event_names.add(str(event.type))
|
2006-04-08 02:36:20 +05:30
|
|
|
self.commit_event(event, transaction, change_time)
|
2005-08-18 11:28:28 +05:30
|
|
|
|
2006-04-08 02:36:20 +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.
|
|
|
|
"""
|
2007-06-25 21:40:10 +05:30
|
|
|
self.commit_base(event, self.event_map, EVENT_KEY,
|
2006-04-08 02:36:20 +05:30
|
|
|
transaction.event_update, transaction.event_add,
|
2005-04-18 04:04:56 +05:30
|
|
|
transaction, change_time)
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2006-05-20 01:18:36 +05:30
|
|
|
attr_list = []
|
|
|
|
for mref in event.media_list:
|
|
|
|
attr_list += [str(attr.type) for attr in mref.attribute_list
|
2006-06-16 09:02:51 +05:30
|
|
|
if attr.type.is_custom() and str(attr.type)]
|
2006-05-20 01:18:36 +05:30
|
|
|
self.media_attributes.update(attr_list)
|
|
|
|
|
2006-04-08 02:36:20 +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.
|
|
|
|
"""
|
2005-12-15 23:02:10 +05:30
|
|
|
|
2007-06-25 21:40:10 +05:30
|
|
|
self.commit_base(family, self.family_map, FAMILY_KEY,
|
2006-04-08 02:36:20 +05:30
|
|
|
transaction.family_update, transaction.family_add,
|
2005-04-18 04:04:56 +05:30
|
|
|
transaction, change_time)
|
2005-04-01 11:03:22 +05:30
|
|
|
|
2006-05-19 06:09:22 +05:30
|
|
|
self.family_attributes.update(
|
|
|
|
[str(attr.type) for attr in family.attribute_list
|
2006-06-16 09:02:51 +05:30
|
|
|
if attr.type.is_custom() and str(attr.type)])
|
2006-05-19 06:09:22 +05:30
|
|
|
|
2006-05-19 23:02:23 +05:30
|
|
|
rel_list = []
|
|
|
|
for ref in family.child_ref_list:
|
|
|
|
if ref.frel.is_custom():
|
|
|
|
rel_list.append(str(ref.frel))
|
|
|
|
if ref.mrel.is_custom():
|
|
|
|
rel_list.append(str(ref.mrel))
|
|
|
|
self.child_ref_types.update(rel_list)
|
2006-05-19 06:09:22 +05:30
|
|
|
|
|
|
|
self.event_role_names.update(
|
|
|
|
[str(eref.role) for eref in family.event_ref_list
|
|
|
|
if eref.role.is_custom()])
|
|
|
|
|
|
|
|
if family.type.is_custom():
|
|
|
|
self.family_rel_types.add(str(family.type))
|
2005-08-18 11:28:28 +05:30
|
|
|
|
2006-05-20 01:18:36 +05:30
|
|
|
attr_list = []
|
|
|
|
for mref in family.media_list:
|
|
|
|
attr_list += [str(attr.type) for attr in mref.attribute_list
|
2006-06-16 09:02:51 +05:30
|
|
|
if attr.type.is_custom() and str(attr.type)]
|
2006-05-20 01:18:36 +05:30
|
|
|
self.media_attributes.update(attr_list)
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def commit_repository(self, repository, transaction, change_time=None):
|
2005-05-27 23:13:04 +05:30
|
|
|
"""
|
|
|
|
Commits the specified Repository to the database, storing the changes
|
|
|
|
as part of the transaction.
|
|
|
|
"""
|
2007-06-25 21:40:10 +05:30
|
|
|
self.commit_base(repository, self.repository_map, REPOSITORY_KEY,
|
2006-04-08 02:36:20 +05:30
|
|
|
transaction.repository_update,
|
|
|
|
transaction.repository_add,
|
2005-05-27 23:13:04 +05:30
|
|
|
transaction, change_time)
|
|
|
|
|
2006-05-19 06:09:22 +05:30
|
|
|
if repository.type.is_custom():
|
|
|
|
self.repository_types.add(str(repository.type))
|
|
|
|
|
|
|
|
self.url_types.update([str(url.type) for url in repository.urls
|
|
|
|
if url.type.is_custom()])
|
|
|
|
|
2007-02-20 06:09:10 +05:30
|
|
|
def commit_note(self, note, transaction, change_time=None):
|
|
|
|
"""
|
|
|
|
Commits the specified Note to the database, storing the changes
|
|
|
|
as part of the transaction.
|
|
|
|
"""
|
2007-06-25 21:40:10 +05:30
|
|
|
self.commit_base(note, self.note_map, NOTE_KEY,
|
2007-02-20 06:09:10 +05:30
|
|
|
transaction.note_update,
|
|
|
|
transaction.note_add,
|
|
|
|
transaction, change_time)
|
|
|
|
|
|
|
|
if note.type.is_custom():
|
|
|
|
self.note_types.add(str(note.type))
|
|
|
|
|
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
|
2006-02-01 02:09:25 +05:30
|
|
|
while self.id_trans.has_key(str(index)):
|
2004-08-01 09:51:31 +05:30
|
|
|
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
|
2006-02-01 02:09:25 +05:30
|
|
|
while self.pid_trans.has_key(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
|
2006-02-01 02:09:25 +05:30
|
|
|
while self.eid_trans.has_key(str(index)):
|
2005-06-08 10:10:33 +05:30
|
|
|
self.emap_index += 1
|
|
|
|
index = self.eprefix % self.emap_index
|
2004-08-11 09:12:38 +05:30
|
|
|
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
|
2006-02-01 02:09:25 +05:30
|
|
|
while self.oid_trans.has_key(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
|
2006-02-01 02:09:25 +05:30
|
|
|
while self.sid_trans.has_key(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
|
2006-02-01 02:09:25 +05:30
|
|
|
while self.fid_trans.has_key(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
|
|
|
|
|
2005-05-27 23:13:04 +05:30
|
|
|
def find_next_repository_gramps_id(self):
|
|
|
|
"""
|
|
|
|
Returns the next available GRAMPS' ID for a Respository object based
|
|
|
|
off the repository ID prefix.
|
|
|
|
"""
|
|
|
|
index = self.rprefix % self.rmap_index
|
2006-02-01 02:09:25 +05:30
|
|
|
while self.rid_trans.has_key(str(index)):
|
2005-05-27 23:13:04 +05:30
|
|
|
self.rmap_index += 1
|
|
|
|
index = self.rprefix % self.rmap_index
|
|
|
|
self.rmap_index += 1
|
|
|
|
return index
|
|
|
|
|
2007-02-20 06:09:10 +05:30
|
|
|
def find_next_note_gramps_id(self):
|
|
|
|
"""
|
|
|
|
Returns the next available GRAMPS' ID for a Note object based
|
|
|
|
off the repository ID prefix.
|
|
|
|
"""
|
|
|
|
index = self.nprefix % self.nmap_index
|
|
|
|
while self.nid_trans.has_key(str(index)):
|
|
|
|
self.nmap_index += 1
|
|
|
|
index = self.nprefix % self.nmap_index
|
|
|
|
self.nmap_index += 1
|
|
|
|
return index
|
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def get_from_handle(self, handle, class_type, data_map):
|
2007-06-17 06:27:21 +05:30
|
|
|
data = data_map.get(str(handle))
|
2004-08-11 09:12:38 +05:30
|
|
|
if data:
|
2005-04-18 04:04:56 +05:30
|
|
|
newobj = class_type()
|
|
|
|
newobj.unserialize(data)
|
|
|
|
return newobj
|
2004-08-11 09:12:38 +05:30
|
|
|
return None
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_person_from_handle(self, handle):
|
2005-04-18 04:04:56 +05:30
|
|
|
"""
|
|
|
|
Finds a Person in the database from the passed gramps' ID.
|
|
|
|
If no such Person exists, None is returned.
|
|
|
|
"""
|
2007-06-26 11:32:17 +05:30
|
|
|
return self.get_from_handle(handle, Person, self.person_map)
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_source_from_handle(self, handle):
|
2005-04-18 04:04:56 +05:30
|
|
|
"""
|
|
|
|
Finds a Source in the database from the passed gramps' ID.
|
|
|
|
If no such Source exists, None is returned.
|
|
|
|
"""
|
2007-06-26 11:32:17 +05:30
|
|
|
return self.get_from_handle(handle, Source, self.source_map)
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_object_from_handle(self, handle):
|
2005-04-18 04:04:56 +05:30
|
|
|
"""
|
|
|
|
Finds an Object in the database from the passed gramps' ID.
|
|
|
|
If no such Object exists, None is returned.
|
|
|
|
"""
|
2007-06-26 11:32:17 +05:30
|
|
|
return self.get_from_handle(handle, MediaObject, self.media_map)
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_place_from_handle(self, handle):
|
2005-04-18 04:04:56 +05:30
|
|
|
"""
|
|
|
|
Finds a Place in the database from the passed gramps' ID.
|
|
|
|
If no such Place exists, None is returned.
|
|
|
|
"""
|
2007-06-26 11:32:17 +05:30
|
|
|
return self.get_from_handle(handle, Place, self.place_map)
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_event_from_handle(self, handle):
|
2005-04-18 04:04:56 +05:30
|
|
|
"""
|
|
|
|
Finds a Event in the database from the passed gramps' ID.
|
|
|
|
If no such Event exists, None is returned.
|
|
|
|
"""
|
2007-06-26 11:32:17 +05:30
|
|
|
return self.get_from_handle(handle, Event, self.event_map)
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_family_from_handle(self, handle):
|
2005-04-18 04:04:56 +05:30
|
|
|
"""
|
|
|
|
Finds a Family in the database from the passed gramps' ID.
|
|
|
|
If no such Family exists, None is returned.
|
|
|
|
"""
|
2007-06-26 11:32:17 +05:30
|
|
|
return self.get_from_handle(handle, Family, self.family_map)
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_repository_from_handle(self, handle):
|
2005-05-27 23:13:04 +05:30
|
|
|
"""
|
|
|
|
Finds a Repository in the database from the passed gramps' ID.
|
|
|
|
If no such Repository exists, None is returned.
|
|
|
|
"""
|
2007-06-26 11:32:17 +05:30
|
|
|
return self.get_from_handle(handle, Repository, self.repository_map)
|
2005-05-27 23:13:04 +05:30
|
|
|
|
2007-02-20 06:09:10 +05:30
|
|
|
def get_note_from_handle(self, handle):
|
|
|
|
"""
|
|
|
|
Finds a Note in the database from the passed gramps' ID.
|
|
|
|
If no such Note exists, None is returned.
|
|
|
|
"""
|
2007-06-26 11:32:17 +05:30
|
|
|
return self.get_from_handle(handle, Note, self.note_map)
|
2007-02-20 06:09:10 +05:30
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def find_from_handle(self, handle, transaction, class_type, dmap,
|
2006-04-08 02:36:20 +05:30
|
|
|
add_func):
|
2005-04-18 04:04:56 +05:30
|
|
|
obj = class_type()
|
2005-04-23 21:23:30 +05:30
|
|
|
handle = str(handle)
|
2006-01-31 07:11:55 +05:30
|
|
|
if dmap.has_key(handle):
|
2005-04-23 21:23:30 +05:30
|
|
|
obj.unserialize(dmap.get(handle))
|
2005-04-18 04:04:56 +05:30
|
|
|
else:
|
2005-04-23 21:23:30 +05:30
|
|
|
obj.set_handle(handle)
|
2006-04-08 02:36:20 +05:30
|
|
|
add_func(obj, transaction)
|
2005-04-18 04:04:56 +05:30
|
|
|
return obj
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def __check_from_handle(self, handle, transaction, class_type, dmap,
|
2007-10-10 01:32:02 +05:30
|
|
|
add_func, set_gid=True):
|
2006-01-31 07:11:55 +05:30
|
|
|
handle = str(handle)
|
|
|
|
if not dmap.has_key(handle):
|
|
|
|
obj = class_type()
|
|
|
|
obj.set_handle(handle)
|
2007-10-10 01:32:02 +05:30
|
|
|
add_func(obj, transaction, set_gid=set_gid)
|
2006-01-31 07:11:55 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def find_person_from_handle(self, handle, transaction):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Finds a Person in the database from the passed GRAMPS ID.
|
|
|
|
If no such Person exists, a new Person is added to the database.
|
|
|
|
"""
|
2007-06-26 11:32:17 +05:30
|
|
|
return self.find_from_handle(handle, transaction, Person,
|
|
|
|
self.person_map, self.add_person)
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def find_source_from_handle(self, handle, transaction):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
2006-01-31 07:11:55 +05:30
|
|
|
Finds a Source in the database from the passed handle.
|
2004-08-13 10:04:07 +05:30
|
|
|
If no such Source exists, a new Source is added to the database.
|
|
|
|
"""
|
2007-06-26 11:32:17 +05:30
|
|
|
return self.find_from_handle(handle, transaction, Source,
|
|
|
|
self.source_map, self.add_source)
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def find_event_from_handle(self, handle, transaction):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
2006-01-31 07:11:55 +05:30
|
|
|
Finds a Event in the database from the passed handle.
|
2004-08-21 23:43:18 +05:30
|
|
|
If no such Event exists, a new Event is added to the database.
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
2007-06-26 11:32:17 +05:30
|
|
|
return self.find_from_handle(handle, transaction, Event,
|
|
|
|
self.event_map, self.add_event)
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def find_object_from_handle(self, handle, transaction):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
2006-01-31 07:11:55 +05:30
|
|
|
Finds an MediaObject in the database from the passed handle.
|
|
|
|
If no such MediaObject exists, a new Object is added to the database.
|
|
|
|
"""
|
2007-06-26 11:32:17 +05:30
|
|
|
return self.find_from_handle(handle, transaction, MediaObject,
|
|
|
|
self.media_map, self.add_object)
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def find_place_from_handle(self, handle, transaction):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
2006-01-31 07:11:55 +05:30
|
|
|
Finds a Place in the database from the passed handle.
|
2004-08-13 10:04:07 +05:30
|
|
|
If no such Place exists, a new Place is added to the database.
|
|
|
|
"""
|
2007-06-26 11:32:17 +05:30
|
|
|
return self.find_from_handle(handle, transaction, Place,
|
|
|
|
self.place_map, self.add_place)
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def find_family_from_handle(self, handle, transaction):
|
2005-04-18 04:04:56 +05:30
|
|
|
"""
|
2006-01-31 07:11:55 +05:30
|
|
|
Finds a Family in the database from the passed handle.
|
2005-04-18 04:04:56 +05:30
|
|
|
If no such Family exists, a new Family is added to the database.
|
|
|
|
"""
|
2007-06-26 11:32:17 +05:30
|
|
|
return self.find_from_handle(handle, transaction, Family,
|
|
|
|
self.family_map, self.add_family)
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def find_repository_from_handle(self, handle, transaction):
|
2005-05-27 23:13:04 +05:30
|
|
|
"""
|
2006-01-31 07:11:55 +05:30
|
|
|
Finds a Repository in the database from the passed handle.
|
2005-05-27 23:13:04 +05:30
|
|
|
If no such Repository exists, a new Repository is added to the database.
|
|
|
|
"""
|
2007-06-26 11:32:17 +05:30
|
|
|
return self.find_from_handle(handle, transaction, Repository,
|
|
|
|
self.repository_map, self.add_repository)
|
2005-05-27 23:13:04 +05:30
|
|
|
|
2007-02-20 06:09:10 +05:30
|
|
|
def find_note_from_handle(self, handle, transaction):
|
|
|
|
"""
|
|
|
|
Finds a Note in the database from the passed handle.
|
|
|
|
If no such Note exists, a new Note is added to the database.
|
|
|
|
"""
|
2007-06-26 11:32:17 +05:30
|
|
|
return self.find_from_handle(handle, transaction, Note,
|
|
|
|
self.note_map, self.add_note)
|
2007-02-20 06:09:10 +05:30
|
|
|
|
2007-10-12 04:11:03 +05:30
|
|
|
def check_person_from_handle(self, handle, transaction, set_gid=True):
|
2006-01-31 07:11:55 +05:30
|
|
|
"""
|
|
|
|
Checks whether a Person with the passed handle exists in the database.
|
|
|
|
If no such Person exists, a new Person is added to the database.
|
2007-10-12 04:11:03 +05:30
|
|
|
If set_gid then a new gramps_id is created, if not, None is used.
|
2006-01-31 07:11:55 +05:30
|
|
|
"""
|
2007-06-04 08:19:31 +05:30
|
|
|
self.__check_from_handle(handle, transaction, Person,
|
2007-10-12 04:11:03 +05:30
|
|
|
self.person_map, self.add_person,
|
|
|
|
set_gid = set_gid)
|
2006-01-31 07:11:55 +05:30
|
|
|
|
2007-10-10 01:32:02 +05:30
|
|
|
def check_source_from_handle(self, handle, transaction, set_gid=True):
|
2006-01-31 07:11:55 +05:30
|
|
|
"""
|
|
|
|
Checks whether a Source with the passed handle exists in the database.
|
|
|
|
If no such Source exists, a new Source is added to the database.
|
2007-10-10 01:32:02 +05:30
|
|
|
If set_gid then a new gramps_id is created, if not, None is used.
|
2006-01-31 07:11:55 +05:30
|
|
|
"""
|
2007-06-04 08:19:31 +05:30
|
|
|
self.__check_from_handle(handle, transaction, Source,
|
2007-10-10 01:32:02 +05:30
|
|
|
self.source_map, self.add_source,
|
|
|
|
set_gid=set_gid)
|
|
|
|
|
2007-10-12 04:11:03 +05:30
|
|
|
def check_event_from_handle(self, handle, transaction, set_gid=True):
|
2006-01-31 07:11:55 +05:30
|
|
|
"""
|
|
|
|
Checks whether an Event with the passed handle exists in the database.
|
|
|
|
If no such Event exists, a new Event is added to the database.
|
2007-10-12 04:11:03 +05:30
|
|
|
If set_gid then a new gramps_id is created, if not, None is used.
|
2006-01-31 07:11:55 +05:30
|
|
|
"""
|
2007-06-04 08:19:31 +05:30
|
|
|
self.__check_from_handle(handle, transaction, Event,
|
2007-10-12 04:11:03 +05:30
|
|
|
self.event_map, self.add_event,
|
|
|
|
set_gid=set_gid)
|
2006-01-31 07:11:55 +05:30
|
|
|
|
2007-10-12 04:11:03 +05:30
|
|
|
def check_object_from_handle(self, handle, transaction, set_gid=True):
|
2006-01-31 07:11:55 +05:30
|
|
|
"""
|
|
|
|
Checks whether a MediaObject with the passed handle exists in
|
|
|
|
the database. If no such MediaObject exists, a new Object is
|
|
|
|
added to the database.
|
2007-10-12 04:11:03 +05:30
|
|
|
If set_gid then a new gramps_id is created, if not, None is used.
|
2006-01-31 07:11:55 +05:30
|
|
|
"""
|
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
self.__check_from_handle(handle, transaction, MediaObject,
|
2007-10-12 04:11:03 +05:30
|
|
|
self.media_map, self.add_object,
|
|
|
|
set_gid=set_gid)
|
2006-01-31 07:11:55 +05:30
|
|
|
|
2007-10-12 04:11:03 +05:30
|
|
|
def check_place_from_handle(self, handle, transaction, set_gid=True):
|
2006-01-31 07:11:55 +05:30
|
|
|
"""
|
|
|
|
Checks whether a Place with the passed handle exists in the database.
|
|
|
|
If no such Place exists, a new Place is added to the database.
|
2007-10-12 04:11:03 +05:30
|
|
|
If set_gid then a new gramps_id is created, if not, None is used.
|
2006-01-31 07:11:55 +05:30
|
|
|
"""
|
2007-06-04 08:19:31 +05:30
|
|
|
self.__check_from_handle(handle, transaction, Place,
|
2007-10-12 04:11:03 +05:30
|
|
|
self.place_map, self.add_place,
|
|
|
|
set_gid=set_gid)
|
2006-01-31 07:11:55 +05:30
|
|
|
|
2007-10-12 04:11:03 +05:30
|
|
|
def check_family_from_handle(self, handle, transaction, set_gid=True):
|
2006-01-31 07:11:55 +05:30
|
|
|
"""
|
|
|
|
Checks whether a Family with the passed handle exists in the database.
|
|
|
|
If no such Family exists, a new Family is added to the database.
|
2007-10-12 04:11:03 +05:30
|
|
|
If set_gid then a new gramps_id is created, if not, None is used.
|
2006-01-31 07:11:55 +05:30
|
|
|
"""
|
2007-06-04 08:19:31 +05:30
|
|
|
self.__check_from_handle(handle, transaction, Family,
|
2007-10-12 04:11:03 +05:30
|
|
|
self.family_map, self.add_family,
|
|
|
|
set_gid=set_gid)
|
2006-01-31 07:11:55 +05:30
|
|
|
|
2007-10-12 04:11:03 +05:30
|
|
|
def check_repository_from_handle(self, handle, transaction, set_gid=True):
|
2006-01-31 07:11:55 +05:30
|
|
|
"""
|
|
|
|
Checks whether a Repository with the passed handle exists in the
|
|
|
|
database. If no such Repository exists, a new Repository is added
|
|
|
|
to the database.
|
2007-10-12 04:11:03 +05:30
|
|
|
If set_gid then a new gramps_id is created, if not, None is used.
|
2006-01-31 07:11:55 +05:30
|
|
|
"""
|
2007-06-04 08:19:31 +05:30
|
|
|
self.__check_from_handle(handle, transaction, Repository,
|
2007-10-12 04:11:03 +05:30
|
|
|
self.repository_map, self.add_repository,
|
|
|
|
set_gid=set_gid)
|
2006-01-31 07:11:55 +05:30
|
|
|
|
2007-10-12 04:11:03 +05:30
|
|
|
def check_note_from_handle(self, handle, transaction, set_gid=True):
|
2007-02-20 06:09:10 +05:30
|
|
|
"""
|
|
|
|
Checks whether a Note with the passed handle exists in the
|
|
|
|
database. If no such Note exists, a new Note is added
|
|
|
|
to the database.
|
2007-10-12 04:11:03 +05:30
|
|
|
If set_gid then a new gramps_id is created, if not, None is used.
|
2007-02-20 06:09:10 +05:30
|
|
|
"""
|
2007-06-04 08:19:31 +05:30
|
|
|
self.__check_from_handle(handle, transaction, Note,
|
2007-10-12 04:11:03 +05:30
|
|
|
self.note_map, self.add_note,
|
|
|
|
set_gid=set_gid)
|
2007-02-20 06:09:10 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_person_from_gramps_id(self, val):
|
2004-08-20 07:50:06 +05:30
|
|
|
"""
|
|
|
|
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.
|
|
|
|
"""
|
2007-05-07 09:09:46 +05:30
|
|
|
raise NotImplementedError
|
2004-08-20 07:50:06 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_family_from_gramps_id(self, val):
|
2004-08-20 07:50:06 +05:30
|
|
|
"""
|
|
|
|
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.
|
|
|
|
"""
|
2007-05-07 09:09:46 +05:30
|
|
|
raise NotImplementedError
|
2004-08-20 07:50:06 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_event_from_gramps_id(self, val):
|
2006-01-27 12:24:35 +05:30
|
|
|
"""
|
|
|
|
Finds an Event in the database from the passed GRAMPS ID.
|
|
|
|
If no such Event exists, None is returned.
|
|
|
|
|
|
|
|
Needs to be overridden by the derrived class.
|
|
|
|
"""
|
2007-05-07 09:09:46 +05:30
|
|
|
raise NotImplementedError
|
2006-01-27 12:24:35 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_place_from_gramps_id(self, val):
|
2006-05-20 06:22:47 +05:30
|
|
|
"""
|
|
|
|
Finds a Place in the database from the passed gramps' ID.
|
|
|
|
If no such Place exists, None is returned.
|
2004-08-24 10:39:50 +05:30
|
|
|
|
|
|
|
Needs to be overridden by the derrived class.
|
|
|
|
"""
|
2007-05-07 09:09:46 +05:30
|
|
|
raise NotImplementedError
|
2004-08-24 10:39:50 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_source_from_gramps_id(self, val):
|
2006-05-20 06:22:47 +05:30
|
|
|
"""
|
|
|
|
Finds a Source in the database from the passed gramps' ID.
|
|
|
|
If no such Source exists, None is returned.
|
2004-08-24 10:39:50 +05:30
|
|
|
|
|
|
|
Needs to be overridden by the derrived class.
|
|
|
|
"""
|
2007-05-07 09:09:46 +05:30
|
|
|
raise NotImplementedError
|
2004-08-24 10:39:50 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_object_from_gramps_id(self, val):
|
2006-05-20 06:22:47 +05:30
|
|
|
"""
|
|
|
|
Finds a MediaObject in the database from the passed gramps' ID.
|
|
|
|
If no such MediaObject exists, None is returned.
|
2004-08-24 10:39:50 +05:30
|
|
|
|
|
|
|
Needs to be overridden by the derrived class.
|
|
|
|
"""
|
2007-05-07 09:09:46 +05:30
|
|
|
raise NotImplementedError
|
2004-08-24 10:39:50 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_repository_from_gramps_id(self, val):
|
2006-05-20 06:22:47 +05:30
|
|
|
"""
|
|
|
|
Finds a Repository in the database from the passed gramps' ID.
|
2007-02-20 06:09:10 +05:30
|
|
|
If no such Repository exists, None is returned.
|
|
|
|
|
|
|
|
Needs to be overridden by the derrived class.
|
|
|
|
"""
|
2007-05-07 09:09:46 +05:30
|
|
|
raise NotImplementedError
|
2007-02-20 06:09:10 +05:30
|
|
|
|
|
|
|
def get_note_from_gramps_id(self, val):
|
|
|
|
"""
|
|
|
|
Finds a Note in the database from the passed gramps' ID.
|
|
|
|
If no such Note exists, None is returned.
|
2005-05-27 23:13:04 +05:30
|
|
|
|
|
|
|
Needs to be overridden by the derrived class.
|
|
|
|
"""
|
2007-05-07 09:09:46 +05:30
|
|
|
raise NotImplementedError
|
2005-05-27 23:13:04 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def __add_object(self, obj, transaction, find_next_func, commit_func):
|
2007-10-10 01:32:02 +05:30
|
|
|
if find_next_func and not obj.gramps_id:
|
2005-05-24 18:38:06 +05:30
|
|
|
obj.gramps_id = find_next_func()
|
|
|
|
if not obj.handle:
|
|
|
|
obj.handle = self.create_id()
|
2006-04-08 02:36:20 +05:30
|
|
|
commit_func(obj, transaction)
|
2005-07-09 01:54:54 +05:30
|
|
|
if obj.__class__.__name__ == 'Person':
|
2006-04-23 09:59:14 +05:30
|
|
|
self.genderStats.count_person (obj)
|
2005-05-24 18:38:06 +05:30
|
|
|
return obj.handle
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2007-10-10 01:32:02 +05:30
|
|
|
def add_person(self, person, transaction, set_gid=True):
|
2005-07-09 01:54:54 +05:30
|
|
|
"""
|
|
|
|
Adds a Person to the database, assigning internal IDs if they have
|
|
|
|
not already been defined.
|
2007-10-10 01:32:02 +05:30
|
|
|
If not set_gid, then gramps_id is not set
|
2005-07-09 01:54:54 +05:30
|
|
|
"""
|
2007-10-10 01:32:02 +05:30
|
|
|
if set_gid:
|
|
|
|
return self.__add_object(person, transaction,
|
|
|
|
self.find_next_person_gramps_id,
|
|
|
|
self.commit_person)
|
|
|
|
else:
|
|
|
|
return self.__add_object(person, transaction,
|
|
|
|
None,
|
|
|
|
self.commit_person)
|
2005-07-09 01:54:54 +05:30
|
|
|
|
2007-10-10 01:32:02 +05:30
|
|
|
def add_family(self, family, transaction, set_gid=True):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Adds a Family to the database, assigning internal IDs if they have
|
|
|
|
not already been defined.
|
2007-10-10 01:32:02 +05:30
|
|
|
If not set_gid, then gramps_id is not set
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
2007-10-10 01:32:02 +05:30
|
|
|
if set_gid:
|
|
|
|
return self.__add_object(family, transaction,
|
|
|
|
self.find_next_family_gramps_id,
|
|
|
|
self.commit_family)
|
|
|
|
else:
|
|
|
|
return self.__add_object(family, transaction,
|
|
|
|
None,
|
|
|
|
self.commit_family)
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2007-10-10 01:32:02 +05:30
|
|
|
def add_source(self, source, transaction, set_gid=True):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Adds a Source to the database, assigning internal IDs if they have
|
|
|
|
not already been defined.
|
2007-10-10 01:32:02 +05:30
|
|
|
If not set_gid, then gramps_id is not set
|
|
|
|
"""
|
|
|
|
if set_gid:
|
|
|
|
return self.__add_object(source, transaction,
|
|
|
|
self.find_next_source_gramps_id,
|
|
|
|
self.commit_source)
|
|
|
|
else :
|
|
|
|
return self.__add_object(source, transaction,
|
|
|
|
None,
|
2005-04-18 04:04:56 +05:30
|
|
|
self.commit_source)
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2007-10-10 01:32:02 +05:30
|
|
|
def add_event(self, event, transaction, set_gid=True):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Adds an Event to the database, assigning internal IDs if they have
|
|
|
|
not already been defined.
|
2007-10-10 01:32:02 +05:30
|
|
|
If not set_gid, then gramps_id is not set
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
2007-10-10 01:32:02 +05:30
|
|
|
if set_gid:
|
|
|
|
return self.__add_object(event, transaction,
|
|
|
|
self.find_next_event_gramps_id,
|
|
|
|
self.commit_event)
|
|
|
|
else:
|
|
|
|
return self.__add_object(event, transaction,
|
|
|
|
None,
|
|
|
|
self.commit_event)
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def add_person_event(self, event, transaction):
|
2006-04-01 05:16:34 +05:30
|
|
|
"""
|
|
|
|
Adds an Event to the database, assigning internal IDs if they have
|
|
|
|
not already been defined.
|
|
|
|
"""
|
2006-04-20 04:29:33 +05:30
|
|
|
if event.type.is_custom():
|
|
|
|
self.individual_event_names.add(str(event.type))
|
2006-04-08 02:36:20 +05:30
|
|
|
return self.add_event(event, transaction)
|
2006-04-01 05:16:34 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def add_family_event(self, event, transaction):
|
2006-04-01 05:16:34 +05:30
|
|
|
"""
|
|
|
|
Adds an Event to the database, assigning internal IDs if they have
|
|
|
|
not already been defined.
|
|
|
|
"""
|
2006-04-20 04:29:33 +05:30
|
|
|
if event.type.is_custom():
|
|
|
|
self.family_event_names.add(str(event.type))
|
2006-04-08 02:36:20 +05:30
|
|
|
return self.add_event(event, transaction)
|
2006-04-01 05:16:34 +05:30
|
|
|
|
2007-10-10 01:32:02 +05:30
|
|
|
def add_place(self, place, transaction, set_gid=True):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Adds a Place to the database, assigning internal IDs if they have
|
|
|
|
not already been defined.
|
2007-10-10 01:32:02 +05:30
|
|
|
If not set_gid, then gramps_id is not set
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
2007-10-10 01:32:02 +05:30
|
|
|
if set_gid:
|
|
|
|
return self.__add_object(place, transaction,
|
|
|
|
self.find_next_place_gramps_id,
|
|
|
|
self.commit_place)
|
|
|
|
else:
|
|
|
|
return self.__add_object(place, transaction,
|
|
|
|
None,
|
|
|
|
self.commit_place)
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2007-10-10 01:32:02 +05:30
|
|
|
def add_object(self, obj, transaction, set_gid=True):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Adds a MediaObject to the database, assigning internal IDs if they have
|
|
|
|
not already been defined.
|
2007-10-10 01:32:02 +05:30
|
|
|
If not set_gid, then gramps_id is not set
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
2007-10-10 01:32:02 +05:30
|
|
|
if set_gid:
|
|
|
|
return self.__add_object(obj, transaction,
|
|
|
|
self.find_next_object_gramps_id,
|
|
|
|
self.commit_media_object)
|
|
|
|
else:
|
|
|
|
return self.__add_object(obj, transaction,
|
|
|
|
None,
|
|
|
|
self.commit_media_object)
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2007-10-10 01:32:02 +05:30
|
|
|
def add_repository(self, obj, transaction, set_gid=True):
|
2005-05-27 23:13:04 +05:30
|
|
|
"""
|
|
|
|
Adds a Repository to the database, assigning internal IDs if they have
|
|
|
|
not already been defined.
|
2007-10-10 01:32:02 +05:30
|
|
|
If not set_gid, then gramps_id is not set
|
2005-05-27 23:13:04 +05:30
|
|
|
"""
|
2007-10-10 01:32:02 +05:30
|
|
|
if set_gid:
|
|
|
|
return self.__add_object(obj, transaction,
|
|
|
|
self.find_next_repository_gramps_id,
|
|
|
|
self.commit_repository)
|
|
|
|
else:
|
|
|
|
return self.__add_object(obj, transaction,
|
|
|
|
None,
|
|
|
|
self.commit_repository)
|
2005-05-27 23:13:04 +05:30
|
|
|
|
2007-10-10 01:32:02 +05:30
|
|
|
def add_note(self, obj, transaction, set_gid=True):
|
2007-02-20 06:09:10 +05:30
|
|
|
"""
|
|
|
|
Adds a Note to the database, assigning internal IDs if they have
|
|
|
|
not already been defined.
|
2007-10-10 01:32:02 +05:30
|
|
|
If not set_gid, then gramps_id is not set
|
2007-02-20 06:09:10 +05:30
|
|
|
"""
|
2007-10-10 01:32:02 +05:30
|
|
|
if set_gid:
|
|
|
|
return self.__add_object(obj, transaction,
|
|
|
|
self.find_next_note_gramps_id,
|
|
|
|
self.commit_note)
|
|
|
|
else:
|
|
|
|
return self.__add_object(obj, transaction,
|
|
|
|
None,
|
|
|
|
self.commit_note)
|
2007-02-20 06:09:10 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_name_group_mapping(self, name):
|
2004-10-01 00:02:56 +05:30
|
|
|
"""
|
|
|
|
Returns the default grouping name for a surname
|
|
|
|
"""
|
2006-08-26 23:34:20 +05:30
|
|
|
return unicode(self.name_group.get(str(name), name))
|
2004-10-01 00:02:56 +05:30
|
|
|
|
|
|
|
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()]
|
|
|
|
|
2007-12-09 15:48:59 +05:30
|
|
|
def has_name_group_key(self, name):
|
|
|
|
"""
|
|
|
|
Return if a key exists in the name_group table
|
|
|
|
"""
|
|
|
|
return self.name_group.has_key(str(name))
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def set_name_group_mapping(self, name, group):
|
2004-10-01 00:02:56 +05:30
|
|
|
"""
|
2005-04-18 04:04:56 +05:30
|
|
|
Sets the default grouping name for a surname. Needs to be overridden
|
|
|
|
in the derived class.
|
2004-10-01 00:02:56 +05:30
|
|
|
"""
|
2007-05-07 09:09:46 +05:30
|
|
|
raise NotImplementedError
|
2004-10-01 00:02:56 +05:30
|
|
|
|
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.
|
|
|
|
"""
|
2006-01-11 03:58:09 +05:30
|
|
|
if self.db_is_open:
|
|
|
|
return len(self.person_map)
|
|
|
|
else:
|
|
|
|
return 0
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2005-08-18 11:28:28 +05:30
|
|
|
def get_number_of_families(self):
|
|
|
|
"""
|
|
|
|
Returns the number of families currently in the databse.
|
|
|
|
"""
|
|
|
|
return len(self.family_map)
|
|
|
|
|
|
|
|
def get_number_of_events(self):
|
|
|
|
"""
|
|
|
|
Returns the number of events currently in the databse.
|
|
|
|
"""
|
|
|
|
return len(self.event_map)
|
|
|
|
|
|
|
|
def get_number_of_places(self):
|
|
|
|
"""
|
|
|
|
Returns the number of places currently in the databse.
|
|
|
|
"""
|
|
|
|
return len(self.place_map)
|
|
|
|
|
|
|
|
def get_number_of_sources(self):
|
|
|
|
"""
|
|
|
|
Returns the number of sources currently in the databse.
|
|
|
|
"""
|
|
|
|
return len(self.source_map)
|
|
|
|
|
|
|
|
def get_number_of_media_objects(self):
|
|
|
|
"""
|
|
|
|
Returns the number of media objects currently in the databse.
|
|
|
|
"""
|
|
|
|
return len(self.media_map)
|
|
|
|
|
2006-01-07 02:25:49 +05:30
|
|
|
def get_number_of_repositories(self):
|
|
|
|
"""
|
|
|
|
Returns the number of source repositories currently in the databse.
|
|
|
|
"""
|
|
|
|
return len(self.repository_map)
|
|
|
|
|
2007-02-20 06:09:10 +05:30
|
|
|
def get_number_of_notes(self):
|
|
|
|
"""
|
|
|
|
Returns the number of notes currently in the databse.
|
|
|
|
"""
|
|
|
|
return len(self.note_map)
|
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def all_handles(self, table):
|
2006-01-11 03:58:09 +05:30
|
|
|
return table.keys()
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_person_handles(self, sort_handles=True):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
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
|
|
|
|
"""
|
2006-01-11 03:58:09 +05:30
|
|
|
if self.db_is_open:
|
2004-08-13 10:04:07 +05:30
|
|
|
if sort_handles:
|
2004-12-20 04:25:41 +05:30
|
|
|
slist = []
|
|
|
|
cursor = self.get_person_cursor()
|
|
|
|
data = cursor.first()
|
|
|
|
while data:
|
2006-04-08 02:36:20 +05:30
|
|
|
slist.append((data[1][3][3], data[0]))
|
2004-12-20 04:25:41 +05:30
|
|
|
data = cursor.next()
|
|
|
|
cursor.close()
|
|
|
|
slist.sort()
|
|
|
|
return map(lambda x: x[1], slist)
|
|
|
|
else:
|
2007-06-26 11:32:17 +05:30
|
|
|
return self.all_handles(self.person_map)
|
2004-08-11 09:12:38 +05:30
|
|
|
return []
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_place_handles(self, sort_handles=True):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
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.
|
|
|
|
"""
|
2006-02-06 00:30:25 +05:30
|
|
|
if self.db_is_open:
|
2004-08-13 10:04:07 +05:30
|
|
|
if sort_handles:
|
2004-12-20 04:25:41 +05:30
|
|
|
slist = []
|
|
|
|
cursor = self.get_place_cursor()
|
|
|
|
data = cursor.first()
|
|
|
|
while data:
|
2006-04-08 02:36:20 +05:30
|
|
|
slist.append((data[1][2], data[0]))
|
2004-12-20 04:25:41 +05:30
|
|
|
data = cursor.next()
|
|
|
|
cursor.close()
|
|
|
|
slist.sort()
|
|
|
|
val = map(lambda x: x[1], slist)
|
|
|
|
return val
|
|
|
|
else:
|
2007-06-26 11:32:17 +05:30
|
|
|
return self.all_handles(self.place_map)
|
2004-08-11 09:12:38 +05:30
|
|
|
return []
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_source_handles(self, sort_handles=True):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
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.
|
|
|
|
"""
|
2006-02-06 00:30:25 +05:30
|
|
|
if self.db_is_open:
|
2007-06-26 11:32:17 +05:30
|
|
|
handle_list = self.all_handles(self.source_map)
|
2004-08-13 10:04:07 +05:30
|
|
|
if sort_handles:
|
2007-06-04 08:19:31 +05:30
|
|
|
handle_list.sort(self.__sortbysource)
|
2004-08-13 10:04:07 +05:30
|
|
|
return handle_list
|
|
|
|
return []
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_media_object_handles(self, sort_handles=True):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
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.
|
|
|
|
"""
|
2006-02-06 00:30:25 +05:30
|
|
|
if self.db_is_open:
|
2007-06-26 11:32:17 +05:30
|
|
|
handle_list = self.all_handles(self.media_map)
|
2004-08-13 10:04:07 +05:30
|
|
|
if sort_handles:
|
2007-06-04 08:19:31 +05:30
|
|
|
handle_list.sort(self.__sortbymedia)
|
2004-08-13 10:04:07 +05:30
|
|
|
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.
|
|
|
|
"""
|
2006-02-06 00:30:25 +05:30
|
|
|
if self.db_is_open:
|
2007-06-26 11:32:17 +05:30
|
|
|
return self.all_handles(self.event_map)
|
2004-08-13 10:04:07 +05:30
|
|
|
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.
|
|
|
|
"""
|
2006-02-06 00:30:25 +05:30
|
|
|
if self.db_is_open:
|
2007-06-26 11:32:17 +05:30
|
|
|
return self.all_handles(self.family_map)
|
2004-08-13 10:04:07 +05:30
|
|
|
return []
|
|
|
|
|
2005-05-27 23:13:04 +05:30
|
|
|
def get_repository_handles(self):
|
|
|
|
"""
|
|
|
|
Returns a list of database handles, one handle for each Repository in
|
|
|
|
the database.
|
|
|
|
"""
|
2006-02-06 00:30:25 +05:30
|
|
|
if self.db_is_open:
|
2007-06-26 11:32:17 +05:30
|
|
|
return self.all_handles(self.repository_map)
|
2005-05-27 23:13:04 +05:30
|
|
|
return []
|
|
|
|
|
2007-02-20 06:09:10 +05:30
|
|
|
def get_note_handles(self):
|
|
|
|
"""
|
|
|
|
Returns a list of database handles, one handle for each Note in
|
|
|
|
the database.
|
|
|
|
"""
|
|
|
|
if self.db_is_open:
|
2007-06-26 11:32:17 +05:30
|
|
|
return self.all_handles(self.note_map)
|
2007-02-20 06:09:10 +05:30
|
|
|
return []
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_gramps_ids(self, obj_key):
|
2006-01-31 07:11:55 +05:30
|
|
|
key2table = {
|
2007-06-04 08:19:31 +05:30
|
|
|
PERSON_KEY: self.id_trans,
|
|
|
|
FAMILY_KEY: self.fid_trans,
|
|
|
|
SOURCE_KEY: self.sid_trans,
|
|
|
|
EVENT_KEY: self.eid_trans,
|
|
|
|
MEDIA_KEY: self.oid_trans,
|
|
|
|
PLACE_KEY: self.pid_trans,
|
2006-04-08 02:36:20 +05:30
|
|
|
REPOSITORY_KEY: self.rid_trans,
|
2007-06-04 08:19:31 +05:30
|
|
|
NOTE_KEY: self.nid_trans,
|
2006-01-31 07:11:55 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
table = key2table[obj_key]
|
|
|
|
return table.keys()
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def has_gramps_id(self, obj_key, gramps_id):
|
2006-01-31 07:11:55 +05:30
|
|
|
key2table = {
|
2007-06-04 08:19:31 +05:30
|
|
|
PERSON_KEY: self.id_trans,
|
|
|
|
FAMILY_KEY: self.fid_trans,
|
|
|
|
SOURCE_KEY: self.sid_trans,
|
|
|
|
EVENT_KEY: self.eid_trans,
|
|
|
|
MEDIA_KEY: self.oid_trans,
|
|
|
|
PLACE_KEY: self.pid_trans,
|
2006-04-08 02:36:20 +05:30
|
|
|
REPOSITORY_KEY: self.rid_trans,
|
2007-06-04 08:19:31 +05:30
|
|
|
NOTE_KEY: self.nid_trans,
|
2006-01-31 07:11:55 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
table = key2table[obj_key]
|
|
|
|
return table.has_key(str(gramps_id))
|
|
|
|
|
2006-01-30 03:35:20 +05:30
|
|
|
def find_initial_person(self):
|
|
|
|
person = self.get_default_person()
|
|
|
|
if not person:
|
|
|
|
the_ids = self.get_gramps_ids(PERSON_KEY)
|
|
|
|
if the_ids:
|
|
|
|
person = self.get_person_from_gramps_id(min(the_ids))
|
|
|
|
return person
|
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
def _validated_id_prefix(self, val, default):
|
|
|
|
if val:
|
|
|
|
try:
|
|
|
|
junk = val % 1
|
|
|
|
prefix_var = val # use the prefix as is because it works fine
|
|
|
|
except:
|
|
|
|
try:
|
|
|
|
val = val + "%d"
|
|
|
|
junk = val % 1
|
|
|
|
prefix_var = val # format string was missing
|
|
|
|
except:
|
|
|
|
prefix_var = default+"%04d" # use default
|
|
|
|
else:
|
|
|
|
prefix_var = default+"%04d"
|
|
|
|
return prefix_var
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def set_person_id_prefix(self, val):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
2005-04-18 04:04:56 +05:30
|
|
|
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-13 10:04:07 +05:30
|
|
|
"""
|
2006-04-08 02:36:20 +05:30
|
|
|
self.iprefix = self._validated_id_prefix(val, "I")
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def set_source_id_prefix(self, val):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
2005-04-18 04:04:56 +05:30
|
|
|
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-13 10:04:07 +05:30
|
|
|
"""
|
2006-04-08 02:36:20 +05:30
|
|
|
self.sprefix = self._validated_id_prefix(val, "S")
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def set_object_id_prefix(self, val):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
2005-04-18 04:04:56 +05:30
|
|
|
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-13 10:04:07 +05:30
|
|
|
"""
|
2006-04-08 02:36:20 +05:30
|
|
|
self.oprefix = self._validated_id_prefix(val, "O")
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def set_place_id_prefix(self, val):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
2005-04-18 04:04:56 +05:30
|
|
|
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-13 10:04:07 +05:30
|
|
|
"""
|
2006-04-08 02:36:20 +05:30
|
|
|
self.pprefix = self._validated_id_prefix(val, "P")
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def set_family_id_prefix(self, val):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
2005-04-18 04:04:56 +05:30
|
|
|
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-13 10:04:07 +05:30
|
|
|
"""
|
2006-04-08 02:36:20 +05:30
|
|
|
self.fprefix = self._validated_id_prefix(val, "F")
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def set_event_id_prefix(self, val):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
2005-04-18 04:04:56 +05:30
|
|
|
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-13 10:04:07 +05:30
|
|
|
"""
|
2006-04-08 02:36:20 +05:30
|
|
|
self.eprefix = self._validated_id_prefix(val, "E")
|
2005-05-27 23:13:04 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def set_repository_id_prefix(self, val):
|
2005-05-27 23:13:04 +05:30
|
|
|
"""
|
|
|
|
Sets the naming template for GRAMPS Repository ID values. The string is
|
|
|
|
expected to be in the form of a simple text string, or in a format
|
2005-12-06 12:08:09 +05:30
|
|
|
that contains a C/Python style format string using %d, such as R%d
|
|
|
|
or R%04d.
|
2005-05-27 23:13:04 +05:30
|
|
|
"""
|
2006-04-08 02:36:20 +05:30
|
|
|
self.rprefix = self._validated_id_prefix(val, "R")
|
2006-10-29 10:06:08 +05:30
|
|
|
|
2007-02-20 06:09:10 +05:30
|
|
|
def set_note_id_prefix(self, val):
|
|
|
|
"""
|
|
|
|
Sets the naming template for GRAMPS Note 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 N%d
|
|
|
|
or N%04d.
|
|
|
|
"""
|
|
|
|
self.nprefix = self._validated_id_prefix(val, "N")
|
|
|
|
|
2007-04-02 09:26:30 +05:30
|
|
|
def transaction_begin(self, msg="", batch=False, no_magic=False):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
2005-04-18 04:04:56 +05:30
|
|
|
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-13 10:04:07 +05:30
|
|
|
"""
|
2007-06-14 11:09:03 +05:30
|
|
|
if self._LOG_ALL:
|
2007-06-04 08:19:31 +05:30
|
|
|
LOG.debug("%s: Transaction begin '%s'\n"
|
2006-01-07 02:25:49 +05:30
|
|
|
% (self.__class__.__name__, str(msg)))
|
2006-05-04 05:06:10 +05:30
|
|
|
if batch:
|
|
|
|
# A batch transaction does not store the commits
|
|
|
|
# Aborting the session completely will become impossible.
|
|
|
|
self.abort_possible = False
|
2006-05-07 10:52:44 +05:30
|
|
|
self.undo_history_timestamp = time.time()
|
2006-05-04 06:08:25 +05:30
|
|
|
# Undo is also impossible after batch transaction
|
|
|
|
self.undoindex = -1
|
2006-05-18 05:06:31 +05:30
|
|
|
self.translist = [None] * _UNDO_SIZE
|
2006-04-08 02:36:20 +05:30
|
|
|
return Transaction(msg, self.undodb, batch)
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def transaction_commit(self, transaction, msg):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Commits the transaction to the assocated UNDO database.
|
|
|
|
"""
|
2007-06-14 11:09:03 +05:30
|
|
|
if self._LOG_ALL:
|
2007-06-04 08:19:31 +05:30
|
|
|
LOG.debug("%s: Transaction commit '%s'\n"
|
2006-01-07 02:25:49 +05:30
|
|
|
% (self.__class__.__name__, str(msg)))
|
2007-01-20 22:25:08 +05:30
|
|
|
|
|
|
|
if not len(transaction) or self.readonly:
|
2004-08-01 09:51:31 +05:30
|
|
|
return
|
2007-01-20 22:25:08 +05:30
|
|
|
|
2004-08-01 09:51:31 +05:30
|
|
|
transaction.set_description(msg)
|
2006-05-06 03:25:01 +05:30
|
|
|
transaction.timestamp = time.time()
|
2005-12-18 02:43:45 +05:30
|
|
|
self.undoindex += 1
|
|
|
|
if self.undoindex >= _UNDO_SIZE:
|
2006-05-04 04:51:49 +05:30
|
|
|
# We overran the undo size.
|
|
|
|
# Aborting the session completely will become impossible.
|
|
|
|
self.abort_possible = False
|
2006-05-07 10:52:44 +05:30
|
|
|
self.undo_history_timestamp = time.time()
|
2005-12-18 02:43:45 +05:30
|
|
|
self.translist = self.translist[0:-1] + [ transaction ]
|
2004-08-01 09:51:31 +05:30
|
|
|
else:
|
|
|
|
self.translist[self.undoindex] = transaction
|
2006-01-13 06:27:01 +05:30
|
|
|
# Real commit erases all subsequent transactions
|
|
|
|
# to there's no Redo anymore.
|
2006-04-08 02:36:20 +05:30
|
|
|
for index in range(self.undoindex+1, _UNDO_SIZE):
|
2006-01-13 06:27:01 +05:30
|
|
|
self.translist[index] = None
|
2005-04-18 04:04:56 +05:30
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
person_add = self.do_commit(transaction.person_add, self.person_map)
|
|
|
|
family_add = self.do_commit(transaction.family_add, self.family_map)
|
|
|
|
source_add = self.do_commit(transaction.source_add, self.source_map)
|
|
|
|
place_add = self.do_commit(transaction.place_add, self.place_map)
|
|
|
|
media_add = self.do_commit(transaction.media_add, self.media_map)
|
|
|
|
event_add = self.do_commit(transaction.event_add, self.event_map)
|
|
|
|
repository_add = self.do_commit(transaction.repository_add,
|
|
|
|
self.repository_map)
|
|
|
|
|
|
|
|
note_add = self.do_commit(transaction.note_add, self.note_map)
|
|
|
|
person_upd = self.do_commit(transaction.person_update, self.person_map)
|
|
|
|
family_upd = self.do_commit(transaction.family_update, self.family_map)
|
|
|
|
source_upd = self.do_commit(transaction.source_update, self.source_map)
|
|
|
|
place_upd = self.do_commit(transaction.place_update, self.place_map)
|
|
|
|
media_upd = self.do_commit(transaction.media_update, self.media_map)
|
|
|
|
event_upd = self.do_commit(transaction.event_update, self.event_map)
|
|
|
|
repository_upd = self.do_commit(transaction.repository_update,
|
|
|
|
self.repository_map)
|
|
|
|
note_upd = self.do_commit(transaction.note_update, self.note_map)
|
2007-06-04 08:19:31 +05:30
|
|
|
|
|
|
|
self.__do_emit('person', person_add, person_upd, transaction.person_del)
|
|
|
|
self.__do_emit('family', family_add, family_upd, transaction.family_del)
|
|
|
|
self.__do_emit('event', event_add, event_upd, transaction.event_del)
|
|
|
|
self.__do_emit('source', source_add, source_upd, transaction.source_del)
|
|
|
|
self.__do_emit('place', place_add, place_upd, transaction.place_del)
|
|
|
|
self.__do_emit('media', media_add, media_upd, transaction.media_del)
|
|
|
|
self.__do_emit('repository', repository_add, repository_upd,
|
2006-01-07 02:25:49 +05:30
|
|
|
transaction.repository_del)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.__do_emit('note', note_add, note_upd, transaction.note_del)
|
2005-04-18 04:04:56 +05:30
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
self.__do_del(transaction.person_del, self.del_person)
|
|
|
|
self.__do_del(transaction.family_del, self.del_family)
|
|
|
|
self.__do_del(transaction.place_del, self.del_place)
|
|
|
|
self.__do_del(transaction.source_del, self.del_source)
|
|
|
|
self.__do_del(transaction.event_del, self.del_event)
|
|
|
|
self.__do_del(transaction.media_del, self.del_media)
|
|
|
|
self.__do_del(transaction.repository_del, self.del_repository)
|
|
|
|
self.__do_del(transaction.note_del, self.del_note)
|
2005-04-18 04:04:56 +05:30
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
if self.undo_callback:
|
|
|
|
self.undo_callback(_("_Undo %s") % transaction.get_description())
|
2006-01-13 06:31:19 +05:30
|
|
|
if self.redo_callback:
|
2006-01-13 06:27:01 +05:30
|
|
|
self.redo_callback(None)
|
2006-05-06 03:25:01 +05:30
|
|
|
if self.undo_history_callback:
|
|
|
|
self.undo_history_callback()
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def __do_emit(self, objtype, add_list, upd_list, del_list):
|
2005-04-18 04:04:56 +05:30
|
|
|
if add_list:
|
2006-04-08 02:36:20 +05:30
|
|
|
self.emit(objtype + '-add', (add_list, ))
|
2005-04-18 04:04:56 +05:30
|
|
|
if upd_list:
|
2006-04-08 02:36:20 +05:30
|
|
|
self.emit(objtype + '-update', (upd_list, ))
|
2005-04-18 04:04:56 +05:30
|
|
|
if del_list:
|
2006-04-08 02:36:20 +05:30
|
|
|
self.emit(objtype + '-delete', (del_list, ))
|
2005-04-18 04:04:56 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def __do_del(self, del_list, func):
|
2005-04-18 04:04:56 +05:30
|
|
|
for handle in del_list:
|
|
|
|
func(handle)
|
|
|
|
return del_list
|
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def do_commit(self, add_list, db_map):
|
2005-04-18 04:04:56 +05:30
|
|
|
retlist = []
|
2006-04-08 02:36:20 +05:30
|
|
|
for (handle, data) in add_list:
|
2005-04-18 04:04:56 +05:30
|
|
|
db_map[handle] = data
|
|
|
|
retlist.append(str(handle))
|
|
|
|
return retlist
|
|
|
|
|
2006-05-07 10:52:44 +05:30
|
|
|
def undo_available(self):
|
2007-06-04 08:19:31 +05:30
|
|
|
"""
|
|
|
|
returns boolean of whether or not there's a possibility of undo
|
|
|
|
"""
|
2006-05-07 10:52:44 +05:30
|
|
|
if self.undoindex == -1 or self.readonly:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
def redo_available(self):
|
2007-06-04 08:19:31 +05:30
|
|
|
"""
|
|
|
|
returns boolean of whether or not there's a possibility of redo
|
|
|
|
"""
|
2006-05-07 10:52:44 +05:30
|
|
|
if self.undoindex >= _UNDO_SIZE or self.readonly:
|
|
|
|
return False
|
|
|
|
|
|
|
|
if self.translist[self.undoindex+1] == None:
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def undo(self, update_history=True):
|
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.
|
|
|
|
"""
|
2006-05-07 10:52:44 +05:30
|
|
|
if not self.undo_available():
|
2004-10-13 09:21:27 +05:30
|
|
|
return False
|
2006-01-13 05:04:33 +05:30
|
|
|
|
2004-08-01 09:51:31 +05:30
|
|
|
transaction = self.translist[self.undoindex]
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
mapbase = (self.person_map, self.family_map, self.source_map,
|
2006-05-06 10:18:30 +05:30
|
|
|
self.event_map, self.media_map, self.place_map,
|
2008-01-01 03:27:54 +05:30
|
|
|
self.repository_map, {}, self.note_map)
|
2005-04-18 04:04:56 +05:30
|
|
|
|
2004-08-01 09:51:31 +05:30
|
|
|
self.undoindex -= 1
|
|
|
|
subitems = transaction.get_recnos()
|
|
|
|
subitems.reverse()
|
|
|
|
for record_id in subitems:
|
2007-06-04 08:19:31 +05:30
|
|
|
(key, handle, old_data, new_data) = transaction.get_record(record_id)
|
2006-01-13 03:32:58 +05:30
|
|
|
if key == REFERENCE_KEY:
|
2006-04-08 02:36:20 +05:30
|
|
|
self.undo_reference(old_data, handle)
|
2006-01-13 03:32:58 +05:30
|
|
|
else:
|
2007-06-14 11:09:03 +05:30
|
|
|
self.undo_data(old_data, handle, mapbase[key], _SIGBASE[key])
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
if self.undo_callback:
|
2006-05-07 10:52:44 +05:30
|
|
|
if self.undo_available():
|
2006-01-13 05:04:33 +05:30
|
|
|
new_transaction = self.translist[self.undoindex]
|
|
|
|
self.undo_callback(_("_Undo %s")
|
|
|
|
% new_transaction.get_description())
|
2006-01-13 06:27:01 +05:30
|
|
|
else:
|
2006-05-07 10:52:44 +05:30
|
|
|
self.undo_callback(None)
|
|
|
|
|
|
|
|
if self.redo_callback:
|
|
|
|
if self. redo_available():
|
2006-01-13 06:27:01 +05:30
|
|
|
self.redo_callback(_("_Redo %s")
|
|
|
|
% transaction.get_description())
|
2006-05-07 10:52:44 +05:30
|
|
|
else:
|
|
|
|
self.redo_callback(None)
|
2006-01-13 05:04:33 +05:30
|
|
|
|
2006-05-06 03:25:01 +05:30
|
|
|
if update_history and self.undo_history_callback:
|
|
|
|
self.undo_history_callback()
|
2006-01-13 05:04:33 +05:30
|
|
|
return True
|
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def redo(self, update_history=True):
|
2006-01-13 05:04:33 +05:30
|
|
|
"""
|
|
|
|
Accesses the last undone transaction, and reverts the data to
|
|
|
|
the state before the transaction was undone.
|
|
|
|
"""
|
|
|
|
|
2006-05-07 10:52:44 +05:30
|
|
|
if not self.redo_available():
|
2006-01-13 05:04:33 +05:30
|
|
|
return False
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
self.undoindex += 1
|
2006-05-07 10:52:44 +05:30
|
|
|
transaction = self.translist[self.undoindex]
|
2006-04-08 02:36:20 +05:30
|
|
|
mapbase = (self.person_map, self.family_map, self.source_map,
|
2006-05-06 10:18:30 +05:30
|
|
|
self.event_map, self.media_map, self.place_map,
|
2008-01-01 03:27:54 +05:30
|
|
|
self.repository_map, {}, self.note_map)
|
2006-01-13 05:04:33 +05:30
|
|
|
|
|
|
|
subitems = transaction.get_recnos()
|
|
|
|
for record_id in subitems:
|
2007-06-04 08:19:31 +05:30
|
|
|
(key, handle, old_data, new_data) = transaction.get_record(record_id)
|
2006-01-13 05:04:33 +05:30
|
|
|
if key == REFERENCE_KEY:
|
2006-04-08 02:36:20 +05:30
|
|
|
self.undo_reference(new_data, handle)
|
2006-01-13 05:04:33 +05:30
|
|
|
else:
|
2007-06-14 11:09:03 +05:30
|
|
|
self.undo_data(new_data, handle, mapbase[key], _SIGBASE[key])
|
2006-01-13 05:04:33 +05:30
|
|
|
|
2006-01-13 06:27:01 +05:30
|
|
|
if self.undo_callback:
|
2006-05-07 10:52:44 +05:30
|
|
|
if self.undo_available():
|
2006-01-13 06:27:01 +05:30
|
|
|
self.undo_callback(_("_Undo %s")
|
|
|
|
% transaction.get_description())
|
|
|
|
else:
|
2006-05-07 10:52:44 +05:30
|
|
|
self.undo_callback(None)
|
|
|
|
|
|
|
|
if self.redo_callback:
|
|
|
|
if self.redo_available():
|
2006-01-13 06:27:01 +05:30
|
|
|
new_transaction = self.translist[self.undoindex+1]
|
|
|
|
self.redo_callback(_("_Redo %s")
|
|
|
|
% new_transaction.get_description())
|
2006-01-13 05:04:33 +05:30
|
|
|
else:
|
2006-05-07 10:52:44 +05:30
|
|
|
self.redo_callback(None)
|
2006-01-13 05:04:33 +05:30
|
|
|
|
2006-05-06 03:25:01 +05:30
|
|
|
if update_history and self.undo_history_callback:
|
|
|
|
self.undo_history_callback()
|
2004-10-13 09:21:27 +05:30
|
|
|
return True
|
2005-04-09 06:01:39 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def undo_reference(self, data, handle):
|
2006-01-13 03:32:58 +05:30
|
|
|
pass
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def undo_data(self, data, handle, db_map, signal_root):
|
2005-04-09 06:01:39 +05:30
|
|
|
if data == None:
|
2006-04-08 02:36:20 +05:30
|
|
|
self.emit(signal_root + '-delete', ([handle], ))
|
2005-04-09 06:01:39 +05:30
|
|
|
del db_map[handle]
|
|
|
|
else:
|
|
|
|
if db_map.has_key(handle):
|
|
|
|
signal = signal_root + '-update'
|
|
|
|
else:
|
|
|
|
signal = signal_root + '-add'
|
|
|
|
db_map[handle] = data
|
2006-04-08 02:36:20 +05:30
|
|
|
self.emit(signal, ([handle], ))
|
2004-10-13 09:21:27 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def set_undo_callback(self, callback):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
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
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def set_redo_callback(self, callback):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
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):
|
|
|
|
"""
|
2007-01-19 22:23:49 +05:30
|
|
|
Returns the list of locale-sorted surnames contained in the database.
|
|
|
|
"""
|
|
|
|
return self.surname_list
|
|
|
|
|
|
|
|
def build_surname_list(self):
|
|
|
|
"""
|
|
|
|
Builds the list of locale-sorted surnames contained in the database.
|
|
|
|
The function must be overridden in the derived class.
|
|
|
|
"""
|
2007-05-07 09:09:46 +05:30
|
|
|
raise NotImplementedError
|
2007-01-19 22:23:49 +05:30
|
|
|
|
|
|
|
def sort_surname_list(self):
|
2007-06-04 08:19:31 +05:30
|
|
|
vals = [(locale.strxfrm(item), item) for item in self.surname_list]
|
2007-01-19 22:23:49 +05:30
|
|
|
vals.sort()
|
|
|
|
self.surname_list = [item[1] for item in vals]
|
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def add_to_surname_list(self, person, batch_transaction):
|
2007-01-19 22:23:49 +05:30
|
|
|
if batch_transaction:
|
|
|
|
return
|
|
|
|
name = unicode(person.get_primary_name().get_surname())
|
|
|
|
if name not in self.surname_list:
|
|
|
|
self.surname_list.append(name)
|
|
|
|
self.sort_surname_list()
|
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def remove_from_surname_list(self, person):
|
2007-01-19 22:23:49 +05:30
|
|
|
"""
|
|
|
|
Check whether there are persons with the same surname left in
|
|
|
|
the database. If not then we need to remove the name from the list.
|
2004-08-13 10:04:07 +05:30
|
|
|
The function must be overridden in the derived class.
|
|
|
|
"""
|
2007-05-07 09:09:46 +05:30
|
|
|
raise NotImplementedError
|
2004-08-13 10:04:07 +05:30
|
|
|
|
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
|
|
|
|
|
2006-04-27 03:18:13 +05:30
|
|
|
def get_family_bookmarks(self):
|
|
|
|
"""returns the list of Person handles in the bookmarks"""
|
|
|
|
return self.family_bookmarks
|
|
|
|
|
|
|
|
def get_event_bookmarks(self):
|
|
|
|
"""returns the list of Person handles in the bookmarks"""
|
|
|
|
return self.event_bookmarks
|
|
|
|
|
|
|
|
def get_place_bookmarks(self):
|
|
|
|
"""returns the list of Person handles in the bookmarks"""
|
|
|
|
return self.place_bookmarks
|
|
|
|
|
|
|
|
def get_source_bookmarks(self):
|
|
|
|
"""returns the list of Person handles in the bookmarks"""
|
|
|
|
return self.source_bookmarks
|
|
|
|
|
|
|
|
def get_media_bookmarks(self):
|
|
|
|
"""returns the list of Person handles in the bookmarks"""
|
|
|
|
return self.media_bookmarks
|
|
|
|
|
|
|
|
def get_repo_bookmarks(self):
|
|
|
|
"""returns the list of Person handles in the bookmarks"""
|
|
|
|
return self.repo_bookmarks
|
|
|
|
|
2007-02-20 06:09:10 +05:30
|
|
|
def get_note_bookmarks(self):
|
|
|
|
"""returns the list of Note handles in the bookmarks"""
|
|
|
|
return self.note_bookmarks
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def set_researcher(self, owner):
|
2004-08-01 09:51:31 +05:30
|
|
|
"""sets the information about the owner of the database"""
|
2007-10-09 00:00:10 +05:30
|
|
|
self.owner.set_from(owner)
|
2004-08-01 09:51:31 +05:30
|
|
|
|
|
|
|
def get_researcher(self):
|
|
|
|
"""returns the Researcher instance, providing information about
|
|
|
|
the owner of the database"""
|
|
|
|
return self.owner
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def set_default_person_handle(self, handle):
|
2004-08-01 09:51:31 +05:30
|
|
|
"""sets the default Person to the passed instance"""
|
2006-12-14 12:08:07 +05:30
|
|
|
if (self.metadata != None) and (not self.readonly):
|
2005-04-18 04:04:56 +05:30
|
|
|
self.metadata['default'] = str(handle)
|
2004-08-01 09:51:31 +05:30
|
|
|
|
|
|
|
def get_default_person(self):
|
|
|
|
"""returns the default Person of the database"""
|
2006-05-09 10:03:21 +05:30
|
|
|
person = self.get_person_from_handle(self.get_default_handle())
|
|
|
|
if person:
|
|
|
|
return person
|
2006-12-14 12:08:07 +05:30
|
|
|
elif (self.metadata != None) and (not self.readonly):
|
2006-05-09 10:03:21 +05:30
|
|
|
self.metadata['default'] = None
|
2004-08-01 09:51:31 +05:30
|
|
|
return None
|
|
|
|
|
2006-05-09 09:45:04 +05:30
|
|
|
def get_default_handle(self):
|
|
|
|
"""returns the default Person of the database"""
|
2006-12-14 12:08:07 +05:30
|
|
|
if self.metadata != None:
|
2006-05-09 09:45:04 +05:30
|
|
|
return self.metadata.get('default')
|
|
|
|
return None
|
|
|
|
|
2004-08-01 09:51:31 +05:30
|
|
|
def get_save_path(self):
|
|
|
|
"""returns the save path of the file, or "" if one does not exist"""
|
|
|
|
return self.path
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def set_save_path(self, path):
|
2004-08-01 09:51:31 +05:30
|
|
|
"""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"""
|
2005-08-18 11:28:28 +05:30
|
|
|
return list(self.individual_event_names)
|
2004-08-01 09:51:31 +05:30
|
|
|
|
|
|
|
def get_person_attribute_types(self):
|
|
|
|
"""returns a list of all Attribute types assocated with Person
|
|
|
|
instances in the database"""
|
2005-08-18 11:28:28 +05:30
|
|
|
return list(self.individual_attributes)
|
2004-08-01 09:51:31 +05:30
|
|
|
|
|
|
|
def get_family_attribute_types(self):
|
|
|
|
"""returns a list of all Attribute types assocated with Family
|
|
|
|
instances in the database"""
|
2005-08-18 11:28:28 +05:30
|
|
|
return list(self.family_attributes)
|
2004-08-01 09:51:31 +05:30
|
|
|
|
|
|
|
def get_family_event_types(self):
|
|
|
|
"""returns a list of all Event types assocated with Family
|
|
|
|
instances in the database"""
|
2005-08-18 11:28:28 +05:30
|
|
|
return list(self.family_event_names)
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_marker_types(self):
|
2005-09-16 20:55:27 +05:30
|
|
|
"""return a list of all marker types available in the database"""
|
|
|
|
return list(self.marker_names)
|
|
|
|
|
2004-08-01 09:51:31 +05:30
|
|
|
def get_media_attribute_types(self):
|
|
|
|
"""returns a list of all Attribute types assocated with Media
|
2006-05-20 01:18:36 +05:30
|
|
|
and MediaRef instances in the database"""
|
|
|
|
return list(self.media_attributes)
|
2004-08-01 09:51:31 +05:30
|
|
|
|
|
|
|
def get_family_relation_types(self):
|
|
|
|
"""returns a list of all relationship types assocated with Family
|
|
|
|
instances in the database"""
|
2006-05-19 23:02:23 +05:30
|
|
|
return list(self.family_rel_types)
|
|
|
|
|
|
|
|
def get_child_reference_types(self):
|
|
|
|
"""returns a list of all child reference types assocated with Family
|
|
|
|
instances in the database"""
|
|
|
|
return list(self.child_ref_types)
|
|
|
|
|
|
|
|
def get_event_roles(self):
|
|
|
|
"""returns a list of all custom event role names assocated with Event
|
|
|
|
instances in the database"""
|
|
|
|
return list(self.event_role_names)
|
|
|
|
|
|
|
|
def get_name_types(self):
|
|
|
|
"""returns a list of all custom names types assocated with Person
|
|
|
|
instances in the database"""
|
|
|
|
return list(self.name_types)
|
|
|
|
|
|
|
|
def get_repository_types(self):
|
|
|
|
"""returns a list of all custom repository types assocated with
|
|
|
|
Repository instances in the database"""
|
|
|
|
return list(self.repository_types)
|
|
|
|
|
2007-02-20 06:09:10 +05:30
|
|
|
def get_note_types(self):
|
|
|
|
"""returns a list of all custom note types assocated with
|
|
|
|
Note instances in the database"""
|
|
|
|
return list(self.note_types)
|
|
|
|
|
2006-05-19 23:02:23 +05:30
|
|
|
def get_source_media_types(self):
|
|
|
|
"""returns a list of all custom source media types assocated with
|
|
|
|
Source instances in the database"""
|
|
|
|
return list(self.source_media_types)
|
|
|
|
|
|
|
|
def get_url_types(self):
|
|
|
|
"""returns a list of all custom names types assocated with Url
|
|
|
|
instances in the database"""
|
|
|
|
return list(self.url_types)
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def remove_person(self, handle, transaction):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
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.
|
|
|
|
"""
|
2005-12-16 17:29:13 +05:30
|
|
|
|
2006-08-30 10:40:50 +05:30
|
|
|
if self.readonly or not handle:
|
|
|
|
return
|
2007-06-26 11:32:17 +05:30
|
|
|
self.delete_primary_from_reference_map(handle, transaction)
|
2006-08-30 10:40:50 +05:30
|
|
|
person = self.get_person_from_handle(handle)
|
|
|
|
self.genderStats.uncount_person (person)
|
2007-01-19 22:23:49 +05:30
|
|
|
self.remove_from_surname_list(person)
|
2006-08-30 10:40:50 +05:30
|
|
|
if transaction.batch:
|
2007-06-26 11:32:17 +05:30
|
|
|
self.del_person(handle)
|
2006-08-30 10:40:50 +05:30
|
|
|
else:
|
|
|
|
transaction.add(PERSON_KEY, handle, person.serialize(), None)
|
2005-04-18 04:04:56 +05:30
|
|
|
transaction.person_del.append(str(handle))
|
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def get_del_func(self, key):
|
2006-08-30 10:40:50 +05:30
|
|
|
key2del = {
|
2007-06-26 11:32:17 +05:30
|
|
|
PERSON_KEY: self.del_person,
|
|
|
|
FAMILY_KEY: self.del_family,
|
|
|
|
SOURCE_KEY: self.del_source,
|
|
|
|
EVENT_KEY: self.del_event,
|
|
|
|
MEDIA_KEY: self.del_media,
|
|
|
|
PLACE_KEY: self.del_place,
|
|
|
|
REPOSITORY_KEY: self.del_repository,
|
|
|
|
NOTE_KEY: self.del_note,
|
2006-08-30 10:40:50 +05:30
|
|
|
}
|
|
|
|
return key2del[key]
|
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def do_remove_object(self, handle, trans, dmap, key, del_list):
|
2006-08-30 10:40:50 +05:30
|
|
|
if self.readonly or not handle:
|
|
|
|
return
|
|
|
|
|
|
|
|
handle = str(handle)
|
2007-06-26 11:32:17 +05:30
|
|
|
self.delete_primary_from_reference_map(handle, trans)
|
2006-08-30 10:40:50 +05:30
|
|
|
if trans.batch:
|
|
|
|
del_func = self.get_del_func(key)
|
|
|
|
del_func(handle)
|
|
|
|
else:
|
|
|
|
old_data = dmap.get(handle)
|
|
|
|
trans.add(key, handle, old_data, None)
|
2005-04-18 04:04:56 +05:30
|
|
|
del_list.append(handle)
|
2004-08-13 10:04:07 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def remove_source(self, handle, transaction):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
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.
|
|
|
|
"""
|
2007-06-26 11:32:17 +05:30
|
|
|
self.do_remove_object(handle, transaction, self.source_map,
|
|
|
|
SOURCE_KEY, transaction.source_del)
|
2004-08-13 10:04:07 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def remove_event(self, handle, transaction):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
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.
|
|
|
|
"""
|
2007-06-26 11:32:17 +05:30
|
|
|
self.do_remove_object(handle, transaction, self.event_map,
|
|
|
|
EVENT_KEY, transaction.event_del)
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def remove_object(self, handle, transaction):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
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.
|
|
|
|
"""
|
2007-06-26 11:32:17 +05:30
|
|
|
self.do_remove_object(handle, transaction, self.media_map,
|
|
|
|
MEDIA_KEY, transaction.media_del)
|
2004-08-11 09:12:38 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def remove_place(self, handle, transaction):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
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.
|
|
|
|
"""
|
2007-06-26 11:32:17 +05:30
|
|
|
self.do_remove_object(handle, transaction, self.place_map,
|
|
|
|
PLACE_KEY, transaction.place_del)
|
2004-08-13 10:04:07 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def remove_family(self, handle, transaction):
|
2004-12-03 07:19:09 +05:30
|
|
|
"""
|
|
|
|
Removes the Family specified by the database handle from the
|
|
|
|
database, preserving the change in the passed transaction. This
|
|
|
|
method must be overridden in the derived class.
|
|
|
|
"""
|
2007-06-26 11:32:17 +05:30
|
|
|
self.do_remove_object(handle, transaction, self.family_map,
|
|
|
|
FAMILY_KEY, transaction.family_del)
|
2004-12-03 07:19:09 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def remove_repository(self, handle, transaction):
|
2005-05-27 23:13:04 +05:30
|
|
|
"""
|
|
|
|
Removes the Repository specified by the database handle from the
|
|
|
|
database, preserving the change in the passed transaction. This
|
|
|
|
method must be overridden in the derived class.
|
|
|
|
"""
|
2007-06-26 11:32:17 +05:30
|
|
|
self.do_remove_object(handle, transaction, self.repository_map,
|
|
|
|
REPOSITORY_KEY, transaction.repository_del)
|
2005-05-27 23:13:04 +05:30
|
|
|
|
2007-02-20 06:09:10 +05:30
|
|
|
def remove_note(self, handle, transaction):
|
|
|
|
"""
|
|
|
|
Removes the Note specified by the database handle from the
|
|
|
|
database, preserving the change in the passed transaction. This
|
|
|
|
method must be overridden in the derived class.
|
|
|
|
"""
|
2007-06-26 11:32:17 +05:30
|
|
|
self.do_remove_object(handle, transaction, self.note_map,
|
|
|
|
NOTE_KEY, transaction.note_del)
|
2007-02-20 06:09:10 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_raw_person_data(self, handle):
|
2006-01-07 03:38:40 +05:30
|
|
|
return self.person_map.get(str(handle))
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_raw_family_data(self, handle):
|
2006-01-07 03:38:40 +05:30
|
|
|
return self.family_map.get(str(handle))
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_raw_object_data(self, handle):
|
2006-01-07 03:38:40 +05:30
|
|
|
return self.media_map.get(str(handle))
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_raw_place_data(self, handle):
|
2006-01-07 03:38:40 +05:30
|
|
|
return self.place_map.get(str(handle))
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_raw_event_data(self, handle):
|
2006-01-07 03:38:40 +05:30
|
|
|
return self.event_map.get(str(handle))
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_raw_source_data(self, handle):
|
2006-01-07 03:38:40 +05:30
|
|
|
return self.source_map.get(str(handle))
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_raw_repository_data(self, handle):
|
2006-01-07 03:38:40 +05:30
|
|
|
return self.repository_map.get(str(handle))
|
|
|
|
|
2007-02-20 06:09:10 +05:30
|
|
|
def get_raw_note_data(self, handle):
|
|
|
|
return self.note_map.get(str(handle))
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def has_person_handle(self, handle):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
returns True if the handle exists in the current Person database.
|
|
|
|
"""
|
|
|
|
return self.person_map.has_key(str(handle))
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def has_event_handle(self, handle):
|
2006-01-07 03:38:40 +05:30
|
|
|
"""
|
|
|
|
returns True if the handle exists in the current Event database.
|
|
|
|
"""
|
|
|
|
return self.event_map.has_key(str(handle))
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def has_source_handle(self, handle):
|
2006-01-07 03:38:40 +05:30
|
|
|
"""
|
|
|
|
returns True if the handle exists in the current Source database.
|
|
|
|
"""
|
|
|
|
return self.source_map.has_key(str(handle))
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def has_place_handle(self, handle):
|
2006-01-07 03:38:40 +05:30
|
|
|
"""
|
|
|
|
returns True if the handle exists in the current Place database.
|
|
|
|
"""
|
|
|
|
return self.place_map.has_key(str(handle))
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def has_family_handle(self, handle):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
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
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def has_object_handle(self, handle):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
returns True if the handle exists in the current MediaObjectdatabase.
|
|
|
|
"""
|
2006-10-10 09:57:13 +05:30
|
|
|
return self.media_map.has_key(str(handle))
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def has_repository_handle(self, handle):
|
2005-05-27 23:13:04 +05:30
|
|
|
"""
|
|
|
|
returns True if the handle exists in the current Repository database.
|
|
|
|
"""
|
2006-05-18 08:44:55 +05:30
|
|
|
return self.repository_map.has_key(str(handle))
|
2005-05-27 23:13:04 +05:30
|
|
|
|
2007-02-20 06:09:10 +05:30
|
|
|
def has_note_handle(self, handle):
|
|
|
|
"""
|
|
|
|
returns True if the handle exists in the current Note database.
|
|
|
|
"""
|
|
|
|
return self.note_map.has_key(str(handle))
|
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def __sortbyplace(self, first, second):
|
2006-04-08 02:36:20 +05:30
|
|
|
return locale.strcoll(self.place_map.get(str(first))[2],
|
|
|
|
self.place_map.get(str(second))[2])
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def __sortbysource(self, first, second):
|
2006-04-08 02:36:20 +05:30
|
|
|
source1 = unicode(self.source_map[str(first)][2])
|
|
|
|
source2 = unicode(self.source_map[str(second)][2])
|
|
|
|
return locale.strcoll(source1, source2)
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def __sortbymedia(self, first, second):
|
2006-04-08 02:36:20 +05:30
|
|
|
media1 = self.media_map[str(first)][4]
|
|
|
|
media2 = self.media_map[str(second)][4]
|
|
|
|
return locale.strcoll(media1, media2)
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2007-12-01 05:20:05 +05:30
|
|
|
def set_mediapath(self, path):
|
|
|
|
"""sets the default media path for database, path should be utf-8"""
|
|
|
|
if (self.metadata != None) and (not self.readonly):
|
|
|
|
self.metadata['mediapath'] = path
|
|
|
|
|
|
|
|
def get_mediapath(self):
|
|
|
|
"""returns the default media path of the database"""
|
|
|
|
if self.metadata != None:
|
|
|
|
return self.metadata.get('mediapath', None)
|
|
|
|
return None
|
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def set_column_order(self, col_list, name):
|
2006-12-14 12:08:07 +05:30
|
|
|
if (self.metadata != None) and (not self.readonly):
|
2005-04-18 04:04:56 +05:30
|
|
|
self.metadata[name] = col_list
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def set_person_column_order(self, col_list):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Stores the Person display common information in the
|
|
|
|
database's metadata.
|
|
|
|
"""
|
2007-07-08 08:57:06 +05:30
|
|
|
self.set_column_order(col_list, PERSON_COL_KEY)
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def set_family_list_column_order(self, col_list):
|
2006-01-08 11:14:19 +05:30
|
|
|
"""
|
|
|
|
Stores the Person display common information in the
|
|
|
|
database's metadata.
|
|
|
|
"""
|
2007-07-08 08:57:06 +05:30
|
|
|
self.set_column_order(col_list, FAMILY_COL_KEY)
|
2006-01-08 11:14:19 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def set_child_column_order(self, col_list):
|
2004-11-19 01:51:06 +05:30
|
|
|
"""
|
|
|
|
Stores the Person display common information in the
|
|
|
|
database's metadata.
|
|
|
|
"""
|
2007-07-08 08:57:06 +05:30
|
|
|
self.set_column_order(col_list, CHILD_COL_KEY)
|
2004-11-19 01:51:06 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def set_place_column_order(self, col_list):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Stores the Place display common information in the
|
|
|
|
database's metadata.
|
|
|
|
"""
|
2007-07-08 08:57:06 +05:30
|
|
|
self.set_column_order(col_list, PLACE_COL_KEY)
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def set_source_column_order(self, col_list):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Stores the Source display common information in the
|
|
|
|
database's metadata.
|
|
|
|
"""
|
2007-07-08 08:57:06 +05:30
|
|
|
self.set_column_order(col_list, SOURCE_COL_KEY)
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def set_media_column_order(self, col_list):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
Stores the Media display common information in the
|
|
|
|
database's metadata.
|
|
|
|
"""
|
2007-07-08 08:57:06 +05:30
|
|
|
self.set_column_order(col_list, MEDIA_COL_KEY)
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def set_event_column_order(self, col_list):
|
2005-06-08 21:05:31 +05:30
|
|
|
"""
|
|
|
|
Stores the Event display common information in the
|
|
|
|
database's metadata.
|
|
|
|
"""
|
2007-07-08 08:57:06 +05:30
|
|
|
self.set_column_order(col_list, EVENT_COL_KEY)
|
2005-06-08 21:05:31 +05:30
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def set_repository_column_order(self, col_list):
|
2005-05-27 23:13:04 +05:30
|
|
|
"""
|
|
|
|
Stores the Repository display common information in the
|
|
|
|
database's metadata.
|
|
|
|
"""
|
2007-07-08 08:57:06 +05:30
|
|
|
self.set_column_order(col_list, REPOSITORY_COL_KEY)
|
2005-05-27 23:13:04 +05:30
|
|
|
|
2007-02-20 06:09:10 +05:30
|
|
|
def set_note_column_order(self, col_list):
|
|
|
|
"""
|
|
|
|
Stores the Note display common information in the
|
|
|
|
database's metadata.
|
|
|
|
"""
|
2007-07-08 08:57:06 +05:30
|
|
|
self.set_column_order(col_list, NOTE_COL_KEY)
|
2007-02-20 06:09:10 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def __get_column_order(self, name, default):
|
2004-08-01 09:51:31 +05:30
|
|
|
if self.metadata == None:
|
|
|
|
return default
|
|
|
|
else:
|
2006-04-08 02:36:20 +05:30
|
|
|
cols = self.metadata.get(name, default)
|
2004-08-01 09:51:31 +05:30
|
|
|
if len(cols) != len(default):
|
|
|
|
return cols + default[len(cols):]
|
|
|
|
else:
|
|
|
|
return cols
|
|
|
|
|
2005-04-18 04:04:56 +05:30
|
|
|
def get_person_column_order(self):
|
|
|
|
"""
|
|
|
|
Returns the Person display common information stored in the
|
|
|
|
database's metadata.
|
|
|
|
"""
|
2006-04-08 02:36:20 +05:30
|
|
|
default = [(1, 1, 100), (1, 2, 100), (1, 3, 150), (0, 4, 150),
|
|
|
|
(1, 5, 150), (0, 6, 150), (0, 7, 100), (0, 8, 100),
|
2006-08-21 12:02:31 +05:30
|
|
|
]
|
2007-06-04 08:19:31 +05:30
|
|
|
return self.__get_column_order(PERSON_COL_KEY, default)
|
2005-04-18 04:04:56 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def __get_columns(self, key, default):
|
|
|
|
values = self.__get_column_order(key, default)
|
2006-01-20 23:48:03 +05:30
|
|
|
new = []
|
|
|
|
for val in values:
|
|
|
|
if len(val) == 2:
|
|
|
|
for x in default:
|
|
|
|
if val[1] == x[1]:
|
2006-04-08 02:36:20 +05:30
|
|
|
new.append((val[0], val[1], x[2]))
|
2006-01-20 23:48:03 +05:30
|
|
|
break
|
|
|
|
else:
|
|
|
|
new.append(val)
|
|
|
|
return new
|
|
|
|
|
2006-01-08 11:14:19 +05:30
|
|
|
def get_family_list_column_order(self):
|
|
|
|
"""
|
|
|
|
Returns the Person display common information stored in the
|
|
|
|
database's metadata.
|
|
|
|
"""
|
2006-04-08 02:36:20 +05:30
|
|
|
default = [(1, 0, 75), (1, 1, 200), (1, 2, 200), (1, 3, 100),
|
|
|
|
(0, 4, 100)]
|
2007-06-04 08:19:31 +05:30
|
|
|
return self.__get_columns(FAMILY_COL_KEY, default)
|
2006-01-08 11:14:19 +05:30
|
|
|
|
2004-11-19 01:51:06 +05:30
|
|
|
def get_child_column_order(self):
|
|
|
|
"""
|
|
|
|
Returns the Person display common information stored in the
|
|
|
|
database's metadata.
|
|
|
|
"""
|
2006-04-08 02:36:20 +05:30
|
|
|
default = [(1, 0), (1, 1), (1, 2), (1, 3), (1, 4), (1, 5),
|
|
|
|
(0, 6), (0, 7)]
|
2007-06-04 08:19:31 +05:30
|
|
|
return self.__get_column_order(CHILD_COL_KEY, default)
|
2004-11-19 01:51:06 +05:30
|
|
|
|
2004-08-01 09:51:31 +05:30
|
|
|
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.
|
|
|
|
"""
|
2006-09-29 09:43:10 +05:30
|
|
|
default = [(1, 0, 250), (1, 1, 75), (1, 11, 100), (0, 3, 100),
|
|
|
|
(1, 4, 100, ), (0, 5, 150), (1, 6, 150), (0, 7, 150),
|
|
|
|
(0, 8, 150), (0, 9, 150), (0, 10, 150),(0,2,100)]
|
2007-06-04 08:19:31 +05:30
|
|
|
return self.__get_columns(PLACE_COL_KEY, default)
|
2004-08-01 09:51:31 +05:30
|
|
|
|
|
|
|
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.
|
|
|
|
"""
|
2006-04-08 02:36:20 +05:30
|
|
|
default = [(1, 0, 200), (1, 1, 75), (1, 2, 150), (0, 3, 100),
|
|
|
|
(1, 4, 150), (0, 5, 100)]
|
2007-06-04 08:19:31 +05:30
|
|
|
return self.__get_columns(SOURCE_COL_KEY, default)
|
2004-08-01 09:51:31 +05:30
|
|
|
|
|
|
|
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.
|
|
|
|
"""
|
2006-04-08 02:36:20 +05:30
|
|
|
default = [(1, 0, 200, ), (1, 1, 75), (1, 2, 100), (1, 3, 200),
|
|
|
|
(1, 5, 150), (0, 4, 150)]
|
2007-06-04 08:19:31 +05:30
|
|
|
return self.__get_columns(MEDIA_COL_KEY, default)
|
2004-10-23 09:26:48 +05:30
|
|
|
|
2005-06-07 10:38:50 +05:30
|
|
|
def get_event_column_order(self):
|
|
|
|
"""
|
|
|
|
Returns the Event display common information stored in the
|
|
|
|
database's metadata.
|
|
|
|
"""
|
2006-04-08 02:36:20 +05:30
|
|
|
default = [(1, 0, 200), (1, 1, 75), (1, 2, 100), (1, 3, 150),
|
2006-08-21 12:02:31 +05:30
|
|
|
(1, 4, 200), (0, 5, 100)]
|
2007-06-04 08:19:31 +05:30
|
|
|
return self.__get_columns(EVENT_COL_KEY, default)
|
2005-06-07 10:38:50 +05:30
|
|
|
|
2005-05-27 23:13:04 +05:30
|
|
|
def get_repository_column_order(self):
|
|
|
|
"""
|
|
|
|
Returns the Repository display common information stored in the
|
|
|
|
database's metadata.
|
|
|
|
"""
|
2006-04-08 02:36:20 +05:30
|
|
|
default = [(1, 0, 200), (1, 1, 75), (0, 5, 100), (0, 6, 100),
|
|
|
|
(1, 2, 100), (1, 3, 250), (1, 4, 100), (0, 7, 100),
|
2007-11-29 19:32:22 +05:30
|
|
|
(0, 8, 100), (0, 9, 100), (0, 10, 100), (0, 12, 100)]
|
2007-06-04 08:19:31 +05:30
|
|
|
return self.__get_columns(REPOSITORY_COL_KEY, default)
|
2005-05-27 23:13:04 +05:30
|
|
|
|
2007-02-20 06:09:10 +05:30
|
|
|
def get_note_column_order(self):
|
|
|
|
"""
|
|
|
|
Returns the Note display common information stored in the
|
|
|
|
database's metadata.
|
|
|
|
"""
|
2008-01-10 02:45:28 +05:30
|
|
|
default = [(1, 0, 350), (1, 1, 75), (1, 2, 100), (1, 3, 100)]
|
2007-06-04 08:19:31 +05:30
|
|
|
return self.__get_columns(NOTE_COL_KEY, default)
|
2007-02-20 06:09:10 +05:30
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def delete_primary_from_reference_map(self, handle, transaction):
|
2006-01-13 03:32:58 +05:30
|
|
|
"""Called each time an object is removed from the database. This can
|
|
|
|
be used by subclasses to update any additional index tables that might
|
|
|
|
need to be changed."""
|
|
|
|
pass
|
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def update_reference_map(self, obj, transaction):
|
2005-12-15 23:02:10 +05:30
|
|
|
"""Called each time an object is writen to the database. This can
|
|
|
|
be used by subclasses to update any additional index tables that might
|
|
|
|
need to be changed."""
|
|
|
|
pass
|
2005-12-15 17:33:24 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def reindex_reference_map(self, callback):
|
2006-12-01 13:53:51 +05:30
|
|
|
"""
|
|
|
|
Reindex all primary records in the database.
|
|
|
|
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2005-12-15 17:33:24 +05:30
|
|
|
def find_backlink_handles(self, handle, include_classes=None):
|
|
|
|
"""
|
|
|
|
Find all objects that hold a reference to the object handle.
|
2006-04-08 02:36:20 +05:30
|
|
|
Returns an interator over alist of (class_name, handle) tuples.
|
2005-12-15 17:33:24 +05:30
|
|
|
|
|
|
|
@param handle: handle of the object to search for.
|
|
|
|
@type handle: database handle
|
|
|
|
@param include_classes: list of class names to include in the results.
|
|
|
|
Default: None means include all classes.
|
|
|
|
@type include_classes: list of class names
|
|
|
|
|
|
|
|
This default implementation does a sequencial scan through all
|
|
|
|
the primary object databases and is very slow. Backends can
|
|
|
|
override this method to provide much faster implementations that
|
|
|
|
make use of additional capabilities of the backend.
|
|
|
|
|
|
|
|
Note that this is a generator function, it returns a iterator for
|
|
|
|
use in loops. If you want a list of the results use:
|
|
|
|
|
2006-10-29 10:06:08 +05:30
|
|
|
> result_list = [i for i in find_backlink_handles(handle)]
|
2005-12-15 17:33:24 +05:30
|
|
|
"""
|
|
|
|
|
|
|
|
# Make a dictionary of the functions and classes that we need for
|
|
|
|
# each of the primary object tables.
|
2006-04-08 02:36:20 +05:30
|
|
|
primary_tables = {
|
|
|
|
'Person': {'cursor_func': self.get_person_cursor,
|
|
|
|
'class_func': Person},
|
|
|
|
'Family': {'cursor_func': self.get_family_cursor,
|
|
|
|
'class_func': Family},
|
|
|
|
'Event': {'cursor_func': self.get_event_cursor,
|
|
|
|
'class_func': Event},
|
|
|
|
'Place': {'cursor_func': self.get_place_cursor,
|
|
|
|
'class_func': Place},
|
|
|
|
'Source': {'cursor_func': self.get_source_cursor,
|
|
|
|
'class_func': Source},
|
|
|
|
'MediaObject': {'cursor_func': self.get_media_cursor,
|
|
|
|
'class_func': MediaObject},
|
|
|
|
'Repository': {'cursor_func': self.get_repository_cursor,
|
2007-02-20 06:09:10 +05:30
|
|
|
'class_func': Repository},
|
|
|
|
'Note': {'cursor_func': self.get_note_cursor,
|
|
|
|
'class_func': Note},
|
2006-04-08 02:36:20 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-25 22:34:37 +05:30
|
|
|
# Find which tables to iterate over
|
|
|
|
if (include_classes == None):
|
|
|
|
the_tables = primary_tables.keys()
|
|
|
|
else:
|
|
|
|
the_tables = include_classes
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
# Now we use the functions and classes defined above to loop through
|
2006-05-02 04:38:09 +05:30
|
|
|
# each of the existing primary object tables
|
2007-01-25 22:34:37 +05:30
|
|
|
for primary_table_name in the_tables:
|
2006-05-02 04:38:09 +05:30
|
|
|
cursor = primary_tables[primary_table_name]['cursor_func']()
|
|
|
|
data = cursor.first()
|
|
|
|
|
|
|
|
# Grab the real object class here so that the lookup does
|
|
|
|
# not happen inside the main loop.
|
|
|
|
class_func = primary_tables[primary_table_name]['class_func']
|
|
|
|
|
|
|
|
while data:
|
|
|
|
found_handle, val = data
|
|
|
|
obj = class_func()
|
|
|
|
obj.unserialize(val)
|
|
|
|
|
|
|
|
# Now we need to loop over all object types
|
|
|
|
# that have been requests in the include_classes list
|
2007-01-25 22:34:37 +05:30
|
|
|
for classname in primary_tables.keys():
|
2007-06-04 08:19:31 +05:30
|
|
|
if obj.has_handle_reference(classname, handle):
|
2007-01-25 22:34:37 +05:30
|
|
|
yield (primary_table_name, found_handle)
|
2005-12-15 17:33:24 +05:30
|
|
|
|
2006-05-02 06:09:05 +05:30
|
|
|
data = cursor.next()
|
2005-12-15 17:33:24 +05:30
|
|
|
|
2006-05-02 06:09:05 +05:30
|
|
|
cursor.close()
|
2005-12-15 17:33:24 +05:30
|
|
|
|
|
|
|
return
|
2007-10-05 14:55:31 +05:30
|
|
|
|
|
|
|
def report_bm_change(self):
|
2007-10-05 15:00:27 +05:30
|
|
|
"""method that adds 1 to the number of bookmark changes during this session
|
|
|
|
"""
|
2007-10-05 14:55:31 +05:30
|
|
|
self._bm_changes += 1;
|
|
|
|
|
|
|
|
def db_has_bm_changes(self):
|
2007-10-05 15:00:27 +05:30
|
|
|
"""method that returns True if there where bookmark changes during the session
|
|
|
|
"""
|
2007-10-05 14:55:31 +05:30
|
|
|
return self._bm_changes > 0
|
2005-12-15 17:33:24 +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.
|
|
|
|
"""
|
2006-04-08 02:36:20 +05:30
|
|
|
def __init__(self, msg, db, batch=False, no_magic=False):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
2006-02-02 20:23:31 +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.
|
|
|
|
|
|
|
|
The batch parameter is set to True for large transactions. For such
|
|
|
|
transactions, the list of changes is not maintained, and no undo
|
|
|
|
is possible.
|
|
|
|
|
|
|
|
The no_magic parameter is ignored for non-batch transactions, and
|
|
|
|
is also of no importance for DB backends other than BSD DB. For
|
|
|
|
the BSDDB, when this paramter is set to True, some secondary
|
|
|
|
indices will be removed at the beginning and then rebuilt at
|
|
|
|
the end of such transaction (only if it is batch).
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
self.db = db
|
|
|
|
self.first = None
|
|
|
|
self.last = None
|
2006-01-18 02:47:14 +05:30
|
|
|
self.batch = batch
|
2006-02-02 20:23:31 +05:30
|
|
|
self.no_magic = no_magic
|
2005-04-23 21:23:30 +05:30
|
|
|
self.length = 0
|
2006-05-06 03:25:01 +05:30
|
|
|
self.timestamp = 0
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2005-04-18 04:04:56 +05:30
|
|
|
self.person_add = []
|
|
|
|
self.person_del = []
|
|
|
|
self.person_update = []
|
|
|
|
|
|
|
|
self.family_add = []
|
|
|
|
self.family_del = []
|
|
|
|
self.family_update = []
|
|
|
|
|
|
|
|
self.source_add = []
|
|
|
|
self.source_del = []
|
|
|
|
self.source_update = []
|
|
|
|
|
|
|
|
self.event_add = []
|
|
|
|
self.event_del = []
|
|
|
|
self.event_update = []
|
|
|
|
|
|
|
|
self.media_add = []
|
|
|
|
self.media_del = []
|
|
|
|
self.media_update = []
|
|
|
|
|
|
|
|
self.place_add = []
|
|
|
|
self.place_del = []
|
|
|
|
self.place_update = []
|
|
|
|
|
2005-05-27 23:13:04 +05:30
|
|
|
self.repository_add = []
|
|
|
|
self.repository_del = []
|
|
|
|
self.repository_update = []
|
|
|
|
|
2007-02-20 06:09:10 +05:30
|
|
|
self.note_add = []
|
|
|
|
self.note_del = []
|
|
|
|
self.note_update = []
|
|
|
|
|
2004-08-01 09:51:31 +05:30
|
|
|
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
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
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
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def add(self, obj_type, handle, old_data, new_data):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
2006-04-08 02:36:20 +05:30
|
|
|
Adds a commit operation to the Transaction. The obj_type is a constant
|
2004-08-13 10:04:07 +05:30
|
|
|
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.
|
|
|
|
"""
|
2007-03-25 07:55:37 +05:30
|
|
|
self.last = self.db.append(
|
2007-03-25 08:47:25 +05:30
|
|
|
cPickle.dumps((obj_type, handle, old_data, new_data), 1))
|
2004-08-01 09:51:31 +05:30
|
|
|
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)
|
|
|
|
|
2006-04-08 02:36:20 +05:30
|
|
|
def get_record(self, recno):
|
2004-08-13 10:04:07 +05:30
|
|
|
"""
|
|
|
|
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
|
2005-08-12 08:20:56 +05:30
|
|
|
|