This commit is contained in:
Raoul Snyman 2019-06-04 21:53:18 -07:00
commit bae4cb2a44
112 changed files with 1092 additions and 9917 deletions

View File

@ -34,7 +34,7 @@ def deploy_zipfile(app_root_path, zip_name):
Process the downloaded zip file and add to the correct directory
: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
:param pathlib.Path app_root_path: The directory to expand the zip to
:return: None
"""

View File

@ -24,11 +24,11 @@ import logging
import os
import urllib.error
import urllib.request
from pathlib import Path
from openlp.core.api.http import requires_auth
from openlp.core.api.http.endpoint import Endpoint
from openlp.core.common.applocation import AppLocation
from openlp.core.common.path import Path
from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings
from openlp.core.lib import create_thumb

View File

@ -28,10 +28,12 @@ logging and a plugin framework are contained within the openlp.core module.
"""
import argparse
import logging
import os
import sys
import time
import os
from datetime import datetime
from pathlib import Path
from shutil import copytree
from traceback import format_exception
from PyQt5 import QtCore, QtWebEngineWidgets, QtWidgets # noqa
@ -41,7 +43,7 @@ from openlp.core.common import is_macosx, is_win
from openlp.core.common.applocation import AppLocation
from openlp.core.loader import loader
from openlp.core.common.i18n import LanguageManager, UiStrings, translate
from openlp.core.common.path import copytree, create_paths, Path
from openlp.core.common.path import create_paths
from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings
from openlp.core.display.screens import ScreenList
@ -316,7 +318,7 @@ def set_up_logging(log_path):
"""
Setup our logging using log_path
:param openlp.core.common.path.Path log_path: The file to save the log to.
:param Path log_path: The file to save the log to.
:rtype: None
"""
create_paths(log_path, do_not_log=True)
@ -383,6 +385,15 @@ def main():
else:
application.setApplicationName('OpenLP')
set_up_logging(AppLocation.get_directory(AppLocation.CacheDir))
# Set the libvlc environment variable if we're frozen
if getattr(sys, 'frozen', False):
if is_macosx():
vlc_lib = 'libvlc.dylib'
elif is_win():
vlc_lib = 'libvlc.dll'
os.environ['PYTHON_VLC_LIB_PATH'] = str(AppLocation.get_directory(AppLocation.AppDir) / vlc_lib)
log.debug('VLC Path: {}'.format(os.environ['PYTHON_VLC_LIB_PATH']))
# Initialise the Registry
Registry.create()
Registry().register('application', application)
Registry().set_flag('no_web_server', args.no_web_server)

View File

@ -142,7 +142,7 @@ def path_to_module(path):
"""
Convert a path to a module name (i.e openlp.core.common)
:param openlp.core.common.path.Path path: The path to convert to a module name.
:param pathlib.Path path: The path to convert to a module name.
:return: The module name.
:rtype: str
"""
@ -371,7 +371,7 @@ def delete_file(file_path):
"""
Deletes a file from the system.
:param openlp.core.common.path.Path file_path: The file, including path, to delete.
:param pathlib.Path file_path: The file, including path, to delete.
:return: True if the deletion was successful, or the file never existed. False otherwise.
:rtype: bool
"""
@ -407,7 +407,7 @@ def is_not_image_file(file_path):
"""
Validate that the file is not an image file.
:param openlp.core.common.path.Path file_path: The file to be checked.
:param pathlib.Path file_path: The file to be checked.
:return: If the file is not an image
:rtype: bool
"""
@ -435,7 +435,7 @@ def check_binary_exists(program_path):
"""
Function that checks whether a binary exists.
:param openlp.core.common.path.Path program_path: The full path to the binary to check.
:param pathlib.Path program_path: The full path to the binary to check.
:return: program output to be parsed
:rtype: bytes
"""
@ -462,7 +462,7 @@ def get_file_encoding(file_path):
"""
Utility function to incrementally detect the file encoding.
:param openlp.core.common.path.Path file_path: Filename for the file to determine the encoding for.
:param pathlib.Path file_path: Filename for the file to determine the encoding for.
:return: The name of the encoding detected
:rtype: str
"""

View File

@ -25,12 +25,13 @@ The :mod:`openlp.core.common.applocation` module provides an utility for OpenLP
import logging
import os
import sys
from pathlib import Path
import appdirs
import openlp
from openlp.core.common import get_frozen_path, is_macosx, is_win
from openlp.core.common.path import Path, create_paths
from openlp.core.common.path import create_paths
from openlp.core.common.settings import Settings
@ -58,7 +59,7 @@ class AppLocation(object):
:param dir_type: The directory type you want, for instance the data directory. Default *AppLocation.AppDir*
:return: The requested path
:rtype: openlp.core.common.path.Path
:rtype: Path
"""
if dir_type == AppLocation.AppDir or dir_type == AppLocation.VersionDir:
return get_frozen_path(FROZEN_APP_PATH, APP_PATH)
@ -75,7 +76,7 @@ class AppLocation(object):
Return the path OpenLP stores all its data under.
:return: The data path to use.
:rtype: openlp.core.common.path.Path
:rtype: Path
"""
# Check if we have a different data location.
if Settings().contains('advanced/data path'):
@ -95,7 +96,7 @@ class AppLocation(object):
:param str extension: Defaults to ''. The extension to search for. For example::
'.png'
:return: List of files found.
:rtype: list[openlp.core.common.path.Path]
:rtype: list[Path]
"""
path = AppLocation.get_data_path()
if section:
@ -112,7 +113,7 @@ class AppLocation(object):
Return the path a particular module stores its data under.
:param str section:
:rtype: openlp.core.common.path.Path
:rtype: Path
"""
path = AppLocation.get_data_path() / section
create_paths(path)
@ -125,7 +126,7 @@ def _get_os_dir_path(dir_type):
:param dir_type: AppLocation Enum of the requested path type
:return: The requested path
:rtype: openlp.core.common.path.Path
:rtype: Path
"""
# If running from source, return the language directory from the source directory
if dir_type == AppLocation.LanguageDir:

View File

@ -26,6 +26,7 @@ import hashlib
import logging
import sys
import time
from pathlib import Path
from random import randint
from tempfile import gettempdir
@ -33,7 +34,6 @@ import requests
from PyQt5 import QtCore
from openlp.core.common import trace_error_handler
from openlp.core.common.path import Path
from openlp.core.common.registry import Registry
from openlp.core.common.settings import ProxyMode, Settings
from openlp.core.threading import ThreadWorker

View File

@ -19,14 +19,75 @@
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
##########################################################################
from contextlib import suppress
from json import JSONDecoder, JSONEncoder
from pathlib import Path
from openlp.core.common.path import Path
_registered_classes = {}
class OpenLPJsonDecoder(JSONDecoder):
class JSONMixin(object):
"""
Implement a custom JSONDecoder to handle Path objects
:class:`JSONMixin` is a mixin class to simplify the serialization of a subclass to JSON.
:cvar:`_json_keys` is used to specify the attributes of the subclass that you wish to serialize.
:vartype _json_keys: list[str]
:cvar:`_name` set to override the the subclass name, useful if using a `proxy` class
:vartype _name: str
"""
_json_keys = []
_name = None
_version = 1
def __init_subclass__(cls, register_names=None, **kwargs):
"""
Register the subclass.
:param collections.Iterable[str] register_names: Alternative names to register instead of the class name
:param kwargs: Other args to pass to the super method
:return None:
"""
super().__init_subclass__(**kwargs)
for key in register_names or [cls.__name__]:
_registered_classes[key] = cls
@classmethod
def encode_json(cls, obj, **kwargs):
"""
Create a instance of the subclass from the dictionary that has been constructed by the JSON representation.
Only use the keys specified in :cvar:`_json_keys`.
:param dict[str] obj: The dictionary representation of the subclass (deserailized from the JSON)
:param kwargs: Contains any extra parameters. Not used!
:return: The desrialized object
"""
return cls(**{key: obj[key] for key in cls._json_keys if obj.get(key) is not None})
@classmethod
def attach_meta(cls, j_dict):
"""
Attach meta data to the serialized dictionary.
:param dict[str] j_dict: The dictionary to update with the meta data
:return None:
"""
j_dict.update({'json_meta': {'class': cls._name or cls.__name__, 'version': cls._version}})
def json_object(self, **kwargs):
"""
Create a dictionary that can be JSON decoded.
:param kwargs: Contains any extra parameters. Not used!
:return dict[str]: The dictionary representation of this Path object.
"""
j_dict = {key: self.__dict__[key] for key in self._json_keys if self.__dict__.get(key) is not None}
self.attach_meta(j_dict)
return j_dict
class OpenLPJSONDecoder(JSONDecoder):
"""
Implement a custom JSONDecoder to extend compatibility to custom objects
Example Usage:
object = json.loads(json_string, cls=OpenLPJsonDecoder)
@ -45,23 +106,26 @@ class OpenLPJsonDecoder(JSONDecoder):
def custom_object_hook(self, obj):
"""
Implement a custom Path object decoder.
Implement a custom object decoder.
:param dict obj: A decoded JSON object
:return: The original object literal, or a Path object if the object literal contains a key '__Path__'
:rtype: dict | openlp.core.common.path.Path
:return: The custom object from the serialized data if the custom object is registered, else obj
"""
if '__Path__' in obj:
obj = Path.encode_json(obj, **self.kwargs)
try:
key = obj['json_meta']['class']
except KeyError:
return obj
if key in _registered_classes:
return _registered_classes[key].encode_json(obj, **self.kwargs)
return obj
class OpenLPJsonEncoder(JSONEncoder):
class OpenLPJSONEncoder(JSONEncoder):
"""
Implement a custom JSONEncoder to handle Path objects
Implement a custom JSONEncoder to handle to extend compatibility to custom objects
Example Usage:
json_string = json.dumps(object, cls=OpenLPJsonEncoder)
json_string = json.dumps(object, cls=OpenLPJSONEncoder)
"""
def __init__(self, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False,
indent=None, separators=None, default=None, **kwargs):
@ -78,12 +142,57 @@ class OpenLPJsonEncoder(JSONEncoder):
def custom_default(self, obj):
"""
Convert any Path objects into a dictionary object which can be serialized.
Convert any registered objects into a dictionary object which can be serialized.
:param object obj: The object to convert
:return: The serializable object
:rtype: dict
:return dict: The serializable object
"""
if isinstance(obj, Path):
return obj.json_object(**self.kwargs)
if isinstance(obj, JSONMixin):
return obj.json_object()
elif obj.__class__.__name__ in _registered_classes:
return _registered_classes[obj.__class__.__name__].json_object(obj)
return super().default(obj)
def is_serializable(obj):
return obj.__class__.__name__ in _registered_classes
class PathSerializer(JSONMixin, register_names=('Path', 'PosixPath', 'WindowsPath')):
"""
Implement a de/serializer for pathlib.Path objects
"""
_name = 'Path'
@staticmethod
def encode_json(obj, base_path=None, **kwargs):
"""
Reimplement encode_json to create a Path object from a dictionary representation.
:param dict[str] obj: The dictionary representation
:param Path base_path: If specified, an absolute path to base the relative path off of.
:param kwargs: Contains any extra parameters. Not used!
:return Path: The deserialized Path object
"""
path = Path(*obj['parts'])
if base_path and not path.is_absolute():
return base_path / path
return path
@classmethod
def json_object(cls, obj, base_path=None, **kwargs):
"""
Create a dictionary that can be JSON decoded.
:param Path base_path: If specified, an absolute path to make a relative path from.
:param kwargs: Contains any extra parameters. Not used!
:return: The dictionary representation of this Path object.
:rtype: dict[tuple]
"""
path = obj
if base_path:
with suppress(ValueError):
path = path.relative_to(base_path)
json_dict = {'parts': path.parts}
cls.attach_meta(json_dict)
return json_dict

View File

@ -21,66 +21,11 @@
##########################################################################
import logging
import shutil
from contextlib import suppress
from openlp.core.common import is_win
if is_win():
from pathlib import WindowsPath as PathVariant # pragma: nocover
else:
from pathlib import PosixPath as PathVariant # pragma: nocover
from pathlib import Path
log = logging.getLogger(__name__)
class Path(PathVariant):
"""
Subclass pathlib.Path, so we can add json conversion methods
"""
@staticmethod
def encode_json(obj, base_path=None, **kwargs):
"""
Create a Path object from a dictionary representation. The dictionary has been constructed by JSON encoding of
a JSON reprensation of a Path object.
:param dict[str] obj: The dictionary representation
:param openlp.core.common.path.Path base_path: If specified, an absolute path to base the relative path off of.
:param kwargs: Contains any extra parameters. Not used!
:return: The reconstructed Path object
:rtype: openlp.core.common.path.Path
"""
path = Path(*obj['__Path__'])
if base_path and not path.is_absolute():
return base_path / path
return path
def json_object(self, base_path=None, **kwargs):
"""
Create a dictionary that can be JSON decoded.
:param openlp.core.common.path.Path base_path: If specified, an absolute path to make a relative path from.
:param kwargs: Contains any extra parameters. Not used!
:return: The dictionary representation of this Path object.
:rtype: dict[tuple]
"""
path = self
if base_path:
with suppress(ValueError):
path = path.relative_to(base_path)
return {'__Path__': path.parts}
def rmtree(self, ignore_errors=False, onerror=None):
"""
Provide an interface to :func:`shutil.rmtree`
:param bool ignore_errors: Ignore errors
:param onerror: Handler function to handle any errors
:rtype: None
"""
shutil.rmtree(self, ignore_errors, onerror)
def replace_params(args, kwargs, params):
"""
Apply a transformation function to the specified args or kwargs
@ -110,65 +55,11 @@ def replace_params(args, kwargs, params):
return tuple(args), kwargs
def copy(*args, **kwargs):
"""
Wraps :func:`shutil.copy` so that we can accept Path objects.
:param src openlp.core.common.path.Path: Takes a Path object which is then converted to a str object
:param dst openlp.core.common.path.Path: Takes a Path object which is then converted to a str object
:return: Converts the str object received from :func:`shutil.copy` to a Path or NoneType object
:rtype: openlp.core.common.path.Path | None
See the following link for more information on the other parameters:
https://docs.python.org/3/library/shutil.html#shutil.copy
"""
args, kwargs = replace_params(args, kwargs, ((0, 'src', path_to_str), (1, 'dst', path_to_str)))
return str_to_path(shutil.copy(*args, **kwargs))
def copyfile(*args, **kwargs):
"""
Wraps :func:`shutil.copyfile` so that we can accept Path objects.
:param openlp.core.common.path.Path src: Takes a Path object which is then converted to a str object
:param openlp.core.common.path.Path dst: Takes a Path object which is then converted to a str object
:return: Converts the str object received from :func:`shutil.copyfile` to a Path or NoneType object
:rtype: openlp.core.common.path.Path | None
See the following link for more information on the other parameters:
https://docs.python.org/3/library/shutil.html#shutil.copyfile
"""
args, kwargs = replace_params(args, kwargs, ((0, 'src', path_to_str), (1, 'dst', path_to_str)))
return str_to_path(shutil.copyfile(*args, **kwargs))
def copytree(*args, **kwargs):
"""
Wraps :func:shutil.copytree` so that we can accept Path objects.
:param openlp.core.common.path.Path src : Takes a Path object which is then converted to a str object
:param openlp.core.common.path.Path dst: Takes a Path object which is then converted to a str object
:return: Converts the str object received from :func:`shutil.copytree` to a Path or NoneType object
:rtype: openlp.core.common.path.Path | None
See the following link for more information on the other parameters:
https://docs.python.org/3/library/shutil.html#shutil.copytree
"""
args, kwargs = replace_params(args, kwargs, ((0, 'src', path_to_str), (1, 'dst', path_to_str)))
return str_to_path(shutil.copytree(*args, **kwargs))
def which(*args, **kwargs):
"""
Wraps :func:shutil.which` so that it return a Path objects.
:rtype: openlp.core.common.Path
:rtype: Path
See the following link for more information on the other parameters:
https://docs.python.org/3/library/shutil.html#shutil.which
@ -183,7 +74,7 @@ def path_to_str(path=None):
"""
A utility function to convert a Path object or NoneType to a string equivalent.
:param openlp.core.common.path.Path | None path: The value to convert to a string
:param Path | None path: The value to convert to a string
:return: An empty string if :param:`path` is None, else a string representation of the :param:`path`
:rtype: str
"""
@ -206,7 +97,7 @@ def str_to_path(string):
:param str string: The string to convert
:return: None if :param:`string` is empty, or a Path object representation of :param:`string`
:rtype: openlp.core.common.path.Path | None
:rtype: Path | None
"""
if not isinstance(string, str):
log.error('parameter \'string\' must be of type str, got {} which is a {} instead'.format(string, type(string)))
@ -220,7 +111,7 @@ def create_paths(*paths, **kwargs):
"""
Create one or more paths
:param openlp.core.common.path.Path paths: The paths to create
:param Path paths: The paths to create
:param bool do_not_log: To not log anything. This is need for the start up, when the log isn't ready.
:rtype: None
"""
@ -241,7 +132,7 @@ def files_to_paths(file_names):
:param list[str] file_names: The list of file names to convert.
:return: The list converted to file paths
:rtype: openlp.core.common.path.Path
:rtype: Path
"""
if file_names:
return [str_to_path(file_name) for file_name in file_names]

View File

@ -27,13 +27,14 @@ import json
import logging
import os
from enum import IntEnum
from pathlib import Path
from tempfile import gettempdir
from PyQt5 import QtCore, QtGui
from openlp.core.common import SlideLimits, ThemeLevel, is_linux, is_win
from openlp.core.common.json import OpenLPJsonDecoder, OpenLPJsonEncoder
from openlp.core.common.path import Path, files_to_paths, str_to_path
from openlp.core.common.json import OpenLPJSONDecoder, OpenLPJSONEncoder, is_serializable
from openlp.core.common.path import files_to_paths, str_to_path
log = logging.getLogger(__name__)
@ -337,7 +338,7 @@ class Settings(QtCore.QSettings):
Does not affect existing Settings objects.
:param openlp.core.common.path.Path ini_path: ini file path
:param Path ini_path: ini file path
:rtype: None
"""
Settings.__file_path__ = str(ini_path)
@ -584,8 +585,9 @@ class Settings(QtCore.QSettings):
:param value: The value to save
:rtype: None
"""
if isinstance(value, (Path, dict)) or (isinstance(value, list) and value and isinstance(value[0], Path)):
value = json.dumps(value, cls=OpenLPJsonEncoder)
if is_serializable(value) or isinstance(value, dict) or \
(isinstance(value, list) and value and is_serializable(value[0])):
value = json.dumps(value, cls=OpenLPJSONEncoder)
super().setValue(key, value)
def _convert_value(self, setting, default_value):
@ -611,8 +613,8 @@ class Settings(QtCore.QSettings):
elif isinstance(default_value, dict):
return {}
elif isinstance(setting, str):
if '__Path__' in setting or setting.startswith('{'):
return json.loads(setting, cls=OpenLPJsonDecoder)
if 'json_meta' in setting or setting.startswith('{'):
return json.loads(setting, cls=OpenLPJSONDecoder)
# Convert the setting to the correct type.
if isinstance(default_value, bool):
if isinstance(setting, bool):
@ -629,7 +631,7 @@ class Settings(QtCore.QSettings):
"""
Export the settings to file.
:param openlp.core.common.path.Path dest_path: The file path to create the export file.
:param Path dest_path: The file path to create the export file.
:return: Success
:rtype: bool
"""

View File

@ -249,18 +249,18 @@ class DisplayWindow(QtWidgets.QWidget):
"""
Set images in the display
"""
for image in images:
if not image['path'].startswith('file://'):
image['path'] = 'file://' + image['path']
json_images = json.dumps(images)
imagesr = copy.deepcopy(images)
for image in imagesr:
image['path'] = image['path'].as_uri()
json_images = json.dumps(imagesr)
self.run_javascript('Display.setImageSlides({images});'.format(images=json_images))
def load_video(self, video):
"""
Load video in the display
"""
if not video['path'].startswith('file://'):
video['path'] = 'file://' + video['path']
video = copy.deepcopy(video)
video['path'] = video['path'].as_uri()
json_video = json.dumps(video)
self.run_javascript('Display.setVideo({video});'.format(video=json_video))

View File

@ -24,11 +24,11 @@ The :mod:`lib` module contains most of the components and libraries that make
OpenLP work.
"""
import logging
from pathlib import Path
from PyQt5 import QtCore, QtGui, QtWidgets
from openlp.core.common.i18n import translate
from openlp.core.common.path import Path
log = logging.getLogger(__name__ + '.__init__')
@ -181,7 +181,7 @@ def get_text_file_string(text_file_path):
returns False. If there is an error loading the file or the content can't be decoded then the function will return
None.
:param openlp.core.common.path.Path text_file_path: The path to the file.
:param Path text_file_path: The path to the file.
:return: The contents of the file, False if the file does not exist, or None if there is an Error reading or
decoding the file.
:rtype: str | False | None
@ -263,8 +263,8 @@ def create_thumb(image_path, thumb_path, return_icon=True, size=None):
"""
Create a thumbnail from the given image path and depending on ``return_icon`` it returns an icon from this thumb.
:param openlp.core.common.path.Path image_path: The image file to create the icon from.
:param openlp.core.common.path.Path thumb_path: The filename to save the thumbnail to.
:param Path image_path: The image file to create the icon from.
:param Path thumb_path: The filename to save the thumbnail to.
:param return_icon: States if an icon should be build and returned from the thumb. Defaults to ``True``.
:param size: Allows to state a own size (QtCore.QSize) to use. Defaults to ``None``, which means that a default
height of 88 is used.
@ -311,8 +311,8 @@ def validate_thumb(file_path, thumb_path):
Validates whether an file's thumb still exists and if is up to date. **Note**, you must **not** call this function,
before checking the existence of the file.
:param openlp.core.common.path.Path file_path: The path to the file. The file **must** exist!
:param openlp.core.common.path.Path thumb_path: The path to the thumb.
:param Path file_path: The path to the file. The file **must** exist!
:param Path thumb_path: The path to the thumb.
:return: Has the image changed since the thumb was created?
:rtype: bool
"""

View File

@ -40,7 +40,7 @@ from sqlalchemy.pool import NullPool
from openlp.core.common import delete_file
from openlp.core.common.applocation import AppLocation
from openlp.core.common.i18n import translate
from openlp.core.common.json import OpenLPJsonDecoder, OpenLPJsonEncoder
from openlp.core.common.json import OpenLPJSONDecoder, OpenLPJSONEncoder
from openlp.core.common.settings import Settings
from openlp.core.lib.ui import critical_error_message_box
@ -132,7 +132,7 @@ def get_db_path(plugin_name, db_file_name=None):
Create a path to a database from the plugin name and database name
:param plugin_name: Name of plugin
:param openlp.core.common.path.Path | str | None db_file_name: File name of database
:param pathlib.Path | str | None db_file_name: File name of database
:return: The path to the database
:rtype: str
"""
@ -150,7 +150,7 @@ def handle_db_error(plugin_name, db_file_path):
Log and report to the user that a database cannot be loaded
:param plugin_name: Name of plugin
:param openlp.core.common.path.Path db_file_path: File name of database
:param pathlib.Path db_file_path: File name of database
:return: None
"""
db_path = get_db_path(plugin_name, db_file_path)
@ -165,8 +165,8 @@ def init_url(plugin_name, db_file_name=None):
Construct the connection string for a database.
:param plugin_name: The name of the plugin for the database creation.
:param openlp.core.common.path.Path | str | None db_file_name: The database file name. Defaults to None resulting
in the plugin_name being used.
:param pathlib.Path | str | None db_file_name: The database file name. Defaults to None resulting in the plugin_name
being used.
:return: The database URL
:rtype: str
"""
@ -215,7 +215,7 @@ class PathType(types.TypeDecorator):
Create a PathType for storing Path objects with SQLAlchemy. Behind the scenes we convert the Path object to a JSON
representation and store it as a Unicode type
"""
impl = types.UnicodeText
impl = types.Unicode
def coerce_compared_value(self, op, value):
"""
@ -224,10 +224,8 @@ class PathType(types.TypeDecorator):
:param op: The operation being carried out. Not used, as we only care about the type that is being used with the
operation.
:param openlp.core.common.path.Path | str value: The value being used for the comparison. Most likely a Path
Object or str.
:return: The coerced value stored in the db
:rtype: PathType or UnicodeText
:param pathlib.Path | str value: The value being used for the comparison. Most likely a Path Object or str.
:return PathType | UnicodeText: The coerced value stored in the db
"""
if isinstance(value, str):
return UnicodeText()
@ -238,13 +236,12 @@ class PathType(types.TypeDecorator):
"""
Convert the Path object to a JSON representation
:param openlp.core.common.path.Path value: The value to convert
:param pathlib.Path value: The value to convert
:param dialect: Not used
:return: The Path object as a JSON string
:rtype: str
:return str: The Path object as a JSON string
"""
data_path = AppLocation.get_data_path()
return json.dumps(value, cls=OpenLPJsonEncoder, base_path=data_path)
return json.dumps(value, cls=OpenLPJSONEncoder, base_path=data_path)
def process_result_value(self, value, dialect):
"""
@ -253,10 +250,10 @@ class PathType(types.TypeDecorator):
:param types.UnicodeText value: The value to convert
:param dialect: Not used
:return: The JSON object converted Python object (in this case it should be a Path object)
:rtype: openlp.core.common.path.Path
:rtype: pathlib.Path
"""
data_path = AppLocation.get_data_path()
return json.loads(value, cls=OpenLPJsonDecoder, base_path=data_path)
return json.loads(value, cls=OpenLPJSONDecoder, base_path=data_path)
def upgrade_db(url, upgrade):
@ -351,8 +348,8 @@ class Manager(object):
:param plugin_name: The name to setup paths and settings section names
:param init_schema: The init_schema function for this database
:param openlp.core.common.path.Path db_file_path: The file name to use for this database. Defaults to None
resulting in the plugin_name being used.
:param pathlib.Path | None db_file_path: The file name to use for this database. Defaults to None resulting in
the plugin_name being used.
:param upgrade_mod: The upgrade_schema function for this database
"""
super().__init__()

View File

@ -369,7 +369,7 @@ class MediaManagerItem(QtWidgets.QWidget, RegistryProperties):
Process a list for files either from the File Dialog or from Drag and
Drop
:param list[openlp.core.common.path.Path] file_paths: The files to be loaded.
:param list[pathlib.Path] file_paths: The files to be loaded.
:param target_group: The QTreeWidgetItem of the group that will be the parent of the added files
"""
full_list = []
@ -410,7 +410,7 @@ class MediaManagerItem(QtWidgets.QWidget, RegistryProperties):
"""
Return the current list of files
:rtype: list[openlp.core.common.path.Path]
:rtype: list[pathlib.Path]
"""
file_paths = []
for index in range(self.list_view.count()):
@ -462,7 +462,7 @@ class MediaManagerItem(QtWidgets.QWidget, RegistryProperties):
:param item: The database item to be used to build the service item
:param remote: Was this remote triggered (False)
:param context: The service context
:param openlp.core.common.path.Path file_path:
:param pathlib.Path file_path:
"""
raise NotImplementedError('MediaManagerItem.generate_slide_data needs to be defined by the plugin')
@ -589,7 +589,7 @@ class MediaManagerItem(QtWidgets.QWidget, RegistryProperties):
"""
Add this item to the current service.
:param item: Item to be processed
:param QtWidgets.QListWidgetItem | QtWidgets.QTreeWidgetItem | None item: Item to be processed
:param replace: Replace the existing item
:param remote: Triggered from remote
:param position: Position to place item
@ -627,7 +627,7 @@ class MediaManagerItem(QtWidgets.QWidget, RegistryProperties):
def build_service_item(self, item=None, remote=False, context=ServiceItemContext.Live):
"""
Common method for generating a service item
:param item: Service Item to be built.
:param QtWidgets.QListWidgetItem | QtWidgets.QTreeWidgetItem | None item: Service Item to be built.
:param remote: Remote triggered (False)
:param context: The context on which this is called
"""

View File

@ -29,6 +29,7 @@ import ntpath
import os
import uuid
from copy import deepcopy
from pathlib import Path
from PyQt5 import QtGui
@ -37,7 +38,6 @@ from openlp.core.common import md5_hash
from openlp.core.common.applocation import AppLocation
from openlp.core.common.i18n import translate
from openlp.core.common.mixins import RegistryProperties
from openlp.core.common.path import Path
from openlp.core.common.settings import Settings
from openlp.core.display.render import remove_tags, render_tags
from openlp.core.lib import ItemCapabilities
@ -264,8 +264,8 @@ class ServiceItem(RegistryProperties):
if image and not self.has_original_files and self.name == 'presentations':
file_location = os.path.join(path, file_name)
file_location_hash = md5_hash(file_location.encode('utf-8'))
image = os.path.join(str(AppLocation.get_section_data_path(self.name)), 'thumbnails',
file_location_hash, ntpath.basename(image)) # TODO: Pathlib
image = os.path.join(AppLocation.get_section_data_path(self.name), 'thumbnails', file_location_hash,
ntpath.basename(image)) # TODO: Pathlib
self.slides.append({'title': file_name, 'image': image, 'path': path, 'display_title': display_title,
'notes': notes, 'thumbnail': image})
# if self.is_capable(ItemCapabilities.HasThumbnails):
@ -593,9 +593,11 @@ class ServiceItem(RegistryProperties):
"""
return not bool(self.slides)
def validate_item(self, suffix_list=None):
def validate_item(self, suffixes=None):
"""
Validates a service item to make sure it is valid
:param set[str] suffixes: A set of vaild suffixes
"""
self.is_valid = True
for slide in self.slides:
@ -612,8 +614,8 @@ class ServiceItem(RegistryProperties):
if not os.path.exists(file_name):
self.is_valid = False
break
if suffix_list and not self.is_text():
if suffixes and not self.is_text():
file_suffix = slide['title'].split('.')[-1]
if file_suffix.lower() not in suffix_list:
if file_suffix.lower() not in suffixes:
self.is_valid = False
break

View File

@ -29,7 +29,7 @@ from lxml import etree, objectify
from openlp.core.common import de_hump
from openlp.core.common.applocation import AppLocation
from openlp.core.common.json import OpenLPJsonDecoder, OpenLPJsonEncoder
from openlp.core.common.json import OpenLPJSONDecoder, OpenLPJSONEncoder
from openlp.core.display.screens import ScreenList
from openlp.core.lib import get_text_file_string, str_to_bool
@ -190,7 +190,7 @@ class Theme(object):
"""
Add the path name to the image name so the background can be rendered.
:param openlp.core.common.path.Path path: The path name to be added.
:param pathlib.Path path: The path name to be added.
:rtype: None
"""
if self.background_type == 'image' or self.background_type == 'video':
@ -216,13 +216,13 @@ class Theme(object):
Convert the JSON file and expand it.
:param theme: the theme string
:param openlp.core.common.path.Path theme_path: The path to the theme
:param pathlib.Path theme_path: The path to the theme
:rtype: None
"""
if theme_path:
jsn = json.loads(theme, cls=OpenLPJsonDecoder, base_path=theme_path)
jsn = json.loads(theme, cls=OpenLPJSONDecoder, base_path=theme_path)
else:
jsn = json.loads(theme, cls=OpenLPJsonDecoder)
jsn = json.loads(theme, cls=OpenLPJSONDecoder)
self.expand_json(jsn)
def export_theme(self, theme_path=None):
@ -234,8 +234,8 @@ class Theme(object):
for attr, value in self.__dict__.items():
theme_data["{attr}".format(attr=attr)] = value
if theme_path:
return json.dumps(theme_data, cls=OpenLPJsonEncoder, base_path=theme_path)
return json.dumps(theme_data, cls=OpenLPJsonEncoder)
return json.dumps(theme_data, cls=OpenLPJSONEncoder, base_path=theme_path)
return json.dumps(theme_data, cls=OpenLPJSONEncoder)
def parse(self, xml):
"""

View File

@ -39,6 +39,7 @@ PJLINK_PREFIX = '%'
PJLINK_PORT = 4352
PJLINK_SUFFIX = CR
PJLINK_TIMEOUT = 30.0
PJLINK_TOKEN_SIZE = 8 # PJLINK 1 <token> : where <token> is 8 characters
# Error and status codes
S_OK = E_OK = 0 # E_OK included since I sometimes forget

View File

@ -281,6 +281,7 @@ class PJLink(QtNetwork.QTcpSocket):
self.pjlink_class = copy(PJLINK_CLASS)
self.pjlink_name = None # NAME
self.power = S_OFF # POWR
self.projector_errors = {} # Full ERST errors
self.serial_no = None # SNUM
self.serial_no_received = None
self.sw_version = None # SVER

View File

