From 340b2f3298000efdee935aa39bdacd0c1e555e7e Mon Sep 17 00:00:00 2001 From: Olli Suutari Date: Mon, 17 Oct 2016 07:17:33 +0300 Subject: [PATCH] - Actually fixed the missing DB bug. --- openlp/core/__init__.py | 40 ++++++++++++++++++++++++++++++++--- openlp/core/lib/db.py | 1 - openlp/core/ui/advancedtab.py | 30 -------------------------- 3 files changed, 37 insertions(+), 34 deletions(-) diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index dd9b231e4..887da172c 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -177,6 +177,40 @@ class OpenLP(OpenLPMixin, QtWidgets.QApplication): self.shared_memory.create(1) return False + def is_data_path_missing(self): + """ + Check if the data folder path exists. + """ + data_folder_path = AppLocation.get_data_path() + if not os.path.exists(data_folder_path): + log.critical('Database was not found in: {path}'.format(path=data_folder_path)) + status = QtWidgets.QMessageBox.critical(None, translate('OpenLP', 'Data Directory Error'), + translate('OpenLP', 'OpenLP data folder was not found in:\n\n{path}' + '\n\nThe location of the data folder was ' + 'previously changed from the OpenLP\'s\n' + 'default location. If the data was stored on ' + 'removable device, that device\nneeds to be ' + 'made available.\n\n You may reset the data ' + 'location back to the default settings, ' + 'or you can try to make the current location ' + 'available.\n\n Do you want to reset the ' + 'default data location?\n\n Click "No" to close' + 'OpenLP so you can try to fix the the problem.' + '\n Click "Yes" to reset the default data ' + 'location and start OpenLP.') + .format(path=data_folder_path), + QtWidgets.QMessageBox.StandardButtons(QtWidgets.QMessageBox.Yes | + QtWidgets.QMessageBox.No), + QtWidgets.QMessageBox.No) + if status == QtWidgets.QMessageBox.No: + # If answer was "No", return "True", it will shutdown OpenLP in def main + log.info('User requested termination') + return True + # If answer was "Yes", remove the custom data path thus resetting the default location. + Settings().remove('advanced/data path') + log.info('Database location has been reset to the default settings.') + return False + def hook_exception(self, exc_type, value, traceback): """ Add an exception hook so that any uncaught exceptions are displayed in this window rather than somewhere where @@ -202,6 +236,7 @@ class OpenLP(OpenLPMixin, QtWidgets.QApplication): """ data_version = Settings().value('core/application version') openlp_version = get_application_version()['version'] + data_folder_path = AppLocation.get_data_path() # New installation, no need to create backup if not has_run_wizard: Settings().setValue('core/application version', openlp_version) @@ -213,7 +248,6 @@ class OpenLP(OpenLPMixin, QtWidgets.QApplication): QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.Yes) == QtWidgets.QMessageBox.Yes: # Create copy of data folder - data_folder_path = AppLocation.get_data_path() timestamp = time.strftime("%Y%m%d-%H%M%S") data_folder_backup_path = data_folder_path + '-' + timestamp try: @@ -368,8 +402,8 @@ def main(args=None): Registry.create() Registry().register('application', application) application.setApplicationVersion(get_application_version()['version']) - # Instance check - if application.is_already_running(): + # If user answers "No" to already running or missing db dialogue, shutdown OpenLP. + if application.is_already_running() or application.is_data_path_missing(): sys.exit() # Remove/convert obsolete settings. Settings().remove_obsolete_settings() diff --git a/openlp/core/lib/db.py b/openlp/core/lib/db.py index 59d13e568..f42c3b5fc 100644 --- a/openlp/core/lib/db.py +++ b/openlp/core/lib/db.py @@ -79,7 +79,6 @@ def handle_db_error(plugin_name, db_file_name): """ Log and report to the user that a database cannot be loaded - :param self: :param plugin_name: Name of plugin :param db_file_name: File name of database :return: None diff --git a/openlp/core/ui/advancedtab.py b/openlp/core/ui/advancedtab.py index be4c9bcd6..fed712ed2 100644 --- a/openlp/core/ui/advancedtab.py +++ b/openlp/core/ui/advancedtab.py @@ -397,36 +397,6 @@ class AdvancedTab(SettingsTab): self.data_directory_cancel_button.hide() # Since data location can be changed, make sure the path is present. self.current_data_path = AppLocation.get_data_path() - if not os.path.exists(self.current_data_path): - log.error('Data path not found {path}'.format(path=self.current_data_path)) - answer = QtWidgets.QMessageBox.critical( - self, translate('OpenLP.AdvancedTab', 'Data Directory Error'), - translate('OpenLP.AdvancedTab', 'OpenLP data folder was not found in:\n\n{path}\n\n' - 'The location of the data folder was previously changed from the OpenLP\'s\n' - 'default location. If the data was stored on removable device, that device\nneeds to ' - 'be made available.\n\n You may reset the data location ' - 'back to the default settings, or you can try to make the current ' - 'location available.\n\n' - 'Do you want to reset the default data location?\n\n' - 'If you click "No" you can try to fix the the problem.\n' - 'If you click "Yes" the data will be reset to the default location. \n\n' - 'You will need to re-start OpenLP after this decision.').format(path=self.current_data_path), - QtWidgets.QMessageBox.StandardButtons(QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No), - QtWidgets.QMessageBox.No) - if answer == QtWidgets.QMessageBox.No: - log.info('User requested termination') - # self.main_window.clean_up() is causing tracebacks, not sure if it's required in some cases. - try: - self.main_window.clean_up() - except: - pass - sys.exit() - # If answer was yes, Set data location to default and shut down OpenLP. - if answer == QtWidgets.QMessageBox.Yes: - settings.remove('advanced/data path') - self.current_data_path = AppLocation.get_data_path() - log.warning('User requested data path set to default {path}'.format(path=self.current_data_path)) - sys.exit() self.data_directory_label.setText(os.path.abspath(self.current_data_path)) # Don't allow data directory move if running portable. if settings.value('advanced/is portable'):