diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index 8192f206d..5ffeb0b51 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -338,7 +338,7 @@ def parse_options(args): parser.add_argument('-d', '--dev-version', dest='dev_version', action='store_true', help='Ignore the version file and pull the version directly from Bazaar') parser.add_argument('-s', '--style', dest='style', help='Set the Qt5 style (passed directly to Qt5).') - parser.add_argument('-w', '--webServer', dest='webServer', action='store_false', + parser.add_argument('-w', '--no-web-server', dest='no_web_server', action='store_false', help='Turn off the Web and Socket Server ') parser.add_argument('rargs', nargs='?', default=[]) # Parse command line options and deal with them. Use args supplied pragmatically if possible. @@ -413,7 +413,7 @@ def main(args=None): set_up_logging(AppLocation.get_directory(AppLocation.CacheDir)) Registry.create() Registry().register('application', application) - Registry().set_flag('webServer', args.webServer) + Registry().set_flag('no_web_server', args.no_web_server) application.setApplicationVersion(get_application_version()['version']) # Check if an instance of OpenLP is already running. Quit if there is a running instance and the user only wants one if application.is_already_running(): diff --git a/openlp/core/api/deploy.py b/openlp/core/api/deploy.py deleted file mode 100644 index 039580280..000000000 --- a/openlp/core/api/deploy.py +++ /dev/null @@ -1,87 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 - -############################################################################### -# OpenLP - Open Source Lyrics Projection # -# --------------------------------------------------------------------------- # -# Copyright (c) 2008-2017 OpenLP Developers # -# --------------------------------------------------------------------------- # -# This program is free software; you can redistribute it and/or modify it # -# under the terms of the GNU General Public License as published by the Free # -# Software Foundation; version 2 of the License. # -# # -# This program is distributed in the hope that it will be useful, but WITHOUT # -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # -# more details. # -# # -# You should have received a copy of the GNU General Public License along # -# with this program; if not, write to the Free Software Foundation, Inc., 59 # -# Temple Place, Suite 330, Boston, MA 02111-1307 USA # -############################################################################### - -import os -import zipfile -import urllib.error - -from openlp.core.common import AppLocation, Registry -from openlp.core.common.httputils import url_get_file, get_web_page - - -def deploy_zipfile(app_root, zip_name): - """ - Process the downloaded zip file and add to the correct directory - - :param zip_name: the zip file to be processed - :param app_root: the directory where the zip get expanded to - - :return: None - """ - zip_file = os.path.join(app_root, zip_name) - web_zip = zipfile.ZipFile(zip_file) - for web_file in web_zip.namelist(): - (dir_name, filename) = os.path.split(web_file) - real_path = os.path.join(app_root, web_file[4:]) - if filename == '': - if not os.path.exists(real_path): - os.makedirs(real_path) - else: - file_web = web_zip.read(web_file) - out_file = open(real_path, 'w') - # extract the file from the zip. If an image then the exception will be used. - try: - out_file.write(file_web.decode("utf-8")) - except UnicodeDecodeError as ude: - out_file.close() - out_file = open(real_path, 'wb') - out_file.write(file_web) - out_file.close() - web_zip.close() - - -def check_for_previous_deployment(app_root, create=False): - marker_file = os.path.join(app_root, "marker.txt") - if os.path.isfile(marker_file): - return True - else: - if create: - os.mknod(marker_file) - return False - - -def download_sha256(): - user_agent = 'OpenLP/' + Registry().get('application').applicationVersion() - try: - web_config = get_web_page('{host}{name}'.format(host='https://get.openlp.org/webclient/', name='download.cfg'), - header=('User-Agent', user_agent)) - except (urllib.error.URLError, ConnectionError) as err: - return False - return web_config.read().decode('utf-8').split()[0] - - -def download_and_check(callback=None): - sha256 = download_sha256() - if url_get_file(callback, '{host}{name}'.format(host='https://get.openlp.org/webclient/', name='site.zip'), - os.path.join(AppLocation.get_section_data_path('remotes'), 'site.zip'), - sha256=sha256): - deploy_zipfile(AppLocation.get_section_data_path('remotes'), 'site.zip') diff --git a/openlp/core/ui/firsttimeform.py b/openlp/core/ui/firsttimeform.py index b317df9dd..9c2eaa605 100644 --- a/openlp/core/ui/firsttimeform.py +++ b/openlp/core/ui/firsttimeform.py @@ -34,7 +34,7 @@ from configparser import ConfigParser, MissingSectionHeaderError, NoSectionError from PyQt5 import QtCore, QtWidgets -from openlp.core.api.deploy import download_and_check +from openlp.plugins.remotes.deploy import download_and_check from openlp.core.common import Registry, RegistryProperties, AppLocation, Settings, check_directory_exists, \ translate, clean_button_text, trace_error_handler from openlp.core.lib import PluginStatus, build_icon diff --git a/tests/functional/openlp_core_api/test_deploy.py b/tests/functional/openlp_core_api/test_deploy.py deleted file mode 100644 index c0727159e..000000000 --- a/tests/functional/openlp_core_api/test_deploy.py +++ /dev/null @@ -1,117 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 - -############################################################################### -# OpenLP - Open Source Lyrics Projection # -# --------------------------------------------------------------------------- # -# Copyright (c) 2008-2017 OpenLP Developers # -# --------------------------------------------------------------------------- # -# This program is free software; you can redistribute it and/or modify it # -# under the terms of the GNU General Public License as published by the Free # -# Software Foundation; version 2 of the License. # -# # -# This program is distributed in the hope that it will be useful, but WITHOUT # -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # -# more details. # -# # -# You should have received a copy of the GNU General Public License along # -# with this program; if not, write to the Free Software Foundation, Inc., 59 # -# Temple Place, Suite 330, Boston, MA 02111-1307 USA # -############################################################################### - -import os -import shutil - -from tempfile import mkdtemp -from unittest import TestCase - -from openlp.core.api.deploy import check_for_previous_deployment, deploy_zipfile - -from tests.functional import patch - - -TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'resources')) - - -class TestRemoteDeploy(TestCase): - """ - Test the Remote plugin deploy functions - """ - - def setUp(self): - """ - Setup for tests - """ - self.app_root = mkdtemp() - - def tearDown(self): - """ - Clean up after tests - """ - shutil.rmtree(self.app_root) - - @patch('openlp.core.api.deploy.os.path.isfile') - @patch('openlp.core.api.deploy.os.mknod') - def test_check_for_previous_deployment_false(self, mocked_mknod, mocked_isfile): - """ - Remote Deploy tests - Test when the marker file is missing - """ - # GIVEN: A new setup with no marker file - # WHEN: I check for a deployment which does not create the marker file - mocked_isfile.return_value = False - processed = check_for_previous_deployment(self.app_root) - - # THEN test the see if marker has not been created - self.assertFalse(processed, 'should return False as marker does not exist') - mocked_isfile.assert_called_once_with(os.path.join(self.app_root, 'marker.txt')) - mocked_mknod.assert_not_called() - - @patch('openlp.core.api.deploy.os.path.isfile') - @patch('openlp.core.api.deploy.os.mknod') - def test_check_for_previous_deployment_true(self, mocked_mknod, mocked_isfile): - """ - Remote Deploy tests - Test when the marker file is missing - """ - # GIVEN: A new setup with not market file - # WHEN: I check for a deployment which does create the marker file - mocked_isfile.return_value = False - processed = check_for_previous_deployment(self.app_root, True) - - # THEN test the see if marker has been created - marker_file = os.path.join(self.app_root, 'marker.txt') - self.assertFalse(processed, 'should return False as marker does not exist') - mocked_isfile.assert_called_once_with(marker_file) - mocked_mknod.assert_called_once_with(marker_file) - - @patch('openlp.core.api.deploy.os.path.isfile') - @patch('openlp.core.api.deploy.os.mknod') - def test_check_for_previous_deployment_true(self, mocked_mknod, mocked_isfile): - """ - Remote Deploy tests - Test when the marker file is present - """ - # GIVEN: A new setup with not market file - # WHEN: I check for a deployment which does not create the marker file - mocked_isfile.return_value = True - processed = check_for_previous_deployment(self.app_root, True) - - # THEN test the see if marker is present and has not been created - marker_file = os.path.join(self.app_root, 'marker.txt') - self.assertTrue(processed, 'should return True as marker does exist') - mocked_isfile.assert_called_once_with(marker_file) - mocked_mknod.assert_not_called() - - @patch('openlp.core.api.deploy.open') - def test_deploy_zipfile(self, mocked_open): - """ - Remote Deploy tests - test the dummy zip file is processed correctly - """ - # GIVEN: A new downloaded zip file - zip_file = os.path.join(TEST_PATH, 'remotes', 'site.zip') - app_root = os.path.join(self.app_root, 'site.zip') - shutil.copyfile(zip_file, app_root) - # WHEN: I process the zipfile - deploy_zipfile(self.app_root, 'site.zip') - - # THEN test the see if marker is present and has not been created - self.assertEqual(mocked_open.call_count, 46, 'We should write 46 files')