Show More
@@ -136,6 +136,8 b' class transaction(object):' | |||||
136 | self._finalizecallback = {} |
|
136 | self._finalizecallback = {} | |
137 | # hold callback for post transaction close |
|
137 | # hold callback for post transaction close | |
138 | self._postclosecallback = {} |
|
138 | self._postclosecallback = {} | |
|
139 | # holds callbacks to call during abort | |||
|
140 | self._abortcallback = {} | |||
139 |
|
141 | |||
140 | def __del__(self): |
|
142 | def __del__(self): | |
141 | if self.journal: |
|
143 | if self.journal: | |
@@ -361,6 +363,17 b' class transaction(object):' | |||||
361 | self._postclosecallback[category] = callback |
|
363 | self._postclosecallback[category] = callback | |
362 |
|
364 | |||
363 | @active |
|
365 | @active | |
|
366 | def addabort(self, category, callback): | |||
|
367 | """add a callback to be called when the transaction is aborted. | |||
|
368 | ||||
|
369 | The transaction will be given as the first argument to the callback. | |||
|
370 | ||||
|
371 | Category is a unique identifier to allow overwriting an old callback | |||
|
372 | with a newer callback. | |||
|
373 | """ | |||
|
374 | self._abortcallback[category] = callback | |||
|
375 | ||||
|
376 | @active | |||
364 | def close(self): |
|
377 | def close(self): | |
365 | '''commit the transaction''' |
|
378 | '''commit the transaction''' | |
366 | if self.count == 1: |
|
379 | if self.count == 1: | |
@@ -443,6 +456,8 b' class transaction(object):' | |||||
443 | self.report(_("transaction abort!\n")) |
|
456 | self.report(_("transaction abort!\n")) | |
444 |
|
457 | |||
445 | try: |
|
458 | try: | |
|
459 | for cat in sorted(self._abortcallback): | |||
|
460 | self._abortcallback[cat](self) | |||
446 | _playback(self.journal, self.report, self.opener, self._vfsmap, |
|
461 | _playback(self.journal, self.report, self.opener, self._vfsmap, | |
447 | self.entries, self._backupentries, False) |
|
462 | self.entries, self._backupentries, False) | |
448 | self.report(_("rollback completed\n")) |
|
463 | self.report(_("rollback completed\n")) |
General Comments 0
You need to be logged in to leave comments.
Login now