2017-09-26 17:51:09 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2019-04-13 13:00:22 +00:00
|
|
|
##########################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# ---------------------------------------------------------------------- #
|
2020-01-01 02:53:08 +00:00
|
|
|
# Copyright (c) 2008-2020 OpenLP Developers #
|
2019-04-13 13:00:22 +00:00
|
|
|
# ---------------------------------------------------------------------- #
|
|
|
|
# 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, either version 3 of the License, or #
|
|
|
|
# (at your option) any later version. #
|
|
|
|
# #
|
|
|
|
# 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, see <https://www.gnu.org/licenses/>. #
|
|
|
|
##########################################################################
|
2017-09-26 17:51:09 +00:00
|
|
|
"""
|
|
|
|
Download and "install" the remote web client
|
|
|
|
"""
|
|
|
|
from zipfile import ZipFile
|
2020-01-04 21:24:32 +00:00
|
|
|
from PyQt5 import QtWidgets
|
2017-09-26 17:51:09 +00:00
|
|
|
|
2017-10-07 07:05:07 +00:00
|
|
|
from openlp.core.common.applocation import AppLocation
|
2018-10-02 04:39:42 +00:00
|
|
|
from openlp.core.common.httputils import download_file, get_url_file_size, get_web_page
|
2017-09-26 17:51:09 +00:00
|
|
|
|
|
|
|
|
2017-11-18 11:23:15 +00:00
|
|
|
def deploy_zipfile(app_root_path, zip_name):
|
2017-09-26 17:51:09 +00:00
|
|
|
"""
|
|
|
|
Process the downloaded zip file and add to the correct directory
|
|
|
|
|
2017-11-18 11:23:15 +00:00
|
|
|
:param str zip_name: the zip file name to be processed
|
2019-05-22 06:47:00 +00:00
|
|
|
:param pathlib.Path app_root_path: The directory to expand the zip to
|
2017-09-26 17:51:09 +00:00
|
|
|
|
|
|
|
:return: None
|
|
|
|
"""
|
2017-11-18 11:23:15 +00:00
|
|
|
zip_path = app_root_path / zip_name
|
2019-03-10 21:01:39 +00:00
|
|
|
web_zip = ZipFile(zip_path)
|
|
|
|
web_zip.extractall(app_root_path)
|
2017-09-26 17:51:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
def download_sha256():
|
|
|
|
"""
|
|
|
|
Download the config file to extract the sha256 and version number
|
|
|
|
"""
|
2020-01-04 21:24:32 +00:00
|
|
|
user_agent = 'OpenLP/' + QtWidgets.QApplication.applicationVersion()
|
2017-09-26 17:51:09 +00:00
|
|
|
try:
|
|
|
|
web_config = get_web_page('https://get.openlp.org/webclient/download.cfg', headers={'User-Agent': user_agent})
|
|
|
|
except ConnectionError:
|
|
|
|
return False
|
2017-12-02 21:47:11 +00:00
|
|
|
if not web_config:
|
|
|
|
return None
|
2017-09-26 17:51:09 +00:00
|
|
|
file_bits = web_config.split()
|
|
|
|
return file_bits[0], file_bits[2]
|
|
|
|
|
|
|
|
|
|
|
|
def download_and_check(callback=None):
|
|
|
|
"""
|
|
|
|
Download the web site and deploy it.
|
|
|
|
"""
|
|
|
|
sha256, version = download_sha256()
|
|
|
|
file_size = get_url_file_size('https://get.openlp.org/webclient/site.zip')
|
|
|
|
callback.setRange(0, file_size)
|
2018-01-04 06:01:35 +00:00
|
|
|
if download_file(callback, 'https://get.openlp.org/webclient/site.zip',
|
2020-01-27 22:57:58 +00:00
|
|
|
AppLocation.get_section_data_path('remotes') / 'site.zip'):
|
2017-11-18 11:23:15 +00:00
|
|
|
deploy_zipfile(AppLocation.get_section_data_path('remotes'), 'site.zip')
|