forked from openlp/openlp
Break out json and path refactors from fixes branch
This commit is contained in:
parent
fa7e8f9d3c
commit
5482e70e6d
@ -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
|
||||
"""
|
||||
|
@ -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
|
||||
|
@ -32,6 +32,8 @@ 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)
|
||||
|
@ -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
|
||||
"""
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
@ -19,14 +19,76 @@
|
||||
# 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 openlp.core.common.path import Path
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class OpenLPJsonDecoder(JSONDecoder):
|
||||
_registered_classes = {}
|
||||
|
||||
|
||||
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 +107,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 +143,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(path, json_dict)
|
||||
return json_dict
|
||||
|
@ -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
|
||||
"""
|
||||
@ -204,7 +95,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)))
|
||||
@ -218,7 +109,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
|
||||
"""
|
||||
@ -239,7 +130,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]
|
||||
|
@ -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,8 @@ 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): # TODO: doesnt handle list off path objects
|
||||
value = json.dumps(value, cls=OpenLPJSONEncoder)
|
||||
super().setValue(key, value)
|
||||
|
||||
def _convert_value(self, setting, default_value):
|
||||
@ -611,8 +612,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('{'): # TODO: Appears screeen settings is using this, subcass from jsonmixin
|
||||
return json.loads(setting, cls=OpenLPJSONDecoder)
|
||||
# Convert the setting to the correct type.
|
||||
if isinstance(default_value, bool):
|
||||
if isinstance(setting, bool):
|
||||
@ -629,7 +630,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
|
||||
"""
|
||||
|
@ -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
|
||||
"""
|
||||
|
@ -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,7 +165,7 @@ 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
|
||||
: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,8 +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):
|
||||
"""
|
||||
Some times it make sense to compare a PathType with a string. In the case a string is used coerce the the
|
||||
@ -224,7 +223,7 @@ 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
|
||||
:param psthlib.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
|
||||
@ -238,13 +237,13 @@ class PathType(types.TypeDecorator):
|
||||
"""
|
||||
Convert the Path object to a JSON representation
|
||||
|
||||
:param openlp.core.common.path.Path value: The value to convert
|
||||
:param psthlib.Path value: The value to convert
|
||||
:param dialect: Not used
|
||||
:return: The Path object as a JSON string
|
||||
:rtype: str
|
||||
"""
|
||||
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 +252,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: psthlib.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,7 +350,7 @@ 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
|
||||
:param pathlib.Path 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
|
||||
"""
|
||||
|
@ -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')
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
"""
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
@ -371,7 +372,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 +387,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
|
||||
|
||||
@ -443,7 +444,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()
|
||||
@ -518,7 +519,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 +582,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 +680,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 +703,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 +1251,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):
|
||||
"""
|
||||
|
@ -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
|
||||
|
@ -462,7 +462,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 +472,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
|
||||
|
@ -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
|
||||
"""
|
||||
|
@ -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),))
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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():
|
||||
|
@ -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(
|
||||
|
@ -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
|
||||
"""
|
||||
|
@ -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]
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
"""
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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')
|
||||
|
@ -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
|
||||
"""
|
||||
|
@ -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
|
||||
|
@ -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')
|
||||
|
@ -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')
|
||||
|
@ -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:
|
||||
@ -473,7 +475,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
|
||||
"""
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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()]
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
"""
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
"""
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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')
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
"""
|
||||
|
@ -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)
|
||||
|
@ -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):
|
||||
|
@ -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']
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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}}
|
||||
|
@ -22,12 +22,13 @@
|
||||
"""
|
||||
Package to test the openlp.core.common.path package.
|
||||
"""
|
||||
# TODO: fix patches
|
||||
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 +67,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.
|
||||
@ -287,57 +155,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
|
||||
|
@ -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'
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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):
|
||||
"""
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
"""
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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):
|
||||
"""
|
||||
|
@ -82,7 +82,7 @@ class SongImportTestHelper(TestCase):
|
||||
"""
|
||||
A method to load and return an object containing the song data from an external file.
|
||||
|
||||
:param openlp.core.common.path.Path file_path: The path of the file to load
|
||||
:param pathlib.Path file_path: The path of the file to load
|
||||
"""
|
||||
return json.loads(file_path.read_bytes().decode())
|
||||
|
||||
|
@ -22,7 +22,9 @@
|
||||
"""
|
||||
Package to test the openlp.core.lib.pluginmanager package.
|
||||
"""
|
||||
import shutil
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from tempfile import mkdtemp
|
||||
from unittest import TestCase, skip
|
||||
from unittest.mock import MagicMock, patch
|
||||
@ -30,7 +32,6 @@ from unittest.mock import MagicMock, patch
|
||||
from PyQt5 import QtWidgets
|
||||
|
||||
from openlp.core.common import is_win
|
||||
from openlp.core.common.path import Path
|
||||
from openlp.core.common.registry import Registry
|
||||
from openlp.core.common.settings import Settings
|
||||
from openlp.core.state import State
|
||||
@ -65,7 +66,7 @@ class TestPluginManager(TestCase, TestMixin):
|
||||
if is_win():
|
||||
import gc
|
||||
gc.collect()
|
||||
self.temp_dir_path.rmtree()
|
||||
shutil.rmtree(self.temp_dir_path)
|
||||
|
||||
@skip
|
||||
# This test is broken but totally unable to debug it.
|
||||
|
@ -22,10 +22,10 @@
|
||||
"""
|
||||
Package to test the openlp.core.ui.firsttimeform package.
|
||||
"""
|
||||
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.core.ui.firsttimeform import ThemeListWidgetItem
|
||||
from openlp.core.ui.icons import UiIcons
|
||||
|
@ -22,10 +22,10 @@
|
||||
"""
|
||||
Interface tests to test the themeManager class and related methods.
|
||||
"""
|
||||
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.common.settings import Settings
|
||||
from openlp.core.ui.thememanager import ThemeManager
|
||||
|
@ -44,6 +44,6 @@ def load_external_result_data(file_path):
|
||||
"""
|
||||
A method to load and return an object containing the song data from an external file.
|
||||
|
||||
:param openlp.core.common.path.Path file_path: The path of the file to load
|
||||
:param pathlib.Path file_path: The path of the file to load
|
||||
"""
|
||||
return json.loads(file_path.read_bytes().decode())
|
||||
|
@ -20,8 +20,7 @@
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
|
||||
##########################################################################
|
||||
import os
|
||||
|
||||
from openlp.core.common.path import Path
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
OPENLP_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
|
||||
|
Loading…
Reference in New Issue
Block a user