Phill has proposed merging lp:~phill-ridout/openlp/path_fixes into lp:openlp.

Commit message:
Path fix ups

Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~phill-ridout/openlp/path_fixes/+merge/369195
-- 
Your team OpenLP Core is requested to review the proposed merge of 
lp:~phill-ridout/openlp/path_fixes into lp:openlp.
=== modified file 'openlp/core/common/json.py'
--- openlp/core/common/json.py	2019-05-26 10:30:37 +0000
+++ openlp/core/common/json.py	2019-06-21 22:10:16 +0000
@@ -111,6 +111,8 @@
         :param dict obj: A decoded JSON object
         :return: The custom object from the serialized data if the custom object is registered, else obj
         """
+        if '__Path__' in obj:
+            return PathSerializer.encode_json(obj, **self.kwargs)
         try:
             key = obj['json_meta']['class']
         except KeyError:
@@ -150,8 +152,8 @@
         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)
+            return _registered_classes[obj.__class__.__name__].json_object(obj, **self.kwargs)
+        return super().default(obj, **self.kwargs)
 
 
 def is_serializable(obj):
@@ -174,17 +176,22 @@
         :param kwargs: Contains any extra parameters. Not used!
         :return Path: The deserialized Path object
         """
-        path = Path(*obj['parts'])
+        if '__Path__' in obj:
+            parts = obj['__Path__']
+        else:
+            parts = obj['parts']
+        path = Path(*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):
+    def json_object(cls, obj, base_path=None, is_js=False, **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 bool is_js: Encode the path as a uri. For example for use in the js rendering code.
         :param kwargs: Contains any extra parameters. Not used!
         :return: The dictionary representation of this Path object.
         :rtype: dict[tuple]
@@ -193,6 +200,8 @@
         if base_path:
             with suppress(ValueError):
                 path = path.relative_to(base_path)
+        if is_js is True:
+            return path.as_uri()
         json_dict = {'parts': path.parts}
         cls.attach_meta(json_dict)
         return json_dict

=== modified file 'openlp/core/common/settings.py'
--- openlp/core/common/settings.py	2019-06-14 17:54:04 +0000
+++ openlp/core/common/settings.py	2019-06-21 22:10:16 +0000
@@ -612,7 +612,7 @@
             elif isinstance(default_value, dict):
                 return {}
         elif isinstance(setting, str):
-            if 'json_meta' in setting or setting.startswith('{'):
+            if 'json_meta' in setting or '__Path__' in setting or setting.startswith('{'):
                 return json.loads(setting, cls=OpenLPJSONDecoder)
         # Convert the setting to the correct type.
         if isinstance(default_value, bool):

=== modified file 'openlp/core/display/html/display.js'
--- openlp/core/display/html/display.js	2019-03-16 10:26:05 +0000
+++ openlp/core/display/html/display.js	2019-06-21 22:10:16 +0000
@@ -118,20 +118,6 @@
 }
 
 /**
- * The paths we get are JSON versions of Python Path objects, so let's just fix that.
- * @private
- * @param {object} path - The Path object
- * @returns {string} The actual file path
- */
-function _pathToString(path) {
-    var filename = path.__Path__.join("/").replace("//", "/");
-    if (!filename.startsWith("/")) {
-        filename = "/" + filename;
-    }
-    return filename;
-}
-
-/**
  * An audio player with a play list
  */
 var AudioPlayer = function (audioElement) {
@@ -676,13 +662,13 @@
         }
         break;
       case BackgroundType.Image:
-        background_filename = _pathToString(theme.background_filename);
-        backgroundStyle["background-image"] = "url('file://" + background_filename + "')";
+        backgroundStyle["background-image"] = "url('" + theme.background_filename + "')";
+        console.warn(backgroundStyle["background-image"]);
         break;
       case BackgroundType.Video:
-        background_filename = _pathToString(theme.background_filename);
         backgroundStyle["background-color"] = theme.background_border_color;
-        backgroundHtml = "<video loop autoplay muted><source src='file://" + background_filename + "'></video>";
+        backgroundHtml = "<video loop autoplay muted><source src='" + theme.background_filename + "'></video>";
+        console.warn(backgroundHtml);
         break;
       default:
         backgroundStyle["background"] = "#000";

=== modified file 'openlp/core/display/window.py'
--- openlp/core/display/window.py	2019-05-23 19:33:46 +0000
+++ openlp/core/display/window.py	2019-06-21 22:10:16 +0000
@@ -332,9 +332,9 @@
             theme_copy = copy.deepcopy(theme)
             theme_copy.background_type = 'image'
             theme_copy.background_filename = self.checkerboard_path
-            exported_theme = theme_copy.export_theme()
+            exported_theme = theme_copy.export_theme(is_js=True)
         else:
-            exported_theme = theme.export_theme()
+            exported_theme = theme.export_theme(is_js=True)
         self.run_javascript('Display.setTheme({theme});'.format(theme=exported_theme))
 
     def get_video_types(self):

=== modified file 'openlp/core/lib/theme.py'
--- openlp/core/lib/theme.py	2019-05-22 06:47:00 +0000
+++ openlp/core/lib/theme.py	2019-06-21 22:10:16 +0000
@@ -225,17 +225,18 @@
             jsn = json.loads(theme, cls=OpenLPJSONDecoder)
         self.expand_json(jsn)
 
-    def export_theme(self, theme_path=None):
+    def export_theme(self, theme_path=None, is_js=False):
         """
         Loop through the fields and build a dictionary of them
 
+        :param pathlib.Path | None theme_path:
+        :param bool is_js: For internal use, for example with the theme js code.
+        :return str: The json encoded theme object
         """
         theme_data = {}
         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, is_js=is_js)
 
     def parse(self, xml):
         """

=== modified file 'openlp/plugins/presentations/lib/presentationcontroller.py'
--- openlp/plugins/presentations/lib/presentationcontroller.py	2019-06-11 05:01:02 +0000
+++ openlp/plugins/presentations/lib/presentationcontroller.py	2019-06-21 22:10:16 +0000
@@ -129,7 +129,7 @@
             thumbnail_folder_path = self.get_thumbnail_folder()
             temp_folder_path = self.get_temp_folder()
             if thumbnail_folder_path.exists():
-                thumbnail_folder_path.rmtree()
+                shutil.rmtree(thumbnail_folder_path)
             if temp_folder_path.exists():
                 shutil.rmtree(temp_folder_path)
         except OSError:

_______________________________________________
Mailing list: https://launchpad.net/~openlp-core
Post to     : openlp-core@lists.launchpad.net
Unsubscribe : https://launchpad.net/~openlp-core
More help   : https://help.launchpad.net/ListHelp

Reply via email to