Merge lp:~tomasgroth/openlp/bugfixes18 into lp:openlp

Proposed by Tomas Groth
Status: Merged
Approved by: Raoul Snyman
Approved revision: 2529
Merged at revision: 2526
Proposed branch: lp:~tomasgroth/openlp/bugfixes18
Merge into: lp:openlp
Diff against target: 206 lines (+53/-13)
9 files modified
openlp/core/common/__init__.py (+3/-2)
openlp/core/lib/__init__.py (+1/-1)
openlp/core/ui/maindisplay.py (+2/-2)
openlp/core/ui/media/mediacontroller.py (+2/-0)
openlp/core/ui/thememanager.py (+9/-5)
openlp/plugins/custom/lib/mediaitem.py (+4/-0)
openlp/plugins/songs/lib/openlyricsxml.py (+2/-2)
tests/functional/openlp_core_lib/test_lib.py (+1/-1)
tests/functional/openlp_core_ui/test_thememanager.py (+29/-0)
To merge this branch: bzr merge lp:~tomasgroth/openlp/bugfixes18
Reviewer Review Type Date Requested Status
Raoul Snyman Approve
Tim Bentley Approve
Review via email: mp+255147@code.launchpad.net

Description of the change

Mark a custom slide edited from preview as coming from plugin. Fixes bug 1439671.
Use html.escape instead of the deprecated cgi.escape
Fix support for special characters in theme names. Fixes bug 1438563.
Fix another case of traceback when playing media with no players available/enabled (bug 1422761).

To post a comment you must log in.
Revision history for this message
Tomas Groth (tomasgroth) wrote :

lp:~tomasgroth/openlp/bugfixes18 (revision 2529)
[SUCCESS] https//ci.openlp.io/job/Branch-01-Pull/1003/
[SUCCESS] https//ci.openlp.io/job/Branch-02-Functional-Tests/926/
[SUCCESS] https//ci.openlp.io/job/Branch-03-Interface-Tests/868/
[SUCCESS] https//ci.openlp.io/job/Branch-04a-Windows_Functional_Tests/758/
[SUCCESS] https//ci.openlp.io/job/Branch-04b-Windows_Interface_Tests/356/
[SUCCESS] https//ci.openlp.io/job/Branch-05a-Code_Analysis/490/
[SUCCESS] https//ci.openlp.io/job/Branch-05b-Test_Coverage/361/

Revision history for this message
Tim Bentley (trb143) wrote :

Nice set. Fixed a bug we found but I forgot to raise on our new W7 test machine.

