From 64ba30b24dced2acb9fabf32f143bf28891736a7 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 26 Sep 2017 18:51:09 +0100 Subject: [PATCH] add files --- openlp/core/api/deploy.py | 69 ++++++++++++++++++++++++++++++ openlp/core/api/endpoint/remote.py | 46 ++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 openlp/core/api/deploy.py create mode 100644 openlp/core/api/endpoint/remote.py diff --git a/openlp/core/api/deploy.py b/openlp/core/api/deploy.py new file mode 100644 index 000000000..44c628837 --- /dev/null +++ b/openlp/core/api/deploy.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2017 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; version 2 of the License. # +# # +# 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, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### +""" +Download and "install" the remote web client +""" +import os +from zipfile import ZipFile + +from openlp.core.common import AppLocation, Registry +from openlp.core.common.httputils import url_get_file, get_web_page, get_url_file_size + + +def deploy_zipfile(app_root, zip_name): + """ + Process the downloaded zip file and add to the correct directory + + :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(zip_file) + web_zip.extractall(app_root) + + +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 + 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) + if url_get_file(callback, '{host}{name}'.format(host='https://get.openlp.org/webclient/', name='site.zip'), + AppLocation.get_section_data_path('remotes') / 'site.zip', + sha256=sha256): + deploy_zipfile(str(AppLocation.get_section_data_path('remotes')), 'site.zip') diff --git a/openlp/core/api/endpoint/remote.py b/openlp/core/api/endpoint/remote.py new file mode 100644 index 000000000..a9b0d0815 --- /dev/null +++ b/openlp/core/api/endpoint/remote.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2017 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; version 2 of the License. # +# # +# 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, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### +import logging + +import os + +from openlp.core.api.http.endpoint import Endpoint +from openlp.core.api.endpoint.core import TRANSLATED_STRINGS +from openlp.core.common import AppLocation + + +static_dir = os.path.join(str(AppLocation.get_section_data_path('remotes'))) + +log = logging.getLogger(__name__) + +remote_endpoint = Endpoint('remote', template_dir=static_dir, static_dir=static_dir) + + +@remote_endpoint.route('{view}') +def index(request, view): + """ + Handles requests for /remotes url + + :param request: The http request object. + :param view: The view name to be servered. + """ + return remote_endpoint.render_template('{view}.mako'.format(view=view), **TRANSLATED_STRINGS)