@ -29,13 +29,13 @@ NOTE: PJLink Class (version) checks are handled in the respective PJLink/PJLinkU
import logging
import re
import string
from openlp.core.common.i18n import translate
from openlp.core.common.settings import Settings
from openlp.core.projectors.constants import E_AUTHENTICATION, PJLINK_DEFAULT_CODES, PJLINK_ERRORS, \
PJLINK_ERST_DATA, PJLINK_ERST_STATUS, PJLINK_POWR_STATUS, S_AUTHENTICATE, S_CONNECT, S_DATA_OK, S_OFF, S_OK, S_ON, \
S_STANDBY, STATUS_MSG
PJLINK_ERST_DATA, PJLINK_ERST_LIST, PJLINK_ERST_STATUS, PJLINK_POWR_STATUS, PJLINK_TOKEN_SIZE, \
E_NO_AUTHENTICATION, S_AUTHENTICATE, S_CONNECT, S_DATA_OK, S_OFF, S_OK, S_ON, S_STANDBY, STATUS_MSG
log = logging.getLogger(__name__)
log.debug('Loading pjlinkcommands')
@ -195,8 +195,7 @@ def process_erst(projector, data):
# Bad data - ignore
log.warning('({ip}) Invalid error status response "{data}"'.format(ip=projector.entry.name, data=data))
return
datacheck = int(data)
if datacheck == 0:
if int(data) == 0:
projector.projector_errors = None
# No errors
return
@ -209,23 +208,17 @@ def process_erst(projector, data):
data[PJLINK_ERST_DATA['FILTER']],
data[PJLINK_ERST_DATA['OTHER']])
if fan != PJLINK_ERST_STATUS[S_OK]:
projector.projector_errors[translate('OpenLP.ProjectorPJLink', 'Fan')] = \
PJLINK_ERST_STATUS[fan]
projector.projector_errors[PJLINK_ERST_LIST['FAN']] = PJLINK_ERST_STATUS[fan]
if lamp != PJLINK_ERST_STATUS[S_OK]:
projector.projector_errors[translate('OpenLP.ProjectorPJLink', 'Lamp')] = \
PJLINK_ERST_STATUS[lamp]
projector.projector_errors[PJLINK_ERST_LIST['LAMP']] = PJLINK_ERST_STATUS[lamp]
if temp != PJLINK_ERST_STATUS[S_OK]:
projector.projector_errors[translate('OpenLP.ProjectorPJLink', 'Temperature')] = \
PJLINK_ERST_STATUS[temp]
projector.projector_errors[PJLINK_ERST_LIST['TEMP']] = PJLINK_ERST_STATUS[temp]
if cover != PJLINK_ERST_STATUS[S_OK]:
projector.projector_errors[translate('OpenLP.ProjectorPJLink', 'Cover')] = \
PJLINK_ERST_STATUS[cover]
projector.projector_errors[PJLINK_ERST_LIST['COVER']] = PJLINK_ERST_STATUS[cover]
if filt != PJLINK_ERST_STATUS[S_OK]:
projector.projector_errors[translate('OpenLP.ProjectorPJLink', 'Filter')] = \
PJLINK_ERST_STATUS[filt]
projector.projector_errors[PJLINK_ERST_LIST['FILTER']] = PJLINK_ERST_STATUS[filt]
if other != PJLINK_ERST_STATUS[S_OK]:
projector.projector_errors[translate('OpenLP.ProjectorPJLink', 'Other')] = \
PJLINK_ERST_STATUS[other]
projector.projector_errors[PJLINK_ERST_LIST['OTHER']] = PJLINK_ERST_STATUS[other]
return
@ -389,20 +382,29 @@ def process_pjlink(projector, data):
if len(chk) > 1:
# Invalid data - there should be nothing after a normal authentication scheme
log.error('({ip}) Normal connection with extra information - aborting'.format(ip=projector.entry.name))
return E_AUTHENTICATION
return E_NO_AUTHENTICATION
elif projector.pin:
log.error('({ip}) Normal connection but PIN set - aborting'.format(ip=projector.entry.name))
return E_AUTHENTICATION
return E_NO_AUTHENTICATION
log.debug('({ip}) PJLINK: Returning S_CONNECT'.format(ip=projector.entry.name))
return S_CONNECT
elif chk[0] == '1':
if len(chk) < 2:
# Not enough information for authenticated connection
log.error('({ip}) Authenticated connection but not enough info - aborting'.format(ip=projector.entry.name))
return E_AUTHENTICATION
return E_NO_AUTHENTICATION
elif len(chk[-1]) != PJLINK_TOKEN_SIZE:
# Bad token - incorrect size
log.error('({ip}) Authentication token invalid (size) - aborting'.format(ip=projector.entry.name))
return E_NO_AUTHENTICATION
elif not all(c in string.hexdigits for c in chk[-1]):
# Bad token - not hexadecimal
log.error('({ip}) Authentication token invalid (not a hexadecimal number) '
'- aborting'.format(ip=projector.entry.name))
return E_NO_AUTHENTICATION
elif not projector.pin:
log.error('({ip}) Authenticate connection but no PIN - aborting'.format(ip=projector.entry.name))
return E_AUTHENTICATION
return E_NO_AUTHENTICATION
log.debug('({ip}) PJLINK: Returning S_AUTHENTICATE'.format(ip=projector.entry.name))
return S_AUTHENTICATE

View File

@ -19,10 +19,11 @@
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
##########################################################################
from pathlib import Path
from PyQt5 import QtCore, QtNetwork
from openlp.core.common.mixins import LogMixin
from openlp.core.common.path import Path
from openlp.core.common.registry import Registry

View File

@ -518,7 +518,7 @@ class AdvancedTab(SettingsTab):
"""
Handle the `editPathChanged` signal of the data_directory_path_edit
:param openlp.core.common.path.Path new_path: The new path
:param pathlib.Path new_path: The new path
:rtype: None
"""
# Make sure they want to change the data.
@ -552,7 +552,7 @@ class AdvancedTab(SettingsTab):
"""
Check if there's already data in the target directory.
:param openlp.core.common.path.Path data_path: The target directory to check
:param pathlib.Path data_path: The target directory to check
"""
if (data_path / 'songs').exists():
self.data_exists = True

View File

@ -28,6 +28,7 @@ import time
import urllib.error
import urllib.parse
import urllib.request
from pathlib import Path
from tempfile import gettempdir
from PyQt5 import QtCore, QtWidgets
@ -37,7 +38,7 @@ from openlp.core.common.applocation import AppLocation
from openlp.core.common.httputils import DownloadWorker, download_file, get_url_file_size, get_web_page
from openlp.core.common.i18n import translate
from openlp.core.common.mixins import RegistryProperties
from openlp.core.common.path import Path, create_paths
from openlp.core.common.path import create_paths
from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings
from openlp.core.lib import build_icon

View File

@ -23,12 +23,12 @@
The general tab of the configuration dialog.
"""
import logging
from pathlib import Path
from PyQt5 import QtGui, QtWidgets
from openlp.core.common import get_images_filter
from openlp.core.common.i18n import UiStrings, translate
from openlp.core.common.path import Path
from openlp.core.common.settings import Settings
from openlp.core.display.screens import ScreenList
from openlp.core.lib.settingstab import SettingsTab

View File

@ -23,9 +23,11 @@
This is the main window, where all the action happens.
"""
import os
import shutil
from datetime import datetime
from distutils import dir_util
from distutils.errors import DistutilsFileError
from pathlib import Path
from tempfile import gettempdir
from PyQt5 import QtCore, QtGui, QtWidgets
@ -38,7 +40,7 @@ from openlp.core.common.actions import ActionList, CategoryOrder
from openlp.core.common.applocation import AppLocation
from openlp.core.common.i18n import LanguageManager, UiStrings, translate
from openlp.core.common.mixins import LogMixin, RegistryProperties
from openlp.core.common.path import Path, copyfile, create_paths
from openlp.core.common.path import create_paths
from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings
from openlp.core.display.screens import ScreenList
@ -658,7 +660,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
plugin.first_time()
self.application.process_events()
temp_path = Path(gettempdir(), 'openlp')
temp_path.rmtree(True)
shutil.rmtree(temp_path, True)
def on_first_time_wizard_clicked(self):
"""
@ -861,7 +863,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
temp_dir_path = Path(gettempdir(), 'openlp')
create_paths(temp_dir_path)
temp_config_path = temp_dir_path / import_file_path.name
copyfile(import_file_path, temp_config_path)
shutil.copyfile(import_file_path, temp_config_path)
settings = Settings()
import_settings = Settings(str(temp_config_path), Settings.IniFormat)
@ -1332,7 +1334,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
self.show_status_message(
translate('OpenLP.MainWindow', 'Copying OpenLP data to new data directory location - {path} '
'- Please wait for copy to finish').format(path=self.new_data_path))
dir_util.copy_tree(old_data_path, self.new_data_path)
dir_util.copy_tree(str(old_data_path), str(self.new_data_path))
self.log_info('Copy successful')
except (OSError, DistutilsFileError) as why:
self.application.set_normal_cursor()

View File

@ -44,7 +44,7 @@ from openlp.core.lib.ui import critical_error_message_box
from openlp.core.ui import DisplayControllerType
from openlp.core.ui.media import MediaState, ItemMediaInfo, MediaType, parse_optical_path
from openlp.core.ui.media.endpoint import media_endpoint
from openlp.core.ui.media.vlcplayer import VlcPlayer, get_vlc
from openlp.core.ui.media.vlcplayer import AUDIO_EXT, VIDEO_EXT, VlcPlayer, get_vlc
log = logging.getLogger(__name__)
@ -65,11 +65,6 @@ class MediaController(RegistryBase, LogMixin, RegistryProperties):
current_media_players is an array of player instances keyed on ControllerType.
"""
def __init__(self, parent=None):
"""
Constructor
"""
super(MediaController, self).__init__(parent)
def setup(self):
self.vlc_player = None
@ -95,28 +90,8 @@ class MediaController(RegistryBase, LogMixin, RegistryProperties):
Registry().register_function('songs_hide', self.media_hide)
Registry().register_function('songs_blank', self.media_blank)
Registry().register_function('songs_unblank', self.media_unblank)
Registry().register_function('mediaitem_suffixes', self._generate_extensions_lists)
register_endpoint(media_endpoint)
def _generate_extensions_lists(self):
"""
Set the active players and available media files
"""
suffix_list = []
self.audio_extensions_list = []
if self.vlc_player.is_active:
for item in self.vlc_player.audio_extensions_list:
if item not in self.audio_extensions_list:
self.audio_extensions_list.append(item)
suffix_list.append(item[2:])
self.video_extensions_list = []
if self.vlc_player.is_active:
for item in self.vlc_player.video_extensions_list:
if item not in self.video_extensions_list:
self.video_extensions_list.append(item)
suffix_list.append(item[2:])
self.service_manager.supported_suffixes(suffix_list)
def bootstrap_initialise(self):
"""
Check to see if we have any media Player's available.
@ -133,7 +108,6 @@ class MediaController(RegistryBase, LogMixin, RegistryProperties):
self.main_window.splash.hide()
State().missing_text('media_live', translate('OpenLP.SlideController',
'VLC or pymediainfo are missing, so you are unable to play any media'))
self._generate_extensions_lists()
return True
def bootstrap_post_set_up(self):
@ -383,7 +357,7 @@ class MediaController(RegistryBase, LogMixin, RegistryProperties):
if file.is_file:
suffix = '*%s' % file.suffix.lower()
file = str(file)
if suffix in self.vlc_player.video_extensions_list:
if suffix in VIDEO_EXT:
if not controller.media_info.is_background or controller.media_info.is_background and \
self.vlc_player.can_background:
self.resize(display, self.vlc_player)
@ -391,7 +365,7 @@ class MediaController(RegistryBase, LogMixin, RegistryProperties):
self.current_media_players[controller.controller_type] = self.vlc_player
controller.media_info.media_type = MediaType.Video
return True
if suffix in self.vlc_player.audio_extensions_list:
if suffix in AUDIO_EXT:
if self.vlc_player.load(display, file):
self.current_media_players[controller.controller_type] = self.vlc_player
controller.media_info.media_type = MediaType.Audio

View File

@ -38,13 +38,10 @@ class MediaPlayer(RegistryProperties):
self.parent = parent
self.name = name
self.available = self.check_available()
self.is_active = False
self.can_background = False
self.can_folder = False
self.state = {0: MediaState.Off, 1: MediaState.Off}
self.has_own_widget = False
self.audio_extensions_list = []
self.video_extensions_list = []
def check_available(self):
"""
@ -166,12 +163,6 @@ class MediaPlayer(RegistryProperties):
"""
return ''
def get_info(self):
"""
Returns Information about the player
"""
return ''
def get_live_state(self):
"""
Get the state of the live player

View File

@ -1,25 +0,0 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
##########################################################################
# 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/>. #
##########################################################################
"""
The :mod:`~openlp.core.ui.media.vendor` module contains any scripts or libraries
from 3rd party vendors which are required to make certain media modules work.
"""

File diff suppressed because it is too large Load Diff

View File

