def cloneDB_handle(self): with self.catchExceptions(): try: self.setDB(self.future.result()) if self.storeLogin: config.setAuthInformation(self.db) except AuthError as e: ans = LoginDialog.getLogin(self, str(e)) if ans: self.login['username'], self.login['password'], self.storeLogin = ans self.cloneDB_init() else: raise e
def catchExceptions(self, onAuthEntered=None): """Contextmanager catching common exceptions and displaying message boxes if they occur. The caught exceptions are :class:`DatabaseFormatError`, :class:`MergeConflict` and :class:`AuthError`. `onAuthEntered` is an optional callable. If it is provided and an :class:`AuthError` is caught, the following happens: - A :class:`LoginDialog` is shown to ask the user for a login, - if the dialog is canceled, the :class:`AuthError` is re-raised - otherwise, the function `onAuthEntered` is called. If the `store login` checkbox in the :class:`LoginDialog` was checked, the information is set to `self.db.vcs` and :fun:`config.setAuthInformation` is called. """ M = QtWidgets.QMessageBox try: yield except DatabaseFormatError as e: M.critical(self, 'Error Opening Database', str(e)) except MergeConflict as mc: M.critical(self, "Merge conflict", str(mc)) except AuthError as a: if onAuthEntered is not None: ans = LoginDialog.getLogin(self, str(a)) if ans: self.db.vcs.username, self.db.vcs.password, store = ans if store: config.setAuthInformation(self.db) onAuthEntered() return M.critical(self, "Authorization Required", str(a)) except VCSNotFoundError as e: M.critical(self, 'VCS program not found', str(e)) except Exception as e: M.critical(self, 'Unhandled {}'.format(type(e)), traceback.format_exc())