From b765d7eae05968706de5b5a7eed581eac5b2ebf7 Mon Sep 17 00:00:00 2001 From: prculley Date: Fri, 25 Jan 2019 10:53:36 -0600 Subject: [PATCH] On restart after crash, offer to run Check & Repair --- gramps/gen/config.py | 1 + gramps/grampsapp.py | 17 ++++++++++++----- gramps/gui/viewmanager.py | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/gramps/gen/config.py b/gramps/gen/config.py index 67568bdf0..e3c3ff4f0 100644 --- a/gramps/gen/config.py +++ b/gramps/gen/config.py @@ -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) diff --git a/gramps/grampsapp.py b/gramps/grampsapp.py index 8573a4f9a..37e7e0db1 100644 --- a/gramps/grampsapp.py +++ b/gramps/grampsapp.py @@ -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 diff --git a/gramps/gui/viewmanager.py b/gramps/gui/viewmanager.py index a793dc5d3..272cee6a5 100644 --- a/gramps/gui/viewmanager.py +++ b/gramps/gui/viewmanager.py @@ -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)