@ -33,7 +33,6 @@ import vlc
from PyQt5 import QtWidgets
from openlp.core.common import is_linux, is_macosx, is_win
from openlp.core.common.i18n import translate
from openlp.core.common.settings import Settings
from openlp.core.ui.media import MediaState, MediaType
from openlp.core.ui.media.mediaplayer import MediaPlayer
@ -42,20 +41,18 @@ from openlp.core.ui.media.mediaplayer import MediaPlayer
log = logging.getLogger(__name__)
# Audio and video extensions copied from 'include/vlc_interface.h' from vlc 2.2.0 source
AUDIO_EXT = ['*.3ga', '*.669', '*.a52', '*.aac', '*.ac3', '*.adt', '*.adts', '*.aif', '*.aifc', '*.aiff', '*.amr',
'*.aob', '*.ape', '*.awb', '*.caf', '*.dts', '*.flac', '*.it', '*.kar', '*.m4a', '*.m4b', '*.m4p', '*.m5p',
'*.mid', '*.mka', '*.mlp', '*.mod', '*.mpa', '*.mp1', '*.mp2', '*.mp3', '*.mpc', '*.mpga', '*.mus',
'*.oga', '*.ogg', '*.oma', '*.opus', '*.qcp', '*.ra', '*.rmi', '*.s3m', '*.sid', '*.spx', '*.thd', '*.tta',
'*.voc', '*.vqf', '*.w64', '*.wav', '*.wma', '*.wv', '*.xa', '*.xm']
AUDIO_EXT = ('3ga', '669', 'a52', 'aac', 'ac3', 'adt', 'adts', 'aif', 'aifc', 'aiff', 'amr', 'aob', 'ape', 'awb', 'caf',
'dts', 'flac', 'it', 'kar', 'm4a', 'm4b', 'm4p', 'm5p', 'mid', 'mka', 'mlp', 'mod', 'mpa', 'mp1', 'mp2',
'mp3', 'mpc', 'mpga', 'mus', 'oga', 'ogg', 'oma', 'opus', 'qcp', 'ra', 'rmi', 's3m', 'sid', 'spx', 'thd',
'tta', 'voc', 'vqf', 'w64', 'wav', 'wma', 'wv', 'xa', 'xm')
VIDEO_EXT = ['*.3g2', '*.3gp', '*.3gp2', '*.3gpp', '*.amv', '*.asf', '*.avi', '*.bik', '*.divx', '*.drc', '*.dv',
'*.f4v', '*.flv', '*.gvi', '*.gxf', '*.iso', '*.m1v', '*.m2v', '*.m2t', '*.m2ts', '*.m4v', '*.mkv',
'*.mov', '*.mp2', '*.mp2v', '*.mp4', '*.mp4v', '*.mpe', '*.mpeg', '*.mpeg1', '*.mpeg2', '*.mpeg4', '*.mpg',
'*.mpv2', '*.mts', '*.mtv', '*.mxf', '*.mxg', '*.nsv', '*.nuv', '*.ogg', '*.ogm', '*.ogv', '*.ogx', '*.ps',
'*.rec', '*.rm', '*.rmvb', '*.rpl', '*.thp', '*.tod', '*.ts', '*.tts', '*.txd', '*.vob', '*.vro', '*.webm',
'*.wm', '*.wmv', '*.wtv', '*.xesc',
VIDEO_EXT = ('3g2', '3gp', '3gp2', '3gpp', 'amv', 'asf', 'avi', 'bik', 'divx', 'drc', 'dv', 'f4v', 'flv', 'gvi', 'gxf',
'iso', 'm1v', 'm2v', 'm2t', 'm2ts', 'm4v', 'mkv', 'mov', 'mp2', 'mp2v', 'mp4', 'mp4v', 'mpe', 'mpeg',
'mpeg1', 'mpeg2', 'mpeg4', 'mpg', 'mpv2', 'mts', 'mtv', 'mxf', 'mxg', 'nsv', 'nuv', 'ogg', 'ogm', 'ogv',
'ogx', 'ps', 'rec', 'rm', 'rmvb', 'rpl', 'thp', 'tod', 'ts', 'tts', 'txd', 'vob', 'vro', 'webm', 'wm',
'wmv', 'wtv', 'xesc',
# These extensions was not in the official list, added manually.
'*.nut', '*.rv', '*.xvid']
'nut', 'rv', 'xvid')
def get_vlc():
@ -109,8 +106,6 @@ class VlcPlayer(MediaPlayer):
self.display_name = '&VLC'
self.parent = parent
self.can_folder = True
self.audio_extensions_list = AUDIO_EXT
self.video_extensions_list = VIDEO_EXT
def setup(self, output_display, live_display):
"""
@ -374,14 +369,3 @@ class VlcPlayer(MediaPlayer):
else:
controller.seek_slider.setSliderPosition(output_display.vlc_media_player.get_time())
controller.seek_slider.blockSignals(False)
def get_info(self):
"""
Return some information about this player
"""
return(translate('Media.player', 'VLC is an external player which '
'supports a number of different formats.') +
'<br/> <strong>' + translate('Media.player', 'Audio') +
'</strong><br/>' + str(AUDIO_EXT) + '<br/><strong>' +
translate('Media.player', 'Video') + '</strong><br/>' +
str(VIDEO_EXT) + '<br/>')

View File

@ -24,10 +24,12 @@ The service manager sets up, loads, saves and manages services.
"""
import html
import json
import shutil
import os
import zipfile
from contextlib import suppress
from datetime import datetime, timedelta
from pathlib import Path
from tempfile import NamedTemporaryFile
from PyQt5 import QtCore, QtGui, QtWidgets
@ -36,9 +38,8 @@ from openlp.core.common import ThemeLevel, delete_file
from openlp.core.common.actions import ActionList, CategoryOrder
from openlp.core.common.applocation import AppLocation
from openlp.core.common.i18n import UiStrings, format_time, translate
from openlp.core.common.json import OpenLPJsonDecoder, OpenLPJsonEncoder
from openlp.core.common.json import OpenLPJSONDecoder, OpenLPJSONEncoder
from openlp.core.common.mixins import LogMixin, RegistryProperties
from openlp.core.common.path import Path
from openlp.core.common.registry import Registry, RegistryBase
from openlp.core.common.settings import Settings
from openlp.core.lib import build_icon
@ -47,6 +48,7 @@ from openlp.core.lib.plugin import PluginStatus
from openlp.core.lib.serviceitem import ItemCapabilities, ServiceItem
from openlp.core.lib.ui import create_widget_action, critical_error_message_box, find_and_set_in_combo_box
from openlp.core.ui.icons import UiIcons
from openlp.core.ui.media.vlcplayer import AUDIO_EXT, VIDEO_EXT
from openlp.core.ui.serviceitemeditform import ServiceItemEditForm
from openlp.core.ui.servicenoteform import ServiceNoteForm
from openlp.core.ui.starttimeform import StartTimeForm
@ -319,7 +321,8 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
"""
super().__init__(parent)
self.service_items = []
self.suffixes = []
self.suffixes = set()
self.add_media_suffixes()
self.drop_position = -1
self.service_id = 0
# is a new service and has not been saved
@ -346,6 +349,13 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
self.service_item_edit_form = ServiceItemEditForm()
self.start_time_form = StartTimeForm()
def add_media_suffixes(self):
"""
Add the suffixes supported by :mod:`openlp.core.ui.media.vlcplayer`
"""
self.suffixes.update(AUDIO_EXT)
self.suffixes.update(VIDEO_EXT)
def set_modified(self, modified=True):
"""
Setter for property "modified". Sets whether or not the current service has been modified.
@ -371,7 +381,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
"""
Setter for service file.
:param openlp.core.common.path.Path file_path: The service file name
:param Path file_path: The service file name
:rtype: None
"""
self._service_path = file_path
@ -386,7 +396,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
"""
Return the current file name including path.
:rtype: openlp.core.common.path.Path
:rtype: Path
"""
return self._service_path
@ -400,22 +410,19 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
def reset_supported_suffixes(self):
"""
Resets the Suffixes list.
"""
self.suffixes = []
self.suffixes.clear()
def supported_suffixes(self, suffix_list):
"""
Adds Suffixes supported to the master list. Called from Plugins.
:param suffix_list: New Suffix's to be supported
:param list[str] | str suffix_list: New suffix(s) to be supported
"""
if isinstance(suffix_list, str):
self.suffixes.append(suffix_list)
self.suffixes.add(suffix_list)
else:
for suffix in suffix_list:
if suffix not in self.suffixes:
self.suffixes.append(suffix)
self.suffixes.update(suffix_list)
def on_new_service_clicked(self):
"""
@ -443,7 +450,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
"""
Loads the service file and saves the existing one it there is one unchanged.
:param openlp.core.common.path.Path | None file_path: The service file to the loaded.
:param Path | None file_path: The service file to the loaded.
"""
if self.is_modified():
result = self.save_modified_service()
@ -474,9 +481,11 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
QtWidgets.QMessageBox.Save | QtWidgets.QMessageBox.Discard |
QtWidgets.QMessageBox.Cancel, QtWidgets.QMessageBox.Save)
def on_recent_service_clicked(self):
def on_recent_service_clicked(self, checked):
"""
Load a recent file as the service triggered by mainwindow recent service list.
:param bool checked: Not used
"""
if self.is_modified():
result = self.save_modified_service()
@ -518,7 +527,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
Get a list of files used in the service and files that are missing.
:return: A list of files used in the service that exist, and a list of files that don't.
:rtype: (list[openlp.core.common.path.Path], list[openlp.core.common.path.Path])
:rtype: (list[Path], list[Path])
"""
write_list = []
missing_list = []
@ -581,7 +590,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
# Add the service item to the service.
service.append({'serviceitem': service_item})
self.repaint_service_list(-1, -1)
service_content = json.dumps(service, cls=OpenLPJsonEncoder)
service_content = json.dumps(service, cls=OpenLPJSONEncoder)
service_content_size = len(bytes(service_content, encoding='utf-8'))
total_size = service_content_size
for file_item in write_list:
@ -679,7 +688,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
"""
Load an existing service file.
:param openlp.core.common.path.Path file_path: The service file to load.
:param Path file_path: The service file to load.
"""
if not file_path.exists():
return False
@ -702,7 +711,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
zip_file.extract(zip_info, self.service_path)
self.main_window.increment_progress_bar(zip_info.compress_size)
if service_data:
items = json.loads(service_data, cls=OpenLPJsonDecoder)
items = json.loads(service_data, cls=OpenLPJSONDecoder)
self.new_file()
self.process_service_items(items)
self.set_file_name(file_path)
@ -1250,7 +1259,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
delete_file(file_path)
audio_path = self.service_path / 'audio'
if audio_path.exists():
audio_path.rmtree(True)
shutil.rmtree(audio_path, True)
def on_theme_combo_box_selected(self, current_index):
"""

View File

@ -25,6 +25,7 @@ The :mod:`slidecontroller` module contains the most important part of OpenLP - t
import copy
import datetime
from collections import deque
from pathlib import Path
from threading import Lock
from PyQt5 import QtCore, QtGui, QtWidgets
@ -33,7 +34,6 @@ from openlp.core.common import SlideLimits
from openlp.core.common.actions import ActionList, CategoryOrder
from openlp.core.common.i18n import UiStrings, translate
from openlp.core.common.mixins import LogMixin, RegistryProperties
from openlp.core.common.path import Path
from openlp.core.common.registry import Registry, RegistryBase
from openlp.core.common.settings import Settings
from openlp.core.display.screens import ScreenList

View File

@ -32,7 +32,6 @@ from openlp.core.common.mixins import RegistryProperties
from openlp.core.common.registry import Registry
from openlp.core.lib.theme import BackgroundGradientType, BackgroundType
from openlp.core.lib.ui import critical_error_message_box
# TODO: Fix this. Use a "get_video_extensions" method which uses the current media player
from openlp.core.ui.media.vlcplayer import VIDEO_EXT
from openlp.core.ui.themelayoutform import ThemeLayoutForm
from openlp.core.ui.themewizard import Ui_ThemeWizard
@ -76,9 +75,8 @@ class ThemeForm(QtWidgets.QWizard, Ui_ThemeWizard, RegistryProperties):
self.image_path_edit.filters = \
'{name};;{text} (*)'.format(name=get_images_filter(), text=UiStrings().AllFiles)
self.image_path_edit.pathChanged.connect(self.on_image_path_edit_path_changed)
# TODO: Should work
visible_formats = '({name})'.format(name='; '.join(VIDEO_EXT))
actual_formats = '({name})'.format(name=' '.join(VIDEO_EXT))
visible_formats = '(*.{name})'.format(name='; *.'.join(VIDEO_EXT))
actual_formats = '(*.{name})'.format(name=' *.'.join(VIDEO_EXT))
video_filter = '{trans} {visible} {actual}'.format(trans=translate('OpenLP', 'Video Files'),
visible=visible_formats, actual=actual_formats)
self.video_path_edit.filters = '{video};;{ui} (*)'.format(video=video_filter, ui=UiStrings().AllFiles)
@ -462,7 +460,7 @@ class ThemeForm(QtWidgets.QWizard, Ui_ThemeWizard, RegistryProperties):
"""
Handle the `pathEditChanged` signal from image_path_edit
:param openlp.core.common.path.Path new_path: Path to the new image
:param pathlib.Path new_path: Path to the new image
:rtype: None
"""
self.theme.background_filename = new_path
@ -472,7 +470,7 @@ class ThemeForm(QtWidgets.QWizard, Ui_ThemeWizard, RegistryProperties):
"""
Handle the `pathEditChanged` signal from video_path_edit
:param openlp.core.common.path.Path new_path: Path to the new video
:param pathlib.Path new_path: Path to the new video
:rtype: None
"""
self.theme.background_filename = new_path

View File

@ -23,7 +23,9 @@
The Theme Manager manages adding, deleteing and modifying of themes.
"""
import os
import shutil
import zipfile
from pathlib import Path
from xml.etree.ElementTree import XML, ElementTree
from PyQt5 import QtCore, QtWidgets
@ -32,7 +34,7 @@ from openlp.core.common import delete_file
from openlp.core.common.applocation import AppLocation
from openlp.core.common.i18n import UiStrings, get_locale_key, translate
from openlp.core.common.mixins import LogMixin, RegistryProperties
from openlp.core.common.path import Path, copyfile, create_paths
from openlp.core.common.path import create_paths
from openlp.core.common.registry import Registry, RegistryBase
from openlp.core.common.settings import Settings
from openlp.core.lib import build_icon, check_item_selected, create_thumb, get_text_file_string, validate_thumb
@ -378,7 +380,7 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
delete_file(self.theme_path / thumb)
delete_file(self.thumb_path / thumb)
try:
(self.theme_path / theme).rmtree()
shutil.rmtree(self.theme_path / theme)
except OSError:
self.log_exception('Error deleting theme {name}'.format(name=theme))
@ -415,7 +417,7 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
"""
Create the zipfile with the theme contents.
:param openlp.core.common.path.Path theme_path: Location where the zip file will be placed
:param Path theme_path: Location where the zip file will be placed
:param str theme_name: The name of the theme to be exported
:return: The success of creating the zip file
:rtype: bool
@ -433,7 +435,7 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
'The {theme_name} export failed because this error occurred: {err}')
.format(theme_name=theme_name, err=ose.strerror))
if theme_path.exists():
theme_path.rmtree(ignore_errors=True)
shutil.rmtree(theme_path, ignore_errors=True)
return False
def on_import_theme(self, checked=None):
@ -557,8 +559,8 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
"""
Unzip the theme, remove the preview file if stored. Generate a new preview file. Check the XML theme version
and upgrade if necessary.
:param openlp.core.common.path.Path file_path:
:param openlp.core.common.path.Path directory_path:
:param Path file_path:
:param Path directory_path:
"""
self.log_debug('Unzipping theme {name}'.format(name=file_path))
file_xml = None
@ -642,8 +644,8 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
Called by theme maintenance Dialog to save the theme and to trigger the reload of the theme list
:param Theme theme: The theme data object.
:param openlp.core.common.path.Path image_source_path: Where the theme image is currently located.
:param openlp.core.common.path.Path image_destination_path: Where the Theme Image is to be saved to
:param Path image_source_path: Where the theme image is currently located.
:param Path image_destination_path: Where the Theme Image is to be saved to
:rtype: None
"""
self._write_theme(theme, image_source_path, image_destination_path)
@ -653,8 +655,8 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
Writes the theme to the disk and handles the background image if necessary
:param Theme theme: The theme data object.
:param openlp.core.common.path.Path image_source_path: Where the theme image is currently located.
:param openlp.core.common.path.Path image_destination_path: Where the Theme Image is to be saved to
:param Path image_source_path: Where the theme image is currently located.
:param Path image_destination_path: Where the Theme Image is to be saved to
:rtype: None
"""
name = theme.theme_name
@ -671,7 +673,7 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
delete_file(self.old_background_image_path)
if image_source_path != image_destination_path:
try:
copyfile(image_source_path, image_destination_path)
shutil.copyfile(image_source_path, image_destination_path)
except OSError:
self.log_exception('Failed to save theme image')
self.generate_and_save_image(name, theme)
@ -718,7 +720,7 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
Return a theme object using information parsed from XML
:param theme_xml: The Theme data object.
:param openlp.core.common.path.Path image_path: Where the theme image is stored
:param Path image_path: Where the theme image is stored
:return: Theme data.
:rtype: Theme
"""
@ -732,7 +734,7 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
Return a theme object using information parsed from JSON
:param theme_json: The Theme data object.
:param openlp.core.common.path.Path image_path: Where the theme image is stored
:param Path image_path: Where the theme image is stored
:return: Theme data.
:rtype: Theme
"""

View File

@ -33,9 +33,9 @@ class FileDialog(QtWidgets.QFileDialog):
:type parent: QtWidgets.QWidget | None
:type caption: str
:type directory: openlp.core.common.path.Path
:type directory: pathlib.Path
:type options: QtWidgets.QFileDialog.Options
:rtype: openlp.core.common.path.Path
:rtype: pathlib.Path
"""
args, kwargs = replace_params(args, kwargs, ((2, 'directory', path_to_str),))
@ -52,11 +52,11 @@ class FileDialog(QtWidgets.QFileDialog):
:type parent: QtWidgets.QWidget | None
:type caption: str
:type directory: openlp.core.common.path.Path
:type directory: pathlib.Path
:type filter: str
:type initialFilter: str
:type options: QtWidgets.QFileDialog.Options
:rtype: tuple[openlp.core.common.path.Path, str]
:rtype: tuple[pathlib.Path, str]
"""
args, kwargs = replace_params(args, kwargs, ((2, 'directory', path_to_str),))
@ -73,11 +73,11 @@ class FileDialog(QtWidgets.QFileDialog):
:type parent: QtWidgets.QWidget | None
:type caption: str
:type directory: openlp.core.common.path.Path
:type directory: pathlib.Path
:type filter: str
:type initialFilter: str
:type options: QtWidgets.QFileDialog.Options
:rtype: tuple[list[openlp.core.common.path.Path], str]
:rtype: tuple[list[pathlib.Path], str]
"""
args, kwargs = replace_params(args, kwargs, ((2, 'directory', path_to_str),))
@ -95,11 +95,11 @@ class FileDialog(QtWidgets.QFileDialog):
:type parent: QtWidgets.QWidget | None
:type caption: str
:type directory: openlp.core.common.path.Path
:type directory: pathlib.Path
:type filter: str
:type initialFilter: str
:type options: QtWidgets.QFileDialog.Options
:rtype: tuple[openlp.core.common.path.Path | None, str]
:rtype: tuple[pathlib.Path | None, str]
"""
args, kwargs = replace_params(args, kwargs, ((2, 'directory', path_to_str),))

View File

@ -24,12 +24,13 @@ The :mod:`~openlp.core.widgets.edits` module contains all the customised edit wi
"""
import logging
import re
from pathlib import Path
from PyQt5 import QtCore, QtGui, QtWidgets
from openlp.core.common import CONTROL_CHARS
from openlp.core.common.i18n import UiStrings, translate
from openlp.core.common.path import Path, path_to_str, str_to_path
from openlp.core.common.path import path_to_str, str_to_path
from openlp.core.common.settings import Settings
from openlp.core.lib.formattingtags import FormattingTags
from openlp.core.lib.ui import create_action, create_widget_action
@ -207,7 +208,7 @@ class PathEdit(QtWidgets.QWidget):
:param QtWidget.QWidget | None: The parent of the widget. This is just passed to the super method.
:param str dialog_caption: Used to customise the caption in the QFileDialog.
:param openlp.core.common.path.Path default_path: The default path. This is set as the path when the revert
:param Path default_path: The default path. This is set as the path when the revert
button is clicked
:param bool show_revert: Used to determine if the 'revert button' should be visible.
:rtype: None
@ -250,7 +251,7 @@ class PathEdit(QtWidgets.QWidget):
A property getter method to return the selected path.
:return: The selected path
:rtype: openlp.core.common.path.Path
:rtype: Path
"""
return self._path
@ -259,7 +260,7 @@ class PathEdit(QtWidgets.QWidget):
"""
A Property setter method to set the selected path
:param openlp.core.common.path.Path path: The path to set the widget to
:param Path path: The path to set the widget to
:rtype: None
"""
self._path = path
@ -348,7 +349,7 @@ class PathEdit(QtWidgets.QWidget):
Emits the pathChanged Signal
:param openlp.core.common.path.Path path: The new path
:param Path path: The new path
:rtype: None
"""
if self._path != path:

