download and deploy works

This commit is contained in:
Tim Bentley 2017-03-05 09:23:28 +00:00
parent 9204dc23a0
commit 7a72b2cad4
9 changed files with 67 additions and 27 deletions

View File

@ -22,19 +22,22 @@
import os import os
import zipfile import zipfile
import urllib.error
from openlp.core.common.httputils import url_get_file from openlp.core.common import AppLocation, Registry
from openlp.core.common.httputils import url_get_file, get_web_page
def deploy_zipfile(zip_file, app_root): def deploy_zipfile(app_root, zip_name):
""" """
Process the downloaded zip file and add to the correct directory Process the downloaded zip file and add to the correct directory
:param zip_file: the zip file to be processed :param zip_name: the zip file to be processed
:param app_root: the directory where the zip get expanded to :param app_root: the directory where the zip get expanded to
:return: None :return: None
""" """
zip_file = os.path.join(app_root, zip_name)
web_zip = zipfile.ZipFile(zip_file) web_zip = zipfile.ZipFile(zip_file)
for web_file in web_zip.namelist(): for web_file in web_zip.namelist():
(dir_name, filename) = os.path.split(web_file) (dir_name, filename) = os.path.split(web_file)
@ -66,17 +69,19 @@ def check_for_previous_deployment(app_root, create=False):
return False return False
#def download_and_check(): def download_sha256():
# f = url_get_file(None, 'https://get.openlp.org/webclient', 'download.cfg') user_agent = 'OpenLP/' + Registry().get('application').applicationVersion()
# print(f) try:
web_config = get_web_page('{host}{name}'.format(host='https://get.openlp.org/webclient/', name='download.cfg'),
#download_and_check() header=('User-Agent', user_agent))
except (urllib.error.URLError, ConnectionError) as err:
return False
return web_config.read().decode('utf-8').split()[0]
#file_name = "/home/tim/Projects/OpenLP/openlp/remoteweb/deploy.zip" def download_and_check(callback=None):
#app_root = "/home/tim/.openlp/data/remotes/" sha256 = download_sha256()
if url_get_file(callback, '{host}{name}'.format(host='https://get.openlp.org/webclient/', name='site.zip'),
#deploy_zipfile(file_name) os.path.join(AppLocation.get_section_data_path('remotes'), 'site.zip'),
#print(check_for_previous_deployment(app_root)) sha256=sha256):
#print(check_for_previous_deployment(app_root, True)) deploy_zipfile(AppLocation.get_section_data_path('remotes'), 'site.zip')
#print(check_for_previous_deployment(app_root))

View File

@ -106,6 +106,11 @@ class ApiTab(SettingsTab):
self.password.setObjectName('password') self.password.setObjectName('password')
self.user_login_layout.addRow(self.password_label, self.password) self.user_login_layout.addRow(self.password_label, self.password)
self.left_layout.addWidget(self.user_login_group_box) self.left_layout.addWidget(self.user_login_group_box)
self.update_site_group_box = QtWidgets.QGroupBox(self.left_column)
self.update_site_group_box.setCheckable(True)
self.update_site_group_box.setChecked(False)
self.update_site_group_box.setObjectName('update_site_group_box')
self.left_layout.addWidget(self.update_site_group_box)
self.android_app_group_box = QtWidgets.QGroupBox(self.right_column) self.android_app_group_box = QtWidgets.QGroupBox(self.right_column)
self.android_app_group_box.setObjectName('android_app_group_box') self.android_app_group_box.setObjectName('android_app_group_box')
self.right_layout.addWidget(self.android_app_group_box) self.right_layout.addWidget(self.android_app_group_box)
@ -183,6 +188,7 @@ class ApiTab(SettingsTab):
'Scan the QR code or click <a href="{qr}">download</a> to install the iOS app from the App ' 'Scan the QR code or click <a href="{qr}">download</a> to install the iOS app from the App '
'Store.').format(qr='https://itunes.apple.com/app/id1096218725')) 'Store.').format(qr='https://itunes.apple.com/app/id1096218725'))
self.user_login_group_box.setTitle(translate('RemotePlugin.RemoteTab', 'User Authentication')) self.user_login_group_box.setTitle(translate('RemotePlugin.RemoteTab', 'User Authentication'))
self.update_site_group_box.setTitle(translate('RemotePlugin.RemoteTab', 'Download latest web site'))
self.user_id_label.setText(translate('RemotePlugin.RemoteTab', 'User id:')) self.user_id_label.setText(translate('RemotePlugin.RemoteTab', 'User id:'))
self.password_label.setText(translate('RemotePlugin.RemoteTab', 'Password:')) self.password_label.setText(translate('RemotePlugin.RemoteTab', 'Password:'))
@ -247,6 +253,8 @@ class ApiTab(SettingsTab):
Settings().setValue(self.settings_section + '/user id', self.user_id.text()) Settings().setValue(self.settings_section + '/user id', self.user_id.text())
Settings().setValue(self.settings_section + '/password', self.password.text()) Settings().setValue(self.settings_section + '/password', self.password.text())
self.generate_icon() self.generate_icon()
if self.update_site_group_box.isChecked():
self.settings_form.register_post_process('download_website')
def on_twelve_hour_check_box_changed(self, check_state): def on_twelve_hour_check_box_changed(self, check_state):
""" """

