From 851be10fd011a70ca1cd969a0a6f0c8c52099929 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Mon, 6 Dec 2004 04:13:13 +0000 Subject: [PATCH] * src/DateParser.py: documenation enhancements * src/GrampsBSDDB.py: Add cursor class * src/GrampsDbBase.py: Add base cursor class * src/GrampsGEDDB.py: documenation enhancements * src/GrampsInMemDB.py: Add cursor class * src/GrampsXMLDB.py: documenation enhancements svn: r3781 --- ChangeLog | 8 ++++++++ src/DateParser.py | 5 +++-- src/GrampsBSDDB.py | 20 +++++++++++++++++++- src/GrampsDbBase.py | 45 ++++++++++++++++++++++++++++++++++++++++++++ src/GrampsGEDDB.py | 5 +++++ src/GrampsInMemDB.py | 15 ++++++++++++--- src/GrampsXMLDB.py | 5 +++++ 7 files changed, 97 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 481da78bb..9cf27ae4a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2004-12-05 Don Allingham + * src/DateParser.py: documenation enhancements + * src/GrampsBSDDB.py: Add cursor class + * src/GrampsDbBase.py: Add base cursor class + * src/GrampsGEDDB.py: documenation enhancements + * src/GrampsInMemDB.py: Add cursor class + * src/GrampsXMLDB.py: documenation enhancements + 2004-12-04 Don Allingham * src/ChooseParents.py: use new cursor for interation * src/DbPrompter.py: reformat diff --git a/src/DateParser.py b/src/DateParser.py index 238651fb4..1a34d481f 100644 --- a/src/DateParser.py +++ b/src/DateParser.py @@ -21,8 +21,9 @@ # $Id$ """ -U.S. English date parsing class. Serves as the base class for any localized -date parsing class. +Date parsing class. Serves as the base class for any localized +date parsing class. The default, base class provides parsing for +English. """ __author__ = "Donald N. Allingham" diff --git a/src/GrampsBSDDB.py b/src/GrampsBSDDB.py index 1a102223e..dcfe639fa 100644 --- a/src/GrampsBSDDB.py +++ b/src/GrampsBSDDB.py @@ -20,6 +20,10 @@ # $Id$ +""" +Provides the Berkeley DB (BSDDB) database backend for GRAMPS +""" + import os import time import locale @@ -41,6 +45,20 @@ def find_fidmap(key,data): def find_eventname(key,data): return str(data[1]) +class GrampsBSDDBCursor(GrampsCursor): + + def __init__(self,source): + self.cursor = source.cursor() + + def first(self): + return self.cursor.first() + + def next(self): + return self.cursor.next() + + def close(self): + self.cursor.close() + #------------------------------------------------------------------------- # # GrampsBSDDB @@ -61,7 +79,7 @@ class GrampsBSDDB(GrampsDbBase): return dbmap def get_person_cursor(self): - return self.person_map.cursor() + return GrampsBSDDBCursor(self.person_map) def load(self,name,callback): if self.person_map: diff --git a/src/GrampsDbBase.py b/src/GrampsDbBase.py index 651ffeebc..fcc7cd74a 100644 --- a/src/GrampsDbBase.py +++ b/src/GrampsDbBase.py @@ -32,6 +32,7 @@ from this class. #------------------------------------------------------------------------- from RelLib import * import cPickle + import time import locale import re @@ -55,6 +56,50 @@ EVENT_KEY = 3 MEDIA_KEY = 4 PLACE_KEY = 5 +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 + class GrampsDbBase: """ GRAMPS database object. This object is a base class for all diff --git a/src/GrampsGEDDB.py b/src/GrampsGEDDB.py index 3bff6ce53..dcc6f35fe 100644 --- a/src/GrampsGEDDB.py +++ b/src/GrampsGEDDB.py @@ -20,6 +20,11 @@ # $Id$ +""" +Provides the GRAMPS DB interface for supporting in-memory editing +of GEDCOM files. +""" + from RelLib import * from GrampsInMemDB import * diff --git a/src/GrampsInMemDB.py b/src/GrampsInMemDB.py index 19bde89e4..b506a1282 100644 --- a/src/GrampsInMemDB.py +++ b/src/GrampsInMemDB.py @@ -20,6 +20,11 @@ # $Id$ +""" +Provides the common infrastructure for database formats that +must hold all of their data in memory. +""" + from RelLib import * from GrampsDbBase import * @@ -28,8 +33,12 @@ import md5 import gtk -class GrampsCursor: - +class GrampsInMemCursor(GrampsCursor): + """ + Cursor class for in-memory database classes. Since the in-memory + classes use python dictionaries, the python iter class is used + to provide the cursor function. + """ def __init__(self,src_map): self.src_map = src_map self.current = iter(src_map) @@ -81,7 +90,7 @@ class GrampsInMemDB(GrampsDbBase): pass def get_person_cursor(self): - return GrampsCursor(self.person_map) + return GrampsInMemCursor(self.person_map) def close(self): pass diff --git a/src/GrampsXMLDB.py b/src/GrampsXMLDB.py index 9d8a05076..da2c91df2 100644 --- a/src/GrampsXMLDB.py +++ b/src/GrampsXMLDB.py @@ -20,6 +20,11 @@ # $Id$ +""" +Provides the GRAMPS DB interface for supporting in-memory editing +of GRAMPS XML format. +""" + from RelLib import * from GrampsInMemDB import *