add initial cursor iter impl.

svn: r8052
This commit is contained in:
Richard Taylor 2007-02-04 21:20:46 +00:00
parent 63614a2740
commit 3a69a0145e
3 changed files with 76 additions and 0 deletions

View File

@ -1,3 +1,7 @@
2007-02-04 Richard Taylor <rjt-gramps@thegrindstone.me.uk>
* src/GrampsDb/_GrampsDbBase.py: add initial cursor iter impl.
* src/GrampsDb/_CursorIterator.py: add initial cursor iter impl.
2007-02-04 Zsolt Foldvari <zfoldvar@users.sourceforge.net>
* src/GrampsLocale: set svn:ignore propery
* src/BasicUtils: set svn:ignore propery

View File

@ -0,0 +1,47 @@
class LongOpStatus(object):
def __init__(self):
self._cancel = False
def cancel(self):
self._cancel = True
def shouldCancel(self):
return self._cancel
class CursorIterator(object):
def __init__(self,db,cursor):
self._db = db
self._cursor = cursor
self._status = LongOpStatus()
def __iter__(self):
try:
# Emit start signal
self._db.emit('long-op-start',(self._status,))
first = self._cursor.first()
if first:
yield first
next = self._cursor.next()
while next:
yield next
# check for cancel
#if self._status.shouldCancel():
# raise GrampsDbUserCancel
# emit heartbeat
self._db.emit('long-op-heartbeat')
next = self._cursor.next()
# emit stop signal
self._db.emit('long-op-end')
self._cursor.close()
raise StopIteration
except:
self._cursor.close()
self._db.emit('long-op-end')
raise

View File

@ -52,6 +52,7 @@ log = logging.getLogger(".GrampsDb")
#-------------------------------------------------------------------------
from RelLib import *
from _GrampsDBCallback import GrampsDBCallback
from _CursorIterator import CursorIterator
#-------------------------------------------------------------------------
#
@ -196,6 +197,9 @@ class GrampsDbBase(GrampsDBCallback):
'repository-update' : (list, ),
'repository-delete' : (list, ),
'repository-rebuild' : None,
'long-op-start' : (object, ),
'long-op-heartbeat' : None,
'long-op-end' : None
}
@ -342,24 +346,45 @@ class GrampsDbBase(GrampsDBCallback):
def get_person_cursor(self):
assert False, "Needs to be overridden in the derived class"
def get_person_cursor_iter(self):
return CursorIterator(self,self.get_person_cursor())
def get_family_cursor(self):
assert False, "Needs to be overridden in the derived class"
def get_family_cursor_iter(self):
return CursorIterator(self,self.get_family_cursor())
def get_event_cursor(self):
assert False, "Needs to be overridden in the derived class"
def get_event_cursor_iter(self):
return CursorIterator(self,self.get_event_cursor())
def get_place_cursor(self):
assert False, "Needs to be overridden in the derived class"
def get_place_cursor_iter(self):
return CursorIterator(self,self.get_place_cursor())
def get_source_cursor(self):
assert False, "Needs to be overridden in the derived class"
def get_source_cursor_iter(self):
return CursorIterator(self,self.get_source_cursor())
def get_media_cursor(self):
assert False, "Needs to be overridden in the derived class"
def get_media_cursor_iter(self):
return CursorIterator(self,self.get_media_cursor())
def get_repository_cursor(self):
assert False, "Needs to be overridden in the derived class"
def get_repository_cursor_iter(self):
return CursorIterator(self,self.get_repository_cursor())
def open_undodb(self):
if not self.readonly:
self.undolog = "%s.undo" % self.full_name