← Back to team overview

openlp-core team mailing list archive

Re: [Merge] lp:~phill-ridout/openlp/ftw-json-theme-list into lp:openlp

 

Review: Needs Fixing

This looks good, though I'm not a fan of f"{Strings}" (I prefer to follow the mantra of "explicit is better than implicit").

One small change to remove a #noqa below, and we're good to go.

Diff comments:

> === modified file 'openlp/core/common/httputils.py'
> --- openlp/core/common/httputils.py	2019-02-14 15:09:09 +0000
> +++ openlp/core/common/httputils.py	2019-02-16 09:08:06 +0000
> @@ -227,4 +231,46 @@
>      return True
>  
>  
> -__all__ = ['get_web_page']
> +class DownloadWorker(ThreadWorker):
> +    """
> +    This worker allows a file to be downloaded in a thread
> +    """
> +    download_failed = QtCore.pyqtSignal()
> +    download_succeeded = QtCore.pyqtSignal(Path)
> +
> +    def __init__(self, base_url, file_name):
> +        """
> +        Set up the worker object
> +        """
> +        self._base_url = base_url
> +        self._file_name = file_name
> +        self._download_cancelled = False
> +        super().__init__()
> +
> +    def start(self):
> +        """
> +        Download the url to the temporary directory
> +        """
> +        if self._download_cancelled:
> +            self.quit.emit()
> +            return
> +        try:
> +            dest_path = Path(gettempdir()) / 'openlp' / self._file_name
> +            url = f'{self._base_url}{self._file_name}'
> +            is_success = download_file(self, url, dest_path)
> +            if is_success and not self._download_cancelled:
> +                self.download_succeeded.emit(dest_path)
> +            else:
> +                self.download_failed.emit()
> +        except:                                                                 # noqa

except Exception:

> +            log.exception('Unable to download %s', url)
> +            self.download_failed.emit()
> +        finally:
> +            self.quit.emit()
> +
> +    @QtCore.pyqtSlot()
> +    def cancel_download(self):
> +        """
> +        A slot to allow the download to be cancelled from outside of the thread
> +        """
> +        self._download_cancelled = True


-- 
https://code.launchpad.net/~phill-ridout/openlp/ftw-json-theme-list/+merge/363282
Your team OpenLP Core is subscribed to branch lp:openlp.


References