← Back to team overview

openlp-core team mailing list archive

Re: [Merge] lp:~trb143/openlp/webfull into lp:openlp

 

So, some thoughts around removing the web remote from OpenLP:

 - The remote plugin should handle the download and install of the web remote
 - The downloadable web remote should be versioned
 - OpenLP needs to be aware of the versions
 - Users should be able to check if there's a new version of the web remote
 - Users should be able to download an updated version of the web remote
 - Technically, the remote plugin should implement the old API
 - We should really make the new API RESTful, which means returning 400,
   500 and 200 status codes and not {"result": {"success": true}}

I'm going to write up more on the wiki about how I think the new API methods should look.

Also, see inline comments.

Diff comments:

> === modified file 'openlp/core/__init__.py'
> --- openlp/core/__init__.py	2016-12-31 11:01:36 +0000
> +++ openlp/core/__init__.py	2017-03-05 17:49:39 +0000
> @@ -338,6 +338,8 @@
>      parser.add_argument('-d', '--dev-version', dest='dev_version', action='store_true',
>                          help='Ignore the version file and pull the version directly from Bazaar')
>      parser.add_argument('-s', '--style', dest='style', help='Set the Qt5 style (passed directly to Qt5).')
> +    parser.add_argument('-w', '--webServer', dest='webServer', action='store_false',
> +                        help='Turn off the Web and Socket Server ')

--no-web-server, no_web_server

>      parser.add_argument('rargs', nargs='?', default=[])
>      # Parse command line options and deal with them. Use args supplied pragmatically if possible.
>      return parser.parse_args(args) if args else parser.parse_args()
> @@ -411,6 +413,7 @@
>          set_up_logging(AppLocation.get_directory(AppLocation.CacheDir))
>      Registry.create()
>      Registry().register('application', application)
> +    Registry().set_flag('webServer', args.webServer)

no_web_server

>      application.setApplicationVersion(get_application_version()['version'])
>      # Check if an instance of OpenLP is already running. Quit if there is a running instance and the user only wants one
>      if application.is_already_running():
> 
> === added file 'openlp/core/api/deploy.py'
> --- openlp/core/api/deploy.py	1970-01-01 00:00:00 +0000
> +++ openlp/core/api/deploy.py	2017-03-05 17:49:39 +0000
> @@ -0,0 +1,87 @@
> +# -*- 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 os
> +import zipfile
> +import urllib.error
> +
> +from openlp.core.common import AppLocation, Registry
> +from openlp.core.common.httputils import url_get_file, get_web_page
> +
> +
> +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.ZipFile(zip_file)
> +    for web_file in web_zip.namelist():

Why are you doing it the long way? Just use web_zip.extractall()

> +        (dir_name, filename) = os.path.split(web_file)
> +        real_path = os.path.join(app_root, web_file[4:])
> +        if filename == '':
> +            if not os.path.exists(real_path):
> +                os.makedirs(real_path)
> +        else:
> +            file_web = web_zip.read(web_file)
> +            out_file = open(real_path, 'w')
> +            # extract the file from the zip.  If an image then the exception will be used.
> +            try:
> +                out_file.write(file_web.decode("utf-8"))
> +            except UnicodeDecodeError as ude:
> +                out_file.close()
> +                out_file = open(real_path, 'wb')
> +                out_file.write(file_web)
> +            out_file.close()
> +    web_zip.close()
> +
> +
> +def check_for_previous_deployment(app_root, create=False):
> +    marker_file = os.path.join(app_root, "marker.txt")
> +    if os.path.isfile(marker_file):
> +        return True
> +    else:
> +        if create:
> +            os.mknod(marker_file)
> +        return False
> +
> +
> +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]
> +
> +
> +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')


-- 
https://code.launchpad.net/~trb143/openlp/webfull/+merge/319003
Your team OpenLP Core is requested to review the proposed merge of lp:~trb143/openlp/webfull into lp:openlp.


References