View File

@ -56,7 +56,7 @@ class ImageThread(QtCore.QThread):
""" """
Run the thread. Run the thread.
""" """
self.image_manager._process() self.image_manager.process()
class Priority(object): class Priority(object):
@ -307,11 +307,11 @@ class ImageManager(QtCore.QObject):
if not self.image_thread.isRunning(): if not self.image_thread.isRunning():
self.image_thread.start() self.image_thread.start()
def _process(self): def process(self):
""" """
Controls the processing called from a ``QtCore.QThread``. Controls the processing called from a ``QtCore.QThread``.
""" """
log.debug('_process - started') log.debug('process - started')
while not self._conversion_queue.empty() and not self.stop_manager: while not self._conversion_queue.empty() and not self.stop_manager:
self._process_cache() self._process_cache()
log.debug('_process - ended') log.debug('_process - ended')

View File

@ -555,6 +555,7 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties):
songs_destination = os.path.join(gettempdir(), 'openlp') songs_destination = os.path.join(gettempdir(), 'openlp')
bibles_destination = AppLocation.get_section_data_path('bibles') bibles_destination = AppLocation.get_section_data_path('bibles')
themes_destination = AppLocation.get_section_data_path('themes') themes_destination = AppLocation.get_section_data_path('themes')
remote_destination = AppLocation.get_section_data_path('remotes')
missed_files = [] missed_files = []
# Download songs # Download songs
for i in range(self.songs_list_widget.count()): for i in range(self.songs_list_widget.count()):
@ -594,6 +595,12 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties):
os.path.join(themes_destination, theme), os.path.join(themes_destination, theme),
sha256): sha256):
missed_files.append('Theme: {name}'.format(name=theme)) missed_files.append('Theme: {name}'.format(name=theme))
if self.remote_check_box.isChecked():
self._increment_progress_bar(self.downloading.format(name='AA'), 0)
self.previous_size = 0
url_get_file(self, 'https://get.openlp.org/webclient', 'download.cfg',
os.path.join(remote_destination, theme),
sha256)
if missed_files: if missed_files:
file_list = '' file_list = ''
for entry in missed_files: for entry in missed_files:

View File

@ -254,8 +254,7 @@ class UiFirstTimeWizard(object):
self.presentation_check_box.setText(translate('OpenLP.FirstTimeWizard', self.presentation_check_box.setText(translate('OpenLP.FirstTimeWizard',
'Presentations Show .ppt, .odp and .pdf files')) 'Presentations Show .ppt, .odp and .pdf files'))
self.media_check_box.setText(translate('OpenLP.FirstTimeWizard', 'Media Playback of Audio and Video files')) self.media_check_box.setText(translate('OpenLP.FirstTimeWizard', 'Media Playback of Audio and Video files'))
self.remote_check_box.setText(translate('OpenLP.FirstTimeWizard', 'Remote Control OpenLP via browser or smart' self.remote_check_box.setText(translate('OpenLP.FirstTimeWizard', 'Remote Download latest Web Pages'))
'phone app'))
self.song_usage_check_box.setText(translate('OpenLP.FirstTimeWizard', 'Song Usage Monitor')) self.song_usage_check_box.setText(translate('OpenLP.FirstTimeWizard', 'Song Usage Monitor'))
self.alert_check_box.setText(translate('OpenLP.FirstTimeWizard', self.alert_check_box.setText(translate('OpenLP.FirstTimeWizard',
'Alerts Display informative messages while showing other slides')) 'Alerts Display informative messages while showing other slides'))

