Merge lp:~phill-ridout/openlp/path_fixes into lp:openlp

Proposed by Phill
Status: Superseded
Proposed branch: lp:~phill-ridout/openlp/path_fixes
Merge into: lp:openlp
Diff against target: 169 lines (+26/-30)
6 files modified
openlp/core/common/json.py (+13/-4)
openlp/core/common/settings.py (+1/-1)
openlp/core/display/html/display.js (+4/-18)
openlp/core/display/window.py (+2/-2)
openlp/core/lib/theme.py (+5/-4)
openlp/plugins/presentations/lib/presentationcontroller.py (+1/-1)
To merge this branch: bzr merge lp:~phill-ridout/openlp/path_fixes
Reviewer Review Type Date Requested Status
OpenLP Core Pending
Review via email: mp+369191@code.launchpad.net

This proposal has been superseded by a proposal from 2019-06-21.

Commit message

Path fix ups

To post a comment you must log in.
Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

Linux tests failed, please see https://ci.openlp.io/job/MP-02-Linux_Tests/188/ for more details

lp:~phill-ridout/openlp/path_fixes updated
2882. By Phill

revert suffix stuff

2883. By Phill

rename param js_use to is_js

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openlp/core/common/json.py'
2--- openlp/core/common/json.py 2019-05-26 10:30:37 +0000
3+++ openlp/core/common/json.py 2019-06-21 21:09:44 +0000
4@@ -111,6 +111,8 @@
5 :param dict obj: A decoded JSON object
6 :return: The custom object from the serialized data if the custom object is registered, else obj
7 """
8+ if '__Path__' in obj:
9+ return PathSerializer.encode_json(obj, **self.kwargs)
10 try:
11 key = obj['json_meta']['class']
12 except KeyError:
13@@ -150,8 +152,8 @@
14 if isinstance(obj, JSONMixin):
15 return obj.json_object()
16 elif obj.__class__.__name__ in _registered_classes:
17- return _registered_classes[obj.__class__.__name__].json_object(obj)
18- return super().default(obj)
19+ return _registered_classes[obj.__class__.__name__].json_object(obj, **self.kwargs)
20+ return super().default(obj, **self.kwargs)
21
22
23 def is_serializable(obj):
24@@ -174,17 +176,22 @@
25 :param kwargs: Contains any extra parameters. Not used!
26 :return Path: The deserialized Path object
27 """
28- path = Path(*obj['parts'])
29+ if '__Path__' in obj:
30+ parts = obj['__Path__']
31+ else:
32+ parts = obj['parts']
33+ path = Path(*parts)
34 if base_path and not path.is_absolute():
35 return base_path / path
36 return path
37
38 @classmethod
39- def json_object(cls, obj, base_path=None, **kwargs):
40+ def json_object(cls, obj, base_path=None, js_use=False, **kwargs):
41 """
42 Create a dictionary that can be JSON decoded.
43
44 :param Path base_path: If specified, an absolute path to make a relative path from.
45+ :param bool js_use: Encode the path as a uri. For example for use in the js rendering code.
46 :param kwargs: Contains any extra parameters. Not used!
47 :return: The dictionary representation of this Path object.
48 :rtype: dict[tuple]
49@@ -193,6 +200,8 @@
50 if base_path:
51 with suppress(ValueError):
52 path = path.relative_to(base_path)
53+ if js_use is True:
54+ return path.as_uri()
55 json_dict = {'parts': path.parts}
56 cls.attach_meta(json_dict)
57 return json_dict
58
59=== modified file 'openlp/core/common/settings.py'
60--- openlp/core/common/settings.py 2019-06-14 17:54:04 +0000
61+++ openlp/core/common/settings.py 2019-06-21 21:09:44 +0000
62@@ -612,7 +612,7 @@
63 elif isinstance(default_value, dict):
64 return {}
65 elif isinstance(setting, str):
66- if 'json_meta' in setting or setting.startswith('{'):
67+ if 'json_meta' in setting or '__Path__' in setting or setting.startswith('{'):
68 return json.loads(setting, cls=OpenLPJSONDecoder)
69 # Convert the setting to the correct type.
70 if isinstance(default_value, bool):
71
72=== modified file 'openlp/core/display/html/display.js'
73--- openlp/core/display/html/display.js 2019-03-16 10:26:05 +0000
74+++ openlp/core/display/html/display.js 2019-06-21 21:09:44 +0000
75@@ -118,20 +118,6 @@
76 }
77
78 /**
79- * The paths we get are JSON versions of Python Path objects, so let's just fix that.
80- * @private
81- * @param {object} path - The Path object
82- * @returns {string} The actual file path
83- */
84-function _pathToString(path) {
85- var filename = path.__Path__.join("/").replace("//", "/");
86- if (!filename.startsWith("/")) {
87- filename = "/" + filename;
88- }
89- return filename;
90-}
91-
92-/**
93 * An audio player with a play list
94 */
95 var AudioPlayer = function (audioElement) {
96@@ -676,13 +662,13 @@
97 }
98 break;
99 case BackgroundType.Image:
100- background_filename = _pathToString(theme.background_filename);
101- backgroundStyle["background-image"] = "url('file://" + background_filename + "')";
102+ backgroundStyle["background-image"] = "url('" + theme.background_filename + "')";
103+ console.warn(backgroundStyle["background-image"]);
104 break;
105 case BackgroundType.Video:
106- background_filename = _pathToString(theme.background_filename);
107 backgroundStyle["background-color"] = theme.background_border_color;
108- backgroundHtml = "<video loop autoplay muted><source src='file://" + background_filename + "'></video>";
109+ backgroundHtml = "<video loop autoplay muted><source src='" + theme.background_filename + "'></video>";
110+ console.warn(backgroundHtml);
111 break;
112 default:
113 backgroundStyle["background"] = "#000";
114
115=== modified file 'openlp/core/display/window.py'
116--- openlp/core/display/window.py 2019-05-23 19:33:46 +0000
117+++ openlp/core/display/window.py 2019-06-21 21:09:44 +0000
118@@ -332,9 +332,9 @@
119 theme_copy = copy.deepcopy(theme)
120 theme_copy.background_type = 'image'
121 theme_copy.background_filename = self.checkerboard_path
122- exported_theme = theme_copy.export_theme()
123+ exported_theme = theme_copy.export_theme(js_use=True)
124 else:
125- exported_theme = theme.export_theme()
126+ exported_theme = theme.export_theme(js_use=True)
127 self.run_javascript('Display.setTheme({theme});'.format(theme=exported_theme))
128
129 def get_video_types(self):
130
131=== modified file 'openlp/core/lib/theme.py'
132--- openlp/core/lib/theme.py 2019-05-22 06:47:00 +0000
133+++ openlp/core/lib/theme.py 2019-06-21 21:09:44 +0000
134@@ -225,17 +225,18 @@
135 jsn = json.loads(theme, cls=OpenLPJSONDecoder)
136 self.expand_json(jsn)
137
138- def export_theme(self, theme_path=None):
139+ def export_theme(self, theme_path=None, js_use=False):
140 """
141 Loop through the fields and build a dictionary of them
142
143+ :param pathlib.Path | None theme_path:
144+ :param bool js_use: For internal use, for example with the theme js code.
145+ :return str: The json encoded theme object
146 """
147 theme_data = {}
148 for attr, value in self.__dict__.items():
149 theme_data["{attr}".format(attr=attr)] = value
150- if theme_path:
151- return json.dumps(theme_data, cls=OpenLPJSONEncoder, base_path=theme_path)
152- return json.dumps(theme_data, cls=OpenLPJSONEncoder)
153+ return json.dumps(theme_data, cls=OpenLPJSONEncoder, base_path=theme_path, js_use=js_use)
154
155 def parse(self, xml):
156 """
157
158=== modified file 'openlp/plugins/presentations/lib/presentationcontroller.py'
159--- openlp/plugins/presentations/lib/presentationcontroller.py 2019-06-11 05:01:02 +0000
160+++ openlp/plugins/presentations/lib/presentationcontroller.py 2019-06-21 21:09:44 +0000
161@@ -129,7 +129,7 @@
162 thumbnail_folder_path = self.get_thumbnail_folder()
163 temp_folder_path = self.get_temp_folder()
164 if thumbnail_folder_path.exists():
165- thumbnail_folder_path.rmtree()
166+ shutil.rmtree(thumbnail_folder_path)
167 if temp_folder_path.exists():
168 shutil.rmtree(temp_folder_path)
169 except OSError: