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 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
: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
: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)
@ -66,17 +69,19 @@ def check_for_previous_deployment(app_root, create=False):
return False
#def download_and_check():
# f = url_get_file(None, 'https://get.openlp.org/webclient', 'download.cfg')
# print(f)
#download_and_check()
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]
#file_name = "/home/tim/Projects/OpenLP/openlp/remoteweb/deploy.zip"
#app_root = "/home/tim/.openlp/data/remotes/"
#deploy_zipfile(file_name)
#print(check_for_previous_deployment(app_root))
#print(check_for_previous_deployment(app_root, True))
#print(check_for_previous_deployment(app_root))
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')

View File

@ -106,6 +106,11 @@ class ApiTab(SettingsTab):
self.password.setObjectName('password')
self.user_login_layout.addRow(self.password_label, self.password)
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.setObjectName('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 '
'Store.').format(qr='https://itunes.apple.com/app/id1096218725'))
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.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 + '/password', self.password.text())
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):
"""

View File

@ -56,7 +56,7 @@ class ImageThread(QtCore.QThread):
"""
Run the thread.
"""
self.image_manager._process()
self.image_manager.process()
class Priority(object):
@ -307,11 +307,11 @@ class ImageManager(QtCore.QObject):
if not self.image_thread.isRunning():
self.image_thread.start()
def _process(self):
def process(self):
"""
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:
self._process_cache()
log.debug('_process - ended')

View File

@ -555,6 +555,7 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties):
songs_destination = os.path.join(gettempdir(), 'openlp')
bibles_destination = AppLocation.get_section_data_path('bibles')
themes_destination = AppLocation.get_section_data_path('themes')
remote_destination = AppLocation.get_section_data_path('remotes')
missed_files = []
# Download songs
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),
sha256):
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:
file_list = ''
for entry in missed_files:

View File

@ -254,8 +254,7 @@ class UiFirstTimeWizard(object):
self.presentation_check_box.setText(translate('OpenLP.FirstTimeWizard',
'Presentations Show .ppt, .odp and .pdf 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'
'phone app'))
self.remote_check_box.setText(translate('OpenLP.FirstTimeWizard', 'Remote Download latest Web Pages'))
self.song_usage_check_box.setText(translate('OpenLP.FirstTimeWizard', 'Song Usage Monitor'))
self.alert_check_box.setText(translate('OpenLP.FirstTimeWizard',
'Alerts Display informative messages while showing other slides'))

View File

@ -24,10 +24,11 @@ import logging
import os
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.lib import Plugin, StringContent, translate, build_icon
from openlp.plugins.remotes.endpoint import remote_endpoint
from openlp.plugins.remotes.deploy import download_and_check
log = logging.getLogger(__name__)
@ -46,6 +47,7 @@ class RemotesPlugin(Plugin, OpenLPMixin):
self.live_cache = None
self.stage_cache = None
register_endpoint(remote_endpoint)
Registry().register_function('download_website', self.manage_download)
@staticmethod
def about():
@ -121,3 +123,7 @@ class RemotesPlugin(Plugin, OpenLPMixin):
else:
self.live_cache = False
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 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.helpers.testmixin import TestMixin
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
"""
@ -44,6 +47,11 @@ class TestRemoteDeploy(TestCase):
Setup for tests
"""
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):
"""
@ -56,11 +64,8 @@ class TestRemoteDeploy(TestCase):
Remote Deploy tests - Test hosted sites file matches the config file
"""
# GIVEN: a hosted configuration file
user_agent = 'OpenLP/2.4.4'
web = 'https://get.openlp.org/webclient/'
web_config = get_web_page('{host}{name}'.format(host=web, name='download.cfg'),
header=('User-Agent', user_agent))
sha = web_config.read().decode('utf-8').split()[0]
sha = download_sha256()
callback = MagicMock()
callback.was_cancelled = False
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
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)