2007-06-03 Don Allingham <don@gramps-project.org>

* src/Simple/__init__.py: add



svn: r8531
This commit is contained in:
Don Allingham 2007-06-04 02:49:31 +00:00
parent a9791011c3
commit 2615728437
14 changed files with 1159 additions and 1046 deletions

View File

@ -1,3 +1,6 @@
2007-06-03 Don Allingham <don@gramps-project.org>
* src/Simple/__init__.py: add
2007-06-01 Alex Roitman <shura@gramps-project.org>
* src/DbLoader.py (_OPEN_FORMATS): Remove grdb from the native
format list.

300
INSTALL
View File

@ -1,98 +1,236 @@
$Id$
Installation Instructions
*************************
This file contains some useful details on the installation from source code
for GRAMPS. It does not cover installation of a pre-built binary package.
For that use your package manager, the rest is already done by the packager.
Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005 Free
Software Foundation, Inc.
This file is free documentation; the Free Software Foundation gives
unlimited permission to copy, distribute and modify it.
configure vs autogen scripts
----------------------------
If you are building from released tarball, you should be able to just
run "./configure && make". However, if you're building from the SVN,
the configure is not present. You should auto-generate it by
running ./autogen.sh and then "make" and, finally, "make install".
Basic Installation
==================
Running ./autogen.sh on this branch of gramps requires the following
packages to be installed:
* automake-1.9
* gnome-common
* intltool
* libglib2.0-dev (may be called differently on other distros) and
maybe something else. If autogen.sh fails, it should inform you what's
missing.
These are generic installation instructions.
The `configure' shell script attempts to guess correct values for
various system-dependent variables used during compilation. It uses
those values to create a `Makefile' in each directory of the package.
It may also create one or more `.h' files containing system-dependent
definitions. Finally, it creates a shell script `config.status' that
you can run in the future to recreate the current configuration, and a
file `config.log' containing compiler output (useful mainly for
debugging `configure').
Regular vs local installation
-----------------------------
This version of gramps requires, among others, the two things to be done:
gconf schemas and mime types for gramps MUST be properly installed.
The usual ./configure, make, and make install as a root should do the trick.
But be careful if you're using the non-default options or would like
to install without being root.
It can also use an optional file (typically called `config.cache'
and enabled with `--cache-file=config.cache' or simply `-C') that saves
the results of its tests to speed up reconfiguring. (Caching is
disabled by default to prevent problems with accidental use of stale
cache files.)
The latter is possible, but you should supply additional arguments to
autogen or configure:
--with-gconf-source=xml::$HOME/.gconf
--with-gconf-schema-file-dir=$HOME
--with-mime-dir=$HOME/.local/share/mime
--disable-scrollkeeper
Most likely, such local install will also need some prefix with write
permissions for you:
--prefix=$HOME/my_gramps_path
If you need to do unusual things to compile the package, please try
to figure out how `configure' could check whether to do them, and mail
diffs or instructions to the address given in the `README' so they can
be considered for the next release. If you are using the cache, and at
some point `config.cache' contains results you don't want to keep, you
may remove or edit it.
Whether you're doing local install or regular install,
YOU MUST INSTALL GCONF SCHEMAS AND MIME TYPES.
YOU HAVE BEEN WARNED!
The file `configure.ac' (or `configure.in') is used to create
`configure' by a program called `autoconf'. You only need
`configure.ac' if you want to change it or regenerate `configure' using
a newer version of `autoconf'.
The simplest way to compile this package is:
Installing under non-default prefix
-----------------------------------
As hinted above, the gconf schemas and mime types for gramps
MUST be properly installed. The "proper install" means installing
them where gconfd and shared mime system, respectively, will
find them.
1. `cd' to the directory containing the package's source code and type
`./configure' to configure the package for your system. If you're
using `csh' on an old version of System V, you might need to type
`sh ./configure' instead to prevent `csh' from trying to execute
`configure' itself.
By default, gconfd will look in these places:
1. Whatever is returned by running:
$ gconftool-2 --get-default-source
2. The xml::$HOME/.gconf : this is a per-user setup, not system-wide
or xml:merged:$HOME/.gconf : this is a per-user setup, not system-wide
There is a number of ways to let gconfd know where else
to look, but this is outside the scope of installing gramps.
Running `configure' takes awhile. While running, it prints some
messages telling which features it is checking for.
By default, the shared mime systems will look in these places:
1. /usr/share/mime
2. /usr/local/share/mime : this may be broken on some systems
3. $HOME/.local/share/mime : this is a per-user setup, not system-wide
Likewise, there's a number of ways to instruct the shared mime system
to look in other places, but this is the whole other story.
2. Type `make' to compile the package.
So if you install some place other than /usr/share, you will most
likely need to add this option to autogen.sh/configure scripts:
--with-mime-dir=/usr/share/mime
3. Optionally, type `make check' to run any self-tests that come with
the package.
Using the --prefix=/usr/share and installing as a root will most
likely do everything correctly, so no extra care needs to be
taken. You should take extra care only if you are installing under
something like --prefix=/usr/local/my_gramps, /var/gramps123/blah, etc.
4. Type `make install' to install the programs and any data files and
documentation.
5. You can remove the program binaries and object files from the
source code directory by typing `make clean'. To also remove the
files that `configure' created (so you can compile the package for
a different kind of computer), type `make distclean'. There is
also a `make maintainer-clean' target, but that is intended mainly
for the package's developers. If you use it, you may have to get
all sorts of other programs in order to regenerate files that came
with the distribution.
Packager's issues
------------------
The above mentioned gconf schemas and mime types must be installed.
However, the update-mime-database and the gconftool-2 calls to process
the newly installed types and schemas must be done in POST-INSTALLATION.
In packager's world, the install happens on packager's machine
into something like /tmp/gramps-tmp. However, the postinstall
should happen on the user's machine.
Compilers and Options
=====================
Some systems require unusual options for compilation or linking that the
`configure' script does not know about. Run `./configure --help' for
details on some of the pertinent environment variables.
You can give `configure' initial values for configuration parameters
by setting variables in the command line or in the environment. Here
is an example:
./configure CC=c89 CFLAGS=-O2 LIBS=-lposix
*Note Defining Variables::, for more details.
Compiling For Multiple Architectures
====================================
You can compile the package for more than one kind of computer at the
same time, by placing the object files for each architecture in their
own directory. To do this, you must use a version of `make' that
supports the `VPATH' variable, such as GNU `make'. `cd' to the
directory where you want the object files and executables to go and run
the `configure' script. `configure' automatically checks for the
source code in the directory that `configure' is in and in `..'.
If you have to use a `make' that does not support the `VPATH'
variable, you have to compile the package for one architecture at a
time in the source code directory. After you have installed the
package for one architecture, use `make distclean' before reconfiguring
for another architecture.
Installation Names
==================
By default, `make install' installs the package's commands under
`/usr/local/bin', include files under `/usr/local/include', etc. You
can specify an installation prefix other than `/usr/local' by giving
`configure' the option `--prefix=PREFIX'.
You can specify separate installation prefixes for
architecture-specific files and architecture-independent files. If you
pass the option `--exec-prefix=PREFIX' to `configure', the package uses
PREFIX as the prefix for installing programs and libraries.
Documentation and other data files still use the regular prefix.
In addition, if you use an unusual directory layout you can give
options like `--bindir=DIR' to specify different values for particular
kinds of files. Run `configure --help' for a list of the directories
you can set and what kinds of files go in them.
If the package supports it, you can cause programs to be installed
with an extra prefix or suffix on their names by giving `configure' the
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
Optional Features
=================
Some packages pay attention to `--enable-FEATURE' options to
`configure', where FEATURE indicates an optional part of the package.
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
is something like `gnu-as' or `x' (for the X Window System). The
`README' should mention any `--enable-' and `--with-' options that the
package recognizes.
For packages that use the X Window System, `configure' can usually
find the X include and library files automatically, but if it doesn't,
you can use the `configure' options `--x-includes=DIR' and
`--x-libraries=DIR' to specify their locations.
Specifying the System Type
==========================
There may be some features `configure' cannot figure out automatically,
but needs to determine by the type of machine the package will run on.
Usually, assuming the package is built to be run on the _same_
architectures, `configure' can figure that out, but if it prints a
message saying it cannot guess the machine type, give it the
`--build=TYPE' option. TYPE can either be a short name for the system
type, such as `sun4', or a canonical name which has the form:
CPU-COMPANY-SYSTEM
where SYSTEM can have one of these forms:
OS KERNEL-OS
See the file `config.sub' for the possible values of each field. If
`config.sub' isn't included in this package, then this package doesn't
need to know the machine type.
If you are _building_ compiler tools for cross-compiling, you should
use the option `--target=TYPE' to select the type of system they will
produce code for.
If you want to _use_ a cross compiler, that generates code for a
platform different from the build platform, you should specify the
"host" platform (i.e., that on which the generated programs will
eventually be run) with `--host=TYPE'.
Sharing Defaults
================
If you want to set default values for `configure' scripts to share, you
can create a site shell script called `config.site' that gives default
values for variables like `CC', `cache_file', and `prefix'.
`configure' looks for `PREFIX/share/config.site' if it exists, then
`PREFIX/etc/config.site' if it exists. Or, you can set the
`CONFIG_SITE' environment variable to the location of the site script.
A warning: not all `configure' scripts look for a site script.
Defining Variables
==================
Variables not defined in a site shell script can be set in the
environment passed to `configure'. However, some packages may run
configure again during the build, and the customized values of these
variables may be lost. In order to avoid this problem, you should set
them in the `configure' command line, using `VAR=value'. For example:
./configure CC=/usr/local2/bin/gcc
causes the specified `gcc' to be used as the C compiler (unless it is
overridden in the site shell script). Here is a another example:
/bin/bash ./configure CONFIG_SHELL=/bin/bash
Here the `CONFIG_SHELL=/bin/bash' operand causes subsequent
configuration-related scripts to be executed by `/bin/bash'.
`configure' Invocation
======================
`configure' recognizes the following options to control how it operates.
`--help'
`-h'
Print a summary of the options to `configure', and exit.
`--version'
`-V'
Print the version of Autoconf used to generate the `configure'
script, and exit.
`--cache-file=FILE'
Enable the cache: use and save the results of the tests in FILE,
traditionally `config.cache'. FILE defaults to `/dev/null' to
disable caching.
`--config-cache'
`-C'
Alias for `--cache-file=config.cache'.
`--quiet'
`--silent'
`-q'
Do not print messages saying which checks are being made. To
suppress all normal output, redirect it to `/dev/null' (any error
messages will still be shown).
`--srcdir=DIR'
Look for the package's source code in directory DIR. Usually
`configure' can determine that directory automatically.
`configure' also accepts some other, not widely useful, options. Run
`configure --help' for more details.
To assist with that, there's an argument available in configure
(or autogen, which will pass it to configure) which disables
the gconf schema and mime type processing:
--enable-packager-mode
This argument should disable postinstall calls made during
make install, and print a nasty warning during configure.
IT IS PACKAGER'S RESPONSIBILITY to follow the advice given
by the configure output and to copy the appropriate code
from the src/data/Makefile.am into the post-install (and post-uninstall)
of the particular packaging system.

View File

@ -29,6 +29,15 @@ MOSTLYCLEANFILES = *pyc *pyo
GRAMPS_PY_MODPATH = ".."
docfiles=\
_DateDisplay.py\
_DateParser.py\
_DateHandler.py\
_DateUtils.py
docs:
export PYTHONPATH='..'; epydoc --graph=umlclasstree -o ../html --url http://gramps-project.org --name GRAMPS --html $(docfiles)
pycheck:
(export PYTHONPATH=$(GRAMPS_PY_MODPATH); \
pychecker $(pkgdata_PYTHON));

View File

@ -75,7 +75,7 @@ _KNOWN_FORMATS = {
const.app_gedcom : _('GEDCOM'),
}
_OPEN_FORMATS = [const.app_gramps_xml, const.app_gedcom]
OPEN_FORMATS = [const.app_gramps_xml, const.app_gedcom]
#-------------------------------------------------------------------------
#
@ -101,7 +101,7 @@ class DbLoader:
add_xml_filter(choose)
add_gedcom_filter(choose)
(box, type_selector) = format_maker(_OPEN_FORMATS)
(box, type_selector) = format_maker(OPEN_FORMATS)
choose.set_extra_widget(box)
choose.set_current_folder(get_default_dir())
@ -117,7 +117,7 @@ class DbLoader:
filetype = Mime.get_type(filename)
(the_path, the_file) = os.path.split(filename)
choose.destroy()
if filetype in _OPEN_FORMATS:
if filetype in OPEN_FORMATS:
self.read_file(filename, filetype)
try:
os.chdir(os.path.dirname(filename))
@ -213,7 +213,7 @@ class DbLoader:
add_xml_filter(choose)
add_gedcom_filter(choose)
(box, type_selector) = format_maker(_OPEN_FORMATS)
(box, type_selector) = format_maker(OPEN_FORMATS)
choose.set_extra_widget(box)
default_dir = get_default_dir()
@ -246,7 +246,7 @@ class DbLoader:
str(msg))
return ('','')
# First we try our best formats
if filetype not in _OPEN_FORMATS:
if filetype not in OPEN_FORMATS:
QuestionDialog.ErrorDialog(
_("Could not open file: %s") % filename,
_("Unknown type: %s") % filetype
@ -290,7 +290,7 @@ class DbLoader:
add_xml_filter(choose)
add_gedcom_filter(choose)
format_list = _OPEN_FORMATS[:]
format_list = OPEN_FORMATS
# Add more data type selections if opening existing db
for data in import_list:
@ -336,7 +336,7 @@ class DbLoader:
return False
# First we try our best formats
if filetype in _OPEN_FORMATS:
if filetype in OPEN_FORMATS:
importer = GrampsDbUtils.gramps_db_reader_factory(filetype)
self.do_import(choose, importer, filename)
return True
@ -549,7 +549,7 @@ def add_gramps_files_filter(chooser):
"""
mime_filter = gtk.FileFilter()
mime_filter.set_name(_('All GRAMPS files'))
for fmt in _OPEN_FORMATS:
for fmt in OPEN_FORMATS:
mime_filter.add_mime_type(fmt)
chooser.add_filter(mime_filter)

View File

@ -9,6 +9,7 @@ pkgdata_PYTHON = \
_DbUtils.py \
_GrampsBSDDB.py\
_GrampsDbBase.py\
_GrampsCursor.py\
_GrampsDBCallback.py\
_GrampsDbExceptions.py\
_GrampsDbFactories.py\

View File

@ -37,7 +37,7 @@ import time
from gettext import gettext as _
from bsddb import dbshelve, db
import logging
log = logging.getLogger(".GrampsDb")
__LOG = logging.getLogger(".GrampsDb")
#-------------------------------------------------------------------------
#
@ -51,28 +51,53 @@ import _GrampsDbConst as const
from _GrampsDbExceptions import FileVersionError
from BasicUtils import UpdateCallback
from _GrampsCursor import GrampsCursor
_MINVERSION = 9
_DBVERSION = 13
def find_surname(key,data):
#--------------------------------------------------------------------------
#
# Secondary index functions
#
#--------------------------------------------------------------------------
def __find_surname(key, data):
"""
Returns the surname from the data stream. Used for building a secondary
index.
"""
return str(data[3][5])
def find_idmap(key,data):
def __find_idmap(key, data):
"""
Returns the ID from the data stream. Used for building a secondary
index.
"""
return str(data[1])
# 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))
def find_primary_handle(key,data):
def __find_primary_handle(key, data):
"""
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))
"""
return str((data)[0][1])
def find_referenced_handle(key,data):
def __find_referenced_handle(key, data):
"""
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))
"""
return str((data)[1][1])
class GrampsBSDDBCursor(GrampsCursor):
"""
Cursor to loop through a BSDDB table
"""
def __init__(self, source, txn=None):
self.cursor = source.db.cursor(txn)
self.source = source
@ -134,7 +159,6 @@ class GrampsBSDDBDupCursor(GrampsBSDDBAssocCursor):
def next_dup(self):
return self.cursor.next_dup()
#-------------------------------------------------------------------------
#
# GrampsBSDDB
@ -148,27 +172,28 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
"""creates a new GrampsDB"""
GrampsDbBase.__init__(self)
#xUpdateCallback.__init__(self)
self.txn = None
self.secondary_connected = False
self.UseTXN = use_txn
def open_flags(self):
def __open_flags(self):
if self.UseTXN:
return db.DB_CREATE|db.DB_AUTO_COMMIT
else:
return db.DB_CREATE
def open_table(self,file_name,table_name,dbtype=db.DB_HASH):
def __open_table(self, file_name, table_name, dbtype=db.DB_HASH):
dbmap = dbshelve.DBShelf(self.env)
dbmap.db.set_pagesize(16384)
print file_name
if self.readonly:
dbmap.open(file_name, table_name, dbtype, db.DB_RDONLY)
else:
dbmap.open(file_name, table_name, dbtype, self.open_flags(), 0666)
dbmap.open(file_name, table_name, dbtype, self.__open_flags(), 0666)
return dbmap
def _all_handles(self,table):
def __all_handles(self, table):
return table.keys(self.txn)
def get_person_cursor(self):
@ -244,27 +269,51 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
return self.source_map.get(str(handle), txn=self.txn) != None
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)
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)
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)
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)
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)
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)
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)
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)
# cursors for lookups in the reference_map for back reference
@ -371,28 +420,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
# Environment name is now based on the filename
drive, tmp_name = os.path.splitdrive(self.full_name)
tmp_name = tmp_name.lstrip(os.sep)
env_name = os.path.join(os.path.expanduser(const.env_dir),
tmp_name)
# Create the env dir if it does not exist
if not os.path.isdir(env_name):
os.makedirs(env_name)
# If this is not a new db, see about copying old env dir
if os.path.isfile(self.full_name):
common_env_name = os.path.expanduser(const.bsddbenv_dir)
# Copy the old env dir contents into the new one
# ONLY if the old env dir exists
if os.path.isdir(common_env_name):
shutil.rmtree(env_name)
shutil.copytree(common_env_name,env_name)
else:
# For existing env and new database, clean the env
# (means the env dir remains from previous db
# with the same name)
if not os.path.isfile(self.full_name):
shutil.rmtree(env_name)
os.mkdir(env_name)
env_name = os.path.join(os.path.expanduser(const.env_dir), tmp_name)
else:
env_flags = db.DB_CREATE | db.DB_PRIVATE | db.DB_INIT_MPOOL
env_name = os.path.expanduser('~')
@ -402,26 +430,25 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
self.env.txn_checkpoint()
callback(25)
self.metadata = self.open_table(self.full_name,"meta")
self.metadata = self.__open_table(self.full_name, "meta")
# If we cannot work with this DB version,
# it makes no sense to go further
if not self.version_supported:
self._close_early()
self.__close_early()
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",
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)
callback(37)
self._load_metadata()
self.__load_metadata()
gstats = self.metadata.get('gender_stats', default=None)
@ -455,18 +482,12 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
if self.need_upgrade():
self.gramps_upgrade(callback)
callback(50)
if not self.secondary_connected:
self.connect_secondary()
callback(75)
self.open_undodb()
self.db_is_open = True
callback(87)
# Re-set the undo history to a fresh session start
self.undoindex = -1
self.translist = [None] * len(self.translist)
@ -480,7 +501,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
db_copy(other_database, self, callback)
return 1
def _load_metadata(self):
def __load_metadata(self):
# name display formats
self.name_formats = self.metadata.get('name_formats', default=[])
# upgrade formats if they were saved in the old way
@ -554,7 +575,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
if self.readonly:
table_flags = db.DB_RDONLY
else:
table_flags = self.open_flags()
table_flags = self.__open_flags()
self.surnames = db.DB(self.env)
self.surnames.set_flags(db.DB_DUP|db.DB_DUPSORT)
@ -619,21 +640,21 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
db.DB_BTREE, flags=table_flags)
if not self.readonly:
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,
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,
table_flags)
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)
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)
self.reference_map.associate(self.reference_map_primary_map,
find_primary_handle,
__find_primary_handle,
table_flags)
self.reference_map.associate(self.reference_map_referenced_map,
find_referenced_handle,
__find_referenced_handle,
table_flags)
self.secondary_connected = True
@ -650,7 +671,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
if self.readonly:
return
table_flags = self.open_flags()
table_flags = self.__open_flags()
# remove existing secondary indices
self.id_trans.close()
@ -775,7 +796,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
return
def _delete_primary_from_reference_map(self,handle,transaction,txn=None):
def __delete_primary_from_reference_map(self, hndl, transaction, txn=None):
"""
Remove all references to the primary object from the reference_map.
"""
@ -783,7 +804,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
primary_cur = self.get_reference_map_primary_cursor()
try:
ret = primary_cur.set(handle)
ret = primary_cur.set(hndl)
except:
ret = None
@ -798,7 +819,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
# so we need the second tuple give us a reference that we can
# combine with the primary_handle to get the main key.
main_key = (handle, pickle.loads(data)[1][1])
main_key = (hndl, pickle.loads(data)[1][1])
# The trick is not to remove while inside the cursor,
# but collect them all and remove after the cursor is closed
@ -810,9 +831,9 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
# Now that the cursor is closed, we can remove things
for main_key in remove_list:
self._remove_reference(main_key,transaction,txn)
self.__remove_reference(main_key, transaction, txn)
def _update_reference_map(self, obj, transaction, txn=None):
def __update_reference_map(self, obj, transaction, txn=None):
"""
If txn is given, then changes are written right away using txn.
"""
@ -880,17 +901,17 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
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)
self.__add_reference((handle, ref_handle), data, transaction, txn)
# handle deletion of old references
for (ref_class_name, ref_handle) in no_longer_required_references:
try:
self._remove_reference((handle,ref_handle),transaction,txn)
self.__remove_reference((handle, ref_handle), transaction, txn)
except:
# ignore missing old reference
pass
def _remove_reference(self,key,transaction,txn=None):
def __remove_reference(self, key, transaction, txn=None):
"""
Removes the reference specified by the key,
preserving the change in the passed transaction.
@ -905,7 +926,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
transaction.add(REFERENCE_KEY, str(key), old_data, None)
transaction.reference_del.append(str(key))
def _add_reference(self,key,data,transaction,txn=None):
def __add_reference(self, key, data, transaction, txn=None):
"""
Adds the reference specified by the key and the data,
preserving the change in the passed transaction.
@ -946,17 +967,17 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
callback(3)
# Open reference_map and primapry map
self.reference_map = self.open_table(self.full_name, "reference_map",
self.reference_map = self.__open_table(self.full_name, "reference_map",
dbtype=db.DB_BTREE)
open_flags = self.open_flags()
open_flags = self.__open_flags()
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,
find_primary_handle,
__find_primary_handle,
open_flags)
# Make a dictionary of the functions and classes that we need for
@ -1002,7 +1023,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
the_txn = self.env.txn_begin()
else:
the_txn = None
self._update_reference_map(obj,transaction,the_txn)
self.__update_reference_map(obj, transaction, the_txn)
if not self.UseTXN:
self.reference_map.sync()
if the_txn:
@ -1020,12 +1041,12 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
self.full_name, "reference_map_referenced_map",
db.DB_BTREE, flags=open_flags)
self.reference_map.associate(self.reference_map_referenced_map,
find_referenced_handle,open_flags)
__find_referenced_handle, open_flags)
callback(6)
return
def _close_metadata(self):
def __close_metadata(self):
if not self.readonly:
if self.UseTXN:
# Start transaction if needed
@ -1098,7 +1119,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
self.metadata.close()
def _close_early(self):
def __close_early(self):
"""
Bail out if the incompatible version is discovered:
* close cleanly to not damage data/env
@ -1122,7 +1143,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
if self.UseTXN:
self.env.txn_checkpoint()
self._close_metadata()
self.__close_metadata()
self.name_group.close()
self.surnames.close()
self.id_trans.close()
@ -1147,16 +1168,6 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
self.source_map.close()
self.media_map.close()
self.event_map.close()
# Attempt to clear log sequence numbers, to make database portable
# This will only work for python2.5 and higher
# Comment this our because it causes crashes.
# To reproduce the crash, create a new DB, import example.gramps, open and close the db a few times.
# try:
# self.env.lsn_reset(self.full_name)
# except AttributeError:
# pass
self.env.close()
try:
@ -1177,7 +1188,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
self.metadata = None
self.db_is_open = False
def _do_remove_object(self,handle,transaction,data_map,key,del_list):
def __do_remove_object(self, handle, transaction, data_map, key, del_list):
if self.readonly or not handle:
return
@ -1187,7 +1198,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
the_txn = self.env.txn_begin()
else:
the_txn = None
self._delete_primary_from_reference_map(handle,transaction,
self.__delete_primary_from_reference_map(handle, transaction,
txn=the_txn)
data_map.delete(handle, txn=the_txn)
if not self.UseTXN:
@ -1195,47 +1206,47 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
if the_txn:
the_txn.commit()
else:
self._delete_primary_from_reference_map(handle,transaction)
self.__delete_primary_from_reference_map(handle, transaction)
old_data = data_map.get(handle, txn=self.txn)
transaction.add(key, handle, old_data, None)
del_list.append(handle)
def _del_person(self,handle):
def __del_person(self, handle):
self.person_map.delete(str(handle), txn=self.txn)
if not self.UseTXN:
self.person_map.sync()
def _del_source(self,handle):
def __del_source(self, handle):
self.source_map.delete(str(handle), txn=self.txn)
if not self.UseTXN:
self.source_map.sync()
def _del_repository(self,handle):
def __del_repository(self, handle):
self.repository_map.delete(str(handle), txn=self.txn)
if not self.UseTXN:
self.repository_map.sync()
def _del_note(self,handle):
def __del_note(self, handle):
self.note_map.delete(str(handle), txn=self.txn)
if not self.UseTXN:
self.note_map.sync()
def _del_place(self,handle):
def __del_place(self, handle):
self.place_map.delete(str(handle), txn=self.txn)
if not self.UseTXN:
self.place_map.sync()
def _del_media(self,handle):
def __del_media(self, handle):
self.media_map.delete(str(handle), txn=self.txn)
if not self.UseTXN:
self.media_map.sync()
def _del_family(self,handle):
def __del_family(self, handle):
self.family_map.delete(str(handle), txn=self.txn)
if not self.UseTXN:
self.family_map.sync()
def _del_event(self,handle):
def __del_event(self, handle):
self.event_map.delete(str(handle), txn=self.txn)
if not self.UseTXN:
self.event_map.sync()
@ -1276,7 +1287,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
except ValueError:
pass
def _get_obj_from_gramps_id(self,val,tbl,class_init,prim_tbl):
def __get_obj_from_gramps_id(self, val, tbl, class_init, prim_tbl):
if tbl.has_key(str(val)):
data = tbl.get(str(val), txn=self.txn)
obj = class_init()
@ -1298,7 +1309,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
Finds a Person in the database from the passed gramps' ID.
If no such Person exists, None is returned.
"""
return self._get_obj_from_gramps_id(val,self.id_trans,Person,
return self.__get_obj_from_gramps_id(val, self.id_trans, Person,
self.person_map)
def get_family_from_gramps_id(self, val):
@ -1306,7 +1317,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
Finds a Family in the database from the passed gramps' ID.
If no such Family exists, None is return.
"""
return self._get_obj_from_gramps_id(val,self.fid_trans,Family,
return self.__get_obj_from_gramps_id(val, self.fid_trans, Family,
self.family_map)
def get_event_from_gramps_id(self, val):
@ -1314,7 +1325,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
Finds an Event in the database from the passed gramps' ID.
If no such Family exists, None is returned.
"""
return self._get_obj_from_gramps_id(val,self.eid_trans,Event,
return self.__get_obj_from_gramps_id(val, self.eid_trans, Event,
self.event_map)
def get_place_from_gramps_id(self, val):
@ -1322,7 +1333,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
Finds a Place in the database from the passed gramps' ID.
If no such Place exists, None is returned.
"""
return self._get_obj_from_gramps_id(val,self.pid_trans,Place,
return self.__get_obj_from_gramps_id(val, self.pid_trans, Place,
self.place_map)
def get_source_from_gramps_id(self, val):
@ -1330,7 +1341,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
Finds a Source in the database from the passed gramps' ID.
If no such Source exists, None is returned.
"""
return self._get_obj_from_gramps_id(val,self.sid_trans,Source,
return self.__get_obj_from_gramps_id(val, self.sid_trans, Source,
self.source_map)
def get_object_from_gramps_id(self, val):
@ -1338,7 +1349,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
Finds a MediaObject in the database from the passed gramps' ID.
If no such MediaObject exists, None is returned.
"""
return self._get_obj_from_gramps_id(val,self.oid_trans,MediaObject,
return self.__get_obj_from_gramps_id(val, self.oid_trans, MediaObject,
self.media_map)
def get_repository_from_gramps_id(self, val):
@ -1346,7 +1357,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
Finds a Repository in the database from the passed gramps' ID.
If no such Repository exists, None is returned.
"""
return self._get_obj_from_gramps_id(val,self.rid_trans,Repository,
return self.__get_obj_from_gramps_id(val, self.rid_trans, Repository,
self.repository_map)
def get_note_from_gramps_id(self, val):
@ -1354,10 +1365,10 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
Finds a Note in the database from the passed gramps' ID.
If no such Note exists, None is returned.
"""
return self._get_obj_from_gramps_id(val,self.nid_trans,Note,
return self.__get_obj_from_gramps_id(val, self.nid_trans, Note,
self.note_map)
def _commit_base(self, obj, data_map, key, update_list, add_list,
def __commit_base(self, obj, data_map, key, update_list, add_list,
transaction, change_time):
"""
Commits the specified object to the database, storing the changes
@ -1377,7 +1388,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
the_txn = self.env.txn_begin()
else:
the_txn = None
self._update_reference_map(obj,transaction,txn=the_txn)
self.__update_reference_map(obj, transaction, txn=the_txn)
data_map.put(handle, obj.serialize(), txn=the_txn)
if not self.UseTXN:
data_map.sync()
@ -1385,7 +1396,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
the_txn.commit()
old_data = None
else:
self._update_reference_map(obj,transaction)
self.__update_reference_map(obj, transaction)
old_data = data_map.get(handle, txn=self.txn)
new_data = obj.serialize()
transaction.add(key, handle, old_data, new_data)
@ -1395,7 +1406,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
add_list.append((handle, new_data))
return old_data
def _do_commit(self,add_list,db_map):
def __do_commit(self, add_list, db_map):
retlist = []
for (handle, data) in add_list:
db_map.put(handle, data, self.txn)
@ -1404,7 +1415,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
retlist.append(str(handle))
return retlist
def _get_from_handle(self, handle, class_type, data_map):
def __get_from_handle(self, handle, class_type, data_map):
try:
data = data_map.get(str(handle), txn=self.txn)
except:
@ -1412,21 +1423,21 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
# under certain circumstances during a database reload,
# data_map can be none. If so, then don't report an error
if data_map:
log.error("Failed to get from handle",exc_info=True)
__LOG.error("Failed to get from handle", exc_info=True)
if data:
newobj = class_type()
newobj.unserialize(data)
return newobj
return None
def _find_from_handle(self,handle,transaction,class_type,dmap,add_func):
def __find_from_handle(self, hndl, transaction, class_type, dmap, add_func):
obj = class_type()
handle = str(handle)
if dmap.has_key(handle):
data = dmap.get(handle,txn=self.txn)
hndl = str(hndl)
if dmap.has_key(hndl):
data = dmap.get(hndl, txn=self.txn)
obj.unserialize(data)
else:
obj.set_handle(handle)
obj.set_handle(hndl)
add_func(obj, transaction)
return obj
@ -1492,14 +1503,14 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
if not transaction.no_magic:
# create new secondary indices to replace the ones removed
open_flags = self.open_flags()
open_flags = self.__open_flags()
dupe_flags = db.DB_DUP|db.DB_DUPSORT
self.surnames = db.DB(self.env)
self.surnames.set_flags(dupe_flags)
self.surnames.open(self.full_name, "surnames",
db.DB_BTREE, flags=open_flags)
self.person_map.associate(self.surnames,find_surname,
self.person_map.associate(self.surnames, __find_surname,
open_flags)
self.reference_map_referenced_map = db.DB(self.env)
@ -1508,7 +1519,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
self.full_name, "reference_map_referenced_map",
db.DB_BTREE, flags=open_flags)
self.reference_map.associate(self.reference_map_referenced_map,
find_referenced_handle,open_flags)
__find_referenced_handle, open_flags)
# Only build surname list after surname index is surely back
self.build_surname_list()
@ -1802,8 +1813,8 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
new_alt_loc = [convert_location_11(loc) for loc in alt_loc]
info = (handle,gramps_id,title,long,lat,main_loc,new_alt_loc,urls,
media_list, source_list, note, change, marker, private)
info = (handle, gramps_id, title, long, lat, main_loc, new_alt_loc,
urls, media_list, source_list, note, change, marker, private)
if self.UseTXN:
the_txn = self.env.txn_begin()
@ -1835,12 +1846,12 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
def gramps_upgrade_12(self):
print "Upgrading to DB version 12..."
# Hook up surnames
table_flags = self.open_flags()
table_flags = self.__open_flags()
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,
flags=table_flags)
self.person_map.associate(self.surnames, find_surname, table_flags)
self.person_map.associate(self.surnames, __find_surname, table_flags)
self.build_surname_list()
@ -1867,12 +1878,12 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
"""
print "Upgrading to DB version 13..."
# Hook up note id index
table_flags = self.open_flags()
table_flags = self.__open_flags()
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)
self.note_map.associate(self.nid_trans, find_idmap, table_flags)
self.note_map.associate(self.nid_trans, __find_idmap, table_flags)
# This upgrade modifies repos (store change attribute)
# And converts notes to the list of handles in all records
@ -1969,7 +1980,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
"reference_map_primary_map",
db.DB_BTREE, flags=table_flags)
self.reference_map.associate(self.reference_map_primary_map,
find_primary_handle,
__find_primary_handle,
table_flags)
self.reference_map_primary_map.close()
@ -1981,7 +1992,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
"reference_map_referenced_map",
db.DB_BTREE, flags=table_flags)
self.reference_map.associate(self.reference_map_referenced_map,
find_referenced_handle,
__find_referenced_handle,
table_flags)
self.reference_map_referenced_map.close()
@ -2336,20 +2347,3 @@ def convert_location_11(loc):
street = u''
new_location_base = (street, city, county, state, country, postal, phone)
return (new_location_base, parish)
if __name__ == "__main__":
import sys
d = GrampsBSDDB()
d.load(sys.argv[1],lambda x: x)
c = d.get_person_cursor()
data = c.first()
while data:
person = Person(data[1])
print data[0], person.get_primary_name().get_name(),
data = c.next()
c.close()
print d.surnames.keys()

View File

@ -51,6 +51,7 @@ from _DbUtils import db_copy
import _GrampsDbConst as const
from _GrampsDbExceptions import FileVersionError
from BasicUtils import UpdateCallback
from _GrampsCursor import GrampsCursor
_MINVERSION = 9
_DBVERSION = 13
@ -1168,42 +1169,42 @@ class GrampsDBDir(GrampsDbBase,UpdateCallback):
transaction.add(key,handle,old_data,None)
del_list.append(handle)
def _del_person(self,handle):
def __del_person(self,handle):
self.person_map.delete(str(handle),txn=self.txn)
if not self.UseTXN:
self.person_map.sync()
def _del_source(self,handle):
def __del_source(self,handle):
self.source_map.delete(str(handle),txn=self.txn)
if not self.UseTXN:
self.source_map.sync()
def _del_repository(self,handle):
def __del_repository(self,handle):
self.repository_map.delete(str(handle),txn=self.txn)
if not self.UseTXN:
self.repository_map.sync()
def _del_note(self,handle):
def __del_note(self,handle):
self.note_map.delete(str(handle),txn=self.txn)
if not self.UseTXN:
self.note_map.sync()
def _del_place(self,handle):
def __del_place(self,handle):
self.place_map.delete(str(handle),txn=self.txn)
if not self.UseTXN:
self.place_map.sync()
def _del_media(self,handle):
def __del_media(self,handle):
self.media_map.delete(str(handle),txn=self.txn)
if not self.UseTXN:
self.media_map.sync()
def _del_family(self,handle):
def __del_family(self,handle):
self.family_map.delete(str(handle),txn=self.txn)
if not self.UseTXN:
self.family_map.sync()
def _del_event(self,handle):
def __del_event(self,handle):
self.event_map.delete(str(handle),txn=self.txn)
if not self.UseTXN:
self.event_map.sync()
@ -1325,7 +1326,7 @@ class GrampsDBDir(GrampsDbBase,UpdateCallback):
return self._get_obj_from_gramps_id(val,self.nid_trans,Note,
self.note_map)
def _commit_base(self, obj, data_map, key, update_list, add_list,
def __commit_base(self, obj, data_map, key, update_list, add_list,
transaction, change_time):
"""
Commits the specified object to the database, storing the changes

View File

@ -43,7 +43,7 @@ from bsddb import db
from gettext import gettext as _
import logging
log = logging.getLogger(".GrampsDb")
LOG = logging.getLogger(".GrampsDb")
#-------------------------------------------------------------------------
#
@ -60,6 +60,7 @@ from _CursorIterator import CursorIterator
#
#-------------------------------------------------------------------------
from _GrampsDbConst import *
from _GrampsCursor import GrampsCursor
_UNDO_SIZE = 1000
@ -88,61 +89,9 @@ KEY_TO_CLASS_MAP = {PERSON_KEY: Person.__name__,
REPOSITORY_KEY: Repository.__name__,
NOTE_KEY: Note.__name__}
_sigbase = ('person', 'family', 'source', 'event',
__SIGBASE = ('person', 'family', 'source', 'event',
'media', 'place', 'repository','note')
class GrampsCursor:
"""
Provides a basic iterator that allows the user to cycle through
the elements in a particular map. A cursor should never be
directly instantiated. Instead, in should be created by the
database class.
A cursor should only be used for a single pass through the
database. If multiple passes are needed, multiple cursors
should be used.
"""
def first(self):
"""
Returns the first (index, data) pair in the database. This
should be called before the first call to next(). Note that
the data return is in the format of the serialized format
stored in the database, not in the more usable class object.
The data should be converted to a class using the class's
unserialize method.
If no data is available, None is returned.
"""
return None
def next(self):
"""
Returns the next (index, data) pair in the database. Like
the first() method, the data return is in the format of the
serialized format stored in the database, not in the more
usable class object. The data should be converted to a class
using the class's unserialize method.
None is returned when no more data is available.
"""
return None
def close(self):
"""
Closes the cursor. This should be called when the user is
finished using the cursor, freeing up the cursor's resources.
"""
pass
def get_length(self):
"""
Returns the number of records in the table referenced by the
cursor
"""
raise NotImplementedError, \
"get_length must be implemented by all subclasses of GrampsCursor"
class GrampsDbBookmarks:
def __init__(self, default = []):
self.bookmarks = default
@ -216,7 +165,6 @@ class GrampsDbBase(GrampsDBCallback):
'long-op-end' : None
}
# If this is True logging will be turned on.
try:
__LOG_ALL = int(os.environ.get('GRAMPS_SIGNAL', "0")) == 1
@ -272,26 +220,26 @@ class GrampsDbBase(GrampsDBCallback):
self.open = 0
self.genderStats = GenderStats()
self.undodb = None
self.id_trans = None
self.fid_trans = None
self.pid_trans = None
self.sid_trans = None
self.oid_trans = None
self.rid_trans = None
self.nid_trans = None
self.eid_trans = None
self.undodb = []
self.id_trans = {}
self.fid_trans = {}
self.pid_trans = {}
self.sid_trans = {}
self.oid_trans = {}
self.rid_trans = {}
self.nid_trans = {}
self.eid_trans = {}
self.env = None
self.person_map = None
self.family_map = None
self.place_map = None
self.source_map = None
self.repository_map = None
self.note_map = None
self.media_map = None
self.event_map = None
self.metadata = None
self.name_group = None
self.person_map = {}
self.family_map = {}
self.place_map = {}
self.source_map = {}
self.repository_map = {}
self.note_map = {}
self.media_map = {}
self.event_map = {}
self.metadata = {}
self.name_group = {}
self.undo_callback = None
self.redo_callback = None
self.undo_history_callback = None
@ -340,28 +288,28 @@ class GrampsDbBase(GrampsDBCallback):
def gramps_upgrade(self):
pass
def _del_person(self, handle):
def __del_person(self, handle):
pass
def _del_source(self, handle):
def __del_source(self, handle):
pass
def _del_repository(self, handle):
def __del_repository(self, handle):
pass
def _del_note(self, handle):
def __del_note(self, handle):
pass
def _del_place(self, handle):
def __del_place(self, handle):
pass
def _del_media(self, handle):
def __del_media(self, handle):
pass
def _del_family(self, handle):
def __del_family(self, handle):
pass
def _del_event(self, handle):
def __del_event(self, handle):
pass
def create_id(self):
@ -472,7 +420,7 @@ class GrampsDbBase(GrampsDBCallback):
self.emit('repository-rebuild')
self.emit('note-rebuild')
def _commit_base(self, obj, data_map, key, update_list, add_list,
def __commit_base(self, obj, data_map, key, update_list, add_list,
transaction, change_time):
"""
Commits the specified Person to the database, storing the changes
@ -487,7 +435,7 @@ class GrampsDbBase(GrampsDBCallback):
obj.change = int(time.time())
handle = str(obj.handle)
self._update_reference_map(obj, transaction)
self.__update_reference_map(obj, transaction)
try:
if transaction.batch:
@ -516,7 +464,7 @@ class GrampsDbBase(GrampsDBCallback):
as part of the transaction.
"""
old_data = self._commit_base(
old_data = self.__commit_base(
person, self.person_map, PERSON_KEY, transaction.person_update,
transaction.person_add, transaction, change_time)
if old_data:
@ -563,7 +511,7 @@ class GrampsDbBase(GrampsDBCallback):
as part of the transaction.
"""
self._commit_base(obj, self.media_map, MEDIA_KEY,
self.__commit_base(obj, self.media_map, MEDIA_KEY,
transaction.media_update, transaction.media_add,
transaction, change_time)
self.media_attributes.update(
@ -576,7 +524,7 @@ class GrampsDbBase(GrampsDBCallback):
as part of the transaction.
"""
self._commit_base(source, self.source_map, SOURCE_KEY,
self.__commit_base(source, self.source_map, SOURCE_KEY,
transaction.source_update, transaction.source_add,
transaction, change_time)
@ -596,7 +544,7 @@ class GrampsDbBase(GrampsDBCallback):
as part of the transaction.
"""
self._commit_base(place, self.place_map, PLACE_KEY,
self.__commit_base(place, self.place_map, PLACE_KEY,
transaction.place_update, transaction.place_add,
transaction, change_time)
@ -624,7 +572,7 @@ class GrampsDbBase(GrampsDBCallback):
Commits the specified Event to the database, storing the changes
as part of the transaction.
"""
self._commit_base(event, self.event_map, EVENT_KEY,
self.__commit_base(event, self.event_map, EVENT_KEY,
transaction.event_update, transaction.event_add,
transaction, change_time)
@ -640,7 +588,7 @@ class GrampsDbBase(GrampsDBCallback):
as part of the transaction.
"""
self._commit_base(family, self.family_map, FAMILY_KEY,
self.__commit_base(family, self.family_map, FAMILY_KEY,
transaction.family_update, transaction.family_add,
transaction, change_time)
@ -675,7 +623,7 @@ class GrampsDbBase(GrampsDBCallback):
as part of the transaction.
"""
self._commit_base(repository, self.repository_map, REPOSITORY_KEY,
self.__commit_base(repository, self.repository_map, REPOSITORY_KEY,
transaction.repository_update,
transaction.repository_add,
transaction, change_time)
@ -695,7 +643,7 @@ class GrampsDbBase(GrampsDBCallback):
import traceback
traceback.print_stack()
self._commit_base(note, self.note_map, NOTE_KEY,
self.__commit_base(note, self.note_map, NOTE_KEY,
transaction.note_update,
transaction.note_add,
transaction, change_time)
@ -799,7 +747,7 @@ class GrampsDbBase(GrampsDBCallback):
self.nmap_index += 1
return index
def _get_from_handle(self, handle, class_type, data_map):
def __get_from_handle(self, handle, class_type, data_map):
if not data_map:
return
data = data_map.get(str(handle))
@ -814,56 +762,56 @@ class GrampsDbBase(GrampsDBCallback):
Finds a Person in the database from the passed gramps' ID.
If no such Person exists, None is returned.
"""
return self._get_from_handle(handle, Person, self.person_map)
return self.__get_from_handle(handle, Person, self.person_map)
def get_source_from_handle(self, handle):
"""
Finds a Source in the database from the passed gramps' ID.
If no such Source exists, None is returned.
"""
return self._get_from_handle(handle, Source, self.source_map)
return self.__get_from_handle(handle, Source, self.source_map)
def get_object_from_handle(self, handle):
"""
Finds an Object in the database from the passed gramps' ID.
If no such Object exists, None is returned.
"""
return self._get_from_handle(handle, MediaObject, self.media_map)
return self.__get_from_handle(handle, MediaObject, self.media_map)
def get_place_from_handle(self, handle):
"""
Finds a Place in the database from the passed gramps' ID.
If no such Place exists, None is returned.
"""
return self._get_from_handle(handle, Place, self.place_map)
return self.__get_from_handle(handle, Place, self.place_map)
def get_event_from_handle(self, handle):
"""
Finds a Event in the database from the passed gramps' ID.
If no such Event exists, None is returned.
"""
return self._get_from_handle(handle, Event, self.event_map)
return self.__get_from_handle(handle, Event, self.event_map)
def get_family_from_handle(self, handle):
"""
Finds a Family in the database from the passed gramps' ID.
If no such Family exists, None is returned.
"""
return self._get_from_handle(handle, Family, self.family_map)
return self.__get_from_handle(handle, Family, self.family_map)
def get_repository_from_handle(self, handle):
"""
Finds a Repository in the database from the passed gramps' ID.
If no such Repository exists, None is returned.
"""
return self._get_from_handle(handle, Repository, self.repository_map)
return self.__get_from_handle(handle, Repository, self.repository_map)
def get_note_from_handle(self, handle):
"""
Finds a Note in the database from the passed gramps' ID.
If no such Note exists, None is returned.
"""
return self._get_from_handle(handle, Note, self.note_map)
return self.__get_from_handle(handle, Note, self.note_map)
def _find_from_handle(self, handle, transaction, class_type, dmap,
add_func):
@ -876,7 +824,7 @@ class GrampsDbBase(GrampsDBCallback):
add_func(obj, transaction)
return obj
def _check_from_handle(self, handle, transaction, class_type, dmap,
def __check_from_handle(self, handle, transaction, class_type, dmap,
add_func):
handle = str(handle)
if not dmap.has_key(handle):
@ -953,7 +901,7 @@ class GrampsDbBase(GrampsDBCallback):
Checks whether a Person with the passed handle exists in the database.
If no such Person exists, a new Person is added to the database.
"""
self._check_from_handle(handle, transaction, Person,
self.__check_from_handle(handle, transaction, Person,
self.person_map, self.add_person)
def check_source_from_handle(self, handle, transaction):
@ -961,7 +909,7 @@ class GrampsDbBase(GrampsDBCallback):
Checks whether a Source with the passed handle exists in the database.
If no such Source exists, a new Source is added to the database.
"""
self._check_from_handle(handle, transaction, Source,
self.__check_from_handle(handle, transaction, Source,
self.source_map, self.add_source)
def check_event_from_handle(self, handle, transaction):
@ -969,7 +917,7 @@ class GrampsDbBase(GrampsDBCallback):
Checks whether an Event with the passed handle exists in the database.
If no such Event exists, a new Event is added to the database.
"""
self._check_from_handle(handle, transaction, Event,
self.__check_from_handle(handle, transaction, Event,
self.event_map, self.add_event)
def check_object_from_handle(self, handle, transaction):
@ -979,7 +927,7 @@ class GrampsDbBase(GrampsDBCallback):
added to the database.
"""
self._check_from_handle(handle, transaction, MediaObject,
self.__check_from_handle(handle, transaction, MediaObject,
self.media_map, self.add_object)
def check_place_from_handle(self, handle, transaction):
@ -987,7 +935,7 @@ class GrampsDbBase(GrampsDBCallback):
Checks whether a Place with the passed handle exists in the database.
If no such Place exists, a new Place is added to the database.
"""
self._check_from_handle(handle, transaction, Place,
self.__check_from_handle(handle, transaction, Place,
self.place_map, self.add_place)
def check_family_from_handle(self, handle, transaction):
@ -995,7 +943,7 @@ class GrampsDbBase(GrampsDBCallback):
Checks whether a Family with the passed handle exists in the database.
If no such Family exists, a new Family is added to the database.
"""
self._check_from_handle(handle, transaction, Family,
self.__check_from_handle(handle, transaction, Family,
self.family_map, self.add_family)
def check_repository_from_handle(self, handle, transaction):
@ -1004,7 +952,7 @@ class GrampsDbBase(GrampsDBCallback):
database. If no such Repository exists, a new Repository is added
to the database.
"""
self._check_from_handle(handle, transaction, Repository,
self.__check_from_handle(handle, transaction, Repository,
self.repository_map, self.add_repository)
def check_note_from_handle(self, handle, transaction):
@ -1013,7 +961,7 @@ class GrampsDbBase(GrampsDBCallback):
database. If no such Note exists, a new Note is added
to the database.
"""
self._check_from_handle(handle, transaction, Note,
self.__check_from_handle(handle, transaction, Note,
self.note_map, self.add_note)
def get_person_from_gramps_id(self, val):
@ -1088,7 +1036,7 @@ class GrampsDbBase(GrampsDBCallback):
"""
raise NotImplementedError
def _add_object(self, obj, transaction, find_next_func, commit_func):
def __add_object(self, obj, transaction, find_next_func, commit_func):
if not obj.gramps_id:
obj.gramps_id = find_next_func()
if not obj.handle:
@ -1103,7 +1051,7 @@ class GrampsDbBase(GrampsDBCallback):
Adds a Person to the database, assigning internal IDs if they have
not already been defined.
"""
return self._add_object(person, transaction,
return self.__add_object(person, transaction,
self.find_next_person_gramps_id,
self.commit_person)
@ -1112,7 +1060,7 @@ class GrampsDbBase(GrampsDBCallback):
Adds a Family to the database, assigning internal IDs if they have
not already been defined.
"""
return self._add_object(family, transaction,
return self.__add_object(family, transaction,
self.find_next_family_gramps_id,
self.commit_family)
@ -1121,7 +1069,7 @@ class GrampsDbBase(GrampsDBCallback):
Adds a Source to the database, assigning internal IDs if they have
not already been defined.
"""
return self._add_object(source, transaction,
return self.__add_object(source, transaction,
self.find_next_source_gramps_id,
self.commit_source)
@ -1130,7 +1078,7 @@ class GrampsDbBase(GrampsDBCallback):
Adds an Event to the database, assigning internal IDs if they have
not already been defined.
"""
return self._add_object(event, transaction,
return self.__add_object(event, transaction,
self.find_next_event_gramps_id,
self.commit_event)
@ -1157,7 +1105,7 @@ class GrampsDbBase(GrampsDBCallback):
Adds a Place to the database, assigning internal IDs if they have
not already been defined.
"""
return self._add_object(place, transaction,
return self.__add_object(place, transaction,
self.find_next_place_gramps_id,
self.commit_place)
@ -1166,7 +1114,7 @@ class GrampsDbBase(GrampsDBCallback):
Adds a MediaObject to the database, assigning internal IDs if they have
not already been defined.
"""
return self._add_object(obj, transaction,
return self.__add_object(obj, transaction,
self.find_next_object_gramps_id,
self.commit_media_object)
@ -1175,7 +1123,7 @@ class GrampsDbBase(GrampsDBCallback):
Adds a Repository to the database, assigning internal IDs if they have
not already been defined.
"""
return self._add_object(obj, transaction,
return self.__add_object(obj, transaction,
self.find_next_repository_gramps_id,
self.commit_repository)
@ -1184,7 +1132,7 @@ class GrampsDbBase(GrampsDBCallback):
Adds a Note to the database, assigning internal IDs if they have
not already been defined.
"""
return self._add_object(obj, transaction,
return self.__add_object(obj, transaction,
self.find_next_note_gramps_id,
self.commit_note)
@ -1258,7 +1206,7 @@ class GrampsDbBase(GrampsDBCallback):
"""
return len(self.note_map)
def _all_handles(self, table):
def __all_handles(self, table):
return table.keys()
def get_person_handles(self, sort_handles=True):
@ -1278,7 +1226,7 @@ class GrampsDbBase(GrampsDBCallback):
slist.sort()
return map(lambda x: x[1], slist)
else:
return self._all_handles(self.person_map)
return self.__all_handles(self.person_map)
return []
def get_place_handles(self, sort_handles=True):
@ -1300,7 +1248,7 @@ class GrampsDbBase(GrampsDBCallback):
val = map(lambda x: x[1], slist)
return val
else:
return self._all_handles(self.place_map)
return self.__all_handles(self.place_map)
return []
def get_source_handles(self, sort_handles=True):
@ -1310,9 +1258,9 @@ class GrampsDbBase(GrampsDBCallback):
Source title.
"""
if self.db_is_open:
handle_list = self._all_handles(self.source_map)
handle_list = self.__all_handles(self.source_map)
if sort_handles:
handle_list.sort(self._sortbysource)
handle_list.sort(self.__sortbysource)
return handle_list
return []
@ -1322,9 +1270,9 @@ class GrampsDbBase(GrampsDBCallback):
the database. If sort_handles is True, the list is sorted by title.
"""
if self.db_is_open:
handle_list = self._all_handles(self.media_map)
handle_list = self.__all_handles(self.media_map)
if sort_handles:
handle_list.sort(self._sortbymedia)
handle_list.sort(self.__sortbymedia)
return handle_list
return []
@ -1334,7 +1282,7 @@ class GrampsDbBase(GrampsDBCallback):
the database.
"""
if self.db_is_open:
return self._all_handles(self.event_map)
return self.__all_handles(self.event_map)
return []
def get_family_handles(self):
@ -1343,7 +1291,7 @@ class GrampsDbBase(GrampsDBCallback):
the database.
"""
if self.db_is_open:
return self._all_handles(self.family_map)
return self.__all_handles(self.family_map)
return []
def get_repository_handles(self):
@ -1352,7 +1300,7 @@ class GrampsDbBase(GrampsDBCallback):
the database.
"""
if self.db_is_open:
return self._all_handles(self.repository_map)
return self.__all_handles(self.repository_map)
return []
def get_note_handles(self):
@ -1361,7 +1309,7 @@ class GrampsDbBase(GrampsDBCallback):
the database.
"""
if self.db_is_open:
return self._all_handles(self.note_map)
return self.__all_handles(self.note_map)
return []
def get_gramps_ids(self, obj_key):
@ -1497,7 +1445,7 @@ class GrampsDbBase(GrampsDBCallback):
transaction_commit function of the this database object.
"""
if self.__LOG_ALL:
log.debug("%s: Transaction begin '%s'\n"
LOG.debug("%s: Transaction begin '%s'\n"
% (self.__class__.__name__, str(msg)))
if batch:
# A batch transaction does not store the commits
@ -1514,7 +1462,7 @@ class GrampsDbBase(GrampsDBCallback):
Commits the transaction to the assocated UNDO database.
"""
if self.__LOG_ALL:
log.debug("%s: Transaction commit '%s'\n"
LOG.debug("%s: Transaction commit '%s'\n"
% (self.__class__.__name__, str(msg)))
if not len(transaction) or self.readonly:
@ -1536,51 +1484,44 @@ class GrampsDbBase(GrampsDBCallback):
for index in range(self.undoindex+1, _UNDO_SIZE):
self.translist[index] = None
person_add = self._do_commit(transaction.person_add,self.person_map)
family_add = self._do_commit(transaction.family_add,self.family_map)
source_add = self._do_commit(transaction.source_add,self.source_map)
place_add = self._do_commit(transaction.place_add, self.place_map)
media_add = self._do_commit(transaction.media_add, self.media_map)
event_add = self._do_commit(transaction.event_add, self.event_map)
repository_add= self._do_commit(transaction.repository_add,
person_add = self.__do_commit(transaction.person_add, self.person_map)
family_add = self.__do_commit(transaction.family_add, self.family_map)
source_add = self.__do_commit(transaction.source_add, self.source_map)
place_add = self.__do_commit(transaction.place_add, self.place_map)
media_add = self.__do_commit(transaction.media_add, self.media_map)
event_add = self.__do_commit(transaction.event_add, self.event_map)
repository_add = self.__do_commit(transaction.repository_add,
self.repository_map)
note_add = self._do_commit(transaction.note_add, self.note_map)
person_upd = self._do_commit(transaction.person_update,
self.person_map)
family_upd = self._do_commit(transaction.family_update,
self.family_map)
source_upd = self._do_commit(transaction.source_update,
self.source_map)
place_upd = self._do_commit(transaction.place_update,
self.place_map)
media_upd = self._do_commit(transaction.media_update,
self.media_map)
event_upd = self._do_commit(transaction.event_update,
self.event_map)
repository_upd= self._do_commit(transaction.repository_update,
note_add = self.__do_commit(transaction.note_add, self.note_map)
person_upd = self.__do_commit(transaction.person_update, self.person_map)
family_upd = self.__do_commit(transaction.family_update, self.family_map)
source_upd = self.__do_commit(transaction.source_update, self.source_map)
place_upd = self.__do_commit(transaction.place_update, self.place_map)
media_upd = self.__do_commit(transaction.media_update, self.media_map)
event_upd = self.__do_commit(transaction.event_update, self.event_map)
repository_upd = self.__do_commit(transaction.repository_update,
self.repository_map)
note_upd = self._do_commit(transaction.note_update,
self.note_map)
note_upd = self.__do_commit(transaction.note_update, self.note_map)
self._do_emit('person', person_add, person_upd, transaction.person_del)
self._do_emit('family', family_add, family_upd, transaction.family_del)
self._do_emit('event', event_add, event_upd, transaction.event_del)
self._do_emit('source', source_add, source_upd, transaction.source_del)
self._do_emit('place', place_add, place_upd, transaction.place_del)
self._do_emit('media', media_add, media_upd, transaction.media_del)
self._do_emit('repository', repository_add, repository_upd,
self.__do_emit('person', person_add, person_upd, transaction.person_del)
self.__do_emit('family', family_add, family_upd, transaction.family_del)
self.__do_emit('event', event_add, event_upd, transaction.event_del)
self.__do_emit('source', source_add, source_upd, transaction.source_del)
self.__do_emit('place', place_add, place_upd, transaction.place_del)
self.__do_emit('media', media_add, media_upd, transaction.media_del)
self.__do_emit('repository', repository_add, repository_upd,
transaction.repository_del)
self._do_emit('note', note_add, note_upd, transaction.note_del)
self.__do_emit('note', note_add, note_upd, transaction.note_del)
self._do_del(transaction.person_del, self._del_person)
self._do_del(transaction.family_del, self._del_family)
self._do_del(transaction.place_del, self._del_place)
self._do_del(transaction.source_del, self._del_source)
self._do_del(transaction.event_del, self._del_event)
self._do_del(transaction.media_del, self._del_media)
self._do_del(transaction.repository_del, self._del_repository)
self._do_del(transaction.note_del, self._del_note)
self.__do_del(transaction.person_del, self.__del_person)
self.__do_del(transaction.family_del, self.__del_family)
self.__do_del(transaction.place_del, self.__del_place)
self.__do_del(transaction.source_del, self.__del_source)
self.__do_del(transaction.event_del, self.__del_event)
self.__do_del(transaction.media_del, self.__del_media)
self.__do_del(transaction.repository_del, self.__del_repository)
self.__do_del(transaction.note_del, self.__del_note)
if self.undo_callback:
self.undo_callback(_("_Undo %s") % transaction.get_description())
@ -1589,7 +1530,7 @@ class GrampsDbBase(GrampsDBCallback):
if self.undo_history_callback:
self.undo_history_callback()
def _do_emit(self, objtype, add_list, upd_list, del_list):
def __do_emit(self, objtype, add_list, upd_list, del_list):
if add_list:
self.emit(objtype + '-add', (add_list, ))
if upd_list:
@ -1597,12 +1538,12 @@ class GrampsDbBase(GrampsDBCallback):
if del_list:
self.emit(objtype + '-delete', (del_list, ))
def _do_del(self, del_list, func):
def __do_del(self, del_list, func):
for handle in del_list:
func(handle)
return del_list
def _do_commit(self, add_list, db_map):
def __do_commit(self, add_list, db_map):
retlist = []
for (handle, data) in add_list:
db_map[handle] = data
@ -1610,14 +1551,17 @@ class GrampsDbBase(GrampsDBCallback):
return retlist
def undo_available(self):
# returns boolean of whether or not there's a possibility of undo
"""
returns boolean of whether or not there's a possibility of undo
"""
if self.undoindex == -1 or self.readonly:
return False
return True
def redo_available(self):
# returns boolean of whether or not there's a possibility of redo
"""
returns boolean of whether or not there's a possibility of redo
"""
if self.undoindex >= _UNDO_SIZE or self.readonly:
return False
@ -1648,7 +1592,7 @@ class GrampsDbBase(GrampsDBCallback):
if key == REFERENCE_KEY:
self.undo_reference(old_data, handle)
else:
self.undo_data(old_data, handle, mapbase[key], _sigbase[key])
self.undo_data(old_data, handle, mapbase[key], __SIGBASE[key])
if self.undo_callback:
if self.undo_available():
@ -1690,7 +1634,7 @@ class GrampsDbBase(GrampsDBCallback):
if key == REFERENCE_KEY:
self.undo_reference(new_data, handle)
else:
self.undo_data(new_data, handle, mapbase[key], _sigbase[key])
self.undo_data(new_data, handle, mapbase[key], __SIGBASE[key])
if self.undo_callback:
if self.undo_available():
@ -1926,35 +1870,35 @@ class GrampsDbBase(GrampsDBCallback):
if self.readonly or not handle:
return
self._delete_primary_from_reference_map(handle, transaction)
self.__delete_primary_from_reference_map(handle, transaction)
person = self.get_person_from_handle(handle)
self.genderStats.uncount_person (person)
self.remove_from_surname_list(person)
if transaction.batch:
self._del_person(handle)
self.__del_person(handle)
else:
transaction.add(PERSON_KEY, handle, person.serialize(), None)
transaction.person_del.append(str(handle))
def get_del_func(self, key):
key2del = {
PERSON_KEY: self._del_person,
FAMILY_KEY: self._del_family,
SOURCE_KEY: self._del_source,
EVENT_KEY: self._del_event,
MEDIA_KEY: self._del_media,
PLACE_KEY: self._del_place,
REPOSITORY_KEY: self._del_repository,
NOTE_KEY: self._del_note,
PERSON_KEY: self.__del_person,
FAMILY_KEY: self.__del_family,
SOURCE_KEY: self.__del_source,
EVENT_KEY: self.__del_event,
MEDIA_KEY: self.__del_media,
PLACE_KEY: self.__del_place,
REPOSITORY_KEY: self.__del_repository,
NOTE_KEY: self.__del_note,
}
return key2del[key]
def _do_remove_object(self, handle, trans, dmap, key, del_list):
def __do_remove_object(self, handle, trans, dmap, key, del_list):
if self.readonly or not handle:
return
handle = str(handle)
self._delete_primary_from_reference_map(handle, trans)
self.__delete_primary_from_reference_map(handle, trans)
if trans.batch:
del_func = self.get_del_func(key)
del_func(handle)
@ -1969,7 +1913,7 @@ class GrampsDbBase(GrampsDBCallback):
database, preserving the change in the passed transaction. This
method must be overridden in the derived class.
"""
self._do_remove_object(handle, transaction, self.source_map,
self.__do_remove_object(handle, transaction, self.source_map,
SOURCE_KEY, transaction.source_del)
def remove_event(self, handle, transaction):
@ -1978,7 +1922,7 @@ class GrampsDbBase(GrampsDBCallback):
database, preserving the change in the passed transaction. This
method must be overridden in the derived class.
"""
self._do_remove_object(handle, transaction, self.event_map,
self.__do_remove_object(handle, transaction, self.event_map,
EVENT_KEY, transaction.event_del)
def remove_object(self, handle, transaction):
@ -1987,7 +1931,7 @@ class GrampsDbBase(GrampsDBCallback):
database, preserving the change in the passed transaction. This
method must be overridden in the derived class.
"""
self._do_remove_object(handle, transaction, self.media_map,
self.__do_remove_object(handle, transaction, self.media_map,
MEDIA_KEY, transaction.media_del)
def remove_place(self, handle, transaction):
@ -1996,7 +1940,7 @@ class GrampsDbBase(GrampsDBCallback):
database, preserving the change in the passed transaction. This
method must be overridden in the derived class.
"""
self._do_remove_object(handle, transaction, self.place_map,
self.__do_remove_object(handle, transaction, self.place_map,
PLACE_KEY, transaction.place_del)
def remove_family(self, handle, transaction):
@ -2005,7 +1949,7 @@ class GrampsDbBase(GrampsDBCallback):
database, preserving the change in the passed transaction. This
method must be overridden in the derived class.
"""
self._do_remove_object(handle, transaction, self.family_map,
self.__do_remove_object(handle, transaction, self.family_map,
FAMILY_KEY, transaction.family_del)
def remove_repository(self, handle, transaction):
@ -2014,7 +1958,7 @@ class GrampsDbBase(GrampsDBCallback):
database, preserving the change in the passed transaction. This
method must be overridden in the derived class.
"""
self._do_remove_object(handle, transaction, self.repository_map,
self.__do_remove_object(handle, transaction, self.repository_map,
REPOSITORY_KEY, transaction.repository_del)
def remove_note(self, handle, transaction):
@ -2023,7 +1967,7 @@ class GrampsDbBase(GrampsDBCallback):
database, preserving the change in the passed transaction. This
method must be overridden in the derived class.
"""
self._do_remove_object(handle, transaction, self.note_map,
self.__do_remove_object(handle, transaction, self.note_map,
NOTE_KEY, transaction.note_del)
def get_raw_person_data(self, handle):
@ -2098,21 +2042,21 @@ class GrampsDbBase(GrampsDBCallback):
"""
return self.note_map.has_key(str(handle))
def _sortbyplace(self, first, second):
def __sortbyplace(self, first, second):
return locale.strcoll(self.place_map.get(str(first))[2],
self.place_map.get(str(second))[2])
def _sortbysource(self, first, second):
def __sortbysource(self, first, second):
source1 = unicode(self.source_map[str(first)][2])
source2 = unicode(self.source_map[str(second)][2])
return locale.strcoll(source1, source2)
def _sortbymedia(self, first, second):
def __sortbymedia(self, first, second):
media1 = self.media_map[str(first)][4]
media2 = self.media_map[str(second)][4]
return locale.strcoll(media1, media2)
def _set_column_order(self, col_list, name):
def __set_column_order(self, col_list, name):
if (self.metadata != None) and (not self.readonly):
self.metadata[name] = col_list
@ -2121,65 +2065,65 @@ class GrampsDbBase(GrampsDBCallback):
Stores the Person display common information in the
database's metadata.
"""
self._set_column_order(col_list, PERSON_COL_KEY)
self.__set_column_order(col_list, PERSON_COL_KEY)
def set_family_list_column_order(self, col_list):
"""
Stores the Person display common information in the
database's metadata.
"""
self._set_column_order(col_list, FAMILY_COL_KEY)
self.__set_column_order(col_list, FAMILY_COL_KEY)
def set_child_column_order(self, col_list):
"""
Stores the Person display common information in the
database's metadata.
"""
self._set_column_order(col_list, CHILD_COL_KEY)
self.__set_column_order(col_list, CHILD_COL_KEY)
def set_place_column_order(self, col_list):
"""
Stores the Place display common information in the
database's metadata.
"""
self._set_column_order(col_list, PLACE_COL_KEY)
self.__set_column_order(col_list, PLACE_COL_KEY)
def set_source_column_order(self, col_list):
"""
Stores the Source display common information in the
database's metadata.
"""
self._set_column_order(col_list, SOURCE_COL_KEY)
self.__set_column_order(col_list, SOURCE_COL_KEY)
def set_media_column_order(self, col_list):
"""
Stores the Media display common information in the
database's metadata.
"""
self._set_column_order(col_list, MEDIA_COL_KEY)
self.__set_column_order(col_list, MEDIA_COL_KEY)
def set_event_column_order(self, col_list):
"""
Stores the Event display common information in the
database's metadata.
"""
self._set_column_order(col_list, EVENT_COL_KEY)
self.__set_column_order(col_list, EVENT_COL_KEY)
def set_repository_column_order(self, col_list):
"""
Stores the Repository display common information in the
database's metadata.
"""
self._set_column_order(col_list, REPOSITORY_COL_KEY)
self.__set_column_order(col_list, REPOSITORY_COL_KEY)
def set_note_column_order(self, col_list):
"""
Stores the Note display common information in the
database's metadata.
"""
self._set_column_order(col_list, NOTE_COL_KEY)
self.__set_column_order(col_list, NOTE_COL_KEY)
def _get_column_order(self, name, default):
def __get_column_order(self, name, default):
if self.metadata == None:
return default
else:
@ -2197,10 +2141,10 @@ class GrampsDbBase(GrampsDBCallback):
default = [(1, 1, 100), (1, 2, 100), (1, 3, 150), (0, 4, 150),
(1, 5, 150), (0, 6, 150), (0, 7, 100), (0, 8, 100),
]
return self._get_column_order(PERSON_COL_KEY, default)
return self.__get_column_order(PERSON_COL_KEY, default)
def _get_columns(self, key, default):
values = self._get_column_order(key, default)
def __get_columns(self, key, default):
values = self.__get_column_order(key, default)
new = []
for val in values:
if len(val) == 2:
@ -2219,7 +2163,7 @@ class GrampsDbBase(GrampsDBCallback):
"""
default = [(1, 0, 75), (1, 1, 200), (1, 2, 200), (1, 3, 100),
(0, 4, 100)]
return self._get_columns(FAMILY_COL_KEY, default)
return self.__get_columns(FAMILY_COL_KEY, default)
def get_child_column_order(self):
"""
@ -2228,7 +2172,7 @@ class GrampsDbBase(GrampsDBCallback):
"""
default = [(1, 0), (1, 1), (1, 2), (1, 3), (1, 4), (1, 5),
(0, 6), (0, 7)]
return self._get_column_order(CHILD_COL_KEY, default)
return self.__get_column_order(CHILD_COL_KEY, default)
def get_place_column_order(self):
"""
@ -2238,7 +2182,7 @@ class GrampsDbBase(GrampsDBCallback):
default = [(1, 0, 250), (1, 1, 75), (1, 11, 100), (0, 3, 100),
(1, 4, 100, ), (0, 5, 150), (1, 6, 150), (0, 7, 150),
(0, 8, 150), (0, 9, 150), (0, 10, 150),(0,2,100)]
return self._get_columns(PLACE_COL_KEY, default)
return self.__get_columns(PLACE_COL_KEY, default)
def get_source_column_order(self):
"""
@ -2247,7 +2191,7 @@ class GrampsDbBase(GrampsDBCallback):
"""
default = [(1, 0, 200), (1, 1, 75), (1, 2, 150), (0, 3, 100),
(1, 4, 150), (0, 5, 100)]
return self._get_columns(SOURCE_COL_KEY, default)
return self.__get_columns(SOURCE_COL_KEY, default)
def get_media_column_order(self):
"""
@ -2256,7 +2200,7 @@ class GrampsDbBase(GrampsDBCallback):
"""
default = [(1, 0, 200, ), (1, 1, 75), (1, 2, 100), (1, 3, 200),
(1, 5, 150), (0, 4, 150)]
return self._get_columns(MEDIA_COL_KEY, default)
return self.__get_columns(MEDIA_COL_KEY, default)
def get_event_column_order(self):
"""
@ -2265,7 +2209,7 @@ class GrampsDbBase(GrampsDBCallback):
"""
default = [(1, 0, 200), (1, 1, 75), (1, 2, 100), (1, 3, 150),
(1, 4, 200), (0, 5, 100)]
return self._get_columns(EVENT_COL_KEY, default)
return self.__get_columns(EVENT_COL_KEY, default)
def get_repository_column_order(self):
"""
@ -2275,7 +2219,7 @@ class GrampsDbBase(GrampsDBCallback):
default = [(1, 0, 200), (1, 1, 75), (0, 5, 100), (0, 6, 100),
(1, 2, 100), (1, 3, 250), (1, 4, 100), (0, 7, 100),
(0, 8, 100), (0, 9, 100), (0, 10, 100)]
return self._get_columns(REPOSITORY_COL_KEY, default)
return self.__get_columns(REPOSITORY_COL_KEY, default)
def get_note_column_order(self):
"""
@ -2283,15 +2227,15 @@ class GrampsDbBase(GrampsDBCallback):
database's metadata.
"""
default = [(1, 0, 100), (1, 1, 100), (0, 2, 100), (1, 3, 100)]
return self._get_columns(NOTE_COL_KEY, default)
return self.__get_columns(NOTE_COL_KEY, default)
def _delete_primary_from_reference_map(self, handle, transaction):
def __delete_primary_from_reference_map(self, handle, transaction):
"""Called each time an object is removed from the database. This can
be used by subclasses to update any additional index tables that might
need to be changed."""
pass
def _update_reference_map(self, obj, transaction):
def __update_reference_map(self, obj, transaction):
"""Called each time an object is writen to the database. This can
be used by subclasses to update any additional index tables that might
need to be changed."""
@ -2444,12 +2388,6 @@ class Transaction:
self.note_del = []
self.note_update = []
## def set_batch(self, batch):
## self.batch = batch
def get_batch(self):
return self.batch
def get_description(self):
"""
Returns the text string that describes the logical operation

View File

@ -39,6 +39,7 @@ import time
#-------------------------------------------------------------------------
from RelLib import *
from _GrampsDbBase import *
from _GrampsCursor import GrampsCursor
class GrampsInMemCursor(GrampsCursor):
"""
@ -81,26 +82,7 @@ class GrampsInMemDB(GrampsDbBase):
def __init__(self):
"""creates a new GrampsDB"""
GrampsDbBase.__init__(self)
self.person_map = {}
self.name_group = {}
self.family_map = {}
self.place_map = {}
self.source_map = {}
self.repository_map = {}
self.note_map = {}
self.media_map = {}
self.event_map = {}
self.metadata = {}
self.filename = ""
self.id_trans = {}
self.pid_trans = {}
self.fid_trans = {}
self.eid_trans = {}
self.sid_trans = {}
self.rid_trans = {}
self.nid_trans = {}
self.oid_trans = {}
self.undodb = []
def load(self,name,callback,mode="w"):
self.full_name = name
@ -181,42 +163,42 @@ class GrampsInMemDB(GrampsDbBase):
if do_remove:
self.surname_list.remove(unicode(name))
def _del_person(self,handle):
def __del_person(self,handle):
person = self.get_person_from_handle(str(handle))
del self.id_trans[person.get_gramps_id()]
del self.person_map[str(handle)]
def _del_source(self,handle):
def __del_source(self,handle):
source = self.get_source_from_handle(str(handle))
del self.sid_trans[source.get_gramps_id()]
del self.source_map[str(handle)]
def _del_repository(self,handle):
def __del_repository(self,handle):
repository = self.get_repository_from_handle(str(handle))
del self.rid_trans[repository.get_gramps_id()]
del self.repository_map[str(handle)]
def _del_note(self,handle):
def __del_note(self,handle):
note = self.get_note_from_handle(str(handle))
del self.nid_trans[note.get_gramps_id()]
del self.note_map[str(handle)]
def _del_place(self,handle):
def __del_place(self,handle):
place = self.get_place_from_handle(str(handle))
del self.pid_trans[place.get_gramps_id()]
del self.place_map[str(handle)]
def _del_media(self,handle):
def __del_media(self,handle):
obj = self.get_object_from_handle(str(handle))
del self.oid_trans[obj.get_gramps_id()]
del self.media_map[str(handle)]
def _del_family(self,handle):
def __del_family(self,handle):
family = self.get_family_from_handle(str(handle))
del self.fid_trans[family.get_gramps_id()]
del self.family_map[str(handle)]
def _del_event(self,handle):
def __del_event(self,handle):
event = self.get_event_from_handle(str(handle))
del self.eid_trans[event.get_gramps_id()]
del self.event_map[str(handle)]
@ -263,7 +245,7 @@ class GrampsInMemDB(GrampsDbBase):
trans_map[data[self.ID_INDEX]] = str(handle)
self.emit(signal, ([handle], ))
def _commit_inmem_base(self,obj,db_map,trans_map):
def __commit_inmem_base(self,obj,db_map,trans_map):
if self.readonly or not obj or not obj.get_handle():
return False
gid = obj.gramps_id
@ -276,43 +258,43 @@ class GrampsInMemDB(GrampsDbBase):
return True
def commit_person(self,person,transaction,change_time=None):
if not self._commit_inmem_base(person,self.person_map,self.id_trans):
if not self.__commit_inmem_base(person,self.person_map,self.id_trans):
return
GrampsDbBase.commit_person(self,person,transaction,change_time)
def commit_place(self,place,transaction,change_time=None):
if not self._commit_inmem_base(place,self.place_map,self.pid_trans):
if not self.__commit_inmem_base(place,self.place_map,self.pid_trans):
return
GrampsDbBase.commit_place(self,place,transaction,change_time)
def commit_family(self,family,transaction,change_time=None):
if not self._commit_inmem_base(family,self.family_map,self.fid_trans):
if not self.__commit_inmem_base(family,self.family_map,self.fid_trans):
return
GrampsDbBase.commit_family(self,family,transaction,change_time)
def commit_event(self,event,transaction,change_time=None):
if not self._commit_inmem_base(event,self.event_map,self.eid_trans):
if not self.__commit_inmem_base(event,self.event_map,self.eid_trans):
return
GrampsDbBase.commit_event(self,event,transaction,change_time)
def commit_media_object(self,obj,transaction,change_time=None):
if not self._commit_inmem_base(obj,self.media_map,self.oid_trans):
if not self.__commit_inmem_base(obj,self.media_map,self.oid_trans):
return
GrampsDbBase.commit_media_object(self,obj,transaction,change_time)
def commit_source(self,source,transaction,change_time=None):
if not self._commit_inmem_base(source,self.source_map,self.sid_trans):
if not self.__commit_inmem_base(source,self.source_map,self.sid_trans):
return
GrampsDbBase.commit_source(self,source,transaction,change_time)
def commit_repository(self,repository,transaction,change_time=None):
if not self._commit_inmem_base(repository,self.repository_map,
if not self.__commit_inmem_base(repository,self.repository_map,
self.rid_trans):
return
GrampsDbBase.commit_repository(self,repository,transaction,change_time)
def commit_note(self,note,transaction,change_time=None):
if not self._commit_inmem_base(note, self.note_map,
if not self.__commit_inmem_base(note, self.note_map,
self.nid_trans):
return
GrampsDbBase.commit_note(self,note,transaction,change_time)

View File

@ -1,3 +1,23 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2007 Richard Taylor
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
"""
This module provides a progess dialog for displaying the status of
long running operations.
@ -45,7 +65,7 @@ class ProgressMonitor(object):
popup_time = None):
"""
@param dialog_class: A class used to display the progress dialog.
@type dialog_class: L{_GtkProgressDialog} or the same interface.
@type dialog_class: _GtkProgressDialog or the same interface.
@param dialog_class_params: A tuple that will be used as the initial
arguments to the dialog_class, this might be used for passing in

View File

@ -84,7 +84,7 @@ gdir_PYTHON = \
MOSTLYCLEANFILES = *pyc *pyo
# Which modules to document
docmodules = RelLib DateHandler GrampsDb Filters ReportBase GrampsDbUtils
docmodules = RelLib DateHandler GrampsDb Simple #Filters ReportBase GrampsDbUtils
pycheck:
for d in $(SUBDIRS) ; do \
@ -93,8 +93,7 @@ pycheck:
pychecker $(gdir_PYTHON)
docs:
epydoc -o doc --url http://gramps-project.org --name GRAMPS --html $(docmodules)
epydoc --pdf $(docmodules)
epydoc -v -o html --html --exclude gtk --no-private --show-imports --url=http://gramps-project.org --graph=umlclasstree $(docmodules)
cmdplug:
./build_cmdplug

View File

@ -542,9 +542,6 @@ class SimpleAccess:
@param obj: Person or Family
@type obj: L{RelLib.Person} or L{RelLib.Family}
@param restrict: Optional list of strings that will limit the types
of events to those of the specfied types.
@type restrict: list
@return: list of events assocated with the object
@rtype: list
"""

31
src/Simple/__init__.py Normal file
View File

@ -0,0 +1,31 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2001 David R. Hampton
# Copyright (C) 2001-2006 Donald N. Allingham
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id: __init__.py 7972 2007-01-24 19:45:57Z pez4brian $
"Simple access routines"
__author__ = "Donald N. Allingham"
__version__ = "$Revision: 7972 $"
from _SimpleAccess import *
from _SimpleDoc import *