openlp/openlp/core/api/deploy.py

72 lines
3.1 KiB
Python
Raw Normal View History

2017-09-26 17:51:09 +00:00
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
2019-04-13 13:00:22 +00:00
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
# Copyright (c) 2008-2019 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, 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
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-12-28 08:27:44 +00:00
from openlp.core.common.registry import Registry
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
:param openlp.core.common.path.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
"""
user_agent = 'OpenLP/' + Registry().get('application').applicationVersion()
try:
web_config = get_web_page('https://get.openlp.org/webclient/download.cfg', headers={'User-Agent': user_agent})
except ConnectionError:
return False
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',
2018-01-04 07:00:55 +00:00
AppLocation.get_section_data_path('remotes') / 'site.zip',
sha256=sha256):
2017-11-18 11:23:15 +00:00
deploy_zipfile(AppLocation.get_section_data_path('remotes'), 'site.zip')