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
|
|
|
|
"""
|
2020-02-27 22:23:40 +00:00
|
|
|
import json
|
|
|
|
import logging
|
2017-09-26 17:51:09 +00:00
|
|
|
from zipfile import ZipFile
|
|
|
|
|
2017-10-07 07:05:07 +00:00
|
|
|
from openlp.core.common.applocation import AppLocation
|
2020-02-27 22:23:40 +00:00
|
|
|
from openlp.core.common.httputils import download_file, get_web_page, get_openlp_user_agent
|
|
|
|
|
|
|
|
REMOTE_URL = 'https://get.openlp.org/remote/'
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
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
|
|
|
|
|
|
|
|
2020-02-27 22:23:40 +00:00
|
|
|
def download_version_info():
|
2017-09-26 17:51:09 +00:00
|
|
|
"""
|
2020-02-27 22:23:40 +00:00
|
|
|
Download the version information file
|
2017-09-26 17:51:09 +00:00
|
|
|
"""
|
|
|
|
try:
|
2020-02-27 22:23:40 +00:00
|
|
|
file_contents = get_web_page(REMOTE_URL + 'version.json', headers={'User-Agent': get_openlp_user_agent()})
|
2017-09-26 17:51:09 +00:00
|
|
|
except ConnectionError:
|
|
|
|
return False
|
2020-02-27 22:23:40 +00:00
|
|
|
if not file_contents:
|
2017-12-02 21:47:11 +00:00
|
|
|
return None
|
2020-02-27 22:23:40 +00:00
|
|
|
return json.loads(file_contents)
|
2017-09-26 17:51:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
def download_and_check(callback=None):
|
|
|
|
"""
|
|
|
|
Download the web site and deploy it.
|
|
|
|
"""
|
2020-02-27 22:23:40 +00:00
|
|
|
version_info = download_version_info()
|
|
|
|
if not version_info:
|
|
|
|
log.warning('Unable to access the version information, abandoning download')
|
|
|
|
# Show the user an error message
|
|
|
|
return None
|
|
|
|
file_size = version_info['latest']['size']
|
2017-09-26 17:51:09 +00:00
|
|
|
callback.setRange(0, file_size)
|
2020-02-27 22:23:40 +00:00
|
|
|
if download_file(callback, REMOTE_URL + '{version}/{filename}'.format(**version_info['latest']),
|
|
|
|
AppLocation.get_section_data_path('remotes') / 'remote.zip'):
|
|
|
|
deploy_zipfile(AppLocation.get_section_data_path('remotes'), 'remote.zip')
|
|
|
|
return version_info['latest']['version']
|
|
|
|
return None
|