On restart after crash, offer to run Check & Repair

This commit is contained in:
prculley 2019-01-25 10:53:36 -06:00 committed by Nick Hall
parent 3f28b5fcb5
commit b765d7eae0
3 changed files with 27 additions and 5 deletions

View File

@ -148,6 +148,7 @@ register('behavior.min-generation-years', 13)
register('behavior.owner-warn', False)
register('behavior.pop-plugin-status', False)
register('behavior.recent-export-type', 3)
register('behavior.runcheck', False)
register('behavior.spellcheck', False)
register('behavior.startup', 0)
register('behavior.surname-guessing', 0)

View File

@ -54,6 +54,8 @@ from .gen.const import APP_GRAMPS, USER_DIRLIST, HOME_DIR, ORIG_HOME_DIR
from .gen.constfunc import mac
from .version import VERSION_TUPLE
from .gen.constfunc import win, get_env_var
from .gen.config import config
from .gen.errors import HandleError
#-------------------------------------------------------------------------
#
@ -135,19 +137,24 @@ l = logging.getLogger()
l.setLevel(logging.WARNING)
l.addHandler(stderrh)
# put a hook on to catch any completely unhandled exceptions.
def exc_hook(type, value, tb):
if type == KeyboardInterrupt:
def exc_hook(err_type, value, t_b):
''' put a hook on to catch any completely unhandled exceptions. '''
if err_type == KeyboardInterrupt:
# Ctrl-C is not a bug.
return
if type == IOError:
if err_type == IOError:
# strange Windows logging error on close
return
if err_type == HandleError and 'not found' in value.value:
# tell Gramps to run check & repair on next start
config.set('behavior.runcheck', True)
config.save()
# Use this to show variables in each frame:
#from gramps.gen.utils.debug import format_exception
import traceback
LOG.error("Unhandled exception\n" +
"".join(traceback.format_exception(type, value, tb)))
"".join(traceback.format_exception(err_type, value, t_b)))
sys.excepthook = exc_hook

View File

@ -980,6 +980,20 @@ class ViewManager(CLIManager):
msg = "%s (%s) - Gramps" % (name, _('Read Only'))
self.uistate.window.set_title(msg)
if(bool(config.get('behavior.runcheck')) and QuestionDialog2(
_("Gramps had a problem the last time it was run."),
_("Would you like to run the Check and Repair tool?"),
_("Yes"), _("No"), parent=self.uistate.window).run()):
pdata = self._pmgr.get_plugin('check')
mod = self._pmgr.load_plugin(pdata)
tool.gui_tool(dbstate=self.dbstate, user=self.user,
tool_class=getattr(mod, pdata.toolclass),
options_class=getattr(mod, pdata.optionclass),
translated_name=pdata.name,
name=pdata.id,
category=pdata.category,
callback=self.dbstate.db.request_rebuild)
config.set('behavior.runcheck', False)
self.__change_page(self.notebook.get_current_page())
self.uimanager.set_actions_visible(self.actiongroup, rw)
self.uimanager.set_actions_visible(self.readonlygroup, True)