Status: | Superseded |
---|---|
Proposed branch: | lp:~phill-ridout/openlp/pathlib3 |
Merge into: | lp:openlp |
Diff against target: |
1856 lines (+314/-348) 48 files modified
openlp/core/__init__.py (+16/-12) openlp/core/api/endpoint/controller.py (+2/-2) openlp/core/api/endpoint/pluginhelpers.py (+2/-5) openlp/core/api/http/endpoint.py (+1/-2) openlp/core/api/http/wsgiapp.py (+6/-2) openlp/core/common/__init__.py (+47/-47) openlp/core/common/applocation.py (+8/-19) openlp/core/common/settings.py (+0/-28) openlp/core/lib/__init__.py (+13/-15) openlp/core/lib/db.py (+2/-2) openlp/core/lib/pluginmanager.py (+1/-1) openlp/core/lib/theme.py (+2/-3) openlp/core/ui/firsttimeform.py (+3/-2) openlp/core/ui/mainwindow.py (+2/-1) openlp/core/ui/media/mediacontroller.py (+1/-1) openlp/core/ui/printserviceform.py (+1/-1) openlp/core/ui/servicemanager.py (+6/-5) openlp/core/ui/themeform.py (+3/-1) openlp/core/ui/thememanager.py (+13/-12) openlp/plugins/bibles/lib/importers/csvbible.py (+2/-1) openlp/plugins/bibles/lib/manager.py (+3/-2) openlp/plugins/images/lib/mediaitem.py (+6/-5) openlp/plugins/media/lib/mediaitem.py (+2/-1) openlp/plugins/media/mediaplugin.py (+2/-2) openlp/plugins/presentations/lib/impresscontroller.py (+2/-1) openlp/plugins/presentations/lib/pdfcontroller.py (+2/-1) openlp/plugins/presentations/lib/presentationcontroller.py (+4/-3) openlp/plugins/presentations/presentationplugin.py (+1/-1) openlp/plugins/remotes/remoteplugin.py (+10/-9) openlp/plugins/songs/forms/editsongform.py (+1/-1) openlp/plugins/songs/lib/importers/songbeamer.py (+2/-1) openlp/plugins/songs/lib/importers/songimport.py (+2/-1) openlp/plugins/songs/lib/mediaitem.py (+3/-2) openlp/plugins/songs/lib/openlyricsexport.py (+2/-1) openlp/plugins/songusage/forms/songusagedetailform.py (+2/-1) scripts/appveyor.yml (+1/-1) tests/functional/openlp_core_common/test_applocation.py (+5/-7) tests/functional/openlp_core_common/test_common.py (+61/-35) tests/functional/openlp_core_common/test_init.py (+36/-32) tests/functional/openlp_core_lib/test_db.py (+5/-4) tests/functional/openlp_core_lib/test_file_dialog.py (+0/-45) tests/functional/openlp_core_lib/test_lib.py (+15/-15) tests/functional/openlp_core_ui/test_firsttimeform.py (+2/-1) tests/functional/openlp_core_ui/test_thememanager.py (+2/-2) tests/functional/openlp_plugins/bibles/test_manager.py (+2/-2) tests/functional/openlp_plugins/media/test_mediaplugin.py (+3/-5) tests/functional/openlp_plugins/presentations/test_presentationcontroller.py (+4/-2) tests/interfaces/openlp_core_common/test_utils.py (+3/-3) |
To merge this branch: | bzr merge lp:~phill-ridout/openlp/pathlib3 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tomas Groth | Approve | ||
Tim Bentley | Approve | ||
Raoul Snyman | Pending | ||
Review via email: mp+329481@code.launchpad.net |
This proposal supersedes a proposal from 2017-08-12.
This proposal has been superseded by a proposal from 2017-08-24.
Commit message
Description of the change
Part 3, converted some more utility methods
lp:~phill-ridout/openlp/pathlib3 (revision 2762)
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[FAILURE] https:/
Stopping after failure
Tim Bentley (trb143) wrote : Posted in a previous version of this proposal | # |
Raoul Snyman (raoul-snyman) : Posted in a previous version of this proposal | # |
Phill (phill-ridout) wrote : Posted in a previous version of this proposal | # |
> See inline
See my inline reply.
Phill (phill-ridout) wrote : Posted in a previous version of this proposal | # |
See my inline reply.
Phill (phill-ridout) wrote : Posted in a previous version of this proposal | # |
See inline
Tomas Groth (tomasgroth) wrote : Posted in a previous version of this proposal | # |
It seems the AppVeyor tests fails for a reason: https:/
Tim Bentley (trb143) wrote : | # |
Looks ok as part of the progression
Tomas Groth (tomasgroth) : | # |
Unmerged revisions
Preview Diff
1 | === modified file 'openlp/core/__init__.py' | |||
2 | --- openlp/core/__init__.py 2017-08-03 17:54:40 +0000 | |||
3 | +++ openlp/core/__init__.py 2017-08-24 19:54:19 +0000 | |||
4 | @@ -33,6 +33,7 @@ | |||
5 | 33 | import shutil | 33 | import shutil |
6 | 34 | import sys | 34 | import sys |
7 | 35 | import time | 35 | import time |
8 | 36 | from pathlib import Path | ||
9 | 36 | from traceback import format_exception | 37 | from traceback import format_exception |
10 | 37 | 38 | ||
11 | 38 | from PyQt5 import QtCore, QtGui, QtWidgets | 39 | from PyQt5 import QtCore, QtGui, QtWidgets |
12 | @@ -346,15 +347,18 @@ | |||
13 | 346 | """ | 347 | """ |
14 | 347 | Setup our logging using log_path | 348 | Setup our logging using log_path |
15 | 348 | 349 | ||
17 | 349 | :param log_path: the path | 350 | :param pathlib.Path log_path: The file to save the log to |
18 | 351 | :return: None | ||
19 | 352 | :rtype: None | ||
20 | 350 | """ | 353 | """ |
21 | 351 | check_directory_exists(log_path, True) | 354 | check_directory_exists(log_path, True) |
24 | 352 | filename = os.path.join(log_path, 'openlp.log') | 355 | file_path = log_path / 'openlp.log' |
25 | 353 | logfile = logging.FileHandler(filename, 'w', encoding="UTF-8") | 356 | # TODO: FileHandler accepts a Path object in Py3.6 |
26 | 357 | logfile = logging.FileHandler(str(file_path), 'w', encoding='UTF-8') | ||
27 | 354 | logfile.setFormatter(logging.Formatter('%(asctime)s %(name)-55s %(levelname)-8s %(message)s')) | 358 | logfile.setFormatter(logging.Formatter('%(asctime)s %(name)-55s %(levelname)-8s %(message)s')) |
28 | 355 | log.addHandler(logfile) | 359 | log.addHandler(logfile) |
29 | 356 | if log.isEnabledFor(logging.DEBUG): | 360 | if log.isEnabledFor(logging.DEBUG): |
31 | 357 | print('Logging to: {name}'.format(name=filename)) | 361 | print('Logging to: {name}'.format(name=file_path)) |
32 | 358 | 362 | ||
33 | 359 | 363 | ||
34 | 360 | def main(args=None): | 364 | def main(args=None): |
35 | @@ -390,24 +394,24 @@ | |||
36 | 390 | application.setApplicationName('OpenLPPortable') | 394 | application.setApplicationName('OpenLPPortable') |
37 | 391 | Settings.setDefaultFormat(Settings.IniFormat) | 395 | Settings.setDefaultFormat(Settings.IniFormat) |
38 | 392 | # Get location OpenLPPortable.ini | 396 | # Get location OpenLPPortable.ini |
41 | 393 | application_path = str(AppLocation.get_directory(AppLocation.AppDir)) | 397 | portable_path = (AppLocation.get_directory(AppLocation.AppDir) / '..' / '..').resolve() |
42 | 394 | set_up_logging(os.path.abspath(os.path.join(application_path, '..', '..', 'Other'))) | 398 | data_path = portable_path / 'Data' |
43 | 399 | set_up_logging(portable_path / 'Other') | ||
44 | 395 | log.info('Running portable') | 400 | log.info('Running portable') |
46 | 396 | portable_settings_file = os.path.abspath(os.path.join(application_path, '..', '..', 'Data', 'OpenLP.ini')) | 401 | portable_settings_path = data_path / 'OpenLP.ini' |
47 | 397 | # Make this our settings file | 402 | # Make this our settings file |
50 | 398 | log.info('INI file: {name}'.format(name=portable_settings_file)) | 403 | log.info('INI file: {name}'.format(name=portable_settings_path)) |
51 | 399 | Settings.set_filename(portable_settings_file) | 404 | Settings.set_filename(str(portable_settings_path)) |
52 | 400 | portable_settings = Settings() | 405 | portable_settings = Settings() |
53 | 401 | # Set our data path | 406 | # Set our data path |
54 | 402 | data_path = os.path.abspath(os.path.join(application_path, '..', '..', 'Data',)) | ||
55 | 403 | log.info('Data path: {name}'.format(name=data_path)) | 407 | log.info('Data path: {name}'.format(name=data_path)) |
56 | 404 | # Point to our data path | 408 | # Point to our data path |
58 | 405 | portable_settings.setValue('advanced/data path', data_path) | 409 | portable_settings.setValue('advanced/data path', str(data_path)) |
59 | 406 | portable_settings.setValue('advanced/is portable', True) | 410 | portable_settings.setValue('advanced/is portable', True) |
60 | 407 | portable_settings.sync() | 411 | portable_settings.sync() |
61 | 408 | else: | 412 | else: |
62 | 409 | application.setApplicationName('OpenLP') | 413 | application.setApplicationName('OpenLP') |
64 | 410 | set_up_logging(str(AppLocation.get_directory(AppLocation.CacheDir))) | 414 | set_up_logging(AppLocation.get_directory(AppLocation.CacheDir)) |
65 | 411 | Registry.create() | 415 | Registry.create() |
66 | 412 | Registry().register('application', application) | 416 | Registry().register('application', application) |
67 | 413 | Registry().set_flag('no_web_server', args.no_web_server) | 417 | Registry().set_flag('no_web_server', args.no_web_server) |
68 | 414 | 418 | ||
69 | === modified file 'openlp/core/api/endpoint/controller.py' | |||
70 | --- openlp/core/api/endpoint/controller.py 2017-08-13 05:50:44 +0000 | |||
71 | +++ openlp/core/api/endpoint/controller.py 2017-08-24 19:54:19 +0000 | |||
72 | @@ -64,7 +64,7 @@ | |||
73 | 64 | elif current_item.is_image() and not frame.get('image', '') and Settings().value('api/thumbnails'): | 64 | elif current_item.is_image() and not frame.get('image', '') and Settings().value('api/thumbnails'): |
74 | 65 | item['tag'] = str(index + 1) | 65 | item['tag'] = str(index + 1) |
75 | 66 | thumbnail_path = os.path.join('images', 'thumbnails', frame['title']) | 66 | thumbnail_path = os.path.join('images', 'thumbnails', frame['title']) |
77 | 67 | full_thumbnail_path = os.path.join(AppLocation.get_data_path(), thumbnail_path) | 67 | full_thumbnail_path = str(AppLocation.get_data_path() / thumbnail_path) |
78 | 68 | # Create thumbnail if it doesn't exists | 68 | # Create thumbnail if it doesn't exists |
79 | 69 | if not os.path.exists(full_thumbnail_path): | 69 | if not os.path.exists(full_thumbnail_path): |
80 | 70 | create_thumb(current_item.get_frame_path(index), full_thumbnail_path, False) | 70 | create_thumb(current_item.get_frame_path(index), full_thumbnail_path, False) |
81 | @@ -82,7 +82,7 @@ | |||
82 | 82 | if current_item.is_capable(ItemCapabilities.HasThumbnails) and \ | 82 | if current_item.is_capable(ItemCapabilities.HasThumbnails) and \ |
83 | 83 | Settings().value('api/thumbnails'): | 83 | Settings().value('api/thumbnails'): |
84 | 84 | # If the file is under our app directory tree send the portion after the match | 84 | # If the file is under our app directory tree send the portion after the match |
86 | 85 | data_path = AppLocation.get_data_path() | 85 | data_path = str(AppLocation.get_data_path()) |
87 | 86 | if frame['image'][0:len(data_path)] == data_path: | 86 | if frame['image'][0:len(data_path)] == data_path: |
88 | 87 | item['img'] = urllib.request.pathname2url(frame['image'][len(data_path):]) | 87 | item['img'] = urllib.request.pathname2url(frame['image'][len(data_path):]) |
89 | 88 | Registry().get('image_manager').add_image(frame['image'], frame['title'], None, 88, 88) | 88 | Registry().get('image_manager').add_image(frame['image'], frame['title'], None, 88, 88) |
90 | 89 | 89 | ||
91 | === modified file 'openlp/core/api/endpoint/pluginhelpers.py' | |||
92 | --- openlp/core/api/endpoint/pluginhelpers.py 2017-06-10 10:53:52 +0000 | |||
93 | +++ openlp/core/api/endpoint/pluginhelpers.py 2017-08-24 19:54:19 +0000 | |||
94 | @@ -125,12 +125,9 @@ | |||
95 | 125 | file_name = urllib.parse.unquote(file_name) | 125 | file_name = urllib.parse.unquote(file_name) |
96 | 126 | if '..' not in file_name: # no hacking please | 126 | if '..' not in file_name: # no hacking please |
97 | 127 | if slide: | 127 | if slide: |
100 | 128 | full_path = os.path.normpath(os.path.join(AppLocation.get_section_data_path(controller_name), | 128 | full_path = str(AppLocation.get_section_data_path(controller_name) / 'thumbnails' / file_name / slide) |
99 | 129 | 'thumbnails', file_name, slide)) | ||
101 | 130 | else: | 129 | else: |
105 | 131 | full_path = os.path.normpath(os.path.join(AppLocation.get_section_data_path(controller_name), | 130 | full_path = str(AppLocation.get_section_data_path(controller_name) / 'thumbnails' / file_name) |
103 | 132 | |||
104 | 133 | 'thumbnails', file_name)) | ||
106 | 134 | if os.path.exists(full_path): | 131 | if os.path.exists(full_path): |
107 | 135 | path, just_file_name = os.path.split(full_path) | 132 | path, just_file_name = os.path.split(full_path) |
108 | 136 | Registry().get('image_manager').add_image(full_path, just_file_name, None, width, height) | 133 | Registry().get('image_manager').add_image(full_path, just_file_name, None, width, height) |
109 | 137 | 134 | ||
110 | === modified file 'openlp/core/api/http/endpoint.py' | |||
111 | --- openlp/core/api/http/endpoint.py 2017-08-13 05:28:25 +0000 | |||
112 | +++ openlp/core/api/http/endpoint.py 2017-08-24 19:54:19 +0000 | |||
113 | @@ -68,11 +68,10 @@ | |||
114 | 68 | """ | 68 | """ |
115 | 69 | Render a mako template | 69 | Render a mako template |
116 | 70 | """ | 70 | """ |
118 | 71 | root = os.path.join(str(AppLocation.get_section_data_path('remotes'))) | 71 | root = str(AppLocation.get_section_data_path('remotes')) |
119 | 72 | if not self.template_dir: | 72 | if not self.template_dir: |
120 | 73 | raise Exception('No template directory specified') | 73 | raise Exception('No template directory specified') |
121 | 74 | path = os.path.join(root, self.template_dir, filename) | 74 | path = os.path.join(root, self.template_dir, filename) |
122 | 75 | # path = os.path.abspath(os.path.join(self.template_dir, filename)) | ||
123 | 76 | if self.static_dir: | 75 | if self.static_dir: |
124 | 77 | kwargs['static_url'] = '/{prefix}/static'.format(prefix=self.url_prefix) | 76 | kwargs['static_url'] = '/{prefix}/static'.format(prefix=self.url_prefix) |
125 | 78 | kwargs['static_url'] = kwargs['static_url'].replace('//', '/') | 77 | kwargs['static_url'] = kwargs['static_url'].replace('//', '/') |
126 | 79 | 78 | ||
127 | === modified file 'openlp/core/api/http/wsgiapp.py' | |||
128 | --- openlp/core/api/http/wsgiapp.py 2017-08-12 20:26:39 +0000 | |||
129 | +++ openlp/core/api/http/wsgiapp.py 2017-08-24 19:54:19 +0000 | |||
130 | @@ -138,8 +138,12 @@ | |||
131 | 138 | Add a static directory as a route | 138 | Add a static directory as a route |
132 | 139 | """ | 139 | """ |
133 | 140 | if route not in self.static_routes: | 140 | if route not in self.static_routes: |
136 | 141 | root = os.path.join(str(AppLocation.get_section_data_path('remotes'))) | 141 | root = str(AppLocation.get_section_data_path('remotes')) |
137 | 142 | self.static_routes[route] = DirectoryApp(os.path.abspath(os.path.join(root, static_dir))) | 142 | static_path = os.path.abspath(os.path.join(root, static_dir)) |
138 | 143 | if not os.path.exists(static_path): | ||
139 | 144 | log.error('Static path "%s" does not exist. Skipping creating static route/', static_path) | ||
140 | 145 | return | ||
141 | 146 | self.static_routes[route] = DirectoryApp(static_path) | ||
142 | 143 | 147 | ||
143 | 144 | def dispatch(self, request): | 148 | def dispatch(self, request): |
144 | 145 | """ | 149 | """ |
145 | 146 | 150 | ||
146 | === modified file 'openlp/core/common/__init__.py' | |||
147 | --- openlp/core/common/__init__.py 2017-08-01 20:59:41 +0000 | |||
148 | +++ openlp/core/common/__init__.py 2017-08-24 19:54:19 +0000 | |||
149 | @@ -32,7 +32,6 @@ | |||
150 | 32 | import traceback | 32 | import traceback |
151 | 33 | from chardet.universaldetector import UniversalDetector | 33 | from chardet.universaldetector import UniversalDetector |
152 | 34 | from ipaddress import IPv4Address, IPv6Address, AddressValueError | 34 | from ipaddress import IPv4Address, IPv6Address, AddressValueError |
153 | 35 | from pathlib import Path | ||
154 | 36 | from shutil import which | 35 | from shutil import which |
155 | 37 | from subprocess import check_output, CalledProcessError, STDOUT | 36 | from subprocess import check_output, CalledProcessError, STDOUT |
156 | 38 | 37 | ||
157 | @@ -65,17 +64,19 @@ | |||
158 | 65 | 64 | ||
159 | 66 | def check_directory_exists(directory, do_not_log=False): | 65 | def check_directory_exists(directory, do_not_log=False): |
160 | 67 | """ | 66 | """ |
162 | 68 | Check a theme directory exists and if not create it | 67 | Check a directory exists and if not create it |
163 | 69 | 68 | ||
166 | 70 | :param directory: The directory to make sure exists | 69 | :param pathlib.Path directory: The directory to make sure exists |
167 | 71 | :param do_not_log: To not log anything. This is need for the start up, when the log isn't ready. | 70 | :param bool do_not_log: To not log anything. This is need for the start up, when the log isn't ready. |
168 | 71 | :return: None | ||
169 | 72 | :rtype: None | ||
170 | 72 | """ | 73 | """ |
171 | 73 | if not do_not_log: | 74 | if not do_not_log: |
172 | 74 | log.debug('check_directory_exists {text}'.format(text=directory)) | 75 | log.debug('check_directory_exists {text}'.format(text=directory)) |
173 | 75 | try: | 76 | try: |
177 | 76 | if not os.path.exists(directory): | 77 | if not directory.exists(): |
178 | 77 | os.makedirs(directory) | 78 | directory.mkdir(parents=True) |
179 | 78 | except IOError as e: | 79 | except IOError: |
180 | 79 | if not do_not_log: | 80 | if not do_not_log: |
181 | 80 | log.exception('failed to check if directory exists or create directory') | 81 | log.exception('failed to check if directory exists or create directory') |
182 | 81 | 82 | ||
183 | @@ -85,19 +86,15 @@ | |||
184 | 85 | A utility function to find and load OpenLP extensions, such as plugins, presentation and media controllers and | 86 | A utility function to find and load OpenLP extensions, such as plugins, presentation and media controllers and |
185 | 86 | importers. | 87 | importers. |
186 | 87 | 88 | ||
194 | 88 | :param glob_pattern: A glob pattern used to find the extension(s) to be imported. Should be relative to the | 89 | :param str glob_pattern: A glob pattern used to find the extension(s) to be imported. Should be relative to the |
195 | 89 | application directory. i.e. openlp/plugins/*/*plugin.py | 90 | application directory. i.e. plugins/*/*plugin.py |
196 | 90 | :type glob_pattern: str | 91 | :param list[str] excluded_files: A list of file names to exclude that the glob pattern may find. |
190 | 91 | |||
191 | 92 | :param excluded_files: A list of file names to exclude that the glob pattern may find. | ||
192 | 93 | :type excluded_files: list of strings | ||
193 | 94 | |||
197 | 95 | :return: None | 92 | :return: None |
198 | 96 | :rtype: None | 93 | :rtype: None |
199 | 97 | """ | 94 | """ |
203 | 98 | base_dir_path = AppLocation.get_directory(AppLocation.AppDir).parent | 95 | app_dir = AppLocation.get_directory(AppLocation.AppDir) |
204 | 99 | for extension_path in base_dir_path.glob(glob_pattern): | 96 | for extension_path in app_dir.glob(glob_pattern): |
205 | 100 | extension_path = extension_path.relative_to(base_dir_path) | 97 | extension_path = extension_path.relative_to(app_dir) |
206 | 101 | if extension_path.name in excluded_files: | 98 | if extension_path.name in excluded_files: |
207 | 102 | continue | 99 | continue |
208 | 103 | module_name = path_to_module(extension_path) | 100 | module_name = path_to_module(extension_path) |
209 | @@ -106,21 +103,19 @@ | |||
210 | 106 | except (ImportError, OSError): | 103 | except (ImportError, OSError): |
211 | 107 | # On some platforms importing vlc.py might cause OSError exceptions. (e.g. Mac OS X) | 104 | # On some platforms importing vlc.py might cause OSError exceptions. (e.g. Mac OS X) |
212 | 108 | log.warning('Failed to import {module_name} on path {extension_path}' | 105 | log.warning('Failed to import {module_name} on path {extension_path}' |
214 | 109 | .format(module_name=module_name, extension_path=str(extension_path))) | 106 | .format(module_name=module_name, extension_path=extension_path)) |
215 | 110 | 107 | ||
216 | 111 | 108 | ||
217 | 112 | def path_to_module(path): | 109 | def path_to_module(path): |
218 | 113 | """ | 110 | """ |
219 | 114 | Convert a path to a module name (i.e openlp.core.common) | 111 | Convert a path to a module name (i.e openlp.core.common) |
220 | 115 | 112 | ||
224 | 116 | :param path: The path to convert to a module name. | 113 | :param pathlib.Path path: The path to convert to a module name. |
222 | 117 | :type path: Path | ||
223 | 118 | |||
225 | 119 | :return: The module name. | 114 | :return: The module name. |
226 | 120 | :rtype: str | 115 | :rtype: str |
227 | 121 | """ | 116 | """ |
228 | 122 | module_path = path.with_suffix('') | 117 | module_path = path.with_suffix('') |
230 | 123 | return '.'.join(module_path.parts) | 118 | return 'openlp.' + '.'.join(module_path.parts) |
231 | 124 | 119 | ||
232 | 125 | 120 | ||
233 | 126 | def get_frozen_path(frozen_option, non_frozen_option): | 121 | def get_frozen_path(frozen_option, non_frozen_option): |
234 | @@ -378,20 +373,22 @@ | |||
235 | 378 | return os.path.split(path) | 373 | return os.path.split(path) |
236 | 379 | 374 | ||
237 | 380 | 375 | ||
239 | 381 | def delete_file(file_path_name): | 376 | def delete_file(file_path): |
240 | 382 | """ | 377 | """ |
241 | 383 | Deletes a file from the system. | 378 | Deletes a file from the system. |
242 | 384 | 379 | ||
244 | 385 | :param file_path_name: The file, including path, to delete. | 380 | :param pathlib.Path file_path: The file, including path, to delete. |
245 | 381 | :return: True if the deletion was successful, or the file never existed. False otherwise. | ||
246 | 382 | :rtype: bool | ||
247 | 386 | """ | 383 | """ |
249 | 387 | if not file_path_name: | 384 | if not file_path: |
250 | 388 | return False | 385 | return False |
251 | 389 | try: | 386 | try: |
254 | 390 | if os.path.exists(file_path_name): | 387 | if file_path.exists(): |
255 | 391 | os.remove(file_path_name) | 388 | file_path.unlink() |
256 | 392 | return True | 389 | return True |
257 | 393 | except (IOError, OSError): | 390 | except (IOError, OSError): |
259 | 394 | log.exception("Unable to delete file {text}".format(text=file_path_name)) | 391 | log.exception('Unable to delete file {file_path}'.format(file_path=file_path)) |
260 | 395 | return False | 392 | return False |
261 | 396 | 393 | ||
262 | 397 | 394 | ||
263 | @@ -411,18 +408,19 @@ | |||
264 | 411 | return IMAGES_FILTER | 408 | return IMAGES_FILTER |
265 | 412 | 409 | ||
266 | 413 | 410 | ||
268 | 414 | def is_not_image_file(file_name): | 411 | def is_not_image_file(file_path): |
269 | 415 | """ | 412 | """ |
270 | 416 | Validate that the file is not an image file. | 413 | Validate that the file is not an image file. |
271 | 417 | 414 | ||
273 | 418 | :param file_name: File name to be checked. | 415 | :param pathlib.Path file_path: The file to be checked. |
274 | 416 | :return: If the file is not an image | ||
275 | 417 | :rtype: bool | ||
276 | 419 | """ | 418 | """ |
278 | 420 | if not file_name: | 419 | if not (file_path and file_path.exists()): |
279 | 421 | return True | 420 | return True |
280 | 422 | else: | 421 | else: |
281 | 423 | formats = [bytes(fmt).decode().lower() for fmt in QtGui.QImageReader.supportedImageFormats()] | 422 | formats = [bytes(fmt).decode().lower() for fmt in QtGui.QImageReader.supportedImageFormats()] |
284 | 424 | file_part, file_extension = os.path.splitext(str(file_name)) | 423 | if file_path.suffix[1:].lower() in formats: |
283 | 425 | if file_extension[1:].lower() in formats and os.path.exists(file_name): | ||
285 | 426 | return False | 424 | return False |
286 | 427 | return True | 425 | return True |
287 | 428 | 426 | ||
288 | @@ -431,10 +429,10 @@ | |||
289 | 431 | """ | 429 | """ |
290 | 432 | Removes invalid characters from the given ``filename``. | 430 | Removes invalid characters from the given ``filename``. |
291 | 433 | 431 | ||
293 | 434 | :param filename: The "dirty" file name to clean. | 432 | :param str filename: The "dirty" file name to clean. |
294 | 433 | :return: The cleaned string | ||
295 | 434 | :rtype: str | ||
296 | 435 | """ | 435 | """ |
297 | 436 | if not isinstance(filename, str): | ||
298 | 437 | filename = str(filename, 'utf-8') | ||
299 | 438 | return INVALID_FILE_CHARS.sub('_', CONTROL_CHARS.sub('', filename)) | 436 | return INVALID_FILE_CHARS.sub('_', CONTROL_CHARS.sub('', filename)) |
300 | 439 | 437 | ||
301 | 440 | 438 | ||
302 | @@ -442,8 +440,9 @@ | |||
303 | 442 | """ | 440 | """ |
304 | 443 | Function that checks whether a binary exists. | 441 | Function that checks whether a binary exists. |
305 | 444 | 442 | ||
307 | 445 | :param program_path: The full path to the binary to check. | 443 | :param pathlib.Path program_path: The full path to the binary to check. |
308 | 446 | :return: program output to be parsed | 444 | :return: program output to be parsed |
309 | 445 | :rtype: bytes | ||
310 | 447 | """ | 446 | """ |
311 | 448 | log.debug('testing program_path: {text}'.format(text=program_path)) | 447 | log.debug('testing program_path: {text}'.format(text=program_path)) |
312 | 449 | try: | 448 | try: |
313 | @@ -453,26 +452,27 @@ | |||
314 | 453 | startupinfo.dwFlags |= STARTF_USESHOWWINDOW | 452 | startupinfo.dwFlags |= STARTF_USESHOWWINDOW |
315 | 454 | else: | 453 | else: |
316 | 455 | startupinfo = None | 454 | startupinfo = None |
318 | 456 | runlog = check_output([program_path, '--help'], stderr=STDOUT, startupinfo=startupinfo) | 455 | run_log = check_output([str(program_path), '--help'], stderr=STDOUT, startupinfo=startupinfo) |
319 | 457 | except CalledProcessError as e: | 456 | except CalledProcessError as e: |
321 | 458 | runlog = e.output | 457 | run_log = e.output |
322 | 459 | except Exception: | 458 | except Exception: |
323 | 460 | trace_error_handler(log) | 459 | trace_error_handler(log) |
330 | 461 | runlog = '' | 460 | run_log = '' |
331 | 462 | log.debug('check_output returned: {text}'.format(text=runlog)) | 461 | log.debug('check_output returned: {text}'.format(text=run_log)) |
332 | 463 | return runlog | 462 | return run_log |
333 | 464 | 463 | ||
334 | 465 | 464 | ||
335 | 466 | def get_file_encoding(filename): | 465 | def get_file_encoding(file_path): |
336 | 467 | """ | 466 | """ |
337 | 468 | Utility function to incrementally detect the file encoding. | 467 | Utility function to incrementally detect the file encoding. |
338 | 469 | 468 | ||
340 | 470 | :param filename: Filename for the file to determine the encoding for. Str | 469 | :param pathlib.Path file_path: Filename for the file to determine the encoding for. |
341 | 471 | :return: A dict with the keys 'encoding' and 'confidence' | 470 | :return: A dict with the keys 'encoding' and 'confidence' |
342 | 471 | :rtype: dict[str, float] | ||
343 | 472 | """ | 472 | """ |
344 | 473 | detector = UniversalDetector() | 473 | detector = UniversalDetector() |
345 | 474 | try: | 474 | try: |
347 | 475 | with open(filename, 'rb') as detect_file: | 475 | with file_path.open('rb') as detect_file: |
348 | 476 | while not detector.done: | 476 | while not detector.done: |
349 | 477 | chunk = detect_file.read(1024) | 477 | chunk = detect_file.read(1024) |
350 | 478 | if not chunk: | 478 | if not chunk: |
351 | 479 | 479 | ||
352 | === modified file 'openlp/core/common/applocation.py' | |||
353 | --- openlp/core/common/applocation.py 2017-08-02 06:09:38 +0000 | |||
354 | +++ openlp/core/common/applocation.py 2017-08-24 19:54:19 +0000 | |||
355 | @@ -58,9 +58,6 @@ | |||
356 | 58 | CacheDir = 5 | 58 | CacheDir = 5 |
357 | 59 | LanguageDir = 6 | 59 | LanguageDir = 6 |
358 | 60 | 60 | ||
359 | 61 | # Base path where data/config/cache dir is located | ||
360 | 62 | BaseDir = None | ||
361 | 63 | |||
362 | 64 | @staticmethod | 61 | @staticmethod |
363 | 65 | def get_directory(dir_type=AppDir): | 62 | def get_directory(dir_type=AppDir): |
364 | 66 | """ | 63 | """ |
365 | @@ -78,8 +75,6 @@ | |||
366 | 78 | return get_frozen_path(FROZEN_APP_PATH, APP_PATH) / 'plugins' | 75 | return get_frozen_path(FROZEN_APP_PATH, APP_PATH) / 'plugins' |
367 | 79 | elif dir_type == AppLocation.LanguageDir: | 76 | elif dir_type == AppLocation.LanguageDir: |
368 | 80 | return get_frozen_path(FROZEN_APP_PATH, _get_os_dir_path(dir_type)) / 'i18n' | 77 | return get_frozen_path(FROZEN_APP_PATH, _get_os_dir_path(dir_type)) / 'i18n' |
369 | 81 | elif dir_type == AppLocation.DataDir and AppLocation.BaseDir: | ||
370 | 82 | return Path(AppLocation.BaseDir, 'data') | ||
371 | 83 | else: | 78 | else: |
372 | 84 | return _get_os_dir_path(dir_type) | 79 | return _get_os_dir_path(dir_type) |
373 | 85 | 80 | ||
374 | @@ -96,7 +91,7 @@ | |||
375 | 96 | path = Path(Settings().value('advanced/data path')) | 91 | path = Path(Settings().value('advanced/data path')) |
376 | 97 | else: | 92 | else: |
377 | 98 | path = AppLocation.get_directory(AppLocation.DataDir) | 93 | path = AppLocation.get_directory(AppLocation.DataDir) |
379 | 99 | check_directory_exists(str(path)) | 94 | check_directory_exists(path) |
380 | 100 | return path | 95 | return path |
381 | 101 | 96 | ||
382 | 102 | @staticmethod | 97 | @staticmethod |
383 | @@ -104,14 +99,10 @@ | |||
384 | 104 | """ | 99 | """ |
385 | 105 | Get a list of files from the data files path. | 100 | Get a list of files from the data files path. |
386 | 106 | 101 | ||
392 | 107 | :param section: Defaults to *None*. The section of code getting the files - used to load from a section's data | 102 | :param None | str section: Defaults to *None*. The section of code getting the files - used to load from a |
393 | 108 | subdirectory. | 103 | section's data subdirectory. |
394 | 109 | :type section: None | str | 104 | :param str extension: Defaults to ''. The extension to search for. For example:: |
390 | 110 | |||
391 | 111 | :param extension: Defaults to ''. The extension to search for. For example:: | ||
395 | 112 | '.png' | 105 | '.png' |
396 | 113 | :type extension: str | ||
397 | 114 | |||
398 | 115 | :return: List of files found. | 106 | :return: List of files found. |
399 | 116 | :rtype: list[pathlib.Path] | 107 | :rtype: list[pathlib.Path] |
400 | 117 | """ | 108 | """ |
401 | @@ -134,7 +125,7 @@ | |||
402 | 134 | :rtype: pathlib.Path | 125 | :rtype: pathlib.Path |
403 | 135 | """ | 126 | """ |
404 | 136 | path = AppLocation.get_data_path() / section | 127 | path = AppLocation.get_data_path() / section |
406 | 137 | check_directory_exists(str(path)) | 128 | check_directory_exists(path) |
407 | 138 | return path | 129 | return path |
408 | 139 | 130 | ||
409 | 140 | 131 | ||
410 | @@ -143,14 +134,12 @@ | |||
411 | 143 | Return a path based on which OS and environment we are running in. | 134 | Return a path based on which OS and environment we are running in. |
412 | 144 | 135 | ||
413 | 145 | :param dir_type: AppLocation Enum of the requested path type | 136 | :param dir_type: AppLocation Enum of the requested path type |
414 | 146 | :type dir_type: AppLocation Enum | ||
415 | 147 | |||
416 | 148 | :return: The requested path | 137 | :return: The requested path |
417 | 149 | :rtype: pathlib.Path | 138 | :rtype: pathlib.Path |
418 | 150 | """ | 139 | """ |
419 | 151 | # If running from source, return the language directory from the source directory | 140 | # If running from source, return the language directory from the source directory |
420 | 152 | if dir_type == AppLocation.LanguageDir: | 141 | if dir_type == AppLocation.LanguageDir: |
422 | 153 | directory = Path(os.path.abspath(os.path.join(os.path.dirname(openlp.__file__), '..', 'resources'))) | 142 | directory = Path(openlp.__file__, '..', '..').resolve() / 'resources' |
423 | 154 | if directory.exists(): | 143 | if directory.exists(): |
424 | 155 | return directory | 144 | return directory |
425 | 156 | if is_win(): | 145 | if is_win(): |
426 | @@ -158,14 +147,14 @@ | |||
427 | 158 | if dir_type == AppLocation.DataDir: | 147 | if dir_type == AppLocation.DataDir: |
428 | 159 | return openlp_folder_path / 'data' | 148 | return openlp_folder_path / 'data' |
429 | 160 | elif dir_type == AppLocation.LanguageDir: | 149 | elif dir_type == AppLocation.LanguageDir: |
431 | 161 | return os.path.dirname(openlp.__file__) | 150 | return Path(openlp.__file__).parent |
432 | 162 | return openlp_folder_path | 151 | return openlp_folder_path |
433 | 163 | elif is_macosx(): | 152 | elif is_macosx(): |
434 | 164 | openlp_folder_path = Path(os.getenv('HOME'), 'Library', 'Application Support', 'openlp') | 153 | openlp_folder_path = Path(os.getenv('HOME'), 'Library', 'Application Support', 'openlp') |
435 | 165 | if dir_type == AppLocation.DataDir: | 154 | if dir_type == AppLocation.DataDir: |
436 | 166 | return openlp_folder_path / 'Data' | 155 | return openlp_folder_path / 'Data' |
437 | 167 | elif dir_type == AppLocation.LanguageDir: | 156 | elif dir_type == AppLocation.LanguageDir: |
439 | 168 | return os.path.dirname(openlp.__file__) | 157 | return Path(openlp.__file__).parent |
440 | 169 | return openlp_folder_path | 158 | return openlp_folder_path |
441 | 170 | else: | 159 | else: |
442 | 171 | if dir_type == AppLocation.LanguageDir: | 160 | if dir_type == AppLocation.LanguageDir: |
443 | 172 | 161 | ||
444 | === modified file 'openlp/core/common/settings.py' | |||
445 | --- openlp/core/common/settings.py 2017-08-23 20:21:11 +0000 | |||
446 | +++ openlp/core/common/settings.py 2017-08-24 19:54:19 +0000 | |||
447 | @@ -502,31 +502,3 @@ | |||
448 | 502 | if isinstance(default_value, int): | 502 | if isinstance(default_value, int): |
449 | 503 | return int(setting) | 503 | return int(setting) |
450 | 504 | return setting | 504 | return setting |
451 | 505 | |||
452 | 506 | def get_files_from_config(self, plugin): | ||
453 | 507 | """ | ||
454 | 508 | This removes the settings needed for old way we saved files (e. g. the image paths for the image plugin). A list | ||
455 | 509 | of file paths are returned. | ||
456 | 510 | |||
457 | 511 | **Note**: Only a list of paths is returned; this does not convert anything! | ||
458 | 512 | |||
459 | 513 | :param plugin: The Plugin object.The caller has to convert/save the list himself; o | ||
460 | 514 | """ | ||
461 | 515 | files_list = [] | ||
462 | 516 | # We need QSettings instead of Settings here to bypass our central settings dict. | ||
463 | 517 | # Do NOT do this anywhere else! | ||
464 | 518 | settings = QtCore.QSettings(self.fileName(), Settings.IniFormat) | ||
465 | 519 | settings.beginGroup(plugin.settings_section) | ||
466 | 520 | if settings.contains('{name} count'.format(name=plugin.name)): | ||
467 | 521 | # Get the count. | ||
468 | 522 | list_count = int(settings.value('{name} count'.format(name=plugin.name), 0)) | ||
469 | 523 | if list_count: | ||
470 | 524 | for counter in range(list_count): | ||
471 | 525 | # The keys were named e. g.: "image 0" | ||
472 | 526 | item = settings.value('{name} {counter:d}'.format(name=plugin.name, counter=counter), '') | ||
473 | 527 | if item: | ||
474 | 528 | files_list.append(item) | ||
475 | 529 | settings.remove('{name} {counter:d}'.format(name=plugin.name, counter=counter)) | ||
476 | 530 | settings.remove('{name} count'.format(name=plugin.name)) | ||
477 | 531 | settings.endGroup() | ||
478 | 532 | return files_list | ||
479 | 533 | 505 | ||
480 | === modified file 'openlp/core/lib/__init__.py' | |||
481 | --- openlp/core/lib/__init__.py 2017-08-23 20:21:11 +0000 | |||
482 | +++ openlp/core/lib/__init__.py 2017-08-24 19:54:19 +0000 | |||
483 | @@ -83,30 +83,28 @@ | |||
484 | 83 | Next = 3 | 83 | Next = 3 |
485 | 84 | 84 | ||
486 | 85 | 85 | ||
488 | 86 | def get_text_file_string(text_file): | 86 | def get_text_file_string(text_file_path): |
489 | 87 | """ | 87 | """ |
491 | 88 | Open a file and return its content as unicode string. If the supplied file name is not a file then the function | 88 | Open a file and return its content as a string. If the supplied file path is not a file then the function |
492 | 89 | returns False. If there is an error loading the file or the content can't be decoded then the function will return | 89 | returns False. If there is an error loading the file or the content can't be decoded then the function will return |
493 | 90 | None. | 90 | None. |
494 | 91 | 91 | ||
497 | 92 | :param text_file: The name of the file. | 92 | :param pathlib.Path text_file_path: The path to the file. |
498 | 93 | :return: The file as a single string | 93 | :return: The contents of the file, False if the file does not exist, or None if there is an Error reading or |
499 | 94 | decoding the file. | ||
500 | 95 | :rtype: str | False | None | ||
501 | 94 | """ | 96 | """ |
503 | 95 | if not os.path.isfile(text_file): | 97 | if not text_file_path.is_file(): |
504 | 96 | return False | 98 | return False |
505 | 97 | file_handle = None | ||
506 | 98 | content = None | 99 | content = None |
507 | 99 | try: | 100 | try: |
513 | 100 | file_handle = open(text_file, 'r', encoding='utf-8') | 101 | with text_file_path.open('r', encoding='utf-8') as file_handle: |
514 | 101 | if file_handle.read(3) != '\xEF\xBB\xBF': | 102 | if file_handle.read(3) != '\xEF\xBB\xBF': |
515 | 102 | # no BOM was found | 103 | # no BOM was found |
516 | 103 | file_handle.seek(0) | 104 | file_handle.seek(0) |
517 | 104 | content = file_handle.read() | 105 | content = file_handle.read() |
518 | 105 | except (IOError, UnicodeError): | 106 | except (IOError, UnicodeError): |
523 | 106 | log.exception('Failed to open text file {text}'.format(text=text_file)) | 107 | log.exception('Failed to open text file {text}'.format(text=text_file_path)) |
520 | 107 | finally: | ||
521 | 108 | if file_handle: | ||
522 | 109 | file_handle.close() | ||
524 | 110 | return content | 108 | return content |
525 | 111 | 109 | ||
526 | 112 | 110 | ||
527 | 113 | 111 | ||
528 | === modified file 'openlp/core/lib/db.py' | |||
529 | --- openlp/core/lib/db.py 2017-08-01 20:59:41 +0000 | |||
530 | +++ openlp/core/lib/db.py 2017-08-24 19:54:19 +0000 | |||
531 | @@ -274,9 +274,9 @@ | |||
532 | 274 | :param db_file_name: The database file name. Defaults to None resulting in the plugin_name being used. | 274 | :param db_file_name: The database file name. Defaults to None resulting in the plugin_name being used. |
533 | 275 | """ | 275 | """ |
534 | 276 | if db_file_name: | 276 | if db_file_name: |
536 | 277 | db_file_path = os.path.join(str(AppLocation.get_section_data_path(plugin_name)), db_file_name) | 277 | db_file_path = AppLocation.get_section_data_path(plugin_name) / db_file_name |
537 | 278 | else: | 278 | else: |
539 | 279 | db_file_path = os.path.join(str(AppLocation.get_section_data_path(plugin_name)), plugin_name) | 279 | db_file_path = AppLocation.get_section_data_path(plugin_name) / plugin_name |
540 | 280 | return delete_file(db_file_path) | 280 | return delete_file(db_file_path) |
541 | 281 | 281 | ||
542 | 282 | 282 | ||
543 | 283 | 283 | ||
544 | === modified file 'openlp/core/lib/pluginmanager.py' | |||
545 | --- openlp/core/lib/pluginmanager.py 2017-08-01 20:59:41 +0000 | |||
546 | +++ openlp/core/lib/pluginmanager.py 2017-08-24 19:54:19 +0000 | |||
547 | @@ -69,7 +69,7 @@ | |||
548 | 69 | """ | 69 | """ |
549 | 70 | Scan a directory for objects inheriting from the ``Plugin`` class. | 70 | Scan a directory for objects inheriting from the ``Plugin`` class. |
550 | 71 | """ | 71 | """ |
552 | 72 | glob_pattern = os.path.join('openlp', 'plugins', '*', '*plugin.py') | 72 | glob_pattern = os.path.join('plugins', '*', '*plugin.py') |
553 | 73 | extension_loader(glob_pattern) | 73 | extension_loader(glob_pattern) |
554 | 74 | plugin_classes = Plugin.__subclasses__() | 74 | plugin_classes = Plugin.__subclasses__() |
555 | 75 | plugin_objects = [] | 75 | plugin_objects = [] |
556 | 76 | 76 | ||
557 | === modified file 'openlp/core/lib/theme.py' | |||
558 | --- openlp/core/lib/theme.py 2017-08-01 20:59:41 +0000 | |||
559 | +++ openlp/core/lib/theme.py 2017-08-24 19:54:19 +0000 | |||
560 | @@ -158,9 +158,8 @@ | |||
561 | 158 | Initialise the theme object. | 158 | Initialise the theme object. |
562 | 159 | """ | 159 | """ |
563 | 160 | # basic theme object with defaults | 160 | # basic theme object with defaults |
567 | 161 | json_dir = os.path.join(str(AppLocation.get_directory(AppLocation.AppDir)), 'core', 'lib', 'json') | 161 | json_path = AppLocation.get_directory(AppLocation.AppDir) / 'core' / 'lib' / 'json' / 'theme.json' |
568 | 162 | json_file = os.path.join(json_dir, 'theme.json') | 162 | jsn = get_text_file_string(json_path) |
566 | 163 | jsn = get_text_file_string(json_file) | ||
569 | 164 | jsn = json.loads(jsn) | 163 | jsn = json.loads(jsn) |
570 | 165 | self.expand_json(jsn) | 164 | self.expand_json(jsn) |
571 | 166 | self.background_filename = '' | 165 | self.background_filename = '' |
572 | 167 | 166 | ||
573 | === modified file 'openlp/core/ui/firsttimeform.py' | |||
574 | --- openlp/core/ui/firsttimeform.py 2017-08-03 17:54:40 +0000 | |||
575 | +++ openlp/core/ui/firsttimeform.py 2017-08-24 19:54:19 +0000 | |||
576 | @@ -29,8 +29,9 @@ | |||
577 | 29 | import urllib.request | 29 | import urllib.request |
578 | 30 | import urllib.parse | 30 | import urllib.parse |
579 | 31 | import urllib.error | 31 | import urllib.error |
580 | 32 | from configparser import ConfigParser, MissingSectionHeaderError, NoOptionError, NoSectionError | ||
581 | 33 | from pathlib import Path | ||
582 | 32 | from tempfile import gettempdir | 34 | from tempfile import gettempdir |
583 | 33 | from configparser import ConfigParser, MissingSectionHeaderError, NoSectionError, NoOptionError | ||
584 | 34 | 35 | ||
585 | 35 | from PyQt5 import QtCore, QtWidgets | 36 | from PyQt5 import QtCore, QtWidgets |
586 | 36 | 37 | ||
587 | @@ -282,7 +283,7 @@ | |||
588 | 282 | self.no_internet_cancel_button.setVisible(False) | 283 | self.no_internet_cancel_button.setVisible(False) |
589 | 283 | # Check if this is a re-run of the wizard. | 284 | # Check if this is a re-run of the wizard. |
590 | 284 | self.has_run_wizard = Settings().value('core/has run wizard') | 285 | self.has_run_wizard = Settings().value('core/has run wizard') |
592 | 285 | check_directory_exists(os.path.join(gettempdir(), 'openlp')) | 286 | check_directory_exists(Path(gettempdir(), 'openlp')) |
593 | 286 | 287 | ||
594 | 287 | def update_screen_list_combo(self): | 288 | def update_screen_list_combo(self): |
595 | 288 | """ | 289 | """ |
596 | 289 | 290 | ||
597 | === modified file 'openlp/core/ui/mainwindow.py' | |||
598 | --- openlp/core/ui/mainwindow.py 2017-08-03 17:54:40 +0000 | |||
599 | +++ openlp/core/ui/mainwindow.py 2017-08-24 19:54:19 +0000 | |||
600 | @@ -30,6 +30,7 @@ | |||
601 | 30 | from datetime import datetime | 30 | from datetime import datetime |
602 | 31 | from distutils import dir_util | 31 | from distutils import dir_util |
603 | 32 | from distutils.errors import DistutilsFileError | 32 | from distutils.errors import DistutilsFileError |
604 | 33 | from pathlib import Path | ||
605 | 33 | from tempfile import gettempdir | 34 | from tempfile import gettempdir |
606 | 34 | 35 | ||
607 | 35 | from PyQt5 import QtCore, QtGui, QtWidgets | 36 | from PyQt5 import QtCore, QtGui, QtWidgets |
608 | @@ -870,7 +871,7 @@ | |||
609 | 870 | setting_sections.extend([plugin.name for plugin in self.plugin_manager.plugins]) | 871 | setting_sections.extend([plugin.name for plugin in self.plugin_manager.plugins]) |
610 | 871 | # Copy the settings file to the tmp dir, because we do not want to change the original one. | 872 | # Copy the settings file to the tmp dir, because we do not want to change the original one. |
611 | 872 | temp_directory = os.path.join(str(gettempdir()), 'openlp') | 873 | temp_directory = os.path.join(str(gettempdir()), 'openlp') |
613 | 873 | check_directory_exists(temp_directory) | 874 | check_directory_exists(Path(temp_directory)) |
614 | 874 | temp_config = os.path.join(temp_directory, os.path.basename(import_file_name)) | 875 | temp_config = os.path.join(temp_directory, os.path.basename(import_file_name)) |
615 | 875 | shutil.copyfile(import_file_name, temp_config) | 876 | shutil.copyfile(import_file_name, temp_config) |
616 | 876 | settings = Settings() | 877 | settings = Settings() |
617 | 877 | 878 | ||
618 | === modified file 'openlp/core/ui/media/mediacontroller.py' | |||
619 | --- openlp/core/ui/media/mediacontroller.py 2017-06-25 17:03:31 +0000 | |||
620 | +++ openlp/core/ui/media/mediacontroller.py 2017-08-24 19:54:19 +0000 | |||
621 | @@ -177,7 +177,7 @@ | |||
622 | 177 | Check to see if we have any media Player's available. | 177 | Check to see if we have any media Player's available. |
623 | 178 | """ | 178 | """ |
624 | 179 | log.debug('_check_available_media_players') | 179 | log.debug('_check_available_media_players') |
626 | 180 | controller_dir = os.path.join('openlp', 'core', 'ui', 'media') | 180 | controller_dir = os.path.join('core', 'ui', 'media') |
627 | 181 | glob_pattern = os.path.join(controller_dir, '*player.py') | 181 | glob_pattern = os.path.join(controller_dir, '*player.py') |
628 | 182 | extension_loader(glob_pattern, ['mediaplayer.py']) | 182 | extension_loader(glob_pattern, ['mediaplayer.py']) |
629 | 183 | player_classes = MediaPlayer.__subclasses__() | 183 | player_classes = MediaPlayer.__subclasses__() |
630 | 184 | 184 | ||
631 | === modified file 'openlp/core/ui/printserviceform.py' | |||
632 | --- openlp/core/ui/printserviceform.py 2017-08-01 20:59:41 +0000 | |||
633 | +++ openlp/core/ui/printserviceform.py 2017-08-24 19:54:19 +0000 | |||
634 | @@ -176,7 +176,7 @@ | |||
635 | 176 | html_data = self._add_element('html') | 176 | html_data = self._add_element('html') |
636 | 177 | self._add_element('head', parent=html_data) | 177 | self._add_element('head', parent=html_data) |
637 | 178 | self._add_element('title', self.title_line_edit.text(), html_data.head) | 178 | self._add_element('title', self.title_line_edit.text(), html_data.head) |
639 | 179 | css_path = os.path.join(str(AppLocation.get_data_path()), 'serviceprint', 'service_print.css') | 179 | css_path = AppLocation.get_data_path() / 'serviceprint' / 'service_print.css' |
640 | 180 | custom_css = get_text_file_string(css_path) | 180 | custom_css = get_text_file_string(css_path) |
641 | 181 | if not custom_css: | 181 | if not custom_css: |
642 | 182 | custom_css = DEFAULT_CSS | 182 | custom_css = DEFAULT_CSS |
643 | 183 | 183 | ||
644 | === modified file 'openlp/core/ui/servicemanager.py' | |||
645 | --- openlp/core/ui/servicemanager.py 2017-08-03 17:54:40 +0000 | |||
646 | +++ openlp/core/ui/servicemanager.py 2017-08-24 19:54:19 +0000 | |||
647 | @@ -28,6 +28,7 @@ | |||
648 | 28 | import shutil | 28 | import shutil |
649 | 29 | import zipfile | 29 | import zipfile |
650 | 30 | from datetime import datetime, timedelta | 30 | from datetime import datetime, timedelta |
651 | 31 | from pathlib import Path | ||
652 | 31 | from tempfile import mkstemp | 32 | from tempfile import mkstemp |
653 | 32 | 33 | ||
654 | 33 | from PyQt5 import QtCore, QtGui, QtWidgets | 34 | from PyQt5 import QtCore, QtGui, QtWidgets |
655 | @@ -587,7 +588,7 @@ | |||
656 | 587 | audio_from = os.path.join(self.service_path, audio_from) | 588 | audio_from = os.path.join(self.service_path, audio_from) |
657 | 588 | save_file = os.path.join(self.service_path, audio_to) | 589 | save_file = os.path.join(self.service_path, audio_to) |
658 | 589 | save_path = os.path.split(save_file)[0] | 590 | save_path = os.path.split(save_file)[0] |
660 | 590 | check_directory_exists(save_path) | 591 | check_directory_exists(Path(save_path)) |
661 | 591 | if not os.path.exists(save_file): | 592 | if not os.path.exists(save_file): |
662 | 592 | shutil.copy(audio_from, save_file) | 593 | shutil.copy(audio_from, save_file) |
663 | 593 | zip_file.write(audio_from, audio_to) | 594 | zip_file.write(audio_from, audio_to) |
664 | @@ -614,7 +615,7 @@ | |||
665 | 614 | success = False | 615 | success = False |
666 | 615 | self.main_window.add_recent_file(path_file_name) | 616 | self.main_window.add_recent_file(path_file_name) |
667 | 616 | self.set_modified(False) | 617 | self.set_modified(False) |
669 | 617 | delete_file(temp_file_name) | 618 | delete_file(Path(temp_file_name)) |
670 | 618 | return success | 619 | return success |
671 | 619 | 620 | ||
672 | 620 | def save_local_file(self): | 621 | def save_local_file(self): |
673 | @@ -669,7 +670,7 @@ | |||
674 | 669 | return self.save_file_as() | 670 | return self.save_file_as() |
675 | 670 | self.main_window.add_recent_file(path_file_name) | 671 | self.main_window.add_recent_file(path_file_name) |
676 | 671 | self.set_modified(False) | 672 | self.set_modified(False) |
678 | 672 | delete_file(temp_file_name) | 673 | delete_file(Path(temp_file_name)) |
679 | 673 | return success | 674 | return success |
680 | 674 | 675 | ||
681 | 675 | def save_file_as(self, field=None): | 676 | def save_file_as(self, field=None): |
682 | @@ -774,7 +775,7 @@ | |||
683 | 774 | self.set_file_name(file_name) | 775 | self.set_file_name(file_name) |
684 | 775 | self.main_window.display_progress_bar(len(items)) | 776 | self.main_window.display_progress_bar(len(items)) |
685 | 776 | self.process_service_items(items) | 777 | self.process_service_items(items) |
687 | 777 | delete_file(p_file) | 778 | delete_file(Path(p_file)) |
688 | 778 | self.main_window.add_recent_file(file_name) | 779 | self.main_window.add_recent_file(file_name) |
689 | 779 | self.set_modified(False) | 780 | self.set_modified(False) |
690 | 780 | Settings().setValue('servicemanager/last file', file_name) | 781 | Settings().setValue('servicemanager/last file', file_name) |
691 | @@ -1343,7 +1344,7 @@ | |||
692 | 1343 | Empties the service_path of temporary files on system exit. | 1344 | Empties the service_path of temporary files on system exit. |
693 | 1344 | """ | 1345 | """ |
694 | 1345 | for file_name in os.listdir(self.service_path): | 1346 | for file_name in os.listdir(self.service_path): |
696 | 1346 | file_path = os.path.join(self.service_path, file_name) | 1347 | file_path = Path(self.service_path, file_name) |
697 | 1347 | delete_file(file_path) | 1348 | delete_file(file_path) |
698 | 1348 | if os.path.exists(os.path.join(self.service_path, 'audio')): | 1349 | if os.path.exists(os.path.join(self.service_path, 'audio')): |
699 | 1349 | shutil.rmtree(os.path.join(self.service_path, 'audio'), True) | 1350 | shutil.rmtree(os.path.join(self.service_path, 'audio'), True) |
700 | 1350 | 1351 | ||
701 | === modified file 'openlp/core/ui/themeform.py' | |||
702 | --- openlp/core/ui/themeform.py 2017-08-07 20:50:01 +0000 | |||
703 | +++ openlp/core/ui/themeform.py 2017-08-24 19:54:19 +0000 | |||
704 | @@ -24,6 +24,7 @@ | |||
705 | 24 | """ | 24 | """ |
706 | 25 | import logging | 25 | import logging |
707 | 26 | import os | 26 | import os |
708 | 27 | from pathlib import Path | ||
709 | 27 | 28 | ||
710 | 28 | from PyQt5 import QtCore, QtGui, QtWidgets | 29 | from PyQt5 import QtCore, QtGui, QtWidgets |
711 | 29 | 30 | ||
712 | @@ -188,7 +189,8 @@ | |||
713 | 188 | """ | 189 | """ |
714 | 189 | background_image = BackgroundType.to_string(BackgroundType.Image) | 190 | background_image = BackgroundType.to_string(BackgroundType.Image) |
715 | 190 | if self.page(self.currentId()) == self.background_page and \ | 191 | if self.page(self.currentId()) == self.background_page and \ |
717 | 191 | self.theme.background_type == background_image and is_not_image_file(self.theme.background_filename): | 192 | self.theme.background_type == background_image and \ |
718 | 193 | is_not_image_file(Path(self.theme.background_filename)): | ||
719 | 192 | QtWidgets.QMessageBox.critical(self, translate('OpenLP.ThemeWizard', 'Background Image Empty'), | 194 | QtWidgets.QMessageBox.critical(self, translate('OpenLP.ThemeWizard', 'Background Image Empty'), |
720 | 193 | translate('OpenLP.ThemeWizard', 'You have not selected a ' | 195 | translate('OpenLP.ThemeWizard', 'You have not selected a ' |
721 | 194 | 'background image. Please select one before continuing.')) | 196 | 'background image. Please select one before continuing.')) |
722 | 195 | 197 | ||
723 | === modified file 'openlp/core/ui/thememanager.py' | |||
724 | --- openlp/core/ui/thememanager.py 2017-08-07 20:50:01 +0000 | |||
725 | +++ openlp/core/ui/thememanager.py 2017-08-24 19:54:19 +0000 | |||
726 | @@ -25,6 +25,7 @@ | |||
727 | 25 | import os | 25 | import os |
728 | 26 | import zipfile | 26 | import zipfile |
729 | 27 | import shutil | 27 | import shutil |
730 | 28 | from pathlib import Path | ||
731 | 28 | 29 | ||
732 | 29 | from xml.etree.ElementTree import ElementTree, XML | 30 | from xml.etree.ElementTree import ElementTree, XML |
733 | 30 | from PyQt5 import QtCore, QtGui, QtWidgets | 31 | from PyQt5 import QtCore, QtGui, QtWidgets |
734 | @@ -161,9 +162,9 @@ | |||
735 | 161 | Set up the theme path variables | 162 | Set up the theme path variables |
736 | 162 | """ | 163 | """ |
737 | 163 | self.path = str(AppLocation.get_section_data_path(self.settings_section)) | 164 | self.path = str(AppLocation.get_section_data_path(self.settings_section)) |
739 | 164 | check_directory_exists(self.path) | 165 | check_directory_exists(Path(self.path)) |
740 | 165 | self.thumb_path = os.path.join(self.path, 'thumbnails') | 166 | self.thumb_path = os.path.join(self.path, 'thumbnails') |
742 | 166 | check_directory_exists(self.thumb_path) | 167 | check_directory_exists(Path(self.thumb_path)) |
743 | 167 | 168 | ||
744 | 168 | def check_list_state(self, item, field=None): | 169 | def check_list_state(self, item, field=None): |
745 | 169 | """ | 170 | """ |
746 | @@ -355,8 +356,8 @@ | |||
747 | 355 | """ | 356 | """ |
748 | 356 | self.theme_list.remove(theme) | 357 | self.theme_list.remove(theme) |
749 | 357 | thumb = '{name}.png'.format(name=theme) | 358 | thumb = '{name}.png'.format(name=theme) |
752 | 358 | delete_file(os.path.join(self.path, thumb)) | 359 | delete_file(Path(self.path, thumb)) |
753 | 359 | delete_file(os.path.join(self.thumb_path, thumb)) | 360 | delete_file(Path(self.thumb_path, thumb)) |
754 | 360 | try: | 361 | try: |
755 | 361 | # Windows is always unicode, so no need to encode filenames | 362 | # Windows is always unicode, so no need to encode filenames |
756 | 362 | if is_win(): | 363 | if is_win(): |
757 | @@ -450,7 +451,7 @@ | |||
758 | 450 | for theme_file in files: | 451 | for theme_file in files: |
759 | 451 | theme_file = os.path.join(self.path, str(theme_file)) | 452 | theme_file = os.path.join(self.path, str(theme_file)) |
760 | 452 | self.unzip_theme(theme_file, self.path) | 453 | self.unzip_theme(theme_file, self.path) |
762 | 453 | delete_file(theme_file) | 454 | delete_file(Path(theme_file)) |
763 | 454 | files = AppLocation.get_files(self.settings_section, '.png') | 455 | files = AppLocation.get_files(self.settings_section, '.png') |
764 | 455 | # No themes have been found so create one | 456 | # No themes have been found so create one |
765 | 456 | if not files: | 457 | if not files: |
766 | @@ -514,12 +515,12 @@ | |||
767 | 514 | :return: The theme object. | 515 | :return: The theme object. |
768 | 515 | """ | 516 | """ |
769 | 516 | self.log_debug('get theme data for theme {name}'.format(name=theme_name)) | 517 | self.log_debug('get theme data for theme {name}'.format(name=theme_name)) |
772 | 517 | theme_file = os.path.join(self.path, str(theme_name), str(theme_name) + '.json') | 518 | theme_file_path = Path(self.path, str(theme_name), '{file_name}.json'.format(file_name=theme_name)) |
773 | 518 | theme_data = get_text_file_string(theme_file) | 519 | theme_data = get_text_file_string(theme_file_path) |
774 | 519 | jsn = True | 520 | jsn = True |
775 | 520 | if not theme_data: | 521 | if not theme_data: |
778 | 521 | theme_file = os.path.join(self.path, str(theme_name), str(theme_name) + '.xml') | 522 | theme_file_path = theme_file_path.with_suffix('.xml') |
779 | 522 | theme_data = get_text_file_string(theme_file) | 523 | theme_data = get_text_file_string(theme_file_path) |
780 | 523 | jsn = False | 524 | jsn = False |
781 | 524 | if not theme_data: | 525 | if not theme_data: |
782 | 525 | self.log_debug('No theme data - using default theme') | 526 | self.log_debug('No theme data - using default theme') |
783 | @@ -592,7 +593,7 @@ | |||
784 | 592 | # is directory or preview file | 593 | # is directory or preview file |
785 | 593 | continue | 594 | continue |
786 | 594 | full_name = os.path.join(directory, out_name) | 595 | full_name = os.path.join(directory, out_name) |
788 | 595 | check_directory_exists(os.path.dirname(full_name)) | 596 | check_directory_exists(Path(os.path.dirname(full_name))) |
789 | 596 | if os.path.splitext(name)[1].lower() == '.xml' or os.path.splitext(name)[1].lower() == '.json': | 597 | if os.path.splitext(name)[1].lower() == '.xml' or os.path.splitext(name)[1].lower() == '.json': |
790 | 597 | file_xml = str(theme_zip.read(name), 'utf-8') | 598 | file_xml = str(theme_zip.read(name), 'utf-8') |
791 | 598 | out_file = open(full_name, 'w', encoding='utf-8') | 599 | out_file = open(full_name, 'w', encoding='utf-8') |
792 | @@ -670,10 +671,10 @@ | |||
793 | 670 | name = theme.theme_name | 671 | name = theme.theme_name |
794 | 671 | theme_pretty = theme.export_theme() | 672 | theme_pretty = theme.export_theme() |
795 | 672 | theme_dir = os.path.join(self.path, name) | 673 | theme_dir = os.path.join(self.path, name) |
797 | 673 | check_directory_exists(theme_dir) | 674 | check_directory_exists(Path(theme_dir)) |
798 | 674 | theme_file = os.path.join(theme_dir, name + '.json') | 675 | theme_file = os.path.join(theme_dir, name + '.json') |
799 | 675 | if self.old_background_image and image_to != self.old_background_image: | 676 | if self.old_background_image and image_to != self.old_background_image: |
801 | 676 | delete_file(self.old_background_image) | 677 | delete_file(Path(self.old_background_image)) |
802 | 677 | out_file = None | 678 | out_file = None |
803 | 678 | try: | 679 | try: |
804 | 679 | out_file = open(theme_file, 'w', encoding='utf-8') | 680 | out_file = open(theme_file, 'w', encoding='utf-8') |
805 | 680 | 681 | ||
806 | === modified file 'openlp/plugins/bibles/lib/importers/csvbible.py' | |||
807 | --- openlp/plugins/bibles/lib/importers/csvbible.py 2016-12-31 11:01:36 +0000 | |||
808 | +++ openlp/plugins/bibles/lib/importers/csvbible.py 2017-08-24 19:54:19 +0000 | |||
809 | @@ -51,6 +51,7 @@ | |||
810 | 51 | """ | 51 | """ |
811 | 52 | import csv | 52 | import csv |
812 | 53 | from collections import namedtuple | 53 | from collections import namedtuple |
813 | 54 | from pathlib import Path | ||
814 | 54 | 55 | ||
815 | 55 | from openlp.core.common import get_file_encoding, translate | 56 | from openlp.core.common import get_file_encoding, translate |
816 | 56 | from openlp.core.lib.exceptions import ValidationError | 57 | from openlp.core.lib.exceptions import ValidationError |
817 | @@ -100,7 +101,7 @@ | |||
818 | 100 | :return: An iterable yielding namedtuples of type results_tuple | 101 | :return: An iterable yielding namedtuples of type results_tuple |
819 | 101 | """ | 102 | """ |
820 | 102 | try: | 103 | try: |
822 | 103 | encoding = get_file_encoding(filename)['encoding'] | 104 | encoding = get_file_encoding(Path(filename))['encoding'] |
823 | 104 | with open(filename, 'r', encoding=encoding, newline='') as csv_file: | 105 | with open(filename, 'r', encoding=encoding, newline='') as csv_file: |
824 | 105 | csv_reader = csv.reader(csv_file, delimiter=',', quotechar='"') | 106 | csv_reader = csv.reader(csv_file, delimiter=',', quotechar='"') |
825 | 106 | return [results_tuple(*line) for line in csv_reader] | 107 | return [results_tuple(*line) for line in csv_reader] |
826 | 107 | 108 | ||
827 | === modified file 'openlp/plugins/bibles/lib/manager.py' | |||
828 | --- openlp/plugins/bibles/lib/manager.py 2017-08-01 20:59:41 +0000 | |||
829 | +++ openlp/plugins/bibles/lib/manager.py 2017-08-24 19:54:19 +0000 | |||
830 | @@ -22,6 +22,7 @@ | |||
831 | 22 | 22 | ||
832 | 23 | import logging | 23 | import logging |
833 | 24 | import os | 24 | import os |
834 | 25 | from pathlib import Path | ||
835 | 25 | 26 | ||
836 | 26 | from openlp.core.common import AppLocation, OpenLPMixin, RegistryProperties, Settings, translate, delete_file, UiStrings | 27 | from openlp.core.common import AppLocation, OpenLPMixin, RegistryProperties, Settings, translate, delete_file, UiStrings |
837 | 27 | from openlp.plugins.bibles.lib import LanguageSelection, parse_reference | 28 | from openlp.plugins.bibles.lib import LanguageSelection, parse_reference |
838 | @@ -137,7 +138,7 @@ | |||
839 | 137 | # Remove corrupted files. | 138 | # Remove corrupted files. |
840 | 138 | if name is None: | 139 | if name is None: |
841 | 139 | bible.session.close_all() | 140 | bible.session.close_all() |
843 | 140 | delete_file(os.path.join(self.path, filename)) | 141 | delete_file(Path(self.path, filename)) |
844 | 141 | continue | 142 | continue |
845 | 142 | log.debug('Bible Name: "{name}"'.format(name=name)) | 143 | log.debug('Bible Name: "{name}"'.format(name=name)) |
846 | 143 | self.db_cache[name] = bible | 144 | self.db_cache[name] = bible |
847 | @@ -185,7 +186,7 @@ | |||
848 | 185 | bible = self.db_cache[name] | 186 | bible = self.db_cache[name] |
849 | 186 | bible.session.close_all() | 187 | bible.session.close_all() |
850 | 187 | bible.session = None | 188 | bible.session = None |
852 | 188 | return delete_file(os.path.join(bible.path, bible.file)) | 189 | return delete_file(Path(bible.path, bible.file)) |
853 | 189 | 190 | ||
854 | 190 | def get_bibles(self): | 191 | def get_bibles(self): |
855 | 191 | """ | 192 | """ |
856 | 192 | 193 | ||
857 | === modified file 'openlp/plugins/images/lib/mediaitem.py' | |||
858 | --- openlp/plugins/images/lib/mediaitem.py 2017-08-03 17:54:40 +0000 | |||
859 | +++ openlp/plugins/images/lib/mediaitem.py 2017-08-24 19:54:19 +0000 | |||
860 | @@ -22,6 +22,7 @@ | |||
861 | 22 | 22 | ||
862 | 23 | import logging | 23 | import logging |
863 | 24 | import os | 24 | import os |
864 | 25 | from pathlib import Path | ||
865 | 25 | 26 | ||
866 | 26 | from PyQt5 import QtCore, QtGui, QtWidgets | 27 | from PyQt5 import QtCore, QtGui, QtWidgets |
867 | 27 | 28 | ||
868 | @@ -99,7 +100,7 @@ | |||
869 | 99 | self.list_view.setIndentation(self.list_view.default_indentation) | 100 | self.list_view.setIndentation(self.list_view.default_indentation) |
870 | 100 | self.list_view.allow_internal_dnd = True | 101 | self.list_view.allow_internal_dnd = True |
871 | 101 | self.service_path = os.path.join(str(AppLocation.get_section_data_path(self.settings_section)), 'thumbnails') | 102 | self.service_path = os.path.join(str(AppLocation.get_section_data_path(self.settings_section)), 'thumbnails') |
873 | 102 | check_directory_exists(self.service_path) | 103 | check_directory_exists(Path(self.service_path)) |
874 | 103 | # Load images from the database | 104 | # Load images from the database |
875 | 104 | self.load_full_list( | 105 | self.load_full_list( |
876 | 105 | self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename), initial_load=True) | 106 | self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename), initial_load=True) |
877 | @@ -210,8 +211,8 @@ | |||
878 | 210 | """ | 211 | """ |
879 | 211 | images = self.manager.get_all_objects(ImageFilenames, ImageFilenames.group_id == image_group.id) | 212 | images = self.manager.get_all_objects(ImageFilenames, ImageFilenames.group_id == image_group.id) |
880 | 212 | for image in images: | 213 | for image in images: |
883 | 213 | delete_file(os.path.join(self.service_path, os.path.split(image.filename)[1])) | 214 | delete_file(Path(self.service_path, os.path.split(image.filename)[1])) |
884 | 214 | delete_file(self.generate_thumbnail_path(image)) | 215 | delete_file(Path(self.generate_thumbnail_path(image))) |
885 | 215 | self.manager.delete_object(ImageFilenames, image.id) | 216 | self.manager.delete_object(ImageFilenames, image.id) |
886 | 216 | image_groups = self.manager.get_all_objects(ImageGroups, ImageGroups.parent_id == image_group.id) | 217 | image_groups = self.manager.get_all_objects(ImageGroups, ImageGroups.parent_id == image_group.id) |
887 | 217 | for group in image_groups: | 218 | for group in image_groups: |
888 | @@ -233,8 +234,8 @@ | |||
889 | 233 | if row_item: | 234 | if row_item: |
890 | 234 | item_data = row_item.data(0, QtCore.Qt.UserRole) | 235 | item_data = row_item.data(0, QtCore.Qt.UserRole) |
891 | 235 | if isinstance(item_data, ImageFilenames): | 236 | if isinstance(item_data, ImageFilenames): |
894 | 236 | delete_file(os.path.join(self.service_path, row_item.text(0))) | 237 | delete_file(Path(self.service_path, row_item.text(0))) |
895 | 237 | delete_file(self.generate_thumbnail_path(item_data)) | 238 | delete_file(Path(self.generate_thumbnail_path(item_data))) |
896 | 238 | if item_data.group_id == 0: | 239 | if item_data.group_id == 0: |
897 | 239 | self.list_view.takeTopLevelItem(self.list_view.indexOfTopLevelItem(row_item)) | 240 | self.list_view.takeTopLevelItem(self.list_view.indexOfTopLevelItem(row_item)) |
898 | 240 | else: | 241 | else: |
899 | 241 | 242 | ||
900 | === modified file 'openlp/plugins/media/lib/mediaitem.py' | |||
901 | --- openlp/plugins/media/lib/mediaitem.py 2017-08-03 17:54:40 +0000 | |||
902 | +++ openlp/plugins/media/lib/mediaitem.py 2017-08-24 19:54:19 +0000 | |||
903 | @@ -22,6 +22,7 @@ | |||
904 | 22 | 22 | ||
905 | 23 | import logging | 23 | import logging |
906 | 24 | import os | 24 | import os |
907 | 25 | from pathlib import Path | ||
908 | 25 | 26 | ||
909 | 26 | from PyQt5 import QtCore, QtWidgets | 27 | from PyQt5 import QtCore, QtWidgets |
910 | 27 | 28 | ||
911 | @@ -301,7 +302,7 @@ | |||
912 | 301 | """ | 302 | """ |
913 | 302 | self.list_view.clear() | 303 | self.list_view.clear() |
914 | 303 | self.service_path = os.path.join(str(AppLocation.get_section_data_path(self.settings_section)), 'thumbnails') | 304 | self.service_path = os.path.join(str(AppLocation.get_section_data_path(self.settings_section)), 'thumbnails') |
916 | 304 | check_directory_exists(self.service_path) | 305 | check_directory_exists(Path(self.service_path)) |
917 | 305 | self.load_list(Settings().value(self.settings_section + '/media files')) | 306 | self.load_list(Settings().value(self.settings_section + '/media files')) |
918 | 306 | self.rebuild_players() | 307 | self.rebuild_players() |
919 | 307 | 308 | ||
920 | 308 | 309 | ||
921 | === modified file 'openlp/plugins/media/mediaplugin.py' | |||
922 | --- openlp/plugins/media/mediaplugin.py 2017-08-03 17:54:40 +0000 | |||
923 | +++ openlp/plugins/media/mediaplugin.py 2017-08-24 19:54:19 +0000 | |||
924 | @@ -26,6 +26,7 @@ | |||
925 | 26 | import logging | 26 | import logging |
926 | 27 | import os | 27 | import os |
927 | 28 | import re | 28 | import re |
928 | 29 | from pathlib import Path | ||
929 | 29 | 30 | ||
930 | 30 | from PyQt5 import QtCore | 31 | from PyQt5 import QtCore |
931 | 31 | 32 | ||
932 | @@ -165,8 +166,7 @@ | |||
933 | 165 | :param program_path:The full path to the binary to check. | 166 | :param program_path:The full path to the binary to check. |
934 | 166 | :return: If exists or not | 167 | :return: If exists or not |
935 | 167 | """ | 168 | """ |
938 | 168 | program_type = None | 169 | runlog = check_binary_exists(Path(program_path)) |
937 | 169 | runlog = check_binary_exists(program_path) | ||
939 | 170 | # Analyse the output to see it the program is mediainfo | 170 | # Analyse the output to see it the program is mediainfo |
940 | 171 | for line in runlog.splitlines(): | 171 | for line in runlog.splitlines(): |
941 | 172 | decoded_line = line.decode() | 172 | decoded_line = line.decode() |
942 | 173 | 173 | ||
943 | === modified file 'openlp/plugins/presentations/lib/impresscontroller.py' | |||
944 | --- openlp/plugins/presentations/lib/impresscontroller.py 2017-05-14 10:11:10 +0000 | |||
945 | +++ openlp/plugins/presentations/lib/impresscontroller.py 2017-08-24 19:54:19 +0000 | |||
946 | @@ -34,6 +34,7 @@ | |||
947 | 34 | import logging | 34 | import logging |
948 | 35 | import os | 35 | import os |
949 | 36 | import time | 36 | import time |
950 | 37 | from pathlib import Path | ||
951 | 37 | 38 | ||
952 | 38 | from openlp.core.common import is_win, Registry, get_uno_command, get_uno_instance, delete_file | 39 | from openlp.core.common import is_win, Registry, get_uno_command, get_uno_instance, delete_file |
953 | 39 | 40 | ||
954 | @@ -275,7 +276,7 @@ | |||
955 | 275 | try: | 276 | try: |
956 | 276 | doc.storeToURL(url_path, properties) | 277 | doc.storeToURL(url_path, properties) |
957 | 277 | self.convert_thumbnail(path, index + 1) | 278 | self.convert_thumbnail(path, index + 1) |
959 | 278 | delete_file(path) | 279 | delete_file(Path(path)) |
960 | 279 | except ErrorCodeIOException as exception: | 280 | except ErrorCodeIOException as exception: |
961 | 280 | log.exception('ERROR! ErrorCodeIOException {error:d}'.format(error=exception.ErrCode)) | 281 | log.exception('ERROR! ErrorCodeIOException {error:d}'.format(error=exception.ErrCode)) |
962 | 281 | except: | 282 | except: |
963 | 282 | 283 | ||
964 | === modified file 'openlp/plugins/presentations/lib/pdfcontroller.py' | |||
965 | --- openlp/plugins/presentations/lib/pdfcontroller.py 2017-08-01 20:59:41 +0000 | |||
966 | +++ openlp/plugins/presentations/lib/pdfcontroller.py 2017-08-24 19:54:19 +0000 | |||
967 | @@ -23,6 +23,7 @@ | |||
968 | 23 | import os | 23 | import os |
969 | 24 | import logging | 24 | import logging |
970 | 25 | import re | 25 | import re |
971 | 26 | from pathlib import Path | ||
972 | 26 | from shutil import which | 27 | from shutil import which |
973 | 27 | from subprocess import check_output, CalledProcessError | 28 | from subprocess import check_output, CalledProcessError |
974 | 28 | 29 | ||
975 | @@ -69,7 +70,7 @@ | |||
976 | 69 | :return: Type of the binary, 'gs' if ghostscript, 'mudraw' if mudraw, None if invalid. | 70 | :return: Type of the binary, 'gs' if ghostscript, 'mudraw' if mudraw, None if invalid. |
977 | 70 | """ | 71 | """ |
978 | 71 | program_type = None | 72 | program_type = None |
980 | 72 | runlog = check_binary_exists(program_path) | 73 | runlog = check_binary_exists(Path(program_path)) |
981 | 73 | # Analyse the output to see it the program is mudraw, ghostscript or neither | 74 | # Analyse the output to see it the program is mudraw, ghostscript or neither |
982 | 74 | for line in runlog.splitlines(): | 75 | for line in runlog.splitlines(): |
983 | 75 | decoded_line = line.decode() | 76 | decoded_line = line.decode() |
984 | 76 | 77 | ||
985 | === modified file 'openlp/plugins/presentations/lib/presentationcontroller.py' | |||
986 | --- openlp/plugins/presentations/lib/presentationcontroller.py 2017-08-01 20:59:41 +0000 | |||
987 | +++ openlp/plugins/presentations/lib/presentationcontroller.py 2017-08-24 19:54:19 +0000 | |||
988 | @@ -23,6 +23,7 @@ | |||
989 | 23 | import logging | 23 | import logging |
990 | 24 | import os | 24 | import os |
991 | 25 | import shutil | 25 | import shutil |
992 | 26 | from pathlib import Path | ||
993 | 26 | 27 | ||
994 | 27 | from PyQt5 import QtCore | 28 | from PyQt5 import QtCore |
995 | 28 | 29 | ||
996 | @@ -98,7 +99,7 @@ | |||
997 | 98 | """ | 99 | """ |
998 | 99 | self.slide_number = 0 | 100 | self.slide_number = 0 |
999 | 100 | self.file_path = name | 101 | self.file_path = name |
1001 | 101 | check_directory_exists(self.get_thumbnail_folder()) | 102 | check_directory_exists(Path(self.get_thumbnail_folder())) |
1002 | 102 | 103 | ||
1003 | 103 | def load_presentation(self): | 104 | def load_presentation(self): |
1004 | 104 | """ | 105 | """ |
1005 | @@ -419,8 +420,8 @@ | |||
1006 | 419 | self.thumbnail_folder = os.path.join( | 420 | self.thumbnail_folder = os.path.join( |
1007 | 420 | str(AppLocation.get_section_data_path(self.settings_section)), 'thumbnails') | 421 | str(AppLocation.get_section_data_path(self.settings_section)), 'thumbnails') |
1008 | 421 | self.thumbnail_prefix = 'slide' | 422 | self.thumbnail_prefix = 'slide' |
1011 | 422 | check_directory_exists(self.thumbnail_folder) | 423 | check_directory_exists(Path(self.thumbnail_folder)) |
1012 | 423 | check_directory_exists(self.temp_folder) | 424 | check_directory_exists(Path(self.temp_folder)) |
1013 | 424 | 425 | ||
1014 | 425 | def enabled(self): | 426 | def enabled(self): |
1015 | 426 | """ | 427 | """ |
1016 | 427 | 428 | ||
1017 | === modified file 'openlp/plugins/presentations/presentationplugin.py' | |||
1018 | --- openlp/plugins/presentations/presentationplugin.py 2017-06-09 15:56:40 +0000 | |||
1019 | +++ openlp/plugins/presentations/presentationplugin.py 2017-08-24 19:54:19 +0000 | |||
1020 | @@ -125,7 +125,7 @@ | |||
1021 | 125 | Check to see if we have any presentation software available. If not do not install the plugin. | 125 | Check to see if we have any presentation software available. If not do not install the plugin. |
1022 | 126 | """ | 126 | """ |
1023 | 127 | log.debug('check_pre_conditions') | 127 | log.debug('check_pre_conditions') |
1025 | 128 | controller_dir = os.path.join('openlp', 'plugins', 'presentations', 'lib') | 128 | controller_dir = os.path.join('plugins', 'presentations', 'lib') |
1026 | 129 | glob_pattern = os.path.join(controller_dir, '*controller.py') | 129 | glob_pattern = os.path.join(controller_dir, '*controller.py') |
1027 | 130 | extension_loader(glob_pattern, ['presentationcontroller.py']) | 130 | extension_loader(glob_pattern, ['presentationcontroller.py']) |
1028 | 131 | controller_classes = PresentationController.__subclasses__() | 131 | controller_classes = PresentationController.__subclasses__() |
1029 | 132 | 132 | ||
1030 | === modified file 'openlp/plugins/remotes/remoteplugin.py' | |||
1031 | --- openlp/plugins/remotes/remoteplugin.py 2017-06-18 06:03:42 +0000 | |||
1032 | +++ openlp/plugins/remotes/remoteplugin.py 2017-08-24 19:54:19 +0000 | |||
1033 | @@ -59,21 +59,22 @@ | |||
1034 | 59 | Create the internal file structure if it does not exist | 59 | Create the internal file structure if it does not exist |
1035 | 60 | :return: | 60 | :return: |
1036 | 61 | """ | 61 | """ |
1042 | 62 | check_directory_exists(os.path.join(AppLocation.get_section_data_path('remotes'), 'assets')) | 62 | check_directory_exists(AppLocation.get_section_data_path('remotes') / 'assets') |
1043 | 63 | check_directory_exists(os.path.join(AppLocation.get_section_data_path('remotes'), 'images')) | 63 | check_directory_exists(AppLocation.get_section_data_path('remotes') / 'images') |
1044 | 64 | check_directory_exists(os.path.join(AppLocation.get_section_data_path('remotes'), 'static')) | 64 | check_directory_exists(AppLocation.get_section_data_path('remotes') / 'static') |
1045 | 65 | check_directory_exists(os.path.join(AppLocation.get_section_data_path('remotes'), 'static', 'index')) | 65 | check_directory_exists(AppLocation.get_section_data_path('remotes') / 'static', 'index') |
1046 | 66 | check_directory_exists(os.path.join(AppLocation.get_section_data_path('remotes'), 'templates')) | 66 | check_directory_exists(AppLocation.get_section_data_path('remotes') / 'templates') |
1047 | 67 | 67 | ||
1048 | 68 | @staticmethod | 68 | @staticmethod |
1049 | 69 | def about(): | 69 | def about(): |
1050 | 70 | """ | 70 | """ |
1051 | 71 | Information about this plugin | 71 | Information about this plugin |
1052 | 72 | """ | 72 | """ |
1057 | 73 | about_text = translate('RemotePlugin', '<strong>Web Interface</strong>' | 73 | about_text = translate( |
1058 | 74 | '<br />The web interface plugin provides the ability develop web based ' | 74 | 'RemotePlugin', |
1059 | 75 | 'interfaces using openlp web services. \nPredefined interfaces can be ' | 75 | '<strong>Web Interface</strong>' |
1060 | 76 | 'download as well as custom developed interfaces') | 76 | '<br />The web interface plugin provides the ability to develop web based interfaces using OpenLP web ' |
1061 | 77 | 'services.\nPredefined interfaces can be download as well as custom developed interfaces.') | ||
1062 | 77 | return about_text | 78 | return about_text |
1063 | 78 | 79 | ||
1064 | 79 | def set_plugin_text_strings(self): | 80 | def set_plugin_text_strings(self): |
1065 | 80 | 81 | ||
1066 | === modified file 'openlp/plugins/songs/forms/editsongform.py' | |||
1067 | --- openlp/plugins/songs/forms/editsongform.py 2017-08-11 20:47:52 +0000 | |||
1068 | +++ openlp/plugins/songs/forms/editsongform.py 2017-08-24 19:54:19 +0000 | |||
1069 | @@ -1071,7 +1071,7 @@ | |||
1070 | 1071 | log.debug(audio_files) | 1071 | log.debug(audio_files) |
1071 | 1072 | save_path = os.path.join(str(AppLocation.get_section_data_path(self.media_item.plugin.name)), 'audio', | 1072 | save_path = os.path.join(str(AppLocation.get_section_data_path(self.media_item.plugin.name)), 'audio', |
1072 | 1073 | str(self.song.id)) | 1073 | str(self.song.id)) |
1074 | 1074 | check_directory_exists(save_path) | 1074 | check_directory_exists(Path(save_path)) |
1075 | 1075 | self.song.media_files = [] | 1075 | self.song.media_files = [] |
1076 | 1076 | files = [] | 1076 | files = [] |
1077 | 1077 | for row in range(self.audio_list_widget.count()): | 1077 | for row in range(self.audio_list_widget.count()): |
1078 | 1078 | 1078 | ||
1079 | === modified file 'openlp/plugins/songs/lib/importers/songbeamer.py' | |||
1080 | --- openlp/plugins/songs/lib/importers/songbeamer.py 2017-05-11 19:53:47 +0000 | |||
1081 | +++ openlp/plugins/songs/lib/importers/songbeamer.py 2017-08-24 19:54:19 +0000 | |||
1082 | @@ -27,6 +27,7 @@ | |||
1083 | 27 | import re | 27 | import re |
1084 | 28 | import base64 | 28 | import base64 |
1085 | 29 | import math | 29 | import math |
1086 | 30 | from pathlib import Path | ||
1087 | 30 | 31 | ||
1088 | 31 | from openlp.plugins.songs.lib import VerseType | 32 | from openlp.plugins.songs.lib import VerseType |
1089 | 32 | from openlp.plugins.songs.lib.importers.songimport import SongImport | 33 | from openlp.plugins.songs.lib.importers.songimport import SongImport |
1090 | @@ -122,7 +123,7 @@ | |||
1091 | 122 | file_name = os.path.split(import_file)[1] | 123 | file_name = os.path.split(import_file)[1] |
1092 | 123 | if os.path.isfile(import_file): | 124 | if os.path.isfile(import_file): |
1093 | 124 | # Detect the encoding | 125 | # Detect the encoding |
1095 | 125 | self.input_file_encoding = get_file_encoding(import_file)['encoding'] | 126 | self.input_file_encoding = get_file_encoding(Path(import_file))['encoding'] |
1096 | 126 | # The encoding should only be ANSI (cp1252), UTF-8, Unicode, Big-Endian-Unicode. | 127 | # The encoding should only be ANSI (cp1252), UTF-8, Unicode, Big-Endian-Unicode. |
1097 | 127 | # So if it doesn't start with 'u' we default to cp1252. See: | 128 | # So if it doesn't start with 'u' we default to cp1252. See: |
1098 | 128 | # https://forum.songbeamer.com/viewtopic.php?p=419&sid=ca4814924e37c11e4438b7272a98b6f2 | 129 | # https://forum.songbeamer.com/viewtopic.php?p=419&sid=ca4814924e37c11e4438b7272a98b6f2 |
1099 | 129 | 130 | ||
1100 | === modified file 'openlp/plugins/songs/lib/importers/songimport.py' | |||
1101 | --- openlp/plugins/songs/lib/importers/songimport.py 2017-08-01 20:59:41 +0000 | |||
1102 | +++ openlp/plugins/songs/lib/importers/songimport.py 2017-08-24 19:54:19 +0000 | |||
1103 | @@ -24,6 +24,7 @@ | |||
1104 | 24 | import re | 24 | import re |
1105 | 25 | import shutil | 25 | import shutil |
1106 | 26 | import os | 26 | import os |
1107 | 27 | from pathlib import Path | ||
1108 | 27 | 28 | ||
1109 | 28 | from PyQt5 import QtCore | 29 | from PyQt5 import QtCore |
1110 | 29 | 30 | ||
1111 | @@ -423,7 +424,7 @@ | |||
1112 | 423 | if not hasattr(self, 'save_path'): | 424 | if not hasattr(self, 'save_path'): |
1113 | 424 | self.save_path = os.path.join(str(AppLocation.get_section_data_path(self.import_wizard.plugin.name)), | 425 | self.save_path = os.path.join(str(AppLocation.get_section_data_path(self.import_wizard.plugin.name)), |
1114 | 425 | 'audio', str(song_id)) | 426 | 'audio', str(song_id)) |
1116 | 426 | check_directory_exists(self.save_path) | 427 | check_directory_exists(Path(self.save_path)) |
1117 | 427 | if not filename.startswith(self.save_path): | 428 | if not filename.startswith(self.save_path): |
1118 | 428 | old_file, filename = filename, os.path.join(self.save_path, os.path.split(filename)[1]) | 429 | old_file, filename = filename, os.path.join(self.save_path, os.path.split(filename)[1]) |
1119 | 429 | shutil.copyfile(old_file, filename) | 430 | shutil.copyfile(old_file, filename) |
1120 | 430 | 431 | ||
1121 | === modified file 'openlp/plugins/songs/lib/mediaitem.py' | |||
1122 | --- openlp/plugins/songs/lib/mediaitem.py 2017-08-03 17:54:40 +0000 | |||
1123 | +++ openlp/plugins/songs/lib/mediaitem.py 2017-08-24 19:54:19 +0000 | |||
1124 | @@ -23,6 +23,7 @@ | |||
1125 | 23 | import logging | 23 | import logging |
1126 | 24 | import os | 24 | import os |
1127 | 25 | import shutil | 25 | import shutil |
1128 | 26 | from pathlib import Path | ||
1129 | 26 | 27 | ||
1130 | 27 | from PyQt5 import QtCore, QtWidgets | 28 | from PyQt5 import QtCore, QtWidgets |
1131 | 28 | from sqlalchemy.sql import and_, or_ | 29 | from sqlalchemy.sql import and_, or_ |
1132 | @@ -89,7 +90,7 @@ | |||
1133 | 89 | for i, bga in enumerate(item.background_audio): | 90 | for i, bga in enumerate(item.background_audio): |
1134 | 90 | dest_file = os.path.join( | 91 | dest_file = os.path.join( |
1135 | 91 | str(AppLocation.get_section_data_path(self.plugin.name)), 'audio', str(song.id), os.path.split(bga)[1]) | 92 | str(AppLocation.get_section_data_path(self.plugin.name)), 'audio', str(song.id), os.path.split(bga)[1]) |
1137 | 92 | check_directory_exists(os.path.split(dest_file)[0]) | 93 | check_directory_exists(Path(os.path.split(dest_file)[0])) |
1138 | 93 | shutil.copyfile(os.path.join(str(AppLocation.get_section_data_path('servicemanager')), bga), dest_file) | 94 | shutil.copyfile(os.path.join(str(AppLocation.get_section_data_path('servicemanager')), bga), dest_file) |
1139 | 94 | song.media_files.append(MediaFile.populate(weight=i, file_name=dest_file)) | 95 | song.media_files.append(MediaFile.populate(weight=i, file_name=dest_file)) |
1140 | 95 | self.plugin.manager.save_object(song, True) | 96 | self.plugin.manager.save_object(song, True) |
1141 | @@ -535,7 +536,7 @@ | |||
1142 | 535 | if len(old_song.media_files) > 0: | 536 | if len(old_song.media_files) > 0: |
1143 | 536 | save_path = os.path.join( | 537 | save_path = os.path.join( |
1144 | 537 | str(AppLocation.get_section_data_path(self.plugin.name)), 'audio', str(new_song.id)) | 538 | str(AppLocation.get_section_data_path(self.plugin.name)), 'audio', str(new_song.id)) |
1146 | 538 | check_directory_exists(save_path) | 539 | check_directory_exists(Path(save_path)) |
1147 | 539 | for media_file in old_song.media_files: | 540 | for media_file in old_song.media_files: |
1148 | 540 | new_media_file_name = os.path.join(save_path, os.path.basename(media_file.file_name)) | 541 | new_media_file_name = os.path.join(save_path, os.path.basename(media_file.file_name)) |
1149 | 541 | shutil.copyfile(media_file.file_name, new_media_file_name) | 542 | shutil.copyfile(media_file.file_name, new_media_file_name) |
1150 | 542 | 543 | ||
1151 | === modified file 'openlp/plugins/songs/lib/openlyricsexport.py' | |||
1152 | --- openlp/plugins/songs/lib/openlyricsexport.py 2016-12-31 11:01:36 +0000 | |||
1153 | +++ openlp/plugins/songs/lib/openlyricsexport.py 2017-08-24 19:54:19 +0000 | |||
1154 | @@ -25,6 +25,7 @@ | |||
1155 | 25 | """ | 25 | """ |
1156 | 26 | import logging | 26 | import logging |
1157 | 27 | import os | 27 | import os |
1158 | 28 | from pathlib import Path | ||
1159 | 28 | 29 | ||
1160 | 29 | from lxml import etree | 30 | from lxml import etree |
1161 | 30 | 31 | ||
1162 | @@ -47,7 +48,7 @@ | |||
1163 | 47 | self.manager = parent.plugin.manager | 48 | self.manager = parent.plugin.manager |
1164 | 48 | self.songs = songs | 49 | self.songs = songs |
1165 | 49 | self.save_path = save_path | 50 | self.save_path = save_path |
1167 | 50 | check_directory_exists(self.save_path) | 51 | check_directory_exists(Path(self.save_path)) |
1168 | 51 | 52 | ||
1169 | 52 | def do_export(self): | 53 | def do_export(self): |
1170 | 53 | """ | 54 | """ |
1171 | 54 | 55 | ||
1172 | === modified file 'openlp/plugins/songusage/forms/songusagedetailform.py' | |||
1173 | --- openlp/plugins/songusage/forms/songusagedetailform.py 2017-08-04 17:40:57 +0000 | |||
1174 | +++ openlp/plugins/songusage/forms/songusagedetailform.py 2017-08-24 19:54:19 +0000 | |||
1175 | @@ -22,6 +22,7 @@ | |||
1176 | 22 | 22 | ||
1177 | 23 | import logging | 23 | import logging |
1178 | 24 | import os | 24 | import os |
1179 | 25 | from pathlib import Path | ||
1180 | 25 | 26 | ||
1181 | 26 | from PyQt5 import QtCore, QtWidgets | 27 | from PyQt5 import QtCore, QtWidgets |
1182 | 27 | from sqlalchemy.sql import and_ | 28 | from sqlalchemy.sql import and_ |
1183 | @@ -78,7 +79,7 @@ | |||
1184 | 78 | ' song usage report. \nPlease select an existing path on your computer.') | 79 | ' song usage report. \nPlease select an existing path on your computer.') |
1185 | 79 | ) | 80 | ) |
1186 | 80 | return | 81 | return |
1188 | 81 | check_directory_exists(path) | 82 | check_directory_exists(Path(path)) |
1189 | 82 | file_name = translate('SongUsagePlugin.SongUsageDetailForm', | 83 | file_name = translate('SongUsagePlugin.SongUsageDetailForm', |
1190 | 83 | 'usage_detail_{old}_{new}.txt' | 84 | 'usage_detail_{old}_{new}.txt' |
1191 | 84 | ).format(old=self.from_date_calendar.selectedDate().toString('ddMMyyyy'), | 85 | ).format(old=self.from_date_calendar.selectedDate().toString('ddMMyyyy'), |
1192 | 85 | 86 | ||
1193 | === modified file 'scripts/appveyor.yml' | |||
1194 | --- scripts/appveyor.yml 2017-05-11 20:24:20 +0000 | |||
1195 | +++ scripts/appveyor.yml 2017-08-24 19:54:19 +0000 | |||
1196 | @@ -12,7 +12,7 @@ | |||
1197 | 12 | 12 | ||
1198 | 13 | install: | 13 | install: |
1199 | 14 | # Install dependencies from pypi | 14 | # Install dependencies from pypi |
1201 | 15 | - "%PYTHON%\\python.exe -m pip install sqlalchemy alembic chardet beautifulsoup4 Mako nose mock pyodbc==4.0.8 psycopg2 pypiwin32 pyenchant" | 15 | - "%PYTHON%\\python.exe -m pip install sqlalchemy alembic chardet beautifulsoup4 Mako nose mock pyodbc==4.0.8 psycopg2 pypiwin32 pyenchant websockets asyncio waitress six webob" |
1202 | 16 | # Install mysql dependency | 16 | # Install mysql dependency |
1203 | 17 | - "%PYTHON%\\python.exe -m pip install http://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.0.4.zip#md5=3df394d89300db95163f17c843ef49df" | 17 | - "%PYTHON%\\python.exe -m pip install http://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.0.4.zip#md5=3df394d89300db95163f17c843ef49df" |
1204 | 18 | # Download and install lxml and pyicu (originally from http://www.lfd.uci.edu/~gohlke/pythonlibs/) | 18 | # Download and install lxml and pyicu (originally from http://www.lfd.uci.edu/~gohlke/pythonlibs/) |
1205 | 19 | 19 | ||
1206 | === modified file 'tests/functional/openlp_core_common/test_applocation.py' | |||
1207 | --- tests/functional/openlp_core_common/test_applocation.py 2017-08-01 20:59:41 +0000 | |||
1208 | +++ tests/functional/openlp_core_common/test_applocation.py 2017-08-24 19:54:19 +0000 | |||
1209 | @@ -43,14 +43,12 @@ | |||
1210 | 43 | """ | 43 | """ |
1211 | 44 | with patch('openlp.core.common.applocation.Settings') as mocked_class, \ | 44 | with patch('openlp.core.common.applocation.Settings') as mocked_class, \ |
1212 | 45 | patch('openlp.core.common.AppLocation.get_directory') as mocked_get_directory, \ | 45 | patch('openlp.core.common.AppLocation.get_directory') as mocked_get_directory, \ |
1215 | 46 | patch('openlp.core.common.applocation.check_directory_exists') as mocked_check_directory_exists, \ | 46 | patch('openlp.core.common.applocation.check_directory_exists') as mocked_check_directory_exists: |
1214 | 47 | patch('openlp.core.common.applocation.os') as mocked_os: | ||
1216 | 48 | # GIVEN: A mocked out Settings class and a mocked out AppLocation.get_directory() | 47 | # GIVEN: A mocked out Settings class and a mocked out AppLocation.get_directory() |
1217 | 49 | mocked_settings = mocked_class.return_value | 48 | mocked_settings = mocked_class.return_value |
1218 | 50 | mocked_settings.contains.return_value = False | 49 | mocked_settings.contains.return_value = False |
1220 | 51 | mocked_get_directory.return_value = os.path.join('test', 'dir') | 50 | mocked_get_directory.return_value = Path('test', 'dir') |
1221 | 52 | mocked_check_directory_exists.return_value = True | 51 | mocked_check_directory_exists.return_value = True |
1222 | 53 | mocked_os.path.normpath.return_value = os.path.join('test', 'dir') | ||
1223 | 54 | 52 | ||
1224 | 55 | # WHEN: we call AppLocation.get_data_path() | 53 | # WHEN: we call AppLocation.get_data_path() |
1225 | 56 | data_path = AppLocation.get_data_path() | 54 | data_path = AppLocation.get_data_path() |
1226 | @@ -58,8 +56,8 @@ | |||
1227 | 58 | # THEN: check that all the correct methods were called, and the result is correct | 56 | # THEN: check that all the correct methods were called, and the result is correct |
1228 | 59 | mocked_settings.contains.assert_called_with('advanced/data path') | 57 | mocked_settings.contains.assert_called_with('advanced/data path') |
1229 | 60 | mocked_get_directory.assert_called_with(AppLocation.DataDir) | 58 | mocked_get_directory.assert_called_with(AppLocation.DataDir) |
1232 | 61 | mocked_check_directory_exists.assert_called_with(os.path.join('test', 'dir')) | 59 | mocked_check_directory_exists.assert_called_with(Path('test', 'dir')) |
1233 | 62 | self.assertEqual(os.path.join('test', 'dir'), data_path, 'Result should be "test/dir"') | 60 | self.assertEqual(Path('test', 'dir'), data_path, 'Result should be "test/dir"') |
1234 | 63 | 61 | ||
1235 | 64 | def test_get_data_path_with_custom_location(self): | 62 | def test_get_data_path_with_custom_location(self): |
1236 | 65 | """ | 63 | """ |
1237 | @@ -125,7 +123,7 @@ | |||
1238 | 125 | data_path = AppLocation.get_section_data_path('section') | 123 | data_path = AppLocation.get_section_data_path('section') |
1239 | 126 | 124 | ||
1240 | 127 | # THEN: check that all the correct methods were called, and the result is correct | 125 | # THEN: check that all the correct methods were called, and the result is correct |
1242 | 128 | mocked_check_directory_exists.assert_called_with(os.path.join('test', 'dir', 'section')) | 126 | mocked_check_directory_exists.assert_called_with(Path('test', 'dir', 'section')) |
1243 | 129 | self.assertEqual(Path('test', 'dir', 'section'), data_path, 'Result should be "test/dir/section"') | 127 | self.assertEqual(Path('test', 'dir', 'section'), data_path, 'Result should be "test/dir/section"') |
1244 | 130 | 128 | ||
1245 | 131 | def test_get_directory_for_app_dir(self): | 129 | def test_get_directory_for_app_dir(self): |
1246 | 132 | 130 | ||
1247 | === modified file 'tests/functional/openlp_core_common/test_common.py' | |||
1248 | --- tests/functional/openlp_core_common/test_common.py 2017-08-01 20:59:41 +0000 | |||
1249 | +++ tests/functional/openlp_core_common/test_common.py 2017-08-24 19:54:19 +0000 | |||
1250 | @@ -35,44 +35,70 @@ | |||
1251 | 35 | """ | 35 | """ |
1252 | 36 | A test suite to test out various functions in the openlp.core.common module. | 36 | A test suite to test out various functions in the openlp.core.common module. |
1253 | 37 | """ | 37 | """ |
1262 | 38 | def test_check_directory_exists(self): | 38 | def test_check_directory_exists_dir_exists(self): |
1263 | 39 | """ | 39 | """ |
1264 | 40 | Test the check_directory_exists() function | 40 | Test the check_directory_exists() function when the path already exists |
1265 | 41 | """ | 41 | """ |
1266 | 42 | with patch('openlp.core.lib.os.path.exists') as mocked_exists, \ | 42 | # GIVEN: A `Path` to check with patched out mkdir and exists methods |
1267 | 43 | patch('openlp.core.lib.os.makedirs') as mocked_makedirs: | 43 | with patch.object(Path, 'exists') as mocked_exists, \ |
1268 | 44 | # GIVEN: A directory to check and a mocked out os.makedirs and os.path.exists | 44 | patch.object(Path, 'mkdir') as mocked_mkdir, \ |
1269 | 45 | directory_to_check = 'existing/directory' | 45 | patch('openlp.core.common.log'): |
1270 | 46 | 46 | ||
1272 | 47 | # WHEN: os.path.exists returns True and we check to see if the directory exists | 47 | # WHEN: `check_directory_exists` is called and the path exists |
1273 | 48 | mocked_exists.return_value = True | 48 | mocked_exists.return_value = True |
1281 | 49 | check_directory_exists(directory_to_check) | 49 | check_directory_exists(Path('existing', 'directory')) |
1282 | 50 | 50 | ||
1283 | 51 | # THEN: Only os.path.exists should have been called | 51 | # THEN: The function should not attempt to create the directory |
1284 | 52 | mocked_exists.assert_called_with(directory_to_check) | 52 | mocked_exists.assert_called_with() |
1285 | 53 | self.assertIsNot(mocked_makedirs.called, 'os.makedirs should not have been called') | 53 | self.assertFalse(mocked_mkdir.called) |
1286 | 54 | 54 | ||
1287 | 55 | # WHEN: os.path.exists returns False and we check the directory exists | 55 | def test_check_directory_exists_dir_doesnt_exists(self): |
1288 | 56 | """ | ||
1289 | 57 | Test the check_directory_exists() function when the path does not already exist | ||
1290 | 58 | """ | ||
1291 | 59 | # GIVEN: A `Path` to check with patched out mkdir and exists methods | ||
1292 | 60 | with patch.object(Path, 'exists') as mocked_exists, \ | ||
1293 | 61 | patch.object(Path, 'mkdir') as mocked_mkdir, \ | ||
1294 | 62 | patch('openlp.core.common.log'): | ||
1295 | 63 | |||
1296 | 64 | # WHEN: `check_directory_exists` is called and the path does not exist | ||
1297 | 56 | mocked_exists.return_value = False | 65 | mocked_exists.return_value = False |
1305 | 57 | check_directory_exists(directory_to_check) | 66 | check_directory_exists(Path('existing', 'directory')) |
1306 | 58 | 67 | ||
1307 | 59 | # THEN: Both the mocked functions should have been called | 68 | # THEN: The directory should have been created |
1308 | 60 | mocked_exists.assert_called_with(directory_to_check) | 69 | mocked_exists.assert_called_with() |
1309 | 61 | mocked_makedirs.assert_called_with(directory_to_check) | 70 | mocked_mkdir.assert_called_with(parents=True) |
1310 | 62 | 71 | ||
1311 | 63 | # WHEN: os.path.exists raises an IOError | 72 | def test_check_directory_exists_dir_io_error(self): |
1312 | 73 | """ | ||
1313 | 74 | Test the check_directory_exists() when an IOError is raised | ||
1314 | 75 | """ | ||
1315 | 76 | # GIVEN: A `Path` to check with patched out mkdir and exists methods | ||
1316 | 77 | with patch.object(Path, 'exists') as mocked_exists, \ | ||
1317 | 78 | patch.object(Path, 'mkdir'), \ | ||
1318 | 79 | patch('openlp.core.common.log') as mocked_logger: | ||
1319 | 80 | |||
1320 | 81 | # WHEN: An IOError is raised when checking the if the path exists. | ||
1321 | 64 | mocked_exists.side_effect = IOError() | 82 | mocked_exists.side_effect = IOError() |
1326 | 65 | check_directory_exists(directory_to_check) | 83 | check_directory_exists(Path('existing', 'directory')) |
1327 | 66 | 84 | ||
1328 | 67 | # THEN: We shouldn't get an exception though the mocked exists has been called | 85 | # THEN: The Error should have been logged |
1329 | 68 | mocked_exists.assert_called_with(directory_to_check) | 86 | mocked_logger.exception.assert_called_once_with('failed to check if directory exists or create directory') |
1330 | 87 | |||
1331 | 88 | def test_check_directory_exists_dir_value_error(self): | ||
1332 | 89 | """ | ||
1333 | 90 | Test the check_directory_exists() when an error other than IOError is raised | ||
1334 | 91 | """ | ||
1335 | 92 | # GIVEN: A `Path` to check with patched out mkdir and exists methods | ||
1336 | 93 | with patch.object(Path, 'exists') as mocked_exists, \ | ||
1337 | 94 | patch.object(Path, 'mkdir'), \ | ||
1338 | 95 | patch('openlp.core.common.log'): | ||
1339 | 69 | 96 | ||
1340 | 70 | # WHEN: Some other exception is raised | 97 | # WHEN: Some other exception is raised |
1341 | 71 | mocked_exists.side_effect = ValueError() | 98 | mocked_exists.side_effect = ValueError() |
1342 | 72 | 99 | ||
1346 | 73 | # THEN: check_directory_exists raises an exception | 100 | # THEN: `check_directory_exists` raises an exception |
1347 | 74 | mocked_exists.assert_called_with(directory_to_check) | 101 | self.assertRaises(ValueError, check_directory_exists, Path('existing', 'directory')) |
1345 | 75 | self.assertRaises(ValueError, check_directory_exists, directory_to_check) | ||
1348 | 76 | 102 | ||
1349 | 77 | def test_extension_loader_no_files_found(self): | 103 | def test_extension_loader_no_files_found(self): |
1350 | 78 | """ | 104 | """ |
1351 | @@ -80,7 +106,7 @@ | |||
1352 | 80 | """ | 106 | """ |
1353 | 81 | # GIVEN: A mocked `Path.glob` method which does not match any files | 107 | # GIVEN: A mocked `Path.glob` method which does not match any files |
1354 | 82 | with patch('openlp.core.common.AppLocation.get_directory', return_value=Path('/', 'app', 'dir', 'openlp')), \ | 108 | with patch('openlp.core.common.AppLocation.get_directory', return_value=Path('/', 'app', 'dir', 'openlp')), \ |
1356 | 83 | patch.object(common.Path, 'glob', return_value=[]), \ | 109 | patch.object(Path, 'glob', return_value=[]), \ |
1357 | 84 | patch('openlp.core.common.importlib.import_module') as mocked_import_module: | 110 | patch('openlp.core.common.importlib.import_module') as mocked_import_module: |
1358 | 85 | 111 | ||
1359 | 86 | # WHEN: Calling `extension_loader` | 112 | # WHEN: Calling `extension_loader` |
1360 | @@ -95,7 +121,7 @@ | |||
1361 | 95 | """ | 121 | """ |
1362 | 96 | # GIVEN: A mocked `Path.glob` method which returns a list of files | 122 | # GIVEN: A mocked `Path.glob` method which returns a list of files |
1363 | 97 | with patch('openlp.core.common.AppLocation.get_directory', return_value=Path('/', 'app', 'dir', 'openlp')), \ | 123 | with patch('openlp.core.common.AppLocation.get_directory', return_value=Path('/', 'app', 'dir', 'openlp')), \ |
1365 | 98 | patch.object(common.Path, 'glob', return_value=[ | 124 | patch.object(Path, 'glob', return_value=[ |
1366 | 99 | Path('/', 'app', 'dir', 'openlp', 'import_dir', 'file1.py'), | 125 | Path('/', 'app', 'dir', 'openlp', 'import_dir', 'file1.py'), |
1367 | 100 | Path('/', 'app', 'dir', 'openlp', 'import_dir', 'file2.py'), | 126 | Path('/', 'app', 'dir', 'openlp', 'import_dir', 'file2.py'), |
1368 | 101 | Path('/', 'app', 'dir', 'openlp', 'import_dir', 'file3.py'), | 127 | Path('/', 'app', 'dir', 'openlp', 'import_dir', 'file3.py'), |
1369 | @@ -115,7 +141,7 @@ | |||
1370 | 115 | """ | 141 | """ |
1371 | 116 | # GIVEN: A mocked `import_module` which raises an `ImportError` | 142 | # GIVEN: A mocked `import_module` which raises an `ImportError` |
1372 | 117 | with patch('openlp.core.common.AppLocation.get_directory', return_value=Path('/', 'app', 'dir', 'openlp')), \ | 143 | with patch('openlp.core.common.AppLocation.get_directory', return_value=Path('/', 'app', 'dir', 'openlp')), \ |
1374 | 118 | patch.object(common.Path, 'glob', return_value=[ | 144 | patch.object(Path, 'glob', return_value=[ |
1375 | 119 | Path('/', 'app', 'dir', 'openlp', 'import_dir', 'file1.py')]), \ | 145 | Path('/', 'app', 'dir', 'openlp', 'import_dir', 'file1.py')]), \ |
1376 | 120 | patch('openlp.core.common.importlib.import_module', side_effect=ImportError()), \ | 146 | patch('openlp.core.common.importlib.import_module', side_effect=ImportError()), \ |
1377 | 121 | patch('openlp.core.common.log') as mocked_logger: | 147 | patch('openlp.core.common.log') as mocked_logger: |
1378 | @@ -132,7 +158,7 @@ | |||
1379 | 132 | """ | 158 | """ |
1380 | 133 | # GIVEN: A mocked `SourceFileLoader` which raises an `OSError` | 159 | # GIVEN: A mocked `SourceFileLoader` which raises an `OSError` |
1381 | 134 | with patch('openlp.core.common.AppLocation.get_directory', return_value=Path('/', 'app', 'dir', 'openlp')), \ | 160 | with patch('openlp.core.common.AppLocation.get_directory', return_value=Path('/', 'app', 'dir', 'openlp')), \ |
1383 | 135 | patch.object(common.Path, 'glob', return_value=[ | 161 | patch.object(Path, 'glob', return_value=[ |
1384 | 136 | Path('/', 'app', 'dir', 'openlp', 'import_dir', 'file1.py')]), \ | 162 | Path('/', 'app', 'dir', 'openlp', 'import_dir', 'file1.py')]), \ |
1385 | 137 | patch('openlp.core.common.importlib.import_module', side_effect=OSError()), \ | 163 | patch('openlp.core.common.importlib.import_module', side_effect=OSError()), \ |
1386 | 138 | patch('openlp.core.common.log') as mocked_logger: | 164 | patch('openlp.core.common.log') as mocked_logger: |
1387 | @@ -174,7 +200,7 @@ | |||
1388 | 174 | Test `path_to_module` when supplied with a `Path` object | 200 | Test `path_to_module` when supplied with a `Path` object |
1389 | 175 | """ | 201 | """ |
1390 | 176 | # GIVEN: A `Path` object | 202 | # GIVEN: A `Path` object |
1392 | 177 | path = Path('openlp/core/ui/media/webkitplayer.py') | 203 | path = Path('core', 'ui', 'media', 'webkitplayer.py') |
1393 | 178 | 204 | ||
1394 | 179 | # WHEN: Calling path_to_module with the `Path` object | 205 | # WHEN: Calling path_to_module with the `Path` object |
1395 | 180 | result = path_to_module(path) | 206 | result = path_to_module(path) |
1396 | 181 | 207 | ||
1397 | === modified file 'tests/functional/openlp_core_common/test_init.py' | |||
1398 | --- tests/functional/openlp_core_common/test_init.py 2017-04-24 05:17:55 +0000 | |||
1399 | +++ tests/functional/openlp_core_common/test_init.py 2017-08-24 19:54:19 +0000 | |||
1400 | @@ -24,6 +24,7 @@ | |||
1401 | 24 | """ | 24 | """ |
1402 | 25 | import os | 25 | import os |
1403 | 26 | from io import BytesIO | 26 | from io import BytesIO |
1404 | 27 | from pathlib import Path | ||
1405 | 27 | from unittest import TestCase | 28 | from unittest import TestCase |
1406 | 28 | from unittest.mock import MagicMock, PropertyMock, call, patch | 29 | from unittest.mock import MagicMock, PropertyMock, call, patch |
1407 | 29 | 30 | ||
1408 | @@ -296,10 +297,10 @@ | |||
1409 | 296 | """ | 297 | """ |
1410 | 297 | # GIVEN: A blank path | 298 | # GIVEN: A blank path |
1411 | 298 | # WEHN: Calling delete_file | 299 | # WEHN: Calling delete_file |
1413 | 299 | result = delete_file('') | 300 | result = delete_file(None) |
1414 | 300 | 301 | ||
1415 | 301 | # THEN: delete_file should return False | 302 | # THEN: delete_file should return False |
1417 | 302 | self.assertFalse(result, "delete_file should return False when called with ''") | 303 | self.assertFalse(result, "delete_file should return False when called with None") |
1418 | 303 | 304 | ||
1419 | 304 | def test_delete_file_path_success(self): | 305 | def test_delete_file_path_success(self): |
1420 | 305 | """ | 306 | """ |
1421 | @@ -309,84 +310,87 @@ | |||
1422 | 309 | with patch('openlp.core.common.os', **{'path.exists.return_value': False}): | 310 | with patch('openlp.core.common.os', **{'path.exists.return_value': False}): |
1423 | 310 | 311 | ||
1424 | 311 | # WHEN: Calling delete_file with a file path | 312 | # WHEN: Calling delete_file with a file path |
1426 | 312 | result = delete_file('path/file.ext') | 313 | result = delete_file(Path('path', 'file.ext')) |
1427 | 313 | 314 | ||
1428 | 314 | # THEN: delete_file should return True | 315 | # THEN: delete_file should return True |
1429 | 315 | self.assertTrue(result, 'delete_file should return True when it successfully deletes a file') | 316 | self.assertTrue(result, 'delete_file should return True when it successfully deletes a file') |
1430 | 316 | 317 | ||
1431 | 317 | def test_delete_file_path_no_file_exists(self): | 318 | def test_delete_file_path_no_file_exists(self): |
1432 | 318 | """ | 319 | """ |
1434 | 319 | Test the delete_file function when the file to remove does not exist | 320 | Test the `delete_file` function when the file to remove does not exist |
1435 | 320 | """ | 321 | """ |
1443 | 321 | # GIVEN: A mocked os which returns False when os.path.exists is called | 322 | # GIVEN: A patched `exists` methods on the Path object, which returns False |
1444 | 322 | with patch('openlp.core.common.os', **{'path.exists.return_value': False}): | 323 | with patch.object(Path, 'exists', return_value=False), \ |
1445 | 323 | 324 | patch.object(Path, 'unlink') as mocked_unlink: | |
1446 | 324 | # WHEN: Calling delete_file with a file path | 325 | |
1447 | 325 | result = delete_file('path/file.ext') | 326 | # WHEN: Calling `delete_file with` a file path |
1448 | 326 | 327 | result = delete_file(Path('path', 'file.ext')) | |
1449 | 327 | # THEN: delete_file should return True | 328 | |
1450 | 329 | # THEN: The function should not attempt to delete the file and it should return True | ||
1451 | 330 | self.assertFalse(mocked_unlink.called) | ||
1452 | 328 | self.assertTrue(result, 'delete_file should return True when the file doesnt exist') | 331 | self.assertTrue(result, 'delete_file should return True when the file doesnt exist') |
1453 | 329 | 332 | ||
1454 | 330 | def test_delete_file_path_exception(self): | 333 | def test_delete_file_path_exception(self): |
1455 | 331 | """ | 334 | """ |
1457 | 332 | Test the delete_file function when os.remove raises an exception | 335 | Test the delete_file function when an exception is raised |
1458 | 333 | """ | 336 | """ |
1460 | 334 | # GIVEN: A mocked os which returns True when os.path.exists is called and raises an OSError when os.remove is | 337 | # GIVEN: A test `Path` object with a patched exists method which raises an OSError |
1461 | 335 | # called. | 338 | # called. |
1463 | 336 | with patch('openlp.core.common.os', **{'path.exists.return_value': True, 'path.exists.side_effect': OSError}), \ | 339 | with patch.object(Path, 'exists') as mocked_exists, \ |
1464 | 337 | patch('openlp.core.common.log') as mocked_log: | 340 | patch('openlp.core.common.log') as mocked_log: |
1474 | 338 | 341 | mocked_exists.side_effect = OSError | |
1475 | 339 | # WHEN: Calling delete_file with a file path | 342 | |
1476 | 340 | result = delete_file('path/file.ext') | 343 | # WHEN: Calling delete_file with a the test Path object |
1477 | 341 | 344 | result = delete_file(Path('path', 'file.ext')) | |
1478 | 342 | # THEN: delete_file should log and exception and return False | 345 | |
1479 | 343 | self.assertEqual(mocked_log.exception.call_count, 1) | 346 | # THEN: The exception should be logged and `delete_file` should return False |
1480 | 344 | self.assertFalse(result, 'delete_file should return False when os.remove raises an OSError') | 347 | self.assertTrue(mocked_log.exception.called) |
1481 | 345 | 348 | self.assertFalse(result, 'delete_file should return False when an OSError is raised') | |
1482 | 346 | def test_get_file_name_encoding_done_test(self): | 349 | |
1483 | 350 | def test_get_file_encoding_done_test(self): | ||
1484 | 347 | """ | 351 | """ |
1485 | 348 | Test get_file_encoding when the detector sets done to True | 352 | Test get_file_encoding when the detector sets done to True |
1486 | 349 | """ | 353 | """ |
1487 | 350 | # GIVEN: A mocked UniversalDetector instance with done attribute set to True after first iteration | 354 | # GIVEN: A mocked UniversalDetector instance with done attribute set to True after first iteration |
1488 | 351 | with patch('openlp.core.common.UniversalDetector') as mocked_universal_detector, \ | 355 | with patch('openlp.core.common.UniversalDetector') as mocked_universal_detector, \ |
1490 | 352 | patch('builtins.open', return_value=BytesIO(b"data" * 260)) as mocked_open: | 356 | patch.object(Path, 'open', return_value=BytesIO(b"data" * 260)) as mocked_open: |
1491 | 353 | encoding_result = {'encoding': 'UTF-8', 'confidence': 0.99} | 357 | encoding_result = {'encoding': 'UTF-8', 'confidence': 0.99} |
1492 | 354 | mocked_universal_detector_inst = MagicMock(result=encoding_result) | 358 | mocked_universal_detector_inst = MagicMock(result=encoding_result) |
1493 | 355 | type(mocked_universal_detector_inst).done = PropertyMock(side_effect=[False, True]) | 359 | type(mocked_universal_detector_inst).done = PropertyMock(side_effect=[False, True]) |
1494 | 356 | mocked_universal_detector.return_value = mocked_universal_detector_inst | 360 | mocked_universal_detector.return_value = mocked_universal_detector_inst |
1495 | 357 | 361 | ||
1496 | 358 | # WHEN: Calling get_file_encoding | 362 | # WHEN: Calling get_file_encoding |
1498 | 359 | result = get_file_encoding('file name') | 363 | result = get_file_encoding(Path('file name')) |
1499 | 360 | 364 | ||
1500 | 361 | # THEN: The feed method of UniversalDetector should only br called once before returning a result | 365 | # THEN: The feed method of UniversalDetector should only br called once before returning a result |
1502 | 362 | mocked_open.assert_called_once_with('file name', 'rb') | 366 | mocked_open.assert_called_once_with('rb') |
1503 | 363 | self.assertEqual(mocked_universal_detector_inst.feed.mock_calls, [call(b"data" * 256)]) | 367 | self.assertEqual(mocked_universal_detector_inst.feed.mock_calls, [call(b"data" * 256)]) |
1504 | 364 | mocked_universal_detector_inst.close.assert_called_once_with() | 368 | mocked_universal_detector_inst.close.assert_called_once_with() |
1505 | 365 | self.assertEqual(result, encoding_result) | 369 | self.assertEqual(result, encoding_result) |
1506 | 366 | 370 | ||
1508 | 367 | def test_get_file_name_encoding_eof_test(self): | 371 | def test_get_file_encoding_eof_test(self): |
1509 | 368 | """ | 372 | """ |
1510 | 369 | Test get_file_encoding when the end of the file is reached | 373 | Test get_file_encoding when the end of the file is reached |
1511 | 370 | """ | 374 | """ |
1512 | 371 | # GIVEN: A mocked UniversalDetector instance which isn't set to done and a mocked open, with 1040 bytes of test | 375 | # GIVEN: A mocked UniversalDetector instance which isn't set to done and a mocked open, with 1040 bytes of test |
1513 | 372 | # data (enough to run the iterator twice) | 376 | # data (enough to run the iterator twice) |
1514 | 373 | with patch('openlp.core.common.UniversalDetector') as mocked_universal_detector, \ | 377 | with patch('openlp.core.common.UniversalDetector') as mocked_universal_detector, \ |
1516 | 374 | patch('builtins.open', return_value=BytesIO(b"data" * 260)) as mocked_open: | 378 | patch.object(Path, 'open', return_value=BytesIO(b"data" * 260)) as mocked_open: |
1517 | 375 | encoding_result = {'encoding': 'UTF-8', 'confidence': 0.99} | 379 | encoding_result = {'encoding': 'UTF-8', 'confidence': 0.99} |
1518 | 376 | mocked_universal_detector_inst = MagicMock(mock=mocked_universal_detector, | 380 | mocked_universal_detector_inst = MagicMock(mock=mocked_universal_detector, |
1519 | 377 | **{'done': False, 'result': encoding_result}) | 381 | **{'done': False, 'result': encoding_result}) |
1520 | 378 | mocked_universal_detector.return_value = mocked_universal_detector_inst | 382 | mocked_universal_detector.return_value = mocked_universal_detector_inst |
1521 | 379 | 383 | ||
1522 | 380 | # WHEN: Calling get_file_encoding | 384 | # WHEN: Calling get_file_encoding |
1524 | 381 | result = get_file_encoding('file name') | 385 | result = get_file_encoding(Path('file name')) |
1525 | 382 | 386 | ||
1526 | 383 | # THEN: The feed method of UniversalDetector should have been called twice before returning a result | 387 | # THEN: The feed method of UniversalDetector should have been called twice before returning a result |
1528 | 384 | mocked_open.assert_called_once_with('file name', 'rb') | 388 | mocked_open.assert_called_once_with('rb') |
1529 | 385 | self.assertEqual(mocked_universal_detector_inst.feed.mock_calls, [call(b"data" * 256), call(b"data" * 4)]) | 389 | self.assertEqual(mocked_universal_detector_inst.feed.mock_calls, [call(b"data" * 256), call(b"data" * 4)]) |
1530 | 386 | mocked_universal_detector_inst.close.assert_called_once_with() | 390 | mocked_universal_detector_inst.close.assert_called_once_with() |
1531 | 387 | self.assertEqual(result, encoding_result) | 391 | self.assertEqual(result, encoding_result) |
1532 | 388 | 392 | ||
1534 | 389 | def test_get_file_name_encoding_oserror_test(self): | 393 | def test_get_file_encoding_oserror_test(self): |
1535 | 390 | """ | 394 | """ |
1536 | 391 | Test get_file_encoding when the end of the file is reached | 395 | Test get_file_encoding when the end of the file is reached |
1537 | 392 | """ | 396 | """ |
1538 | @@ -397,7 +401,7 @@ | |||
1539 | 397 | patch('openlp.core.common.log') as mocked_log: | 401 | patch('openlp.core.common.log') as mocked_log: |
1540 | 398 | 402 | ||
1541 | 399 | # WHEN: Calling get_file_encoding | 403 | # WHEN: Calling get_file_encoding |
1543 | 400 | result = get_file_encoding('file name') | 404 | result = get_file_encoding(Path('file name')) |
1544 | 401 | 405 | ||
1545 | 402 | # THEN: log.exception should be called and get_file_encoding should return None | 406 | # THEN: log.exception should be called and get_file_encoding should return None |
1546 | 403 | mocked_log.exception.assert_called_once_with('Error detecting file encoding') | 407 | mocked_log.exception.assert_called_once_with('Error detecting file encoding') |
1547 | 404 | 408 | ||
1548 | === modified file 'tests/functional/openlp_core_lib/test_db.py' | |||
1549 | --- tests/functional/openlp_core_lib/test_db.py 2017-06-09 13:45:18 +0000 | |||
1550 | +++ tests/functional/openlp_core_lib/test_db.py 2017-08-24 19:54:19 +0000 | |||
1551 | @@ -24,6 +24,7 @@ | |||
1552 | 24 | """ | 24 | """ |
1553 | 25 | import os | 25 | import os |
1554 | 26 | import shutil | 26 | import shutil |
1555 | 27 | from pathlib import Path | ||
1556 | 27 | 28 | ||
1557 | 28 | from tempfile import mkdtemp | 29 | from tempfile import mkdtemp |
1558 | 29 | from unittest import TestCase | 30 | from unittest import TestCase |
1559 | @@ -129,10 +130,10 @@ | |||
1560 | 129 | # GIVEN: Mocked out AppLocation class and delete_file method, a test plugin name and a db location | 130 | # GIVEN: Mocked out AppLocation class and delete_file method, a test plugin name and a db location |
1561 | 130 | with patch('openlp.core.lib.db.AppLocation') as MockedAppLocation, \ | 131 | with patch('openlp.core.lib.db.AppLocation') as MockedAppLocation, \ |
1562 | 131 | patch('openlp.core.lib.db.delete_file') as mocked_delete_file: | 132 | patch('openlp.core.lib.db.delete_file') as mocked_delete_file: |
1564 | 132 | MockedAppLocation.get_section_data_path.return_value = 'test-dir' | 133 | MockedAppLocation.get_section_data_path.return_value = Path('test-dir') |
1565 | 133 | mocked_delete_file.return_value = True | 134 | mocked_delete_file.return_value = True |
1566 | 134 | test_plugin = 'test' | 135 | test_plugin = 'test' |
1568 | 135 | test_location = os.path.join('test-dir', test_plugin) | 136 | test_location = Path('test-dir', test_plugin) |
1569 | 136 | 137 | ||
1570 | 137 | # WHEN: delete_database is run without a database file | 138 | # WHEN: delete_database is run without a database file |
1571 | 138 | result = delete_database(test_plugin) | 139 | result = delete_database(test_plugin) |
1572 | @@ -149,11 +150,11 @@ | |||
1573 | 149 | # GIVEN: Mocked out AppLocation class and delete_file method, a test plugin name and a db location | 150 | # GIVEN: Mocked out AppLocation class and delete_file method, a test plugin name and a db location |
1574 | 150 | with patch('openlp.core.lib.db.AppLocation') as MockedAppLocation, \ | 151 | with patch('openlp.core.lib.db.AppLocation') as MockedAppLocation, \ |
1575 | 151 | patch('openlp.core.lib.db.delete_file') as mocked_delete_file: | 152 | patch('openlp.core.lib.db.delete_file') as mocked_delete_file: |
1577 | 152 | MockedAppLocation.get_section_data_path.return_value = 'test-dir' | 153 | MockedAppLocation.get_section_data_path.return_value = Path('test-dir') |
1578 | 153 | mocked_delete_file.return_value = False | 154 | mocked_delete_file.return_value = False |
1579 | 154 | test_plugin = 'test' | 155 | test_plugin = 'test' |
1580 | 155 | test_db_file = 'mydb.sqlite' | 156 | test_db_file = 'mydb.sqlite' |
1582 | 156 | test_location = os.path.join('test-dir', test_db_file) | 157 | test_location = Path('test-dir', test_db_file) |
1583 | 157 | 158 | ||
1584 | 158 | # WHEN: delete_database is run without a database file | 159 | # WHEN: delete_database is run without a database file |
1585 | 159 | result = delete_database(test_plugin, test_db_file) | 160 | result = delete_database(test_plugin, test_db_file) |
1586 | 160 | 161 | ||
1587 | === removed file 'tests/functional/openlp_core_lib/test_file_dialog.py' | |||
1588 | --- tests/functional/openlp_core_lib/test_file_dialog.py 2017-08-07 21:12:42 +0000 | |||
1589 | +++ tests/functional/openlp_core_lib/test_file_dialog.py 1970-01-01 00:00:00 +0000 | |||
1590 | @@ -1,45 +0,0 @@ | |||
1591 | 1 | # -*- coding: utf-8 -*- | ||
1592 | 2 | # vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 | ||
1593 | 3 | |||
1594 | 4 | ############################################################################### | ||
1595 | 5 | # OpenLP - Open Source Lyrics Projection # | ||
1596 | 6 | # --------------------------------------------------------------------------- # | ||
1597 | 7 | # Copyright (c) 2008-2017 OpenLP Developers # | ||
1598 | 8 | # --------------------------------------------------------------------------- # | ||
1599 | 9 | # This program is free software; you can redistribute it and/or modify it # | ||
1600 | 10 | # under the terms of the GNU General Public License as published by the Free # | ||
1601 | 11 | # Software Foundation; version 2 of the License. # | ||
1602 | 12 | # # | ||
1603 | 13 | # This program is distributed in the hope that it will be useful, but WITHOUT # | ||
1604 | 14 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # | ||
1605 | 15 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # | ||
1606 | 16 | # more details. # | ||
1607 | 17 | # # | ||
1608 | 18 | # You should have received a copy of the GNU General Public License along # | ||
1609 | 19 | # with this program; if not, write to the Free Software Foundation, Inc., 59 # | ||
1610 | 20 | # Temple Place, Suite 330, Boston, MA 02111-1307 USA # | ||
1611 | 21 | ############################################################################### | ||
1612 | 22 | """ | ||
1613 | 23 | Package to test the openlp.core.ui.lib.filedialog package. | ||
1614 | 24 | """ | ||
1615 | 25 | from unittest import TestCase | ||
1616 | 26 | from unittest.mock import MagicMock, patch | ||
1617 | 27 | |||
1618 | 28 | |||
1619 | 29 | class TestFileDialog(TestCase): | ||
1620 | 30 | """ | ||
1621 | 31 | Test the functions in the :mod:`filedialog` module. | ||
1622 | 32 | """ | ||
1623 | 33 | def setUp(self): | ||
1624 | 34 | self.os_patcher = patch('openlp.core.ui.lib.filedialog.os') | ||
1625 | 35 | self.qt_gui_patcher = patch('openlp.core.ui.lib.filedialog.QtWidgets') | ||
1626 | 36 | self.ui_strings_patcher = patch('openlp.core.ui.lib.filedialog.UiStrings') | ||
1627 | 37 | self.mocked_os = self.os_patcher.start() | ||
1628 | 38 | self.mocked_qt_gui = self.qt_gui_patcher.start() | ||
1629 | 39 | self.mocked_ui_strings = self.ui_strings_patcher.start() | ||
1630 | 40 | self.mocked_parent = MagicMock() | ||
1631 | 41 | |||
1632 | 42 | def tearDown(self): | ||
1633 | 43 | self.os_patcher.stop() | ||
1634 | 44 | self.qt_gui_patcher.stop() | ||
1635 | 45 | self.ui_strings_patcher.stop() | ||
1636 | 46 | 0 | ||
1637 | === modified file 'tests/functional/openlp_core_lib/test_lib.py' | |||
1638 | --- tests/functional/openlp_core_lib/test_lib.py 2017-08-23 20:21:11 +0000 | |||
1639 | +++ tests/functional/openlp_core_lib/test_lib.py 2017-08-24 19:54:19 +0000 | |||
1640 | @@ -24,6 +24,7 @@ | |||
1641 | 24 | """ | 24 | """ |
1642 | 25 | import os | 25 | import os |
1643 | 26 | from datetime import datetime, timedelta | 26 | from datetime import datetime, timedelta |
1644 | 27 | from pathlib import Path | ||
1645 | 27 | from unittest import TestCase | 28 | from unittest import TestCase |
1646 | 28 | from unittest.mock import MagicMock, patch | 29 | from unittest.mock import MagicMock, patch |
1647 | 29 | 30 | ||
1648 | @@ -148,35 +149,34 @@ | |||
1649 | 148 | """ | 149 | """ |
1650 | 149 | Test the get_text_file_string() function when a file does not exist | 150 | Test the get_text_file_string() function when a file does not exist |
1651 | 150 | """ | 151 | """ |
1656 | 151 | with patch('openlp.core.lib.os.path.isfile') as mocked_isfile: | 152 | # GIVEN: A patched is_file which returns False, and a file path |
1657 | 152 | # GIVEN: A mocked out isfile which returns true, and a text file name | 153 | with patch.object(Path, 'is_file', return_value=False): |
1658 | 153 | filename = 'testfile.txt' | 154 | file_path = Path('testfile.txt') |
1655 | 154 | mocked_isfile.return_value = False | ||
1659 | 155 | 155 | ||
1660 | 156 | # WHEN: get_text_file_string is called | 156 | # WHEN: get_text_file_string is called |
1662 | 157 | result = get_text_file_string(filename) | 157 | result = get_text_file_string(file_path) |
1663 | 158 | 158 | ||
1664 | 159 | # THEN: The result should be False | 159 | # THEN: The result should be False |
1666 | 160 | mocked_isfile.assert_called_with(filename) | 160 | file_path.is_file.assert_called_with() |
1667 | 161 | self.assertFalse(result, 'False should be returned if no file exists') | 161 | self.assertFalse(result, 'False should be returned if no file exists') |
1668 | 162 | 162 | ||
1669 | 163 | def test_get_text_file_string_read_error(self): | 163 | def test_get_text_file_string_read_error(self): |
1670 | 164 | """ | 164 | """ |
1671 | 165 | Test the get_text_file_string() method when a read error happens | 165 | Test the get_text_file_string() method when a read error happens |
1672 | 166 | """ | 166 | """ |
1679 | 167 | with patch('openlp.core.lib.os.path.isfile') as mocked_isfile, \ | 167 | # GIVEN: A patched open which raises an exception and is_file which returns True |
1680 | 168 | patch('openlp.core.lib.open', create=True) as mocked_open: | 168 | with patch.object(Path, 'is_file'), \ |
1681 | 169 | # GIVEN: A mocked-out open() which raises an exception and isfile returns True | 169 | patch.object(Path, 'open'): |
1682 | 170 | filename = 'testfile.txt' | 170 | file_path = Path('testfile.txt') |
1683 | 171 | mocked_isfile.return_value = True | 171 | file_path.is_file.return_value = True |
1684 | 172 | mocked_open.side_effect = IOError() | 172 | file_path.open.side_effect = IOError() |
1685 | 173 | 173 | ||
1686 | 174 | # WHEN: get_text_file_string is called | 174 | # WHEN: get_text_file_string is called |
1688 | 175 | result = get_text_file_string(filename) | 175 | result = get_text_file_string(file_path) |
1689 | 176 | 176 | ||
1690 | 177 | # THEN: None should be returned | 177 | # THEN: None should be returned |
1693 | 178 | mocked_isfile.assert_called_with(filename) | 178 | file_path.is_file.assert_called_once_with() |
1694 | 179 | mocked_open.assert_called_with(filename, 'r', encoding='utf-8') | 179 | file_path.open.assert_called_once_with('r', encoding='utf-8') |
1695 | 180 | self.assertIsNone(result, 'None should be returned if the file cannot be opened') | 180 | self.assertIsNone(result, 'None should be returned if the file cannot be opened') |
1696 | 181 | 181 | ||
1697 | 182 | def test_get_text_file_string_decode_error(self): | 182 | def test_get_text_file_string_decode_error(self): |
1698 | 183 | 183 | ||
1699 | === modified file 'tests/functional/openlp_core_ui/test_firsttimeform.py' | |||
1700 | --- tests/functional/openlp_core_ui/test_firsttimeform.py 2017-04-24 05:17:55 +0000 | |||
1701 | +++ tests/functional/openlp_core_ui/test_firsttimeform.py 2017-08-24 19:54:19 +0000 | |||
1702 | @@ -25,6 +25,7 @@ | |||
1703 | 25 | import os | 25 | import os |
1704 | 26 | import tempfile | 26 | import tempfile |
1705 | 27 | import urllib | 27 | import urllib |
1706 | 28 | from pathlib import Path | ||
1707 | 28 | from unittest import TestCase | 29 | from unittest import TestCase |
1708 | 29 | from unittest.mock import MagicMock, patch | 30 | from unittest.mock import MagicMock, patch |
1709 | 30 | 31 | ||
1710 | @@ -116,7 +117,7 @@ | |||
1711 | 116 | mocked_settings.value.return_value = True | 117 | mocked_settings.value.return_value = True |
1712 | 117 | MockedSettings.return_value = mocked_settings | 118 | MockedSettings.return_value = mocked_settings |
1713 | 118 | mocked_gettempdir.return_value = 'temp' | 119 | mocked_gettempdir.return_value = 'temp' |
1715 | 119 | expected_temp_path = os.path.join('temp', 'openlp') | 120 | expected_temp_path = Path('temp', 'openlp') |
1716 | 120 | 121 | ||
1717 | 121 | # WHEN: The set_defaults() method is run | 122 | # WHEN: The set_defaults() method is run |
1718 | 122 | frw.set_defaults() | 123 | frw.set_defaults() |
1719 | 123 | 124 | ||
1720 | === modified file 'tests/functional/openlp_core_ui/test_thememanager.py' | |||
1721 | --- tests/functional/openlp_core_ui/test_thememanager.py 2017-06-01 06:18:47 +0000 | |||
1722 | +++ tests/functional/openlp_core_ui/test_thememanager.py 2017-08-24 19:54:19 +0000 | |||
1723 | @@ -90,7 +90,7 @@ | |||
1724 | 90 | # theme, check_directory_exists and thememanager-attributes. | 90 | # theme, check_directory_exists and thememanager-attributes. |
1725 | 91 | with patch('builtins.open') as mocked_open, \ | 91 | with patch('builtins.open') as mocked_open, \ |
1726 | 92 | patch('openlp.core.ui.thememanager.shutil.copyfile') as mocked_copyfile, \ | 92 | patch('openlp.core.ui.thememanager.shutil.copyfile') as mocked_copyfile, \ |
1728 | 93 | patch('openlp.core.ui.thememanager.check_directory_exists') as mocked_check_directory_exists: | 93 | patch('openlp.core.ui.thememanager.check_directory_exists'): |
1729 | 94 | mocked_open.return_value = MagicMock() | 94 | mocked_open.return_value = MagicMock() |
1730 | 95 | theme_manager = ThemeManager(None) | 95 | theme_manager = ThemeManager(None) |
1731 | 96 | theme_manager.old_background_image = None | 96 | theme_manager.old_background_image = None |
1732 | @@ -118,7 +118,7 @@ | |||
1733 | 118 | # theme, check_directory_exists and thememanager-attributes. | 118 | # theme, check_directory_exists and thememanager-attributes. |
1734 | 119 | with patch('builtins.open') as mocked_open, \ | 119 | with patch('builtins.open') as mocked_open, \ |
1735 | 120 | patch('openlp.core.ui.thememanager.shutil.copyfile') as mocked_copyfile, \ | 120 | patch('openlp.core.ui.thememanager.shutil.copyfile') as mocked_copyfile, \ |
1737 | 121 | patch('openlp.core.ui.thememanager.check_directory_exists') as mocked_check_directory_exists: | 121 | patch('openlp.core.ui.thememanager.check_directory_exists'): |
1738 | 122 | mocked_open.return_value = MagicMock() | 122 | mocked_open.return_value = MagicMock() |
1739 | 123 | theme_manager = ThemeManager(None) | 123 | theme_manager = ThemeManager(None) |
1740 | 124 | theme_manager.old_background_image = None | 124 | theme_manager.old_background_image = None |
1741 | 125 | 125 | ||
1742 | === modified file 'tests/functional/openlp_plugins/bibles/test_manager.py' | |||
1743 | --- tests/functional/openlp_plugins/bibles/test_manager.py 2016-12-31 11:01:36 +0000 | |||
1744 | +++ tests/functional/openlp_plugins/bibles/test_manager.py 2017-08-24 19:54:19 +0000 | |||
1745 | @@ -22,6 +22,7 @@ | |||
1746 | 22 | """ | 22 | """ |
1747 | 23 | This module contains tests for the manager submodule of the Bibles plugin. | 23 | This module contains tests for the manager submodule of the Bibles plugin. |
1748 | 24 | """ | 24 | """ |
1749 | 25 | from pathlib import Path | ||
1750 | 25 | from unittest import TestCase | 26 | from unittest import TestCase |
1751 | 26 | from unittest.mock import MagicMock, patch | 27 | from unittest.mock import MagicMock, patch |
1752 | 27 | 28 | ||
1753 | @@ -50,7 +51,6 @@ | |||
1754 | 50 | """ | 51 | """ |
1755 | 51 | # GIVEN: An instance of BibleManager and a mocked bible | 52 | # GIVEN: An instance of BibleManager and a mocked bible |
1756 | 52 | with patch.object(BibleManager, 'reload_bibles'), \ | 53 | with patch.object(BibleManager, 'reload_bibles'), \ |
1757 | 53 | patch('openlp.plugins.bibles.lib.manager.os.path.join', side_effect=lambda x, y: '{}/{}'.format(x, y)),\ | ||
1758 | 54 | patch('openlp.plugins.bibles.lib.manager.delete_file', return_value=True) as mocked_delete_file: | 54 | patch('openlp.plugins.bibles.lib.manager.delete_file', return_value=True) as mocked_delete_file: |
1759 | 55 | instance = BibleManager(MagicMock()) | 55 | instance = BibleManager(MagicMock()) |
1760 | 56 | # We need to keep a reference to the mock for close_all as it gets set to None later on! | 56 | # We need to keep a reference to the mock for close_all as it gets set to None later on! |
1761 | @@ -66,4 +66,4 @@ | |||
1762 | 66 | self.assertTrue(result) | 66 | self.assertTrue(result) |
1763 | 67 | mocked_close_all.assert_called_once_with() | 67 | mocked_close_all.assert_called_once_with() |
1764 | 68 | self.assertIsNone(mocked_bible.session) | 68 | self.assertIsNone(mocked_bible.session) |
1766 | 69 | mocked_delete_file.assert_called_once_with('bibles/KJV.sqlite') | 69 | mocked_delete_file.assert_called_once_with(Path('bibles', 'KJV.sqlite')) |
1767 | 70 | 70 | ||
1768 | === modified file 'tests/functional/openlp_plugins/media/test_mediaplugin.py' | |||
1769 | --- tests/functional/openlp_plugins/media/test_mediaplugin.py 2017-06-06 20:58:12 +0000 | |||
1770 | +++ tests/functional/openlp_plugins/media/test_mediaplugin.py 2017-08-24 19:54:19 +0000 | |||
1771 | @@ -38,20 +38,18 @@ | |||
1772 | 38 | def setUp(self): | 38 | def setUp(self): |
1773 | 39 | Registry.create() | 39 | Registry.create() |
1774 | 40 | 40 | ||
1776 | 41 | @patch(u'openlp.plugins.media.mediaplugin.Plugin.initialise') | 41 | @patch('openlp.plugins.media.mediaplugin.Plugin.initialise') |
1777 | 42 | def test_initialise(self, mocked_initialise): | 42 | def test_initialise(self, mocked_initialise): |
1778 | 43 | """ | 43 | """ |
1779 | 44 | Test that the initialise() method overwrites the built-in one, but still calls it | 44 | Test that the initialise() method overwrites the built-in one, but still calls it |
1780 | 45 | """ | 45 | """ |
1782 | 46 | # GIVEN: A media plugin instance and a mocked settings object | 46 | # GIVEN: A media plugin instance |
1783 | 47 | media_plugin = MediaPlugin() | 47 | media_plugin = MediaPlugin() |
1784 | 48 | mocked_settings = MagicMock() | ||
1785 | 49 | mocked_settings.get_files_from_config.return_value = True # Not the real value, just need something "true-ish" | ||
1786 | 50 | 48 | ||
1787 | 51 | # WHEN: initialise() is called | 49 | # WHEN: initialise() is called |
1788 | 52 | media_plugin.initialise() | 50 | media_plugin.initialise() |
1789 | 53 | 51 | ||
1791 | 54 | # THEN: The settings should be upgraded and the base initialise() method should be called | 52 | # THEN: The the base initialise() method should be called |
1792 | 55 | mocked_initialise.assert_called_with() | 53 | mocked_initialise.assert_called_with() |
1793 | 56 | 54 | ||
1794 | 57 | def test_about_text(self): | 55 | def test_about_text(self): |
1795 | 58 | 56 | ||
1796 | === modified file 'tests/functional/openlp_plugins/presentations/test_presentationcontroller.py' | |||
1797 | --- tests/functional/openlp_plugins/presentations/test_presentationcontroller.py 2017-05-30 18:42:35 +0000 | |||
1798 | +++ tests/functional/openlp_plugins/presentations/test_presentationcontroller.py 2017-08-24 19:54:19 +0000 | |||
1799 | @@ -24,6 +24,7 @@ | |||
1800 | 24 | classes and related methods. | 24 | classes and related methods. |
1801 | 25 | """ | 25 | """ |
1802 | 26 | import os | 26 | import os |
1803 | 27 | from pathlib import Path | ||
1804 | 27 | from unittest import TestCase | 28 | from unittest import TestCase |
1805 | 28 | from unittest.mock import MagicMock, mock_open, patch | 29 | from unittest.mock import MagicMock, mock_open, patch |
1806 | 29 | 30 | ||
1807 | @@ -38,7 +39,8 @@ | |||
1808 | 38 | """ | 39 | """ |
1809 | 39 | def setUp(self): | 40 | def setUp(self): |
1810 | 40 | self.get_thumbnail_folder_patcher = \ | 41 | self.get_thumbnail_folder_patcher = \ |
1812 | 41 | patch('openlp.plugins.presentations.lib.presentationcontroller.PresentationDocument.get_thumbnail_folder') | 42 | patch('openlp.plugins.presentations.lib.presentationcontroller.PresentationDocument.get_thumbnail_folder', |
1813 | 43 | return_value=Path()) | ||
1814 | 42 | self.get_thumbnail_folder_patcher.start() | 44 | self.get_thumbnail_folder_patcher.start() |
1815 | 43 | mocked_plugin = MagicMock() | 45 | mocked_plugin = MagicMock() |
1816 | 44 | mocked_plugin.settings_section = 'presentations' | 46 | mocked_plugin.settings_section = 'presentations' |
1817 | @@ -225,7 +227,7 @@ | |||
1818 | 225 | PresentationDocument(self.mock_controller, 'Name') | 227 | PresentationDocument(self.mock_controller, 'Name') |
1819 | 226 | 228 | ||
1820 | 227 | # THEN: check_directory_exists should have been called with 'returned/path/' | 229 | # THEN: check_directory_exists should have been called with 'returned/path/' |
1822 | 228 | self.mock_check_directory_exists.assert_called_once_with('returned/path/') | 230 | self.mock_check_directory_exists.assert_called_once_with(Path('returned', 'path')) |
1823 | 229 | 231 | ||
1824 | 230 | self._setup_patcher.start() | 232 | self._setup_patcher.start() |
1825 | 231 | 233 | ||
1826 | 232 | 234 | ||
1827 | === modified file 'tests/interfaces/openlp_core_common/test_utils.py' | |||
1828 | --- tests/interfaces/openlp_core_common/test_utils.py 2016-12-31 11:01:36 +0000 | |||
1829 | +++ tests/interfaces/openlp_core_common/test_utils.py 2017-08-24 19:54:19 +0000 | |||
1830 | @@ -22,7 +22,7 @@ | |||
1831 | 22 | """ | 22 | """ |
1832 | 23 | Functional tests to test the AppLocation class and related methods. | 23 | Functional tests to test the AppLocation class and related methods. |
1833 | 24 | """ | 24 | """ |
1835 | 25 | import os | 25 | from pathlib import Path |
1836 | 26 | from unittest import TestCase | 26 | from unittest import TestCase |
1837 | 27 | 27 | ||
1838 | 28 | from openlp.core.common import is_not_image_file | 28 | from openlp.core.common import is_not_image_file |
1839 | @@ -59,7 +59,7 @@ | |||
1840 | 59 | Test the method handles an image file | 59 | Test the method handles an image file |
1841 | 60 | """ | 60 | """ |
1842 | 61 | # Given and empty string | 61 | # Given and empty string |
1844 | 62 | file_name = os.path.join(TEST_RESOURCES_PATH, 'church.jpg') | 62 | file_name = Path(TEST_RESOURCES_PATH, 'church.jpg') |
1845 | 63 | 63 | ||
1846 | 64 | # WHEN testing for it | 64 | # WHEN testing for it |
1847 | 65 | result = is_not_image_file(file_name) | 65 | result = is_not_image_file(file_name) |
1848 | @@ -72,7 +72,7 @@ | |||
1849 | 72 | Test the method handles a non image file | 72 | Test the method handles a non image file |
1850 | 73 | """ | 73 | """ |
1851 | 74 | # Given and empty string | 74 | # Given and empty string |
1853 | 75 | file_name = os.path.join(TEST_RESOURCES_PATH, 'serviceitem_custom_1.osj') | 75 | file_name = Path(TEST_RESOURCES_PATH, 'serviceitem_custom_1.osj') |
1854 | 76 | 76 | ||
1855 | 77 | # WHEN testing for it | 77 | # WHEN testing for it |
1856 | 78 | result = is_not_image_file(file_name) | 78 | result = is_not_image_file(file_name) |
See inline