View File

@ -23,12 +23,13 @@
The :mod:`listpreviewwidget` is a widget that lists the slides in the slide controller.
It is based on a QTableWidget but represents its contents in list form.
"""
from pathlib import Path
from PyQt5 import QtCore, QtGui, QtWidgets
from openlp.core.common import is_win
from openlp.core.common.i18n import UiStrings
from openlp.core.common.mixins import RegistryProperties
from openlp.core.common.path import Path
from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings
from openlp.core.lib.serviceitem import ItemCapabilities, ServiceItem
@ -41,7 +42,7 @@ def handle_mime_data_urls(mime_data):
:param QtCore.QMimeData mime_data: The mime data from the drag and drop opperation.
:return: A list of file paths that were dropped
:rtype: list[openlp.core.common.path.Path]
:rtype: list[Path]
"""
file_paths = []
for url in mime_data.urls():
@ -201,14 +202,14 @@ class ListPreviewWidget(QtWidgets.QTableWidget, RegistryProperties):
label.setScaledContents(True)
if self.service_item.is_command():
if self.service_item.is_capable(ItemCapabilities.HasThumbnails):
pixmap = QtGui.QPixmap(remove_url_prefix(slide['thumbnail']))
pixmap = QtGui.QPixmap(str(slide['thumbnail']))
else:
if isinstance(slide['image'], QtGui.QIcon):
pixmap = slide['image'].pixmap(QtCore.QSize(32, 32))
else:
pixmap = QtGui.QPixmap(remove_url_prefix(slide['image']))
pixmap = QtGui.QPixmap(str(slide['image']))
else:
pixmap = QtGui.QPixmap(remove_url_prefix(slide['path']))
pixmap = QtGui.QPixmap(str(slide['path']))
label.setPixmap(pixmap)
container = QtWidgets.QWidget()
layout = AspectRatioLayout(container, self.screen_ratio)

View File

