Status: | Superseded |
---|---|
Proposed branch: | lp:~phill-ridout/openlp/pathlib3 |
Merge into: | lp:openlp |
Diff against target: |
1730 lines (+292/-327) 42 files modified
openlp/core/__init__.py (+16/-12) 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/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) 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 | Needs Fixing | ||
Raoul Snyman | Needs Information | ||
Tim Bentley | Needs Fixing | ||
Review via email: mp+328950@code.launchpad.net |
This proposal has been superseded by a proposal from 2017-08-23.
Commit message
Description of the change
Part 3, converted some more utility methods
lp:~phill-ridout/openlp/pathlib3 (revision 2759)
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[FAILURE] https:/
Stopping after failure
Raoul Snyman (raoul-snyman) : | # |
Phill (phill-ridout) wrote : | # |
> See inline
See my inline reply.
Phill (phill-ridout) wrote : | # |
See my inline reply.
Phill (phill-ridout) wrote : | # |
See inline
Tomas Groth (tomasgroth) wrote : | # |
It seems the AppVeyor tests fails for a reason: https:/
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-23 20:14:53 +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/common/__init__.py' | |||
70 | --- openlp/core/common/__init__.py 2017-08-01 20:59:41 +0000 | |||
71 | +++ openlp/core/common/__init__.py 2017-08-23 20:14:53 +0000 | |||
72 | @@ -32,7 +32,6 @@ | |||
73 | 32 | import traceback | 32 | import traceback |
74 | 33 | from chardet.universaldetector import UniversalDetector | 33 | from chardet.universaldetector import UniversalDetector |
75 | 34 | from ipaddress import IPv4Address, IPv6Address, AddressValueError | 34 | from ipaddress import IPv4Address, IPv6Address, AddressValueError |
76 | 35 | from pathlib import Path | ||
77 | 36 | from shutil import which | 35 | from shutil import which |
78 | 37 | from subprocess import check_output, CalledProcessError, STDOUT | 36 | from subprocess import check_output, CalledProcessError, STDOUT |
79 | 38 | 37 | ||
80 | @@ -65,17 +64,19 @@ | |||
81 | 65 | 64 | ||
82 | 66 | def check_directory_exists(directory, do_not_log=False): | 65 | def check_directory_exists(directory, do_not_log=False): |
83 | 67 | """ | 66 | """ |
85 | 68 | Check a theme directory exists and if not create it | 67 | Check a directory exists and if not create it |
86 | 69 | 68 | ||
89 | 70 | :param directory: The directory to make sure exists | 69 | :param pathlib.Path directory: The directory to make sure exists |
90 | 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. |
91 | 71 | :return: None | ||
92 | 72 | :rtype: None | ||
93 | 72 | """ | 73 | """ |
94 | 73 | if not do_not_log: | 74 | if not do_not_log: |
95 | 74 | log.debug('check_directory_exists {text}'.format(text=directory)) | 75 | log.debug('check_directory_exists {text}'.format(text=directory)) |
96 | 75 | try: | 76 | try: |
100 | 76 | if not os.path.exists(directory): | 77 | if not directory.exists(): |
101 | 77 | os.makedirs(directory) | 78 | directory.mkdir(parents=True) |
102 | 78 | except IOError as e: | 79 | except IOError: |
103 | 79 | if not do_not_log: | 80 | if not do_not_log: |
104 | 80 | log.exception('failed to check if directory exists or create directory') | 81 | log.exception('failed to check if directory exists or create directory') |
105 | 81 | 82 | ||
106 | @@ -85,19 +86,15 @@ | |||
107 | 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 |
108 | 86 | importers. | 87 | importers. |
109 | 87 | 88 | ||
117 | 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 |
118 | 89 | application directory. i.e. openlp/plugins/*/*plugin.py | 90 | application directory. i.e. plugins/*/*plugin.py |
119 | 90 | :type glob_pattern: str | 91 | :param list[str] excluded_files: A list of file names to exclude that the glob pattern may find. |
113 | 91 | |||
114 | 92 | :param excluded_files: A list of file names to exclude that the glob pattern may find. | ||
115 | 93 | :type excluded_files: list of strings | ||
116 | 94 | |||
120 | 95 | :return: None | 92 | :return: None |
121 | 96 | :rtype: None | 93 | :rtype: None |
122 | 97 | """ | 94 | """ |
126 | 98 | base_dir_path = AppLocation.get_directory(AppLocation.AppDir).parent | 95 | app_dir = AppLocation.get_directory(AppLocation.AppDir) |
127 | 99 | for extension_path in base_dir_path.glob(glob_pattern): | 96 | for extension_path in app_dir.glob(glob_pattern): |
128 | 100 | extension_path = extension_path.relative_to(base_dir_path) | 97 | extension_path = extension_path.relative_to(app_dir) |
129 | 101 | if extension_path.name in excluded_files: | 98 | if extension_path.name in excluded_files: |
130 | 102 | continue | 99 | continue |
131 | 103 | module_name = path_to_module(extension_path) | 100 | module_name = path_to_module(extension_path) |
132 | @@ -106,21 +103,19 @@ | |||
133 | 106 | except (ImportError, OSError): | 103 | except (ImportError, OSError): |
134 | 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) |
135 | 108 | log.warning('Failed to import {module_name} on path {extension_path}' | 105 | log.warning('Failed to import {module_name} on path {extension_path}' |
137 | 109 | .format(module_name=module_name, extension_path=str(extension_path))) | 106 | .format(module_name=module_name, extension_path=extension_path)) |
138 | 110 | 107 | ||
139 | 111 | 108 | ||
140 | 112 | def path_to_module(path): | 109 | def path_to_module(path): |
141 | 113 | """ | 110 | """ |
142 | 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) |
143 | 115 | 112 | ||
147 | 116 | :param path: The path to convert to a module name. | 113 | :param pathlib.Path path: The path to convert to a module name. |
145 | 117 | :type path: Path | ||
146 | 118 | |||
148 | 119 | :return: The module name. | 114 | :return: The module name. |
149 | 120 | :rtype: str | 115 | :rtype: str |
150 | 121 | """ | 116 | """ |
151 | 122 | module_path = path.with_suffix('') | 117 | module_path = path.with_suffix('') |
153 | 123 | return '.'.join(module_path.parts) | 118 | return 'openlp.' + '.'.join(module_path.parts) |
154 | 124 | 119 | ||
155 | 125 | 120 | ||
156 | 126 | def get_frozen_path(frozen_option, non_frozen_option): | 121 | def get_frozen_path(frozen_option, non_frozen_option): |
157 | @@ -378,20 +373,22 @@ | |||
158 | 378 | return os.path.split(path) | 373 | return os.path.split(path) |
159 | 379 | 374 | ||
160 | 380 | 375 | ||
162 | 381 | def delete_file(file_path_name): | 376 | def delete_file(file_path): |
163 | 382 | """ | 377 | """ |
164 | 383 | Deletes a file from the system. | 378 | Deletes a file from the system. |
165 | 384 | 379 | ||
167 | 385 | :param file_path_name: The file, including path, to delete. | 380 | :param pathlib.Path file_path: The file, including path, to delete. |
168 | 381 | :return: True if the deletion was successful, or the file never existed. False otherwise. | ||
169 | 382 | :rtype: bool | ||
170 | 386 | """ | 383 | """ |
172 | 387 | if not file_path_name: | 384 | if not file_path: |
173 | 388 | return False | 385 | return False |
174 | 389 | try: | 386 | try: |
177 | 390 | if os.path.exists(file_path_name): | 387 | if file_path.exists(): |
178 | 391 | os.remove(file_path_name) | 388 | file_path.unlink() |
179 | 392 | return True | 389 | return True |
180 | 393 | except (IOError, OSError): | 390 | except (IOError, OSError): |
182 | 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)) |
183 | 395 | return False | 392 | return False |
184 | 396 | 393 | ||
185 | 397 | 394 | ||
186 | @@ -411,18 +408,19 @@ | |||
187 | 411 | return IMAGES_FILTER | 408 | return IMAGES_FILTER |
188 | 412 | 409 | ||
189 | 413 | 410 | ||
191 | 414 | def is_not_image_file(file_name): | 411 | def is_not_image_file(file_path): |
192 | 415 | """ | 412 | """ |
193 | 416 | Validate that the file is not an image file. | 413 | Validate that the file is not an image file. |
194 | 417 | 414 | ||
196 | 418 | :param file_name: File name to be checked. | 415 | :param pathlib.Path file_path: The file to be checked. |
197 | 416 | :return: If the file is not an image | ||
198 | 417 | :rtype: bool | ||
199 | 419 | """ | 418 | """ |
201 | 420 | if not file_name: | 419 | if not (file_path and file_path.exists()): |
202 | 421 | return True | 420 | return True |
203 | 422 | else: | 421 | else: |
204 | 423 | formats = [bytes(fmt).decode().lower() for fmt in QtGui.QImageReader.supportedImageFormats()] | 422 | formats = [bytes(fmt).decode().lower() for fmt in QtGui.QImageReader.supportedImageFormats()] |
207 | 424 | file_part, file_extension = os.path.splitext(str(file_name)) | 423 | if file_path.suffix[1:].lower() in formats: |
206 | 425 | if file_extension[1:].lower() in formats and os.path.exists(file_name): | ||
208 | 426 | return False | 424 | return False |
209 | 427 | return True | 425 | return True |
210 | 428 | 426 | ||
211 | @@ -431,10 +429,10 @@ | |||
212 | 431 | """ | 429 | """ |
213 | 432 | Removes invalid characters from the given ``filename``. | 430 | Removes invalid characters from the given ``filename``. |
214 | 433 | 431 | ||
216 | 434 | :param filename: The "dirty" file name to clean. | 432 | :param str filename: The "dirty" file name to clean. |
217 | 433 | :return: The cleaned string | ||
218 | 434 | :rtype: str | ||
219 | 435 | """ | 435 | """ |
220 | 436 | if not isinstance(filename, str): | ||
221 | 437 | filename = str(filename, 'utf-8') | ||
222 | 438 | return INVALID_FILE_CHARS.sub('_', CONTROL_CHARS.sub('', filename)) | 436 | return INVALID_FILE_CHARS.sub('_', CONTROL_CHARS.sub('', filename)) |
223 | 439 | 437 | ||
224 | 440 | 438 | ||
225 | @@ -442,8 +440,9 @@ | |||
226 | 442 | """ | 440 | """ |
227 | 443 | Function that checks whether a binary exists. | 441 | Function that checks whether a binary exists. |
228 | 444 | 442 | ||
230 | 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. |
231 | 446 | :return: program output to be parsed | 444 | :return: program output to be parsed |
232 | 445 | :rtype: bytes | ||
233 | 447 | """ | 446 | """ |
234 | 448 | log.debug('testing program_path: {text}'.format(text=program_path)) | 447 | log.debug('testing program_path: {text}'.format(text=program_path)) |
235 | 449 | try: | 448 | try: |
236 | @@ -453,26 +452,27 @@ | |||
237 | 453 | startupinfo.dwFlags |= STARTF_USESHOWWINDOW | 452 | startupinfo.dwFlags |= STARTF_USESHOWWINDOW |
238 | 454 | else: | 453 | else: |
239 | 455 | startupinfo = None | 454 | startupinfo = None |
241 | 456 | runlog = check_output([program_path, '--help'], stderr=STDOUT, startupinfo=startupinfo) | 455 | run_log = check_output([str(program_path), '--help'], stderr=STDOUT, startupinfo=startupinfo) |
242 | 457 | except CalledProcessError as e: | 456 | except CalledProcessError as e: |
244 | 458 | runlog = e.output | 457 | run_log = e.output |
245 | 459 | except Exception: | 458 | except Exception: |
246 | 460 | trace_error_handler(log) | 459 | trace_error_handler(log) |
253 | 461 | runlog = '' | 460 | run_log = '' |
254 | 462 | log.debug('check_output returned: {text}'.format(text=runlog)) | 461 | log.debug('check_output returned: {text}'.format(text=run_log)) |
255 | 463 | return runlog | 462 | return run_log |
256 | 464 | 463 | ||
257 | 465 | 464 | ||
258 | 466 | def get_file_encoding(filename): | 465 | def get_file_encoding(file_path): |
259 | 467 | """ | 466 | """ |
260 | 468 | Utility function to incrementally detect the file encoding. | 467 | Utility function to incrementally detect the file encoding. |
261 | 469 | 468 | ||
263 | 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. |
264 | 471 | :return: A dict with the keys 'encoding' and 'confidence' | 470 | :return: A dict with the keys 'encoding' and 'confidence' |
265 | 471 | :rtype: dict[str, float] | ||
266 | 472 | """ | 472 | """ |
267 | 473 | detector = UniversalDetector() | 473 | detector = UniversalDetector() |
268 | 474 | try: | 474 | try: |
270 | 475 | with open(filename, 'rb') as detect_file: | 475 | with file_path.open('rb') as detect_file: |
271 | 476 | while not detector.done: | 476 | while not detector.done: |
272 | 477 | chunk = detect_file.read(1024) | 477 | chunk = detect_file.read(1024) |
273 | 478 | if not chunk: | 478 | if not chunk: |
274 | 479 | 479 | ||
275 | === modified file 'openlp/core/common/applocation.py' | |||
276 | --- openlp/core/common/applocation.py 2017-08-02 06:09:38 +0000 | |||
277 | +++ openlp/core/common/applocation.py 2017-08-23 20:14:53 +0000 | |||
278 | @@ -58,9 +58,6 @@ | |||
279 | 58 | CacheDir = 5 | 58 | CacheDir = 5 |
280 | 59 | LanguageDir = 6 | 59 | LanguageDir = 6 |
281 | 60 | 60 | ||
282 | 61 | # Base path where data/config/cache dir is located | ||
283 | 62 | BaseDir = None | ||
284 | 63 | |||
285 | 64 | @staticmethod | 61 | @staticmethod |
286 | 65 | def get_directory(dir_type=AppDir): | 62 | def get_directory(dir_type=AppDir): |
287 | 66 | """ | 63 | """ |
288 | @@ -78,8 +75,6 @@ | |||
289 | 78 | return get_frozen_path(FROZEN_APP_PATH, APP_PATH) / 'plugins' | 75 | return get_frozen_path(FROZEN_APP_PATH, APP_PATH) / 'plugins' |
290 | 79 | elif dir_type == AppLocation.LanguageDir: | 76 | elif dir_type == AppLocation.LanguageDir: |
291 | 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' |
292 | 81 | elif dir_type == AppLocation.DataDir and AppLocation.BaseDir: | ||
293 | 82 | return Path(AppLocation.BaseDir, 'data') | ||
294 | 83 | else: | 78 | else: |
295 | 84 | return _get_os_dir_path(dir_type) | 79 | return _get_os_dir_path(dir_type) |
296 | 85 | 80 | ||
297 | @@ -96,7 +91,7 @@ | |||
298 | 96 | path = Path(Settings().value('advanced/data path')) | 91 | path = Path(Settings().value('advanced/data path')) |
299 | 97 | else: | 92 | else: |
300 | 98 | path = AppLocation.get_directory(AppLocation.DataDir) | 93 | path = AppLocation.get_directory(AppLocation.DataDir) |
302 | 99 | check_directory_exists(str(path)) | 94 | check_directory_exists(path) |
303 | 100 | return path | 95 | return path |
304 | 101 | 96 | ||
305 | 102 | @staticmethod | 97 | @staticmethod |
306 | @@ -104,14 +99,10 @@ | |||
307 | 104 | """ | 99 | """ |
308 | 105 | Get a list of files from the data files path. | 100 | Get a list of files from the data files path. |
309 | 106 | 101 | ||
315 | 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 |
316 | 108 | subdirectory. | 103 | section's data subdirectory. |
317 | 109 | :type section: None | str | 104 | :param str extension: Defaults to ''. The extension to search for. For example:: |
313 | 110 | |||
314 | 111 | :param extension: Defaults to ''. The extension to search for. For example:: | ||
318 | 112 | '.png' | 105 | '.png' |
319 | 113 | :type extension: str | ||
320 | 114 | |||
321 | 115 | :return: List of files found. | 106 | :return: List of files found. |
322 | 116 | :rtype: list[pathlib.Path] | 107 | :rtype: list[pathlib.Path] |
323 | 117 | """ | 108 | """ |
324 | @@ -134,7 +125,7 @@ | |||
325 | 134 | :rtype: pathlib.Path | 125 | :rtype: pathlib.Path |
326 | 135 | """ | 126 | """ |
327 | 136 | path = AppLocation.get_data_path() / section | 127 | path = AppLocation.get_data_path() / section |
329 | 137 | check_directory_exists(str(path)) | 128 | check_directory_exists(path) |
330 | 138 | return path | 129 | return path |
331 | 139 | 130 | ||
332 | 140 | 131 | ||
333 | @@ -143,14 +134,12 @@ | |||
334 | 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. |
335 | 144 | 135 | ||
336 | 145 | :param dir_type: AppLocation Enum of the requested path type | 136 | :param dir_type: AppLocation Enum of the requested path type |
337 | 146 | :type dir_type: AppLocation Enum | ||
338 | 147 | |||
339 | 148 | :return: The requested path | 137 | :return: The requested path |
340 | 149 | :rtype: pathlib.Path | 138 | :rtype: pathlib.Path |
341 | 150 | """ | 139 | """ |
342 | 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 |
343 | 152 | if dir_type == AppLocation.LanguageDir: | 141 | if dir_type == AppLocation.LanguageDir: |
345 | 153 | directory = Path(os.path.abspath(os.path.join(os.path.dirname(openlp.__file__), '..', 'resources'))) | 142 | directory = Path(openlp.__file__, '..', '..').resolve() / 'resources' |
346 | 154 | if directory.exists(): | 143 | if directory.exists(): |
347 | 155 | return directory | 144 | return directory |
348 | 156 | if is_win(): | 145 | if is_win(): |
349 | @@ -158,14 +147,14 @@ | |||
350 | 158 | if dir_type == AppLocation.DataDir: | 147 | if dir_type == AppLocation.DataDir: |
351 | 159 | return openlp_folder_path / 'data' | 148 | return openlp_folder_path / 'data' |
352 | 160 | elif dir_type == AppLocation.LanguageDir: | 149 | elif dir_type == AppLocation.LanguageDir: |
354 | 161 | return os.path.dirname(openlp.__file__) | 150 | return Path(openlp.__file__).parent |
355 | 162 | return openlp_folder_path | 151 | return openlp_folder_path |
356 | 163 | elif is_macosx(): | 152 | elif is_macosx(): |
357 | 164 | openlp_folder_path = Path(os.getenv('HOME'), 'Library', 'Application Support', 'openlp') | 153 | openlp_folder_path = Path(os.getenv('HOME'), 'Library', 'Application Support', 'openlp') |
358 | 165 | if dir_type == AppLocation.DataDir: | 154 | if dir_type == AppLocation.DataDir: |
359 | 166 | return openlp_folder_path / 'Data' | 155 | return openlp_folder_path / 'Data' |
360 | 167 | elif dir_type == AppLocation.LanguageDir: | 156 | elif dir_type == AppLocation.LanguageDir: |
362 | 168 | return os.path.dirname(openlp.__file__) | 157 | return Path(openlp.__file__).parent |
363 | 169 | return openlp_folder_path | 158 | return openlp_folder_path |
364 | 170 | else: | 159 | else: |
365 | 171 | if dir_type == AppLocation.LanguageDir: | 160 | if dir_type == AppLocation.LanguageDir: |
366 | 172 | 161 | ||
367 | === modified file 'openlp/core/common/settings.py' | |||
368 | --- openlp/core/common/settings.py 2017-06-09 15:56:40 +0000 | |||
369 | +++ openlp/core/common/settings.py 2017-08-23 20:14:53 +0000 | |||
370 | @@ -501,31 +501,3 @@ | |||
371 | 501 | if isinstance(default_value, int): | 501 | if isinstance(default_value, int): |
372 | 502 | return int(setting) | 502 | return int(setting) |
373 | 503 | return setting | 503 | return setting |
374 | 504 | |||
375 | 505 | def get_files_from_config(self, plugin): | ||
376 | 506 | """ | ||
377 | 507 | This removes the settings needed for old way we saved files (e. g. the image paths for the image plugin). A list | ||
378 | 508 | of file paths are returned. | ||
379 | 509 | |||
380 | 510 | **Note**: Only a list of paths is returned; this does not convert anything! | ||
381 | 511 | |||
382 | 512 | :param plugin: The Plugin object.The caller has to convert/save the list himself; o | ||
383 | 513 | """ | ||
384 | 514 | files_list = [] | ||
385 | 515 | # We need QSettings instead of Settings here to bypass our central settings dict. | ||
386 | 516 | # Do NOT do this anywhere else! | ||
387 | 517 | settings = QtCore.QSettings(self.fileName(), Settings.IniFormat) | ||
388 | 518 | settings.beginGroup(plugin.settings_section) | ||
389 | 519 | if settings.contains('{name} count'.format(name=plugin.name)): | ||
390 | 520 | # Get the count. | ||
391 | 521 | list_count = int(settings.value('{name} count'.format(name=plugin.name), 0)) | ||
392 | 522 | if list_count: | ||
393 | 523 | for counter in range(list_count): | ||
394 | 524 | # The keys were named e. g.: "image 0" | ||
395 | 525 | item = settings.value('{name} {counter:d}'.format(name=plugin.name, counter=counter), '') | ||
396 | 526 | if item: | ||
397 | 527 | files_list.append(item) | ||
398 | 528 | settings.remove('{name} {counter:d}'.format(name=plugin.name, counter=counter)) | ||
399 | 529 | settings.remove('{name} count'.format(name=plugin.name)) | ||
400 | 530 | settings.endGroup() | ||
401 | 531 | return files_list | ||
402 | 532 | 504 | ||
403 | === modified file 'openlp/core/lib/__init__.py' | |||
404 | --- openlp/core/lib/__init__.py 2017-08-07 20:51:50 +0000 | |||
405 | +++ openlp/core/lib/__init__.py 2017-08-23 20:14:53 +0000 | |||
406 | @@ -83,30 +83,28 @@ | |||
407 | 83 | Next = 3 | 83 | Next = 3 |
408 | 84 | 84 | ||
409 | 85 | 85 | ||
411 | 86 | def get_text_file_string(text_file): | 86 | def get_text_file_string(text_file_path): |
412 | 87 | """ | 87 | """ |
414 | 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 |
415 | 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 |
416 | 90 | None. | 90 | None. |
417 | 91 | 91 | ||
420 | 92 | :param text_file: The name of the file. | 92 | :param pathlib.Path text_file_path: The path to the file. |
421 | 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 |
422 | 94 | decoding the file. | ||
423 | 95 | :rtype: str | False | None | ||
424 | 94 | """ | 96 | """ |
426 | 95 | if not os.path.isfile(text_file): | 97 | if not text_file_path.is_file(): |
427 | 96 | return False | 98 | return False |
428 | 97 | file_handle = None | ||
429 | 98 | content = None | 99 | content = None |
430 | 99 | try: | 100 | try: |
436 | 100 | file_handle = open(text_file, 'r', encoding='utf-8') | 101 | with text_file_path.open('r', encoding='utf-8') as file_handle: |
437 | 101 | if file_handle.read(3) != '\xEF\xBB\xBF': | 102 | if file_handle.read(3) != '\xEF\xBB\xBF': |
438 | 102 | # no BOM was found | 103 | # no BOM was found |
439 | 103 | file_handle.seek(0) | 104 | file_handle.seek(0) |
440 | 104 | content = file_handle.read() | 105 | content = file_handle.read() |
441 | 105 | except (IOError, UnicodeError): | 106 | except (IOError, UnicodeError): |
446 | 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)) |
443 | 107 | finally: | ||
444 | 108 | if file_handle: | ||
445 | 109 | file_handle.close() | ||
447 | 110 | return content | 108 | return content |
448 | 111 | 109 | ||
449 | 112 | 110 | ||
450 | 113 | 111 | ||
451 | === modified file 'openlp/core/lib/db.py' | |||
452 | --- openlp/core/lib/db.py 2017-08-01 20:59:41 +0000 | |||
453 | +++ openlp/core/lib/db.py 2017-08-23 20:14:53 +0000 | |||
454 | @@ -274,9 +274,9 @@ | |||
455 | 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. |
456 | 275 | """ | 275 | """ |
457 | 276 | if db_file_name: | 276 | if db_file_name: |
459 | 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 |
460 | 278 | else: | 278 | else: |
462 | 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 |
463 | 280 | return delete_file(db_file_path) | 280 | return delete_file(db_file_path) |
464 | 281 | 281 | ||
465 | 282 | 282 | ||
466 | 283 | 283 | ||
467 | === modified file 'openlp/core/lib/pluginmanager.py' | |||
468 | --- openlp/core/lib/pluginmanager.py 2017-08-01 20:59:41 +0000 | |||
469 | +++ openlp/core/lib/pluginmanager.py 2017-08-23 20:14:53 +0000 | |||
470 | @@ -69,7 +69,7 @@ | |||
471 | 69 | """ | 69 | """ |
472 | 70 | Scan a directory for objects inheriting from the ``Plugin`` class. | 70 | Scan a directory for objects inheriting from the ``Plugin`` class. |
473 | 71 | """ | 71 | """ |
475 | 72 | glob_pattern = os.path.join('openlp', 'plugins', '*', '*plugin.py') | 72 | glob_pattern = os.path.join('plugins', '*', '*plugin.py') |
476 | 73 | extension_loader(glob_pattern) | 73 | extension_loader(glob_pattern) |
477 | 74 | plugin_classes = Plugin.__subclasses__() | 74 | plugin_classes = Plugin.__subclasses__() |
478 | 75 | plugin_objects = [] | 75 | plugin_objects = [] |
479 | 76 | 76 | ||
480 | === modified file 'openlp/core/lib/theme.py' | |||
481 | --- openlp/core/lib/theme.py 2017-08-01 20:59:41 +0000 | |||
482 | +++ openlp/core/lib/theme.py 2017-08-23 20:14:53 +0000 | |||
483 | @@ -158,9 +158,8 @@ | |||
484 | 158 | Initialise the theme object. | 158 | Initialise the theme object. |
485 | 159 | """ | 159 | """ |
486 | 160 | # basic theme object with defaults | 160 | # basic theme object with defaults |
490 | 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' |
491 | 162 | json_file = os.path.join(json_dir, 'theme.json') | 162 | jsn = get_text_file_string(json_path) |
489 | 163 | jsn = get_text_file_string(json_file) | ||
492 | 164 | jsn = json.loads(jsn) | 163 | jsn = json.loads(jsn) |
493 | 165 | self.expand_json(jsn) | 164 | self.expand_json(jsn) |
494 | 166 | self.background_filename = '' | 165 | self.background_filename = '' |
495 | 167 | 166 | ||
496 | === modified file 'openlp/core/ui/firsttimeform.py' | |||
497 | --- openlp/core/ui/firsttimeform.py 2017-08-03 17:54:40 +0000 | |||
498 | +++ openlp/core/ui/firsttimeform.py 2017-08-23 20:14:53 +0000 | |||
499 | @@ -29,8 +29,9 @@ | |||
500 | 29 | import urllib.request | 29 | import urllib.request |
501 | 30 | import urllib.parse | 30 | import urllib.parse |
502 | 31 | import urllib.error | 31 | import urllib.error |
503 | 32 | from configparser import ConfigParser, MissingSectionHeaderError, NoOptionError, NoSectionError | ||
504 | 33 | from pathlib import Path | ||
505 | 32 | from tempfile import gettempdir | 34 | from tempfile import gettempdir |
506 | 33 | from configparser import ConfigParser, MissingSectionHeaderError, NoSectionError, NoOptionError | ||
507 | 34 | 35 | ||
508 | 35 | from PyQt5 import QtCore, QtWidgets | 36 | from PyQt5 import QtCore, QtWidgets |
509 | 36 | 37 | ||
510 | @@ -282,7 +283,7 @@ | |||
511 | 282 | self.no_internet_cancel_button.setVisible(False) | 283 | self.no_internet_cancel_button.setVisible(False) |
512 | 283 | # Check if this is a re-run of the wizard. | 284 | # Check if this is a re-run of the wizard. |
513 | 284 | self.has_run_wizard = Settings().value('core/has run wizard') | 285 | self.has_run_wizard = Settings().value('core/has run wizard') |
515 | 285 | check_directory_exists(os.path.join(gettempdir(), 'openlp')) | 286 | check_directory_exists(Path(gettempdir(), 'openlp')) |
516 | 286 | 287 | ||
517 | 287 | def update_screen_list_combo(self): | 288 | def update_screen_list_combo(self): |
518 | 288 | """ | 289 | """ |
519 | 289 | 290 | ||
520 | === modified file 'openlp/core/ui/mainwindow.py' | |||
521 | --- openlp/core/ui/mainwindow.py 2017-08-03 17:54:40 +0000 | |||
522 | +++ openlp/core/ui/mainwindow.py 2017-08-23 20:14:53 +0000 | |||
523 | @@ -30,6 +30,7 @@ | |||
524 | 30 | from datetime import datetime | 30 | from datetime import datetime |
525 | 31 | from distutils import dir_util | 31 | from distutils import dir_util |
526 | 32 | from distutils.errors import DistutilsFileError | 32 | from distutils.errors import DistutilsFileError |
527 | 33 | from pathlib import Path | ||
528 | 33 | from tempfile import gettempdir | 34 | from tempfile import gettempdir |
529 | 34 | 35 | ||
530 | 35 | from PyQt5 import QtCore, QtGui, QtWidgets | 36 | from PyQt5 import QtCore, QtGui, QtWidgets |
531 | @@ -870,7 +871,7 @@ | |||
532 | 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]) |
533 | 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. |
534 | 872 | temp_directory = os.path.join(str(gettempdir()), 'openlp') | 873 | temp_directory = os.path.join(str(gettempdir()), 'openlp') |
536 | 873 | check_directory_exists(temp_directory) | 874 | check_directory_exists(Path(temp_directory)) |
537 | 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)) |
538 | 875 | shutil.copyfile(import_file_name, temp_config) | 876 | shutil.copyfile(import_file_name, temp_config) |
539 | 876 | settings = Settings() | 877 | settings = Settings() |
540 | 877 | 878 | ||
541 | === modified file 'openlp/core/ui/media/mediacontroller.py' | |||
542 | --- openlp/core/ui/media/mediacontroller.py 2017-06-25 17:03:31 +0000 | |||
543 | +++ openlp/core/ui/media/mediacontroller.py 2017-08-23 20:14:53 +0000 | |||
544 | @@ -177,7 +177,7 @@ | |||
545 | 177 | Check to see if we have any media Player's available. | 177 | Check to see if we have any media Player's available. |
546 | 178 | """ | 178 | """ |
547 | 179 | log.debug('_check_available_media_players') | 179 | log.debug('_check_available_media_players') |
549 | 180 | controller_dir = os.path.join('openlp', 'core', 'ui', 'media') | 180 | controller_dir = os.path.join('core', 'ui', 'media') |
550 | 181 | glob_pattern = os.path.join(controller_dir, '*player.py') | 181 | glob_pattern = os.path.join(controller_dir, '*player.py') |
551 | 182 | extension_loader(glob_pattern, ['mediaplayer.py']) | 182 | extension_loader(glob_pattern, ['mediaplayer.py']) |
552 | 183 | player_classes = MediaPlayer.__subclasses__() | 183 | player_classes = MediaPlayer.__subclasses__() |
553 | 184 | 184 | ||
554 | === modified file 'openlp/core/ui/printserviceform.py' | |||
555 | --- openlp/core/ui/printserviceform.py 2017-08-01 20:59:41 +0000 | |||
556 | +++ openlp/core/ui/printserviceform.py 2017-08-23 20:14:53 +0000 | |||
557 | @@ -176,7 +176,7 @@ | |||
558 | 176 | html_data = self._add_element('html') | 176 | html_data = self._add_element('html') |
559 | 177 | self._add_element('head', parent=html_data) | 177 | self._add_element('head', parent=html_data) |
560 | 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) |
562 | 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' |
563 | 180 | custom_css = get_text_file_string(css_path) | 180 | custom_css = get_text_file_string(css_path) |
564 | 181 | if not custom_css: | 181 | if not custom_css: |
565 | 182 | custom_css = DEFAULT_CSS | 182 | custom_css = DEFAULT_CSS |
566 | 183 | 183 | ||
567 | === modified file 'openlp/core/ui/servicemanager.py' | |||
568 | --- openlp/core/ui/servicemanager.py 2017-08-03 17:54:40 +0000 | |||
569 | +++ openlp/core/ui/servicemanager.py 2017-08-23 20:14:53 +0000 | |||
570 | @@ -28,6 +28,7 @@ | |||
571 | 28 | import shutil | 28 | import shutil |
572 | 29 | import zipfile | 29 | import zipfile |
573 | 30 | from datetime import datetime, timedelta | 30 | from datetime import datetime, timedelta |
574 | 31 | from pathlib import Path | ||
575 | 31 | from tempfile import mkstemp | 32 | from tempfile import mkstemp |
576 | 32 | 33 | ||
577 | 33 | from PyQt5 import QtCore, QtGui, QtWidgets | 34 | from PyQt5 import QtCore, QtGui, QtWidgets |
578 | @@ -587,7 +588,7 @@ | |||
579 | 587 | audio_from = os.path.join(self.service_path, audio_from) | 588 | audio_from = os.path.join(self.service_path, audio_from) |
580 | 588 | save_file = os.path.join(self.service_path, audio_to) | 589 | save_file = os.path.join(self.service_path, audio_to) |
581 | 589 | save_path = os.path.split(save_file)[0] | 590 | save_path = os.path.split(save_file)[0] |
583 | 590 | check_directory_exists(save_path) | 591 | check_directory_exists(Path(save_path)) |
584 | 591 | if not os.path.exists(save_file): | 592 | if not os.path.exists(save_file): |
585 | 592 | shutil.copy(audio_from, save_file) | 593 | shutil.copy(audio_from, save_file) |
586 | 593 | zip_file.write(audio_from, audio_to) | 594 | zip_file.write(audio_from, audio_to) |
587 | @@ -614,7 +615,7 @@ | |||
588 | 614 | success = False | 615 | success = False |
589 | 615 | self.main_window.add_recent_file(path_file_name) | 616 | self.main_window.add_recent_file(path_file_name) |
590 | 616 | self.set_modified(False) | 617 | self.set_modified(False) |
592 | 617 | delete_file(temp_file_name) | 618 | delete_file(Path(temp_file_name)) |
593 | 618 | return success | 619 | return success |
594 | 619 | 620 | ||
595 | 620 | def save_local_file(self): | 621 | def save_local_file(self): |
596 | @@ -669,7 +670,7 @@ | |||
597 | 669 | return self.save_file_as() | 670 | return self.save_file_as() |
598 | 670 | self.main_window.add_recent_file(path_file_name) | 671 | self.main_window.add_recent_file(path_file_name) |
599 | 671 | self.set_modified(False) | 672 | self.set_modified(False) |
601 | 672 | delete_file(temp_file_name) | 673 | delete_file(Path(temp_file_name)) |
602 | 673 | return success | 674 | return success |
603 | 674 | 675 | ||
604 | 675 | def save_file_as(self, field=None): | 676 | def save_file_as(self, field=None): |
605 | @@ -774,7 +775,7 @@ | |||
606 | 774 | self.set_file_name(file_name) | 775 | self.set_file_name(file_name) |
607 | 775 | self.main_window.display_progress_bar(len(items)) | 776 | self.main_window.display_progress_bar(len(items)) |
608 | 776 | self.process_service_items(items) | 777 | self.process_service_items(items) |
610 | 777 | delete_file(p_file) | 778 | delete_file(Path(p_file)) |
611 | 778 | self.main_window.add_recent_file(file_name) | 779 | self.main_window.add_recent_file(file_name) |
612 | 779 | self.set_modified(False) | 780 | self.set_modified(False) |
613 | 780 | Settings().setValue('servicemanager/last file', file_name) | 781 | Settings().setValue('servicemanager/last file', file_name) |
614 | @@ -1343,7 +1344,7 @@ | |||
615 | 1343 | Empties the service_path of temporary files on system exit. | 1344 | Empties the service_path of temporary files on system exit. |
616 | 1344 | """ | 1345 | """ |
617 | 1345 | for file_name in os.listdir(self.service_path): | 1346 | for file_name in os.listdir(self.service_path): |
619 | 1346 | file_path = os.path.join(self.service_path, file_name) | 1347 | file_path = Path(self.service_path, file_name) |
620 | 1347 | delete_file(file_path) | 1348 | delete_file(file_path) |
621 | 1348 | if os.path.exists(os.path.join(self.service_path, 'audio')): | 1349 | if os.path.exists(os.path.join(self.service_path, 'audio')): |
622 | 1349 | shutil.rmtree(os.path.join(self.service_path, 'audio'), True) | 1350 | shutil.rmtree(os.path.join(self.service_path, 'audio'), True) |
623 | 1350 | 1351 | ||
624 | === modified file 'openlp/core/ui/themeform.py' | |||
625 | --- openlp/core/ui/themeform.py 2017-08-07 20:50:01 +0000 | |||
626 | +++ openlp/core/ui/themeform.py 2017-08-23 20:14:53 +0000 | |||
627 | @@ -24,6 +24,7 @@ | |||
628 | 24 | """ | 24 | """ |
629 | 25 | import logging | 25 | import logging |
630 | 26 | import os | 26 | import os |
631 | 27 | from pathlib import Path | ||
632 | 27 | 28 | ||
633 | 28 | from PyQt5 import QtCore, QtGui, QtWidgets | 29 | from PyQt5 import QtCore, QtGui, QtWidgets |
634 | 29 | 30 | ||
635 | @@ -188,7 +189,8 @@ | |||
636 | 188 | """ | 189 | """ |
637 | 189 | background_image = BackgroundType.to_string(BackgroundType.Image) | 190 | background_image = BackgroundType.to_string(BackgroundType.Image) |
638 | 190 | if self.page(self.currentId()) == self.background_page and \ | 191 | if self.page(self.currentId()) == self.background_page and \ |
640 | 191 | self.theme.background_type == background_image and is_not_image_file(self.theme.background_filename): | 192 | self.theme.background_type == background_image and \ |
641 | 193 | is_not_image_file(Path(self.theme.background_filename)): | ||
642 | 192 | QtWidgets.QMessageBox.critical(self, translate('OpenLP.ThemeWizard', 'Background Image Empty'), | 194 | QtWidgets.QMessageBox.critical(self, translate('OpenLP.ThemeWizard', 'Background Image Empty'), |
643 | 193 | translate('OpenLP.ThemeWizard', 'You have not selected a ' | 195 | translate('OpenLP.ThemeWizard', 'You have not selected a ' |
644 | 194 | 'background image. Please select one before continuing.')) | 196 | 'background image. Please select one before continuing.')) |
645 | 195 | 197 | ||
646 | === modified file 'openlp/core/ui/thememanager.py' | |||
647 | --- openlp/core/ui/thememanager.py 2017-08-07 20:50:01 +0000 | |||
648 | +++ openlp/core/ui/thememanager.py 2017-08-23 20:14:53 +0000 | |||
649 | @@ -25,6 +25,7 @@ | |||
650 | 25 | import os | 25 | import os |
651 | 26 | import zipfile | 26 | import zipfile |
652 | 27 | import shutil | 27 | import shutil |
653 | 28 | from pathlib import Path | ||
654 | 28 | 29 | ||
655 | 29 | from xml.etree.ElementTree import ElementTree, XML | 30 | from xml.etree.ElementTree import ElementTree, XML |
656 | 30 | from PyQt5 import QtCore, QtGui, QtWidgets | 31 | from PyQt5 import QtCore, QtGui, QtWidgets |
657 | @@ -161,9 +162,9 @@ | |||
658 | 161 | Set up the theme path variables | 162 | Set up the theme path variables |
659 | 162 | """ | 163 | """ |
660 | 163 | self.path = str(AppLocation.get_section_data_path(self.settings_section)) | 164 | self.path = str(AppLocation.get_section_data_path(self.settings_section)) |
662 | 164 | check_directory_exists(self.path) | 165 | check_directory_exists(Path(self.path)) |
663 | 165 | self.thumb_path = os.path.join(self.path, 'thumbnails') | 166 | self.thumb_path = os.path.join(self.path, 'thumbnails') |
665 | 166 | check_directory_exists(self.thumb_path) | 167 | check_directory_exists(Path(self.thumb_path)) |
666 | 167 | 168 | ||
667 | 168 | def check_list_state(self, item, field=None): | 169 | def check_list_state(self, item, field=None): |
668 | 169 | """ | 170 | """ |
669 | @@ -355,8 +356,8 @@ | |||
670 | 355 | """ | 356 | """ |
671 | 356 | self.theme_list.remove(theme) | 357 | self.theme_list.remove(theme) |
672 | 357 | thumb = '{name}.png'.format(name=theme) | 358 | thumb = '{name}.png'.format(name=theme) |
675 | 358 | delete_file(os.path.join(self.path, thumb)) | 359 | delete_file(Path(self.path, thumb)) |
676 | 359 | delete_file(os.path.join(self.thumb_path, thumb)) | 360 | delete_file(Path(self.thumb_path, thumb)) |
677 | 360 | try: | 361 | try: |
678 | 361 | # Windows is always unicode, so no need to encode filenames | 362 | # Windows is always unicode, so no need to encode filenames |
679 | 362 | if is_win(): | 363 | if is_win(): |
680 | @@ -450,7 +451,7 @@ | |||
681 | 450 | for theme_file in files: | 451 | for theme_file in files: |
682 | 451 | theme_file = os.path.join(self.path, str(theme_file)) | 452 | theme_file = os.path.join(self.path, str(theme_file)) |
683 | 452 | self.unzip_theme(theme_file, self.path) | 453 | self.unzip_theme(theme_file, self.path) |
685 | 453 | delete_file(theme_file) | 454 | delete_file(Path(theme_file)) |
686 | 454 | files = AppLocation.get_files(self.settings_section, '.png') | 455 | files = AppLocation.get_files(self.settings_section, '.png') |
687 | 455 | # No themes have been found so create one | 456 | # No themes have been found so create one |
688 | 456 | if not files: | 457 | if not files: |
689 | @@ -514,12 +515,12 @@ | |||
690 | 514 | :return: The theme object. | 515 | :return: The theme object. |
691 | 515 | """ | 516 | """ |
692 | 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)) |
695 | 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)) |
696 | 518 | theme_data = get_text_file_string(theme_file) | 519 | theme_data = get_text_file_string(theme_file_path) |
697 | 519 | jsn = True | 520 | jsn = True |
698 | 520 | if not theme_data: | 521 | if not theme_data: |
701 | 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') |
702 | 522 | theme_data = get_text_file_string(theme_file) | 523 | theme_data = get_text_file_string(theme_file_path) |
703 | 523 | jsn = False | 524 | jsn = False |
704 | 524 | if not theme_data: | 525 | if not theme_data: |
705 | 525 | self.log_debug('No theme data - using default theme') | 526 | self.log_debug('No theme data - using default theme') |
706 | @@ -592,7 +593,7 @@ | |||
707 | 592 | # is directory or preview file | 593 | # is directory or preview file |
708 | 593 | continue | 594 | continue |
709 | 594 | full_name = os.path.join(directory, out_name) | 595 | full_name = os.path.join(directory, out_name) |
711 | 595 | check_directory_exists(os.path.dirname(full_name)) | 596 | check_directory_exists(Path(os.path.dirname(full_name))) |
712 | 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': |
713 | 597 | file_xml = str(theme_zip.read(name), 'utf-8') | 598 | file_xml = str(theme_zip.read(name), 'utf-8') |
714 | 598 | out_file = open(full_name, 'w', encoding='utf-8') | 599 | out_file = open(full_name, 'w', encoding='utf-8') |
715 | @@ -670,10 +671,10 @@ | |||
716 | 670 | name = theme.theme_name | 671 | name = theme.theme_name |
717 | 671 | theme_pretty = theme.export_theme() | 672 | theme_pretty = theme.export_theme() |
718 | 672 | theme_dir = os.path.join(self.path, name) | 673 | theme_dir = os.path.join(self.path, name) |
720 | 673 | check_directory_exists(theme_dir) | 674 | check_directory_exists(Path(theme_dir)) |
721 | 674 | theme_file = os.path.join(theme_dir, name + '.json') | 675 | theme_file = os.path.join(theme_dir, name + '.json') |
722 | 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: |
724 | 676 | delete_file(self.old_background_image) | 677 | delete_file(Path(self.old_background_image)) |
725 | 677 | out_file = None | 678 | out_file = None |
726 | 678 | try: | 679 | try: |
727 | 679 | out_file = open(theme_file, 'w', encoding='utf-8') | 680 | out_file = open(theme_file, 'w', encoding='utf-8') |
728 | 680 | 681 | ||
729 | === modified file 'openlp/plugins/bibles/lib/importers/csvbible.py' | |||
730 | --- openlp/plugins/bibles/lib/importers/csvbible.py 2016-12-31 11:01:36 +0000 | |||
731 | +++ openlp/plugins/bibles/lib/importers/csvbible.py 2017-08-23 20:14:53 +0000 | |||
732 | @@ -51,6 +51,7 @@ | |||
733 | 51 | """ | 51 | """ |
734 | 52 | import csv | 52 | import csv |
735 | 53 | from collections import namedtuple | 53 | from collections import namedtuple |
736 | 54 | from pathlib import Path | ||
737 | 54 | 55 | ||
738 | 55 | from openlp.core.common import get_file_encoding, translate | 56 | from openlp.core.common import get_file_encoding, translate |
739 | 56 | from openlp.core.lib.exceptions import ValidationError | 57 | from openlp.core.lib.exceptions import ValidationError |
740 | @@ -100,7 +101,7 @@ | |||
741 | 100 | :return: An iterable yielding namedtuples of type results_tuple | 101 | :return: An iterable yielding namedtuples of type results_tuple |
742 | 101 | """ | 102 | """ |
743 | 102 | try: | 103 | try: |
745 | 103 | encoding = get_file_encoding(filename)['encoding'] | 104 | encoding = get_file_encoding(Path(filename))['encoding'] |
746 | 104 | with open(filename, 'r', encoding=encoding, newline='') as csv_file: | 105 | with open(filename, 'r', encoding=encoding, newline='') as csv_file: |
747 | 105 | csv_reader = csv.reader(csv_file, delimiter=',', quotechar='"') | 106 | csv_reader = csv.reader(csv_file, delimiter=',', quotechar='"') |
748 | 106 | return [results_tuple(*line) for line in csv_reader] | 107 | return [results_tuple(*line) for line in csv_reader] |
749 | 107 | 108 | ||
750 | === modified file 'openlp/plugins/bibles/lib/manager.py' | |||
751 | --- openlp/plugins/bibles/lib/manager.py 2017-08-01 20:59:41 +0000 | |||
752 | +++ openlp/plugins/bibles/lib/manager.py 2017-08-23 20:14:53 +0000 | |||
753 | @@ -22,6 +22,7 @@ | |||
754 | 22 | 22 | ||
755 | 23 | import logging | 23 | import logging |
756 | 24 | import os | 24 | import os |
757 | 25 | from pathlib import Path | ||
758 | 25 | 26 | ||
759 | 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 |
760 | 27 | from openlp.plugins.bibles.lib import LanguageSelection, parse_reference | 28 | from openlp.plugins.bibles.lib import LanguageSelection, parse_reference |
761 | @@ -137,7 +138,7 @@ | |||
762 | 137 | # Remove corrupted files. | 138 | # Remove corrupted files. |
763 | 138 | if name is None: | 139 | if name is None: |
764 | 139 | bible.session.close_all() | 140 | bible.session.close_all() |
766 | 140 | delete_file(os.path.join(self.path, filename)) | 141 | delete_file(Path(self.path, filename)) |
767 | 141 | continue | 142 | continue |
768 | 142 | log.debug('Bible Name: "{name}"'.format(name=name)) | 143 | log.debug('Bible Name: "{name}"'.format(name=name)) |
769 | 143 | self.db_cache[name] = bible | 144 | self.db_cache[name] = bible |
770 | @@ -185,7 +186,7 @@ | |||
771 | 185 | bible = self.db_cache[name] | 186 | bible = self.db_cache[name] |
772 | 186 | bible.session.close_all() | 187 | bible.session.close_all() |
773 | 187 | bible.session = None | 188 | bible.session = None |
775 | 188 | return delete_file(os.path.join(bible.path, bible.file)) | 189 | return delete_file(Path(bible.path, bible.file)) |
776 | 189 | 190 | ||
777 | 190 | def get_bibles(self): | 191 | def get_bibles(self): |
778 | 191 | """ | 192 | """ |
779 | 192 | 193 | ||
780 | === modified file 'openlp/plugins/images/lib/mediaitem.py' | |||
781 | --- openlp/plugins/images/lib/mediaitem.py 2017-08-03 17:54:40 +0000 | |||
782 | +++ openlp/plugins/images/lib/mediaitem.py 2017-08-23 20:14:53 +0000 | |||
783 | @@ -22,6 +22,7 @@ | |||
784 | 22 | 22 | ||
785 | 23 | import logging | 23 | import logging |
786 | 24 | import os | 24 | import os |
787 | 25 | from pathlib import Path | ||
788 | 25 | 26 | ||
789 | 26 | from PyQt5 import QtCore, QtGui, QtWidgets | 27 | from PyQt5 import QtCore, QtGui, QtWidgets |
790 | 27 | 28 | ||
791 | @@ -99,7 +100,7 @@ | |||
792 | 99 | self.list_view.setIndentation(self.list_view.default_indentation) | 100 | self.list_view.setIndentation(self.list_view.default_indentation) |
793 | 100 | self.list_view.allow_internal_dnd = True | 101 | self.list_view.allow_internal_dnd = True |
794 | 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') |
796 | 102 | check_directory_exists(self.service_path) | 103 | check_directory_exists(Path(self.service_path)) |
797 | 103 | # Load images from the database | 104 | # Load images from the database |
798 | 104 | self.load_full_list( | 105 | self.load_full_list( |
799 | 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) |
800 | @@ -210,8 +211,8 @@ | |||
801 | 210 | """ | 211 | """ |
802 | 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) |
803 | 212 | for image in images: | 213 | for image in images: |
806 | 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])) |
807 | 214 | delete_file(self.generate_thumbnail_path(image)) | 215 | delete_file(Path(self.generate_thumbnail_path(image))) |
808 | 215 | self.manager.delete_object(ImageFilenames, image.id) | 216 | self.manager.delete_object(ImageFilenames, image.id) |
809 | 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) |
810 | 217 | for group in image_groups: | 218 | for group in image_groups: |
811 | @@ -233,8 +234,8 @@ | |||
812 | 233 | if row_item: | 234 | if row_item: |
813 | 234 | item_data = row_item.data(0, QtCore.Qt.UserRole) | 235 | item_data = row_item.data(0, QtCore.Qt.UserRole) |
814 | 235 | if isinstance(item_data, ImageFilenames): | 236 | if isinstance(item_data, ImageFilenames): |
817 | 236 | delete_file(os.path.join(self.service_path, row_item.text(0))) | 237 | delete_file(Path(self.service_path, row_item.text(0))) |
818 | 237 | delete_file(self.generate_thumbnail_path(item_data)) | 238 | delete_file(Path(self.generate_thumbnail_path(item_data))) |
819 | 238 | if item_data.group_id == 0: | 239 | if item_data.group_id == 0: |
820 | 239 | self.list_view.takeTopLevelItem(self.list_view.indexOfTopLevelItem(row_item)) | 240 | self.list_view.takeTopLevelItem(self.list_view.indexOfTopLevelItem(row_item)) |
821 | 240 | else: | 241 | else: |
822 | 241 | 242 | ||
823 | === modified file 'openlp/plugins/media/lib/mediaitem.py' | |||
824 | --- openlp/plugins/media/lib/mediaitem.py 2017-08-03 17:54:40 +0000 | |||
825 | +++ openlp/plugins/media/lib/mediaitem.py 2017-08-23 20:14:53 +0000 | |||
826 | @@ -22,6 +22,7 @@ | |||
827 | 22 | 22 | ||
828 | 23 | import logging | 23 | import logging |
829 | 24 | import os | 24 | import os |
830 | 25 | from pathlib import Path | ||
831 | 25 | 26 | ||
832 | 26 | from PyQt5 import QtCore, QtWidgets | 27 | from PyQt5 import QtCore, QtWidgets |
833 | 27 | 28 | ||
834 | @@ -301,7 +302,7 @@ | |||
835 | 301 | """ | 302 | """ |
836 | 302 | self.list_view.clear() | 303 | self.list_view.clear() |
837 | 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') |
839 | 304 | check_directory_exists(self.service_path) | 305 | check_directory_exists(Path(self.service_path)) |
840 | 305 | self.load_list(Settings().value(self.settings_section + '/media files')) | 306 | self.load_list(Settings().value(self.settings_section + '/media files')) |
841 | 306 | self.rebuild_players() | 307 | self.rebuild_players() |
842 | 307 | 308 | ||
843 | 308 | 309 | ||
844 | === modified file 'openlp/plugins/media/mediaplugin.py' | |||
845 | --- openlp/plugins/media/mediaplugin.py 2017-08-03 17:54:40 +0000 | |||
846 | +++ openlp/plugins/media/mediaplugin.py 2017-08-23 20:14:53 +0000 | |||
847 | @@ -26,6 +26,7 @@ | |||
848 | 26 | import logging | 26 | import logging |
849 | 27 | import os | 27 | import os |
850 | 28 | import re | 28 | import re |
851 | 29 | from pathlib import Path | ||
852 | 29 | 30 | ||
853 | 30 | from PyQt5 import QtCore | 31 | from PyQt5 import QtCore |
854 | 31 | 32 | ||
855 | @@ -165,8 +166,7 @@ | |||
856 | 165 | :param program_path:The full path to the binary to check. | 166 | :param program_path:The full path to the binary to check. |
857 | 166 | :return: If exists or not | 167 | :return: If exists or not |
858 | 167 | """ | 168 | """ |
861 | 168 | program_type = None | 169 | runlog = check_binary_exists(Path(program_path)) |
860 | 169 | runlog = check_binary_exists(program_path) | ||
862 | 170 | # Analyse the output to see it the program is mediainfo | 170 | # Analyse the output to see it the program is mediainfo |
863 | 171 | for line in runlog.splitlines(): | 171 | for line in runlog.splitlines(): |
864 | 172 | decoded_line = line.decode() | 172 | decoded_line = line.decode() |
865 | 173 | 173 | ||
866 | === modified file 'openlp/plugins/presentations/lib/impresscontroller.py' | |||
867 | --- openlp/plugins/presentations/lib/impresscontroller.py 2017-05-14 10:11:10 +0000 | |||
868 | +++ openlp/plugins/presentations/lib/impresscontroller.py 2017-08-23 20:14:53 +0000 | |||
869 | @@ -34,6 +34,7 @@ | |||
870 | 34 | import logging | 34 | import logging |
871 | 35 | import os | 35 | import os |
872 | 36 | import time | 36 | import time |
873 | 37 | from pathlib import Path | ||
874 | 37 | 38 | ||
875 | 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 |
876 | 39 | 40 | ||
877 | @@ -275,7 +276,7 @@ | |||
878 | 275 | try: | 276 | try: |
879 | 276 | doc.storeToURL(url_path, properties) | 277 | doc.storeToURL(url_path, properties) |
880 | 277 | self.convert_thumbnail(path, index + 1) | 278 | self.convert_thumbnail(path, index + 1) |
882 | 278 | delete_file(path) | 279 | delete_file(Path(path)) |
883 | 279 | except ErrorCodeIOException as exception: | 280 | except ErrorCodeIOException as exception: |
884 | 280 | log.exception('ERROR! ErrorCodeIOException {error:d}'.format(error=exception.ErrCode)) | 281 | log.exception('ERROR! ErrorCodeIOException {error:d}'.format(error=exception.ErrCode)) |
885 | 281 | except: | 282 | except: |
886 | 282 | 283 | ||
887 | === modified file 'openlp/plugins/presentations/lib/pdfcontroller.py' | |||
888 | --- openlp/plugins/presentations/lib/pdfcontroller.py 2017-08-01 20:59:41 +0000 | |||
889 | +++ openlp/plugins/presentations/lib/pdfcontroller.py 2017-08-23 20:14:53 +0000 | |||
890 | @@ -23,6 +23,7 @@ | |||
891 | 23 | import os | 23 | import os |
892 | 24 | import logging | 24 | import logging |
893 | 25 | import re | 25 | import re |
894 | 26 | from pathlib import Path | ||
895 | 26 | from shutil import which | 27 | from shutil import which |
896 | 27 | from subprocess import check_output, CalledProcessError | 28 | from subprocess import check_output, CalledProcessError |
897 | 28 | 29 | ||
898 | @@ -69,7 +70,7 @@ | |||
899 | 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. |
900 | 70 | """ | 71 | """ |
901 | 71 | program_type = None | 72 | program_type = None |
903 | 72 | runlog = check_binary_exists(program_path) | 73 | runlog = check_binary_exists(Path(program_path)) |
904 | 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 |
905 | 74 | for line in runlog.splitlines(): | 75 | for line in runlog.splitlines(): |
906 | 75 | decoded_line = line.decode() | 76 | decoded_line = line.decode() |
907 | 76 | 77 | ||
908 | === modified file 'openlp/plugins/presentations/lib/presentationcontroller.py' | |||
909 | --- openlp/plugins/presentations/lib/presentationcontroller.py 2017-08-01 20:59:41 +0000 | |||
910 | +++ openlp/plugins/presentations/lib/presentationcontroller.py 2017-08-23 20:14:53 +0000 | |||
911 | @@ -23,6 +23,7 @@ | |||
912 | 23 | import logging | 23 | import logging |
913 | 24 | import os | 24 | import os |
914 | 25 | import shutil | 25 | import shutil |
915 | 26 | from pathlib import Path | ||
916 | 26 | 27 | ||
917 | 27 | from PyQt5 import QtCore | 28 | from PyQt5 import QtCore |
918 | 28 | 29 | ||
919 | @@ -98,7 +99,7 @@ | |||
920 | 98 | """ | 99 | """ |
921 | 99 | self.slide_number = 0 | 100 | self.slide_number = 0 |
922 | 100 | self.file_path = name | 101 | self.file_path = name |
924 | 101 | check_directory_exists(self.get_thumbnail_folder()) | 102 | check_directory_exists(Path(self.get_thumbnail_folder())) |
925 | 102 | 103 | ||
926 | 103 | def load_presentation(self): | 104 | def load_presentation(self): |
927 | 104 | """ | 105 | """ |
928 | @@ -419,8 +420,8 @@ | |||
929 | 419 | self.thumbnail_folder = os.path.join( | 420 | self.thumbnail_folder = os.path.join( |
930 | 420 | str(AppLocation.get_section_data_path(self.settings_section)), 'thumbnails') | 421 | str(AppLocation.get_section_data_path(self.settings_section)), 'thumbnails') |
931 | 421 | self.thumbnail_prefix = 'slide' | 422 | self.thumbnail_prefix = 'slide' |
934 | 422 | check_directory_exists(self.thumbnail_folder) | 423 | check_directory_exists(Path(self.thumbnail_folder)) |
935 | 423 | check_directory_exists(self.temp_folder) | 424 | check_directory_exists(Path(self.temp_folder)) |
936 | 424 | 425 | ||
937 | 425 | def enabled(self): | 426 | def enabled(self): |
938 | 426 | """ | 427 | """ |
939 | 427 | 428 | ||
940 | === modified file 'openlp/plugins/presentations/presentationplugin.py' | |||
941 | --- openlp/plugins/presentations/presentationplugin.py 2017-06-09 15:56:40 +0000 | |||
942 | +++ openlp/plugins/presentations/presentationplugin.py 2017-08-23 20:14:53 +0000 | |||
943 | @@ -125,7 +125,7 @@ | |||
944 | 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. |
945 | 126 | """ | 126 | """ |
946 | 127 | log.debug('check_pre_conditions') | 127 | log.debug('check_pre_conditions') |
948 | 128 | controller_dir = os.path.join('openlp', 'plugins', 'presentations', 'lib') | 128 | controller_dir = os.path.join('plugins', 'presentations', 'lib') |
949 | 129 | glob_pattern = os.path.join(controller_dir, '*controller.py') | 129 | glob_pattern = os.path.join(controller_dir, '*controller.py') |
950 | 130 | extension_loader(glob_pattern, ['presentationcontroller.py']) | 130 | extension_loader(glob_pattern, ['presentationcontroller.py']) |
951 | 131 | controller_classes = PresentationController.__subclasses__() | 131 | controller_classes = PresentationController.__subclasses__() |
952 | 132 | 132 | ||
953 | === modified file 'openlp/plugins/songs/forms/editsongform.py' | |||
954 | --- openlp/plugins/songs/forms/editsongform.py 2017-08-11 20:47:52 +0000 | |||
955 | +++ openlp/plugins/songs/forms/editsongform.py 2017-08-23 20:14:53 +0000 | |||
956 | @@ -1071,7 +1071,7 @@ | |||
957 | 1071 | log.debug(audio_files) | 1071 | log.debug(audio_files) |
958 | 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', |
959 | 1073 | str(self.song.id)) | 1073 | str(self.song.id)) |
961 | 1074 | check_directory_exists(save_path) | 1074 | check_directory_exists(Path(save_path)) |
962 | 1075 | self.song.media_files = [] | 1075 | self.song.media_files = [] |
963 | 1076 | files = [] | 1076 | files = [] |
964 | 1077 | for row in range(self.audio_list_widget.count()): | 1077 | for row in range(self.audio_list_widget.count()): |
965 | 1078 | 1078 | ||
966 | === modified file 'openlp/plugins/songs/lib/importers/songbeamer.py' | |||
967 | --- openlp/plugins/songs/lib/importers/songbeamer.py 2017-05-11 19:53:47 +0000 | |||
968 | +++ openlp/plugins/songs/lib/importers/songbeamer.py 2017-08-23 20:14:53 +0000 | |||
969 | @@ -27,6 +27,7 @@ | |||
970 | 27 | import re | 27 | import re |
971 | 28 | import base64 | 28 | import base64 |
972 | 29 | import math | 29 | import math |
973 | 30 | from pathlib import Path | ||
974 | 30 | 31 | ||
975 | 31 | from openlp.plugins.songs.lib import VerseType | 32 | from openlp.plugins.songs.lib import VerseType |
976 | 32 | from openlp.plugins.songs.lib.importers.songimport import SongImport | 33 | from openlp.plugins.songs.lib.importers.songimport import SongImport |
977 | @@ -122,7 +123,7 @@ | |||
978 | 122 | file_name = os.path.split(import_file)[1] | 123 | file_name = os.path.split(import_file)[1] |
979 | 123 | if os.path.isfile(import_file): | 124 | if os.path.isfile(import_file): |
980 | 124 | # Detect the encoding | 125 | # Detect the encoding |
982 | 125 | self.input_file_encoding = get_file_encoding(import_file)['encoding'] | 126 | self.input_file_encoding = get_file_encoding(Path(import_file))['encoding'] |
983 | 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. |
984 | 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: |
985 | 128 | # https://forum.songbeamer.com/viewtopic.php?p=419&sid=ca4814924e37c11e4438b7272a98b6f2 | 129 | # https://forum.songbeamer.com/viewtopic.php?p=419&sid=ca4814924e37c11e4438b7272a98b6f2 |
986 | 129 | 130 | ||
987 | === modified file 'openlp/plugins/songs/lib/importers/songimport.py' | |||
988 | --- openlp/plugins/songs/lib/importers/songimport.py 2017-08-01 20:59:41 +0000 | |||
989 | +++ openlp/plugins/songs/lib/importers/songimport.py 2017-08-23 20:14:53 +0000 | |||
990 | @@ -24,6 +24,7 @@ | |||
991 | 24 | import re | 24 | import re |
992 | 25 | import shutil | 25 | import shutil |
993 | 26 | import os | 26 | import os |
994 | 27 | from pathlib import Path | ||
995 | 27 | 28 | ||
996 | 28 | from PyQt5 import QtCore | 29 | from PyQt5 import QtCore |
997 | 29 | 30 | ||
998 | @@ -423,7 +424,7 @@ | |||
999 | 423 | if not hasattr(self, 'save_path'): | 424 | if not hasattr(self, 'save_path'): |
1000 | 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)), |
1001 | 425 | 'audio', str(song_id)) | 426 | 'audio', str(song_id)) |
1003 | 426 | check_directory_exists(self.save_path) | 427 | check_directory_exists(Path(self.save_path)) |
1004 | 427 | if not filename.startswith(self.save_path): | 428 | if not filename.startswith(self.save_path): |
1005 | 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]) |
1006 | 429 | shutil.copyfile(old_file, filename) | 430 | shutil.copyfile(old_file, filename) |
1007 | 430 | 431 | ||
1008 | === modified file 'openlp/plugins/songs/lib/mediaitem.py' | |||
1009 | --- openlp/plugins/songs/lib/mediaitem.py 2017-08-03 17:54:40 +0000 | |||
1010 | +++ openlp/plugins/songs/lib/mediaitem.py 2017-08-23 20:14:53 +0000 | |||
1011 | @@ -23,6 +23,7 @@ | |||
1012 | 23 | import logging | 23 | import logging |
1013 | 24 | import os | 24 | import os |
1014 | 25 | import shutil | 25 | import shutil |
1015 | 26 | from pathlib import Path | ||
1016 | 26 | 27 | ||
1017 | 27 | from PyQt5 import QtCore, QtWidgets | 28 | from PyQt5 import QtCore, QtWidgets |
1018 | 28 | from sqlalchemy.sql import and_, or_ | 29 | from sqlalchemy.sql import and_, or_ |
1019 | @@ -89,7 +90,7 @@ | |||
1020 | 89 | for i, bga in enumerate(item.background_audio): | 90 | for i, bga in enumerate(item.background_audio): |
1021 | 90 | dest_file = os.path.join( | 91 | dest_file = os.path.join( |
1022 | 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]) |
1024 | 92 | check_directory_exists(os.path.split(dest_file)[0]) | 93 | check_directory_exists(Path(os.path.split(dest_file)[0])) |
1025 | 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) |
1026 | 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)) |
1027 | 95 | self.plugin.manager.save_object(song, True) | 96 | self.plugin.manager.save_object(song, True) |
1028 | @@ -535,7 +536,7 @@ | |||
1029 | 535 | if len(old_song.media_files) > 0: | 536 | if len(old_song.media_files) > 0: |
1030 | 536 | save_path = os.path.join( | 537 | save_path = os.path.join( |
1031 | 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)) |
1033 | 538 | check_directory_exists(save_path) | 539 | check_directory_exists(Path(save_path)) |
1034 | 539 | for media_file in old_song.media_files: | 540 | for media_file in old_song.media_files: |
1035 | 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)) |
1036 | 541 | shutil.copyfile(media_file.file_name, new_media_file_name) | 542 | shutil.copyfile(media_file.file_name, new_media_file_name) |
1037 | 542 | 543 | ||
1038 | === modified file 'openlp/plugins/songs/lib/openlyricsexport.py' | |||
1039 | --- openlp/plugins/songs/lib/openlyricsexport.py 2016-12-31 11:01:36 +0000 | |||
1040 | +++ openlp/plugins/songs/lib/openlyricsexport.py 2017-08-23 20:14:53 +0000 | |||
1041 | @@ -25,6 +25,7 @@ | |||
1042 | 25 | """ | 25 | """ |
1043 | 26 | import logging | 26 | import logging |
1044 | 27 | import os | 27 | import os |
1045 | 28 | from pathlib import Path | ||
1046 | 28 | 29 | ||
1047 | 29 | from lxml import etree | 30 | from lxml import etree |
1048 | 30 | 31 | ||
1049 | @@ -47,7 +48,7 @@ | |||
1050 | 47 | self.manager = parent.plugin.manager | 48 | self.manager = parent.plugin.manager |
1051 | 48 | self.songs = songs | 49 | self.songs = songs |
1052 | 49 | self.save_path = save_path | 50 | self.save_path = save_path |
1054 | 50 | check_directory_exists(self.save_path) | 51 | check_directory_exists(Path(self.save_path)) |
1055 | 51 | 52 | ||
1056 | 52 | def do_export(self): | 53 | def do_export(self): |
1057 | 53 | """ | 54 | """ |
1058 | 54 | 55 | ||
1059 | === modified file 'openlp/plugins/songusage/forms/songusagedetailform.py' | |||
1060 | --- openlp/plugins/songusage/forms/songusagedetailform.py 2017-08-04 17:40:57 +0000 | |||
1061 | +++ openlp/plugins/songusage/forms/songusagedetailform.py 2017-08-23 20:14:53 +0000 | |||
1062 | @@ -22,6 +22,7 @@ | |||
1063 | 22 | 22 | ||
1064 | 23 | import logging | 23 | import logging |
1065 | 24 | import os | 24 | import os |
1066 | 25 | from pathlib import Path | ||
1067 | 25 | 26 | ||
1068 | 26 | from PyQt5 import QtCore, QtWidgets | 27 | from PyQt5 import QtCore, QtWidgets |
1069 | 27 | from sqlalchemy.sql import and_ | 28 | from sqlalchemy.sql import and_ |
1070 | @@ -78,7 +79,7 @@ | |||
1071 | 78 | ' song usage report. \nPlease select an existing path on your computer.') | 79 | ' song usage report. \nPlease select an existing path on your computer.') |
1072 | 79 | ) | 80 | ) |
1073 | 80 | return | 81 | return |
1075 | 81 | check_directory_exists(path) | 82 | check_directory_exists(Path(path)) |
1076 | 82 | file_name = translate('SongUsagePlugin.SongUsageDetailForm', | 83 | file_name = translate('SongUsagePlugin.SongUsageDetailForm', |
1077 | 83 | 'usage_detail_{old}_{new}.txt' | 84 | 'usage_detail_{old}_{new}.txt' |
1078 | 84 | ).format(old=self.from_date_calendar.selectedDate().toString('ddMMyyyy'), | 85 | ).format(old=self.from_date_calendar.selectedDate().toString('ddMMyyyy'), |
1079 | 85 | 86 | ||
1080 | === modified file 'tests/functional/openlp_core_common/test_applocation.py' | |||
1081 | --- tests/functional/openlp_core_common/test_applocation.py 2017-08-01 20:59:41 +0000 | |||
1082 | +++ tests/functional/openlp_core_common/test_applocation.py 2017-08-23 20:14:53 +0000 | |||
1083 | @@ -43,14 +43,12 @@ | |||
1084 | 43 | """ | 43 | """ |
1085 | 44 | with patch('openlp.core.common.applocation.Settings') as mocked_class, \ | 44 | with patch('openlp.core.common.applocation.Settings') as mocked_class, \ |
1086 | 45 | patch('openlp.core.common.AppLocation.get_directory') as mocked_get_directory, \ | 45 | patch('openlp.core.common.AppLocation.get_directory') as mocked_get_directory, \ |
1089 | 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: |
1088 | 47 | patch('openlp.core.common.applocation.os') as mocked_os: | ||
1090 | 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() |
1091 | 49 | mocked_settings = mocked_class.return_value | 48 | mocked_settings = mocked_class.return_value |
1092 | 50 | mocked_settings.contains.return_value = False | 49 | mocked_settings.contains.return_value = False |
1094 | 51 | mocked_get_directory.return_value = os.path.join('test', 'dir') | 50 | mocked_get_directory.return_value = Path('test', 'dir') |
1095 | 52 | mocked_check_directory_exists.return_value = True | 51 | mocked_check_directory_exists.return_value = True |
1096 | 53 | mocked_os.path.normpath.return_value = os.path.join('test', 'dir') | ||
1097 | 54 | 52 | ||
1098 | 55 | # WHEN: we call AppLocation.get_data_path() | 53 | # WHEN: we call AppLocation.get_data_path() |
1099 | 56 | data_path = AppLocation.get_data_path() | 54 | data_path = AppLocation.get_data_path() |
1100 | @@ -58,8 +56,8 @@ | |||
1101 | 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 |
1102 | 59 | mocked_settings.contains.assert_called_with('advanced/data path') | 57 | mocked_settings.contains.assert_called_with('advanced/data path') |
1103 | 60 | mocked_get_directory.assert_called_with(AppLocation.DataDir) | 58 | mocked_get_directory.assert_called_with(AppLocation.DataDir) |
1106 | 61 | mocked_check_directory_exists.assert_called_with(os.path.join('test', 'dir')) | 59 | mocked_check_directory_exists.assert_called_with(Path('test', 'dir')) |
1107 | 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"') |
1108 | 63 | 61 | ||
1109 | 64 | def test_get_data_path_with_custom_location(self): | 62 | def test_get_data_path_with_custom_location(self): |
1110 | 65 | """ | 63 | """ |
1111 | @@ -125,7 +123,7 @@ | |||
1112 | 125 | data_path = AppLocation.get_section_data_path('section') | 123 | data_path = AppLocation.get_section_data_path('section') |
1113 | 126 | 124 | ||
1114 | 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 |
1116 | 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')) |
1117 | 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"') |
1118 | 130 | 128 | ||
1119 | 131 | def test_get_directory_for_app_dir(self): | 129 | def test_get_directory_for_app_dir(self): |
1120 | 132 | 130 | ||
1121 | === modified file 'tests/functional/openlp_core_common/test_common.py' | |||
1122 | --- tests/functional/openlp_core_common/test_common.py 2017-08-01 20:59:41 +0000 | |||
1123 | +++ tests/functional/openlp_core_common/test_common.py 2017-08-23 20:14:53 +0000 | |||
1124 | @@ -35,44 +35,70 @@ | |||
1125 | 35 | """ | 35 | """ |
1126 | 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. |
1127 | 37 | """ | 37 | """ |
1136 | 38 | def test_check_directory_exists(self): | 38 | def test_check_directory_exists_dir_exists(self): |
1137 | 39 | """ | 39 | """ |
1138 | 40 | Test the check_directory_exists() function | 40 | Test the check_directory_exists() function when the path already exists |
1139 | 41 | """ | 41 | """ |
1140 | 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 |
1141 | 43 | patch('openlp.core.lib.os.makedirs') as mocked_makedirs: | 43 | with patch.object(Path, 'exists') as mocked_exists, \ |
1142 | 44 | # GIVEN: A directory to check and a mocked out os.makedirs and os.path.exists | 44 | patch.object(Path, 'mkdir') as mocked_mkdir, \ |
1143 | 45 | directory_to_check = 'existing/directory' | 45 | patch('openlp.core.common.log'): |
1144 | 46 | 46 | ||
1146 | 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 |
1147 | 48 | mocked_exists.return_value = True | 48 | mocked_exists.return_value = True |
1155 | 49 | check_directory_exists(directory_to_check) | 49 | check_directory_exists(Path('existing', 'directory')) |
1156 | 50 | 50 | ||
1157 | 51 | # THEN: Only os.path.exists should have been called | 51 | # THEN: The function should not attempt to create the directory |
1158 | 52 | mocked_exists.assert_called_with(directory_to_check) | 52 | mocked_exists.assert_called_with() |
1159 | 53 | self.assertIsNot(mocked_makedirs.called, 'os.makedirs should not have been called') | 53 | self.assertFalse(mocked_mkdir.called) |
1160 | 54 | 54 | ||
1161 | 55 | # WHEN: os.path.exists returns False and we check the directory exists | 55 | def test_check_directory_exists_dir_doesnt_exists(self): |
1162 | 56 | """ | ||
1163 | 57 | Test the check_directory_exists() function when the path does not already exist | ||
1164 | 58 | """ | ||
1165 | 59 | # GIVEN: A `Path` to check with patched out mkdir and exists methods | ||
1166 | 60 | with patch.object(Path, 'exists') as mocked_exists, \ | ||
1167 | 61 | patch.object(Path, 'mkdir') as mocked_mkdir, \ | ||
1168 | 62 | patch('openlp.core.common.log'): | ||
1169 | 63 | |||
1170 | 64 | # WHEN: `check_directory_exists` is called and the path does not exist | ||
1171 | 56 | mocked_exists.return_value = False | 65 | mocked_exists.return_value = False |
1179 | 57 | check_directory_exists(directory_to_check) | 66 | check_directory_exists(Path('existing', 'directory')) |
1180 | 58 | 67 | ||
1181 | 59 | # THEN: Both the mocked functions should have been called | 68 | # THEN: The directory should have been created |
1182 | 60 | mocked_exists.assert_called_with(directory_to_check) | 69 | mocked_exists.assert_called_with() |
1183 | 61 | mocked_makedirs.assert_called_with(directory_to_check) | 70 | mocked_mkdir.assert_called_with(parents=True) |
1184 | 62 | 71 | ||
1185 | 63 | # WHEN: os.path.exists raises an IOError | 72 | def test_check_directory_exists_dir_io_error(self): |
1186 | 73 | """ | ||
1187 | 74 | Test the check_directory_exists() when an IOError is raised | ||
1188 | 75 | """ | ||
1189 | 76 | # GIVEN: A `Path` to check with patched out mkdir and exists methods | ||
1190 | 77 | with patch.object(Path, 'exists') as mocked_exists, \ | ||
1191 | 78 | patch.object(Path, 'mkdir'), \ | ||
1192 | 79 | patch('openlp.core.common.log') as mocked_logger: | ||
1193 | 80 | |||
1194 | 81 | # WHEN: An IOError is raised when checking the if the path exists. | ||
1195 | 64 | mocked_exists.side_effect = IOError() | 82 | mocked_exists.side_effect = IOError() |
1200 | 65 | check_directory_exists(directory_to_check) | 83 | check_directory_exists(Path('existing', 'directory')) |
1201 | 66 | 84 | ||
1202 | 67 | # THEN: We shouldn't get an exception though the mocked exists has been called | 85 | # THEN: The Error should have been logged |
1203 | 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') |
1204 | 87 | |||
1205 | 88 | def test_check_directory_exists_dir_value_error(self): | ||
1206 | 89 | """ | ||
1207 | 90 | Test the check_directory_exists() when an error other than IOError is raised | ||
1208 | 91 | """ | ||
1209 | 92 | # GIVEN: A `Path` to check with patched out mkdir and exists methods | ||
1210 | 93 | with patch.object(Path, 'exists') as mocked_exists, \ | ||
1211 | 94 | patch.object(Path, 'mkdir'), \ | ||
1212 | 95 | patch('openlp.core.common.log'): | ||
1213 | 69 | 96 | ||
1214 | 70 | # WHEN: Some other exception is raised | 97 | # WHEN: Some other exception is raised |
1215 | 71 | mocked_exists.side_effect = ValueError() | 98 | mocked_exists.side_effect = ValueError() |
1216 | 72 | 99 | ||
1220 | 73 | # THEN: check_directory_exists raises an exception | 100 | # THEN: `check_directory_exists` raises an exception |
1221 | 74 | mocked_exists.assert_called_with(directory_to_check) | 101 | self.assertRaises(ValueError, check_directory_exists, Path('existing', 'directory')) |
1219 | 75 | self.assertRaises(ValueError, check_directory_exists, directory_to_check) | ||
1222 | 76 | 102 | ||
1223 | 77 | def test_extension_loader_no_files_found(self): | 103 | def test_extension_loader_no_files_found(self): |
1224 | 78 | """ | 104 | """ |
1225 | @@ -80,7 +106,7 @@ | |||
1226 | 80 | """ | 106 | """ |
1227 | 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 |
1228 | 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')), \ |
1230 | 83 | patch.object(common.Path, 'glob', return_value=[]), \ | 109 | patch.object(Path, 'glob', return_value=[]), \ |
1231 | 84 | patch('openlp.core.common.importlib.import_module') as mocked_import_module: | 110 | patch('openlp.core.common.importlib.import_module') as mocked_import_module: |
1232 | 85 | 111 | ||
1233 | 86 | # WHEN: Calling `extension_loader` | 112 | # WHEN: Calling `extension_loader` |
1234 | @@ -95,7 +121,7 @@ | |||
1235 | 95 | """ | 121 | """ |
1236 | 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 |
1237 | 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')), \ |
1239 | 98 | patch.object(common.Path, 'glob', return_value=[ | 124 | patch.object(Path, 'glob', return_value=[ |
1240 | 99 | Path('/', 'app', 'dir', 'openlp', 'import_dir', 'file1.py'), | 125 | Path('/', 'app', 'dir', 'openlp', 'import_dir', 'file1.py'), |
1241 | 100 | Path('/', 'app', 'dir', 'openlp', 'import_dir', 'file2.py'), | 126 | Path('/', 'app', 'dir', 'openlp', 'import_dir', 'file2.py'), |
1242 | 101 | Path('/', 'app', 'dir', 'openlp', 'import_dir', 'file3.py'), | 127 | Path('/', 'app', 'dir', 'openlp', 'import_dir', 'file3.py'), |
1243 | @@ -115,7 +141,7 @@ | |||
1244 | 115 | """ | 141 | """ |
1245 | 116 | # GIVEN: A mocked `import_module` which raises an `ImportError` | 142 | # GIVEN: A mocked `import_module` which raises an `ImportError` |
1246 | 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')), \ |
1248 | 118 | patch.object(common.Path, 'glob', return_value=[ | 144 | patch.object(Path, 'glob', return_value=[ |
1249 | 119 | Path('/', 'app', 'dir', 'openlp', 'import_dir', 'file1.py')]), \ | 145 | Path('/', 'app', 'dir', 'openlp', 'import_dir', 'file1.py')]), \ |
1250 | 120 | patch('openlp.core.common.importlib.import_module', side_effect=ImportError()), \ | 146 | patch('openlp.core.common.importlib.import_module', side_effect=ImportError()), \ |
1251 | 121 | patch('openlp.core.common.log') as mocked_logger: | 147 | patch('openlp.core.common.log') as mocked_logger: |
1252 | @@ -132,7 +158,7 @@ | |||
1253 | 132 | """ | 158 | """ |
1254 | 133 | # GIVEN: A mocked `SourceFileLoader` which raises an `OSError` | 159 | # GIVEN: A mocked `SourceFileLoader` which raises an `OSError` |
1255 | 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')), \ |
1257 | 135 | patch.object(common.Path, 'glob', return_value=[ | 161 | patch.object(Path, 'glob', return_value=[ |
1258 | 136 | Path('/', 'app', 'dir', 'openlp', 'import_dir', 'file1.py')]), \ | 162 | Path('/', 'app', 'dir', 'openlp', 'import_dir', 'file1.py')]), \ |
1259 | 137 | patch('openlp.core.common.importlib.import_module', side_effect=OSError()), \ | 163 | patch('openlp.core.common.importlib.import_module', side_effect=OSError()), \ |
1260 | 138 | patch('openlp.core.common.log') as mocked_logger: | 164 | patch('openlp.core.common.log') as mocked_logger: |
1261 | @@ -174,7 +200,7 @@ | |||
1262 | 174 | Test `path_to_module` when supplied with a `Path` object | 200 | Test `path_to_module` when supplied with a `Path` object |
1263 | 175 | """ | 201 | """ |
1264 | 176 | # GIVEN: A `Path` object | 202 | # GIVEN: A `Path` object |
1266 | 177 | path = Path('openlp/core/ui/media/webkitplayer.py') | 203 | path = Path('core', 'ui', 'media', 'webkitplayer.py') |
1267 | 178 | 204 | ||
1268 | 179 | # WHEN: Calling path_to_module with the `Path` object | 205 | # WHEN: Calling path_to_module with the `Path` object |
1269 | 180 | result = path_to_module(path) | 206 | result = path_to_module(path) |
1270 | 181 | 207 | ||
1271 | === modified file 'tests/functional/openlp_core_common/test_init.py' | |||
1272 | --- tests/functional/openlp_core_common/test_init.py 2017-04-24 05:17:55 +0000 | |||
1273 | +++ tests/functional/openlp_core_common/test_init.py 2017-08-23 20:14:53 +0000 | |||
1274 | @@ -24,6 +24,7 @@ | |||
1275 | 24 | """ | 24 | """ |
1276 | 25 | import os | 25 | import os |
1277 | 26 | from io import BytesIO | 26 | from io import BytesIO |
1278 | 27 | from pathlib import Path | ||
1279 | 27 | from unittest import TestCase | 28 | from unittest import TestCase |
1280 | 28 | from unittest.mock import MagicMock, PropertyMock, call, patch | 29 | from unittest.mock import MagicMock, PropertyMock, call, patch |
1281 | 29 | 30 | ||
1282 | @@ -296,10 +297,10 @@ | |||
1283 | 296 | """ | 297 | """ |
1284 | 297 | # GIVEN: A blank path | 298 | # GIVEN: A blank path |
1285 | 298 | # WEHN: Calling delete_file | 299 | # WEHN: Calling delete_file |
1287 | 299 | result = delete_file('') | 300 | result = delete_file(None) |
1288 | 300 | 301 | ||
1289 | 301 | # THEN: delete_file should return False | 302 | # THEN: delete_file should return False |
1291 | 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") |
1292 | 303 | 304 | ||
1293 | 304 | def test_delete_file_path_success(self): | 305 | def test_delete_file_path_success(self): |
1294 | 305 | """ | 306 | """ |
1295 | @@ -309,84 +310,87 @@ | |||
1296 | 309 | with patch('openlp.core.common.os', **{'path.exists.return_value': False}): | 310 | with patch('openlp.core.common.os', **{'path.exists.return_value': False}): |
1297 | 310 | 311 | ||
1298 | 311 | # WHEN: Calling delete_file with a file path | 312 | # WHEN: Calling delete_file with a file path |
1300 | 312 | result = delete_file('path/file.ext') | 313 | result = delete_file(Path('path', 'file.ext')) |
1301 | 313 | 314 | ||
1302 | 314 | # THEN: delete_file should return True | 315 | # THEN: delete_file should return True |
1303 | 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') |
1304 | 316 | 317 | ||
1305 | 317 | def test_delete_file_path_no_file_exists(self): | 318 | def test_delete_file_path_no_file_exists(self): |
1306 | 318 | """ | 319 | """ |
1308 | 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 |
1309 | 320 | """ | 321 | """ |
1317 | 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 |
1318 | 322 | with patch('openlp.core.common.os', **{'path.exists.return_value': False}): | 323 | with patch.object(Path, 'exists', return_value=False), \ |
1319 | 323 | 324 | patch.object(Path, 'unlink') as mocked_unlink: | |
1320 | 324 | # WHEN: Calling delete_file with a file path | 325 | |
1321 | 325 | result = delete_file('path/file.ext') | 326 | # WHEN: Calling `delete_file with` a file path |
1322 | 326 | 327 | result = delete_file(Path('path', 'file.ext')) | |
1323 | 327 | # THEN: delete_file should return True | 328 | |
1324 | 329 | # THEN: The function should not attempt to delete the file and it should return True | ||
1325 | 330 | self.assertFalse(mocked_unlink.called) | ||
1326 | 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') |
1327 | 329 | 332 | ||
1328 | 330 | def test_delete_file_path_exception(self): | 333 | def test_delete_file_path_exception(self): |
1329 | 331 | """ | 334 | """ |
1331 | 332 | Test the delete_file function when os.remove raises an exception | 335 | Test the delete_file function when an exception is raised |
1332 | 333 | """ | 336 | """ |
1334 | 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 |
1335 | 335 | # called. | 338 | # called. |
1337 | 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, \ |
1338 | 337 | patch('openlp.core.common.log') as mocked_log: | 340 | patch('openlp.core.common.log') as mocked_log: |
1348 | 338 | 341 | mocked_exists.side_effect = OSError | |
1349 | 339 | # WHEN: Calling delete_file with a file path | 342 | |
1350 | 340 | result = delete_file('path/file.ext') | 343 | # WHEN: Calling delete_file with a the test Path object |
1351 | 341 | 344 | result = delete_file(Path('path', 'file.ext')) | |
1352 | 342 | # THEN: delete_file should log and exception and return False | 345 | |
1353 | 343 | self.assertEqual(mocked_log.exception.call_count, 1) | 346 | # THEN: The exception should be logged and `delete_file` should return False |
1354 | 344 | self.assertFalse(result, 'delete_file should return False when os.remove raises an OSError') | 347 | self.assertTrue(mocked_log.exception.called) |
1355 | 345 | 348 | self.assertFalse(result, 'delete_file should return False when an OSError is raised') | |
1356 | 346 | def test_get_file_name_encoding_done_test(self): | 349 | |
1357 | 350 | def test_get_file_encoding_done_test(self): | ||
1358 | 347 | """ | 351 | """ |
1359 | 348 | Test get_file_encoding when the detector sets done to True | 352 | Test get_file_encoding when the detector sets done to True |
1360 | 349 | """ | 353 | """ |
1361 | 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 |
1362 | 351 | with patch('openlp.core.common.UniversalDetector') as mocked_universal_detector, \ | 355 | with patch('openlp.core.common.UniversalDetector') as mocked_universal_detector, \ |
1364 | 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: |
1365 | 353 | encoding_result = {'encoding': 'UTF-8', 'confidence': 0.99} | 357 | encoding_result = {'encoding': 'UTF-8', 'confidence': 0.99} |
1366 | 354 | mocked_universal_detector_inst = MagicMock(result=encoding_result) | 358 | mocked_universal_detector_inst = MagicMock(result=encoding_result) |
1367 | 355 | type(mocked_universal_detector_inst).done = PropertyMock(side_effect=[False, True]) | 359 | type(mocked_universal_detector_inst).done = PropertyMock(side_effect=[False, True]) |
1368 | 356 | mocked_universal_detector.return_value = mocked_universal_detector_inst | 360 | mocked_universal_detector.return_value = mocked_universal_detector_inst |
1369 | 357 | 361 | ||
1370 | 358 | # WHEN: Calling get_file_encoding | 362 | # WHEN: Calling get_file_encoding |
1372 | 359 | result = get_file_encoding('file name') | 363 | result = get_file_encoding(Path('file name')) |
1373 | 360 | 364 | ||
1374 | 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 |
1376 | 362 | mocked_open.assert_called_once_with('file name', 'rb') | 366 | mocked_open.assert_called_once_with('rb') |
1377 | 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)]) |
1378 | 364 | mocked_universal_detector_inst.close.assert_called_once_with() | 368 | mocked_universal_detector_inst.close.assert_called_once_with() |
1379 | 365 | self.assertEqual(result, encoding_result) | 369 | self.assertEqual(result, encoding_result) |
1380 | 366 | 370 | ||
1382 | 367 | def test_get_file_name_encoding_eof_test(self): | 371 | def test_get_file_encoding_eof_test(self): |
1383 | 368 | """ | 372 | """ |
1384 | 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 |
1385 | 370 | """ | 374 | """ |
1386 | 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 |
1387 | 372 | # data (enough to run the iterator twice) | 376 | # data (enough to run the iterator twice) |
1388 | 373 | with patch('openlp.core.common.UniversalDetector') as mocked_universal_detector, \ | 377 | with patch('openlp.core.common.UniversalDetector') as mocked_universal_detector, \ |
1390 | 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: |
1391 | 375 | encoding_result = {'encoding': 'UTF-8', 'confidence': 0.99} | 379 | encoding_result = {'encoding': 'UTF-8', 'confidence': 0.99} |
1392 | 376 | mocked_universal_detector_inst = MagicMock(mock=mocked_universal_detector, | 380 | mocked_universal_detector_inst = MagicMock(mock=mocked_universal_detector, |
1393 | 377 | **{'done': False, 'result': encoding_result}) | 381 | **{'done': False, 'result': encoding_result}) |
1394 | 378 | mocked_universal_detector.return_value = mocked_universal_detector_inst | 382 | mocked_universal_detector.return_value = mocked_universal_detector_inst |
1395 | 379 | 383 | ||
1396 | 380 | # WHEN: Calling get_file_encoding | 384 | # WHEN: Calling get_file_encoding |
1398 | 381 | result = get_file_encoding('file name') | 385 | result = get_file_encoding(Path('file name')) |
1399 | 382 | 386 | ||
1400 | 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 |
1402 | 384 | mocked_open.assert_called_once_with('file name', 'rb') | 388 | mocked_open.assert_called_once_with('rb') |
1403 | 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)]) |
1404 | 386 | mocked_universal_detector_inst.close.assert_called_once_with() | 390 | mocked_universal_detector_inst.close.assert_called_once_with() |
1405 | 387 | self.assertEqual(result, encoding_result) | 391 | self.assertEqual(result, encoding_result) |
1406 | 388 | 392 | ||
1408 | 389 | def test_get_file_name_encoding_oserror_test(self): | 393 | def test_get_file_encoding_oserror_test(self): |
1409 | 390 | """ | 394 | """ |
1410 | 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 |
1411 | 392 | """ | 396 | """ |
1412 | @@ -397,7 +401,7 @@ | |||
1413 | 397 | patch('openlp.core.common.log') as mocked_log: | 401 | patch('openlp.core.common.log') as mocked_log: |
1414 | 398 | 402 | ||
1415 | 399 | # WHEN: Calling get_file_encoding | 403 | # WHEN: Calling get_file_encoding |
1417 | 400 | result = get_file_encoding('file name') | 404 | result = get_file_encoding(Path('file name')) |
1418 | 401 | 405 | ||
1419 | 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 |
1420 | 403 | mocked_log.exception.assert_called_once_with('Error detecting file encoding') | 407 | mocked_log.exception.assert_called_once_with('Error detecting file encoding') |
1421 | 404 | 408 | ||
1422 | === modified file 'tests/functional/openlp_core_lib/test_db.py' | |||
1423 | --- tests/functional/openlp_core_lib/test_db.py 2017-06-09 13:45:18 +0000 | |||
1424 | +++ tests/functional/openlp_core_lib/test_db.py 2017-08-23 20:14:53 +0000 | |||
1425 | @@ -24,6 +24,7 @@ | |||
1426 | 24 | """ | 24 | """ |
1427 | 25 | import os | 25 | import os |
1428 | 26 | import shutil | 26 | import shutil |
1429 | 27 | from pathlib import Path | ||
1430 | 27 | 28 | ||
1431 | 28 | from tempfile import mkdtemp | 29 | from tempfile import mkdtemp |
1432 | 29 | from unittest import TestCase | 30 | from unittest import TestCase |
1433 | @@ -129,10 +130,10 @@ | |||
1434 | 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 |
1435 | 130 | with patch('openlp.core.lib.db.AppLocation') as MockedAppLocation, \ | 131 | with patch('openlp.core.lib.db.AppLocation') as MockedAppLocation, \ |
1436 | 131 | patch('openlp.core.lib.db.delete_file') as mocked_delete_file: | 132 | patch('openlp.core.lib.db.delete_file') as mocked_delete_file: |
1438 | 132 | MockedAppLocation.get_section_data_path.return_value = 'test-dir' | 133 | MockedAppLocation.get_section_data_path.return_value = Path('test-dir') |
1439 | 133 | mocked_delete_file.return_value = True | 134 | mocked_delete_file.return_value = True |
1440 | 134 | test_plugin = 'test' | 135 | test_plugin = 'test' |
1442 | 135 | test_location = os.path.join('test-dir', test_plugin) | 136 | test_location = Path('test-dir', test_plugin) |
1443 | 136 | 137 | ||
1444 | 137 | # WHEN: delete_database is run without a database file | 138 | # WHEN: delete_database is run without a database file |
1445 | 138 | result = delete_database(test_plugin) | 139 | result = delete_database(test_plugin) |
1446 | @@ -149,11 +150,11 @@ | |||
1447 | 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 |
1448 | 150 | with patch('openlp.core.lib.db.AppLocation') as MockedAppLocation, \ | 151 | with patch('openlp.core.lib.db.AppLocation') as MockedAppLocation, \ |
1449 | 151 | patch('openlp.core.lib.db.delete_file') as mocked_delete_file: | 152 | patch('openlp.core.lib.db.delete_file') as mocked_delete_file: |
1451 | 152 | MockedAppLocation.get_section_data_path.return_value = 'test-dir' | 153 | MockedAppLocation.get_section_data_path.return_value = Path('test-dir') |
1452 | 153 | mocked_delete_file.return_value = False | 154 | mocked_delete_file.return_value = False |
1453 | 154 | test_plugin = 'test' | 155 | test_plugin = 'test' |
1454 | 155 | test_db_file = 'mydb.sqlite' | 156 | test_db_file = 'mydb.sqlite' |
1456 | 156 | test_location = os.path.join('test-dir', test_db_file) | 157 | test_location = Path('test-dir', test_db_file) |
1457 | 157 | 158 | ||
1458 | 158 | # WHEN: delete_database is run without a database file | 159 | # WHEN: delete_database is run without a database file |
1459 | 159 | result = delete_database(test_plugin, test_db_file) | 160 | result = delete_database(test_plugin, test_db_file) |
1460 | 160 | 161 | ||
1461 | === removed file 'tests/functional/openlp_core_lib/test_file_dialog.py' | |||
1462 | --- tests/functional/openlp_core_lib/test_file_dialog.py 2017-08-07 21:12:42 +0000 | |||
1463 | +++ tests/functional/openlp_core_lib/test_file_dialog.py 1970-01-01 00:00:00 +0000 | |||
1464 | @@ -1,45 +0,0 @@ | |||
1465 | 1 | # -*- coding: utf-8 -*- | ||
1466 | 2 | # vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 | ||
1467 | 3 | |||
1468 | 4 | ############################################################################### | ||
1469 | 5 | # OpenLP - Open Source Lyrics Projection # | ||
1470 | 6 | # --------------------------------------------------------------------------- # | ||
1471 | 7 | # Copyright (c) 2008-2017 OpenLP Developers # | ||
1472 | 8 | # --------------------------------------------------------------------------- # | ||
1473 | 9 | # This program is free software; you can redistribute it and/or modify it # | ||
1474 | 10 | # under the terms of the GNU General Public License as published by the Free # | ||
1475 | 11 | # Software Foundation; version 2 of the License. # | ||
1476 | 12 | # # | ||
1477 | 13 | # This program is distributed in the hope that it will be useful, but WITHOUT # | ||
1478 | 14 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # | ||
1479 | 15 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # | ||
1480 | 16 | # more details. # | ||
1481 | 17 | # # | ||
1482 | 18 | # You should have received a copy of the GNU General Public License along # | ||
1483 | 19 | # with this program; if not, write to the Free Software Foundation, Inc., 59 # | ||
1484 | 20 | # Temple Place, Suite 330, Boston, MA 02111-1307 USA # | ||
1485 | 21 | ############################################################################### | ||
1486 | 22 | """ | ||
1487 | 23 | Package to test the openlp.core.ui.lib.filedialog package. | ||
1488 | 24 | """ | ||
1489 | 25 | from unittest import TestCase | ||
1490 | 26 | from unittest.mock import MagicMock, patch | ||
1491 | 27 | |||
1492 | 28 | |||
1493 | 29 | class TestFileDialog(TestCase): | ||
1494 | 30 | """ | ||
1495 | 31 | Test the functions in the :mod:`filedialog` module. | ||
1496 | 32 | """ | ||
1497 | 33 | def setUp(self): | ||
1498 | 34 | self.os_patcher = patch('openlp.core.ui.lib.filedialog.os') | ||
1499 | 35 | self.qt_gui_patcher = patch('openlp.core.ui.lib.filedialog.QtWidgets') | ||
1500 | 36 | self.ui_strings_patcher = patch('openlp.core.ui.lib.filedialog.UiStrings') | ||
1501 | 37 | self.mocked_os = self.os_patcher.start() | ||
1502 | 38 | self.mocked_qt_gui = self.qt_gui_patcher.start() | ||
1503 | 39 | self.mocked_ui_strings = self.ui_strings_patcher.start() | ||
1504 | 40 | self.mocked_parent = MagicMock() | ||
1505 | 41 | |||
1506 | 42 | def tearDown(self): | ||
1507 | 43 | self.os_patcher.stop() | ||
1508 | 44 | self.qt_gui_patcher.stop() | ||
1509 | 45 | self.ui_strings_patcher.stop() | ||
1510 | 46 | 0 | ||
1511 | === modified file 'tests/functional/openlp_core_lib/test_lib.py' | |||
1512 | --- tests/functional/openlp_core_lib/test_lib.py 2017-08-04 17:40:57 +0000 | |||
1513 | +++ tests/functional/openlp_core_lib/test_lib.py 2017-08-23 20:14:53 +0000 | |||
1514 | @@ -24,6 +24,7 @@ | |||
1515 | 24 | """ | 24 | """ |
1516 | 25 | import os | 25 | import os |
1517 | 26 | from datetime import datetime, timedelta | 26 | from datetime import datetime, timedelta |
1518 | 27 | from pathlib import Path | ||
1519 | 27 | from unittest import TestCase | 28 | from unittest import TestCase |
1520 | 28 | from unittest.mock import MagicMock, patch | 29 | from unittest.mock import MagicMock, patch |
1521 | 29 | 30 | ||
1522 | @@ -148,35 +149,34 @@ | |||
1523 | 148 | """ | 149 | """ |
1524 | 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 |
1525 | 150 | """ | 151 | """ |
1530 | 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 |
1531 | 152 | # GIVEN: A mocked out isfile which returns true, and a text file name | 153 | with patch.object(Path, 'is_file', return_value=False): |
1532 | 153 | filename = 'testfile.txt' | 154 | file_path = Path('testfile.txt') |
1529 | 154 | mocked_isfile.return_value = False | ||
1533 | 155 | 155 | ||
1534 | 156 | # WHEN: get_text_file_string is called | 156 | # WHEN: get_text_file_string is called |
1536 | 157 | result = get_text_file_string(filename) | 157 | result = get_text_file_string(file_path) |
1537 | 158 | 158 | ||
1538 | 159 | # THEN: The result should be False | 159 | # THEN: The result should be False |
1540 | 160 | mocked_isfile.assert_called_with(filename) | 160 | file_path.is_file.assert_called_with() |
1541 | 161 | self.assertFalse(result, 'False should be returned if no file exists') | 161 | self.assertFalse(result, 'False should be returned if no file exists') |
1542 | 162 | 162 | ||
1543 | 163 | def test_get_text_file_string_read_error(self): | 163 | def test_get_text_file_string_read_error(self): |
1544 | 164 | """ | 164 | """ |
1545 | 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 |
1546 | 166 | """ | 166 | """ |
1553 | 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 |
1554 | 168 | patch('openlp.core.lib.open', create=True) as mocked_open: | 168 | with patch.object(Path, 'is_file'), \ |
1555 | 169 | # GIVEN: A mocked-out open() which raises an exception and isfile returns True | 169 | patch.object(Path, 'open'): |
1556 | 170 | filename = 'testfile.txt' | 170 | file_path = Path('testfile.txt') |
1557 | 171 | mocked_isfile.return_value = True | 171 | file_path.is_file.return_value = True |
1558 | 172 | mocked_open.side_effect = IOError() | 172 | file_path.open.side_effect = IOError() |
1559 | 173 | 173 | ||
1560 | 174 | # WHEN: get_text_file_string is called | 174 | # WHEN: get_text_file_string is called |
1562 | 175 | result = get_text_file_string(filename) | 175 | result = get_text_file_string(file_path) |
1563 | 176 | 176 | ||
1564 | 177 | # THEN: None should be returned | 177 | # THEN: None should be returned |
1567 | 178 | mocked_isfile.assert_called_with(filename) | 178 | file_path.is_file.assert_called_once_with() |
1568 | 179 | mocked_open.assert_called_with(filename, 'r', encoding='utf-8') | 179 | file_path.open.assert_called_once_with('r', encoding='utf-8') |
1569 | 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') |
1570 | 181 | 181 | ||
1571 | 182 | def test_get_text_file_string_decode_error(self): | 182 | def test_get_text_file_string_decode_error(self): |
1572 | 183 | 183 | ||
1573 | === modified file 'tests/functional/openlp_core_ui/test_firsttimeform.py' | |||
1574 | --- tests/functional/openlp_core_ui/test_firsttimeform.py 2017-04-24 05:17:55 +0000 | |||
1575 | +++ tests/functional/openlp_core_ui/test_firsttimeform.py 2017-08-23 20:14:53 +0000 | |||
1576 | @@ -25,6 +25,7 @@ | |||
1577 | 25 | import os | 25 | import os |
1578 | 26 | import tempfile | 26 | import tempfile |
1579 | 27 | import urllib | 27 | import urllib |
1580 | 28 | from pathlib import Path | ||
1581 | 28 | from unittest import TestCase | 29 | from unittest import TestCase |
1582 | 29 | from unittest.mock import MagicMock, patch | 30 | from unittest.mock import MagicMock, patch |
1583 | 30 | 31 | ||
1584 | @@ -116,7 +117,7 @@ | |||
1585 | 116 | mocked_settings.value.return_value = True | 117 | mocked_settings.value.return_value = True |
1586 | 117 | MockedSettings.return_value = mocked_settings | 118 | MockedSettings.return_value = mocked_settings |
1587 | 118 | mocked_gettempdir.return_value = 'temp' | 119 | mocked_gettempdir.return_value = 'temp' |
1589 | 119 | expected_temp_path = os.path.join('temp', 'openlp') | 120 | expected_temp_path = Path('temp', 'openlp') |
1590 | 120 | 121 | ||
1591 | 121 | # WHEN: The set_defaults() method is run | 122 | # WHEN: The set_defaults() method is run |
1592 | 122 | frw.set_defaults() | 123 | frw.set_defaults() |
1593 | 123 | 124 | ||
1594 | === modified file 'tests/functional/openlp_core_ui/test_thememanager.py' | |||
1595 | --- tests/functional/openlp_core_ui/test_thememanager.py 2017-06-01 06:18:47 +0000 | |||
1596 | +++ tests/functional/openlp_core_ui/test_thememanager.py 2017-08-23 20:14:53 +0000 | |||
1597 | @@ -90,7 +90,7 @@ | |||
1598 | 90 | # theme, check_directory_exists and thememanager-attributes. | 90 | # theme, check_directory_exists and thememanager-attributes. |
1599 | 91 | with patch('builtins.open') as mocked_open, \ | 91 | with patch('builtins.open') as mocked_open, \ |
1600 | 92 | patch('openlp.core.ui.thememanager.shutil.copyfile') as mocked_copyfile, \ | 92 | patch('openlp.core.ui.thememanager.shutil.copyfile') as mocked_copyfile, \ |
1602 | 93 | patch('openlp.core.ui.thememanager.check_directory_exists') as mocked_check_directory_exists: | 93 | patch('openlp.core.ui.thememanager.check_directory_exists'): |
1603 | 94 | mocked_open.return_value = MagicMock() | 94 | mocked_open.return_value = MagicMock() |
1604 | 95 | theme_manager = ThemeManager(None) | 95 | theme_manager = ThemeManager(None) |
1605 | 96 | theme_manager.old_background_image = None | 96 | theme_manager.old_background_image = None |
1606 | @@ -118,7 +118,7 @@ | |||
1607 | 118 | # theme, check_directory_exists and thememanager-attributes. | 118 | # theme, check_directory_exists and thememanager-attributes. |
1608 | 119 | with patch('builtins.open') as mocked_open, \ | 119 | with patch('builtins.open') as mocked_open, \ |
1609 | 120 | patch('openlp.core.ui.thememanager.shutil.copyfile') as mocked_copyfile, \ | 120 | patch('openlp.core.ui.thememanager.shutil.copyfile') as mocked_copyfile, \ |
1611 | 121 | patch('openlp.core.ui.thememanager.check_directory_exists') as mocked_check_directory_exists: | 121 | patch('openlp.core.ui.thememanager.check_directory_exists'): |
1612 | 122 | mocked_open.return_value = MagicMock() | 122 | mocked_open.return_value = MagicMock() |
1613 | 123 | theme_manager = ThemeManager(None) | 123 | theme_manager = ThemeManager(None) |
1614 | 124 | theme_manager.old_background_image = None | 124 | theme_manager.old_background_image = None |
1615 | 125 | 125 | ||
1616 | === modified file 'tests/functional/openlp_plugins/bibles/test_manager.py' | |||
1617 | --- tests/functional/openlp_plugins/bibles/test_manager.py 2016-12-31 11:01:36 +0000 | |||
1618 | +++ tests/functional/openlp_plugins/bibles/test_manager.py 2017-08-23 20:14:53 +0000 | |||
1619 | @@ -22,6 +22,7 @@ | |||
1620 | 22 | """ | 22 | """ |
1621 | 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. |
1622 | 24 | """ | 24 | """ |
1623 | 25 | from pathlib import Path | ||
1624 | 25 | from unittest import TestCase | 26 | from unittest import TestCase |
1625 | 26 | from unittest.mock import MagicMock, patch | 27 | from unittest.mock import MagicMock, patch |
1626 | 27 | 28 | ||
1627 | @@ -50,7 +51,6 @@ | |||
1628 | 50 | """ | 51 | """ |
1629 | 51 | # GIVEN: An instance of BibleManager and a mocked bible | 52 | # GIVEN: An instance of BibleManager and a mocked bible |
1630 | 52 | with patch.object(BibleManager, 'reload_bibles'), \ | 53 | with patch.object(BibleManager, 'reload_bibles'), \ |
1631 | 53 | patch('openlp.plugins.bibles.lib.manager.os.path.join', side_effect=lambda x, y: '{}/{}'.format(x, y)),\ | ||
1632 | 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: |
1633 | 55 | instance = BibleManager(MagicMock()) | 55 | instance = BibleManager(MagicMock()) |
1634 | 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! |
1635 | @@ -66,4 +66,4 @@ | |||
1636 | 66 | self.assertTrue(result) | 66 | self.assertTrue(result) |
1637 | 67 | mocked_close_all.assert_called_once_with() | 67 | mocked_close_all.assert_called_once_with() |
1638 | 68 | self.assertIsNone(mocked_bible.session) | 68 | self.assertIsNone(mocked_bible.session) |
1640 | 69 | mocked_delete_file.assert_called_once_with('bibles/KJV.sqlite') | 69 | mocked_delete_file.assert_called_once_with(Path('bibles', 'KJV.sqlite')) |
1641 | 70 | 70 | ||
1642 | === modified file 'tests/functional/openlp_plugins/media/test_mediaplugin.py' | |||
1643 | --- tests/functional/openlp_plugins/media/test_mediaplugin.py 2017-06-06 20:58:12 +0000 | |||
1644 | +++ tests/functional/openlp_plugins/media/test_mediaplugin.py 2017-08-23 20:14:53 +0000 | |||
1645 | @@ -38,20 +38,18 @@ | |||
1646 | 38 | def setUp(self): | 38 | def setUp(self): |
1647 | 39 | Registry.create() | 39 | Registry.create() |
1648 | 40 | 40 | ||
1650 | 41 | @patch(u'openlp.plugins.media.mediaplugin.Plugin.initialise') | 41 | @patch('openlp.plugins.media.mediaplugin.Plugin.initialise') |
1651 | 42 | def test_initialise(self, mocked_initialise): | 42 | def test_initialise(self, mocked_initialise): |
1652 | 43 | """ | 43 | """ |
1653 | 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 |
1654 | 45 | """ | 45 | """ |
1656 | 46 | # GIVEN: A media plugin instance and a mocked settings object | 46 | # GIVEN: A media plugin instance |
1657 | 47 | media_plugin = MediaPlugin() | 47 | media_plugin = MediaPlugin() |
1658 | 48 | mocked_settings = MagicMock() | ||
1659 | 49 | mocked_settings.get_files_from_config.return_value = True # Not the real value, just need something "true-ish" | ||
1660 | 50 | 48 | ||
1661 | 51 | # WHEN: initialise() is called | 49 | # WHEN: initialise() is called |
1662 | 52 | media_plugin.initialise() | 50 | media_plugin.initialise() |
1663 | 53 | 51 | ||
1665 | 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 |
1666 | 55 | mocked_initialise.assert_called_with() | 53 | mocked_initialise.assert_called_with() |
1667 | 56 | 54 | ||
1668 | 57 | def test_about_text(self): | 55 | def test_about_text(self): |
1669 | 58 | 56 | ||
1670 | === modified file 'tests/functional/openlp_plugins/presentations/test_presentationcontroller.py' | |||
1671 | --- tests/functional/openlp_plugins/presentations/test_presentationcontroller.py 2017-05-30 18:42:35 +0000 | |||
1672 | +++ tests/functional/openlp_plugins/presentations/test_presentationcontroller.py 2017-08-23 20:14:53 +0000 | |||
1673 | @@ -24,6 +24,7 @@ | |||
1674 | 24 | classes and related methods. | 24 | classes and related methods. |
1675 | 25 | """ | 25 | """ |
1676 | 26 | import os | 26 | import os |
1677 | 27 | from pathlib import Path | ||
1678 | 27 | from unittest import TestCase | 28 | from unittest import TestCase |
1679 | 28 | from unittest.mock import MagicMock, mock_open, patch | 29 | from unittest.mock import MagicMock, mock_open, patch |
1680 | 29 | 30 | ||
1681 | @@ -38,7 +39,8 @@ | |||
1682 | 38 | """ | 39 | """ |
1683 | 39 | def setUp(self): | 40 | def setUp(self): |
1684 | 40 | self.get_thumbnail_folder_patcher = \ | 41 | self.get_thumbnail_folder_patcher = \ |
1686 | 41 | patch('openlp.plugins.presentations.lib.presentationcontroller.PresentationDocument.get_thumbnail_folder') | 42 | patch('openlp.plugins.presentations.lib.presentationcontroller.PresentationDocument.get_thumbnail_folder', |
1687 | 43 | return_value=Path()) | ||
1688 | 42 | self.get_thumbnail_folder_patcher.start() | 44 | self.get_thumbnail_folder_patcher.start() |
1689 | 43 | mocked_plugin = MagicMock() | 45 | mocked_plugin = MagicMock() |
1690 | 44 | mocked_plugin.settings_section = 'presentations' | 46 | mocked_plugin.settings_section = 'presentations' |
1691 | @@ -225,7 +227,7 @@ | |||
1692 | 225 | PresentationDocument(self.mock_controller, 'Name') | 227 | PresentationDocument(self.mock_controller, 'Name') |
1693 | 226 | 228 | ||
1694 | 227 | # THEN: check_directory_exists should have been called with 'returned/path/' | 229 | # THEN: check_directory_exists should have been called with 'returned/path/' |
1696 | 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')) |
1697 | 229 | 231 | ||
1698 | 230 | self._setup_patcher.start() | 232 | self._setup_patcher.start() |
1699 | 231 | 233 | ||
1700 | 232 | 234 | ||
1701 | === modified file 'tests/interfaces/openlp_core_common/test_utils.py' | |||
1702 | --- tests/interfaces/openlp_core_common/test_utils.py 2016-12-31 11:01:36 +0000 | |||
1703 | +++ tests/interfaces/openlp_core_common/test_utils.py 2017-08-23 20:14:53 +0000 | |||
1704 | @@ -22,7 +22,7 @@ | |||
1705 | 22 | """ | 22 | """ |
1706 | 23 | Functional tests to test the AppLocation class and related methods. | 23 | Functional tests to test the AppLocation class and related methods. |
1707 | 24 | """ | 24 | """ |
1709 | 25 | import os | 25 | from pathlib import Path |
1710 | 26 | from unittest import TestCase | 26 | from unittest import TestCase |
1711 | 27 | 27 | ||
1712 | 28 | from openlp.core.common import is_not_image_file | 28 | from openlp.core.common import is_not_image_file |
1713 | @@ -59,7 +59,7 @@ | |||
1714 | 59 | Test the method handles an image file | 59 | Test the method handles an image file |
1715 | 60 | """ | 60 | """ |
1716 | 61 | # Given and empty string | 61 | # Given and empty string |
1718 | 62 | file_name = os.path.join(TEST_RESOURCES_PATH, 'church.jpg') | 62 | file_name = Path(TEST_RESOURCES_PATH, 'church.jpg') |
1719 | 63 | 63 | ||
1720 | 64 | # WHEN testing for it | 64 | # WHEN testing for it |
1721 | 65 | result = is_not_image_file(file_name) | 65 | result = is_not_image_file(file_name) |
1722 | @@ -72,7 +72,7 @@ | |||
1723 | 72 | Test the method handles a non image file | 72 | Test the method handles a non image file |
1724 | 73 | """ | 73 | """ |
1725 | 74 | # Given and empty string | 74 | # Given and empty string |
1727 | 75 | file_name = os.path.join(TEST_RESOURCES_PATH, 'serviceitem_custom_1.osj') | 75 | file_name = Path(TEST_RESOURCES_PATH, 'serviceitem_custom_1.osj') |
1728 | 76 | 76 | ||
1729 | 77 | # WHEN testing for it | 77 | # WHEN testing for it |
1730 | 78 | result = is_not_image_file(file_name) | 78 | result = is_not_image_file(file_name) |
See inline