View File

@ -24,10 +24,11 @@ import logging
import os import os
from openlp.core.api.http import register_endpoint from openlp.core.api.http import register_endpoint
from openlp.core.common import AppLocation, OpenLPMixin, check_directory_exists from openlp.core.common import AppLocation, Registry, OpenLPMixin, check_directory_exists
from openlp.core.common.httputils import get_web_page from openlp.core.common.httputils import get_web_page
from openlp.core.lib import Plugin, StringContent, translate, build_icon from openlp.core.lib import Plugin, StringContent, translate, build_icon
from openlp.plugins.remotes.endpoint import remote_endpoint from openlp.plugins.remotes.endpoint import remote_endpoint
from openlp.plugins.remotes.deploy import download_and_check
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -46,6 +47,7 @@ class RemotesPlugin(Plugin, OpenLPMixin):
self.live_cache = None self.live_cache = None
self.stage_cache = None self.stage_cache = None
register_endpoint(remote_endpoint) register_endpoint(remote_endpoint)
Registry().register_function('download_website', self.manage_download)
@staticmethod @staticmethod
def about(): def about():
@ -121,3 +123,7 @@ class RemotesPlugin(Plugin, OpenLPMixin):
else: else:
self.live_cache = False self.live_cache = False
return self.live_cache return self.live_cache
def manage_download(self):
download_and_check()
print("manage downlaod")

View File

@ -26,15 +26,18 @@ import shutil
from tempfile import mkdtemp from tempfile import mkdtemp
from unittest import TestCase from unittest import TestCase
from openlp.core.common.httputils import url_get_file, get_web_page from openlp.core.common import Registry
from openlp.core.common.httputils import url_get_file
from openlp.core.api.deploy import download_sha256, download_and_check
from tests.functional import MagicMock from tests.functional import MagicMock
from tests.helpers.testmixin import TestMixin
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources')) TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources'))
class TestRemoteDeploy(TestCase): class TestRemoteDeploy(TestCase, TestMixin):
""" """
Test the Remote plugin deploy functions Test the Remote plugin deploy functions
""" """
@ -44,6 +47,11 @@ class TestRemoteDeploy(TestCase):
Setup for tests Setup for tests
""" """
self.app_root = mkdtemp() self.app_root = mkdtemp()
self.setup_application()
self.app.setApplicationVersion('0.0')
self.app.process_events = lambda: None
Registry.create()
Registry().register('application', self.app)
def tearDown(self): def tearDown(self):
""" """
@ -56,11 +64,8 @@ class TestRemoteDeploy(TestCase):
Remote Deploy tests - Test hosted sites file matches the config file Remote Deploy tests - Test hosted sites file matches the config file
""" """
# GIVEN: a hosted configuration file # GIVEN: a hosted configuration file
user_agent = 'OpenLP/2.4.4'
web = 'https://get.openlp.org/webclient/' web = 'https://get.openlp.org/webclient/'
web_config = get_web_page('{host}{name}'.format(host=web, name='download.cfg'), sha = download_sha256()
header=('User-Agent', user_agent))
sha = web_config.read().decode('utf-8').split()[0]
callback = MagicMock() callback = MagicMock()
callback.was_cancelled = False callback.was_cancelled = False
f = os.path.join(self.app_root, 'sites.zip') f = os.path.join(self.app_root, 'sites.zip')
@ -68,4 +73,14 @@ class TestRemoteDeploy(TestCase):
# THEN: the file will download and match the sha256 from the config file # THEN: the file will download and match the sha256 from the config file
url_get_file(callback, web + 'site.zip', f, sha256=sha) url_get_file(callback, web + 'site.zip', f, sha256=sha)
def test_download_and_deploy(self):
"""
Remote Deploy tests - Test hosted sites file matches the config file
"""
# GIVEN: a hosted configuration file
callback = MagicMock()
callback.was_cancelled = False
download_and_check(callback)