review: Approve
Revision history for this message
Raoul Snyman (raoul-snyman) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openlp/core/common/__init__.py'
2--- openlp/core/common/__init__.py 2015-02-04 16:43:04 +0000
3+++ openlp/core/common/__init__.py 2015-04-02 21:03:11 +0000
4@@ -66,8 +66,9 @@
5 try:
6 if not os.path.exists(directory):
7 os.makedirs(directory)
8- except IOError:
9- pass
10+ except IOError as e:
11+ if not do_not_log:
12+ log.exception('failed to check if directory exists or create directory')
13
14
15 def get_frozen_path(frozen_option, non_frozen_option):
16
17=== modified file 'openlp/core/lib/__init__.py'
18--- openlp/core/lib/__init__.py 2015-02-13 21:47:06 +0000
19+++ openlp/core/lib/__init__.py 2015-04-02 21:03:11 +0000
20@@ -90,7 +90,7 @@
21 file_handle = None
22 content = None
23 try:
24- file_handle = open(text_file, 'r')
25+ file_handle = open(text_file, 'r', encoding='utf-8')
26 if not file_handle.read(3) == '\xEF\xBB\xBF':
27 # no BOM was found
28 file_handle.seek(0)
29
30=== modified file 'openlp/core/ui/maindisplay.py'
31--- openlp/core/ui/maindisplay.py 2015-01-29 20:58:14 +0000
32+++ openlp/core/ui/maindisplay.py 2015-04-02 21:03:11 +0000
33@@ -29,7 +29,7 @@
34
35 """
36
37-import cgi
38+import html
39 import logging
40
41 from PyQt4 import QtCore, QtGui, QtWebKit, QtOpenGL
42@@ -273,7 +273,7 @@
43 """
44 # First we convert <>& marks to html variants, then apply
45 # formattingtags, finally we double all backslashes for JavaScript.
46- text_prepared = expand_tags(cgi.escape(text)).replace('\\', '\\\\').replace('\"', '\\\"')
47+ text_prepared = expand_tags(html.escape(text)).replace('\\', '\\\\').replace('\"', '\\\"')
48 if self.height() != self.screen['size'].height() or not self.isVisible():
49 shrink = True
50 js = 'show_alert("%s", "%s")' % (text_prepared, 'top')
51
52=== modified file 'openlp/core/ui/media/mediacontroller.py'
53--- openlp/core/ui/media/mediacontroller.py 2015-03-16 21:32:56 +0000
54+++ openlp/core/ui/media/mediacontroller.py 2015-04-02 21:03:11 +0000
55@@ -523,6 +523,8 @@
56 if controller.media_info.file_info.isFile():
57 suffix = '*.%s' % controller.media_info.file_info.suffix().lower()
58 for title in used_players:
59+ if not title:
60+ continue
61 player = self.media_players[title]
62 if suffix in player.video_extensions_list:
63 if not controller.media_info.is_background or controller.media_info.is_background and \
64
65=== modified file 'openlp/core/ui/thememanager.py'
66--- openlp/core/ui/thememanager.py 2015-02-28 07:04:41 +0000
67+++ openlp/core/ui/thememanager.py 2015-04-02 21:03:11 +0000
68@@ -354,8 +354,12 @@
69 delete_file(os.path.join(self.path, thumb))
70 delete_file(os.path.join(self.thumb_path, thumb))
71 try:
72- encoding = get_filesystem_encoding()
73- shutil.rmtree(os.path.join(self.path, theme).encode(encoding))
74+ # Windows is always unicode, so no need to encode filenames
75+ if is_win():
76+ shutil.rmtree(os.path.join(self.path, theme))
77+ else:
78+ encoding = get_filesystem_encoding()
79+ shutil.rmtree(os.path.join(self.path, theme).encode(encoding))
80 except OSError as os_error:
81 shutil.Error = os_error
82 self.log_exception('Error deleting theme %s' % theme)
83@@ -567,7 +571,7 @@
84 check_directory_exists(os.path.dirname(full_name))
85 if os.path.splitext(name)[1].lower() == '.xml':
86 file_xml = str(theme_zip.read(name), 'utf-8')
87- out_file = open(full_name, 'w')
88+ out_file = open(full_name, 'w', encoding='utf-8')
89 out_file.write(file_xml)
90 else:
91 out_file = open(full_name, 'wb')
92@@ -645,8 +649,8 @@
93 delete_file(self.old_background_image)
94 out_file = None
95 try:
96- out_file = open(theme_file, 'w')
97- out_file.write(theme_pretty_xml.decode('UTF-8'))
98+ out_file = open(theme_file, 'w', encoding='utf-8')
99+ out_file.write(theme_pretty_xml.decode('utf-8'))
100 except IOError:
101 self.log_exception('Saving theme to file failed')
102 finally:
103
104=== modified file 'openlp/plugins/custom/lib/mediaitem.py'
105--- openlp/plugins/custom/lib/mediaitem.py 2015-01-18 13:39:21 +0000
106+++ openlp/plugins/custom/lib/mediaitem.py 2015-04-02 21:03:11 +0000
107@@ -158,6 +158,10 @@
108 self.remote_triggered = None
109 self.remote_custom = 1
110 if item:
111+ if preview:
112+ # A custom slide can only be edited if it comes from plugin,
113+ # so we set it again for the new item.
114+ item.from_plugin = True
115 return item
116 return None
117
118
119=== modified file 'openlp/plugins/songs/lib/openlyricsxml.py'
120--- openlp/plugins/songs/lib/openlyricsxml.py 2015-01-21 20:35:36 +0000
121+++ openlp/plugins/songs/lib/openlyricsxml.py 2015-04-02 21:03:11 +0000
122@@ -55,7 +55,7 @@
123 </lyrics>
124 </song>
125 """
126-import cgi
127+import html
128 import logging
129 import re
130
131@@ -318,7 +318,7 @@
132 if 'lang' in verse[0]:
133 verse_element.set('lang', verse[0]['lang'])
134 # Create a list with all "optional" verses.
135- optional_verses = cgi.escape(verse[1])
136+ optional_verses = html.escape(verse[1])
137 optional_verses = optional_verses.split('\n[---]\n')
138 start_tags = ''
139 end_tags = ''
140
141=== modified file 'tests/functional/openlp_core_lib/test_lib.py'
142--- tests/functional/openlp_core_lib/test_lib.py 2015-01-18 13:39:21 +0000
143+++ tests/functional/openlp_core_lib/test_lib.py 2015-04-02 21:03:11 +0000
144@@ -176,7 +176,7 @@
145
146 # THEN: None should be returned
147 mocked_isfile.assert_called_with(filename)
148- mocked_open.assert_called_with(filename, 'r')
149+ mocked_open.assert_called_with(filename, 'r', encoding='utf-8')
150 self.assertIsNone(result, 'None should be returned if the file cannot be opened')
151
152 def get_text_file_string_decode_error_test(self):
153
154=== modified file 'tests/functional/openlp_core_ui/test_thememanager.py'
155--- tests/functional/openlp_core_ui/test_thememanager.py 2015-02-19 18:57:05 +0000
156+++ tests/functional/openlp_core_ui/test_thememanager.py 2015-04-02 21:03:11 +0000
157@@ -29,6 +29,7 @@
158 from tempfile import mkdtemp
159
160 from PyQt4 import QtGui
161+from tempfile import mkdtemp
162
163 from openlp.core.ui import ThemeManager
164 from openlp.core.common import Registry
165@@ -44,6 +45,13 @@
166 Set up the tests
167 """
168 Registry.create()
169+ self.temp_folder = mkdtemp()
170+
171+ def tearDown(self):
172+ """
173+ Clean up
174+ """
175+ shutil.rmtree(self.temp_folder)
176
177 def export_theme_test(self):
178 """
179@@ -131,6 +139,27 @@
180 # THEN: The mocked_copyfile should not have been called
181 self.assertTrue(mocked_copyfile.called, 'shutil.copyfile should be called')
182
183+ def write_theme_special_char_name_test(self):
184+ """
185+ Test that we can save themes with special characters in the name
186+ """
187+ # GIVEN: A new theme manager instance, with mocked theme and thememanager-attributes.
188+ theme_manager = ThemeManager(None)
189+ theme_manager.old_background_image = None
190+ theme_manager.generate_and_save_image = MagicMock()
191+ theme_manager.path = self.temp_folder
192+ mocked_theme = MagicMock()
193+ mocked_theme.theme_name = 'theme 愛 name'
194+ mocked_theme.extract_formatted_xml = MagicMock()
195+ mocked_theme.extract_formatted_xml.return_value = 'fake theme 愛 XML'.encode()
196+
197+ # WHEN: Calling _write_theme with a theme with a name with special characters in it
198+ theme_manager._write_theme(mocked_theme, None, None)
199+
200+ # THEN: It should have been created
201+ self.assertTrue(os.path.exists(os.path.join(self.temp_folder, 'theme 愛 name', 'theme 愛 name.xml')),
202+ 'Theme with special characters should have been created!')
203+
204 def over_write_message_box_yes_test(self):
205 """
206 Test that theme_manager.over_write_message_box returns True when the user clicks yes.