Comments
Patch
@@ -99,10 +99,14 @@ class transaction(object):
opener.chmod(self.journal, createmode & 0666)
opener.chmod(self.backupjournal, createmode & 0666)
# hold file generations to be performed on commit
self._filegenerators = {}
+ # hold callbalk to write pending data for hooks
+ self._pendingcallback = {}
+ # True is any pending data have been written ever
+ self._anypending = False
def __del__(self):
if self.journal:
self._abort()
@@ -261,10 +265,30 @@ class transaction(object):
self._abort()
def running(self):
return self.count > 0
+ def addpending(self, category, callback):
+ """add a callback to be called when the transaction is pending
+
+ Category is a unique identifier to allow overwriting old callback with
+ newer callback.
+ """
+ self._pendingcallback[category] = callback
+
+ @active
+ def writepending(self):
+ '''write pending file to temporary version
+
+ This is used to allow hooks to view transaction before commit'''
+ categories = sorted(self._pendingcallback)
+ for cat in categories:
+ # remove callback since the data will have been flushed
+ any = self._pendingcallback.pop(cat)()
+ self._anypending = self._anypending or any
+ return self._anypending
+
@active
def close(self):
'''commit the transaction'''
if self.count == 1 and self.onclose is not None:
self._generatefiles()