2004-07-31 00:26:49 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2008-10-21 09:52:45 +05:30
|
|
|
# Copyright (C) 2005-2007 Donald N. Allingham
|
|
|
|
# Copyright (C) 2008 Brian G. Matherly
|
2004-07-31 00:26:49 +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.
|
|
|
|
#
|
2008-10-21 09:52:45 +05:30
|
|
|
# This program is distributed in the hope that it will be useful,
|
2004-07-31 00:26:49 +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$
|
|
|
|
|
2008-10-21 09:52:45 +05:30
|
|
|
# Written by Alex Roitman,
|
|
|
|
# largely based on ReadXML by Don Allingham
|
2004-12-06 09:43:13 +05:30
|
|
|
|
2005-04-01 10:04:31 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2008-10-21 09:52:45 +05:30
|
|
|
# Standard Python Modules
|
2005-04-01 10:04:31 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-06-16 21:19:17 +05:30
|
|
|
from __future__ import with_statement
|
2004-08-01 09:51:31 +05:30
|
|
|
import os
|
2008-10-21 09:52:45 +05:30
|
|
|
import shutil
|
|
|
|
import tempfile
|
2010-01-18 10:12:17 +05:30
|
|
|
from gen.ggettext import gettext as _
|
2008-10-21 09:52:45 +05:30
|
|
|
import cPickle as pickle
|
|
|
|
import time
|
2005-04-01 10:04:31 +05:30
|
|
|
from bsddb import dbshelve, db
|
2006-01-07 02:25:49 +05:30
|
|
|
import logging
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG = logging.getLogger(".Db")
|
2004-08-01 09:51:31 +05:30
|
|
|
|
2005-04-01 10:04:31 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2008-10-21 09:52:45 +05:30
|
|
|
# Gramps Modules
|
2005-04-01 10:04:31 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2008-02-19 01:37:09 +05:30
|
|
|
from gen.lib import (GenderStats, Source, Person, Family, Event, Place,
|
|
|
|
MediaObject, Repository, Note, Attribute, AttributeType,
|
|
|
|
NoteType)
|
2010-01-14 09:38:04 +05:30
|
|
|
from gen.db.write import (KEY_TO_CLASS_MAP, CLASS_TO_KEY_MAP)
|
2009-12-23 21:25:58 +05:30
|
|
|
from libgrdb import DbGrdb
|
|
|
|
from gen.db.txn import DbTxn as Transaction
|
2010-08-09 03:36:54 +05:30
|
|
|
from gen.db.cursor import BsddbBaseCursor
|
2009-09-01 00:12:29 +05:30
|
|
|
from gen.db.dbconst import *
|
2009-12-23 21:25:58 +05:30
|
|
|
from gen.db.exceptions import DbVersionError
|
2008-01-09 21:15:17 +05:30
|
|
|
import const
|
2008-10-21 09:52:45 +05:30
|
|
|
from QuestionDialog import ErrorDialog
|
|
|
|
from Errors import HandleError
|
2010-01-11 01:51:10 +05:30
|
|
|
from gen.updatecallback import UpdateCallback
|
2010-01-14 09:38:04 +05:30
|
|
|
from gen.display.name import displayer as name_displayer
|
2004-07-31 00:26:49 +05:30
|
|
|
|
2008-10-21 09:52:45 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-02-22 13:22:54 +05:30
|
|
|
_MINVERSION = 9
|
2009-04-01 02:51:55 +05:30
|
|
|
_DBVERSION = 14
|
2005-02-20 03:41:51 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
#--------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Secondary index functions
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------------
|
2007-06-04 08:29:36 +05:30
|
|
|
def find_surname(key, data):
|
2007-06-04 08:19:31 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return the surname from the data stream. Used for building a secondary
|
2007-06-04 08:19:31 +05:30
|
|
|
index.
|
|
|
|
"""
|
2006-04-20 20:35:56 +05:30
|
|
|
return str(data[3][5])
|
2004-07-31 00:26:49 +05:30
|
|
|
|
2007-06-04 08:29:36 +05:30
|
|
|
def find_idmap(key, data):
|
2007-06-04 08:19:31 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return the ID from the data stream. Used for building a secondary
|
2007-06-04 08:19:31 +05:30
|
|
|
index.
|
|
|
|
"""
|
2004-08-01 09:51:31 +05:30
|
|
|
return str(data[1])
|
|
|
|
|
2007-06-04 08:29:36 +05:30
|
|
|
def find_primary_handle(key, data):
|
2007-06-04 08:19:31 +05:30
|
|
|
"""
|
|
|
|
Secondary database key lookups for reference_map table
|
|
|
|
reference_map data values are of the form:
|
|
|
|
((primary_object_class_name, primary_object_handle),
|
|
|
|
(referenced_object_class_name, referenced_object_handle))
|
|
|
|
"""
|
2005-12-18 06:58:35 +05:30
|
|
|
return str((data)[0][1])
|
2005-12-15 23:02:10 +05:30
|
|
|
|
2007-06-04 08:29:36 +05:30
|
|
|
def find_referenced_handle(key, data):
|
2007-06-04 08:19:31 +05:30
|
|
|
"""
|
|
|
|
Secondary database key lookups for reference_map table
|
|
|
|
reference_map data values are of the form:
|
|
|
|
((primary_object_class_name, primary_object_handle),
|
|
|
|
(referenced_object_class_name, referenced_object_handle))
|
|
|
|
"""
|
2005-12-18 06:58:35 +05:30
|
|
|
return str((data)[1][1])
|
2005-12-15 23:02:10 +05:30
|
|
|
|
2010-08-09 03:36:54 +05:30
|
|
|
class GrampsBSDDBCursor(BsddbBaseCursor):
|
2007-06-04 08:19:31 +05:30
|
|
|
"""
|
|
|
|
Cursor to loop through a BSDDB table
|
|
|
|
"""
|
|
|
|
def __init__(self, source, txn=None):
|
2006-03-20 10:47:52 +05:30
|
|
|
self.cursor = source.db.cursor(txn)
|
2007-02-18 01:29:21 +05:30
|
|
|
self.source = source
|
2004-12-06 09:43:13 +05:30
|
|
|
|
2010-08-09 03:36:54 +05:30
|
|
|
class GrampsBSDDBAssocCursor(BsddbBaseCursor):
|
2006-03-21 05:35:07 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def __init__(self, source, txn=None):
|
2006-03-21 05:35:07 +05:30
|
|
|
self.cursor = source.cursor(txn)
|
2007-02-18 01:29:21 +05:30
|
|
|
self.source = source
|
2006-03-21 05:35:07 +05:30
|
|
|
|
|
|
|
class GrampsBSDDBDupCursor(GrampsBSDDBAssocCursor):
|
2005-12-15 23:02:10 +05:30
|
|
|
"""Cursor that includes handling for duplicate keys"""
|
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def set(self, key):
|
2005-12-16 02:56:55 +05:30
|
|
|
return self.cursor.set(str(key))
|
2005-12-15 23:02:10 +05:30
|
|
|
|
|
|
|
def next_dup(self):
|
|
|
|
return self.cursor.next_dup()
|
|
|
|
|
2004-07-31 00:26:49 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GrampsBSDDB
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-12-23 21:25:58 +05:30
|
|
|
class GrampsBSDDB(DbGrdb, UpdateCallback):
|
2007-12-09 15:48:59 +05:30
|
|
|
""" GRAMPS database object for Berkeley DB.
|
|
|
|
This is replaced for internal use by gen/db/dbdir.py
|
|
|
|
However, this class is still used for import of the 2.2.x
|
|
|
|
GRDB format. In 3.0+ this format is no longer used.
|
|
|
|
"""
|
2004-07-31 00:26:49 +05:30
|
|
|
|
2006-09-24 10:07:59 +05:30
|
|
|
def __init__(self, use_txn = True):
|
2004-07-31 00:26:49 +05:30
|
|
|
"""creates a new GrampsDB"""
|
2006-09-24 10:07:59 +05:30
|
|
|
|
2009-12-23 21:25:58 +05:30
|
|
|
DbGrdb.__init__(self)
|
2007-06-26 11:32:17 +05:30
|
|
|
#UpdateCallback.__init__(self)
|
2006-01-07 02:25:49 +05:30
|
|
|
self.txn = None
|
2006-01-26 02:36:23 +05:30
|
|
|
self.secondary_connected = False
|
2006-09-24 10:07:59 +05:30
|
|
|
self.UseTXN = use_txn
|
2004-07-31 00:26:49 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def __open_flags(self):
|
2006-03-08 22:52:45 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
return db.DB_CREATE|db.DB_AUTO_COMMIT
|
|
|
|
else:
|
|
|
|
return db.DB_CREATE
|
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def __open_table(self, file_name, table_name, dbtype=db.DB_HASH):
|
2004-10-19 08:49:25 +05:30
|
|
|
dbmap = dbshelve.DBShelf(self.env)
|
2004-10-23 09:26:48 +05:30
|
|
|
dbmap.db.set_pagesize(16384)
|
2005-02-17 04:19:54 +05:30
|
|
|
if self.readonly:
|
2006-08-13 03:25:52 +05:30
|
|
|
dbmap.open(file_name, table_name, dbtype, db.DB_RDONLY)
|
2006-01-07 02:25:49 +05:30
|
|
|
else:
|
2007-06-04 08:19:31 +05:30
|
|
|
dbmap.open(file_name, table_name, dbtype, self.__open_flags(), 0666)
|
2004-10-19 08:49:25 +05:30
|
|
|
return dbmap
|
2006-01-11 03:58:09 +05:30
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def all_handles(self, table):
|
2006-01-11 03:58:09 +05:30
|
|
|
return table.keys(self.txn)
|
2004-10-19 08:49:25 +05:30
|
|
|
|
2004-12-05 09:45:48 +05:30
|
|
|
def get_person_cursor(self):
|
2007-06-04 08:19:31 +05:30
|
|
|
return GrampsBSDDBCursor(self.person_map, self.txn)
|
2004-12-10 06:58:43 +05:30
|
|
|
|
|
|
|
def get_family_cursor(self):
|
2007-06-04 08:19:31 +05:30
|
|
|
return GrampsBSDDBCursor(self.family_map, self.txn)
|
2004-12-10 06:58:43 +05:30
|
|
|
|
2005-04-01 10:04:31 +05:30
|
|
|
def get_event_cursor(self):
|
2007-06-04 08:19:31 +05:30
|
|
|
return GrampsBSDDBCursor(self.event_map, self.txn)
|
2005-04-01 10:04:31 +05:30
|
|
|
|
2004-12-10 06:58:43 +05:30
|
|
|
def get_place_cursor(self):
|
2007-06-04 08:19:31 +05:30
|
|
|
return GrampsBSDDBCursor(self.place_map, self.txn)
|
2004-12-10 06:58:43 +05:30
|
|
|
|
|
|
|
def get_source_cursor(self):
|
2007-06-04 08:19:31 +05:30
|
|
|
return GrampsBSDDBCursor(self.source_map, self.txn)
|
2004-12-10 06:58:43 +05:30
|
|
|
|
|
|
|
def get_media_cursor(self):
|
2007-06-04 08:19:31 +05:30
|
|
|
return GrampsBSDDBCursor(self.media_map, self.txn)
|
2004-12-05 09:45:48 +05:30
|
|
|
|
2005-05-27 23:13:04 +05:30
|
|
|
def get_repository_cursor(self):
|
2007-06-04 08:19:31 +05:30
|
|
|
return GrampsBSDDBCursor(self.repository_map, self.txn)
|
2005-05-27 23:13:04 +05:30
|
|
|
|
2007-02-20 06:09:10 +05:30
|
|
|
def get_note_cursor(self):
|
2007-06-04 08:19:31 +05:30
|
|
|
return GrampsBSDDBCursor(self.note_map, self.txn)
|
2007-02-20 06:09:10 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def has_person_handle(self, handle):
|
2006-01-07 03:38:40 +05:30
|
|
|
"""
|
|
|
|
returns True if the handle exists in the current Person database.
|
|
|
|
"""
|
2008-06-16 20:31:46 +05:30
|
|
|
return self.person_map.get(str(handle), txn=self.txn) is not None
|
2006-01-07 03:38:40 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def has_family_handle(self, handle):
|
2006-01-07 03:38:40 +05:30
|
|
|
"""
|
|
|
|
returns True if the handle exists in the current Family database.
|
|
|
|
"""
|
2008-06-16 20:31:46 +05:30
|
|
|
return self.family_map.get(str(handle), txn=self.txn) is not None
|
2006-01-07 03:38:40 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def has_object_handle(self, handle):
|
2006-01-07 03:38:40 +05:30
|
|
|
"""
|
|
|
|
returns True if the handle exists in the current MediaObjectdatabase.
|
|
|
|
"""
|
2008-06-16 20:31:46 +05:30
|
|
|
return self.media_map.get(str(handle), txn=self.txn) is not None
|
2006-01-07 03:38:40 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def has_repository_handle(self, handle):
|
2006-01-07 03:38:40 +05:30
|
|
|
"""
|
|
|
|
returns True if the handle exists in the current Repository database.
|
|
|
|
"""
|
2008-06-16 20:31:46 +05:30
|
|
|
return self.repository_map.get(str(handle), txn=self.txn) is not None
|
2006-01-07 03:38:40 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def has_note_handle(self, handle):
|
2007-02-20 06:09:10 +05:30
|
|
|
"""
|
|
|
|
returns True if the handle exists in the current Note database.
|
|
|
|
"""
|
2008-06-16 20:31:46 +05:30
|
|
|
return self.note_map.get(str(handle), txn=self.txn) is not None
|
2007-02-20 06:09:10 +05:30
|
|
|
|
2007-06-04 08:19:31 +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 Repository database.
|
|
|
|
"""
|
2008-06-16 20:31:46 +05:30
|
|
|
return self.event_map.get(str(handle), txn=self.txn) is not None
|
2006-01-07 03:38:40 +05:30
|
|
|
|
2007-06-04 08:19:31 +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 Repository database.
|
|
|
|
"""
|
2008-06-16 20:31:46 +05:30
|
|
|
return self.place_map.get(str(handle), txn=self.txn) is not None
|
2006-01-07 03:38:40 +05:30
|
|
|
|
2007-06-04 08:19:31 +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 Repository database.
|
|
|
|
"""
|
2008-06-16 20:31:46 +05:30
|
|
|
return self.source_map.get(str(handle), txn=self.txn) is not None
|
2006-01-07 03:38:40 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def get_raw_person_data(self, handle):
|
|
|
|
"""
|
|
|
|
returns the raw, unserialized data for a person
|
|
|
|
"""
|
|
|
|
return self.person_map.get(str(handle), txn=self.txn)
|
2006-01-07 03:38:40 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def get_raw_family_data(self, handle):
|
|
|
|
"""
|
|
|
|
returns the raw, unserialized data for a family
|
|
|
|
"""
|
|
|
|
return self.family_map.get(str(handle), txn=self.txn)
|
2006-01-07 03:38:40 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def get_raw_object_data(self, handle):
|
|
|
|
"""
|
|
|
|
returns the raw, unserialized data for a media object
|
|
|
|
"""
|
|
|
|
return self.media_map.get(str(handle), txn=self.txn)
|
2006-01-07 03:38:40 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def get_raw_place_data(self, handle):
|
|
|
|
"""
|
|
|
|
returns the raw, unserialized data for a place
|
|
|
|
"""
|
|
|
|
return self.place_map.get(str(handle), txn=self.txn)
|
2006-01-07 03:38:40 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def get_raw_event_data(self, handle):
|
|
|
|
"""
|
|
|
|
returns the raw, unserialized data for an event
|
|
|
|
"""
|
|
|
|
return self.event_map.get(str(handle), txn=self.txn)
|
2006-01-07 03:38:40 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def get_raw_source_data(self, handle):
|
|
|
|
"""
|
|
|
|
returns the raw, unserialized data for a source
|
|
|
|
"""
|
|
|
|
return self.source_map.get(str(handle), txn=self.txn)
|
2006-01-07 03:38:40 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def get_raw_repository_data(self, handle):
|
|
|
|
"""
|
|
|
|
returns the raw, unserialized data for a repository
|
|
|
|
"""
|
|
|
|
return self.repository_map.get(str(handle), txn=self.txn)
|
2006-01-07 03:38:40 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def get_raw_note_data(self, handle):
|
|
|
|
"""
|
|
|
|
returns the raw, unserialized data for a note
|
|
|
|
"""
|
|
|
|
return self.note_map.get(str(handle), txn=self.txn)
|
2007-02-20 06:09:10 +05:30
|
|
|
|
2005-12-15 23:02:10 +05:30
|
|
|
# cursors for lookups in the reference_map for back reference
|
|
|
|
# lookups. The reference_map has three indexes:
|
2007-06-04 08:19:31 +05:30
|
|
|
# the main index: a tuple of (primary_handle, referenced_handle)
|
2005-12-15 23:02:10 +05:30
|
|
|
# the primary_handle index: the primary_handle
|
|
|
|
# the referenced_handle index: the referenced_handle
|
|
|
|
# the main index is unique, the others allow duplicate entries.
|
|
|
|
|
|
|
|
def get_reference_map_cursor(self):
|
2007-06-04 08:19:31 +05:30
|
|
|
return GrampsBSDDBAssocCursor(self.reference_map, self.txn)
|
2005-12-15 23:02:10 +05:30
|
|
|
|
|
|
|
def get_reference_map_primary_cursor(self):
|
2007-06-04 08:19:31 +05:30
|
|
|
return GrampsBSDDBDupCursor(self.reference_map_primary_map, self.txn)
|
2005-12-15 23:02:10 +05:30
|
|
|
|
|
|
|
def get_reference_map_referenced_cursor(self):
|
2007-06-04 08:19:31 +05:30
|
|
|
return GrampsBSDDBDupCursor(self.reference_map_referenced_map, self.txn)
|
2005-12-15 23:02:10 +05:30
|
|
|
|
2009-12-23 21:25:58 +05:30
|
|
|
# These are overriding the DbBase's methods of saving metadata
|
2006-08-12 05:16:24 +05:30
|
|
|
# because we now have txn-capable metadata table
|
|
|
|
def set_default_person_handle(self, handle):
|
|
|
|
"""sets the default Person to the passed instance"""
|
|
|
|
if not self.readonly:
|
2006-08-13 03:25:52 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
# Start transaction if needed
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
else:
|
|
|
|
the_txn = None
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('default', str(handle), txn=the_txn)
|
2006-08-13 03:25:52 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
the_txn.commit()
|
|
|
|
else:
|
|
|
|
self.metadata.sync()
|
2006-08-12 05:16:24 +05:30
|
|
|
|
|
|
|
def get_default_person(self):
|
|
|
|
"""returns the default Person of the database"""
|
|
|
|
person = self.get_person_from_handle(self.get_default_handle())
|
|
|
|
if person:
|
|
|
|
return person
|
|
|
|
elif (self.metadata) and (not self.readonly):
|
2006-08-13 03:25:52 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
# Start transaction if needed
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
else:
|
|
|
|
the_txn = None
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('default', None, txn=the_txn)
|
2006-08-13 03:25:52 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
the_txn.commit()
|
|
|
|
else:
|
|
|
|
self.metadata.sync()
|
2006-08-12 05:16:24 +05:30
|
|
|
return None
|
|
|
|
|
2005-06-05 09:31:56 +05:30
|
|
|
def version_supported(self):
|
2007-06-25 07:16:37 +05:30
|
|
|
dbversion = self.metadata.get('version',default=_DBVERSION)
|
2006-08-12 05:16:24 +05:30
|
|
|
return ((dbversion <= _DBVERSION) and (dbversion >= _MINVERSION))
|
2005-06-05 09:31:56 +05:30
|
|
|
|
2005-03-03 11:03:22 +05:30
|
|
|
def need_upgrade(self):
|
2007-06-04 08:19:31 +05:30
|
|
|
dbversion = self.metadata.get('version', default=0)
|
2006-08-12 05:16:24 +05:30
|
|
|
return not self.readonly and dbversion < _DBVERSION
|
2005-03-03 11:03:22 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def load(self, name, callback, mode="w"):
|
2006-01-11 03:58:09 +05:30
|
|
|
if self.db_is_open:
|
2004-07-31 00:26:49 +05:30
|
|
|
self.close()
|
|
|
|
|
2005-02-17 04:19:54 +05:30
|
|
|
self.readonly = mode == "r"
|
2006-07-15 10:44:39 +05:30
|
|
|
if self.readonly:
|
|
|
|
self.UseTXN = False
|
2005-02-17 04:19:54 +05:30
|
|
|
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
if callback:
|
|
|
|
callback(12)
|
2006-01-17 04:19:49 +05:30
|
|
|
|
2006-05-09 04:48:16 +05:30
|
|
|
self.full_name = os.path.abspath(name)
|
|
|
|
self.brief_name = os.path.basename(name)
|
|
|
|
|
2004-07-31 00:26:49 +05:30
|
|
|
self.env = db.DBEnv()
|
2007-06-04 08:19:31 +05:30
|
|
|
self.env.set_cachesize(0, 0x4000000) # 32MB
|
2006-03-08 22:52:45 +05:30
|
|
|
|
|
|
|
if self.UseTXN:
|
2006-05-18 02:46:59 +05:30
|
|
|
# These env settings are only needed for Txn environment
|
|
|
|
self.env.set_lk_max_locks(25000)
|
|
|
|
self.env.set_lk_max_objects(25000)
|
2009-04-01 02:51:55 +05:30
|
|
|
|
|
|
|
self.set_auto_remove()
|
2006-05-18 02:46:59 +05:30
|
|
|
|
|
|
|
# The DB_PRIVATE flag must go if we ever move to multi-user setup
|
2007-06-04 08:19:31 +05:30
|
|
|
env_flags = db.DB_CREATE | db.DB_PRIVATE | \
|
|
|
|
db.DB_INIT_MPOOL | db.DB_INIT_LOCK | \
|
|
|
|
db.DB_INIT_LOG | db.DB_INIT_TXN | db.DB_THREAD
|
2006-11-27 01:17:34 +05:30
|
|
|
# Only do recovery for existing databases
|
|
|
|
if os.path.isfile(self.full_name):
|
|
|
|
env_flags = env_flags | db.DB_RECOVER
|
2007-06-26 23:10:03 +05:30
|
|
|
else:
|
|
|
|
env_flags = db.DB_CREATE | db.DB_PRIVATE | db.DB_INIT_MPOOL
|
2006-11-26 08:30:44 +05:30
|
|
|
|
2007-06-25 09:05:48 +05:30
|
|
|
env_name = self.make_env_name(self.full_name)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.env.open(env_name, env_flags)
|
2006-03-08 22:52:45 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
self.env.txn_checkpoint()
|
2006-01-07 02:25:49 +05:30
|
|
|
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
if callback:
|
|
|
|
callback(25)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata = self.__open_table(self.full_name, "meta")
|
2006-05-18 02:46:59 +05:30
|
|
|
|
|
|
|
# If we cannot work with this DB version,
|
|
|
|
# it makes no sense to go further
|
2007-06-25 01:33:40 +05:30
|
|
|
if not self.version_supported():
|
2007-06-04 08:19:31 +05:30
|
|
|
self.__close_early()
|
2006-09-24 10:07:59 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
self.family_map = self.__open_table(self.full_name, "family")
|
|
|
|
self.place_map = self.__open_table(self.full_name, "places")
|
|
|
|
self.source_map = self.__open_table(self.full_name, "sources")
|
|
|
|
self.media_map = self.__open_table(self.full_name, "media")
|
|
|
|
self.event_map = self.__open_table(self.full_name, "events")
|
|
|
|
self.person_map = self.__open_table(self.full_name, "person")
|
|
|
|
self.repository_map = self.__open_table(self.full_name, "repository")
|
|
|
|
self.note_map = self.__open_table(self.full_name, "note")
|
|
|
|
self.reference_map = self.__open_table(self.full_name, "reference_map",
|
|
|
|
dbtype=db.DB_BTREE)
|
2006-01-26 02:36:23 +05:30
|
|
|
|
2007-12-09 15:48:59 +05:30
|
|
|
self.name_group = db.DB(self.env)
|
|
|
|
self.name_group.set_flags(db.DB_DUP)
|
|
|
|
if self.readonly:
|
|
|
|
self.name_group.open(self.full_name, "name_group",
|
|
|
|
db.DB_HASH, flags=db.DB_RDONLY)
|
|
|
|
else:
|
|
|
|
self.name_group.open(self.full_name, "name_group",
|
|
|
|
db.DB_HASH, flags=self.__open_flags())
|
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
self.__load_metadata()
|
2006-01-26 02:36:23 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
gstats = self.metadata.get('gender_stats', default=None)
|
2006-01-26 02:36:23 +05:30
|
|
|
|
|
|
|
if not self.readonly:
|
2006-08-13 03:25:52 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
# Start transaction if needed
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
else:
|
|
|
|
the_txn = None
|
|
|
|
|
2008-06-16 20:31:46 +05:30
|
|
|
if gstats is None:
|
2006-08-13 03:25:52 +05:30
|
|
|
# New database. Set up the current version.
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('version', _DBVERSION, txn=the_txn)
|
2008-07-17 23:40:32 +05:30
|
|
|
elif 'version' not in self.metadata:
|
2006-08-13 03:25:52 +05:30
|
|
|
# Not new database, but the version is missing.
|
|
|
|
# Use 0, but it is likely to fail anyway.
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('version', 0, txn=the_txn)
|
2006-08-13 03:25:52 +05:30
|
|
|
|
|
|
|
if self.UseTXN:
|
|
|
|
the_txn.commit()
|
|
|
|
else:
|
|
|
|
self.metadata.sync()
|
2006-08-12 05:16:24 +05:30
|
|
|
|
2006-01-26 02:36:23 +05:30
|
|
|
self.genderStats = GenderStats(gstats)
|
|
|
|
|
|
|
|
# Here we take care of any changes in the tables related to new code.
|
|
|
|
# If secondary indices change, then they should removed
|
|
|
|
# or rebuilt by upgrade as well. In any case, the
|
|
|
|
# self.secondary_connected flag should be set accordingly.
|
|
|
|
if self.need_upgrade():
|
2006-03-15 01:19:34 +05:30
|
|
|
self.gramps_upgrade(callback)
|
2006-01-26 02:36:23 +05:30
|
|
|
|
|
|
|
if not self.secondary_connected:
|
|
|
|
self.connect_secondary()
|
|
|
|
|
2006-05-07 10:52:44 +05:30
|
|
|
self.open_undodb()
|
2006-01-26 02:36:23 +05:30
|
|
|
self.db_is_open = True
|
|
|
|
|
2006-05-07 10:52:44 +05:30
|
|
|
# Re-set the undo history to a fresh session start
|
2009-09-01 00:12:29 +05:30
|
|
|
#self.undoindex = -1
|
|
|
|
#self.translist = [None] * len(self.translist)
|
2006-05-07 10:52:44 +05:30
|
|
|
self.abort_possible = True
|
2009-09-01 00:12:29 +05:30
|
|
|
#self.undo_history_timestamp = time.time()
|
2006-01-26 02:36:23 +05:30
|
|
|
|
|
|
|
return 1
|
|
|
|
|
2008-10-21 09:52:45 +05:30
|
|
|
def make_env_name(self, full_name):
|
2007-06-25 09:05:48 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
# Environment name is now based on the filename
|
|
|
|
drive, tmp_name = os.path.splitdrive(full_name)
|
|
|
|
tmp_name = tmp_name.lstrip(os.sep)
|
2007-09-08 11:24:02 +05:30
|
|
|
env_name = os.path.join(os.path.expanduser(const.ENV_DIR),tmp_name)
|
2007-06-25 09:05:48 +05:30
|
|
|
else:
|
|
|
|
env_name = os.path.expanduser('~')
|
|
|
|
return env_name
|
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def __load_metadata(self):
|
2006-07-06 23:16:46 +05:30
|
|
|
# name display formats
|
2007-06-04 08:19:31 +05:30
|
|
|
self.name_formats = self.metadata.get('name_formats', default=[])
|
2006-07-27 23:14:02 +05:30
|
|
|
# upgrade formats if they were saved in the old way
|
|
|
|
for format_ix in range(len(self.name_formats)):
|
|
|
|
format = self.name_formats[format_ix]
|
|
|
|
if len(format) == 3:
|
2007-06-04 08:19:31 +05:30
|
|
|
format = format + (True, )
|
2006-07-27 23:14:02 +05:30
|
|
|
self.name_formats[format_ix] = format
|
2007-02-05 05:29:03 +05:30
|
|
|
|
|
|
|
# database owner
|
|
|
|
self.set_researcher(self.metadata.get('researcher', default=self.owner))
|
|
|
|
|
2006-05-19 05:35:44 +05:30
|
|
|
# bookmarks
|
2007-06-04 08:19:31 +05:30
|
|
|
self.bookmarks.set(self.metadata.get('bookmarks', default=[]))
|
2006-12-21 08:58:44 +05:30
|
|
|
self.family_bookmarks.set(self.metadata.get('family_bookmarks',
|
|
|
|
default=[]))
|
|
|
|
self.event_bookmarks.set(self.metadata.get('event_bookmarks',
|
|
|
|
default=[]))
|
|
|
|
self.source_bookmarks.set(self.metadata.get('source_bookmarks',
|
|
|
|
default=[]))
|
|
|
|
self.repo_bookmarks.set(self.metadata.get('repo_bookmarks',
|
|
|
|
default=[]))
|
|
|
|
self.media_bookmarks.set(self.metadata.get('media_bookmarks',
|
|
|
|
default=[]))
|
|
|
|
self.place_bookmarks.set(self.metadata.get('place_bookmarks',
|
|
|
|
default=[]))
|
2007-03-28 03:17:18 +05:30
|
|
|
self.note_bookmarks.set(self.metadata.get('note_bookmarks',
|
|
|
|
default=[]))
|
2007-02-05 05:29:03 +05:30
|
|
|
|
2006-05-19 05:35:44 +05:30
|
|
|
# Custom type values
|
2006-08-12 05:16:24 +05:30
|
|
|
self.family_event_names = set(self.metadata.get('fevent_names',
|
|
|
|
default=[]))
|
|
|
|
self.individual_event_names = set(self.metadata.get('pevent_names',
|
|
|
|
default=[]))
|
|
|
|
self.family_attributes = set(self.metadata.get('fattr_names',
|
|
|
|
default=[]))
|
|
|
|
self.individual_attributes = set(self.metadata.get('pattr_names',
|
|
|
|
default=[]))
|
2007-06-04 08:19:31 +05:30
|
|
|
self.marker_names = set(self.metadata.get('marker_names', default=[]))
|
2006-08-12 05:16:24 +05:30
|
|
|
self.child_ref_types = set(self.metadata.get('child_refs',
|
|
|
|
default=[]))
|
|
|
|
self.family_rel_types = set(self.metadata.get('family_rels',
|
|
|
|
default=[]))
|
|
|
|
self.event_role_names = set(self.metadata.get('event_roles',
|
|
|
|
default=[]))
|
2007-06-04 08:19:31 +05:30
|
|
|
self.name_types = set(self.metadata.get('name_types', default=[]))
|
2006-08-12 05:16:24 +05:30
|
|
|
self.repository_types = set(self.metadata.get('repo_types',
|
|
|
|
default=[]))
|
2007-02-20 06:09:10 +05:30
|
|
|
self.note_types = set(self.metadata.get('note_types',
|
|
|
|
default=[]))
|
2006-08-12 05:16:24 +05:30
|
|
|
self.source_media_types = set(self.metadata.get('sm_types',
|
|
|
|
default=[]))
|
2007-06-04 08:19:31 +05:30
|
|
|
self.url_types = set(self.metadata.get('url_types', default=[]))
|
2006-08-12 05:16:24 +05:30
|
|
|
self.media_attributes = set(self.metadata.get('mattr_names',
|
|
|
|
default=[]))
|
2007-02-05 05:29:03 +05:30
|
|
|
|
2007-01-19 22:23:49 +05:30
|
|
|
# surname list
|
2007-06-04 08:19:31 +05:30
|
|
|
self.surname_list = self.metadata.get('surname_list', default=[])
|
2006-05-19 05:35:44 +05:30
|
|
|
|
2006-01-26 02:36:23 +05:30
|
|
|
def connect_secondary(self):
|
|
|
|
"""
|
|
|
|
This method connects or creates secondary index tables.
|
|
|
|
It assumes that the tables either exist and are in the right
|
|
|
|
format or do not exist (in which case they get created).
|
|
|
|
|
|
|
|
It is the responsibility of upgrade code to either create
|
|
|
|
or remove invalid secondary index tables.
|
|
|
|
"""
|
2006-01-18 09:38:28 +05:30
|
|
|
|
2005-12-15 23:02:10 +05:30
|
|
|
# index tables used just for speeding up searches
|
2005-02-17 04:19:54 +05:30
|
|
|
if self.readonly:
|
2006-01-13 03:32:58 +05:30
|
|
|
table_flags = db.DB_RDONLY
|
2005-02-17 04:19:54 +05:30
|
|
|
else:
|
2007-06-04 08:19:31 +05:30
|
|
|
table_flags = self.__open_flags()
|
2005-02-17 04:19:54 +05:30
|
|
|
|
2006-01-26 02:36:23 +05:30
|
|
|
self.surnames = db.DB(self.env)
|
|
|
|
self.surnames.set_flags(db.DB_DUP|db.DB_DUPSORT)
|
|
|
|
self.surnames.open(self.full_name, "surnames", db.DB_BTREE,
|
2006-06-14 01:29:14 +05:30
|
|
|
flags=table_flags)
|
2004-07-31 00:26:49 +05:30
|
|
|
|
|
|
|
self.id_trans = db.DB(self.env)
|
2006-01-18 02:47:14 +05:30
|
|
|
self.id_trans.set_flags(db.DB_DUP)
|
2006-01-07 02:25:49 +05:30
|
|
|
self.id_trans.open(self.full_name, "idtrans",
|
2006-01-13 03:32:58 +05:30
|
|
|
db.DB_HASH, flags=table_flags)
|
2004-07-31 00:26:49 +05:30
|
|
|
|
2004-08-20 07:50:06 +05:30
|
|
|
self.fid_trans = db.DB(self.env)
|
2006-01-18 02:47:14 +05:30
|
|
|
self.fid_trans.set_flags(db.DB_DUP)
|
2006-01-07 02:25:49 +05:30
|
|
|
self.fid_trans.open(self.full_name, "fidtrans",
|
2006-01-13 03:32:58 +05:30
|
|
|
db.DB_HASH, flags=table_flags)
|
2004-08-20 07:50:06 +05:30
|
|
|
|
2005-06-08 10:10:33 +05:30
|
|
|
self.eid_trans = db.DB(self.env)
|
2006-01-18 02:47:14 +05:30
|
|
|
self.eid_trans.set_flags(db.DB_DUP)
|
2006-01-07 02:25:49 +05:30
|
|
|
self.eid_trans.open(self.full_name, "eidtrans",
|
2006-01-13 03:32:58 +05:30
|
|
|
db.DB_HASH, flags=table_flags)
|
2005-06-08 10:10:33 +05:30
|
|
|
|
2004-08-24 09:18:15 +05:30
|
|
|
self.pid_trans = db.DB(self.env)
|
2006-01-18 02:47:14 +05:30
|
|
|
self.pid_trans.set_flags(db.DB_DUP)
|
2006-01-07 02:25:49 +05:30
|
|
|
self.pid_trans.open(self.full_name, "pidtrans",
|
2006-01-13 03:32:58 +05:30
|
|
|
db.DB_HASH, flags=table_flags)
|
2004-08-24 09:18:15 +05:30
|
|
|
|
|
|
|
self.sid_trans = db.DB(self.env)
|
2006-01-18 02:47:14 +05:30
|
|
|
self.sid_trans.set_flags(db.DB_DUP)
|
2006-01-07 02:25:49 +05:30
|
|
|
self.sid_trans.open(self.full_name, "sidtrans",
|
2006-01-13 03:32:58 +05:30
|
|
|
db.DB_HASH, flags=table_flags)
|
2004-08-24 09:18:15 +05:30
|
|
|
|
|
|
|
self.oid_trans = db.DB(self.env)
|
2006-01-18 02:47:14 +05:30
|
|
|
self.oid_trans.set_flags(db.DB_DUP)
|
2006-01-07 02:25:49 +05:30
|
|
|
self.oid_trans.open(self.full_name, "oidtrans",
|
2006-01-13 03:32:58 +05:30
|
|
|
db.DB_HASH, flags=table_flags)
|
2004-08-24 09:18:15 +05:30
|
|
|
|
2005-05-27 23:13:04 +05:30
|
|
|
self.rid_trans = db.DB(self.env)
|
2006-01-18 02:47:14 +05:30
|
|
|
self.rid_trans.set_flags(db.DB_DUP)
|
2006-01-07 02:25:49 +05:30
|
|
|
self.rid_trans.open(self.full_name, "ridtrans",
|
2006-01-13 03:32:58 +05:30
|
|
|
db.DB_HASH, flags=table_flags)
|
2005-05-27 23:13:04 +05:30
|
|
|
|
2007-02-20 06:09:10 +05:30
|
|
|
self.nid_trans = db.DB(self.env)
|
|
|
|
self.nid_trans.set_flags(db.DB_DUP)
|
|
|
|
self.nid_trans.open(self.full_name, "nidtrans",
|
|
|
|
db.DB_HASH, flags=table_flags)
|
|
|
|
|
2005-12-15 23:02:10 +05:30
|
|
|
self.reference_map_primary_map = db.DB(self.env)
|
2006-01-18 02:47:14 +05:30
|
|
|
self.reference_map_primary_map.set_flags(db.DB_DUP)
|
2006-01-07 02:25:49 +05:30
|
|
|
self.reference_map_primary_map.open(self.full_name,
|
2005-12-15 23:02:10 +05:30
|
|
|
"reference_map_primary_map",
|
2006-01-13 03:32:58 +05:30
|
|
|
db.DB_BTREE, flags=table_flags)
|
2005-12-15 23:02:10 +05:30
|
|
|
|
|
|
|
self.reference_map_referenced_map = db.DB(self.env)
|
2006-01-18 22:21:06 +05:30
|
|
|
self.reference_map_referenced_map.set_flags(db.DB_DUP|db.DB_DUPSORT)
|
2006-01-07 02:25:49 +05:30
|
|
|
self.reference_map_referenced_map.open(self.full_name,
|
2005-12-15 23:02:10 +05:30
|
|
|
"reference_map_referenced_map",
|
2006-01-13 03:32:58 +05:30
|
|
|
db.DB_BTREE, flags=table_flags)
|
2005-12-15 23:02:10 +05:30
|
|
|
|
2005-02-17 04:19:54 +05:30
|
|
|
if not self.readonly:
|
2007-06-04 08:29:36 +05:30
|
|
|
self.person_map.associate(self.surnames, find_surname, table_flags)
|
|
|
|
self.person_map.associate(self.id_trans, find_idmap, table_flags)
|
|
|
|
self.family_map.associate(self.fid_trans, find_idmap, table_flags)
|
|
|
|
self.event_map.associate(self.eid_trans, find_idmap, table_flags)
|
|
|
|
self.repository_map.associate(self.rid_trans, find_idmap,
|
2006-01-13 03:32:58 +05:30
|
|
|
table_flags)
|
2007-06-04 08:29:36 +05:30
|
|
|
self.note_map.associate(self.nid_trans, find_idmap, table_flags)
|
|
|
|
self.place_map.associate(self.pid_trans, find_idmap, table_flags)
|
|
|
|
self.media_map.associate(self.oid_trans, find_idmap, table_flags)
|
|
|
|
self.source_map.associate(self.sid_trans, find_idmap, table_flags)
|
2005-12-15 23:02:10 +05:30
|
|
|
self.reference_map.associate(self.reference_map_primary_map,
|
2007-06-04 08:29:36 +05:30
|
|
|
find_primary_handle,
|
2006-01-13 03:32:58 +05:30
|
|
|
table_flags)
|
2005-12-15 23:02:10 +05:30
|
|
|
self.reference_map.associate(self.reference_map_referenced_map,
|
2007-06-04 08:29:36 +05:30
|
|
|
find_referenced_handle,
|
2006-01-13 03:32:58 +05:30
|
|
|
table_flags)
|
2006-01-26 02:36:23 +05:30
|
|
|
self.secondary_connected = True
|
2004-07-31 00:26:49 +05:30
|
|
|
|
2007-01-23 22:32:55 +05:30
|
|
|
self.smap_index = len(self.source_map)
|
|
|
|
self.emap_index = len(self.event_map)
|
|
|
|
self.pmap_index = len(self.person_map)
|
|
|
|
self.fmap_index = len(self.family_map)
|
|
|
|
self.lmap_index = len(self.place_map)
|
|
|
|
self.omap_index = len(self.media_map)
|
|
|
|
self.rmap_index = len(self.repository_map)
|
2007-02-20 06:09:10 +05:30
|
|
|
self.nmap_index = len(self.note_map)
|
2005-12-16 02:56:55 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def rebuild_secondary(self, callback):
|
2006-02-03 21:19:59 +05:30
|
|
|
if self.readonly:
|
2006-01-26 02:36:23 +05:30
|
|
|
return
|
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
table_flags = self.__open_flags()
|
2005-08-18 11:28:28 +05:30
|
|
|
|
2006-01-26 02:36:23 +05:30
|
|
|
# remove existing secondary indices
|
2005-08-18 11:28:28 +05:30
|
|
|
self.id_trans.close()
|
2006-01-19 02:07:15 +05:30
|
|
|
junk = db.DB(self.env)
|
2007-06-04 08:19:31 +05:30
|
|
|
junk.remove(self.full_name, "idtrans")
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
if callback:
|
|
|
|
callback(1)
|
2005-08-18 11:28:28 +05:30
|
|
|
|
2006-01-19 02:07:15 +05:30
|
|
|
self.surnames.close()
|
|
|
|
junk = db.DB(self.env)
|
2007-06-04 08:19:31 +05:30
|
|
|
junk.remove(self.full_name, "surnames")
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
if callback:
|
|
|
|
callback(2)
|
2005-08-18 11:28:28 +05:30
|
|
|
|
|
|
|
# Repair secondary indices related to family_map
|
|
|
|
self.fid_trans.close()
|
2006-01-19 02:07:15 +05:30
|
|
|
junk = db.DB(self.env)
|
2007-06-04 08:19:31 +05:30
|
|
|
junk.remove(self.full_name, "fidtrans")
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
if callback:
|
|
|
|
callback(3)
|
2005-08-18 11:28:28 +05:30
|
|
|
|
|
|
|
# Repair secondary indices related to place_map
|
|
|
|
self.pid_trans.close()
|
2006-01-19 02:07:15 +05:30
|
|
|
junk = db.DB(self.env)
|
2007-06-04 08:19:31 +05:30
|
|
|
junk.remove(self.full_name, "pidtrans")
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
if callback:
|
|
|
|
callback(4)
|
2005-08-18 11:28:28 +05:30
|
|
|
|
|
|
|
# Repair secondary indices related to media_map
|
|
|
|
self.oid_trans.close()
|
2006-01-19 02:07:15 +05:30
|
|
|
junk = db.DB(self.env)
|
2007-06-04 08:19:31 +05:30
|
|
|
junk.remove(self.full_name, "oidtrans")
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
if callback:
|
|
|
|
callback(5)
|
2005-08-18 11:28:28 +05:30
|
|
|
|
|
|
|
# Repair secondary indices related to source_map
|
|
|
|
self.sid_trans.close()
|
2006-01-19 02:07:15 +05:30
|
|
|
junk = db.DB(self.env)
|
2007-06-04 08:19:31 +05:30
|
|
|
junk.remove(self.full_name, "sidtrans")
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
if callback:
|
|
|
|
callback(6)
|
2005-08-18 11:28:28 +05:30
|
|
|
|
2006-01-19 02:07:15 +05:30
|
|
|
# Repair secondary indices related to event_map
|
|
|
|
self.eid_trans.close()
|
|
|
|
junk = db.DB(self.env)
|
2007-06-04 08:19:31 +05:30
|
|
|
junk.remove(self.full_name, "eidtrans")
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
if callback:
|
|
|
|
callback(7)
|
2005-08-18 11:28:28 +05:30
|
|
|
|
2005-12-15 11:49:37 +05:30
|
|
|
# Repair secondary indices related to repository_map
|
|
|
|
self.rid_trans.close()
|
2006-01-19 02:07:15 +05:30
|
|
|
junk = db.DB(self.env)
|
2007-06-04 08:19:31 +05:30
|
|
|
junk.remove(self.full_name, "ridtrans")
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
if callback:
|
|
|
|
callback(8)
|
2006-01-19 02:07:15 +05:30
|
|
|
|
2007-02-20 06:09:10 +05:30
|
|
|
# Repair secondary indices related to note_map
|
|
|
|
self.nid_trans.close()
|
|
|
|
junk = db.DB(self.env)
|
2007-06-04 08:19:31 +05:30
|
|
|
junk.remove(self.full_name, "nidtrans")
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
if callback:
|
|
|
|
callback(9)
|
2007-02-20 06:09:10 +05:30
|
|
|
|
2006-01-19 02:07:15 +05:30
|
|
|
# Repair secondary indices related to reference_map
|
|
|
|
self.reference_map_primary_map.close()
|
|
|
|
junk = db.DB(self.env)
|
2007-06-04 08:19:31 +05:30
|
|
|
junk.remove(self.full_name, "reference_map_primary_map")
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
if callback:
|
|
|
|
callback(10)
|
2006-01-19 02:07:15 +05:30
|
|
|
|
|
|
|
self.reference_map_referenced_map.close()
|
|
|
|
junk = db.DB(self.env)
|
2007-06-04 08:19:31 +05:30
|
|
|
junk.remove(self.full_name, "reference_map_referenced_map")
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
if callback:
|
|
|
|
callback(11)
|
2006-01-26 02:36:23 +05:30
|
|
|
|
|
|
|
# Set flag saying that we have removed secondary indices
|
|
|
|
# and then call the creating routine
|
|
|
|
self.secondary_connected = False
|
|
|
|
self.connect_secondary()
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
if callback:
|
|
|
|
callback(12)
|
2005-12-15 11:49:37 +05:30
|
|
|
|
2005-12-15 23:02:10 +05:30
|
|
|
def find_backlink_handles(self, handle, include_classes=None):
|
|
|
|
"""
|
|
|
|
Find all objects that hold a reference to the object handle.
|
2007-06-04 08:19:31 +05:30
|
|
|
Returns an interator over a list of (class_name, handle) tuples.
|
2005-12-15 23:02:10 +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
|
|
|
|
|
|
|
|
Note that this is a generator function, it returns a iterator for
|
|
|
|
use in loops. If you want a list of the results use:
|
|
|
|
|
2010-01-22 00:12:53 +05:30
|
|
|
> result_list = list(find_backlink_handles(handle))
|
2005-12-15 23:02:10 +05:30
|
|
|
"""
|
|
|
|
|
|
|
|
# Use the secondary index to locate all the reference_map entries
|
|
|
|
# that include a reference to the object we are looking for.
|
|
|
|
referenced_cur = self.get_reference_map_referenced_cursor()
|
|
|
|
|
2005-12-18 01:43:23 +05:30
|
|
|
try:
|
|
|
|
ret = referenced_cur.set(handle)
|
|
|
|
except:
|
|
|
|
ret = None
|
|
|
|
|
2005-12-15 23:02:10 +05:30
|
|
|
while (ret is not None):
|
2007-06-04 08:19:31 +05:30
|
|
|
(key, data) = ret
|
2005-12-15 23:02:10 +05:30
|
|
|
|
|
|
|
# data values are of the form:
|
|
|
|
# ((primary_object_class_name, primary_object_handle),
|
|
|
|
# (referenced_object_class_name, referenced_object_handle))
|
|
|
|
# so we need the first tuple to give us the type to compare
|
|
|
|
|
2006-07-28 09:40:43 +05:30
|
|
|
### FIXME: this is a dirty hack that works without no
|
|
|
|
### sensible explanation. For some reason, for a readonly
|
|
|
|
### database, secondary index returns a primary table key
|
|
|
|
### corresponding to the data, not the data.
|
|
|
|
if self.readonly:
|
|
|
|
data = self.reference_map.get(data)
|
|
|
|
else:
|
|
|
|
data = pickle.loads(data)
|
2008-06-16 20:31:46 +05:30
|
|
|
if include_classes is None or \
|
2006-05-20 00:24:21 +05:30
|
|
|
KEY_TO_CLASS_MAP[data[0][0]] in include_classes:
|
2007-06-04 08:19:31 +05:30
|
|
|
yield (KEY_TO_CLASS_MAP[data[0][0]], data[0][1])
|
2005-12-15 23:02:10 +05:30
|
|
|
|
|
|
|
ret = referenced_cur.next_dup()
|
|
|
|
|
|
|
|
referenced_cur.close()
|
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def delete_primary_from_reference_map(self, hndl, transaction, txn=None):
|
2006-05-20 00:24:21 +05:30
|
|
|
"""
|
|
|
|
Remove all references to the primary object from the reference_map.
|
|
|
|
"""
|
2005-12-15 23:02:10 +05:30
|
|
|
|
2005-12-15 23:18:48 +05:30
|
|
|
primary_cur = self.get_reference_map_primary_cursor()
|
2005-12-18 01:43:23 +05:30
|
|
|
|
|
|
|
try:
|
2007-06-04 08:19:31 +05:30
|
|
|
ret = primary_cur.set(hndl)
|
2005-12-18 01:43:23 +05:30
|
|
|
except:
|
|
|
|
ret = None
|
2005-12-15 23:18:48 +05:30
|
|
|
|
2006-07-19 09:59:04 +05:30
|
|
|
remove_list = set()
|
2005-12-15 23:18:48 +05:30
|
|
|
while (ret is not None):
|
2007-06-04 08:19:31 +05:30
|
|
|
(key, data) = ret
|
2005-12-15 23:18:48 +05:30
|
|
|
|
|
|
|
# data values are of the form:
|
|
|
|
# ((primary_object_class_name, primary_object_handle),
|
|
|
|
# (referenced_object_class_name, referenced_object_handle))
|
|
|
|
|
|
|
|
# so we need the second tuple give us a reference that we can
|
|
|
|
# combine with the primary_handle to get the main key.
|
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
main_key = (hndl, pickle.loads(data)[1][1])
|
2005-12-15 23:18:48 +05:30
|
|
|
|
2006-07-19 09:59:04 +05:30
|
|
|
# The trick is not to remove while inside the cursor,
|
|
|
|
# but collect them all and remove after the cursor is closed
|
|
|
|
remove_list.add(main_key)
|
|
|
|
|
2005-12-15 23:18:48 +05:30
|
|
|
ret = primary_cur.next_dup()
|
|
|
|
|
|
|
|
primary_cur.close()
|
2006-07-19 09:59:04 +05:30
|
|
|
|
|
|
|
# Now that the cursor is closed, we can remove things
|
|
|
|
for main_key in remove_list:
|
2007-06-04 08:19:31 +05:30
|
|
|
self.__remove_reference(main_key, transaction, txn)
|
2005-12-15 23:18:48 +05:30
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def update_reference_map(self, obj, transaction, txn=None):
|
2006-01-18 02:40:20 +05:30
|
|
|
"""
|
2006-01-21 03:22:26 +05:30
|
|
|
If txn is given, then changes are written right away using txn.
|
2006-01-18 02:40:20 +05:30
|
|
|
"""
|
|
|
|
|
2005-12-15 23:02:10 +05:30
|
|
|
# Add references to the reference_map for all primary object referenced
|
2008-02-24 19:25:55 +05:30
|
|
|
# from the primary object 'obj, or any of its secondary objects.
|
2005-12-15 23:02:10 +05:30
|
|
|
|
2006-02-01 11:55:51 +05:30
|
|
|
handle = obj.handle
|
2008-07-17 23:40:32 +05:30
|
|
|
update = str(handle) in self.reference_map_primary_map
|
2006-01-21 00:53:42 +05:30
|
|
|
|
2006-01-21 03:22:26 +05:30
|
|
|
if update:
|
2006-01-18 02:40:20 +05:30
|
|
|
# First thing to do is get hold of all rows in the reference_map
|
2006-02-01 11:55:51 +05:30
|
|
|
# table that hold a reference from this primary obj. This means
|
|
|
|
# finding all the rows that have this handle somewhere in the
|
2007-06-04 08:19:31 +05:30
|
|
|
# list of (class_name, handle) pairs.
|
2006-02-01 11:55:51 +05:30
|
|
|
# The primary_map sec index allows us to look this up quickly.
|
2005-12-15 23:02:10 +05:30
|
|
|
|
2006-01-18 02:40:20 +05:30
|
|
|
existing_references = set()
|
2005-12-15 23:02:10 +05:30
|
|
|
|
2006-01-18 02:40:20 +05:30
|
|
|
primary_cur = self.get_reference_map_primary_cursor()
|
2005-12-15 23:02:10 +05:30
|
|
|
|
2006-01-18 02:40:20 +05:30
|
|
|
try:
|
|
|
|
ret = primary_cur.set(handle)
|
|
|
|
except:
|
|
|
|
ret = None
|
2005-12-15 23:02:10 +05:30
|
|
|
|
2006-01-18 02:40:20 +05:30
|
|
|
while (ret is not None):
|
2007-06-04 08:19:31 +05:30
|
|
|
(key, data) = ret
|
2006-01-18 02:40:20 +05:30
|
|
|
|
|
|
|
# data values are of the form:
|
|
|
|
# ((primary_object_class_name, primary_object_handle),
|
|
|
|
# (referenced_object_class_name, referenced_object_handle))
|
|
|
|
# so we need the second tuple give us a reference that we can
|
2006-02-01 11:55:51 +05:30
|
|
|
# compare with what is returned from
|
|
|
|
# get_referenced_handles_recursively
|
2006-01-18 02:40:20 +05:30
|
|
|
|
2006-02-01 11:55:51 +05:30
|
|
|
# secondary DBs are not DBShelf's, so we need to do pickling
|
|
|
|
# and unpicking ourselves here
|
2006-05-20 00:24:21 +05:30
|
|
|
existing_reference = pickle.loads(data)[1]
|
2006-02-01 11:55:51 +05:30
|
|
|
existing_references.add(
|
|
|
|
(KEY_TO_CLASS_MAP[existing_reference[0]],
|
|
|
|
existing_reference[1]))
|
2006-01-18 02:40:20 +05:30
|
|
|
ret = primary_cur.next_dup()
|
|
|
|
|
|
|
|
primary_cur.close()
|
|
|
|
|
2006-02-01 11:55:51 +05:30
|
|
|
# Once we have the list of rows that already have a reference
|
|
|
|
# we need to compare it with the list of objects that are
|
|
|
|
# still references from the primary object.
|
2006-01-18 02:40:20 +05:30
|
|
|
|
|
|
|
current_references = set(obj.get_referenced_handles_recursively())
|
|
|
|
|
2006-02-01 11:55:51 +05:30
|
|
|
no_longer_required_references = existing_references.difference(
|
|
|
|
current_references)
|
2006-01-18 02:40:20 +05:30
|
|
|
|
|
|
|
new_references = current_references.difference(existing_references)
|
|
|
|
|
|
|
|
else:
|
2006-05-20 00:24:21 +05:30
|
|
|
# No existing refs are found:
|
|
|
|
# all we have is new, nothing to remove
|
|
|
|
no_longer_required_references = set()
|
2006-01-18 02:40:20 +05:30
|
|
|
new_references = set(obj.get_referenced_handles_recursively())
|
|
|
|
|
2005-12-15 23:02:10 +05:30
|
|
|
# handle addition of new references
|
2007-06-04 08:19:31 +05:30
|
|
|
for (ref_class_name, ref_handle) in new_references:
|
|
|
|
data = ((CLASS_TO_KEY_MAP[obj.__class__.__name__], handle),
|
|
|
|
(CLASS_TO_KEY_MAP[ref_class_name], ref_handle), )
|
|
|
|
self.__add_reference((handle, ref_handle), data, transaction, txn)
|
2005-12-18 03:32:48 +05:30
|
|
|
|
2006-05-20 00:24:21 +05:30
|
|
|
# handle deletion of old references
|
2007-06-04 08:19:31 +05:30
|
|
|
for (ref_class_name, ref_handle) in no_longer_required_references:
|
2006-05-20 00:24:21 +05:30
|
|
|
try:
|
2007-06-04 08:19:31 +05:30
|
|
|
self.__remove_reference((handle, ref_handle), transaction, txn)
|
2006-05-20 00:24:21 +05:30
|
|
|
except:
|
|
|
|
# ignore missing old reference
|
|
|
|
pass
|
2005-12-15 23:02:10 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def __remove_reference(self, key, transaction, txn=None):
|
2006-01-13 03:32:58 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Remove the reference specified by the key,
|
2006-01-13 03:32:58 +05:30
|
|
|
preserving the change in the passed transaction.
|
|
|
|
"""
|
|
|
|
if not self.readonly:
|
2006-01-21 03:22:26 +05:30
|
|
|
if transaction.batch:
|
2007-06-04 08:19:31 +05:30
|
|
|
self.reference_map.delete(str(key), txn=txn)
|
2006-03-08 23:14:29 +05:30
|
|
|
if not self.UseTXN:
|
|
|
|
self.reference_map.sync()
|
2006-01-21 03:22:26 +05:30
|
|
|
else:
|
2007-06-04 08:19:31 +05:30
|
|
|
old_data = self.reference_map.get(str(key), txn=self.txn)
|
|
|
|
transaction.add(REFERENCE_KEY, str(key), old_data, None)
|
2006-01-21 03:22:26 +05:30
|
|
|
transaction.reference_del.append(str(key))
|
2006-01-13 03:32:58 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def __add_reference(self, key, data, transaction, txn=None):
|
2006-01-13 03:32:58 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Add the reference specified by the key and the data,
|
2006-01-13 03:32:58 +05:30
|
|
|
preserving the change in the passed transaction.
|
|
|
|
"""
|
|
|
|
|
|
|
|
if self.readonly or not key:
|
|
|
|
return
|
|
|
|
|
|
|
|
if transaction.batch:
|
2007-06-04 08:19:31 +05:30
|
|
|
self.reference_map.put(str(key), data, txn=txn)
|
2006-03-08 23:14:29 +05:30
|
|
|
if not self.UseTXN:
|
|
|
|
self.reference_map.sync()
|
2006-01-13 03:32:58 +05:30
|
|
|
else:
|
2007-06-04 08:19:31 +05:30
|
|
|
transaction.add(REFERENCE_KEY, str(key), None, data)
|
|
|
|
transaction.reference_add.append((str(key), data))
|
2006-01-13 03:32:58 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def reindex_reference_map(self, callback):
|
2006-05-20 00:24:21 +05:30
|
|
|
"""
|
|
|
|
Reindex all primary records in the database.
|
|
|
|
This will be a slow process for large databases.
|
2005-12-16 17:29:13 +05:30
|
|
|
|
|
|
|
"""
|
|
|
|
|
2006-12-01 13:53:51 +05:30
|
|
|
# First, remove the reference map and related tables
|
|
|
|
self.reference_map_referenced_map.close()
|
|
|
|
junk = db.DB(self.env)
|
2007-06-04 08:19:31 +05:30
|
|
|
junk.remove(self.full_name, "reference_map_referenced_map")
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
if callback:
|
|
|
|
callback(1)
|
2006-12-01 13:53:51 +05:30
|
|
|
|
|
|
|
self.reference_map_primary_map.close()
|
|
|
|
junk = db.DB(self.env)
|
2007-06-04 08:19:31 +05:30
|
|
|
junk.remove(self.full_name, "reference_map_primary_map")
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
if callback:
|
|
|
|
callback(2)
|
2006-12-01 13:53:51 +05:30
|
|
|
|
|
|
|
self.reference_map.close()
|
|
|
|
junk = db.DB(self.env)
|
2007-06-04 08:19:31 +05:30
|
|
|
junk.remove(self.full_name, "reference_map")
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
if callback:
|
|
|
|
callback(3)
|
2006-12-01 13:53:51 +05:30
|
|
|
|
|
|
|
# Open reference_map and primapry map
|
2007-06-04 08:19:31 +05:30
|
|
|
self.reference_map = self.__open_table(self.full_name, "reference_map",
|
|
|
|
dbtype=db.DB_BTREE)
|
2006-12-01 13:53:51 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
open_flags = self.__open_flags()
|
2006-12-01 13:53:51 +05:30
|
|
|
self.reference_map_primary_map = db.DB(self.env)
|
|
|
|
self.reference_map_primary_map.set_flags(db.DB_DUP)
|
|
|
|
self.reference_map_primary_map.open(self.full_name,
|
|
|
|
"reference_map_primary_map",
|
|
|
|
db.DB_BTREE, flags=open_flags)
|
|
|
|
self.reference_map.associate(self.reference_map_primary_map,
|
2007-06-04 08:29:36 +05:30
|
|
|
find_primary_handle,
|
2006-12-01 13:53:51 +05:30
|
|
|
open_flags)
|
2005-12-16 17:29:13 +05:30
|
|
|
|
|
|
|
# Make a dictionary of the functions and classes that we need for
|
|
|
|
# each of the primary object tables.
|
2006-05-20 00:24:21 +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,
|
|
|
|
'class_func': Repository},
|
2007-02-20 06:09:10 +05:30
|
|
|
'Note': {'cursor_func': self.get_note_cursor,
|
|
|
|
'class_func': Note},
|
2006-05-20 00:24:21 +05:30
|
|
|
}
|
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
transaction = self.transaction_begin(batch=True, no_magic=True)
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
if callback:
|
|
|
|
callback(4)
|
2006-12-01 13:53:51 +05:30
|
|
|
|
2006-05-20 00:24:21 +05:30
|
|
|
# Now we use the functions and classes defined above
|
|
|
|
# to loop through each of the primary object tables.
|
2009-06-16 21:19:17 +05:30
|
|
|
for primary_table_name, funcs in primary_tables.iteritems():
|
|
|
|
with funcs['cursor_func']() as cursor:
|
2005-12-16 17:29:13 +05:30
|
|
|
|
2006-05-20 00:24:21 +05:30
|
|
|
# Grab the real object class here so that the lookup does
|
|
|
|
# not happen inside the cursor loop.
|
2009-06-16 21:19:17 +05:30
|
|
|
class_func = funcs['class_func']
|
|
|
|
for found_handle, val in cursor:
|
|
|
|
obj = class_func()
|
|
|
|
obj.unserialize(val)
|
|
|
|
|
|
|
|
if self.UseTXN:
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
else:
|
|
|
|
the_txn = None
|
|
|
|
self.update_reference_map(obj, transaction, the_txn)
|
|
|
|
if not self.UseTXN:
|
|
|
|
self.reference_map.sync()
|
|
|
|
if the_txn:
|
|
|
|
the_txn.commit()
|
2005-12-16 17:29:13 +05:30
|
|
|
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
if callback:
|
|
|
|
callback(5)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.transaction_commit(transaction, _("Rebuild reference map"))
|
2006-12-01 13:53:51 +05:30
|
|
|
|
|
|
|
self.reference_map_referenced_map = db.DB(self.env)
|
|
|
|
self.reference_map_referenced_map.set_flags(db.DB_DUP|db.DB_DUPSORT)
|
|
|
|
self.reference_map_referenced_map.open(
|
2007-06-04 08:19:31 +05:30
|
|
|
self.full_name, "reference_map_referenced_map",
|
|
|
|
db.DB_BTREE, flags=open_flags)
|
2006-12-01 13:53:51 +05:30
|
|
|
self.reference_map.associate(self.reference_map_referenced_map,
|
2007-06-04 08:29:36 +05:30
|
|
|
find_referenced_handle, open_flags)
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
if callback:
|
|
|
|
callback(6)
|
2005-12-16 17:29:13 +05:30
|
|
|
|
|
|
|
return
|
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def __close_metadata(self):
|
2006-05-19 05:35:44 +05:30
|
|
|
if not self.readonly:
|
2006-08-13 03:25:52 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
# Start transaction if needed
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
else:
|
|
|
|
the_txn = None
|
2006-08-12 05:16:24 +05:30
|
|
|
|
2006-07-06 23:16:46 +05:30
|
|
|
# name display formats
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('name_formats', self.name_formats, txn=the_txn)
|
2007-02-05 05:29:03 +05:30
|
|
|
|
|
|
|
# database owner
|
|
|
|
self.metadata.put('researcher', self.owner, txn=the_txn)
|
2006-12-21 08:58:44 +05:30
|
|
|
|
2006-05-19 05:35:44 +05:30
|
|
|
# bookmarks
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('bookmarks', self.bookmarks.get(), txn=the_txn)
|
|
|
|
self.metadata.put('family_bookmarks', self.family_bookmarks.get(),
|
2006-12-21 08:58:44 +05:30
|
|
|
txn=the_txn)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('event_bookmarks', self.event_bookmarks.get(),
|
2006-08-12 05:16:24 +05:30
|
|
|
txn=the_txn)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('source_bookmarks', self.source_bookmarks.get(),
|
2006-08-12 05:16:24 +05:30
|
|
|
txn=the_txn)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('place_bookmarks', self.place_bookmarks.get(),
|
2006-08-12 05:16:24 +05:30
|
|
|
txn=the_txn)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('repo_bookmarks', self.repo_bookmarks.get(),
|
2006-08-12 05:16:24 +05:30
|
|
|
txn=the_txn)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('media_bookmarks', self.media_bookmarks.get(),
|
2006-08-12 05:16:24 +05:30
|
|
|
txn=the_txn)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('note_bookmarks', self.note_bookmarks.get(),
|
2007-03-28 03:17:18 +05:30
|
|
|
txn=the_txn)
|
2006-12-21 08:58:44 +05:30
|
|
|
|
2006-05-19 05:35:44 +05:30
|
|
|
# gender stats
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('gender_stats', self.genderStats.save_stats(),
|
2006-08-12 05:16:24 +05:30
|
|
|
txn=the_txn)
|
2006-05-19 05:35:44 +05:30
|
|
|
# Custom type values
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('fevent_names', list(self.family_event_names),
|
2006-08-12 05:16:24 +05:30
|
|
|
txn=the_txn)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('pevent_names', list(self.individual_event_names),
|
2006-08-12 05:16:24 +05:30
|
|
|
txn=the_txn)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('fattr_names', list(self.family_attributes),
|
2006-08-12 05:16:24 +05:30
|
|
|
txn=the_txn)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('pattr_names', list(self.individual_attributes),
|
2006-08-12 05:16:24 +05:30
|
|
|
txn=the_txn)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('marker_names', list(self.marker_names),
|
2006-08-12 05:16:24 +05:30
|
|
|
txn=the_txn)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('child_refs', list(self.child_ref_types),
|
2006-08-12 05:16:24 +05:30
|
|
|
txn=the_txn)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('family_rels', list(self.family_rel_types),
|
2006-08-12 05:16:24 +05:30
|
|
|
txn=the_txn)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('event_roles', list(self.event_role_names),
|
2006-08-12 05:16:24 +05:30
|
|
|
txn=the_txn)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('name_types', list(self.name_types),
|
2006-08-12 05:16:24 +05:30
|
|
|
txn=the_txn)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('repo_types', list(self.repository_types),
|
2006-08-12 05:16:24 +05:30
|
|
|
txn=the_txn)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('note_types', list(self.note_types),
|
2007-02-20 06:09:10 +05:30
|
|
|
txn=the_txn)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('sm_types', list(self.source_media_types),
|
2006-08-12 05:16:24 +05:30
|
|
|
txn=the_txn)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('url_types', list(self.url_types),
|
2006-08-12 05:16:24 +05:30
|
|
|
txn=the_txn)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('mattr_names', list(self.media_attributes),
|
2006-08-12 05:16:24 +05:30
|
|
|
txn=the_txn)
|
2007-01-19 22:23:49 +05:30
|
|
|
# name display formats
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('surname_list', self.surname_list, txn=the_txn)
|
2007-01-19 22:23:49 +05:30
|
|
|
|
2006-08-13 03:25:52 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
the_txn.commit()
|
|
|
|
else:
|
|
|
|
self.metadata.sync()
|
2006-05-19 05:35:44 +05:30
|
|
|
|
|
|
|
self.metadata.close()
|
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def __close_early(self):
|
2006-05-18 02:46:59 +05:30
|
|
|
"""
|
|
|
|
Bail out if the incompatible version is discovered:
|
2006-10-29 10:06:08 +05:30
|
|
|
* close cleanly to not damage data/env
|
|
|
|
* raise exception
|
2006-05-18 02:46:59 +05:30
|
|
|
"""
|
|
|
|
self.metadata.close()
|
|
|
|
self.env.close()
|
|
|
|
self.metadata = None
|
|
|
|
self.env = None
|
|
|
|
self.db_is_open = False
|
2009-12-23 21:25:58 +05:30
|
|
|
raise DbVersionError()
|
2006-05-18 02:46:59 +05:30
|
|
|
|
2004-07-31 00:26:49 +05:30
|
|
|
def close(self):
|
2006-01-11 03:58:09 +05:30
|
|
|
if not self.db_is_open:
|
2005-04-04 06:41:50 +05:30
|
|
|
return
|
2006-05-19 05:35:44 +05:30
|
|
|
|
2006-04-25 22:32:37 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
self.env.txn_checkpoint()
|
2006-08-13 05:53:06 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
self.__close_metadata()
|
2006-04-25 22:32:37 +05:30
|
|
|
self.name_group.close()
|
2004-07-31 00:26:49 +05:30
|
|
|
self.surnames.close()
|
|
|
|
self.id_trans.close()
|
2004-08-20 07:50:06 +05:30
|
|
|
self.fid_trans.close()
|
2005-06-08 10:10:33 +05:30
|
|
|
self.eid_trans.close()
|
2005-05-27 23:13:04 +05:30
|
|
|
self.rid_trans.close()
|
2007-02-20 06:09:10 +05:30
|
|
|
self.nid_trans.close()
|
2004-08-24 09:18:15 +05:30
|
|
|
self.oid_trans.close()
|
|
|
|
self.sid_trans.close()
|
|
|
|
self.pid_trans.close()
|
2005-12-22 10:06:26 +05:30
|
|
|
self.reference_map_primary_map.close()
|
|
|
|
self.reference_map_referenced_map.close()
|
2006-01-25 23:29:22 +05:30
|
|
|
self.reference_map.close()
|
|
|
|
|
|
|
|
# primary databases must be closed after secondary indexes, or
|
|
|
|
# we run into problems with any active cursors.
|
|
|
|
self.person_map.close()
|
|
|
|
self.family_map.close()
|
|
|
|
self.repository_map.close()
|
2007-02-20 06:09:10 +05:30
|
|
|
self.note_map.close()
|
2006-01-25 23:29:22 +05:30
|
|
|
self.place_map.close()
|
|
|
|
self.source_map.close()
|
|
|
|
self.media_map.close()
|
|
|
|
self.event_map.close()
|
2004-07-31 00:26:49 +05:30
|
|
|
self.env.close()
|
|
|
|
|
2006-10-24 08:11:02 +05:30
|
|
|
try:
|
|
|
|
self.close_undodb()
|
|
|
|
except db.DBNoSuchFileError:
|
|
|
|
pass
|
2006-05-07 10:52:44 +05:30
|
|
|
|
2005-05-27 23:13:04 +05:30
|
|
|
self.person_map = None
|
|
|
|
self.family_map = None
|
|
|
|
self.repository_map = None
|
2007-02-20 06:09:10 +05:30
|
|
|
self.note_map = None
|
2005-05-27 23:13:04 +05:30
|
|
|
self.place_map = None
|
|
|
|
self.source_map = None
|
|
|
|
self.media_map = None
|
|
|
|
self.event_map = None
|
|
|
|
self.surnames = None
|
2007-12-09 15:48:59 +05:30
|
|
|
self.name_group = None
|
2005-05-27 23:13:04 +05:30
|
|
|
self.env = None
|
|
|
|
self.metadata = None
|
2006-01-11 03:58:09 +05:30
|
|
|
self.db_is_open = False
|
2004-07-31 00:26:49 +05:30
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def do_remove_object(self, handle, transaction, data_map, key, del_list):
|
2006-04-10 07:15:36 +05:30
|
|
|
if self.readonly or not handle:
|
|
|
|
return
|
|
|
|
|
|
|
|
handle = str(handle)
|
|
|
|
if transaction.batch:
|
|
|
|
if self.UseTXN:
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
else:
|
|
|
|
the_txn = None
|
2007-06-26 11:32:17 +05:30
|
|
|
self.delete_primary_from_reference_map(handle, transaction,
|
2006-04-10 07:15:36 +05:30
|
|
|
txn=the_txn)
|
2007-06-04 08:19:31 +05:30
|
|
|
data_map.delete(handle, txn=the_txn)
|
2006-04-10 07:15:36 +05:30
|
|
|
if not self.UseTXN:
|
|
|
|
data_map.sync()
|
|
|
|
if the_txn:
|
|
|
|
the_txn.commit()
|
|
|
|
else:
|
2007-06-26 11:32:17 +05:30
|
|
|
self.delete_primary_from_reference_map(handle, transaction)
|
2007-06-04 08:19:31 +05:30
|
|
|
old_data = data_map.get(handle, txn=self.txn)
|
|
|
|
transaction.add(key, handle, old_data, None)
|
2006-01-13 05:04:33 +05:30
|
|
|
del_list.append(handle)
|
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def del_person(self, handle):
|
2007-06-04 08:19:31 +05:30
|
|
|
self.person_map.delete(str(handle), txn=self.txn)
|
2006-03-08 23:14:29 +05:30
|
|
|
if not self.UseTXN:
|
|
|
|
self.person_map.sync()
|
2005-04-18 04:04:56 +05:30
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def del_source(self, handle):
|
2007-06-04 08:19:31 +05:30
|
|
|
self.source_map.delete(str(handle), txn=self.txn)
|
2006-03-08 23:14:29 +05:30
|
|
|
if not self.UseTXN:
|
|
|
|
self.source_map.sync()
|
2005-04-18 04:04:56 +05:30
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def del_repository(self, handle):
|
2007-06-04 08:19:31 +05:30
|
|
|
self.repository_map.delete(str(handle), txn=self.txn)
|
2006-03-08 23:14:29 +05:30
|
|
|
if not self.UseTXN:
|
|
|
|
self.repository_map.sync()
|
2005-05-27 23:13:04 +05:30
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def del_note(self, handle):
|
2007-06-04 08:19:31 +05:30
|
|
|
self.note_map.delete(str(handle), txn=self.txn)
|
2007-02-20 06:09:10 +05:30
|
|
|
if not self.UseTXN:
|
|
|
|
self.note_map.sync()
|
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def del_place(self, handle):
|
2007-06-04 08:19:31 +05:30
|
|
|
self.place_map.delete(str(handle), txn=self.txn)
|
2006-03-08 23:14:29 +05:30
|
|
|
if not self.UseTXN:
|
|
|
|
self.place_map.sync()
|
2005-04-18 04:04:56 +05:30
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def del_media(self, handle):
|
2007-06-04 08:19:31 +05:30
|
|
|
self.media_map.delete(str(handle), txn=self.txn)
|
2006-03-08 23:14:29 +05:30
|
|
|
if not self.UseTXN:
|
|
|
|
self.media_map.sync()
|
2005-04-18 04:04:56 +05:30
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def del_family(self, handle):
|
2007-06-04 08:19:31 +05:30
|
|
|
self.family_map.delete(str(handle), txn=self.txn)
|
2006-03-08 23:14:29 +05:30
|
|
|
if not self.UseTXN:
|
|
|
|
self.family_map.sync()
|
2005-04-18 04:04:56 +05:30
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def del_event(self, handle):
|
2007-06-04 08:19:31 +05:30
|
|
|
self.event_map.delete(str(handle), txn=self.txn)
|
2006-03-08 23:14:29 +05:30
|
|
|
if not self.UseTXN:
|
|
|
|
self.event_map.sync()
|
2005-04-18 04:04:56 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def set_name_group_mapping(self, name, group):
|
2007-10-09 18:35:56 +05:30
|
|
|
"""Make name group under the value of group.
|
|
|
|
If group =None, the old grouping is deleted
|
|
|
|
"""
|
2005-02-17 04:19:54 +05:30
|
|
|
if not self.readonly:
|
2006-08-01 21:54:27 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
# Start transaction if needed
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
else:
|
|
|
|
the_txn = None
|
2005-02-17 04:19:54 +05:30
|
|
|
name = str(name)
|
2007-06-04 08:19:31 +05:30
|
|
|
data = self.name_group.get(name, txn=the_txn)
|
2007-10-09 18:35:56 +05:30
|
|
|
if data is not None:
|
2007-06-04 08:19:31 +05:30
|
|
|
self.name_group.delete(name, txn=the_txn)
|
2007-10-09 18:35:56 +05:30
|
|
|
if group is not None:
|
|
|
|
self.name_group.put(name,group,txn=the_txn)
|
2006-08-01 21:54:27 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
the_txn.commit()
|
2005-02-17 04:19:54 +05:30
|
|
|
else:
|
2006-08-01 21:54:27 +05:30
|
|
|
self.name_group.sync()
|
2005-08-18 11:28:28 +05:30
|
|
|
self.emit('person-rebuild')
|
2006-01-27 12:24:35 +05:30
|
|
|
|
2007-01-19 22:23:49 +05:30
|
|
|
def build_surname_list(self):
|
|
|
|
self.surname_list = list(set(self.surnames.keys()))
|
|
|
|
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.
|
|
|
|
The function must be overridden in the derived class.
|
|
|
|
"""
|
|
|
|
name = str(person.get_primary_name().get_surname())
|
2007-01-22 03:02:53 +05:30
|
|
|
try:
|
|
|
|
if self.surnames.keys().count(name) == 1:
|
|
|
|
self.surname_list.remove(unicode(name))
|
|
|
|
except ValueError:
|
|
|
|
pass
|
2004-07-31 00:26:49 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def __get_obj_from_gramps_id(self, val, tbl, class_init, prim_tbl):
|
2008-07-18 02:33:26 +05:30
|
|
|
if tbl.has_key(str(val)):
|
|
|
|
#if str(val) in tbl:
|
2007-06-04 08:19:31 +05:30
|
|
|
data = tbl.get(str(val), txn=self.txn)
|
2005-12-22 11:10:27 +05:30
|
|
|
obj = class_init()
|
2006-07-28 09:40:43 +05:30
|
|
|
### FIXME: this is a dirty hack that works without no
|
|
|
|
### sensible explanation. For some reason, for a readonly
|
|
|
|
### database, secondary index returns a primary table key
|
|
|
|
### corresponding to the data, not the data.
|
|
|
|
if self.readonly:
|
2007-06-04 08:19:31 +05:30
|
|
|
tuple_data = prim_tbl.get(data, txn=self.txn)
|
2006-07-28 09:40:43 +05:30
|
|
|
else:
|
|
|
|
tuple_data = pickle.loads(data)
|
|
|
|
obj.unserialize(tuple_data)
|
2006-01-07 03:38:40 +05:30
|
|
|
return obj
|
2004-08-20 07:50:06 +05:30
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def get_person_from_gramps_id(self, val):
|
2006-05-20 00:24:21 +05:30
|
|
|
"""
|
|
|
|
Finds a Person in the database from the passed gramps' ID.
|
|
|
|
If no such Person exists, None is returned.
|
|
|
|
"""
|
2007-06-04 08:19:31 +05:30
|
|
|
return self.__get_obj_from_gramps_id(val, self.id_trans, Person,
|
2006-07-28 09:40:43 +05:30
|
|
|
self.person_map)
|
2005-12-22 11:10:27 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def get_family_from_gramps_id(self, val):
|
2006-05-20 00:24:21 +05:30
|
|
|
"""
|
|
|
|
Finds a Family in the database from the passed gramps' ID.
|
|
|
|
If no such Family exists, None is return.
|
|
|
|
"""
|
2007-06-04 08:19:31 +05:30
|
|
|
return self.__get_obj_from_gramps_id(val, self.fid_trans, Family,
|
2006-07-28 09:40:43 +05:30
|
|
|
self.family_map)
|
2005-06-08 10:10:33 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def get_event_from_gramps_id(self, val):
|
2006-05-20 00:24:21 +05:30
|
|
|
"""
|
|
|
|
Finds an Event in the database from the passed gramps' ID.
|
|
|
|
If no such Family exists, None is returned.
|
|
|
|
"""
|
2007-06-04 08:19:31 +05:30
|
|
|
return self.__get_obj_from_gramps_id(val, self.eid_trans, Event,
|
2006-07-28 09:40:43 +05:30
|
|
|
self.event_map)
|
2006-01-27 12:24:35 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def get_place_from_gramps_id(self, val):
|
2006-05-20 00:24:21 +05:30
|
|
|
"""
|
|
|
|
Finds a Place in the database from the passed gramps' ID.
|
|
|
|
If no such Place exists, None is returned.
|
|
|
|
"""
|
2007-06-04 08:19:31 +05:30
|
|
|
return self.__get_obj_from_gramps_id(val, self.pid_trans, Place,
|
2006-07-28 09:40:43 +05:30
|
|
|
self.place_map)
|
2004-08-24 09:18:15 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def get_source_from_gramps_id(self, val):
|
2006-05-20 00:24:21 +05:30
|
|
|
"""
|
|
|
|
Finds a Source in the database from the passed gramps' ID.
|
|
|
|
If no such Source exists, None is returned.
|
|
|
|
"""
|
2007-06-04 08:19:31 +05:30
|
|
|
return self.__get_obj_from_gramps_id(val, self.sid_trans, Source,
|
2006-07-28 09:40:43 +05:30
|
|
|
self.source_map)
|
2005-05-27 23:13:04 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def get_object_from_gramps_id(self, val):
|
2006-05-20 00:24:21 +05:30
|
|
|
"""
|
|
|
|
Finds a MediaObject in the database from the passed gramps' ID.
|
|
|
|
If no such MediaObject exists, None is returned.
|
|
|
|
"""
|
2007-06-04 08:19:31 +05:30
|
|
|
return self.__get_obj_from_gramps_id(val, self.oid_trans, MediaObject,
|
2006-07-28 09:40:43 +05:30
|
|
|
self.media_map)
|
2004-08-24 09:18:15 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def get_repository_from_gramps_id(self, val):
|
2006-05-20 00:24:21 +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.
|
2006-05-20 00:24:21 +05:30
|
|
|
"""
|
2007-06-04 08:19:31 +05:30
|
|
|
return self.__get_obj_from_gramps_id(val, self.rid_trans, Repository,
|
2006-07-28 09:40:43 +05:30
|
|
|
self.repository_map)
|
2005-03-03 11:03:22 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def get_note_from_gramps_id(self, val):
|
2007-02-20 06:09:10 +05:30
|
|
|
"""
|
|
|
|
Finds a Note in the database from the passed gramps' ID.
|
|
|
|
If no such Note exists, None is returned.
|
|
|
|
"""
|
2007-06-04 08:19:31 +05:30
|
|
|
return self.__get_obj_from_gramps_id(val, self.nid_trans, Note,
|
2007-02-20 06:09:10 +05:30
|
|
|
self.note_map)
|
|
|
|
|
2007-06-25 21:52:38 +05:30
|
|
|
def commit_base(self, obj, data_map, key, update_list, add_list,
|
2006-01-07 02:25:49 +05:30
|
|
|
transaction, change_time):
|
|
|
|
"""
|
2006-05-20 00:24:21 +05:30
|
|
|
Commits the specified object to the database, storing the changes
|
2006-01-07 02:25:49 +05:30
|
|
|
as part of the transaction.
|
|
|
|
"""
|
|
|
|
if self.readonly or not obj or not obj.handle:
|
|
|
|
return
|
|
|
|
|
|
|
|
if change_time:
|
|
|
|
obj.change = int(change_time)
|
|
|
|
else:
|
|
|
|
obj.change = int(time.time())
|
|
|
|
handle = str(obj.handle)
|
|
|
|
|
|
|
|
if transaction.batch:
|
2006-03-08 22:52:45 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
else:
|
|
|
|
the_txn = None
|
2007-06-26 11:32:17 +05:30
|
|
|
self.update_reference_map(obj, transaction, txn=the_txn)
|
2007-06-04 08:19:31 +05:30
|
|
|
data_map.put(handle, obj.serialize(), txn=the_txn)
|
2006-03-08 23:03:07 +05:30
|
|
|
if not self.UseTXN:
|
|
|
|
data_map.sync()
|
2006-03-08 22:52:45 +05:30
|
|
|
if the_txn:
|
|
|
|
the_txn.commit()
|
2006-01-07 02:25:49 +05:30
|
|
|
old_data = None
|
|
|
|
else:
|
2007-06-26 11:32:17 +05:30
|
|
|
self.update_reference_map(obj, transaction)
|
2007-06-04 08:19:31 +05:30
|
|
|
old_data = data_map.get(handle, txn=self.txn)
|
2006-01-13 05:04:33 +05:30
|
|
|
new_data = obj.serialize()
|
2007-06-04 08:19:31 +05:30
|
|
|
transaction.add(key, handle, old_data, new_data)
|
2006-01-07 02:25:49 +05:30
|
|
|
if old_data:
|
2007-06-04 08:19:31 +05:30
|
|
|
update_list.append((handle, new_data))
|
2006-01-07 02:25:49 +05:30
|
|
|
else:
|
2007-06-04 08:19:31 +05:30
|
|
|
add_list.append((handle, new_data))
|
2006-01-07 02:25:49 +05:30
|
|
|
return old_data
|
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def do_commit(self, add_list, db_map):
|
2006-01-07 02:25:49 +05:30
|
|
|
retlist = []
|
2007-06-04 08:19:31 +05:30
|
|
|
for (handle, data) in add_list:
|
|
|
|
db_map.put(handle, data, self.txn)
|
2006-03-08 23:14:29 +05:30
|
|
|
if not self.UseTXN:
|
|
|
|
db_map.sync()
|
2006-01-07 02:25:49 +05:30
|
|
|
retlist.append(str(handle))
|
|
|
|
return retlist
|
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def get_from_handle(self, handle, class_type, data_map):
|
2006-01-07 02:25:49 +05:30
|
|
|
try:
|
2007-06-04 08:19:31 +05:30
|
|
|
data = data_map.get(str(handle), txn=self.txn)
|
2006-01-07 02:25:49 +05:30
|
|
|
except:
|
|
|
|
data = None
|
2007-06-04 08:19:31 +05:30
|
|
|
# under certain circumstances during a database reload,
|
2006-04-25 08:25:41 +05:30
|
|
|
# data_map can be none. If so, then don't report an error
|
|
|
|
if data_map:
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.error("Failed to get from handle", exc_info=True)
|
2006-01-07 02:25:49 +05:30
|
|
|
if data:
|
|
|
|
newobj = class_type()
|
|
|
|
newobj.unserialize(data)
|
|
|
|
return newobj
|
|
|
|
return None
|
|
|
|
|
2007-06-26 11:32:17 +05:30
|
|
|
def find_from_handle(self, hndl, transaction, class_type, dmap, add_func):
|
2006-01-07 02:25:49 +05:30
|
|
|
obj = class_type()
|
2007-06-04 08:19:31 +05:30
|
|
|
hndl = str(hndl)
|
2008-02-29 04:02:40 +05:30
|
|
|
new = True
|
2008-07-17 23:40:32 +05:30
|
|
|
if hndl in dmap:
|
2007-06-04 08:19:31 +05:30
|
|
|
data = dmap.get(hndl, txn=self.txn)
|
2006-01-07 02:25:49 +05:30
|
|
|
obj.unserialize(data)
|
2008-02-29 04:02:40 +05:30
|
|
|
#references create object with id None before object is really made
|
|
|
|
if obj.gramps_id is not None:
|
|
|
|
new = False
|
2006-01-07 02:25:49 +05:30
|
|
|
else:
|
2007-06-04 08:19:31 +05:30
|
|
|
obj.set_handle(hndl)
|
|
|
|
add_func(obj, transaction)
|
2008-02-29 04:02:40 +05:30
|
|
|
return obj, new
|
2006-01-07 02:25:49 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def transaction_begin(self, msg="", batch=False, no_magic=False):
|
2006-01-07 02:48:50 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Create a new Transaction tied to the current UNDO database. The
|
2006-01-07 02:48:50 +05:30
|
|
|
transaction has no effect until it is committed using the
|
|
|
|
transaction_commit function of the this database object.
|
|
|
|
"""
|
2006-01-07 02:53:27 +05:30
|
|
|
|
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-04 06:08:25 +05:30
|
|
|
# Undo is also impossible after batch transaction
|
2009-09-01 00:12:29 +05:30
|
|
|
#self.undoindex = -1
|
|
|
|
#self.translist = [None] * len(self.translist)
|
2007-06-04 08:19:31 +05:30
|
|
|
transaction = BdbTransaction(msg, self.undodb, batch, no_magic)
|
2006-01-18 02:47:14 +05:30
|
|
|
if transaction.batch:
|
2006-03-08 22:52:45 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
self.env.txn_checkpoint()
|
2007-06-04 08:19:31 +05:30
|
|
|
self.env.set_flags(db.DB_TXN_NOSYNC, 1) # async txn
|
2006-02-02 20:23:31 +05:30
|
|
|
|
2006-02-04 03:33:53 +05:30
|
|
|
if self.secondary_connected and not transaction.no_magic:
|
2006-02-02 20:23:31 +05:30
|
|
|
# Disconnect unneeded secondary indices
|
|
|
|
self.surnames.close()
|
|
|
|
junk = db.DB(self.env)
|
2007-06-04 08:19:31 +05:30
|
|
|
junk.remove(self.full_name, "surnames")
|
2006-02-02 20:23:31 +05:30
|
|
|
|
|
|
|
self.reference_map_referenced_map.close()
|
|
|
|
junk = db.DB(self.env)
|
2007-06-04 08:19:31 +05:30
|
|
|
junk.remove(self.full_name, "reference_map_referenced_map")
|
2006-01-19 22:00:45 +05:30
|
|
|
|
2006-01-18 02:47:14 +05:30
|
|
|
return transaction
|
2006-01-07 02:48:50 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def transaction_commit(self, transaction, msg):
|
2006-01-07 02:48:50 +05:30
|
|
|
|
2006-01-17 03:37:24 +05:30
|
|
|
# Start BSD DB transaction -- DBTxn
|
2006-03-08 22:52:45 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
self.txn = self.env.txn_begin()
|
|
|
|
else:
|
|
|
|
self.txn = None
|
2006-01-17 03:37:24 +05:30
|
|
|
|
2009-12-23 21:25:58 +05:30
|
|
|
DbBase.transaction_commit(self, transaction, msg)
|
2006-01-07 02:25:49 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
for (key, data) in transaction.reference_add:
|
|
|
|
self.reference_map.put(str(key), data, txn=self.txn)
|
2006-01-13 03:32:58 +05:30
|
|
|
|
2006-02-07 02:54:39 +05:30
|
|
|
for key in transaction.reference_del:
|
2007-06-04 08:19:31 +05:30
|
|
|
self.reference_map.delete(str(key), txn=self.txn)
|
2006-01-13 03:32:58 +05:30
|
|
|
|
2006-03-09 03:31:08 +05:30
|
|
|
if (len(transaction.reference_add)+len(transaction.reference_del)) > 0\
|
|
|
|
and not self.UseTXN:
|
|
|
|
self.reference_map.sync()
|
|
|
|
|
2006-01-07 02:25:49 +05:30
|
|
|
# Commit BSD DB transaction -- DBTxn
|
2006-03-08 22:52:45 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
self.txn.commit()
|
2006-01-17 04:19:49 +05:30
|
|
|
if transaction.batch:
|
2006-03-08 22:52:45 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
self.env.txn_checkpoint()
|
2007-06-04 08:19:31 +05:30
|
|
|
self.env.set_flags(db.DB_TXN_NOSYNC, 0) # sync txn
|
2006-01-19 22:00:45 +05:30
|
|
|
|
2006-02-02 20:23:31 +05:30
|
|
|
if not transaction.no_magic:
|
|
|
|
# create new secondary indices to replace the ones removed
|
2007-06-04 08:19:31 +05:30
|
|
|
open_flags = self.__open_flags()
|
2006-02-02 20:23:31 +05:30
|
|
|
dupe_flags = db.DB_DUP|db.DB_DUPSORT
|
|
|
|
|
|
|
|
self.surnames = db.DB(self.env)
|
|
|
|
self.surnames.set_flags(dupe_flags)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.surnames.open(self.full_name, "surnames",
|
|
|
|
db.DB_BTREE, flags=open_flags)
|
2007-06-04 08:29:36 +05:30
|
|
|
self.person_map.associate(self.surnames, find_surname,
|
2006-02-02 20:23:31 +05:30
|
|
|
open_flags)
|
2006-01-19 22:00:45 +05:30
|
|
|
|
2006-02-02 20:23:31 +05:30
|
|
|
self.reference_map_referenced_map = db.DB(self.env)
|
|
|
|
self.reference_map_referenced_map.set_flags(dupe_flags)
|
|
|
|
self.reference_map_referenced_map.open(
|
2007-06-04 08:19:31 +05:30
|
|
|
self.full_name, "reference_map_referenced_map",
|
|
|
|
db.DB_BTREE, flags=open_flags)
|
|
|
|
self.reference_map.associate(self.reference_map_referenced_map,
|
2007-06-04 08:29:36 +05:30
|
|
|
find_referenced_handle, open_flags)
|
2007-01-19 22:23:49 +05:30
|
|
|
|
2007-01-20 22:25:08 +05:30
|
|
|
# Only build surname list after surname index is surely back
|
|
|
|
self.build_surname_list()
|
2007-01-19 22:23:49 +05:30
|
|
|
|
2006-01-07 02:25:49 +05:30
|
|
|
self.txn = None
|
2005-05-24 18:38:06 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def undo(self, update_history=True):
|
2006-03-08 22:52:45 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
self.txn = self.env.txn_begin()
|
2009-12-23 21:25:58 +05:30
|
|
|
status = DbBase.undo(self, update_history)
|
2006-03-08 22:52:45 +05:30
|
|
|
if self.UseTXN:
|
2006-05-04 04:51:49 +05:30
|
|
|
if status:
|
|
|
|
self.txn.commit()
|
|
|
|
else:
|
|
|
|
self.txn.abort()
|
2006-01-13 03:32:58 +05:30
|
|
|
self.txn = None
|
2006-05-04 04:51:49 +05:30
|
|
|
return status
|
2006-01-13 03:32:58 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def redo(self, update_history=True):
|
2006-03-08 22:52:45 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
self.txn = self.env.txn_begin()
|
2009-12-23 21:25:58 +05:30
|
|
|
status = DbBase.redo(self, update_history)
|
2006-03-08 22:52:45 +05:30
|
|
|
if self.UseTXN:
|
2006-05-04 04:51:49 +05:30
|
|
|
if status:
|
|
|
|
self.txn.commit()
|
|
|
|
else:
|
|
|
|
self.txn.abort()
|
|
|
|
self.txn = None
|
|
|
|
return status
|
2006-01-13 05:04:33 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def undo_reference(self, data, handle):
|
2008-06-16 20:31:46 +05:30
|
|
|
if data is None:
|
2007-06-04 08:19:31 +05:30
|
|
|
self.reference_map.delete(handle, txn=self.txn)
|
2006-01-13 03:32:58 +05:30
|
|
|
else:
|
2007-06-04 08:19:31 +05:30
|
|
|
self.reference_map.put(handle, data, txn=self.txn)
|
2006-01-13 03:32:58 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def undo_data(self, data, handle, db_map, signal_root):
|
2008-06-16 20:31:46 +05:30
|
|
|
if data is None:
|
2007-06-04 08:19:31 +05:30
|
|
|
self.emit(signal_root + '-delete', ([handle], ))
|
|
|
|
db_map.delete(handle, txn=self.txn)
|
2006-01-13 03:32:58 +05:30
|
|
|
else:
|
2007-06-04 08:19:31 +05:30
|
|
|
ex_data = db_map.get(handle, txn=self.txn)
|
2006-01-13 03:32:58 +05:30
|
|
|
if ex_data:
|
|
|
|
signal = signal_root + '-update'
|
|
|
|
else:
|
|
|
|
signal = signal_root + '-add'
|
2007-06-04 08:19:31 +05:30
|
|
|
db_map.put(handle, data, txn=self.txn)
|
|
|
|
self.emit(signal, ([handle], ))
|
2006-01-13 03:32:58 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
def gramps_upgrade(self, callback=None):
|
|
|
|
UpdateCallback.__init__(self, callback)
|
2006-05-20 00:24:21 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
version = self.metadata.get('version', default=_MINVERSION)
|
2006-09-24 10:07:59 +05:30
|
|
|
|
2006-03-16 05:28:23 +05:30
|
|
|
t = time.time()
|
2007-02-22 13:22:54 +05:30
|
|
|
if version < 10:
|
|
|
|
self.gramps_upgrade_10()
|
|
|
|
if version < 11:
|
|
|
|
self.gramps_upgrade_11()
|
|
|
|
if version < 12:
|
|
|
|
self.gramps_upgrade_12()
|
|
|
|
if version < 13:
|
|
|
|
self.gramps_upgrade_13()
|
2009-04-01 02:51:55 +05:30
|
|
|
if version < 14:
|
|
|
|
self.gramps_upgrade_14()
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Upgrade time: %s %s", int(time.time()-t), "seconds")
|
2005-04-01 10:04:31 +05:30
|
|
|
|
2006-08-15 10:54:38 +05:30
|
|
|
def gramps_upgrade_10(self):
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Upgrading to DB version 10...")
|
2006-08-21 12:02:31 +05:30
|
|
|
|
2006-08-15 10:54:38 +05:30
|
|
|
# This upgrade adds attribute lists to Event and EventRef objects
|
2006-08-15 21:03:28 +05:30
|
|
|
length = self.get_number_of_events() + len(self.person_map) \
|
|
|
|
+ self.get_number_of_families()
|
|
|
|
self.set_total(length)
|
2006-08-15 10:54:38 +05:30
|
|
|
|
2009-05-23 02:04:05 +05:30
|
|
|
for handle in self.event_map.keys():
|
|
|
|
info = self.event_map[handle]
|
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
(junk_handle, gramps_id, the_type, date, description,
|
|
|
|
place, cause, source_list, note, media_list,
|
2006-08-15 21:03:28 +05:30
|
|
|
change, marker, private) = info
|
|
|
|
|
|
|
|
# Cause is removed, so we're converting it into an attribute
|
2006-08-15 10:54:38 +05:30
|
|
|
if cause.strip():
|
|
|
|
attr = Attribute()
|
|
|
|
attr.set_type(AttributeType.CAUSE)
|
|
|
|
attr.set_value(cause)
|
2006-10-07 11:26:58 +05:30
|
|
|
attr_list = [attr.serialize()]
|
|
|
|
else:
|
|
|
|
attr_list = []
|
2006-08-15 10:54:38 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
info = (handle, gramps_id, the_type, date,
|
|
|
|
description, place, source_list, note, media_list,
|
2006-10-07 11:26:58 +05:30
|
|
|
attr_list, change, marker, private)
|
|
|
|
|
2006-10-11 08:50:56 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
else:
|
|
|
|
the_txn = None
|
2007-06-04 08:19:31 +05:30
|
|
|
self.event_map.put(str(handle), info, txn=the_txn)
|
2006-10-11 08:50:56 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
the_txn.commit()
|
2006-08-15 10:54:38 +05:30
|
|
|
self.update()
|
|
|
|
|
2006-10-11 08:50:56 +05:30
|
|
|
if not self.UseTXN:
|
|
|
|
self.event_map.sync()
|
|
|
|
|
2006-08-15 10:54:38 +05:30
|
|
|
# Personal event references
|
2009-05-23 02:04:05 +05:30
|
|
|
for handle in self.person_map.keys():
|
|
|
|
info = self.person_map[handle]
|
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
(junk_handle, gramps_id, gender,
|
|
|
|
primary_name, alternate_names, death_ref_index,
|
|
|
|
birth_ref_index, event_ref_list, family_list,
|
|
|
|
parent_family_list, media_list, address_list, attribute_list,
|
|
|
|
urls, lds_ord_list, source_list, note, change, marker,
|
|
|
|
private, person_ref_list, ) = info
|
2006-08-15 21:03:28 +05:30
|
|
|
|
2006-08-18 11:19:25 +05:30
|
|
|
# Names lost the "sname" attribute
|
2006-10-07 11:26:58 +05:30
|
|
|
new_primary_name = convert_name_10(primary_name)
|
|
|
|
new_alternate_names = [convert_name_10(name)
|
|
|
|
for name in alternate_names]
|
2006-08-15 10:54:38 +05:30
|
|
|
|
2006-10-07 11:26:58 +05:30
|
|
|
# Events gained attribute_list
|
|
|
|
new_event_ref_list = [
|
2007-06-04 08:19:31 +05:30
|
|
|
(privacy, note, [], ref, role)
|
|
|
|
for (privacy, note, ref, role) in event_ref_list]
|
2006-10-07 11:26:58 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
info = (handle, gramps_id, gender, new_primary_name,
|
|
|
|
new_alternate_names,
|
|
|
|
death_ref_index, birth_ref_index, new_event_ref_list,
|
|
|
|
family_list, parent_family_list, media_list, address_list,
|
|
|
|
attribute_list, urls, lds_ord_list, source_list, note,
|
|
|
|
change, marker, private, person_ref_list, )
|
2006-10-07 11:26:58 +05:30
|
|
|
|
2006-10-11 08:50:56 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
else:
|
|
|
|
the_txn = None
|
2007-06-04 08:19:31 +05:30
|
|
|
self.person_map.put(str(handle), info, txn=the_txn)
|
2006-10-11 08:50:56 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
the_txn.commit()
|
2006-08-15 10:54:38 +05:30
|
|
|
self.update()
|
2006-10-11 08:50:56 +05:30
|
|
|
|
|
|
|
if not self.UseTXN:
|
|
|
|
self.person_map.sync()
|
|
|
|
|
2006-08-15 10:54:38 +05:30
|
|
|
# Family event references
|
2009-05-23 02:04:05 +05:30
|
|
|
for handle in self.family_map.keys():
|
|
|
|
info = self.family_map[handle]
|
2006-08-15 10:54:38 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
(junk_handle, gramps_id, father_handle,
|
|
|
|
mother_handle, child_ref_list, the_type, event_ref_list,
|
|
|
|
media_list, attribute_list, lds_seal_list, source_list, note,
|
2006-08-15 21:03:28 +05:30
|
|
|
change, marker, private) = info
|
|
|
|
|
2006-10-07 11:26:58 +05:30
|
|
|
new_event_ref_list = [
|
2007-06-04 08:19:31 +05:30
|
|
|
(privacy, note, [], ref, role)
|
|
|
|
for (privacy, note, ref, role) in event_ref_list]
|
2006-10-07 11:26:58 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
info = (handle, gramps_id, father_handle,
|
|
|
|
mother_handle, child_ref_list, the_type,
|
|
|
|
new_event_ref_list,
|
|
|
|
media_list, attribute_list, lds_seal_list,
|
|
|
|
source_list, note, change, marker, private)
|
2006-08-15 21:03:28 +05:30
|
|
|
|
2006-10-11 08:50:56 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
else:
|
|
|
|
the_txn = None
|
2007-06-04 08:19:31 +05:30
|
|
|
self.family_map.put(str(handle), info, txn=the_txn)
|
2006-10-11 08:50:56 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
the_txn.commit()
|
2006-08-15 10:54:38 +05:30
|
|
|
self.update()
|
2006-10-11 08:50:56 +05:30
|
|
|
if not self.UseTXN:
|
|
|
|
self.family_map.sync()
|
|
|
|
|
2006-08-15 10:54:38 +05:30
|
|
|
self.reset()
|
|
|
|
|
|
|
|
if self.UseTXN:
|
|
|
|
# Separate transaction to save metadata
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
else:
|
|
|
|
the_txn = None
|
2007-06-04 08:19:31 +05:30
|
|
|
self.metadata.put('version', 10, txn=the_txn)
|
2006-08-15 10:54:38 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
the_txn.commit()
|
|
|
|
else:
|
|
|
|
self.metadata.sync()
|
|
|
|
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Done upgrading to DB version 10")
|
2006-08-15 10:54:38 +05:30
|
|
|
|
2006-09-24 10:07:59 +05:30
|
|
|
def gramps_upgrade_11(self):
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Upgrading to DB version 11...")
|
2006-09-24 10:07:59 +05:30
|
|
|
|
2006-10-07 11:26:58 +05:30
|
|
|
# This upgrade modifies addresses and locations
|
2006-10-06 04:31:43 +05:30
|
|
|
length = len(self.person_map) + len(self.place_map) \
|
|
|
|
+ len(self.repository_map)
|
2006-09-24 10:07:59 +05:30
|
|
|
self.set_total(length)
|
|
|
|
|
2006-10-06 04:31:43 +05:30
|
|
|
# Personal addresses
|
2009-05-23 02:04:05 +05:30
|
|
|
for handle in self.person_map.keys():
|
|
|
|
info = self.person_map[handle]
|
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
(junk_handle, gramps_id, gender,
|
|
|
|
primary_name, alternate_names, death_ref_index,
|
|
|
|
birth_ref_index, event_ref_list, family_list,
|
|
|
|
parent_family_list, media_list, address_list, attribute_list,
|
|
|
|
urls, lds_ord_list, source_list, note, change, marker,
|
|
|
|
private, person_ref_list, ) = info
|
2006-09-24 10:07:59 +05:30
|
|
|
|
2006-10-07 11:26:58 +05:30
|
|
|
new_address_list = [convert_address_11(addr)
|
|
|
|
for addr in address_list]
|
2006-09-24 10:07:59 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
info = (handle, gramps_id, gender,
|
|
|
|
primary_name, alternate_names, death_ref_index,
|
|
|
|
birth_ref_index, event_ref_list, family_list,
|
|
|
|
parent_family_list, media_list, new_address_list,
|
|
|
|
attribute_list,
|
|
|
|
urls, lds_ord_list, source_list, note, change, marker,
|
|
|
|
private, person_ref_list, )
|
2006-09-24 10:07:59 +05:30
|
|
|
|
2006-10-11 08:50:56 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
else:
|
|
|
|
the_txn = None
|
2007-06-04 08:19:31 +05:30
|
|
|
self.person_map.put(str(handle), info, txn=the_txn)
|
2006-10-11 08:50:56 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
the_txn.commit()
|
2006-09-24 10:07:59 +05:30
|
|
|
self.update()
|
2006-10-11 08:50:56 +05:30
|
|
|
|
|
|
|
if not self.UseTXN:
|
|
|
|
self.person_map.sync()
|
2006-09-24 10:07:59 +05:30
|
|
|
|
2006-10-06 04:31:43 +05:30
|
|
|
# Repositories
|
2009-05-23 02:04:05 +05:30
|
|
|
for handle in self.repository_map.keys():
|
|
|
|
info = self.repository_map[handle]
|
2006-10-06 04:31:43 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
(junk_handle, gramps_id, the_type, name, note,
|
2006-10-07 11:26:58 +05:30
|
|
|
address_list, urls, marker, private) = info
|
2006-10-06 04:31:43 +05:30
|
|
|
|
2006-10-07 11:26:58 +05:30
|
|
|
new_address_list = [convert_address_11(addr)
|
|
|
|
for addr in address_list]
|
2006-10-06 04:31:43 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
info = (handle, gramps_id, the_type, name, note,
|
2006-10-07 11:26:58 +05:30
|
|
|
new_address_list, urls, marker, private)
|
|
|
|
|
2006-10-11 08:50:56 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
else:
|
|
|
|
the_txn = None
|
2007-06-04 08:19:31 +05:30
|
|
|
self.repository_map.put(str(handle), info, txn=the_txn)
|
2006-10-11 08:50:56 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
the_txn.commit()
|
2006-10-06 04:31:43 +05:30
|
|
|
self.update()
|
|
|
|
|
2006-10-11 08:50:56 +05:30
|
|
|
if not self.UseTXN:
|
|
|
|
self.repository_map.sync()
|
|
|
|
|
2006-10-06 04:31:43 +05:30
|
|
|
# Places
|
2009-05-23 02:04:05 +05:30
|
|
|
for handle in self.place_map.keys():
|
|
|
|
info = self.place_map[handle]
|
2006-09-24 10:07:59 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
(junk_handle, gramps_id, title, long, lat, main_loc, alt_loc, urls,
|
2006-09-24 10:07:59 +05:30
|
|
|
media_list, source_list, note, change, marker, private) = info
|
|
|
|
|
|
|
|
if main_loc:
|
2006-10-07 11:26:58 +05:30
|
|
|
main_loc = convert_location_11(main_loc)
|
2006-09-24 10:07:59 +05:30
|
|
|
|
2006-10-07 11:26:58 +05:30
|
|
|
new_alt_loc = [convert_location_11(loc) for loc in alt_loc]
|
2006-09-24 10:07:59 +05:30
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
info = (handle, gramps_id, title, long, lat, main_loc, new_alt_loc,
|
|
|
|
urls, media_list, source_list, note, change, marker, private)
|
2006-09-24 10:07:59 +05:30
|
|
|
|
2006-10-11 08:50:56 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
else:
|
|
|
|
the_txn = None
|
2007-06-04 08:19:31 +05:30
|
|
|
self.place_map.put(str(handle), info, txn=the_txn)
|
2006-10-11 08:50:56 +05:30
|
|
|
if self.UseTXN:
|
|
|
|
the_txn.commit()
|
2006-09-24 10:07:59 +05:30
|
|
|
self.update()
|
|
|
|
|
2006-10-11 08:50:56 +05:30
|
|
|
if not self.UseTXN:
|
|
|
|
self.place_map.sync()
|
|
|
|
|
2006-09-24 10:07:59 +05:30
|
|
|
self.reset()
|
|
|
|
|
|
|
|
if self.UseTXN:
|
|
|
|
# Separate transaction to save metadata
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
else:
|
|
|
|
the_txn = None
|
|
|
|
self.metadata.put('version', 11, txn=the_txn)
|
|
|
|
if self.UseTXN:
|
|
|
|
the_txn.commit()
|
|
|
|
else:
|
|
|
|
self.metadata.sync()
|
|
|
|
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Done upgrading to DB version 11")
|
2006-09-24 10:07:59 +05:30
|
|
|
|
2007-01-19 22:23:49 +05:30
|
|
|
def gramps_upgrade_12(self):
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Upgrading to DB version 12...")
|
2007-01-19 22:23:49 +05:30
|
|
|
# Hook up surnames
|
2007-06-04 08:19:31 +05:30
|
|
|
table_flags = self.__open_flags()
|
2007-01-19 22:23:49 +05:30
|
|
|
self.surnames = db.DB(self.env)
|
|
|
|
self.surnames.set_flags(db.DB_DUP|db.DB_DUPSORT)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.surnames.open(self.full_name, "surnames", db.DB_BTREE,
|
2007-01-19 22:23:49 +05:30
|
|
|
flags=table_flags)
|
2007-06-04 08:29:36 +05:30
|
|
|
self.person_map.associate(self.surnames, find_surname, table_flags)
|
2007-01-19 22:23:49 +05:30
|
|
|
|
|
|
|
self.build_surname_list()
|
|
|
|
|
|
|
|
# Close so that we can open it again later
|
|
|
|
self.surnames.close()
|
|
|
|
|
|
|
|
if self.UseTXN:
|
|
|
|
# Separate transaction to save metadata
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
else:
|
|
|
|
the_txn = None
|
|
|
|
self.metadata.put('version', 12, txn=the_txn)
|
|
|
|
if self.UseTXN:
|
|
|
|
the_txn.commit()
|
|
|
|
else:
|
|
|
|
self.metadata.sync()
|
|
|
|
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Done upgrading to DB version 12")
|
2007-01-19 22:23:49 +05:30
|
|
|
|
2007-02-22 13:22:54 +05:30
|
|
|
def gramps_upgrade_13(self):
|
|
|
|
"""
|
2007-07-17 07:29:25 +05:30
|
|
|
First upgrade in 2.3/3.0 branch.
|
2007-02-22 13:22:54 +05:30
|
|
|
We assume that the data is at least from 2.2.x.
|
|
|
|
"""
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Upgrading to DB version 13...")
|
2007-02-22 13:22:54 +05:30
|
|
|
# Hook up note id index
|
2007-06-04 08:19:31 +05:30
|
|
|
table_flags = self.__open_flags()
|
2007-02-22 13:22:54 +05:30
|
|
|
self.nid_trans = db.DB(self.env)
|
|
|
|
self.nid_trans.set_flags(db.DB_DUP)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.nid_trans.open(self.full_name, "nidtrans",
|
2007-02-22 13:22:54 +05:30
|
|
|
db.DB_HASH, flags=table_flags)
|
2007-06-04 08:29:36 +05:30
|
|
|
self.note_map.associate(self.nid_trans, find_idmap, table_flags)
|
2007-01-19 22:23:49 +05:30
|
|
|
|
2007-02-22 13:22:54 +05:30
|
|
|
# This upgrade modifies repos (store change attribute)
|
|
|
|
# And converts notes to the list of handles in all records
|
|
|
|
length = len(self.person_map) + len(self.family_map) + \
|
|
|
|
len(self.event_map) + len(self.source_map) + \
|
|
|
|
len(self.place_map) + len(self.media_map) + \
|
|
|
|
+ len(self.repository_map)
|
|
|
|
self.set_total(length)
|
2006-01-13 03:32:58 +05:30
|
|
|
|
2007-02-22 13:22:54 +05:30
|
|
|
self.change_13 = int(time.time())
|
|
|
|
|
|
|
|
# Person upgrade
|
2009-05-23 02:04:05 +05:30
|
|
|
for handle in self.person_map.keys():
|
|
|
|
info = self.person_map[handle]
|
2007-06-04 08:19:31 +05:30
|
|
|
(new_info, note_handles) = self.convert_notes_13('Person', info)
|
|
|
|
self.commit_13(new_info, PERSON_KEY, self.person_map, note_handles)
|
2007-02-22 13:22:54 +05:30
|
|
|
self.update()
|
|
|
|
|
|
|
|
# Family upgrade
|
2009-05-23 02:04:05 +05:30
|
|
|
for handle in self.family_map.keys():
|
|
|
|
info = self.family_map[handle]
|
2007-06-04 08:19:31 +05:30
|
|
|
(new_info, note_handles) = self.convert_notes_13('Family', info)
|
|
|
|
self.commit_13(new_info, FAMILY_KEY, self.family_map, note_handles)
|
2007-02-22 13:22:54 +05:30
|
|
|
self.update()
|
|
|
|
|
|
|
|
# Event upgrade
|
2009-05-23 02:04:05 +05:30
|
|
|
for handle in self.event_map.keys():
|
|
|
|
info = self.event_map[handle]
|
2007-06-04 08:19:31 +05:30
|
|
|
(new_info, note_handles) = self.convert_notes_13('Event', info)
|
|
|
|
self.commit_13(new_info, EVENT_KEY, self.event_map, note_handles)
|
2007-02-22 13:22:54 +05:30
|
|
|
self.update()
|
|
|
|
|
|
|
|
# Source upgrade
|
2009-05-23 02:04:05 +05:30
|
|
|
for handle in self.source_map.keys():
|
|
|
|
info = self.source_map[handle]
|
2007-06-04 08:19:31 +05:30
|
|
|
(new_info, note_handles) = self.convert_notes_13('Source', info)
|
|
|
|
self.commit_13(new_info, SOURCE_KEY, self.source_map, note_handles)
|
2007-02-22 13:22:54 +05:30
|
|
|
self.update()
|
|
|
|
|
|
|
|
# Place upgrade
|
2009-05-23 02:04:05 +05:30
|
|
|
for handle in self.place_map.keys():
|
|
|
|
info = self.place_map[handle]
|
2007-06-04 08:19:31 +05:30
|
|
|
(new_info, note_handles) = self.convert_notes_13('Place', info)
|
|
|
|
self.commit_13(new_info, PLACE_KEY, self.place_map, note_handles)
|
2007-02-22 13:22:54 +05:30
|
|
|
self.update()
|
|
|
|
|
|
|
|
# Media upgrade
|
2009-05-23 02:04:05 +05:30
|
|
|
for handle in self.media_map.keys():
|
|
|
|
info = self.media_map[handle]
|
2007-06-04 08:19:31 +05:30
|
|
|
(new_info, note_handles) = self.convert_notes_13('MediaObject', info)
|
|
|
|
self.commit_13(new_info, MEDIA_KEY, self.media_map, note_handles)
|
2007-02-22 13:22:54 +05:30
|
|
|
self.update()
|
|
|
|
|
|
|
|
# Repo upgrade
|
2009-05-23 02:04:05 +05:30
|
|
|
for handle in self.repository_map.keys():
|
|
|
|
info = self.repository_map[handle]
|
2007-06-04 08:19:31 +05:30
|
|
|
(new_info, note_handles) = self.convert_notes_13('Repository', info)
|
|
|
|
self.commit_13(new_info, REPOSITORY_KEY,
|
|
|
|
self.repository_map, note_handles)
|
2007-02-22 13:22:54 +05:30
|
|
|
self.update()
|
|
|
|
|
|
|
|
if not self.UseTXN:
|
|
|
|
self.person_map.sync()
|
|
|
|
self.family_map.sync()
|
|
|
|
self.event_map.sync()
|
|
|
|
self.source_map.sync()
|
|
|
|
self.place_map.sync()
|
|
|
|
self.media_map.sync()
|
|
|
|
self.repository_map.sync()
|
|
|
|
self.note_map.sync()
|
|
|
|
self.reference_map.sync()
|
|
|
|
|
|
|
|
# Clean up after the upgrade: metadata and such
|
|
|
|
if self.UseTXN:
|
|
|
|
# Separate transaction to save metadata
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
else:
|
|
|
|
the_txn = None
|
|
|
|
self.metadata.put('version', 13, txn=the_txn)
|
|
|
|
if self.UseTXN:
|
|
|
|
the_txn.commit()
|
2006-01-26 02:36:23 +05:30
|
|
|
else:
|
2007-02-22 13:22:54 +05:30
|
|
|
self.metadata.sync()
|
2006-01-26 02:36:23 +05:30
|
|
|
|
2007-02-22 13:22:54 +05:30
|
|
|
# Close nid_trans that we can open it again later
|
|
|
|
self.nid_trans.close()
|
2006-01-26 02:36:23 +05:30
|
|
|
|
2007-02-22 13:22:54 +05:30
|
|
|
# Rebuild secondary indices related to reference_map
|
|
|
|
junk = db.DB(self.env)
|
2007-06-04 08:19:31 +05:30
|
|
|
junk.remove(self.full_name, "reference_map_primary_map")
|
2007-02-22 13:22:54 +05:30
|
|
|
self.reference_map_primary_map = db.DB(self.env)
|
|
|
|
self.reference_map_primary_map.set_flags(db.DB_DUP)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.reference_map_primary_map.open(self.full_name,
|
|
|
|
"reference_map_primary_map",
|
2007-02-22 13:22:54 +05:30
|
|
|
db.DB_BTREE, flags=table_flags)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.reference_map.associate(self.reference_map_primary_map,
|
2007-06-04 08:29:36 +05:30
|
|
|
find_primary_handle,
|
2007-02-22 13:22:54 +05:30
|
|
|
table_flags)
|
|
|
|
self.reference_map_primary_map.close()
|
2006-01-26 02:36:23 +05:30
|
|
|
|
2007-02-22 13:22:54 +05:30
|
|
|
junk = db.DB(self.env)
|
2007-06-04 08:19:31 +05:30
|
|
|
junk.remove(self.full_name, "reference_map_referenced_map")
|
2007-02-22 13:22:54 +05:30
|
|
|
self.reference_map_referenced_map = db.DB(self.env)
|
|
|
|
self.reference_map_referenced_map.set_flags(db.DB_DUP|db.DB_DUPSORT)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.reference_map_referenced_map.open(self.full_name,
|
|
|
|
"reference_map_referenced_map",
|
2007-02-22 13:22:54 +05:30
|
|
|
db.DB_BTREE, flags=table_flags)
|
2007-06-04 08:19:31 +05:30
|
|
|
self.reference_map.associate(self.reference_map_referenced_map,
|
2007-06-04 08:29:36 +05:30
|
|
|
find_referenced_handle,
|
2007-02-22 13:22:54 +05:30
|
|
|
table_flags)
|
|
|
|
self.reference_map_referenced_map.close()
|
2006-01-26 02:36:23 +05:30
|
|
|
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Done upgrading to DB version 13")
|
2007-02-22 13:22:54 +05:30
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def commit_13(self,data_tuple,data_key_name,data_map, note_handles=None):
|
2007-02-22 13:22:54 +05:30
|
|
|
"""
|
2007-06-04 08:19:31 +05:30
|
|
|
Commits the specified object to the data_map table in the database,
|
2007-02-22 13:22:54 +05:30
|
|
|
add a reference to each note handle.
|
|
|
|
"""
|
|
|
|
handle = str(data_tuple[0])
|
|
|
|
|
|
|
|
if self.UseTXN:
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
else:
|
|
|
|
the_txn = None
|
|
|
|
|
|
|
|
# Add all references
|
|
|
|
for note_handle in note_handles:
|
2007-06-04 08:19:31 +05:30
|
|
|
ref_key = str((handle, note_handle))
|
|
|
|
ref_data = ((data_key_name, handle), (NOTE_KEY, note_handle), )
|
|
|
|
self.reference_map.put(ref_key, ref_data, txn=the_txn)
|
2007-02-22 13:22:54 +05:30
|
|
|
# Commit data itself
|
2007-06-04 08:19:31 +05:30
|
|
|
data_map.put(handle, data_tuple, txn=the_txn)
|
2007-02-22 13:22:54 +05:30
|
|
|
|
|
|
|
# Clean up
|
|
|
|
if the_txn:
|
|
|
|
the_txn.commit()
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def convert_notes_13(self, name, obj, nttype=NoteType._DEFAULT,private=False):
|
2007-02-22 13:22:54 +05:30
|
|
|
"""
|
|
|
|
This is the function for conversion all notes in all objects
|
|
|
|
and their child objects to the top-level notes and handle references.
|
|
|
|
It calls itself recursively to get to the bottom of everything.
|
|
|
|
The obj is the data tuple that is not serialized.
|
|
|
|
|
|
|
|
This functions returns the following tuple:
|
2007-06-04 08:19:31 +05:30
|
|
|
(converted_object, note_handles)
|
2007-02-22 13:22:54 +05:30
|
|
|
where note_handles is the list containing the note handles to which
|
|
|
|
the object and its children refer. These handles will be used to add
|
|
|
|
the references to the reference_map. Every clause has to collect
|
|
|
|
these and return the unique list of all such handles.
|
2007-07-13 07:17:25 +05:30
|
|
|
|
|
|
|
This function also adds privacy of 'False' to LdsOrd instances.
|
2007-02-22 13:22:54 +05:30
|
|
|
"""
|
2007-07-13 07:17:25 +05:30
|
|
|
|
2007-02-22 13:22:54 +05:30
|
|
|
if name == 'Note':
|
|
|
|
# Special case: we are way down at the very bottom.
|
|
|
|
# Create note, commit it, return a list with one handle.
|
2008-06-10 15:18:33 +05:30
|
|
|
if isinstance(obj, tuple) and (len(obj) > 0) and \
|
2007-02-24 02:47:41 +05:30
|
|
|
('strip' in dir(obj[0])) and (obj[0].strip()):
|
|
|
|
# Some notes may be None, from early databases.
|
2007-06-04 08:19:31 +05:30
|
|
|
(text, format) = obj
|
2007-02-22 13:22:54 +05:30
|
|
|
handle = str(self.create_id())
|
|
|
|
gramps_id = self.find_next_note_gramps_id()
|
2007-06-04 08:19:31 +05:30
|
|
|
note_tuple = (handle, gramps_id, text, format, (nttype, '', ),
|
|
|
|
self.change_13, (-1, '', ), private)
|
|
|
|
self.commit_13(note_tuple, NOTE_KEY, self.note_map, [])
|
2007-02-22 13:22:54 +05:30
|
|
|
new_obj = [handle]
|
|
|
|
note_handles = [handle]
|
|
|
|
else:
|
|
|
|
new_obj = []
|
|
|
|
note_handles = []
|
|
|
|
elif name == 'RepoRef':
|
2007-06-04 08:19:31 +05:30
|
|
|
(note, ref, call_number, media_type) = obj
|
|
|
|
(note_list, note_handles) = self.convert_notes_13('Note', note,
|
2007-05-08 04:32:03 +05:30
|
|
|
nttype=NoteType.REPOREF)
|
2007-07-18 04:14:24 +05:30
|
|
|
# Add the privacy field with 'False' content
|
|
|
|
new_obj = (note_list, ref, call_number, media_type, False)
|
2007-02-22 13:22:54 +05:30
|
|
|
elif name == 'SourceRef':
|
2007-06-04 08:19:31 +05:30
|
|
|
(date, priv, note, conf, ref, page, text) = obj
|
|
|
|
(note_list, note_handles) = self.convert_notes_13('Note', note,
|
|
|
|
nttype=NoteType.SOURCEREF,
|
2007-05-08 04:32:03 +05:30
|
|
|
private=priv)
|
2007-07-17 07:29:25 +05:30
|
|
|
# Also we lose the text field and make it a note
|
2007-07-17 22:15:17 +05:30
|
|
|
if text.strip():
|
|
|
|
handle = str(self.create_id())
|
|
|
|
gramps_id = self.find_next_note_gramps_id()
|
|
|
|
note_tuple = (handle, gramps_id, text, Note.FLOWED,
|
|
|
|
(NoteType.SOURCE_TEXT, '', ), self.change_13,
|
|
|
|
(-1, '', ), priv)
|
|
|
|
self.commit_13(note_tuple, NOTE_KEY, self.note_map, [])
|
|
|
|
note_list += [handle]
|
2007-07-17 07:29:25 +05:30
|
|
|
new_obj = (date, priv, note_list, conf, ref, page)
|
2007-02-22 13:22:54 +05:30
|
|
|
elif name == 'Attribute':
|
2007-06-04 08:19:31 +05:30
|
|
|
(priv, source_list, note, the_type, value) = obj
|
|
|
|
(note_list, note_handles) = self.convert_notes_13('Note', note,
|
|
|
|
nttype=NoteType.ATTRIBUTE,
|
2007-05-08 04:32:03 +05:30
|
|
|
private=priv)
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('SourceRef', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in source_list]
|
|
|
|
new_source_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-06-04 08:19:31 +05:30
|
|
|
new_obj = (priv, new_source_list, note_list, the_type, value)
|
2007-02-22 13:22:54 +05:30
|
|
|
elif name == 'Address':
|
2007-06-04 08:19:31 +05:30
|
|
|
(priv, source_list, note, date, loc) = obj
|
|
|
|
(note_list, note_handles) = self.convert_notes_13('Note', note,
|
|
|
|
nttype=NoteType.ADDRESS,
|
2007-05-08 04:32:03 +05:30
|
|
|
private=priv)
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('SourceRef', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in source_list]
|
|
|
|
new_source_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-06-04 08:19:31 +05:30
|
|
|
new_obj = (priv, new_source_list, note_list, date, loc)
|
2007-02-22 13:22:54 +05:30
|
|
|
elif name == 'EventRef':
|
2007-06-04 08:19:31 +05:30
|
|
|
(priv, note, attr_list, ref, role) = obj
|
|
|
|
(note_list, note_handles) = self.convert_notes_13('Note', note,
|
|
|
|
nttype=NoteType.EVENTREF,
|
2007-05-08 04:32:03 +05:30
|
|
|
private=priv)
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('Attribute', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in attr_list]
|
|
|
|
new_attr_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-06-04 08:19:31 +05:30
|
|
|
new_obj = (priv, note_list, new_attr_list, ref, role)
|
2007-02-22 13:22:54 +05:30
|
|
|
elif name == 'ChildRef':
|
2007-06-04 08:19:31 +05:30
|
|
|
(pri, source_list, note, ref, frel, mrel) = obj
|
|
|
|
(note_list, note_handles) = self.convert_notes_13('Note', note,
|
|
|
|
nttype=NoteType.CHILDREF,
|
2007-05-08 04:32:03 +05:30
|
|
|
private=pri)
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('SourceRef', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in source_list]
|
|
|
|
new_source_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-06-04 08:19:31 +05:30
|
|
|
new_obj = (pri, new_source_list, note_list, ref, frel, mrel)
|
2007-02-22 13:22:54 +05:30
|
|
|
elif name == 'PersonRef':
|
2007-06-04 08:19:31 +05:30
|
|
|
(priv, source_list, note, ref, rel) = obj
|
|
|
|
(note_list, note_handles) = self.convert_notes_13('Note', note,
|
|
|
|
nttype=NoteType.ASSOCIATION,
|
2007-05-08 04:32:03 +05:30
|
|
|
private=priv)
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('SourceRef', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in source_list]
|
|
|
|
new_source_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-06-04 08:19:31 +05:30
|
|
|
new_obj = (priv, new_source_list, note_list, ref, rel)
|
2007-02-22 13:22:54 +05:30
|
|
|
elif name == 'MediaRef':
|
2007-06-04 08:19:31 +05:30
|
|
|
(priv, source_list, note, attr_list, ref, rect) = obj
|
|
|
|
(note_list, note_handles) = self.convert_notes_13('Note', note,
|
|
|
|
nttype=NoteType.MEDIAREF,
|
2007-05-08 04:32:03 +05:30
|
|
|
private=priv)
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('SourceRef', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in source_list]
|
|
|
|
new_source_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('Attribute', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in attr_list]
|
|
|
|
new_attr_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-07-13 07:17:25 +05:30
|
|
|
new_obj = (priv, new_source_list, note_list, new_attr_list,
|
|
|
|
ref, rect)
|
2007-02-22 13:22:54 +05:30
|
|
|
elif name == 'Name':
|
2007-07-13 07:17:25 +05:30
|
|
|
(priv, source_list, note, date,
|
|
|
|
f, s, su, t, ty, p, pa, g, so, di, call) = obj
|
2007-06-04 08:19:31 +05:30
|
|
|
(note_list, note_handles) = self.convert_notes_13('Note', note,
|
|
|
|
nttype=NoteType.PERSONNAME,
|
2007-05-08 04:32:03 +05:30
|
|
|
private=priv)
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('SourceRef', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in source_list]
|
|
|
|
new_source_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-06-04 08:19:31 +05:30
|
|
|
new_obj = (priv, new_source_list, note_list,
|
|
|
|
date, f, s, su, t, ty, p, pa, g, so, di, call)
|
2007-02-22 13:22:54 +05:30
|
|
|
elif name == 'LdsOrd':
|
2007-06-04 08:19:31 +05:30
|
|
|
(source_list, note, date, t, place, famc, temple, st) = obj
|
|
|
|
(note_list, note_handles) = self.convert_notes_13('Note', note,
|
2007-05-08 04:32:03 +05:30
|
|
|
nttype=NoteType.LDS)
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('SourceRef', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in source_list]
|
|
|
|
new_source_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-07-13 07:17:25 +05:30
|
|
|
# Add privacy 'False' here
|
|
|
|
new_obj = (new_source_list, note_list, date, t, place,
|
|
|
|
famc, temple, st, False)
|
2007-02-22 13:22:54 +05:30
|
|
|
elif name == 'Event':
|
2007-06-04 08:19:31 +05:30
|
|
|
(handle, gramps_id, the_type, date, description, place,
|
|
|
|
source_list, note, media_list, attr_list,
|
|
|
|
change, marker, priv) = obj
|
|
|
|
(note_list, note_handles) = self.convert_notes_13('Note', note,
|
|
|
|
nttype=NoteType.EVENT,
|
2007-05-08 04:32:03 +05:30
|
|
|
private=priv)
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('SourceRef', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in source_list]
|
|
|
|
new_source_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('MediaRef', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in media_list]
|
|
|
|
new_media_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('Attribute', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in attr_list]
|
|
|
|
new_attr_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-06-04 08:19:31 +05:30
|
|
|
new_obj = (handle, gramps_id, the_type, date, description, place,
|
2007-07-13 07:17:25 +05:30
|
|
|
new_source_list, note_list, new_media_list,
|
|
|
|
new_attr_list, change, marker, priv)
|
2007-02-22 13:22:54 +05:30
|
|
|
elif name == 'Family':
|
2007-07-13 07:17:25 +05:30
|
|
|
(handle, gramps_id, fh, mh, child_ref_list, the_type,
|
|
|
|
event_ref_list, media_list, attr_list, lds_list, source_list,
|
|
|
|
note, change, marker, priv) = obj
|
2007-06-04 08:19:31 +05:30
|
|
|
(note_list, note_handles) = self.convert_notes_13('Note', note,
|
|
|
|
nttype=NoteType.FAMILY,
|
2007-05-08 04:32:03 +05:30
|
|
|
private=priv)
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('SourceRef', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in source_list]
|
|
|
|
new_source_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('MediaRef', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in media_list]
|
|
|
|
new_media_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('Attribute', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in attr_list]
|
|
|
|
new_attr_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('ChildRef', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in child_ref_list]
|
|
|
|
new_child_ref_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('EventRef', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in event_ref_list]
|
|
|
|
new_event_ref_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('LdsOrd', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in lds_list]
|
|
|
|
new_lds_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-07-13 07:17:25 +05:30
|
|
|
new_obj = (handle, gramps_id, fh, mh, new_child_ref_list,
|
|
|
|
the_type, new_event_ref_list, new_media_list,
|
2008-02-24 19:25:55 +05:30
|
|
|
new_attr_list, new_lds_list, new_source_list, note_list,
|
2007-02-22 13:22:54 +05:30
|
|
|
change, marker, priv)
|
|
|
|
elif name == 'MediaObject':
|
2007-07-13 07:17:25 +05:30
|
|
|
(handle, gramps_id, path, mime, desc, attr_list, source_list,
|
|
|
|
note, change,date, marker, priv) = obj
|
2007-06-04 08:19:31 +05:30
|
|
|
(note_list, note_handles) = self.convert_notes_13('Note', note,
|
|
|
|
nttype=NoteType.MEDIA,
|
2007-05-08 04:32:03 +05:30
|
|
|
private=priv)
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('SourceRef', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in source_list]
|
|
|
|
new_source_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('Attribute', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in attr_list]
|
|
|
|
new_attr_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-06-04 08:19:31 +05:30
|
|
|
new_obj = (handle, gramps_id, path, mime, desc, new_attr_list,
|
|
|
|
new_source_list, note_list, change, date, marker, priv)
|
2007-02-22 13:22:54 +05:30
|
|
|
elif name == 'Place':
|
2007-06-04 08:19:31 +05:30
|
|
|
(handle, gramps_id, title, long, lat, main_loc, alt_loc, urls,
|
|
|
|
media_list, source_list, note, change, marker, priv) = obj
|
|
|
|
(note_list, note_handles) = self.convert_notes_13('Note', note,
|
|
|
|
nttype=NoteType.PLACE,
|
2007-05-08 04:32:03 +05:30
|
|
|
private=priv)
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('SourceRef', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in source_list]
|
|
|
|
new_source_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('MediaRef', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in media_list]
|
|
|
|
new_media_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-07-13 07:17:25 +05:30
|
|
|
new_obj = (handle, gramps_id, title, long, lat, main_loc, alt_loc,
|
|
|
|
urls, new_media_list, new_source_list, note_list,
|
2007-06-04 08:19:31 +05:30
|
|
|
change, marker, priv)
|
2007-02-22 13:22:54 +05:30
|
|
|
elif name == 'Source':
|
2007-06-04 08:19:31 +05:30
|
|
|
(handle, gramps_id, title, author, pubinfo, note, media_list,
|
|
|
|
abbrev, change, datamap, reporef_list, marker, priv) = obj
|
|
|
|
(note_list, note_handles) = self.convert_notes_13('Note', note,
|
|
|
|
nttype=NoteType.SOURCE,
|
2007-05-08 04:32:03 +05:30
|
|
|
private=priv)
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('MediaRef', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in media_list]
|
|
|
|
new_media_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('RepoRef', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in reporef_list]
|
|
|
|
new_reporef_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-06-04 08:19:31 +05:30
|
|
|
new_obj = (handle, gramps_id, title, author, pubinfo, note_list,
|
2007-07-13 07:17:25 +05:30
|
|
|
new_media_list, abbrev, change, datamap,
|
|
|
|
new_reporef_list, marker, priv)
|
2007-02-22 13:22:54 +05:30
|
|
|
elif name == 'Repository':
|
2007-07-13 07:17:25 +05:30
|
|
|
(handle, gramps_id, t, n, note, addr_list, urls,
|
|
|
|
marker, priv) = obj
|
2007-06-04 08:19:31 +05:30
|
|
|
(note_list, note_handles) = self.convert_notes_13('Note', note,
|
|
|
|
nttype=NoteType.REPO,
|
2007-05-08 04:32:03 +05:30
|
|
|
private=priv)
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('Address', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in addr_list]
|
|
|
|
new_addr_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-07-13 07:17:25 +05:30
|
|
|
new_obj = (handle, gramps_id, t, n, note_list, new_addr_list,
|
|
|
|
urls, self.change_13, marker, priv)
|
2007-02-22 13:22:54 +05:30
|
|
|
elif name == 'Person':
|
2007-06-04 08:19:31 +05:30
|
|
|
(handle, gramps_id, gender, primary_name, alternate_names,
|
2007-07-13 07:17:25 +05:30
|
|
|
dri, bri, event_ref_list, fl, pfl, media_list, addr_list,
|
|
|
|
attr_list, urls, lds_list, source_list, note, change, marker,
|
|
|
|
priv,person_ref_list) = obj
|
2007-06-04 08:19:31 +05:30
|
|
|
(note_list, note_handles) = self.convert_notes_13('Note', note,
|
|
|
|
nttype=NoteType.PERSON,
|
2007-05-08 04:32:03 +05:30
|
|
|
private=priv)
|
2007-07-13 07:17:25 +05:30
|
|
|
(new_primary_name, nh) = self.convert_notes_13('Name',primary_name)
|
2007-02-22 13:22:54 +05:30
|
|
|
note_handles += nh
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('Name', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in alternate_names]
|
|
|
|
new_alternate_names = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('EventRef', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in event_ref_list]
|
|
|
|
new_event_ref_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('MediaRef', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in media_list]
|
|
|
|
new_media_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('Address', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in addr_list]
|
|
|
|
new_addr_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('Attribute', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in attr_list]
|
|
|
|
new_attr_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('LdsOrd', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in lds_list]
|
|
|
|
new_lds_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('SourceRef', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in source_list]
|
|
|
|
new_source_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
2007-06-04 08:19:31 +05:30
|
|
|
tuples = [self.convert_notes_13('PersonRef', item)
|
2007-02-22 13:22:54 +05:30
|
|
|
for item in person_ref_list]
|
|
|
|
new_person_ref_list = [item[0] for item in tuples]
|
|
|
|
note_handles += [item[1] for item in tuples]
|
|
|
|
|
2007-06-04 08:19:31 +05:30
|
|
|
new_obj = (handle, gramps_id, gender, new_primary_name,
|
|
|
|
new_alternate_names, dri, bri, new_event_ref_list,
|
|
|
|
fl, pfl, new_media_list, new_addr_list, new_attr_list,
|
|
|
|
urls, new_lds_list, new_source_list, note_list,
|
|
|
|
change, marker, priv, new_person_ref_list)
|
2007-02-22 13:22:54 +05:30
|
|
|
else:
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.warn("could not convert_notes_13 %s %s", name, obj)
|
2007-02-22 13:22:54 +05:30
|
|
|
# Return the required tuple
|
2007-06-04 08:19:31 +05:30
|
|
|
return (new_obj, note_handles)
|
2009-04-01 02:51:55 +05:30
|
|
|
|
|
|
|
def gramps_upgrade_14(self):
|
|
|
|
"""Upgrade database from version 13 to 14."""
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Upgrading to DB version 14...")
|
2009-04-01 02:51:55 +05:30
|
|
|
# This upgrade modifies notes and dates
|
|
|
|
length = (len(self.note_map) + len(self.person_map) +
|
|
|
|
len(self.event_map) + len(self.family_map) +
|
|
|
|
len(self.repository_map) + len(self.media_map) +
|
|
|
|
len(self.place_map) + len(self.source_map))
|
|
|
|
self.set_total(length)
|
|
|
|
|
|
|
|
# ---------------------------------
|
|
|
|
# Modify Notes
|
|
|
|
# ---------------------------------
|
|
|
|
# replace clear text with StyledText in Notes
|
2009-05-23 02:04:05 +05:30
|
|
|
for handle in self.note_map.keys():
|
|
|
|
note = self.note_map[handle]
|
2009-04-01 02:51:55 +05:30
|
|
|
(junk_handle, gramps_id, text, format, note_type,
|
|
|
|
change, marker, private) = note
|
|
|
|
styled_text = (text, [])
|
|
|
|
new_note = (handle, gramps_id, styled_text, format, note_type,
|
|
|
|
change, marker, private)
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
self.note_map.put(str(handle), new_note, txn=the_txn)
|
|
|
|
the_txn.commit()
|
|
|
|
self.update()
|
|
|
|
|
|
|
|
# ---------------------------------
|
|
|
|
# Modify Event
|
|
|
|
# ---------------------------------
|
|
|
|
# update dates with newyear
|
2009-05-23 02:04:05 +05:30
|
|
|
for handle in self.event_map.keys():
|
|
|
|
event = self.event_map[handle]
|
2009-04-01 02:51:55 +05:30
|
|
|
(junk_handle, gramps_id, the_type, date, description, place,
|
|
|
|
source_list, note_list, media_list, attribute_list,
|
|
|
|
change, marker, private) = event
|
|
|
|
new_date = self.convert_date_14(date)
|
|
|
|
new_source_list = self.new_source_list_14(source_list)
|
|
|
|
new_media_list = self.new_media_list_14(media_list)
|
|
|
|
new_attribute_list = self.new_attribute_list_14(attribute_list)
|
|
|
|
new_event = (junk_handle, gramps_id, the_type, new_date,
|
|
|
|
description, place, new_source_list, note_list,
|
|
|
|
new_media_list, new_attribute_list, change,marker,private)
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
self.event_map.put(str(handle), new_event, txn=the_txn)
|
|
|
|
the_txn.commit()
|
|
|
|
self.update()
|
|
|
|
|
|
|
|
# ---------------------------------
|
|
|
|
# Modify Person
|
|
|
|
# ---------------------------------
|
|
|
|
# update dates with newyear
|
2009-05-23 02:04:05 +05:30
|
|
|
for handle in self.person_map.keys():
|
|
|
|
person = self.person_map[handle]
|
2009-04-01 02:51:55 +05:30
|
|
|
(junk_handle, # 0
|
|
|
|
gramps_id, # 1
|
|
|
|
gender, # 2
|
|
|
|
primary_name, # 3
|
|
|
|
alternate_names, # 4
|
|
|
|
death_ref_index, # 5
|
|
|
|
birth_ref_index, # 6
|
|
|
|
event_ref_list, # 7
|
|
|
|
family_list, # 8
|
|
|
|
parent_family_list, # 9
|
|
|
|
media_list, # 10
|
|
|
|
address_list, # 11
|
|
|
|
attribute_list, # 12
|
|
|
|
urls, # 13
|
|
|
|
lds_ord_list, # 14
|
|
|
|
psource_list, # 15
|
|
|
|
pnote_list, # 16
|
|
|
|
change, # 17
|
|
|
|
marker, # 18
|
|
|
|
pprivate, # 19
|
|
|
|
person_ref_list, # 20
|
|
|
|
) = person
|
|
|
|
|
|
|
|
new_address_list = []
|
|
|
|
for address in address_list:
|
|
|
|
(privacy, asource_list, anote_list, date, location) = address
|
|
|
|
new_date = self.convert_date_14(date)
|
|
|
|
new_asource_list = self.new_source_list_14(asource_list)
|
|
|
|
new_address_list.append((privacy, new_asource_list, anote_list,
|
|
|
|
new_date, location))
|
|
|
|
new_ord_list = []
|
|
|
|
for ldsord in lds_ord_list:
|
|
|
|
(lsource_list, lnote_list, date, type, place,
|
|
|
|
famc, temple, status, lprivate) = ldsord
|
|
|
|
new_date = self.convert_date_14(date)
|
|
|
|
new_lsource_list = self.new_source_list_14(lsource_list)
|
|
|
|
new_ord_list.append( (new_lsource_list, lnote_list, new_date, type,
|
|
|
|
place, famc, temple, status, lprivate))
|
|
|
|
|
|
|
|
new_primary_name = self.convert_name_14(primary_name)
|
|
|
|
|
|
|
|
new_alternate_names = [self.convert_name_14(name) for name
|
|
|
|
in alternate_names]
|
2007-02-22 13:22:54 +05:30
|
|
|
|
2009-04-01 02:51:55 +05:30
|
|
|
new_media_list = self.new_media_list_14(media_list)
|
|
|
|
new_psource_list = self.new_source_list_14(psource_list)
|
|
|
|
new_attribute_list = self.new_attribute_list_14(attribute_list)
|
|
|
|
|
|
|
|
new_person = (junk_handle, # 0
|
|
|
|
gramps_id, # 1
|
|
|
|
gender, # 2
|
|
|
|
new_primary_name, # 3
|
|
|
|
new_alternate_names, # 4
|
|
|
|
death_ref_index, # 5
|
|
|
|
birth_ref_index, # 6
|
|
|
|
event_ref_list, # 7
|
|
|
|
family_list, # 8
|
|
|
|
parent_family_list, # 9
|
|
|
|
new_media_list, # 10
|
|
|
|
new_address_list, # 11
|
|
|
|
new_attribute_list, # 12
|
|
|
|
urls, # 13
|
|
|
|
new_ord_list, # 14
|
|
|
|
new_psource_list, # 15
|
|
|
|
pnote_list, # 16
|
|
|
|
change, # 17
|
|
|
|
marker, # 18
|
|
|
|
pprivate, # 19
|
|
|
|
person_ref_list, # 20
|
|
|
|
)
|
|
|
|
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
self.person_map.put(str(handle), new_person, txn=the_txn)
|
|
|
|
the_txn.commit()
|
|
|
|
self.update()
|
|
|
|
|
|
|
|
# ---------------------------------
|
|
|
|
# Modify Family
|
|
|
|
# ---------------------------------
|
|
|
|
# update dates with newyear
|
2009-05-23 02:04:05 +05:30
|
|
|
for handle in self.family_map.keys():
|
|
|
|
family = self.family_map[handle]
|
2009-04-01 02:51:55 +05:30
|
|
|
(junk_handle, gramps_id, father_handle, mother_handle,
|
|
|
|
child_ref_list, the_type, event_ref_list, media_list,
|
|
|
|
attribute_list, lds_seal_list, source_list, note_list,
|
|
|
|
change, marker, private) = family
|
|
|
|
new_media_list = self.new_media_list_14(media_list)
|
|
|
|
new_source_list = self.new_source_list_14(source_list)
|
|
|
|
new_attribute_list = self.new_attribute_list_14(attribute_list)
|
|
|
|
new_seal_list = []
|
|
|
|
for ldsord in lds_seal_list:
|
|
|
|
(lsource_list, lnote_list, date, type, place,
|
|
|
|
famc, temple, status, lprivate) = ldsord
|
|
|
|
new_date = self.convert_date_14(date)
|
|
|
|
new_lsource_list = self.new_source_list_14(lsource_list)
|
|
|
|
new_seal_list.append( (new_lsource_list, lnote_list, new_date, type,
|
|
|
|
place, famc, temple, status, lprivate))
|
|
|
|
|
|
|
|
new_family = (junk_handle, gramps_id, father_handle, mother_handle,
|
|
|
|
child_ref_list, the_type, event_ref_list, new_media_list,
|
|
|
|
new_attribute_list, new_seal_list, new_source_list, note_list,
|
|
|
|
change, marker, private)
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
self.family_map.put(str(handle), new_family, txn=the_txn)
|
|
|
|
the_txn.commit()
|
|
|
|
self.update()
|
|
|
|
|
|
|
|
# ---------------------------------
|
|
|
|
# Modify Repository
|
|
|
|
# ---------------------------------
|
|
|
|
# update dates with newyear
|
2009-05-23 02:04:05 +05:30
|
|
|
for handle in self.repository_map.keys():
|
|
|
|
repository = self.repository_map[handle]
|
2009-04-01 02:51:55 +05:30
|
|
|
# address
|
|
|
|
(junk_handle, gramps_id, the_type, name, note_list,
|
|
|
|
address_list, urls, change, marker, private) = repository
|
|
|
|
|
|
|
|
new_address_list = []
|
|
|
|
for address in address_list:
|
|
|
|
(privacy, asource_list, anote_list, date, location) = address
|
|
|
|
new_date = self.convert_date_14(date)
|
|
|
|
new_asource_list = self.new_source_list_14(asource_list)
|
|
|
|
new_address_list.append((privacy, new_asource_list, anote_list,
|
|
|
|
new_date, location))
|
|
|
|
|
|
|
|
new_repository = (junk_handle, gramps_id, the_type, name, note_list,
|
|
|
|
new_address_list, urls, change, marker, private)
|
|
|
|
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
self.repository_map.put(str(handle), new_repository, txn=the_txn)
|
|
|
|
the_txn.commit()
|
|
|
|
self.update()
|
|
|
|
|
|
|
|
# ---------------------------------
|
|
|
|
# Modify Media
|
|
|
|
# ---------------------------------
|
2009-05-23 02:04:05 +05:30
|
|
|
for media_handle in self.media_map.keys():
|
|
|
|
media = self.media_map[media_handle]
|
2009-04-01 02:51:55 +05:30
|
|
|
(handle, gramps_id, path, mime, desc,
|
|
|
|
attribute_list, source_list, note_list, change,
|
|
|
|
date, marker, private) = media
|
|
|
|
new_source_list = self.new_source_list_14(source_list)
|
|
|
|
new_date = self.convert_date_14(date)
|
|
|
|
new_media = (handle, gramps_id, path, mime, desc,
|
|
|
|
attribute_list, new_source_list, note_list, change,
|
|
|
|
new_date, marker, private)
|
|
|
|
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
self.media_map.put(str(handle), new_media, txn=the_txn)
|
|
|
|
the_txn.commit()
|
|
|
|
self.update()
|
|
|
|
|
|
|
|
# ---------------------------------
|
|
|
|
# Modify Place
|
|
|
|
# ---------------------------------
|
2009-05-23 02:04:05 +05:30
|
|
|
for place_handle in self.place_map.keys():
|
|
|
|
place = self.place_map[place_handle]
|
2009-04-01 02:51:55 +05:30
|
|
|
(handle, gramps_id, title, long, lat,
|
|
|
|
main_loc, alt_loc, urls, media_list, source_list, note_list,
|
|
|
|
change, marker, private) = place
|
|
|
|
new_media_list = self.new_media_list_14(media_list)
|
|
|
|
new_source_list = self.new_source_list_14(source_list)
|
|
|
|
new_place = (handle, gramps_id, title, long, lat,
|
|
|
|
main_loc, alt_loc, urls, new_media_list,
|
|
|
|
new_source_list, note_list, change, marker, private)
|
|
|
|
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
self.place_map.put(str(handle), new_place, txn=the_txn)
|
|
|
|
the_txn.commit()
|
|
|
|
self.update()
|
|
|
|
|
|
|
|
# ---------------------------------
|
|
|
|
# Modify Source
|
|
|
|
# ---------------------------------
|
2009-05-23 02:04:05 +05:30
|
|
|
for source_handle in self.source_map.keys():
|
|
|
|
source = self.source_map[source_handle]
|
2009-04-01 02:51:55 +05:30
|
|
|
(handle, gramps_id, title, author,
|
|
|
|
pubinfo, note_list, media_list,
|
|
|
|
abbrev, change, datamap, reporef_list,
|
|
|
|
marker, private) = source
|
|
|
|
new_media_list = self.new_media_list_14(media_list)
|
|
|
|
new_source = (handle, gramps_id, title, author,
|
|
|
|
pubinfo, note_list, new_media_list,
|
|
|
|
abbrev, change, datamap, reporef_list,
|
|
|
|
marker, private)
|
|
|
|
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
self.source_map.put(str(handle), new_source, txn=the_txn)
|
|
|
|
the_txn.commit()
|
|
|
|
self.update()
|
|
|
|
|
|
|
|
# Bump up database version. Separate transaction to save metadata.
|
|
|
|
the_txn = self.env.txn_begin()
|
|
|
|
self.metadata.put('version', 14, txn=the_txn)
|
|
|
|
the_txn.commit()
|
|
|
|
|
|
|
|
def new_source_list_14(self, source_list):
|
|
|
|
new_source_list = []
|
|
|
|
for source in source_list:
|
|
|
|
(date, private, note_list, confidence, ref, page) = source
|
|
|
|
new_date = self.convert_date_14(date)
|
|
|
|
new_source_list.append((new_date, private, note_list, confidence, ref, page))
|
|
|
|
return new_source_list
|
|
|
|
|
|
|
|
def new_attribute_list_14(self, attribute_list):
|
|
|
|
new_attribute_list = []
|
|
|
|
for attribute in attribute_list:
|
|
|
|
(private, asource_list, note_list, the_type, value) = attribute
|
|
|
|
new_asource_list = self.new_source_list_14(asource_list)
|
|
|
|
new_attribute_list.append((private, new_asource_list, note_list, the_type, value))
|
|
|
|
return new_attribute_list
|
|
|
|
|
|
|
|
def new_media_list_14(self, media_list):
|
|
|
|
# ---------------------------------
|
|
|
|
# Event Media list
|
|
|
|
# ---------------------------------
|
|
|
|
new_media_list = []
|
|
|
|
for media in media_list:
|
|
|
|
(private, source_list, note_list,attribute_list,ref,role) = media
|
|
|
|
new_source_list = self.new_source_list_14(source_list)
|
|
|
|
new_attribute_list = self.new_attribute_list_14(attribute_list)
|
|
|
|
new_media_list.append((private, new_source_list, note_list, new_attribute_list, ref, role))
|
|
|
|
return new_media_list
|
|
|
|
|
|
|
|
def convert_date_14(self, date):
|
|
|
|
if date:
|
|
|
|
(calendar, modifier, quality, dateval, text, sortval) = date
|
|
|
|
return (calendar, modifier, quality, dateval, text, sortval, 0)
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def convert_name_14(self, name):
|
|
|
|
(privacy, source_list, note_list, date,
|
|
|
|
first_name, surname, suffix, title,
|
|
|
|
name_type, prefix, patronymic,
|
|
|
|
group_as, sort_as, display_as, call) = name
|
|
|
|
new_date = self.convert_date_14(date)
|
|
|
|
new_source_list = self.new_source_list_14(source_list)
|
|
|
|
return (privacy, new_source_list, note_list, new_date,
|
|
|
|
first_name, surname, suffix, title,
|
|
|
|
name_type, prefix, patronymic,
|
|
|
|
group_as, sort_as, display_as, call)
|
|
|
|
|
|
|
|
def set_auto_remove(self):
|
|
|
|
"""
|
|
|
|
BSDDB change log settings using new method with renamed attributes
|
|
|
|
"""
|
|
|
|
if db.version() < (4, 7):
|
|
|
|
# by the book: old method with old attribute
|
|
|
|
self.env.set_flags(db.DB_LOG_AUTOREMOVE, 1)
|
|
|
|
else: # look at python interface
|
|
|
|
# TODO test with new version of pybsddb
|
|
|
|
try:
|
|
|
|
# try numeric compare, just first 2 digits
|
|
|
|
# this won't work with something like "4.10a", but
|
|
|
|
# hopefully they won't do that
|
|
|
|
old_version = map(int, db.__version__.split(".",2)[:2]) < (4, 7)
|
|
|
|
except:
|
|
|
|
# fallback, weak string compare
|
|
|
|
old_version = db.__version__ < "4.7"
|
|
|
|
if old_version:
|
|
|
|
# undocumented: old method with new attribute
|
|
|
|
self.env.set_flags(db.DB_LOG_AUTO_REMOVE, 1)
|
|
|
|
else:
|
|
|
|
# by the book: new method with new attribute
|
|
|
|
self.env.log_set_config(db.DB_LOG_AUTO_REMOVE, 1)
|
2007-02-22 13:22:54 +05:30
|
|
|
|
|
|
|
class BdbTransaction(Transaction):
|
2007-06-04 08:19:31 +05:30
|
|
|
def __init__(self, msg, db, batch=False, no_magic=False):
|
2009-09-01 00:12:29 +05:30
|
|
|
Transaction.__init__(self, msg, db)
|
|
|
|
self.batch = batch
|
|
|
|
self.no_magic = no_magic
|
2006-01-26 02:36:23 +05:30
|
|
|
|
2006-08-18 11:19:25 +05:30
|
|
|
def convert_name_10(name):
|
|
|
|
# Names lost the "sname" attribute
|
2007-06-04 08:19:31 +05:30
|
|
|
(privacy, source_list, note, date, first_name, surname, suffix, title, name_type,
|
|
|
|
prefix, patronymic, sname, group_as, sort_as, display_as, call) = name
|
|
|
|
return (privacy, source_list, note, date, first_name, surname, suffix, title,
|
|
|
|
name_type, prefix, patronymic, group_as, sort_as, display_as, call)
|
2006-01-26 02:36:23 +05:30
|
|
|
|
2006-10-07 11:26:58 +05:30
|
|
|
def convert_address_11(addr):
|
2007-06-04 08:19:31 +05:30
|
|
|
# addresses got location instead of city, ...
|
|
|
|
(privacy, source_list, note, date,
|
|
|
|
city, state, country, postal, phone, street) = addr
|
2006-10-07 11:26:58 +05:30
|
|
|
county = u''
|
2007-06-04 08:19:31 +05:30
|
|
|
location_base = (street, city, county, state, country, postal, phone)
|
|
|
|
return (privacy, source_list, note, date, location_base)
|
2006-10-07 11:26:58 +05:30
|
|
|
|
|
|
|
def convert_location_11(loc):
|
2007-06-04 08:19:31 +05:30
|
|
|
(location_base, parish, county) = loc
|
|
|
|
(city, state, country, postal, phone) = location_base
|
2006-10-07 11:26:58 +05:30
|
|
|
street = u''
|
2007-06-04 08:19:31 +05:30
|
|
|
new_location_base = (street, city, county, state, country, postal, phone)
|
|
|
|
return (new_location_base, parish)
|
2008-10-21 09:52:45 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Importing data into the currently open database.
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def importData(database, filename, callback=None, cl=0):
|
|
|
|
other_database = GrampsBSDDB()
|
|
|
|
|
|
|
|
# Since we don't want to modify the file being imported,
|
|
|
|
# we create new temp file into which we will copy the imported file
|
|
|
|
orig_filename = os.path.normpath(filename)
|
2010-04-18 04:50:01 +05:30
|
|
|
new_file_id, new_filename = tempfile.mkstemp()
|
|
|
|
os.close(new_file_id)
|
2008-10-21 09:52:45 +05:30
|
|
|
new_env_name = tempfile.mkdtemp()
|
|
|
|
|
|
|
|
# determine old env dir and make db work with new env dir
|
|
|
|
orig_env_name = other_database.make_env_name(orig_filename)
|
|
|
|
other_database.make_env_name = lambda x: new_env_name
|
|
|
|
|
|
|
|
# Copy data
|
|
|
|
shutil.copyfile(orig_filename, new_filename)
|
|
|
|
# Copy env if we need and if it exists
|
|
|
|
if other_database.UseTXN and os.path.isdir(orig_env_name):
|
|
|
|
shutil.rmtree(new_env_name)
|
|
|
|
shutil.copytree(orig_env_name, new_env_name)
|
|
|
|
|
|
|
|
try:
|
|
|
|
other_database.load(new_filename, callback)
|
|
|
|
except:
|
|
|
|
if cl:
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.warn("%s could not be opened. Exiting." % new_filename)
|
2008-10-21 09:52:45 +05:30
|
|
|
else:
|
|
|
|
import traceback
|
2010-02-16 07:48:24 +05:30
|
|
|
traceback.print_exc()
|
2008-10-21 09:52:45 +05:30
|
|
|
ErrorDialog(_("%s could not be opened") % new_filename)
|
|
|
|
return
|
|
|
|
|
|
|
|
if not other_database.version_supported():
|
|
|
|
if cl:
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.warn("Error: %s could not be opened.\n%s Exiting." \
|
2008-10-21 09:52:45 +05:30
|
|
|
% (filename,
|
|
|
|
_("The database version is not supported "
|
2009-11-18 01:44:53 +05:30
|
|
|
"by this version of Gramps.\n"\
|
2008-10-21 09:52:45 +05:30
|
|
|
"Please upgrade to the corresponding version "
|
|
|
|
"or use XML for porting data between different "
|
2010-02-16 07:48:24 +05:30
|
|
|
"database versions.")))
|
2008-10-21 09:52:45 +05:30
|
|
|
else:
|
|
|
|
ErrorDialog(_("%s could not be opened") % filename,
|
|
|
|
_("The Database version is not supported "
|
2009-11-18 01:44:53 +05:30
|
|
|
"by this version of Gramps."))
|
2008-10-21 09:52:45 +05:30
|
|
|
return
|
|
|
|
|
|
|
|
# If other_database contains its custom name formats,
|
|
|
|
# we need to do tricks to remap the format numbers
|
|
|
|
if len(other_database.name_formats) > 0:
|
|
|
|
formats_map = remap_name_formats(database, other_database)
|
|
|
|
name_displayer.set_name_format(database.name_formats)
|
|
|
|
get_person = make_peron_name_remapper(other_database, formats_map)
|
|
|
|
else:
|
|
|
|
# No remapping necessary, proceed as usual
|
|
|
|
get_person = other_database.get_person_from_handle
|
|
|
|
|
|
|
|
# Prepare table and method definitions
|
|
|
|
tables = {
|
|
|
|
'Person' : {'table' : database.person_map,
|
|
|
|
'id_table' : database.id_trans,
|
|
|
|
'add_obj' : database.add_person,
|
|
|
|
'find_next_gramps_id' :database.find_next_person_gramps_id,
|
|
|
|
'other_get_from_handle':
|
|
|
|
get_person,
|
|
|
|
'other_table': other_database.person_map,
|
|
|
|
},
|
|
|
|
'Family' : {'table' : database.family_map,
|
|
|
|
'id_table' : database.fid_trans,
|
|
|
|
'add_obj' : database.add_family,
|
|
|
|
'find_next_gramps_id' :database.find_next_family_gramps_id,
|
|
|
|
'other_get_from_handle':
|
|
|
|
other_database.get_family_from_handle,
|
|
|
|
'other_table': other_database.family_map,
|
|
|
|
},
|
|
|
|
|
|
|
|
'Event' : {'table' : database.event_map,
|
|
|
|
'id_table' : database.eid_trans,
|
|
|
|
'add_obj' : database.add_event,
|
|
|
|
'find_next_gramps_id' : database.find_next_event_gramps_id,
|
|
|
|
'other_get_from_handle':
|
|
|
|
other_database.get_event_from_handle,
|
|
|
|
'other_table': other_database.event_map,
|
|
|
|
},
|
|
|
|
'Source' : {'table' : database.source_map,
|
|
|
|
'id_table' : database.sid_trans,
|
|
|
|
'add_obj' : database.add_source,
|
|
|
|
'find_next_gramps_id': database.find_next_source_gramps_id,
|
|
|
|
'other_get_from_handle':
|
|
|
|
other_database.get_source_from_handle,
|
|
|
|
'other_table': other_database.source_map,
|
|
|
|
},
|
|
|
|
'Place' : {'table' : database.place_map,
|
|
|
|
'id_table' : database.pid_trans,
|
|
|
|
'add_obj' : database.add_place,
|
|
|
|
'find_next_gramps_id' :database.find_next_place_gramps_id,
|
|
|
|
'other_get_from_handle':
|
|
|
|
other_database.get_place_from_handle,
|
|
|
|
'other_table': other_database.place_map,
|
|
|
|
},
|
|
|
|
'Media' : {'table' : database.media_map,
|
|
|
|
'id_table' : database.oid_trans,
|
|
|
|
'add_obj' : database.add_object,
|
|
|
|
'find_next_gramps_id' : database.find_next_object_gramps_id,
|
|
|
|
'other_get_from_handle':
|
|
|
|
other_database.get_object_from_handle,
|
|
|
|
'other_table': other_database.media_map,
|
|
|
|
},
|
|
|
|
'Repository' : {'table' : database.repository_map,
|
|
|
|
'id_table' : database.rid_trans,
|
|
|
|
'add_obj' : database.add_repository,
|
|
|
|
'find_next_gramps_id' :
|
|
|
|
database.find_next_repository_gramps_id,
|
|
|
|
'other_get_from_handle':
|
|
|
|
other_database.get_repository_from_handle,
|
|
|
|
'other_table': other_database.repository_map,
|
|
|
|
},
|
|
|
|
'Note' : {'table': database.note_map,
|
|
|
|
'id_table': database.nid_trans,
|
|
|
|
'add_obj': database.add_note,
|
|
|
|
'find_next_gramps_id': database.find_next_note_gramps_id,
|
|
|
|
'other_get_from_handle':
|
|
|
|
other_database.get_note_from_handle,
|
|
|
|
'other_table': other_database.note_map,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
uc = UpdateCallback(callback)
|
2009-05-23 02:04:05 +05:30
|
|
|
uc.set_total(len(tables.keys()))
|
2008-10-21 09:52:45 +05:30
|
|
|
|
|
|
|
the_len = 0
|
|
|
|
|
|
|
|
# Check for duplicate handles.
|
2009-05-23 02:04:05 +05:30
|
|
|
for key in tables:
|
|
|
|
table_dict = tables[key]
|
2008-10-21 09:52:45 +05:30
|
|
|
table = table_dict['table']
|
|
|
|
other_table = table_dict['other_table']
|
|
|
|
msg = '%s handles in two databases overlap.' % key
|
|
|
|
the_len += check_common_handles(table, other_table, msg)
|
|
|
|
uc.update()
|
|
|
|
|
|
|
|
# Proceed with preparing for import
|
|
|
|
trans = database.transaction_begin("", batch=True)
|
|
|
|
|
|
|
|
database.disable_signals()
|
|
|
|
|
|
|
|
# copy all data from new_database to database,
|
|
|
|
# rename gramps IDs of first-class objects when conflicts are found
|
|
|
|
uc.set_total(the_len)
|
|
|
|
|
|
|
|
for key in tables:
|
|
|
|
table_dict = tables[key]
|
|
|
|
id_table = table_dict['id_table']
|
|
|
|
add_obj = table_dict['add_obj']
|
|
|
|
find_next_gramps_id = table_dict['find_next_gramps_id']
|
|
|
|
other_table = table_dict['other_table']
|
|
|
|
other_get_from_handle = table_dict['other_get_from_handle']
|
|
|
|
import_table(id_table, add_obj, find_next_gramps_id,
|
|
|
|
other_table, other_get_from_handle, trans, uc)
|
|
|
|
|
|
|
|
# Copy bookmarks over:
|
|
|
|
# we already know that there's no overlap in handles anywhere
|
|
|
|
database.bookmarks.append_list(other_database.bookmarks.get())
|
|
|
|
database.family_bookmarks.append_list(other_database.family_bookmarks.get())
|
|
|
|
database.event_bookmarks.append_list(other_database.event_bookmarks.get())
|
|
|
|
database.source_bookmarks.append_list(other_database.source_bookmarks.get())
|
|
|
|
database.place_bookmarks.append_list(other_database.place_bookmarks.get())
|
|
|
|
database.media_bookmarks.append_list(other_database.media_bookmarks.get())
|
|
|
|
database.repo_bookmarks.append_list(other_database.repo_bookmarks.get())
|
|
|
|
database.note_bookmarks.append_list(other_database.note_bookmarks.get())
|
|
|
|
|
|
|
|
# Copy grouping table
|
|
|
|
group_map = other_database.get_name_group_keys()
|
|
|
|
name_len = len(group_map)
|
|
|
|
if name_len > 0:
|
|
|
|
for key in group_map:
|
|
|
|
value = other_database.get_name_group_mapping(key)
|
|
|
|
if database.has_name_group_key(key) :
|
|
|
|
present = database.get_name_group_mapping(key)
|
|
|
|
if not value == present:
|
2010-02-25 21:22:32 +05:30
|
|
|
msg = _("Your family tree groups name %(key)s together"
|
|
|
|
" with %(present)s, did not change this grouping to %(value)s") % {
|
|
|
|
'key' : key, 'present' : present, 'value' : value }
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.warn(msg)
|
2008-10-21 09:52:45 +05:30
|
|
|
else:
|
|
|
|
database.set_name_group_mapping(key, value)
|
|
|
|
|
|
|
|
# close the other database and clean things up
|
|
|
|
other_database.close()
|
|
|
|
|
|
|
|
# Remove temp file and env dir
|
|
|
|
os.unlink(new_filename)
|
|
|
|
shutil.rmtree(new_env_name)
|
|
|
|
|
|
|
|
database.transaction_commit(trans, _("Import database"))
|
|
|
|
database.enable_signals()
|
|
|
|
database.request_rebuild()
|
|
|
|
|
|
|
|
def check_common_handles(table, other_table, msg):
|
|
|
|
# Check for duplicate handles. At the moment we simply exit here,
|
|
|
|
# before modifying any data. In the future we will need to handle
|
|
|
|
# this better. How?
|
|
|
|
handles = set(table.keys())
|
|
|
|
other_handles = set(other_table.keys())
|
|
|
|
if handles.intersection(other_handles):
|
|
|
|
raise HandleError(msg)
|
|
|
|
return len(other_handles)
|
|
|
|
|
|
|
|
def import_table(id_table, add_obj, find_next_gramps_id,
|
|
|
|
other_table, other_get_from_handle, trans, uc):
|
|
|
|
|
2009-05-23 02:04:05 +05:30
|
|
|
for handle in other_table.keys():
|
2008-10-21 09:52:45 +05:30
|
|
|
obj = other_get_from_handle(handle)
|
|
|
|
|
|
|
|
# Then we check gramps_id for conflicts and change it if needed
|
|
|
|
gramps_id = str(obj.gramps_id)
|
2009-04-01 02:51:55 +05:30
|
|
|
if id_table.has_key(gramps_id):
|
2008-10-21 09:52:45 +05:30
|
|
|
gramps_id = find_next_gramps_id()
|
|
|
|
obj.gramps_id = gramps_id
|
|
|
|
add_obj(obj, trans)
|
|
|
|
uc.update()
|
|
|
|
|
|
|
|
def remap_name_formats(database, other_database):
|
|
|
|
formats_map = {}
|
|
|
|
taken_numbers = [num for (num, name, fmt_str, active)
|
|
|
|
in database.name_formats]
|
|
|
|
for (number, name, fmt_str, act) in other_database.name_formats:
|
|
|
|
if number in taken_numbers:
|
|
|
|
new_number = -1
|
|
|
|
while new_number in taken_numbers:
|
|
|
|
new_number -= 1
|
|
|
|
taken_numbers.append(new_number)
|
|
|
|
formats_map[number] = new_number
|
|
|
|
else:
|
|
|
|
new_number = number
|
|
|
|
database.name_formats.append((new_number, name, fmt_str, act))
|
|
|
|
return formats_map
|
|
|
|
|
|
|
|
def remap_name(person, formats_map):
|
|
|
|
for name in [person.primary_name] + person.alternate_names:
|
|
|
|
try:
|
|
|
|
name.sort_as = formats_map[name.sort_as]
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
try:
|
|
|
|
name.display_as = formats_map[name.display_as]
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def make_peron_name_remapper(other_database, formats_map):
|
|
|
|
def new_get_person(handle):
|
|
|
|
person = other_database.get_person_from_handle(handle)
|
|
|
|
remap_name(person, formats_map)
|
|
|
|
return person
|
|
|
|
return new_get_person
|