4750: SessionLog gramplet crash

svn: r17152
This commit is contained in:
Michiel Nauta 2011-04-19 15:26:49 +00:00
parent c8ba5a76e3
commit cf62cb316d
2 changed files with 41 additions and 22 deletions

View File

@ -1651,7 +1651,7 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
"instance of DbTxn which typically happens by using the " "instance of DbTxn which typically happens by using the "
"DbTxn instance as a context manager.") "DbTxn instance as a context manager.")
self.transaction = transaction #only used at the start of this method. self.transaction = transaction
if transaction.batch: if transaction.batch:
# A batch transaction does not store the commits # A batch transaction does not store the commits
# Aborting the session completely will become impossible. # Aborting the session completely will become impossible.
@ -1700,7 +1700,6 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
self.bsddbtxn.commit() self.bsddbtxn.commit()
self.bsddbtxn = None self.bsddbtxn = None
self.txn = None self.txn = None
self.transaction = None
self.env.log_flush() self.env.log_flush()
if not transaction.batch: if not transaction.batch:
emit = self.__emit emit = self.__emit
@ -1708,6 +1707,7 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
emit(transaction, obj_type, TXNADD, obj_name, '-add') emit(transaction, obj_type, TXNADD, obj_name, '-add')
emit(transaction, obj_type, TXNUPD, obj_name, '-update') emit(transaction, obj_type, TXNUPD, obj_name, '-update')
emit(transaction, obj_type, TXNDEL, obj_name, '-delete') emit(transaction, obj_type, TXNDEL, obj_name, '-delete')
self.transaction = None
transaction.clear() transaction.clear()
self.undodb.commit(transaction, msg) self.undodb.commit(transaction, msg)
self.__after_commit(transaction) self.__after_commit(transaction)

View File

@ -26,9 +26,12 @@
import locale import locale
import time import time
from gen.lib import Person, Family
from gen.db import PERSON_KEY, FAMILY_KEY, TXNDEL
from gen.plug import Gramplet from gen.plug import Gramplet
from gen.ggettext import sgettext as _ from gen.ggettext import sgettext as _
from gen.display.name import displayer as name_displayer from gen.display.name import displayer as name_displayer
from Utils import family_name
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
@ -75,23 +78,39 @@ class LogGramplet(Gramplet):
self.last_log = (ltype, action, handle) self.last_log = (ltype, action, handle)
self.timestamp() self.timestamp()
self.append_text("%s: " % _(action) ) self.append_text("%s: " % _(action) )
if action == 'Deleted':
transaction = self.dbstate.db.transaction
if ltype == 'Person':
name = 'a person'
if transaction is not None:
for i in transaction.get_recnos(reverse=True):
(obj_type, trans_type, hndl, old_data, dummy) = \
transaction.get_record(i)
if (obj_type == PERSON_KEY and trans_type == TXNDEL
and hndl == handle):
person = Person()
person.unserialize(old_data)
name = name_displayer.display(person)
break
elif ltype == 'Family':
name = 'a family'
if transaction is not None:
for i in transaction.get_recnos(reverse=True):
(obj_type, trans_type, hndl, old_data, dummy) = \
transaction.get_record(i)
if (obj_type == FAMILY_KEY and trans_type == TXNDEL
and hndl == handle):
family = Family()
family.unserialize(old_data)
name = family_name(family, self.dbstate.db,name)
break
self.append_text(name)
else:
if ltype == 'Person': if ltype == 'Person':
person = self.dbstate.db.get_person_from_handle(handle) person = self.dbstate.db.get_person_from_handle(handle)
name = name_displayer.display(person) name = name_displayer.display(person)
elif ltype == 'Family': elif ltype == 'Family':
family = self.dbstate.db.get_family_from_handle(handle) family = self.dbstate.db.get_family_from_handle(handle)
father_name = _("unknown") name = family_name(family, self.dbstate.db, 'a family')
mother_name = _("unknown")
if family:
father_handle = family.get_father_handle()
if father_handle:
father = self.dbstate.db.get_person_from_handle(father_handle)
if father:
father_name = name_displayer.display(father)
mother_handle = family.get_mother_handle()
if mother_handle:
mother = self.dbstate.db.get_person_from_handle(mother_handle)
mother_name = name_displayer.display(mother)
name = _("%(mother)s and %(father)s") % { 'mother' : mother_name, 'father' : father_name }
self.link(name, ltype, handle) self.link(name, ltype, handle)
self.append_text("\n") self.append_text("\n")