From 2615728437bccb99fa263199c17737dd29cb5b72 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Mon, 4 Jun 2007 02:49:31 +0000 Subject: [PATCH] 2007-06-03 Don Allingham * src/Simple/__init__.py: add svn: r8531 --- ChangeLog | 3 + INSTALL | 300 ++++++-- src/BasicUtils/BasicUtils.py | 2 +- src/DateHandler/Makefile.am | 9 + src/DbLoader.py | 16 +- src/GrampsDb/Makefile.am | 1 + src/GrampsDb/_GrampsBSDDB.py | 1208 +++++++++++++++--------------- src/GrampsDb/_GrampsDBDir.py | 19 +- src/GrampsDb/_GrampsDbBase.py | 528 ++++++------- src/GrampsDb/_GrampsInMemDB.py | 56 +- src/GrampsDb/_ProgressMonitor.py | 24 +- src/Makefile.am | 5 +- src/Simple/_SimpleAccess.py | 3 - src/Simple/__init__.py | 31 + 14 files changed, 1159 insertions(+), 1046 deletions(-) create mode 100644 src/Simple/__init__.py diff --git a/ChangeLog b/ChangeLog index b3cc73d51..f10ade1b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2007-06-03 Don Allingham + * src/Simple/__init__.py: add + 2007-06-01 Alex Roitman * src/DbLoader.py (_OPEN_FORMATS): Remove grdb from the native format list. diff --git a/INSTALL b/INSTALL index f6546ee94..23e5f25d0 100644 --- a/INSTALL +++ b/INSTALL @@ -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. diff --git a/src/BasicUtils/BasicUtils.py b/src/BasicUtils/BasicUtils.py index 0952d6f2c..2430a5565 100644 --- a/src/BasicUtils/BasicUtils.py +++ b/src/BasicUtils/BasicUtils.py @@ -46,7 +46,7 @@ class UpdateCallback: things during lenghty operations. """ - def __init__(self,callback,interval=1): + def __init__(self, callback, interval=1): """ @param callback: a function with one arg to execute every so often @type callback: function diff --git a/src/DateHandler/Makefile.am b/src/DateHandler/Makefile.am index d24d1246d..36d9421dc 100644 --- a/src/DateHandler/Makefile.am +++ b/src/DateHandler/Makefile.am @@ -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)); diff --git a/src/DbLoader.py b/src/DbLoader.py index 83c5cd112..7815d7ab9 100644 --- a/src/DbLoader.py +++ b/src/DbLoader.py @@ -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) diff --git a/src/GrampsDb/Makefile.am b/src/GrampsDb/Makefile.am index b209fc75a..3f354ecdf 100644 --- a/src/GrampsDb/Makefile.am +++ b/src/GrampsDb/Makefile.am @@ -9,6 +9,7 @@ pkgdata_PYTHON = \ _DbUtils.py \ _GrampsBSDDB.py\ _GrampsDbBase.py\ + _GrampsCursor.py\ _GrampsDBCallback.py\ _GrampsDbExceptions.py\ _GrampsDbFactories.py\ diff --git a/src/GrampsDb/_GrampsBSDDB.py b/src/GrampsDb/_GrampsBSDDB.py index 9de69f23a..3c8f277b8 100644 --- a/src/GrampsDb/_GrampsBSDDB.py +++ b/src/GrampsDb/_GrampsBSDDB.py @@ -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,42 +51,67 @@ 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): - - def __init__(self,source,txn=None): + """ + Cursor to loop through a BSDDB table + """ + def __init__(self, source, txn=None): self.cursor = source.db.cursor(txn) self.source = source def first(self): d = self.cursor.first() if d: - return (d[0],pickle.loads(d[1])) + return (d[0], pickle.loads(d[1])) return None def next(self): d = self.cursor.next() if d: - return (d[0],pickle.loads(d[1])) + return (d[0], pickle.loads(d[1])) return None def close(self): @@ -100,20 +125,20 @@ class GrampsBSDDBCursor(GrampsCursor): class GrampsBSDDBAssocCursor(GrampsCursor): - def __init__(self,source,txn=None): + def __init__(self, source, txn=None): self.cursor = source.cursor(txn) self.source = source def first(self): d = self.cursor.first() if d: - return (d[0],pickle.loads(d[1])) + return (d[0], pickle.loads(d[1])) return None def next(self): d = self.cursor.next() if d: - return (d[0],pickle.loads(d[1])) + return (d[0], pickle.loads(d[1])) return None def close(self): @@ -128,19 +153,18 @@ class GrampsBSDDBAssocCursor(GrampsCursor): class GrampsBSDDBDupCursor(GrampsBSDDBAssocCursor): """Cursor that includes handling for duplicate keys""" - def set(self,key): + def set(self, key): return self.cursor.set(str(key)) def next_dup(self): return self.cursor.next_dup() - #------------------------------------------------------------------------- # # GrampsBSDDB # #------------------------------------------------------------------------- -class GrampsBSDDB(GrampsDbBase,UpdateCallback): +class GrampsBSDDB(GrampsDbBase, UpdateCallback): """GRAMPS database object. This object is a base class for other objects.""" @@ -148,140 +172,165 @@ 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): - return GrampsBSDDBCursor(self.person_map,self.txn) + return GrampsBSDDBCursor(self.person_map, self.txn) def get_family_cursor(self): - return GrampsBSDDBCursor(self.family_map,self.txn) + return GrampsBSDDBCursor(self.family_map, self.txn) def get_event_cursor(self): - return GrampsBSDDBCursor(self.event_map,self.txn) + return GrampsBSDDBCursor(self.event_map, self.txn) def get_place_cursor(self): - return GrampsBSDDBCursor(self.place_map,self.txn) + return GrampsBSDDBCursor(self.place_map, self.txn) def get_source_cursor(self): - return GrampsBSDDBCursor(self.source_map,self.txn) + return GrampsBSDDBCursor(self.source_map, self.txn) def get_media_cursor(self): - return GrampsBSDDBCursor(self.media_map,self.txn) + return GrampsBSDDBCursor(self.media_map, self.txn) def get_repository_cursor(self): - return GrampsBSDDBCursor(self.repository_map,self.txn) + return GrampsBSDDBCursor(self.repository_map, self.txn) def get_note_cursor(self): - return GrampsBSDDBCursor(self.note_map,self.txn) + return GrampsBSDDBCursor(self.note_map, self.txn) - def has_person_handle(self,handle): + def has_person_handle(self, handle): """ returns True if the handle exists in the current Person database. """ - return self.person_map.get(str(handle),txn=self.txn) != None + return self.person_map.get(str(handle), txn=self.txn) != None - def has_family_handle(self,handle): + def has_family_handle(self, handle): """ returns True if the handle exists in the current Family database. """ - return self.family_map.get(str(handle),txn=self.txn) != None + return self.family_map.get(str(handle), txn=self.txn) != None - def has_object_handle(self,handle): + def has_object_handle(self, handle): """ returns True if the handle exists in the current MediaObjectdatabase. """ - return self.media_map.get(str(handle),txn=self.txn) != None + return self.media_map.get(str(handle), txn=self.txn) != None - def has_repository_handle(self,handle): + def has_repository_handle(self, handle): """ returns True if the handle exists in the current Repository database. """ - return self.repository_map.get(str(handle),txn=self.txn) != None + return self.repository_map.get(str(handle), txn=self.txn) != None - def has_note_handle(self,handle): + def has_note_handle(self, handle): """ returns True if the handle exists in the current Note database. """ - return self.note_map.get(str(handle),txn=self.txn) != None + return self.note_map.get(str(handle), txn=self.txn) != None - def has_event_handle(self,handle): + def has_event_handle(self, handle): """ returns True if the handle exists in the current Repository database. """ - return self.event_map.get(str(handle),txn=self.txn) != None + return self.event_map.get(str(handle), txn=self.txn) != None - def has_place_handle(self,handle): + def has_place_handle(self, handle): """ returns True if the handle exists in the current Repository database. """ - return self.place_map.get(str(handle),txn=self.txn) != None + return self.place_map.get(str(handle), txn=self.txn) != None - def has_source_handle(self,handle): + def has_source_handle(self, handle): """ returns True if the handle exists in the current Repository database. """ - return self.source_map.get(str(handle),txn=self.txn) != None + return self.source_map.get(str(handle), txn=self.txn) != None - def get_raw_person_data(self,handle): - return self.person_map.get(str(handle),txn=self.txn) + 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): - return self.family_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): - return self.media_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): - return self.place_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): - return self.event_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): - return self.source_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): - return self.repository_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): - return self.note_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 # lookups. The reference_map has three indexes: - # the main index: a tuple of (primary_handle,referenced_handle) + # the main index: a tuple of (primary_handle, referenced_handle) # 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): - return GrampsBSDDBAssocCursor(self.reference_map,self.txn) + return GrampsBSDDBAssocCursor(self.reference_map, self.txn) def get_reference_map_primary_cursor(self): - return GrampsBSDDBDupCursor(self.reference_map_primary_map,self.txn) + return GrampsBSDDBDupCursor(self.reference_map_primary_map, self.txn) def get_reference_map_referenced_cursor(self): - return GrampsBSDDBDupCursor(self.reference_map_referenced_map,self.txn) + return GrampsBSDDBDupCursor(self.reference_map_referenced_map, self.txn) # These are overriding the GrampsDbBase's methods of saving metadata # because we now have txn-capable metadata table @@ -293,7 +342,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): the_txn = self.env.txn_begin() else: the_txn = None - self.metadata.put('default',str(handle),txn=the_txn) + self.metadata.put('default', str(handle), txn=the_txn) if self.UseTXN: the_txn.commit() else: @@ -310,7 +359,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): the_txn = self.env.txn_begin() else: the_txn = None - self.metadata.put('default',None,txn=the_txn) + self.metadata.put('default', None, txn=the_txn) if self.UseTXN: the_txn.commit() else: @@ -324,21 +373,21 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): the_txn = self.env.txn_begin() else: the_txn = None - self.metadata.put(name,col_list,txn=the_txn) + self.metadata.put(name, col_list, txn=the_txn) if self.UseTXN: the_txn.commit() else: self.metadata.sync() def version_supported(self): - dbversion = self.metadata.get('version',default=0) + dbversion = self.metadata.get('version', default=0) return ((dbversion <= _DBVERSION) and (dbversion >= _MINVERSION)) def need_upgrade(self): - dbversion = self.metadata.get('version',default=0) + dbversion = self.metadata.get('version', default=0) return not self.readonly and dbversion < _DBVERSION - def load(self,name,callback,mode="w"): + def load(self, name, callback, mode="w"): if self.db_is_open: self.close() @@ -352,18 +401,18 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): self.brief_name = os.path.basename(name) self.env = db.DBEnv() - self.env.set_cachesize(0,0x4000000) # 32MB + self.env.set_cachesize(0, 0x4000000) # 32MB if self.UseTXN: # These env settings are only needed for Txn environment self.env.set_lk_max_locks(25000) self.env.set_lk_max_objects(25000) - self.env.set_flags(db.DB_LOG_AUTOREMOVE,1) # clean up unused logs + self.env.set_flags(db.DB_LOG_AUTOREMOVE, 1) # clean up unused logs # The DB_PRIVATE flag must go if we ever move to multi-user setup - 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 + 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 # Only do recovery for existing databases if os.path.isfile(self.full_name): env_flags = env_flags | db.DB_RECOVER @@ -371,59 +420,37 @@ 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_flags = db.DB_CREATE | db.DB_PRIVATE | db.DB_INIT_MPOOL env_name = os.path.expanduser('~') - self.env.open(env_name,env_flags) + self.env.open(env_name, env_flags) if self.UseTXN: 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", - dbtype=db.DB_BTREE) - callback(37) + 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) - self._load_metadata() + self.__load_metadata() - gstats = self.metadata.get('gender_stats',default=None) + gstats = self.metadata.get('gender_stats', default=None) if not self.readonly: if self.UseTXN: @@ -434,11 +461,11 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): if gstats == None: # New database. Set up the current version. - self.metadata.put('version',_DBVERSION,txn=the_txn) + self.metadata.put('version', _DBVERSION, txn=the_txn) elif not self.metadata.has_key('version'): # Not new database, but the version is missing. # Use 0, but it is likely to fail anyway. - self.metadata.put('version',0,txn=the_txn) + self.metadata.put('version', 0, txn=the_txn) if self.UseTXN: the_txn.commit() @@ -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) @@ -476,25 +497,25 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): return 1 def load_from(self, other_database, filename, callback): - self.load(filename,callback) - db_copy(other_database,self,callback) + self.load(filename, callback) + 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=[]) + self.name_formats = self.metadata.get('name_formats', default=[]) # 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: - format = format + (True,) + format = format + (True, ) self.name_formats[format_ix] = format # database owner self.set_researcher(self.metadata.get('researcher', default=self.owner)) # bookmarks - self.bookmarks.set(self.metadata.get('bookmarks',default=[])) + self.bookmarks.set(self.metadata.get('bookmarks', default=[])) self.family_bookmarks.set(self.metadata.get('family_bookmarks', default=[])) self.event_bookmarks.set(self.metadata.get('event_bookmarks', @@ -519,26 +540,26 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): default=[])) self.individual_attributes = set(self.metadata.get('pattr_names', default=[])) - self.marker_names = set(self.metadata.get('marker_names',default=[])) + self.marker_names = set(self.metadata.get('marker_names', default=[])) 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=[])) - self.name_types = set(self.metadata.get('name_types',default=[])) + self.name_types = set(self.metadata.get('name_types', default=[])) self.repository_types = set(self.metadata.get('repo_types', default=[])) self.note_types = set(self.metadata.get('note_types', default=[])) self.source_media_types = set(self.metadata.get('sm_types', default=[])) - self.url_types = set(self.metadata.get('url_types',default=[])) + self.url_types = set(self.metadata.get('url_types', default=[])) self.media_attributes = set(self.metadata.get('mattr_names', default=[])) # surname list - self.surname_list = self.metadata.get('surname_list',default=[]) + self.surname_list = self.metadata.get('surname_list', default=[]) def connect_secondary(self): """ @@ -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 @@ -646,74 +667,74 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): self.rmap_index = len(self.repository_map) self.nmap_index = len(self.note_map) - def rebuild_secondary(self,callback): + def rebuild_secondary(self, callback): if self.readonly: return - table_flags = self.open_flags() + table_flags = self.__open_flags() # remove existing secondary indices self.id_trans.close() junk = db.DB(self.env) - junk.remove(self.full_name,"idtrans") + junk.remove(self.full_name, "idtrans") callback(1) self.surnames.close() junk = db.DB(self.env) - junk.remove(self.full_name,"surnames") + junk.remove(self.full_name, "surnames") callback(2) # Repair secondary indices related to family_map self.fid_trans.close() junk = db.DB(self.env) - junk.remove(self.full_name,"fidtrans") + junk.remove(self.full_name, "fidtrans") callback(3) # Repair secondary indices related to place_map self.pid_trans.close() junk = db.DB(self.env) - junk.remove(self.full_name,"pidtrans") + junk.remove(self.full_name, "pidtrans") callback(4) # Repair secondary indices related to media_map self.oid_trans.close() junk = db.DB(self.env) - junk.remove(self.full_name,"oidtrans") + junk.remove(self.full_name, "oidtrans") callback(5) # Repair secondary indices related to source_map self.sid_trans.close() junk = db.DB(self.env) - junk.remove(self.full_name,"sidtrans") + junk.remove(self.full_name, "sidtrans") callback(6) # Repair secondary indices related to event_map self.eid_trans.close() junk = db.DB(self.env) - junk.remove(self.full_name,"eidtrans") + junk.remove(self.full_name, "eidtrans") callback(7) # Repair secondary indices related to repository_map self.rid_trans.close() junk = db.DB(self.env) - junk.remove(self.full_name,"ridtrans") + junk.remove(self.full_name, "ridtrans") callback(8) # Repair secondary indices related to note_map self.nid_trans.close() junk = db.DB(self.env) - junk.remove(self.full_name,"nidtrans") + junk.remove(self.full_name, "nidtrans") callback(9) # Repair secondary indices related to reference_map self.reference_map_primary_map.close() junk = db.DB(self.env) - junk.remove(self.full_name,"reference_map_primary_map") + junk.remove(self.full_name, "reference_map_primary_map") callback(10) self.reference_map_referenced_map.close() junk = db.DB(self.env) - junk.remove(self.full_name,"reference_map_referenced_map") + junk.remove(self.full_name, "reference_map_referenced_map") callback(11) # Set flag saying that we have removed secondary indices @@ -725,7 +746,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): def find_backlink_handles(self, handle, include_classes=None): """ Find all objects that hold a reference to the object handle. - Returns an interator over a list of (class_name,handle) tuples. + Returns an interator over a list of (class_name, handle) tuples. @param handle: handle of the object to search for. @type handle: database handle @@ -750,7 +771,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): ret = None while (ret is not None): - (key,data) = ret + (key, data) = ret # data values are of the form: # ((primary_object_class_name, primary_object_handle), @@ -767,7 +788,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): data = pickle.loads(data) if include_classes == None or \ KEY_TO_CLASS_MAP[data[0][0]] in include_classes: - yield (KEY_TO_CLASS_MAP[data[0][0]],data[0][1]) + yield (KEY_TO_CLASS_MAP[data[0][0]], data[0][1]) ret = referenced_cur.next_dup() @@ -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,13 +804,13 @@ 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 remove_list = set() while (ret is not None): - (key,data) = ret + (key, data) = ret # data values are of the form: # ((primary_object_class_name, primary_object_handle), @@ -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. """ @@ -827,7 +848,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): # First thing to do is get hold of all rows in the reference_map # table that hold a reference from this primary obj. This means # finding all the rows that have this handle somewhere in the - # list of (class_name,handle) pairs. + # list of (class_name, handle) pairs. # The primary_map sec index allows us to look this up quickly. existing_references = set() @@ -840,7 +861,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): ret = None while (ret is not None): - (key,data) = ret + (key, data) = ret # data values are of the form: # ((primary_object_class_name, primary_object_handle), @@ -877,35 +898,35 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): new_references = set(obj.get_referenced_handles_recursively()) # handle addition of new references - 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) + 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) # handle deletion of old references - for (ref_class_name,ref_handle) in no_longer_required_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. """ if not self.readonly: if transaction.batch: - self.reference_map.delete(str(key),txn=txn) + self.reference_map.delete(str(key), txn=txn) if not self.UseTXN: self.reference_map.sync() else: - old_data = self.reference_map.get(str(key),txn=self.txn) - transaction.add(REFERENCE_KEY,str(key),old_data,None) + old_data = self.reference_map.get(str(key), txn=self.txn) + 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. @@ -915,14 +936,14 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): return if transaction.batch: - self.reference_map.put(str(key),data,txn=txn) + self.reference_map.put(str(key), data, txn=txn) if not self.UseTXN: self.reference_map.sync() else: - transaction.add(REFERENCE_KEY,str(key),None,data) - transaction.reference_add.append((str(key),data)) + transaction.add(REFERENCE_KEY, str(key), None, data) + transaction.reference_add.append((str(key), data)) - def reindex_reference_map(self,callback): + def reindex_reference_map(self, callback): """ Reindex all primary records in the database. This will be a slow process for large databases. @@ -932,31 +953,31 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): # First, remove the reference map and related tables self.reference_map_referenced_map.close() junk = db.DB(self.env) - junk.remove(self.full_name,"reference_map_referenced_map") + junk.remove(self.full_name, "reference_map_referenced_map") callback(1) self.reference_map_primary_map.close() junk = db.DB(self.env) - junk.remove(self.full_name,"reference_map_primary_map") + junk.remove(self.full_name, "reference_map_primary_map") callback(2) self.reference_map.close() junk = db.DB(self.env) - junk.remove(self.full_name,"reference_map") + junk.remove(self.full_name, "reference_map") callback(3) # Open reference_map and primapry map - self.reference_map = self.open_table(self.full_name, "reference_map", - dbtype=db.DB_BTREE) + 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 @@ -980,7 +1001,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): 'class_func': Note}, } - transaction = self.transaction_begin(batch=True,no_magic=True) + transaction = self.transaction_begin(batch=True, no_magic=True) callback(4) # Now we use the functions and classes defined above @@ -994,7 +1015,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): # not happen inside the cursor loop. class_func = primary_tables[primary_table_name]['class_func'] while data: - found_handle,val = data + found_handle, val = data obj = class_func() obj.unserialize(val) @@ -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: @@ -1012,20 +1033,20 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): cursor.close() callback(5) - self.transaction_commit(transaction,_("Rebuild reference map")) + self.transaction_commit(transaction, _("Rebuild reference map")) 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( - self.full_name,"reference_map_referenced_map", - db.DB_BTREE,flags=open_flags) + 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 @@ -1034,62 +1055,62 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): the_txn = None # name display formats - self.metadata.put('name_formats',self.name_formats,txn=the_txn) + self.metadata.put('name_formats', self.name_formats, txn=the_txn) # database owner self.metadata.put('researcher', self.owner, txn=the_txn) # bookmarks - self.metadata.put('bookmarks',self.bookmarks.get(),txn=the_txn) - self.metadata.put('family_bookmarks',self.family_bookmarks.get(), + self.metadata.put('bookmarks', self.bookmarks.get(), txn=the_txn) + self.metadata.put('family_bookmarks', self.family_bookmarks.get(), txn=the_txn) - self.metadata.put('event_bookmarks',self.event_bookmarks.get(), + self.metadata.put('event_bookmarks', self.event_bookmarks.get(), txn=the_txn) - self.metadata.put('source_bookmarks',self.source_bookmarks.get(), + self.metadata.put('source_bookmarks', self.source_bookmarks.get(), txn=the_txn) - self.metadata.put('place_bookmarks',self.place_bookmarks.get(), + self.metadata.put('place_bookmarks', self.place_bookmarks.get(), txn=the_txn) - self.metadata.put('repo_bookmarks',self.repo_bookmarks.get(), + self.metadata.put('repo_bookmarks', self.repo_bookmarks.get(), txn=the_txn) - self.metadata.put('media_bookmarks',self.media_bookmarks.get(), + self.metadata.put('media_bookmarks', self.media_bookmarks.get(), txn=the_txn) - self.metadata.put('note_bookmarks',self.note_bookmarks.get(), + self.metadata.put('note_bookmarks', self.note_bookmarks.get(), txn=the_txn) # gender stats - self.metadata.put('gender_stats',self.genderStats.save_stats(), + self.metadata.put('gender_stats', self.genderStats.save_stats(), txn=the_txn) # Custom type values - self.metadata.put('fevent_names',list(self.family_event_names), + self.metadata.put('fevent_names', list(self.family_event_names), txn=the_txn) - self.metadata.put('pevent_names',list(self.individual_event_names), + self.metadata.put('pevent_names', list(self.individual_event_names), txn=the_txn) - self.metadata.put('fattr_names',list(self.family_attributes), + self.metadata.put('fattr_names', list(self.family_attributes), txn=the_txn) - self.metadata.put('pattr_names',list(self.individual_attributes), + self.metadata.put('pattr_names', list(self.individual_attributes), txn=the_txn) - self.metadata.put('marker_names',list(self.marker_names), + self.metadata.put('marker_names', list(self.marker_names), txn=the_txn) - self.metadata.put('child_refs',list(self.child_ref_types), + self.metadata.put('child_refs', list(self.child_ref_types), txn=the_txn) - self.metadata.put('family_rels',list(self.family_rel_types), + self.metadata.put('family_rels', list(self.family_rel_types), txn=the_txn) - self.metadata.put('event_roles',list(self.event_role_names), + self.metadata.put('event_roles', list(self.event_role_names), txn=the_txn) - self.metadata.put('name_types',list(self.name_types), + self.metadata.put('name_types', list(self.name_types), txn=the_txn) - self.metadata.put('repo_types',list(self.repository_types), + self.metadata.put('repo_types', list(self.repository_types), txn=the_txn) - self.metadata.put('note_types',list(self.note_types), + self.metadata.put('note_types', list(self.note_types), txn=the_txn) - self.metadata.put('sm_types',list(self.source_media_types), + self.metadata.put('sm_types', list(self.source_media_types), txn=the_txn) - self.metadata.put('url_types',list(self.url_types), + self.metadata.put('url_types', list(self.url_types), txn=the_txn) - self.metadata.put('mattr_names',list(self.media_attributes), + self.metadata.put('mattr_names', list(self.media_attributes), txn=the_txn) # name display formats - self.metadata.put('surname_list',self.surname_list,txn=the_txn) + self.metadata.put('surname_list', self.surname_list, txn=the_txn) if self.UseTXN: the_txn.commit() @@ -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,60 +1198,60 @@ 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) + data_map.delete(handle, txn=the_txn) if not self.UseTXN: data_map.sync() if the_txn: the_txn.commit() else: - self._delete_primary_from_reference_map(handle,transaction) - old_data = data_map.get(handle,txn=self.txn) - transaction.add(key,handle,old_data,None) + 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): - self.person_map.delete(str(handle),txn=self.txn) + 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): - self.source_map.delete(str(handle),txn=self.txn) + 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): - self.repository_map.delete(str(handle),txn=self.txn) + 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): - self.note_map.delete(str(handle),txn=self.txn) + 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): - self.place_map.delete(str(handle),txn=self.txn) + 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): - self.media_map.delete(str(handle),txn=self.txn) + 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): - self.family_map.delete(str(handle),txn=self.txn) + 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): - self.event_map.delete(str(handle),txn=self.txn) + def __del_event(self, handle): + self.event_map.delete(str(handle), txn=self.txn) if not self.UseTXN: self.event_map.sync() - def set_name_group_mapping(self,name,group): + def set_name_group_mapping(self, name, group): if not self.readonly: if self.UseTXN: # Start transaction if needed @@ -1248,11 +1259,11 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): else: the_txn = None name = str(name) - data = self.name_group.get(name,txn=the_txn) + data = self.name_group.get(name, txn=the_txn) if not group and data: - self.name_group.delete(name,txn=the_txn) + self.name_group.delete(name, txn=the_txn) else: - self.name_group.put(name,group,txn=the_txn) + self.name_group.put(name, group, txn=the_txn) if self.UseTXN: the_txn.commit() else: @@ -1263,7 +1274,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): self.surname_list = list(set(self.surnames.keys())) self.sort_surname_list() - def remove_from_surname_list(self,person): + def remove_from_surname_list(self, person): """ 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. @@ -1276,16 +1287,16 @@ 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) + data = tbl.get(str(val), txn=self.txn) obj = class_init() ### 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: - tuple_data = prim_tbl.get(data,txn=self.txn) + tuple_data = prim_tbl.get(data, txn=self.txn) else: tuple_data = pickle.loads(data) obj.unserialize(tuple_data) @@ -1293,71 +1304,71 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): else: return None - def get_person_from_gramps_id(self,val): + def get_person_from_gramps_id(self, val): """ Finds a Person in the database from the passed gramps' ID. If no such Person exists, None is returned. """ - 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): + def get_family_from_gramps_id(self, val): """ Finds a Family in the database from the passed gramps' ID. If no such Family exists, None is 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): + def get_event_from_gramps_id(self, val): """ 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): + def get_place_from_gramps_id(self, val): """ 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): + def get_source_from_gramps_id(self, val): """ 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): + def get_object_from_gramps_id(self, val): """ 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): + def get_repository_from_gramps_id(self, val): """ 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): + def get_note_from_gramps_id(self, val): """ Finds a Note in the database from the passed gramps' ID. If no such Note exists, None is returned. """ - 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,60 +1388,60 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): the_txn = self.env.txn_begin() else: the_txn = None - self._update_reference_map(obj,transaction,txn=the_txn) - data_map.put(handle,obj.serialize(),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() if the_txn: the_txn.commit() old_data = None else: - self._update_reference_map(obj,transaction) - old_data = data_map.get(handle,txn=self.txn) + 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) + transaction.add(key, handle, old_data, new_data) if old_data: - update_list.append((handle,new_data)) + update_list.append((handle, new_data)) else: - add_list.append((handle,new_data)) + 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) + for (handle, data) in add_list: + db_map.put(handle, data, self.txn) if not self.UseTXN: db_map.sync() 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) + data = data_map.get(str(handle), txn=self.txn) except: data = None - # under certain circumstances during a database reload, + # 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) - add_func(obj,transaction) + obj.set_handle(hndl) + add_func(obj, transaction) return obj - def transaction_begin(self,msg="",batch=False,no_magic=False): + def transaction_begin(self, msg="", batch=False, no_magic=False): """ Creates a new Transaction tied to the current UNDO database. The transaction has no effect until it is committed using the @@ -1444,25 +1455,25 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): # Undo is also impossible after batch transaction self.undoindex = -1 self.translist = [None] * len(self.translist) - transaction = BdbTransaction(msg,self.undodb,batch,no_magic) + transaction = BdbTransaction(msg, self.undodb, batch, no_magic) if transaction.batch: if self.UseTXN: self.env.txn_checkpoint() - self.env.set_flags(db.DB_TXN_NOSYNC,1) # async txn + self.env.set_flags(db.DB_TXN_NOSYNC, 1) # async txn if self.secondary_connected and not transaction.no_magic: # Disconnect unneeded secondary indices self.surnames.close() junk = db.DB(self.env) - junk.remove(self.full_name,"surnames") + junk.remove(self.full_name, "surnames") self.reference_map_referenced_map.close() junk = db.DB(self.env) - junk.remove(self.full_name,"reference_map_referenced_map") + junk.remove(self.full_name, "reference_map_referenced_map") return transaction - def transaction_commit(self,transaction,msg): + def transaction_commit(self, transaction, msg): # Start BSD DB transaction -- DBTxn if self.UseTXN: @@ -1470,13 +1481,13 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): else: self.txn = None - GrampsDbBase.transaction_commit(self,transaction,msg) + GrampsDbBase.transaction_commit(self, transaction, msg) - for (key,data) in transaction.reference_add: - self.reference_map.put(str(key),data,txn=self.txn) + for (key, data) in transaction.reference_add: + self.reference_map.put(str(key), data, txn=self.txn) for key in transaction.reference_del: - self.reference_map.delete(str(key),txn=self.txn) + self.reference_map.delete(str(key), txn=self.txn) if (len(transaction.reference_add)+len(transaction.reference_del)) > 0\ and not self.UseTXN: @@ -1488,38 +1499,38 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): if transaction.batch: if self.UseTXN: self.env.txn_checkpoint() - self.env.set_flags(db.DB_TXN_NOSYNC,0) # sync txn + self.env.set_flags(db.DB_TXN_NOSYNC, 0) # sync txn 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.surnames.open(self.full_name, "surnames", + db.DB_BTREE, flags=open_flags) + self.person_map.associate(self.surnames, __find_surname, open_flags) self.reference_map_referenced_map = db.DB(self.env) self.reference_map_referenced_map.set_flags(dupe_flags) self.reference_map_referenced_map.open( - 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) + 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) # Only build surname list after surname index is surely back self.build_surname_list() self.txn = None - def undo(self,update_history=True): + def undo(self, update_history=True): print "Undoing it" if self.UseTXN: self.txn = self.env.txn_begin() - status = GrampsDbBase.undo(self,update_history) + status = GrampsDbBase.undo(self, update_history) if self.UseTXN: if status: self.txn.commit() @@ -1528,11 +1539,11 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): self.txn = None return status - def redo(self,update_history=True): + def redo(self, update_history=True): print "Redoing it" if self.UseTXN: self.txn = self.env.txn_begin() - status = GrampsDbBase.redo(self,update_history) + status = GrampsDbBase.redo(self, update_history) if self.UseTXN: if status: self.txn.commit() @@ -1541,33 +1552,33 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): self.txn = None return status - def undo_reference(self,data,handle): + def undo_reference(self, data, handle): if data == None: - self.reference_map.delete(handle,txn=self.txn) + self.reference_map.delete(handle, txn=self.txn) else: - self.reference_map.put(handle,data,txn=self.txn) + self.reference_map.put(handle, data, txn=self.txn) - def undo_data(self,data,handle,db_map,signal_root): + def undo_data(self, data, handle, db_map, signal_root): if data == None: - self.emit(signal_root + '-delete',([handle],)) - db_map.delete(handle,txn=self.txn) + self.emit(signal_root + '-delete', ([handle], )) + db_map.delete(handle, txn=self.txn) else: - ex_data = db_map.get(handle,txn=self.txn) + ex_data = db_map.get(handle, txn=self.txn) if ex_data: signal = signal_root + '-update' else: signal = signal_root + '-add' - db_map.put(handle,data,txn=self.txn) - self.emit(signal,([handle],)) + db_map.put(handle, data, txn=self.txn) + self.emit(signal, ([handle], )) - def gramps_upgrade(self,callback=None): - UpdateCallback.__init__(self,callback) + def gramps_upgrade(self, callback=None): + UpdateCallback.__init__(self, callback) child_rel_notrans = [ - "None", "Birth", "Adopted", "Stepchild", + "None", "Birth", "Adopted", "Stepchild", "Sponsored", "Foster", "Unknown", "Other", ] - version = self.metadata.get('version',default=_MINVERSION) + version = self.metadata.get('version', default=_MINVERSION) t = time.time() if version < 10: @@ -1585,14 +1596,14 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): # Remove event column metadata, since columns have changed. # This will reset all columns to defaults in event view - for name in (PERSON_COL_KEY,EVENT_COL_KEY): + for name in (PERSON_COL_KEY, EVENT_COL_KEY): try: if self.UseTXN: # Start transaction if needed the_txn = self.env.txn_begin() else: the_txn = None - self.metadata.delete(name,txn=the_txn) + self.metadata.delete(name, txn=the_txn) if self.UseTXN: the_txn.commit() else: @@ -1609,8 +1620,8 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): for handle in self.event_map.keys(): info = self.event_map[handle] - (junk_handle, gramps_id, the_type, date,description, - place, cause,source_list, note, media_list, + (junk_handle, gramps_id, the_type, date, description, + place, cause, source_list, note, media_list, change, marker, private) = info # Cause is removed, so we're converting it into an attribute @@ -1622,15 +1633,15 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): else: attr_list = [] - info = (handle, gramps_id, the_type, date, - description, place, source_list, note, media_list, + info = (handle, gramps_id, the_type, date, + description, place, source_list, note, media_list, attr_list, change, marker, private) if self.UseTXN: the_txn = self.env.txn_begin() else: the_txn = None - self.event_map.put(str(handle),info,txn=the_txn) + self.event_map.put(str(handle), info, txn=the_txn) if self.UseTXN: the_txn.commit() self.update() @@ -1642,12 +1653,12 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): for handle in self.person_map.keys(): info = self.person_map[handle] - (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 + (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 # Names lost the "sname" attribute new_primary_name = convert_name_10(primary_name) @@ -1656,21 +1667,21 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): # Events gained attribute_list new_event_ref_list = [ - (privacy,note,[],ref,role) - for (privacy,note,ref,role) in event_ref_list] + (privacy, note, [], ref, role) + for (privacy, note, ref, role) in event_ref_list] - 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,) + 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, ) if self.UseTXN: the_txn = self.env.txn_begin() else: the_txn = None - self.person_map.put(str(handle),info,txn=the_txn) + self.person_map.put(str(handle), info, txn=the_txn) if self.UseTXN: the_txn.commit() self.update() @@ -1682,26 +1693,26 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): for handle in self.family_map.keys(): info = self.family_map[handle] - (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, + (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, change, marker, private) = info new_event_ref_list = [ - (privacy,note,[],ref,role) - for (privacy,note,ref,role) in event_ref_list] + (privacy, note, [], ref, role) + for (privacy, note, ref, role) in event_ref_list] - 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) + 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) if self.UseTXN: the_txn = self.env.txn_begin() else: the_txn = None - self.family_map.put(str(handle),info,txn=the_txn) + self.family_map.put(str(handle), info, txn=the_txn) if self.UseTXN: the_txn.commit() self.update() @@ -1715,7 +1726,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): the_txn = self.env.txn_begin() else: the_txn = None - self.metadata.put('version',10,txn=the_txn) + self.metadata.put('version', 10, txn=the_txn) if self.UseTXN: the_txn.commit() else: @@ -1735,29 +1746,29 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): for handle in self.person_map.keys(): info = self.person_map[handle] - (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 + (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 new_address_list = [convert_address_11(addr) for addr in address_list] - 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,) + 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, ) if self.UseTXN: the_txn = self.env.txn_begin() else: the_txn = None - self.person_map.put(str(handle),info,txn=the_txn) + self.person_map.put(str(handle), info, txn=the_txn) if self.UseTXN: the_txn.commit() self.update() @@ -1769,20 +1780,20 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): for handle in self.repository_map.keys(): info = self.repository_map[handle] - (junk_handle, gramps_id, the_type, name, note, + (junk_handle, gramps_id, the_type, name, note, address_list, urls, marker, private) = info new_address_list = [convert_address_11(addr) for addr in address_list] - info = (handle, gramps_id, the_type, name, note, + info = (handle, gramps_id, the_type, name, note, new_address_list, urls, marker, private) if self.UseTXN: the_txn = self.env.txn_begin() else: the_txn = None - self.repository_map.put(str(handle),info,txn=the_txn) + self.repository_map.put(str(handle), info, txn=the_txn) if self.UseTXN: the_txn.commit() self.update() @@ -1794,7 +1805,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): for handle in self.place_map.keys(): info = self.place_map[handle] - (junk_handle, gramps_id, title, long, lat, main_loc, alt_loc, urls, + (junk_handle, gramps_id, title, long, lat, main_loc, alt_loc, urls, media_list, source_list, note, change, marker, private) = info if main_loc: @@ -1802,14 +1813,14 @@ 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() else: the_txn = None - self.place_map.put(str(handle),info,txn=the_txn) + self.place_map.put(str(handle), info, txn=the_txn) if self.UseTXN: the_txn.commit() self.update() @@ -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, + 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", + 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 @@ -1887,51 +1898,51 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): # Person upgrade for handle in self.person_map.keys(): info = self.person_map[handle] - (new_info,note_handles) = self.convert_notes_13('Person',info) - self.commit_13(new_info,PERSON_KEY,self.person_map,note_handles) + (new_info, note_handles) = self.convert_notes_13('Person', info) + self.commit_13(new_info, PERSON_KEY, self.person_map, note_handles) self.update() # Family upgrade for handle in self.family_map.keys(): info = self.family_map[handle] - (new_info,note_handles) = self.convert_notes_13('Family',info) - self.commit_13(new_info,FAMILY_KEY,self.family_map,note_handles) + (new_info, note_handles) = self.convert_notes_13('Family', info) + self.commit_13(new_info, FAMILY_KEY, self.family_map, note_handles) self.update() # Event upgrade for handle in self.event_map.keys(): info = self.event_map[handle] - (new_info,note_handles) = self.convert_notes_13('Event',info) - self.commit_13(new_info,EVENT_KEY,self.event_map,note_handles) + (new_info, note_handles) = self.convert_notes_13('Event', info) + self.commit_13(new_info, EVENT_KEY, self.event_map, note_handles) self.update() # Source upgrade for handle in self.source_map.keys(): info = self.source_map[handle] - (new_info,note_handles) = self.convert_notes_13('Source',info) - self.commit_13(new_info,SOURCE_KEY,self.source_map,note_handles) + (new_info, note_handles) = self.convert_notes_13('Source', info) + self.commit_13(new_info, SOURCE_KEY, self.source_map, note_handles) self.update() # Place upgrade for handle in self.place_map.keys(): info = self.place_map[handle] - (new_info,note_handles) = self.convert_notes_13('Place',info) - self.commit_13(new_info,PLACE_KEY,self.place_map,note_handles) + (new_info, note_handles) = self.convert_notes_13('Place', info) + self.commit_13(new_info, PLACE_KEY, self.place_map, note_handles) self.update() # Media upgrade for handle in self.media_map.keys(): info = self.media_map[handle] - (new_info,note_handles) = self.convert_notes_13('MediaObject',info) - self.commit_13(new_info,MEDIA_KEY,self.media_map,note_handles) + (new_info, note_handles) = self.convert_notes_13('MediaObject', info) + self.commit_13(new_info, MEDIA_KEY, self.media_map, note_handles) self.update() # Repo upgrade for handle in self.repository_map.keys(): info = self.repository_map[handle] - (new_info,note_handles) = self.convert_notes_13('Repository',info) - self.commit_13(new_info,REPOSITORY_KEY, - self.repository_map,note_handles) + (new_info, note_handles) = self.convert_notes_13('Repository', info) + self.commit_13(new_info, REPOSITORY_KEY, + self.repository_map, note_handles) self.update() if not self.UseTXN: @@ -1962,34 +1973,34 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): # Rebuild secondary indices related to reference_map junk = db.DB(self.env) - junk.remove(self.full_name,"reference_map_primary_map") + junk.remove(self.full_name, "reference_map_primary_map") 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", + self.reference_map_primary_map.open(self.full_name, + "reference_map_primary_map", db.DB_BTREE, flags=table_flags) - self.reference_map.associate(self.reference_map_primary_map, - find_primary_handle, + self.reference_map.associate(self.reference_map_primary_map, + __find_primary_handle, table_flags) self.reference_map_primary_map.close() junk = db.DB(self.env) - junk.remove(self.full_name,"reference_map_referenced_map") + junk.remove(self.full_name, "reference_map_referenced_map") 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(self.full_name, - "reference_map_referenced_map", + self.reference_map_referenced_map.open(self.full_name, + "reference_map_referenced_map", db.DB_BTREE, flags=table_flags) - self.reference_map.associate(self.reference_map_referenced_map, - find_referenced_handle, + self.reference_map.associate(self.reference_map_referenced_map, + __find_referenced_handle, table_flags) self.reference_map_referenced_map.close() print "Done upgrading to DB version 13" - def commit_13(self,data_tuple,data_key_name,data_map,note_handles=None): + def commit_13(self, data_tuple, data_key_name, data_map, note_handles=None): """ - Commits the specified object to the data_map table in the database, + Commits the specified object to the data_map table in the database, add a reference to each note handle. """ handle = str(data_tuple[0]) @@ -2001,17 +2012,17 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): # Add all references for note_handle in note_handles: - 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) + 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) # Commit data itself - data_map.put(handle,data_tuple,txn=the_txn) + data_map.put(handle, data_tuple, txn=the_txn) # Clean up if the_txn: the_txn.commit() - def convert_notes_13(self,name,obj,nttype=NoteType._DEFAULT, private=False): + def convert_notes_13(self, name, obj, nttype=NoteType._DEFAULT, private=False): """ This is the function for conversion all notes in all objects and their child objects to the top-level notes and handle references. @@ -2019,7 +2030,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): The obj is the data tuple that is not serialized. This functions returns the following tuple: - (converted_object,note_handles) + (converted_object, note_handles) 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 @@ -2031,325 +2042,308 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): if (type(obj) == tuple) and (len(obj) > 0) and \ ('strip' in dir(obj[0])) and (obj[0].strip()): # Some notes may be None, from early databases. - (text,format) = obj + (text, format) = obj handle = str(self.create_id()) gramps_id = self.find_next_note_gramps_id() - note_tuple = (handle,gramps_id,text,format,(nttype,'',), - self.change_13,(-1,'',),private) - self.commit_13(note_tuple,NOTE_KEY,self.note_map,[]) + note_tuple = (handle, gramps_id, text, format, (nttype, '', ), + self.change_13, (-1, '', ), private) + self.commit_13(note_tuple, NOTE_KEY, self.note_map, []) new_obj = [handle] note_handles = [handle] else: new_obj = [] note_handles = [] elif name == 'RepoRef': - (note,ref,call_number,media_type) = obj - (note_list,note_handles) = self.convert_notes_13('Note',note, + (note, ref, call_number, media_type) = obj + (note_list, note_handles) = self.convert_notes_13('Note', note, nttype=NoteType.REPOREF) - new_obj = (note_list,ref,call_number,media_type) + new_obj = (note_list, ref, call_number, media_type) elif name == 'SourceRef': - (date,priv,note,conf,ref,page,text) = obj - (note_list,note_handles) = self.convert_notes_13('Note',note, - nttype=NoteType.SOURCEREF, + (date, priv, note, conf, ref, page, text) = obj + (note_list, note_handles) = self.convert_notes_13('Note', note, + nttype=NoteType.SOURCEREF, private=priv) - new_obj = (date,priv,note_list,conf,ref,page,text) + new_obj = (date, priv, note_list, conf, ref, page, text) elif name == 'Attribute': - (priv,source_list,note,the_type,value) = obj - (note_list,note_handles) = self.convert_notes_13('Note',note, - nttype=NoteType.ATTRIBUTE, + (priv, source_list, note, the_type, value) = obj + (note_list, note_handles) = self.convert_notes_13('Note', note, + nttype=NoteType.ATTRIBUTE, private=priv) - tuples = [self.convert_notes_13('SourceRef',item) + tuples = [self.convert_notes_13('SourceRef', item) for item in source_list] new_source_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - new_obj = (priv,new_source_list,note_list,the_type,value) + new_obj = (priv, new_source_list, note_list, the_type, value) elif name == 'Address': - (priv,source_list,note,date,loc) = obj - (note_list,note_handles) = self.convert_notes_13('Note',note, - nttype=NoteType.ADDRESS, + (priv, source_list, note, date, loc) = obj + (note_list, note_handles) = self.convert_notes_13('Note', note, + nttype=NoteType.ADDRESS, private=priv) - tuples = [self.convert_notes_13('SourceRef',item) + tuples = [self.convert_notes_13('SourceRef', item) for item in source_list] new_source_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - new_obj = (priv,new_source_list,note_list,date,loc) + new_obj = (priv, new_source_list, note_list, date, loc) elif name == 'EventRef': - (priv,note,attr_list,ref,role) = obj - (note_list,note_handles) = self.convert_notes_13('Note',note, - nttype=NoteType.EVENTREF, + (priv, note, attr_list, ref, role) = obj + (note_list, note_handles) = self.convert_notes_13('Note', note, + nttype=NoteType.EVENTREF, private=priv) - tuples = [self.convert_notes_13('Attribute',item) + tuples = [self.convert_notes_13('Attribute', item) for item in attr_list] new_attr_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - new_obj = (priv,note_list,new_attr_list,ref,role) + new_obj = (priv, note_list, new_attr_list, ref, role) elif name == 'ChildRef': - (pri,source_list,note,ref,frel,mrel) = obj - (note_list,note_handles) = self.convert_notes_13('Note',note, - nttype=NoteType.CHILDREF, + (pri, source_list, note, ref, frel, mrel) = obj + (note_list, note_handles) = self.convert_notes_13('Note', note, + nttype=NoteType.CHILDREF, private=pri) - tuples = [self.convert_notes_13('SourceRef',item) + tuples = [self.convert_notes_13('SourceRef', item) for item in source_list] new_source_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - new_obj = (pri,new_source_list,note_list,ref,frel,mrel) + new_obj = (pri, new_source_list, note_list, ref, frel, mrel) elif name == 'PersonRef': - (priv,source_list,note,ref,rel) = obj - (note_list,note_handles) = self.convert_notes_13('Note',note, - nttype=NoteType.ASSOCIATION, + (priv, source_list, note, ref, rel) = obj + (note_list, note_handles) = self.convert_notes_13('Note', note, + nttype=NoteType.ASSOCIATION, private=priv) - tuples = [self.convert_notes_13('SourceRef',item) + tuples = [self.convert_notes_13('SourceRef', item) for item in source_list] new_source_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - new_obj = (priv,new_source_list,note_list,ref,rel) + new_obj = (priv, new_source_list, note_list, ref, rel) elif name == 'MediaRef': - (priv,source_list,note,attr_list,ref,rect) = obj - (note_list,note_handles) = self.convert_notes_13('Note',note, - nttype=NoteType.MEDIAREF, + (priv, source_list, note, attr_list, ref, rect) = obj + (note_list, note_handles) = self.convert_notes_13('Note', note, + nttype=NoteType.MEDIAREF, private=priv) - tuples = [self.convert_notes_13('SourceRef',item) + tuples = [self.convert_notes_13('SourceRef', item) for item in source_list] new_source_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - tuples = [self.convert_notes_13('Attribute',item) + tuples = [self.convert_notes_13('Attribute', item) for item in attr_list] new_attr_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - new_obj = (priv,new_source_list,note_list,new_attr_list,ref,rect) + new_obj = (priv, new_source_list, note_list, new_attr_list, ref, rect) elif name == 'Name': - (priv,source_list,note,date,f,s,su,t,ty,p,pa,g,so,di,call) = obj - (note_list,note_handles) = self.convert_notes_13('Note',note, - nttype=NoteType.PERSONNAME, + (priv, source_list, note, date, f, s, su, t, ty, p, pa, g, so, di, call) = obj + (note_list, note_handles) = self.convert_notes_13('Note', note, + nttype=NoteType.PERSONNAME, private=priv) - tuples = [self.convert_notes_13('SourceRef',item) + tuples = [self.convert_notes_13('SourceRef', item) for item in source_list] new_source_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - new_obj = (priv,new_source_list,note_list, - date,f,s,su,t,ty,p,pa,g,so,di,call) + new_obj = (priv, new_source_list, note_list, + date, f, s, su, t, ty, p, pa, g, so, di, call) elif name == 'LdsOrd': - (source_list,note,date,t,place,famc,temple,st) = obj - (note_list,note_handles) = self.convert_notes_13('Note',note, + (source_list, note, date, t, place, famc, temple, st) = obj + (note_list, note_handles) = self.convert_notes_13('Note', note, nttype=NoteType.LDS) - tuples = [self.convert_notes_13('SourceRef',item) + tuples = [self.convert_notes_13('SourceRef', item) for item in source_list] new_source_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - new_obj = (new_source_list,note_list,date,t,place,famc,temple,st) + new_obj = (new_source_list, note_list, date, t, place, famc, temple, st) elif name == 'Event': - (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, - private=priv) - tuples = [self.convert_notes_13('SourceRef',item) - for item in source_list] - new_source_list = [item[0] for item in tuples] - note_handles += [item[1] for item in tuples] - tuples = [self.convert_notes_13('MediaRef',item) - for item in media_list] - new_media_list = [item[0] for item in tuples] - note_handles += [item[1] for item in tuples] - tuples = [self.convert_notes_13('Attribute',item) - for item in attr_list] - new_attr_list = [item[0] for item in tuples] - note_handles += [item[1] for item in tuples] - new_obj = (handle,gramps_id,the_type,date,description,place, - new_source_list,note_list,new_media_list,new_attr_list, - change,marker,priv) - elif name == 'Family': - (handle,gramps_id,fh,mh,child_ref_list,the_type,event_ref_list, - media_list,attr_list,lds_list,source_list,note, + (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.FAMILY, + (note_list, note_handles) = self.convert_notes_13('Note', note, + nttype=NoteType.EVENT, private=priv) - tuples = [self.convert_notes_13('SourceRef',item) + tuples = [self.convert_notes_13('SourceRef', item) for item in source_list] new_source_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - tuples = [self.convert_notes_13('MediaRef',item) + tuples = [self.convert_notes_13('MediaRef', item) for item in media_list] new_media_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - tuples = [self.convert_notes_13('Attribute',item) + tuples = [self.convert_notes_13('Attribute', item) for item in attr_list] new_attr_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - tuples = [self.convert_notes_13('ChildRef',item) + new_obj = (handle, gramps_id, the_type, date, description, place, + new_source_list, note_list, new_media_list, new_attr_list, + change, marker, priv) + elif name == 'Family': + (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 + (note_list, note_handles) = self.convert_notes_13('Note', note, + nttype=NoteType.FAMILY, + private=priv) + tuples = [self.convert_notes_13('SourceRef', item) + for item in source_list] + new_source_list = [item[0] for item in tuples] + note_handles += [item[1] for item in tuples] + tuples = [self.convert_notes_13('MediaRef', item) + for item in media_list] + new_media_list = [item[0] for item in tuples] + note_handles += [item[1] for item in tuples] + tuples = [self.convert_notes_13('Attribute', item) + for item in attr_list] + new_attr_list = [item[0] for item in tuples] + note_handles += [item[1] for item in tuples] + tuples = [self.convert_notes_13('ChildRef', item) for item in child_ref_list] new_child_ref_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - tuples = [self.convert_notes_13('EventRef',item) + tuples = [self.convert_notes_13('EventRef', item) for item in event_ref_list] new_event_ref_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - tuples = [self.convert_notes_13('LdsOrd',item) + tuples = [self.convert_notes_13('LdsOrd', item) for item in lds_list] new_lds_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - new_obj = (handle,gramps_id,fh,mh,new_child_ref_list,the_type, - new_event_ref_list,new_media_list,new_attr_list, - new_lds_list,new_source_list,note_list, + new_obj = (handle, gramps_id, fh, mh, new_child_ref_list, the_type, + new_event_ref_list, new_media_list, new_attr_list, + new_lds_list, new_source_list, note_list, change, marker, priv) elif name == 'MediaObject': - (handle,gramps_id,path,mime,desc,attr_list,source_list,note,change, + (handle, gramps_id, path, mime, desc, attr_list, source_list, note, change, date, marker, priv) = obj - (note_list,note_handles) = self.convert_notes_13('Note',note, - nttype=NoteType.MEDIA, + (note_list, note_handles) = self.convert_notes_13('Note', note, + nttype=NoteType.MEDIA, private=priv) - tuples = [self.convert_notes_13('SourceRef',item) + tuples = [self.convert_notes_13('SourceRef', item) for item in source_list] new_source_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - tuples = [self.convert_notes_13('Attribute',item) + tuples = [self.convert_notes_13('Attribute', item) for item in attr_list] new_attr_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - new_obj = (handle,gramps_id,path,mime,desc,new_attr_list, - new_source_list,note_list,change,date,marker,priv) + new_obj = (handle, gramps_id, path, mime, desc, new_attr_list, + new_source_list, note_list, change, date, marker, priv) elif name == 'Place': - (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, + (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, private=priv) - tuples = [self.convert_notes_13('SourceRef',item) + tuples = [self.convert_notes_13('SourceRef', item) for item in source_list] new_source_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - tuples = [self.convert_notes_13('MediaRef',item) + tuples = [self.convert_notes_13('MediaRef', item) for item in media_list] new_media_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - new_obj = (handle,gramps_id,title,long,lat,main_loc,alt_loc,urls, - new_media_list,new_source_list,note_list, - change,marker,priv) + new_obj = (handle, gramps_id, title, long, lat, main_loc, alt_loc, urls, + new_media_list, new_source_list, note_list, + change, marker, priv) elif name == 'Source': - (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, + (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, private=priv) - tuples = [self.convert_notes_13('MediaRef',item) + tuples = [self.convert_notes_13('MediaRef', item) for item in media_list] new_media_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - tuples = [self.convert_notes_13('RepoRef',item) + tuples = [self.convert_notes_13('RepoRef', item) for item in reporef_list] new_reporef_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - new_obj = (handle,gramps_id,title,author,pubinfo,note_list, - new_media_list,abbrev,change,datamap,new_reporef_list, - marker,priv) + new_obj = (handle, gramps_id, title, author, pubinfo, note_list, + new_media_list, abbrev, change, datamap, new_reporef_list, + marker, priv) elif name == 'Repository': - (handle,gramps_id,t,n,note,addr_list,urls,marker,priv) = obj - (note_list,note_handles) = self.convert_notes_13('Note',note, - nttype=NoteType.REPO, + (handle, gramps_id, t, n, note, addr_list, urls, marker, priv) = obj + (note_list, note_handles) = self.convert_notes_13('Note', note, + nttype=NoteType.REPO, private=priv) - tuples = [self.convert_notes_13('Address',item) + tuples = [self.convert_notes_13('Address', item) for item in addr_list] new_addr_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - new_obj = (handle,gramps_id,t,n,note_list,new_addr_list,urls, - self.change_13,marker,priv) + new_obj = (handle, gramps_id, t, n, note_list, new_addr_list, urls, + self.change_13, marker, priv) elif name == 'Person': - (handle,gramps_id,gender,primary_name,alternate_names, - dri,bri,event_ref_list,fl,pfl,media_list,addr_list,attr_list, - urls,lds_list,source_list,note,change,marker,priv, + (handle, gramps_id, gender, primary_name, alternate_names, + 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 - (note_list,note_handles) = self.convert_notes_13('Note',note, - nttype=NoteType.PERSON, + (note_list, note_handles) = self.convert_notes_13('Note', note, + nttype=NoteType.PERSON, private=priv) - (new_primary_name,nh) = self.convert_notes_13('Name',primary_name) + (new_primary_name, nh) = self.convert_notes_13('Name', primary_name) note_handles += nh - tuples = [self.convert_notes_13('Name',item) + tuples = [self.convert_notes_13('Name', item) for item in alternate_names] new_alternate_names = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - tuples = [self.convert_notes_13('EventRef',item) + tuples = [self.convert_notes_13('EventRef', item) for item in event_ref_list] new_event_ref_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - tuples = [self.convert_notes_13('MediaRef',item) + tuples = [self.convert_notes_13('MediaRef', item) for item in media_list] new_media_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - tuples = [self.convert_notes_13('Address',item) + tuples = [self.convert_notes_13('Address', item) for item in addr_list] new_addr_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - tuples = [self.convert_notes_13('Attribute',item) + tuples = [self.convert_notes_13('Attribute', item) for item in attr_list] new_attr_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - tuples = [self.convert_notes_13('LdsOrd',item) + tuples = [self.convert_notes_13('LdsOrd', item) for item in lds_list] new_lds_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - tuples = [self.convert_notes_13('SourceRef',item) + tuples = [self.convert_notes_13('SourceRef', item) for item in source_list] new_source_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - tuples = [self.convert_notes_13('PersonRef',item) + tuples = [self.convert_notes_13('PersonRef', item) for item in person_ref_list] new_person_ref_list = [item[0] for item in tuples] note_handles += [item[1] for item in tuples] - 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) + 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) else: - print name,obj + print name, obj # Return the required tuple - return (new_obj,note_handles) + return (new_obj, note_handles) class BdbTransaction(Transaction): - def __init__(self,msg,db,batch=False,no_magic=False): - Transaction.__init__(self,msg,db,batch,no_magic) + def __init__(self, msg, db, batch=False, no_magic=False): + Transaction.__init__(self, msg, db, batch, no_magic) self.reference_del = [] self.reference_add = [] def convert_name_10(name): # Names lost the "sname" attribute - (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) + (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) def convert_address_11(addr): - # addresses got location instead of city,... - (privacy,source_list,note,date, - city,state,country,postal,phone,street) = addr + # addresses got location instead of city, ... + (privacy, source_list, note, date, + city, state, country, postal, phone, street) = addr county = u'' - location_base = (street,city,county,state,country,postal,phone) - return (privacy,source_list,note,date,location_base) + location_base = (street, city, county, state, country, postal, phone) + return (privacy, source_list, note, date, location_base) def convert_location_11(loc): - (location_base,parish,county) = loc - (city,state,country,postal,phone) = location_base + (location_base, parish, county) = loc + (city, state, country, postal, phone) = location_base 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() + new_location_base = (street, city, county, state, country, postal, phone) + return (new_location_base, parish) diff --git a/src/GrampsDb/_GrampsDBDir.py b/src/GrampsDb/_GrampsDBDir.py index 866ac1180..40b30311c 100644 --- a/src/GrampsDb/_GrampsDBDir.py +++ b/src/GrampsDb/_GrampsDBDir.py @@ -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 diff --git a/src/GrampsDb/_GrampsDbBase.py b/src/GrampsDb/_GrampsDbBase.py index f2d23fd20..75e93ca83 100644 --- a/src/GrampsDb/_GrampsDbBase.py +++ b/src/GrampsDb/_GrampsDbBase.py @@ -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 @@ -179,44 +128,43 @@ class GrampsDbBase(GrampsDBCallback): __config__ = None __signals__ = { - 'person-add' : (list, ), - 'person-update' : (list, ), - 'person-delete' : (list, ), - 'person-rebuild' : None, - 'family-add' : (list, ), - 'family-update' : (list, ), - 'family-delete' : (list, ), - 'family-rebuild' : None, - 'source-add' : (list, ), - 'source-update' : (list, ), - 'source-delete' : (list, ), - 'source-rebuild' : None, - 'place-add' : (list, ), - 'place-update' : (list, ), - 'place-delete' : (list, ), - 'place-rebuild' : None, - 'media-add' : (list, ), - 'media-update' : (list, ), - 'media-delete' : (list, ), - 'media-rebuild' : None, - 'event-add' : (list, ), - 'event-update' : (list, ), - 'event-delete' : (list, ), - 'event-rebuild' : None, - 'repository-add' : (list, ), - 'repository-update' : (list, ), - 'repository-delete' : (list, ), - 'repository-rebuild' : None, - 'note-add' : (list, ), - 'note-update' : (list, ), - 'note-delete' : (list, ), - 'note-rebuild' : None, - 'long-op-start' : (object, ), - 'long-op-heartbeat' : None, - 'long-op-end' : None + 'person-add' : (list, ), + 'person-update' : (list, ), + 'person-delete' : (list, ), + 'person-rebuild' : None, + 'family-add' : (list, ), + 'family-update' : (list, ), + 'family-delete' : (list, ), + 'family-rebuild' : None, + 'source-add' : (list, ), + 'source-update' : (list, ), + 'source-delete' : (list, ), + 'source-rebuild' : None, + 'place-add' : (list, ), + 'place-update' : (list, ), + 'place-delete' : (list, ), + 'place-rebuild' : None, + 'media-add' : (list, ), + 'media-update' : (list, ), + 'media-delete' : (list, ), + 'media-rebuild' : None, + 'event-add' : (list, ), + 'event-update' : (list, ), + 'event-delete' : (list, ), + 'event-rebuild' : None, + 'repository-add' : (list, ), + 'repository-update' : (list, ), + 'repository-delete' : (list, ), + 'repository-rebuild' : None, + 'note-add' : (list, ), + 'note-update' : (list, ), + 'note-delete' : (list, ), + 'note-rebuild' : None, + 'long-op-start' : (object, ), + 'long-op-heartbeat' : None, + 'long-op-end' : None } - # 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: @@ -527,10 +475,10 @@ class GrampsDbBase(GrampsDBCallback): self.genderStats.count_person(person) if (old_data[3][5]!=person.primary_name.surname): self.remove_from_surname_list(old_person) - self.add_to_surname_list(person,transaction.batch) + self.add_to_surname_list(person, transaction.batch) else: self.genderStats.count_person(person) - self.add_to_surname_list(person,transaction.batch) + self.add_to_surname_list(person, transaction.batch) self.individual_attributes.update( [str(attr.type) for attr in person.attribute_list @@ -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,9 +1132,9 @@ 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, - self.find_next_note_gramps_id, - self.commit_note) + return self.__add_object(obj, transaction, + self.find_next_note_gramps_id, + self.commit_note) def get_name_group_mapping(self, name): """ @@ -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,19 +1309,19 @@ 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): key2table = { - PERSON_KEY: self.id_trans, - FAMILY_KEY: self.fid_trans, - SOURCE_KEY: self.sid_trans, - EVENT_KEY: self.eid_trans, - MEDIA_KEY: self.oid_trans, - PLACE_KEY: self.pid_trans, + PERSON_KEY: self.id_trans, + FAMILY_KEY: self.fid_trans, + SOURCE_KEY: self.sid_trans, + EVENT_KEY: self.eid_trans, + MEDIA_KEY: self.oid_trans, + PLACE_KEY: self.pid_trans, REPOSITORY_KEY: self.rid_trans, - NOTE_KEY: self.nid_trans, + NOTE_KEY: self.nid_trans, } table = key2table[obj_key] @@ -1381,14 +1329,14 @@ class GrampsDbBase(GrampsDBCallback): def has_gramps_id(self, obj_key, gramps_id): key2table = { - PERSON_KEY: self.id_trans, - FAMILY_KEY: self.fid_trans, - SOURCE_KEY: self.sid_trans, - EVENT_KEY: self.eid_trans, - MEDIA_KEY: self.oid_trans, - PLACE_KEY: self.pid_trans, + PERSON_KEY: self.id_trans, + FAMILY_KEY: self.fid_trans, + SOURCE_KEY: self.sid_trans, + EVENT_KEY: self.eid_trans, + MEDIA_KEY: self.oid_trans, + PLACE_KEY: self.pid_trans, REPOSITORY_KEY: self.rid_trans, - NOTE_KEY: self.nid_trans, + NOTE_KEY: self.nid_trans, } table = key2table[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, - self.repository_map) - note_upd = self._do_commit(transaction.note_update, - self.note_map) + note_add = self.__do_commit(transaction.note_add, self.note_map) + person_upd = self.__do_commit(transaction.person_update, self.person_map) + family_upd = self.__do_commit(transaction.family_update, self.family_map) + source_upd = self.__do_commit(transaction.source_update, self.source_map) + place_upd = self.__do_commit(transaction.place_update, self.place_map) + media_upd = self.__do_commit(transaction.media_update, self.media_map) + event_upd = self.__do_commit(transaction.event_update, self.event_map) + repository_upd = self.__do_commit(transaction.repository_update, + self.repository_map) + note_upd = self.__do_commit(transaction.note_update, self.note_map) - 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 @@ -1626,7 +1570,7 @@ class GrampsDbBase(GrampsDBCallback): return True - def undo(self,update_history=True): + def undo(self, update_history=True): """ Accesses the last committed transaction, and reverts the data to the state before the transaction was committed. @@ -1644,11 +1588,11 @@ class GrampsDbBase(GrampsDBCallback): subitems = transaction.get_recnos() subitems.reverse() for record_id in subitems: - (key,handle,old_data,new_data) = transaction.get_record(record_id) + (key, handle, old_data, new_data) = transaction.get_record(record_id) 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(): @@ -1669,7 +1613,7 @@ class GrampsDbBase(GrampsDBCallback): self.undo_history_callback() return True - def redo(self,update_history=True): + def redo(self, update_history=True): """ Accesses the last undone transaction, and reverts the data to the state before the transaction was undone. @@ -1686,11 +1630,11 @@ class GrampsDbBase(GrampsDBCallback): subitems = transaction.get_recnos() for record_id in subitems: - (key,handle,old_data,new_data) = transaction.get_record(record_id) + (key, handle, old_data, new_data) = transaction.get_record(record_id) 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(): @@ -1756,11 +1700,11 @@ class GrampsDbBase(GrampsDBCallback): raise NotImplementedError def sort_surname_list(self): - vals = [(locale.strxfrm(item),item) for item in self.surname_list] + vals = [(locale.strxfrm(item), item) for item in self.surname_list] vals.sort() self.surname_list = [item[1] for item in vals] - def add_to_surname_list(self,person,batch_transaction): + def add_to_surname_list(self, person, batch_transaction): if batch_transaction: return name = unicode(person.get_primary_name().get_surname()) @@ -1768,7 +1712,7 @@ class GrampsDbBase(GrampsDBCallback): self.surname_list.append(name) self.sort_surname_list() - def remove_from_surname_list(self,person): + def remove_from_surname_list(self, person): """ 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. @@ -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): + 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,21 +2227,21 @@ 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.""" pass - def reindex_reference_map(self,callback): + def reindex_reference_map(self, callback): """ Reindex all primary records in the database. @@ -2372,7 +2316,7 @@ class GrampsDbBase(GrampsDBCallback): # Now we need to loop over all object types # that have been requests in the include_classes list for classname in primary_tables.keys(): - if obj.has_handle_reference(classname,handle): + if obj.has_handle_reference(classname, handle): yield (primary_table_name, found_handle) data = cursor.next() @@ -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 diff --git a/src/GrampsDb/_GrampsInMemDB.py b/src/GrampsDb/_GrampsInMemDB.py index dcc1979dd..144cac148 100644 --- a/src/GrampsDb/_GrampsInMemDB.py +++ b/src/GrampsDb/_GrampsInMemDB.py @@ -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,44 +258,44 @@ 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, - self.nid_trans): + if not self.__commit_inmem_base(note, self.note_map, + self.nid_trans): return GrampsDbBase.commit_note(self,note,transaction,change_time) diff --git a/src/GrampsDb/_ProgressMonitor.py b/src/GrampsDb/_ProgressMonitor.py index 3fcc18e02..c9b943785 100644 --- a/src/GrampsDb/_ProgressMonitor.py +++ b/src/GrampsDb/_ProgressMonitor.py @@ -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 @@ -138,4 +158,4 @@ class ProgressMonitor(object): facade.status_obj.disconnect(facade.end_cb_id) del self._status_stack[idx] - \ No newline at end of file + diff --git a/src/Makefile.am b/src/Makefile.am index d5652cdda..097b3f0d4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 diff --git a/src/Simple/_SimpleAccess.py b/src/Simple/_SimpleAccess.py index 28781e31b..a9cfa4db9 100644 --- a/src/Simple/_SimpleAccess.py +++ b/src/Simple/_SimpleAccess.py @@ -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 """ diff --git a/src/Simple/__init__.py b/src/Simple/__init__.py new file mode 100644 index 000000000..b8602f6b2 --- /dev/null +++ b/src/Simple/__init__.py @@ -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 * +