@ -48,7 +48,7 @@ class BibleImport(BibleDB, LogMixin, RegistryProperties):
"""
Check if the supplied file is compressed
:param openlp.core.common.path.Path file_path: A path to the file to check
:param pathlib.Path file_path: A path to the file to check
"""
if is_zipfile(file_path):
critical_error_message_box(

View File

@ -24,6 +24,7 @@ import logging
import re
import sqlite3
import time
from pathlib import Path
import chardet
from PyQt5 import QtCore
@ -35,7 +36,6 @@ from sqlalchemy.orm.exc import UnmappedClassError
from openlp.core.common import clean_filename
from openlp.core.common.applocation import AppLocation
from openlp.core.common.i18n import translate
from openlp.core.common.path import Path
from openlp.core.lib.db import BaseModel, Manager, init_db
from openlp.core.lib.ui import critical_error_message_box
from openlp.plugins.bibles.lib import BibleStrings, LanguageSelection, upgrade
@ -130,13 +130,13 @@ class BibleDB(Manager):
:param parent:
:param kwargs:
``path``
The path to the bible database file. Type: openlp.core.common.path.Path
The path to the bible database file. Type: Path
``name``
The name of the database. This is also used as the file name for SQLite databases.
``file``
Type: openlp.core.common.path.Path
Type: Path
:rtype: None
"""

View File

@ -96,7 +96,7 @@ class CSVBible(BibleImport):
"""
Parse the supplied CSV file.
:param openlp.core.common.path.Path file_path: The name of the file to parse.
:param pathlib.Path file_path: The name of the file to parse.
:param namedtuple results_tuple: The namedtuple to use to store the results.
:return: An list of namedtuples of type results_tuple
:rtype: list[namedtuple]

View File

@ -21,12 +21,12 @@
##########################################################################
import logging
import re
from pathlib import Path
from tempfile import TemporaryDirectory
from zipfile import ZipFile
from bs4 import BeautifulSoup, NavigableString, Tag
from openlp.core.common.path import Path
from openlp.plugins.bibles.lib.bibleimport import BibleImport

View File

@ -20,12 +20,12 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
##########################################################################
import logging
from pathlib import Path
from openlp.core.common import delete_file
from openlp.core.common.applocation import AppLocation
from openlp.core.common.i18n import UiStrings, translate
from openlp.core.common.mixins import LogMixin, RegistryProperties
from openlp.core.common.path import Path
from openlp.core.common.settings import Settings
from openlp.plugins.bibles.lib import LanguageSelection, parse_reference
from openlp.plugins.bibles.lib.db import BibleDB, BibleMeta

View File

@ -21,13 +21,14 @@
##########################################################################
import logging
from pathlib import Path
from PyQt5 import QtCore, QtGui, QtWidgets
from openlp.core.common import delete_file, get_images_filter
from openlp.core.common.applocation import AppLocation
from openlp.core.common.i18n import UiStrings, get_natural_key, translate
from openlp.core.common.path import Path, create_paths
from openlp.core.common.path import create_paths
from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings
from openlp.core.lib import ServiceItemContext, build_icon, check_item_selected, create_thumb, validate_thumb
@ -343,7 +344,7 @@ class ImageMediaItem(MediaManagerItem):
:param openlp.plugins.images.lib.db.ImageFilenames image: The image to generate the thumbnail path for.
:return: A path to the thumbnail
:rtype: openlp.core.common.path.Path
:rtype: Path
"""
ext = image.file_path.suffix.lower()
return self.service_path / '{name:d}{ext}'.format(name=image.id, ext=ext)
@ -401,7 +402,7 @@ class ImageMediaItem(MediaManagerItem):
Process a list for files either from the File Dialog or from Drag and Drop.
This method is overloaded from MediaManagerItem.
:param list[openlp.core.common.path.Path] file_paths: A List of paths to be loaded
:param list[Path] file_paths: A List of paths to be loaded
:param target_group: The QTreeWidgetItem of the group that will be the parent of the added files
"""
self.application.set_normal_cursor()
@ -413,7 +414,7 @@ class ImageMediaItem(MediaManagerItem):
"""
Add new images to the database. This method is called when adding images using the Add button or DnD.
:param list[openlp.core.common.Path] image_paths: A list of file paths to the images to be loaded
:param list[Path] image_paths: A list of file paths to the images to be loaded
:param target_group: The QTreeWidgetItem of the group that will be the parent of the added files
:param initial_load: When set to False, the busy cursor and progressbar will be shown while loading images
"""
@ -610,7 +611,7 @@ class ImageMediaItem(MediaManagerItem):
for image in images:
name = image.file_path.name
thumbnail_path = self.generate_thumbnail_path(image)
service_item.add_from_image(str(image.file_path), name, background, str(thumbnail_path))
service_item.add_from_image(image.file_path, name, background, str(thumbnail_path))
return True
def check_group_exists(self, new_group):

View File

@ -24,13 +24,13 @@ The :mod:`upgrade` module provides the migration path for the OLP Paths database
"""
import json
import logging
from pathlib import Path
from sqlalchemy import Column, Table
from openlp.core.common.applocation import AppLocation
from openlp.core.common.db import drop_columns
from openlp.core.common.json import OpenLPJsonEncoder
from openlp.core.common.path import Path
from openlp.core.common.json import OpenLPJSONEncoder
from openlp.core.lib.db import PathType, get_upgrade_op
@ -58,7 +58,7 @@ def upgrade_2(session, metadata):
results = conn.execute('SELECT * FROM image_filenames')
data_path = AppLocation.get_data_path()
for row in results.fetchall():
file_path_json = json.dumps(Path(row.filename), cls=OpenLPJsonEncoder, base_path=data_path)
file_path_json = json.dumps(Path(row.filename), cls=OpenLPJSONEncoder, base_path=data_path)
sql = 'UPDATE image_filenames SET file_path = \'{file_path_json}\' WHERE id = {id}'.format(
file_path_json=file_path_json, id=row.id)
conn.execute(sql)

View File

@ -23,6 +23,7 @@ import logging
import os
import re
from datetime import datetime
from pathlib import Path
from time import sleep
from PyQt5 import QtCore, QtWidgets
@ -30,7 +31,6 @@ from PyQt5 import QtCore, QtWidgets
from openlp.core.common import is_linux, is_macosx, is_win
from openlp.core.common.i18n import translate
from openlp.core.common.mixins import RegistryProperties
from openlp.core.common.path import Path
from openlp.core.lib.ui import critical_error_message_box
from openlp.core.ui.icons import UiIcons
from openlp.core.ui.media.vlcplayer import get_vlc

View File

@ -38,7 +38,7 @@ from openlp.core.lib.serviceitem import ItemCapabilities
from openlp.core.lib.ui import critical_error_message_box
from openlp.core.ui.icons import UiIcons
from openlp.core.ui.media import parse_optical_path, format_milliseconds
from openlp.core.ui.media.vlcplayer import get_vlc
from openlp.core.ui.media.vlcplayer import AUDIO_EXT, VIDEO_EXT, get_vlc
if get_vlc() is not None:
@ -232,9 +232,9 @@ class MediaMediaItem(MediaManagerItem, RegistryProperties):
"""
# self.populate_display_types()
self.on_new_file_masks = translate('MediaPlugin.MediaItem',
'Videos ({video});;Audio ({audio});;{files} '
'(*)').format(video=' '.join(self.media_controller.video_extensions_list),
audio=' '.join(self.media_controller.audio_extensions_list),
'Videos (*.{video});;Audio (*.{audio});;{files} '
'(*)').format(video=' *.'.join(VIDEO_EXT),
audio=' *.'.join(AUDIO_EXT),
files=UiStrings().AllFiles)
def on_delete_click(self):
@ -301,9 +301,9 @@ class MediaMediaItem(MediaManagerItem, RegistryProperties):
media_file_paths = Settings().value(self.settings_section + '/media files')
media_file_paths.sort(key=lambda file_path: get_natural_key(file_path.name))
if media_type == MediaType.Audio:
extension = self.media_controller.audio_extensions_list
extension = AUDIO_EXT
else:
extension = self.media_controller.video_extensions_list
extension = VIDEO_EXT
extension = [x[1:] for x in extension]
media = [x for x in media_file_paths if x.suffix in extension]
return media

View File

@ -205,7 +205,7 @@ class ImpressDocument(PresentationDocument):
"""
Constructor, store information about the file and initialise.
:param openlp.core.common.path.Path document_path: File path for the document to load
:param pathlib.Path document_path: File path for the document to load
:rtype: None
"""
log.debug('Init Presentation OpenOffice')

View File

@ -156,7 +156,7 @@ class PresentationMediaItem(MediaManagerItem):
Add presentations into the media manager. This is called both on initial load of the plugin to populate with
existing files, and when the user adds new files via the media manager.
:param list[openlp.core.common.path.Path] file_paths: List of file paths to add to the media manager.
:param list[pathlib.Path] file_paths: List of file paths to add to the media manager.
"""
current_paths = self.get_file_list()
titles = [file_path.name for file_path in current_paths]
@ -241,7 +241,7 @@ class PresentationMediaItem(MediaManagerItem):
"""
Clean up the files created such as thumbnails
:param openlp.core.common.path.Path file_path: File path of the presentation to clean up after
:param pathlib.Path file_path: File path of the presentation to clean up after
:param bool clean_for_update: Only clean thumbnails if update is needed
:rtype: None
"""
@ -385,7 +385,7 @@ class PresentationMediaItem(MediaManagerItem):
set as the preferred controller. Find the first (alphabetic) enabled controller which "supports" the extension.
If none found, then look for a controller which "also supports" it instead.
:param openlp.core.common.path.Path file_path: The file path
:param pathlib.Path file_path: The file path
:return: The default application controller for this file type, or None if not supported
:rtype: PresentationController
"""

View File

@ -21,10 +21,10 @@
##########################################################################
import copy
import logging
from pathlib import Path
from PyQt5 import QtCore
from openlp.core.common.path import Path
from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings
from openlp.core.lib import ServiceItemContext

View File

@ -21,11 +21,11 @@
##########################################################################
import logging
import re
from shutil import which
from subprocess import CalledProcessError, check_output
from openlp.core.common import check_binary_exists, is_win
from openlp.core.common.applocation import AppLocation
from openlp.core.common.path import which
from openlp.core.common.settings import Settings
from openlp.core.display.screens import ScreenList
from openlp.plugins.presentations.lib.presentationcontroller import PresentationController, PresentationDocument
@ -71,7 +71,7 @@ class PdfController(PresentationController):
Function that checks whether a binary is either ghostscript or mudraw or neither.
Is also used from presentationtab.py
:param openlp.core.common.path.Path program_path: The full path to the binary to check.
:param pathlib.Path program_path: The full path to the binary to check.
:return: Type of the binary, 'gs' if ghostscript, 'mudraw' if mudraw, None if invalid.
:rtype: str | None
"""
@ -182,7 +182,7 @@ class PdfDocument(PresentationDocument):
"""
Constructor, store information about the file and initialise.
:param openlp.core.common.path.Path document_path: Path to the document to load
:param pathlib.Path document_path: Path to the document to load
:rtype: None
"""
log.debug('Init Presentation Pdf')

View File

@ -124,7 +124,7 @@ class PowerpointDocument(PresentationDocument):
Constructor, store information about the file and initialise.
:param controller:
:param openlp.core.common.path.Path document_path: Path to the document to load
:param pathlib.Path document_path: Path to the document to load
:rtype: None
"""
log.debug('Init Presentation Powerpoint')

View File

@ -20,12 +20,14 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
##########################################################################
import logging
import shutil
from pathlib import Path
from PyQt5 import QtCore
from openlp.core.common import md5_hash
from openlp.core.common.applocation import AppLocation
from openlp.core.common.path import Path, create_paths
from openlp.core.common.path import create_paths
from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings
from openlp.core.lib import create_thumb, validate_thumb
@ -92,7 +94,7 @@ class PresentationDocument(object):
Constructor for the PresentationController class
:param controller:
:param openlp.core.common.path.Path document_path: Path to the document to load.
:param Path document_path: Path to the document to load.
:rtype: None
"""
self.controller = controller
@ -102,7 +104,7 @@ class PresentationDocument(object):
"""
Run some initial setup. This method is separate from __init__ in order to mock it out in tests.
:param openlp.core.common.path.Path document_path: Path to the document to load.
:param Path document_path: Path to the document to load.
:rtype: None
"""
self.slide_number = 0
@ -129,7 +131,7 @@ class PresentationDocument(object):
if thumbnail_folder_path.exists():
thumbnail_folder_path.rmtree()
if temp_folder_path.exists():
temp_folder_path.rmtree()
shutil.rmtree(temp_folder_path)
except OSError:
log.exception('Failed to delete presentation controller files')
@ -138,7 +140,7 @@ class PresentationDocument(object):
The location where thumbnail images will be stored
:return: The path to the thumbnail
:rtype: openlp.core.common.path.Path
:rtype: Path
"""
# TODO: Can be removed when the upgrade path to OpenLP 3.0 is no longer needed, also ensure code in
# get_temp_folder and PresentationPluginapp_startup is removed
@ -153,7 +155,7 @@ class PresentationDocument(object):
The location where thumbnail images will be stored
:return: The path to the temporary file folder
:rtype: openlp.core.common.path.Path
:rtype: Path
"""
# TODO: Can be removed when the upgrade path to OpenLP 3.0 is no longer needed, also ensure code in
# get_thumbnail_folder and PresentationPluginapp_startup is removed
@ -260,7 +262,7 @@ class PresentationDocument(object):
"""
Convert the slide image the application made to a scaled 360px height .png image.
:param openlp.core.common.path.Path image_path: Path to the image to create a thumb nail of
:param Path image_path: Path to the image to create a thumbnail of
:param int index: The index of the slide to create the thumbnail for.
:rtype: None
"""
@ -277,7 +279,7 @@ class PresentationDocument(object):
:param int slide_no: The slide an image is required for, starting at 1
:param bool check_exists: Check if the generated path exists
:return: The path, or None if the :param:`check_exists` is True and the file does not exist
:rtype: openlp.core.common.path.Path | None
:rtype: Path | None
"""
path = self.get_thumbnail_folder() / (self.controller.thumbnail_prefix + str(slide_no) + '.png')
if path.is_file() or not check_exists:
@ -475,7 +477,7 @@ class PresentationController(object):
"""
Called when a new presentation document is opened.
:param openlp.core.common.path.Path document_path: Path to the document to load
:param Path document_path: Path to the document to load
:return: The document
:rtype: PresentationDocument
"""

View File

@ -221,7 +221,7 @@ class PresentationTab(SettingsTab):
"""
Handle the `pathEditChanged` signal from program_path_edit
:param openlp.core.common.path.Path new_path: File path to the new program
:param pathlib.Path new_path: File path to the new program
:rtype: None
"""
if new_path:

View File

@ -25,13 +25,14 @@ used to edit songs.
"""
import logging
import re
from shutil import copyfile
from PyQt5 import QtCore, QtWidgets
from openlp.core.common.applocation import AppLocation
from openlp.core.common.i18n import UiStrings, get_natural_key, translate
from openlp.core.common.mixins import RegistryProperties
from openlp.core.common.path import copyfile, create_paths
from openlp.core.common.path import create_paths
from openlp.core.common.registry import Registry
from openlp.core.lib import MediaType, create_separated_list
from openlp.core.lib.plugin import PluginStatus

View File

@ -43,7 +43,7 @@ class MediaFilesForm(QtWidgets.QDialog, Ui_MediaFilesDialog):
def populate_files(self, file_paths):
"""
:param list[openlp.core.common.path.Path] file_paths:
:param list[pathlib.Path] file_paths:
:return:
"""
self.file_list_widget.clear()
@ -54,6 +54,6 @@ class MediaFilesForm(QtWidgets.QDialog, Ui_MediaFilesDialog):
def get_selected_files(self):
"""
:rtype: list[openlp.core.common.path.Path]
:rtype: list[pathlib.Path]
"""
return [item.data(QtCore.Qt.UserRole) for item in self.file_list_widget.selectedItems()]

View File

@ -28,9 +28,9 @@ import re
import sqlite3
import struct
import zlib
from pathlib import Path
from openlp.core.common.i18n import translate
from openlp.core.common.path import Path
from openlp.plugins.songs.lib import VerseType, retrieve_windows_encoding, strip_rtf
from .songimport import SongImport

View File

@ -24,9 +24,9 @@ The :mod:`powersong` module provides the functionality for importing
PowerSong songs into the OpenLP database.
"""
import logging
from pathlib import Path
from openlp.core.common.i18n import translate
from openlp.core.common.path import Path
from openlp.plugins.songs.lib.importers.songimport import SongImport
@ -73,7 +73,7 @@ class PowerSongImport(SongImport):
* is a directory
* contains at least one * .song file
:param openlp.core.common.path.Path import_source: Should be a Path object that fulfills the above criteria
:param Path import_source: Should be a Path object that fulfills the above criteria
:return: If the source is valid
:rtype: bool
"""

View File

@ -78,7 +78,7 @@ class PresentationManagerImport(SongImport):
def process_song(self, root, file_path):
"""
:param root:
:param openlp.core.common.path.Path file_path: Path to the file to process
:param pathlib.Path file_path: Path to the file to process
:rtype: None
"""
self.set_defaults()

View File

@ -55,7 +55,7 @@ class ProPresenterImport(SongImport):
def process_song(self, root, file_path):
"""
:param root:
:param openlp.core.common.path.Path file_path: Path to the file thats being imported
:param pathlib.Path file_path: Path to the file thats being imported
:rtype: None
"""
self.set_defaults()

View File

@ -27,9 +27,9 @@ import logging
import math
import os
import re
from pathlib import Path
from openlp.core.common import get_file_encoding, is_macosx, is_win
from openlp.core.common.path import Path
from openlp.core.common.settings import Settings
from openlp.plugins.songs.lib import VerseType
from openlp.plugins.songs.lib.importers.songimport import SongImport

View File

@ -22,13 +22,14 @@
import logging
import re
from shutil import copyfile
from PyQt5 import QtCore
from openlp.core.common import normalize_str
from openlp.core.common.applocation import AppLocation
from openlp.core.common.i18n import translate
from openlp.core.common.path import copyfile, create_paths
from openlp.core.common.path import create_paths
from openlp.core.common.registry import Registry
from openlp.core.widgets.wizard import WizardStrings
from openlp.plugins.songs.lib import VerseType, clean_song
@ -401,9 +402,9 @@ class SongImport(QtCore.QObject):
the new file location.
:param song_id:
:param openlp.core.common.path.Path file_path: The file to copy.
:param pathlib.Path file_path: The file to copy.
:return: The new location of the file
:rtype: openlp.core.common.path.Path
:rtype: pathlib.Path
"""
if not hasattr(self, 'save_path'):
self.save_path = AppLocation.get_section_data_path(self.import_wizard.plugin.name) / 'audio' / str(song_id)

View File

@ -24,8 +24,8 @@ The :mod:`songpro` module provides the functionality for importing SongPro
songs into the OpenLP database.
"""
import re
from pathlib import Path
from openlp.core.common.path import Path
from openlp.plugins.songs.lib import strip_rtf
from openlp.plugins.songs.lib.importers.songimport import SongImport

View File

@ -65,7 +65,7 @@ class SundayPlusImport(SongImport):
"""
Process the Sunday Plus song file
:param openlp.core.common.path.Path file_path: The song file to import
:param pathlib.Path file_path: The song file to import
:rtype: None
"""
with file_path.open('rb') as song_file:
@ -180,7 +180,7 @@ class SundayPlusImport(SongImport):
"""
Extract the title from the filename
:param openlp.core.common.path.Path file_path: File being imported
:param pathlib.Path file_path: File being imported
:return: The song title
:rtype: str
"""

View File

@ -25,9 +25,9 @@ exported from Lyrix."""
import json
import logging
import re
from pathlib import Path
from openlp.core.common.i18n import translate
from openlp.core.common.path import Path
from openlp.core.common.settings import Settings
from openlp.plugins.songs.lib.db import AuthorType
from openlp.plugins.songs.lib.importers.songimport import SongImport

View File

@ -20,8 +20,9 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
##########################################################################
import logging
import os
import mako
import os
from shutil import copyfile
from PyQt5 import QtCore, QtWidgets
from sqlalchemy.sql import and_, or_
@ -29,7 +30,7 @@ from sqlalchemy.sql import and_, or_
from openlp.core.state import State
from openlp.core.common.applocation import AppLocation
from openlp.core.common.i18n import UiStrings, get_natural_key, translate
from openlp.core.common.path import copyfile, create_paths
from openlp.core.common.path import create_paths
from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings
from openlp.core.lib import ServiceItemContext, check_item_selected, create_separated_list

View File

@ -45,7 +45,7 @@ class OpenLyricsExport(RegistryProperties):
"""
Initialise the export.
:param openlp.core.common.path.Path save_path: The directory to save the exported songs in
:param pathlib.Path save_path: The directory to save the exported songs in
:rtype: None
"""
log.debug('initialise OpenLyricsExport')

View File

@ -25,14 +25,14 @@ backend for the Songs plugin
"""
import json
import logging
from pathlib import Path
from sqlalchemy import Column, ForeignKey, Table, types
from sqlalchemy.sql.expression import false, func, null, text
from openlp.core.common.applocation import AppLocation
from openlp.core.common.db import drop_columns
from openlp.core.common.json import OpenLPJsonEncoder
from openlp.core.common.path import Path
from openlp.core.common.json import OpenLPJSONEncoder
from openlp.core.lib.db import PathType, get_upgrade_op
@ -182,7 +182,7 @@ def upgrade_7(session, metadata):
results = conn.execute('SELECT * FROM media_files')
data_path = AppLocation.get_data_path()
for row in results.fetchall():
file_path_json = json.dumps(Path(row.file_name), cls=OpenLPJsonEncoder, base_path=data_path)
file_path_json = json.dumps(Path(row.file_name), cls=OpenLPJSONEncoder, base_path=data_path)
sql = 'UPDATE media_files SET file_path = \'{file_path_json}\' WHERE id = {id}'.format(
file_path_json=file_path_json, id=row.id)
conn.execute(sql)

View File

@ -24,9 +24,9 @@ The :mod:`db` module provides the ability to provide a csv file of all songs
"""
import csv
import logging
from pathlib import Path
from openlp.core.common.i18n import translate
from openlp.core.common.path import Path
from openlp.core.common.registry import Registry
from openlp.core.lib.ui import critical_error_message_box
from openlp.core.widgets.dialogs import FileDialog

View File

@ -432,7 +432,7 @@ class SongsPlugin(Plugin):
"""
Provide a count of the songs in the database
:param openlp.core.common.path.Path db_path: The database to use
:param Path db_path: The database to use
:return: The number of songs in the db.
:rtype: int
"""

View File

@ -70,7 +70,7 @@ class SongUsageDetailForm(QtWidgets.QDialog, Ui_SongUsageDetailDialog, RegistryP
"""
Handle the `pathEditChanged` signal from report_path_edit
:param openlp.core.common.path.Path file_path: The new path.
:param pathlib.Path file_path: The new path.
:rtype: None
"""
Settings().setValue(self.plugin.settings_section + '/last directory export', file_path)

View File

@ -12,11 +12,13 @@ clone_script:
environment:
matrix:
- PYTHON: C:\\Python37-x64
CHOCO_VLC: vlc
- PYTHON: C:\\Python37
CHOCO_VLC: vlc --forcex86
install:
# Install dependencies from pypi
- "%PYTHON%\\python.exe -m pip install sqlalchemy alembic appdirs chardet beautifulsoup4 lxml Mako mysql-connector-python pytest mock pyodbc psycopg2 pypiwin32 websockets asyncio waitress six webob requests QtAwesome PyQt5 PyQtWebEngine pymediainfo PyMuPDF"
- "%PYTHON%\\python.exe -m pip install sqlalchemy alembic appdirs chardet beautifulsoup4 lxml Mako mysql-connector-python pytest mock pyodbc psycopg2 pypiwin32 websockets asyncio waitress six webob requests QtAwesome PyQt5 PyQtWebEngine pymediainfo PyMuPDF QDarkStyle python-vlc"
build: off
@ -31,12 +33,6 @@ after_test:
# This is where we create a package using PyInstaller
# Install PyInstaller
- "%PYTHON%\\python.exe -m pip install pyinstaller"
# Download and install Inno Setup - used for packaging
- appveyor DownloadFile http://www.jrsoftware.org/download.php/is-unicode.exe
- is-unicode.exe /VERYSILENT /SUPPRESSMSGBOXES /SP-
# Download and unpack portable-bundle
- appveyor DownloadFile https://get.openlp.org/win-sdk/portable-setup.7z
- 7z x portable-setup.7z
# Disabled portable installers - can't figure out how to make them silent
# - curl -L -O http://downloads.sourceforge.net/project/portableapps/PortableApps.com%20Installer/PortableApps.comInstaller_3.4.4.paf.exe
# - PortableApps.comInstaller_3.4.4.paf.exe /S
@ -44,6 +40,11 @@ after_test:
# - PortableApps.comLauncher_2.2.1.paf.exe /S
# - curl -L -O http://downloads.sourceforge.net/project/portableapps/NSIS%20Portable/NSISPortable_3.0_English.paf.exe
# - NSISPortable_3.0_English.paf.exe /S
# Download and unpack portable-bundle
- appveyor DownloadFile https://get.openlp.org/win-sdk/portable-setup.7z
- 7z x portable-setup.7z
# Install VLC
- choco install %CHOCO_VLC%
# Get the packaging code
- appveyor DownloadFile http://bazaar.launchpad.net/~openlp-core/openlp/packaging/tarball -FileName packaging.tar.gz
- 7z e packaging.tar.gz
@ -66,3 +67,6 @@ after_test:
artifacts:
- path: openlp-branch\dist\*.exe
name: Portable-installer
- path: openlp-branch\dist\*.msi
name: Installer

View File

@ -20,12 +20,13 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
##########################################################################
import os
import shutil
from pathlib import Path
from tempfile import mkdtemp
from unittest import TestCase
from unittest.mock import MagicMock, patch
from openlp.core.api.deploy import deploy_zipfile, download_and_check, download_sha256
from openlp.core.common.path import Path
CONFIG_FILE = '2c266badff1e3d140664c50fd1460a2b332b24d5ad8c267fa62e506b5eb6d894 deploy/site.zip\n2017_06_27'
@ -46,7 +47,7 @@ class TestRemoteDeploy(TestCase):
"""
Clean up after tests
"""
self.app_root_path.rmtree()
shutil.rmtree(self.app_root_path)
@patch('openlp.core.api.deploy.ZipFile')
def test_deploy_zipfile(self, MockZipFile):

View File

@ -23,11 +23,11 @@
Functional tests to test the AppLocation class and related methods.
"""
import os
from pathlib import Path
from unittest.mock import patch
from openlp.core.common import get_frozen_path
from openlp.core.common.applocation import AppLocation
from openlp.core.common.path import Path
FILE_LIST = ['file1', 'file2', 'file3.txt', 'file4.txt', 'file5.mp3', 'file6.mp3']

View File

@ -22,12 +22,12 @@
"""
Functional tests to test the AppLocation class and related methods.
"""
from pathlib import Path
from unittest import TestCase
from unittest.mock import MagicMock, call, patch
from openlp.core.common import clean_button_text, de_hump, extension_loader, is_linux, is_macosx, is_win, \
normalize_str, path_to_module, trace_error_handler
from openlp.core.common.path import Path
class TestCommonFunctions(TestCase):

View File

@ -24,12 +24,12 @@ Functional tests to test the AppLocation class and related methods.
"""
import os
import tempfile
from pathlib import Path
from unittest import TestCase
from unittest.mock import MagicMock, patch
from openlp.core.common.httputils import ProxyMode, download_file, get_proxy_settings, get_url_file_size, \
get_user_agent, get_web_page
from openlp.core.common.path import Path
from openlp.core.common.settings import Settings
from tests.helpers.testmixin import TestMixin

View File

@ -23,12 +23,12 @@
Functional tests to test the AppLocation class and related methods.
"""
from io import BytesIO
from pathlib import Path
from unittest import TestCase
from unittest.mock import MagicMock, PropertyMock, call, patch
from openlp.core.common import add_actions, clean_filename, delete_file, get_file_encoding, get_filesystem_encoding, \
get_uno_command, get_uno_instance
from openlp.core.common.path import Path
from tests.helpers.testmixin import TestMixin

View File

@ -23,14 +23,134 @@
Package to test the openlp.core.common.json package.
"""
import json
import os
from pathlib import Path
from unittest import TestCase
from unittest.mock import patch
from openlp.core.common.json import OpenLPJsonDecoder, OpenLPJsonEncoder
from openlp.core.common.path import Path
from openlp.core.common.json import JSONMixin, OpenLPJSONDecoder, OpenLPJSONEncoder, PathSerializer, _registered_classes
class TestOpenLPJsonDecoder(TestCase):
class TestClassBase(object):
"""
Simple class to avoid repetition
"""
def __init__(self, a=None, b=None, c=None):
self.a = a
self.b = b
self.c = c
class TestJSONMixin(TestCase):
"""
Test the JSONMixin class
"""
def setUp(self):
self._registered_classes_patcher = patch.dict(_registered_classes, clear=True)
self.addCleanup(self._registered_classes_patcher.stop)
self._registered_classes_patcher.start()
def test_subclass_json_mixin(self):
"""
Test that a class is `registered` when subclassing JSONMixin
"""
# GIVEN: The JSONMixin class
# WHEN: Subclassing it
class TestClass(JSONMixin):
pass
# THEN: The TestClass should have been `registered`
assert _registered_classes['TestClass'] == TestClass
def test_subclass_json_mixin_alt_names(self):
"""
Test that a class is `registered` using the specified names when subclassing JSONMixin
"""
# GIVEN: The JSONMixin class
# WHEN: Subclassing it with custom names
class TestClass(JSONMixin, register_names=('AltName1', 'AltName2')):
pass
# THEN: The TestClass should have been registered with only those names
assert 'TestClass' not in _registered_classes
assert _registered_classes['AltName1'] == TestClass
assert _registered_classes['AltName2'] == TestClass
def test_encoding_json_mixin_subclass(self):
"""
Test that an instance of a JSONMixin subclass is properly serialized to a JSON string
"""
# GIVEN: A instance of a subclass of the JSONMixin class
class TestClass(TestClassBase, JSONMixin):
_json_keys = ['a', 'b']
instance = TestClass(a=1, c=2)
# WHEN: Serializing the instance
json_string = json.dumps(instance, cls=OpenLPJSONEncoder)
# THEN: Only the attributes specified by `_json_keys` should be serialized, and only if they have been set
assert json_string == '{"a": 1, "json_meta": {"class": "TestClass", "version": 1}}'
def test_decoding_json_mixin_subclass(self):
"""
Test that an instance of a JSONMixin subclass is properly deserialized from a JSON string
"""
# GIVEN: A subclass of the JSONMixin class
class TestClass(TestClassBase, JSONMixin):
_json_keys = ['a', 'b']
# WHEN: Deserializing a JSON representation of the TestClass
instance = json.loads(
'{"a": 1, "c": 2, "json_meta": {"class": "TestClass", "version": 1}}', cls=OpenLPJSONDecoder)
# THEN: Only the attributes specified by `_json_keys` should have been set
assert instance.__class__ == TestClass
assert instance.a == 1
assert instance.b is None
assert instance.c is None
def test_encoding_json_mixin_subclass_custom_name(self):
"""
Test that an instance of a JSONMixin subclass is properly serialized to a JSON string when using a custom name
"""
# GIVEN: A instance of a subclass of the JSONMixin class with a custom name
class TestClass(TestClassBase, JSONMixin, register_names=('AltName', )):
_json_keys = ['a', 'b']
_name = 'AltName'
_version = 2
instance = TestClass(a=1, c=2)
# WHEN: Serializing the instance
json_string = json.dumps(instance, cls=OpenLPJSONEncoder)
# THEN: Only the attributes specified by `_json_keys` should be serialized, and only if they have been set
assert json_string == '{"a": 1, "json_meta": {"class": "AltName", "version": 2}}'
def test_decoding_json_mixin_subclass_custom_name(self):
"""
Test that an instance of a JSONMixin subclass is properly deserialized from a JSON string when using a custom
name
"""
# GIVEN: A instance of a subclass of the JSONMixin class with a custom name
class TestClass(TestClassBase, JSONMixin, register_names=('AltName', )):
_json_keys = ['a', 'b']
_name = 'AltName'
_version = 2
# WHEN: Deserializing a JSON representation of the TestClass
instance = json.loads(
'{"a": 1, "c": 2, "json_meta": {"class": "AltName", "version": 2}}', cls=OpenLPJSONDecoder)
# THEN: Only the attributes specified by `_json_keys` should have been set
assert instance.__class__ == TestClass
assert instance.a == 1
assert instance.b is None
assert instance.c is None
class TestOpenLPJSONDecoder(TestCase):
"""
Test the OpenLPJsonDecoder class
"""
@ -39,10 +159,10 @@ class TestOpenLPJsonDecoder(TestCase):
Test the object_hook method when called with a decoded Path JSON object
"""
# GIVEN: An instance of OpenLPJsonDecoder
instance = OpenLPJsonDecoder()
instance = OpenLPJSONDecoder()
# WHEN: Calling the object_hook method with a decoded JSON object which contains a Path
result = instance.object_hook({'__Path__': ['test', 'path']})
result = instance.object_hook({'parts': ['test', 'path'], "json_meta": {"class": "Path", "version": 1}})
# THEN: A Path object should be returned
assert result == Path('test', 'path')
@ -52,7 +172,7 @@ class TestOpenLPJsonDecoder(TestCase):
Test the object_hook method when called with a decoded JSON object
"""
# GIVEN: An instance of OpenLPJsonDecoder
instance = OpenLPJsonDecoder()
instance = OpenLPJSONDecoder()
# WHEN: Calling the object_hook method with a decoded JSON object which contains a Path
with patch('openlp.core.common.json.Path') as mocked_path:
@ -67,31 +187,32 @@ class TestOpenLPJsonDecoder(TestCase):
Test the OpenLPJsonDecoder when decoding a JSON string
"""
# GIVEN: A JSON encoded string
json_string = '[{"__Path__": ["test", "path1"]}, {"__Path__": ["test", "path2"]}]'
json_string = '[{"parts": ["test", "path1"], "json_meta": {"class": "Path", "version": 1}}, ' \
'{"parts": ["test", "path2"], "json_meta": {"class": "Path", "version": 1}}]'
# WHEN: Decoding the string using the OpenLPJsonDecoder class
obj = json.loads(json_string, cls=OpenLPJsonDecoder)
obj = json.loads(json_string, cls=OpenLPJSONDecoder)
# THEN: The object returned should be a python version of the JSON string
assert obj == [Path('test', 'path1'), Path('test', 'path2')]
class TestOpenLPJsonEncoder(TestCase):
class TestOpenLPJSONEncoder(TestCase):
"""
Test the OpenLPJsonEncoder class
Test the OpenLPJSONEncoder class
"""
def test_default_path_object(self):
"""
Test the default method when called with a Path object
"""
# GIVEN: An instance of OpenLPJsonEncoder
instance = OpenLPJsonEncoder()
# GIVEN: An instance of OpenLPJSONEncoder
instance = OpenLPJSONEncoder()
# WHEN: Calling the default method with a Path object
result = instance.default(Path('test', 'path'))
# THEN: A dictionary object that can be JSON encoded should be returned
assert result == {'__Path__': ('test', 'path')}
assert result == {'parts': ('test', 'path'), "json_meta": {"class": "Path", "version": 1}}
def test_default_non_path_object(self):
"""
@ -99,8 +220,8 @@ class TestOpenLPJsonEncoder(TestCase):
"""
with patch('openlp.core.common.json.JSONEncoder.default') as mocked_super_default:
# GIVEN: An instance of OpenLPJsonEncoder
instance = OpenLPJsonEncoder()
# GIVEN: An instance of OpenLPJSONEncoder
instance = OpenLPJSONEncoder()
# WHEN: Calling the default method with a object other than a Path object
instance.default('invalid object')
@ -115,8 +236,65 @@ class TestOpenLPJsonEncoder(TestCase):
# GIVEN: A list of Path objects
obj = [Path('test', 'path1'), Path('test', 'path2')]
# WHEN: Encoding the object using the OpenLPJsonEncoder class
json_string = json.dumps(obj, cls=OpenLPJsonEncoder)
# WHEN: Encoding the object using the OpenLPJSONEncoder class
json_string = json.dumps(obj, cls=OpenLPJSONEncoder)
# THEN: The JSON string return should be a representation of the object encoded
assert json_string == '[{"__Path__": ["test", "path1"]}, {"__Path__": ["test", "path2"]}]'
assert json_string == '[{"parts": ["test", "path1"], "json_meta": {"class": "Path", "version": 1}}, ' \
'{"parts": ["test", "path2"], "json_meta": {"class": "Path", "version": 1}}]'
class TestPathSerializer(TestCase):
def test_path_encode_json(self):
"""
Test that `Path.encode_json` returns a Path object from a dictionary representation of a Path object decoded
from JSON
"""
# GIVEN: A Path object from openlp.core.common.path
# WHEN: Calling encode_json, with a dictionary representation
path = PathSerializer.encode_json(
{'parts': ['path', 'to', 'fi.le'], "json_meta": {"class": "Path", "version": 1}}, extra=1, args=2)
# THEN: A Path object should have been returned
assert path == Path('path', 'to', 'fi.le')
def test_path_encode_json_base_path(self):
"""
Test that `Path.encode_json` returns a Path object from a dictionary representation of a Path object decoded
from JSON when the base_path arg is supplied.
"""
# GIVEN: A Path object from openlp.core.common.path
# WHEN: Calling encode_json, with a dictionary representation
path = PathSerializer.encode_json(
{'parts': ['path', 'to', 'fi.le'], "json_meta": {"class": "Path", "version": 1}}, base_path=Path('/base'))
# THEN: A Path object should have been returned with an absolute path
assert path == Path('/', 'base', 'path', 'to', 'fi.le')
def test_path_json_object(self):
"""
Test that `Path.json_object` creates a JSON decode-able object from a Path object
"""
# GIVEN: A Path object from openlp.core.common.path
path = Path('/base', 'path', 'to', 'fi.le')
# WHEN: Calling json_object
obj = PathSerializer().json_object(path, extra=1, args=2)
# THEN: A JSON decodeable object should have been returned.
assert obj == {'parts': (os.sep, 'base', 'path', 'to', 'fi.le'), "json_meta": {"class": "Path", "version": 1}}
def test_path_json_object_base_path(self):
"""
Test that `Path.json_object` creates a JSON decode-able object from a Path object, that is relative to the
base_path
"""
# GIVEN: A Path object from openlp.core.common.path
path = Path('/base', 'path', 'to', 'fi.le')
# WHEN: Calling json_object with a base_path
obj = PathSerializer().json_object(path, base_path=Path('/', 'base'))
# THEN: A JSON decodable object should have been returned.
assert obj == {'parts': ('path', 'to', 'fi.le'), "json_meta": {"class": "Path", "version": 1}}

View File

@ -23,11 +23,11 @@
Package to test the openlp.core.common.path package.
"""
import os
from pathlib import Path
from unittest import TestCase
from unittest.mock import ANY, MagicMock, patch
from unittest.mock import MagicMock, patch
from openlp.core.common.path import Path, copy, copyfile, copytree, create_paths, files_to_paths, path_to_str, \
replace_params, str_to_path, which
from openlp.core.common.path import create_paths, files_to_paths, path_to_str, replace_params, str_to_path, which
class TestShutil(TestCase):
@ -66,139 +66,6 @@ class TestShutil(TestCase):
assert result_args == (1, '2')
assert result_kwargs == {'arg3': '3', 'arg4': 4}
def test_copy(self):
"""
Test :func:`openlp.core.common.path.copy`
"""
# GIVEN: A mocked `shutil.copy` which returns a test path as a string
with patch('openlp.core.common.path.shutil.copy', return_value=os.path.join('destination', 'test', 'path')) \
as mocked_shutil_copy:
# WHEN: Calling :func:`openlp.core.common.path.copy` with the src and dst parameters as Path object types
result = copy(Path('source', 'test', 'path'), Path('destination', 'test', 'path'))
# THEN: :func:`shutil.copy` should have been called with the str equivalents of the Path objects.
# :func:`openlp.core.common.path.copy` should return the str type result of calling
# :func:`shutil.copy` as a Path object.
mocked_shutil_copy.assert_called_once_with(os.path.join('source', 'test', 'path'),
os.path.join('destination', 'test', 'path'))
assert result == Path('destination', 'test', 'path')
def test_copy_follow_optional_params(self):
"""
Test :func:`openlp.core.common.path.copy` when follow_symlinks is set to false
"""
# GIVEN: A mocked `shutil.copy`
with patch('openlp.core.common.path.shutil.copy', return_value='') as mocked_shutil_copy:
# WHEN: Calling :func:`openlp.core.common.path.copy` with :param:`follow_symlinks` set to False
copy(Path('source', 'test', 'path'), Path('destination', 'test', 'path'), follow_symlinks=False)
# THEN: :func:`shutil.copy` should have been called with :param:`follow_symlinks` set to false
mocked_shutil_copy.assert_called_once_with(ANY, ANY, follow_symlinks=False)
def test_copyfile(self):
"""
Test :func:`openlp.core.common.path.copyfile`
"""
# GIVEN: A mocked :func:`shutil.copyfile` which returns a test path as a string
with patch('openlp.core.common.path.shutil.copyfile',
return_value=os.path.join('destination', 'test', 'path')) as mocked_shutil_copyfile:
# WHEN: Calling :func:`openlp.core.common.path.copyfile` with the src and dst parameters as Path object
# types
result = copyfile(Path('source', 'test', 'path'), Path('destination', 'test', 'path'))
# THEN: :func:`shutil.copyfile` should have been called with the str equivalents of the Path objects.
# :func:`openlp.core.common.path.copyfile` should return the str type result of calling
# :func:`shutil.copyfile` as a Path object.
mocked_shutil_copyfile.assert_called_once_with(os.path.join('source', 'test', 'path'),
os.path.join('destination', 'test', 'path'))
assert result == Path('destination', 'test', 'path')
def test_copyfile_optional_params(self):
"""
Test :func:`openlp.core.common.path.copyfile` when follow_symlinks is set to false
"""
# GIVEN: A mocked :func:`shutil.copyfile`
with patch('openlp.core.common.path.shutil.copyfile', return_value='') as mocked_shutil_copyfile:
# WHEN: Calling :func:`openlp.core.common.path.copyfile` with :param:`follow_symlinks` set to False
copyfile(Path('source', 'test', 'path'), Path('destination', 'test', 'path'), follow_symlinks=False)
# THEN: :func:`shutil.copyfile` should have been called with the optional parameters, with out any of the
# values being modified
mocked_shutil_copyfile.assert_called_once_with(ANY, ANY, follow_symlinks=False)
def test_copytree(self):
"""
Test :func:`openlp.core.common.path.copytree`
"""
# GIVEN: A mocked :func:`shutil.copytree` which returns a test path as a string
with patch('openlp.core.common.path.shutil.copytree',
return_value=os.path.join('destination', 'test', 'path')) as mocked_shutil_copytree:
# WHEN: Calling :func:`openlp.core.common.path.copytree` with the src and dst parameters as Path object
# types
result = copytree(Path('source', 'test', 'path'), Path('destination', 'test', 'path'))
# THEN: :func:`shutil.copytree` should have been called with the str equivalents of the Path objects.
# :func:`openlp.core.common.path.copytree` should return the str type result of calling
# :func:`shutil.copytree` as a Path object.
mocked_shutil_copytree.assert_called_once_with(os.path.join('source', 'test', 'path'),
os.path.join('destination', 'test', 'path'))
assert result == Path('destination', 'test', 'path')
def test_copytree_optional_params(self):
"""
Test :func:`openlp.core.common.path.copytree` when optional parameters are passed
"""
# GIVEN: A mocked :func:`shutil.copytree`
with patch('openlp.core.common.path.shutil.copytree', return_value='') as mocked_shutil_copytree:
mocked_ignore = MagicMock()
mocked_copy_function = MagicMock()
# WHEN: Calling :func:`openlp.core.common.path.copytree` with the optional parameters set
copytree(Path('source', 'test', 'path'), Path('destination', 'test', 'path'), symlinks=True,
ignore=mocked_ignore, copy_function=mocked_copy_function, ignore_dangling_symlinks=True)
# THEN: :func:`shutil.copytree` should have been called with the optional parameters, with out any of the
# values being modified
mocked_shutil_copytree.assert_called_once_with(ANY, ANY, symlinks=True, ignore=mocked_ignore,
copy_function=mocked_copy_function,
ignore_dangling_symlinks=True)
def test_rmtree(self):
"""
Test :func:`rmtree`
"""
# GIVEN: A mocked :func:`shutil.rmtree` and a test Path object
with patch('openlp.core.common.path.shutil.rmtree', return_value=None) as mocked_shutil_rmtree:
path = Path('test', 'path')
# WHEN: Calling :func:`openlp.core.common.path.rmtree` with the path parameter as Path object type
path.rmtree()
# THEN: :func:`shutil.rmtree` should have been called with the the Path object.
mocked_shutil_rmtree.assert_called_once_with(Path('test', 'path'), False, None)
def test_rmtree_optional_params(self):
"""
Test :func:`openlp.core.common.path.rmtree` when optional parameters are passed
"""
# GIVEN: A mocked :func:`shutil.rmtree` and a test Path object.
with patch('openlp.core.common.path.shutil.rmtree', return_value=None) as mocked_shutil_rmtree:
path = Path('test', 'path')
mocked_on_error = MagicMock()
# WHEN: Calling :func:`openlp.core.common.path.rmtree` with :param:`ignore_errors` set to True and
# :param:`onerror` set to a mocked object
path.rmtree(ignore_errors=True, onerror=mocked_on_error)
# THEN: :func:`shutil.rmtree` should have been called with the optional parameters, with out any of the
# values being modified
mocked_shutil_rmtree.assert_called_once_with(path, True, mocked_on_error)
def test_which_no_command(self):
"""
Test :func:`openlp.core.common.path.which` when the command is not found.
@ -298,57 +165,6 @@ class TestPath(TestCase):
# THEN: `path_to_str` should return None
assert result is None
def test_path_encode_json(self):
"""
Test that `Path.encode_json` returns a Path object from a dictionary representation of a Path object decoded
from JSON
"""
# GIVEN: A Path object from openlp.core.common.path
# WHEN: Calling encode_json, with a dictionary representation
path = Path.encode_json({'__Path__': ['path', 'to', 'fi.le']}, extra=1, args=2)
# THEN: A Path object should have been returned
assert path == Path('path', 'to', 'fi.le')
def test_path_encode_json_base_path(self):
"""
Test that `Path.encode_json` returns a Path object from a dictionary representation of a Path object decoded
from JSON when the base_path arg is supplied.
"""
# GIVEN: A Path object from openlp.core.common.path
# WHEN: Calling encode_json, with a dictionary representation
path = Path.encode_json({'__Path__': ['path', 'to', 'fi.le']}, base_path=Path('/base'))
# THEN: A Path object should have been returned with an absolute path
assert path == Path('/', 'base', 'path', 'to', 'fi.le')
def test_path_json_object(self):
"""
Test that `Path.json_object` creates a JSON decode-able object from a Path object
"""
# GIVEN: A Path object from openlp.core.common.path
path = Path('/base', 'path', 'to', 'fi.le')
# WHEN: Calling json_object
obj = path.json_object(extra=1, args=2)
# THEN: A JSON decodable object should have been returned.
assert obj == {'__Path__': (os.sep, 'base', 'path', 'to', 'fi.le')}
def test_path_json_object_base_path(self):
"""
Test that `Path.json_object` creates a JSON decode-able object from a Path object, that is relative to the
base_path
"""
# GIVEN: A Path object from openlp.core.common.path
path = Path('/base', 'path', 'to', 'fi.le')
# WHEN: Calling json_object with a base_path
obj = path.json_object(base_path=Path('/', 'base'))
# THEN: A JSON decodable object should have been returned.
assert obj == {'__Path__': ('path', 'to', 'fi.le')}
def test_create_paths_dir_exists(self):
"""
Test the create_paths() function when the path already exists

View File

@ -277,7 +277,8 @@ class TestSettings(TestCase, TestMixin):
"""Test the Settings._convert_value() method when a setting is JSON and represents a Path object"""
# GIVEN: A settings object
# WHEN: _convert_value() is run
result = Settings()._convert_value('{"__Path__": ["openlp", "core"]}', None)
result = Settings()._convert_value(
'{"parts": ["openlp", "core"], "json_meta": {"class": "Path", "version": 1}}', None)
# THEN: The result should be a Path object
assert isinstance(result, Path), 'The result should be a Path object'

View File

@ -23,6 +23,7 @@
Package to test the openlp.core.lib package.
"""
import shutil
from pathlib import Path
from tempfile import mkdtemp
from unittest import TestCase
from unittest.mock import MagicMock, patch
@ -31,7 +32,6 @@ from sqlalchemy import MetaData
from sqlalchemy.orm.scoping import ScopedSession
from sqlalchemy.pool import NullPool
from openlp.core.common.path import Path
from openlp.core.lib.db import delete_database, get_upgrade_op, init_db, upgrade_db

View File

@ -22,12 +22,12 @@
"""
Package to test the openlp.core.lib package.
"""
from pathlib import Path
from unittest import TestCase
from unittest.mock import MagicMock, patch
from PyQt5 import QtCore, QtGui
from openlp.core.common.path import Path
from openlp.core.lib import build_icon, check_item_selected, create_separated_list, create_thumb, \
get_text_file_string, image_to_byte, resize_image, str_to_bool, validate_thumb
from tests.utils.constants import RESOURCE_PATH

View File

@ -23,12 +23,12 @@
Package to test the openlp.core.lib package.
"""
import os
from pathlib import Path
from unittest import TestCase
from unittest.mock import MagicMock, patch
from openlp.core.state import State
from openlp.core.common import md5_hash
from openlp.core.common.path import Path
from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings
from openlp.core.lib.formattingtags import FormattingTags

View File

@ -19,10 +19,10 @@
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
##########################################################################
from pathlib import Path
from unittest import TestCase
from unittest.mock import MagicMock, patch
from openlp.core.common.path import Path
from openlp.core.common.registry import Registry
from openlp.core.server import Server
from tests.helpers.testmixin import TestMixin

View File

@ -27,7 +27,6 @@ from unittest.mock import MagicMock, patch
from openlp.core.common.registry import Registry
from openlp.core.ui.media.mediacontroller import MediaController
from openlp.core.ui.media.vlcplayer import VlcPlayer
from tests.helpers.testmixin import TestMixin
from tests.utils.constants import RESOURCE_PATH
@ -43,26 +42,6 @@ class TestMediaController(TestCase, TestMixin):
Registry.create()
Registry().register('service_manager', MagicMock())
def test_generate_extensions_lists(self):
"""
Test that the extensions are create correctly
"""
# GIVEN: A MediaController and an active player with audio and video extensions
media_controller = MediaController()
media_controller.vlc_player = VlcPlayer(None)
media_controller.vlc_player.is_active = True
media_controller.vlc_player.audio_extensions_list = ['*.mp3', '*.wav', '*.wma', '*.ogg']
media_controller.vlc_player.video_extensions_list = ['*.mp4', '*.mov', '*.avi', '*.ogm']
# WHEN: calling _generate_extensions_lists
media_controller._generate_extensions_lists()
# THEN: extensions list should have been copied from the player to the mediacontroller
assert media_controller.video_extensions_list == media_controller.video_extensions_list, \
'Video extensions should be the same'
assert media_controller.audio_extensions_list == media_controller.audio_extensions_list, \
'Audio extensions should be the same'
def test_resize(self):
"""
Test that the resize method is called correctly

View File

@ -30,7 +30,7 @@ from unittest.mock import MagicMock, call, patch
from openlp.core.common.registry import Registry
from openlp.core.ui.media import MediaState, MediaType
from openlp.core.ui.media.vlcplayer import AUDIO_EXT, VIDEO_EXT, VlcPlayer, get_vlc
from openlp.core.ui.media.vlcplayer import VlcPlayer, get_vlc
from tests.helpers import MockDateTime
from tests.helpers.testmixin import TestMixin
@ -95,8 +95,6 @@ class TestVLCPlayer(TestCase, TestMixin):
assert '&VLC' == vlc_player.display_name
assert vlc_player.parent is None
assert vlc_player.can_folder is True
assert AUDIO_EXT == vlc_player.audio_extensions_list
assert VIDEO_EXT == vlc_player.video_extensions_list
@patch('openlp.core.ui.media.vlcplayer.is_win')
@patch('openlp.core.ui.media.vlcplayer.is_macosx')
@ -958,20 +956,3 @@ class TestVLCPlayer(TestCase, TestMixin):
mocked_controller.seek_slider.setSliderPosition.assert_called_with(300)
expected_calls = [call(True), call(False)]
assert expected_calls == mocked_controller.seek_slider.blockSignals.call_args_list
@patch('openlp.core.ui.media.vlcplayer.translate')
def test_get_info(self, mocked_translate):
"""
Test that get_info() returns some information about the VLC player
"""
# GIVEN: A VlcPlayer
mocked_translate.side_effect = lambda *x: x[1]
vlc_player = VlcPlayer(None)
# WHEN: get_info() is run
info = vlc_player.get_info()
# THEN: The information should be correct
assert 'VLC is an external player which supports a number of different formats.<br/> ' \
'<strong>Audio</strong><br/>' + str(AUDIO_EXT) + '<br/><strong>Video</strong><br/>' + \
str(VIDEO_EXT) + '<br/>' == info

View File

@ -25,10 +25,10 @@ Package to test the openlp.core.ui.exeptionform package.
import os
import tempfile
from collections import OrderedDict
from pathlib import Path
from unittest import TestCase
from unittest.mock import call, patch
from openlp.core.common.path import Path
from openlp.core.common.registry import Registry
from openlp.core.ui import exceptionform
from tests.helpers.testmixin import TestMixin

View File

@ -24,12 +24,12 @@ Package to test the openlp.core.ui.firsttimeform package.
"""
import os
import tempfile
from pathlib import Path
from unittest import TestCase
from unittest.mock import MagicMock, call, patch, DEFAULT
from PyQt5 import QtWidgets
from openlp.core.common.path import Path
from openlp.core.common.registry import Registry
from openlp.core.ui.firsttimeform import FirstTimeForm, ThemeListWidgetItem
from tests.helpers.testmixin import TestMixin

View File

@ -22,10 +22,10 @@
"""
Package to test the openlp.core.ui.themeform package.
"""
from pathlib import Path
from unittest import TestCase
from unittest.mock import MagicMock, patch
from openlp.core.common.path import Path
from openlp.core.ui.themeform import ThemeForm

View File

@ -24,13 +24,13 @@ Package to test the openlp.core.ui.thememanager package.
"""
import os
import shutil
from pathlib import Path
from tempfile import mkdtemp
from unittest import TestCase
from unittest.mock import ANY, MagicMock, patch
from PyQt5 import QtWidgets
from openlp.core.common.path import Path
from openlp.core.common.registry import Registry
from openlp.core.ui.thememanager import ThemeManager
from tests.utils.constants import RESOURCE_PATH
@ -81,9 +81,9 @@ class TestThemeManager(TestCase):
# THEN: The the controller should be registered in the registry.
assert Registry().get('theme_manager') is not None, 'The base theme manager should be registered'
@patch('openlp.core.ui.thememanager.copyfile')
@patch('openlp.core.ui.thememanager.shutil')
@patch('openlp.core.ui.thememanager.create_paths')
def test_write_theme_same_image(self, mocked_create_paths, mocked_copyfile):
def test_write_theme_same_image(self, mocked_create_paths, mocked_shutil):
"""
Test that we don't try to overwrite a theme background image with itself
"""
@ -103,11 +103,11 @@ class TestThemeManager(TestCase):
theme_manager._write_theme(mocked_theme, file_path_1, file_path_1)
# THEN: The mocked_copyfile should not have been called
assert mocked_copyfile.called is False, 'copyfile should not be called'
assert mocked_shutil.copyfile.called is False, 'copyfile should not be called'
@patch('openlp.core.ui.thememanager.copyfile')
@patch('openlp.core.ui.thememanager.shutil')
@patch('openlp.core.ui.thememanager.create_paths')
def test_write_theme_diff_images(self, mocked_create_paths, mocked_copyfile):
def test_write_theme_diff_images(self, mocked_create_paths, mocked_shutil):
"""
Test that we do overwrite a theme background image when a new is submitted
"""
@ -127,7 +127,7 @@ class TestThemeManager(TestCase):
theme_manager._write_theme(mocked_theme, file_path_1, file_path_2)
# THEN: The mocked_copyfile should not have been called
assert mocked_copyfile.called is True, 'copyfile should be called'
assert mocked_shutil.copyfile.called is True, 'copyfile should be called'
def test_write_theme_special_char_name(self):
"""
@ -207,7 +207,7 @@ class TestThemeManager(TestCase):
# THEN: Files should be unpacked
assert (folder_path / 'Moss on tree' / 'Moss on tree.xml').exists() is True
assert mocked_critical_error_message_box.call_count == 0, 'No errors should have happened'
folder_path.rmtree()
shutil.rmtree(folder_path)
def test_unzip_theme_invalid_version(self):
"""

View File

@ -20,12 +20,12 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
##########################################################################
import os
from pathlib import Path
from unittest import TestCase
from unittest.mock import patch
from PyQt5 import QtWidgets
from openlp.core.common.path import Path
from openlp.core.widgets.dialogs import FileDialog

View File

@ -23,10 +23,10 @@
This module contains tests for the openlp.core.widgets.edits module
"""
import os
from pathlib import Path
from unittest import TestCase
from unittest.mock import MagicMock, PropertyMock, patch
from openlp.core.common.path import Path
from openlp.core.widgets.dialogs import FileDialog
from openlp.core.widgets.edits import PathEdit
from openlp.core.widgets.enums import PathEditType

View File

@ -23,6 +23,7 @@
This module contains tests for the bibleimport module.
"""
from io import BytesIO
from pathlib import Path
from unittest import TestCase
from unittest.mock import MagicMock, patch
@ -30,7 +31,6 @@ from lxml import etree, objectify
from PyQt5.QtWidgets import QDialog
from openlp.core.common.i18n import Language
from openlp.core.common.path import Path
from openlp.core.lib.exceptions import ValidationError
from openlp.plugins.bibles.lib.bibleimport import BibleImport
from openlp.plugins.bibles.lib.db import BibleDB

View File

@ -24,10 +24,10 @@ This module contains tests for the CSV Bible importer.
"""
import csv
from collections import namedtuple
from pathlib import Path
from unittest import TestCase
from unittest.mock import MagicMock, PropertyMock, call, patch
from openlp.core.common.path import Path
from openlp.core.lib.exceptions import ValidationError
from openlp.plugins.bibles.lib.bibleimport import BibleImport
from openlp.plugins.bibles.lib.importers.csvbible import Book, CSVBible, Verse

View File

@ -22,10 +22,10 @@
"""
This module contains tests for the manager submodule of the Bibles plugin.
"""
from pathlib import Path
from unittest import TestCase
from unittest.mock import MagicMock, patch
from openlp.core.common.path import Path
from openlp.plugins.bibles.lib.manager import BibleManager

View File

@ -22,10 +22,10 @@
"""
This module contains tests for the WordProject Bible importer.
"""
from pathlib import Path
from unittest import TestCase
from unittest.mock import MagicMock, call, patch
from openlp.core.common.path import Path
from openlp.plugins.bibles.lib.importers.wordproject import WordProjectBible
from tests.utils.constants import RESOURCE_PATH

View File

@ -22,12 +22,12 @@
"""
This module contains tests for the lib submodule of the Images plugin.
"""
from pathlib import Path
from unittest import TestCase
from unittest.mock import ANY, MagicMock, patch
from PyQt5 import QtCore, QtWidgets
from openlp.core.common.path import Path
from openlp.core.common.registry import Registry
from openlp.plugins.images.lib.db import ImageFilenames, ImageGroups
from openlp.plugins.images.lib.mediaitem import ImageMediaItem

View File

@ -24,12 +24,12 @@ This module contains tests for the lib submodule of the Images plugin.
"""
import os
import shutil
from pathlib import Path
from tempfile import mkdtemp
from unittest import TestCase, skip
from unittest.mock import patch
from openlp.core.common.applocation import AppLocation
from openlp.core.common.path import Path
from openlp.core.common.settings import Settings
from openlp.core.lib.db import Manager
from openlp.plugins.images.lib import upgrade

View File

@ -22,12 +22,12 @@
"""
Test the media plugin
"""
from pathlib import Path
from unittest import TestCase
from unittest.mock import MagicMock, patch
from PyQt5 import QtCore
from openlp.core.common.path import Path
from openlp.core.common.settings import Settings
from openlp.plugins.media.lib.mediaitem import MediaMediaItem
from tests.helpers.testmixin import TestMixin

View File

@ -22,10 +22,10 @@
"""
This module contains tests for the lib submodule of the Presentations plugin.
"""
from pathlib import Path
from unittest import TestCase
from unittest.mock import MagicMock, call, patch
from openlp.core.common.path import Path
from openlp.core.common.registry import Registry
from openlp.plugins.presentations.lib.mediaitem import PresentationMediaItem
from tests.helpers.testmixin import TestMixin

View File

@ -23,7 +23,8 @@
This module contains tests for the PdfController
"""
import os
from shutil import which
from pathlib import Path
from shutil import rmtree, which
from tempfile import mkdtemp
from unittest import TestCase
from unittest.mock import MagicMock, patch
@ -31,7 +32,6 @@ from unittest.mock import MagicMock, patch
from PyQt5 import QtCore, QtGui
from openlp.core.common import is_macosx, is_linux, is_win
from openlp.core.common.path import Path
from openlp.core.common.settings import Settings
from openlp.core.display.screens import ScreenList
from openlp.plugins.presentations.lib.pdfcontroller import PdfController, PdfDocument
@ -99,8 +99,8 @@ class TestPdfController(TestCase, TestMixin):
"""
del self.screens
self.destroy_settings()
self.thumbnail_folder_path.rmtree()
self.temp_folder_path.rmtree()
rmtree(self.thumbnail_folder_path)
rmtree(self.temp_folder_path)
def test_constructor(self):
"""

View File

@ -23,10 +23,10 @@
Functional tests to test the PresentationController and PresentationDocument
classes and related methods.
"""
from pathlib import Path
from unittest import TestCase
from unittest.mock import MagicMock, call, patch
from openlp.core.common.path import Path
from openlp.plugins.presentations.lib.presentationcontroller import PresentationController, PresentationDocument

View File

@ -22,11 +22,12 @@
"""
This module contains tests for the OpenLyrics song importer.
"""
import shutil
from pathlib import Path
from tempfile import mkdtemp
from unittest import TestCase
from unittest.mock import MagicMock, patch
from openlp.core.common.path import Path
from openlp.core.common.registry import Registry
from openlp.plugins.songs.lib.openlyricsexport import OpenLyricsExport
from tests.helpers.testmixin import TestMixin
@ -47,7 +48,7 @@ class TestOpenLyricsExport(TestCase, TestMixin):
"""
Cleanup
"""
self.temp_folder.rmtree()
shutil.rmtree(self.temp_folder)
def test_export_same_filename(self):
"""

Some files were not shown because too many files have changed in this diff Show More