Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 2774 | ||||
Proposed branch: | lp:~phill-ridout/openlp/pathlib8 | ||||
Merge into: | lp:openlp | ||||
Diff against target: |
3277 lines (+662/-713) 66 files modified
openlp/core/lib/serviceitem.py (+2/-2) openlp/core/ui/maindisplay.py (+1/-1) openlp/core/ui/servicemanager.py (+3/-1) openlp/core/ui/slidecontroller.py (+1/-1) openlp/plugins/songs/forms/editsongform.py (+34/-38) openlp/plugins/songs/forms/mediafilesform.py (+11/-4) openlp/plugins/songs/forms/songexportform.py (+13/-29) openlp/plugins/songs/forms/songimportform.py (+43/-68) openlp/plugins/songs/lib/__init__.py (+5/-5) openlp/plugins/songs/lib/db.py (+5/-4) openlp/plugins/songs/lib/importers/cclifile.py (+27/-31) openlp/plugins/songs/lib/importers/chordpro.py (+3/-4) openlp/plugins/songs/lib/importers/dreambeam.py (+10/-8) openlp/plugins/songs/lib/importers/easyslides.py (+1/-1) openlp/plugins/songs/lib/importers/easyworship.py (+30/-46) openlp/plugins/songs/lib/importers/foilpresenter.py (+2/-5) openlp/plugins/songs/lib/importers/lyrix.py (+3/-4) openlp/plugins/songs/lib/importers/openlp.py (+1/-1) openlp/plugins/songs/lib/importers/openlyrics.py (+2/-5) openlp/plugins/songs/lib/importers/openoffice.py (+5/-12) openlp/plugins/songs/lib/importers/opensong.py (+3/-5) openlp/plugins/songs/lib/importers/opspro.py (+9/-10) openlp/plugins/songs/lib/importers/powerpraise.py (+4/-6) openlp/plugins/songs/lib/importers/powersong.py (+7/-3) openlp/plugins/songs/lib/importers/presentationmanager.py (+11/-11) openlp/plugins/songs/lib/importers/propresenter.py (+11/-9) openlp/plugins/songs/lib/importers/songbeamer.py (+14/-14) openlp/plugins/songs/lib/importers/songimport.py (+26/-27) openlp/plugins/songs/lib/importers/songpro.py (+3/-1) openlp/plugins/songs/lib/importers/songshowplus.py (+84/-87) openlp/plugins/songs/lib/importers/sundayplus.py (+3/-7) openlp/plugins/songs/lib/importers/videopsalm.py (+8/-9) openlp/plugins/songs/lib/importers/wordsofworship.py (+55/-56) openlp/plugins/songs/lib/importers/worshipassistant.py (+11/-15) openlp/plugins/songs/lib/importers/zionworx.py (+1/-1) openlp/plugins/songs/lib/mediaitem.py (+16/-18) openlp/plugins/songs/lib/openlyricsexport.py (+10/-9) openlp/plugins/songs/lib/upgrade.py (+31/-2) openlp/plugins/songs/reporting.py (+2/-3) openlp/plugins/songs/songsplugin.py (+1/-3) tests/functional/openlp_plugins/images/test_upgrade.py (+1/-0) tests/functional/openlp_plugins/songs/test_chordproimport.py (+3/-1) tests/functional/openlp_plugins/songs/test_easyslidesimport.py (+4/-3) tests/functional/openlp_plugins/songs/test_ewimport.py (+35/-54) tests/functional/openlp_plugins/songs/test_lyriximport.py (+5/-4) tests/functional/openlp_plugins/songs/test_mediashout.py (+6/-6) tests/functional/openlp_plugins/songs/test_openlpimporter.py (+2/-2) tests/functional/openlp_plugins/songs/test_openlyricsexport.py (+10/-8) tests/functional/openlp_plugins/songs/test_openlyricsimport.py (+5/-4) tests/functional/openlp_plugins/songs/test_openoffice.py (+2/-2) tests/functional/openlp_plugins/songs/test_opensongimport.py (+9/-8) tests/functional/openlp_plugins/songs/test_opsproimport.py (+5/-5) tests/functional/openlp_plugins/songs/test_powerpraiseimport.py (+4/-3) tests/functional/openlp_plugins/songs/test_presentationmanagerimport.py (+4/-3) tests/functional/openlp_plugins/songs/test_propresenterimport.py (+5/-4) tests/functional/openlp_plugins/songs/test_songbeamerimport.py (+8/-7) tests/functional/openlp_plugins/songs/test_songproimport.py (+3/-2) tests/functional/openlp_plugins/songs/test_songselect.py (+4/-3) tests/functional/openlp_plugins/songs/test_songshowplusimport.py (+10/-9) tests/functional/openlp_plugins/songs/test_sundayplusimport.py (+3/-1) tests/functional/openlp_plugins/songs/test_videopsalm.py (+4/-3) tests/functional/openlp_plugins/songs/test_wordsofworshipimport.py (+5/-4) tests/functional/openlp_plugins/songs/test_worshipassistantimport.py (+5/-4) tests/functional/openlp_plugins/songs/test_worshipcenterproimport.py (+3/-3) tests/functional/openlp_plugins/songs/test_zionworximport.py (+4/-3) tests/helpers/songfileimport.py (+1/-1) |
||||
To merge this branch: | bzr merge lp:~phill-ridout/openlp/pathlib8 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tomas Groth | Approve | ||
Tim Bentley | Approve | ||
Review via email: mp+331621@code.launchpad.net |
Commit message
Description of the change
Pathlib changes for the song plugin
lp:~phill-ridout/openlp/pathlib8 (revision 2777)
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[FAILURE] https:/
Stopping after failure
To post a comment you must log in.
Revision history for this message
Tim Bentley (trb143) : | # |
review:
Approve
Revision history for this message
Tomas Groth (tomasgroth) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'openlp/core/lib/serviceitem.py' | |||
2 | --- openlp/core/lib/serviceitem.py 2017-08-03 17:54:40 +0000 | |||
3 | +++ openlp/core/lib/serviceitem.py 2017-09-30 23:24:21 +0000 | |||
4 | @@ -426,10 +426,10 @@ | |||
5 | 426 | self.background_audio = [] | 426 | self.background_audio = [] |
6 | 427 | for filename in header['background_audio']: | 427 | for filename in header['background_audio']: |
7 | 428 | # Give them real file paths. | 428 | # Give them real file paths. |
9 | 429 | filepath = filename | 429 | filepath = str(filename) |
10 | 430 | if path: | 430 | if path: |
11 | 431 | # Windows can handle both forward and backward slashes, so we use ntpath to get the basename | 431 | # Windows can handle both forward and backward slashes, so we use ntpath to get the basename |
13 | 432 | filepath = os.path.join(path, ntpath.basename(filename)) | 432 | filepath = os.path.join(path, ntpath.basename(str(filename))) |
14 | 433 | self.background_audio.append(filepath) | 433 | self.background_audio.append(filepath) |
15 | 434 | self.theme_overwritten = header.get('theme_overwritten', False) | 434 | self.theme_overwritten = header.get('theme_overwritten', False) |
16 | 435 | if self.service_item_type == ServiceItemType.Text: | 435 | if self.service_item_type == ServiceItemType.Text: |
17 | 436 | 436 | ||
18 | === modified file 'openlp/core/ui/maindisplay.py' | |||
19 | --- openlp/core/ui/maindisplay.py 2017-09-26 16:39:13 +0000 | |||
20 | +++ openlp/core/ui/maindisplay.py 2017-09-30 23:24:21 +0000 | |||
21 | @@ -684,7 +684,7 @@ | |||
22 | 684 | if not isinstance(file_names, list): | 684 | if not isinstance(file_names, list): |
23 | 685 | file_names = [file_names] | 685 | file_names = [file_names] |
24 | 686 | for file_name in file_names: | 686 | for file_name in file_names: |
26 | 687 | self.playlist.addMedia(QtMultimedia.QMediaContent(QtCore.QUrl.fromLocalFile(file_name))) | 687 | self.playlist.addMedia(QtMultimedia.QMediaContent(QtCore.QUrl.fromLocalFile(str(file_name)))) |
27 | 688 | 688 | ||
28 | 689 | def next(self): | 689 | def next(self): |
29 | 690 | """ | 690 | """ |
30 | 691 | 691 | ||
31 | === modified file 'openlp/core/ui/servicemanager.py' | |||
32 | --- openlp/core/ui/servicemanager.py 2017-09-23 13:06:42 +0000 | |||
33 | +++ openlp/core/ui/servicemanager.py 2017-09-30 23:24:21 +0000 | |||
34 | @@ -561,7 +561,7 @@ | |||
35 | 561 | service_item = item['service_item'].get_service_repr(self._save_lite) | 561 | service_item = item['service_item'].get_service_repr(self._save_lite) |
36 | 562 | if service_item['header']['background_audio']: | 562 | if service_item['header']['background_audio']: |
37 | 563 | for i, file_name in enumerate(service_item['header']['background_audio']): | 563 | for i, file_name in enumerate(service_item['header']['background_audio']): |
39 | 564 | new_file = os.path.join('audio', item['service_item'].unique_identifier, file_name) | 564 | new_file = os.path.join('audio', item['service_item'].unique_identifier, str(file_name)) |
40 | 565 | audio_files.append((file_name, new_file)) | 565 | audio_files.append((file_name, new_file)) |
41 | 566 | service_item['header']['background_audio'][i] = new_file | 566 | service_item['header']['background_audio'][i] = new_file |
42 | 567 | # Add the service item to the service. | 567 | # Add the service item to the service. |
43 | @@ -586,6 +586,8 @@ | |||
44 | 586 | for write_from in write_list: | 586 | for write_from in write_list: |
45 | 587 | zip_file.write(write_from, write_from) | 587 | zip_file.write(write_from, write_from) |
46 | 588 | for audio_from, audio_to in audio_files: | 588 | for audio_from, audio_to in audio_files: |
47 | 589 | audio_from = str(audio_from) | ||
48 | 590 | audio_to = str(audio_to) | ||
49 | 589 | if audio_from.startswith('audio'): | 591 | if audio_from.startswith('audio'): |
50 | 590 | # When items are saved, they get new unique_identifier. Let's copy the file to the new location. | 592 | # When items are saved, they get new unique_identifier. Let's copy the file to the new location. |
51 | 591 | # Unused files can be ignored, OpenLP automatically cleans up the service manager dir on exit. | 593 | # Unused files can be ignored, OpenLP automatically cleans up the service manager dir on exit. |
52 | 592 | 594 | ||
53 | === modified file 'openlp/core/ui/slidecontroller.py' | |||
54 | --- openlp/core/ui/slidecontroller.py 2017-06-06 20:58:12 +0000 | |||
55 | +++ openlp/core/ui/slidecontroller.py 2017-09-30 23:24:21 +0000 | |||
56 | @@ -868,7 +868,7 @@ | |||
57 | 868 | self.track_menu.clear() | 868 | self.track_menu.clear() |
58 | 869 | for counter in range(len(self.service_item.background_audio)): | 869 | for counter in range(len(self.service_item.background_audio)): |
59 | 870 | action = self.track_menu.addAction( | 870 | action = self.track_menu.addAction( |
61 | 871 | os.path.basename(self.service_item.background_audio[counter])) | 871 | os.path.basename(str(self.service_item.background_audio[counter]))) |
62 | 872 | action.setData(counter) | 872 | action.setData(counter) |
63 | 873 | action.triggered.connect(self.on_track_triggered) | 873 | action.triggered.connect(self.on_track_triggered) |
64 | 874 | self.display.audio_player.repeat = \ | 874 | self.display.audio_player.repeat = \ |
65 | 875 | 875 | ||
66 | === modified file 'openlp/plugins/songs/forms/editsongform.py' | |||
67 | --- openlp/plugins/songs/forms/editsongform.py 2017-08-25 20:03:25 +0000 | |||
68 | +++ openlp/plugins/songs/forms/editsongform.py 2017-09-30 23:24:21 +0000 | |||
69 | @@ -23,27 +23,25 @@ | |||
70 | 23 | The :mod:`~openlp.plugins.songs.forms.editsongform` module contains the form | 23 | The :mod:`~openlp.plugins.songs.forms.editsongform` module contains the form |
71 | 24 | used to edit songs. | 24 | used to edit songs. |
72 | 25 | """ | 25 | """ |
73 | 26 | |||
74 | 27 | import logging | 26 | import logging |
75 | 27 | import os | ||
76 | 28 | import re | 28 | import re |
77 | 29 | import os | ||
78 | 30 | import shutil | ||
79 | 31 | 29 | ||
80 | 32 | from PyQt5 import QtCore, QtWidgets | 30 | from PyQt5 import QtCore, QtWidgets |
81 | 33 | 31 | ||
82 | 34 | from openlp.core.common import Registry, RegistryProperties, AppLocation, UiStrings, check_directory_exists, translate | 32 | from openlp.core.common import Registry, RegistryProperties, AppLocation, UiStrings, check_directory_exists, translate |
84 | 35 | from openlp.core.common.path import Path, path_to_str | 33 | from openlp.core.common.languagemanager import get_natural_key |
85 | 34 | from openlp.core.common.path import copyfile | ||
86 | 36 | from openlp.core.lib import PluginStatus, MediaType, create_separated_list | 35 | from openlp.core.lib import PluginStatus, MediaType, create_separated_list |
87 | 37 | from openlp.core.lib.ui import set_case_insensitive_completer, critical_error_message_box, find_and_set_in_combo_box | 36 | from openlp.core.lib.ui import set_case_insensitive_completer, critical_error_message_box, find_and_set_in_combo_box |
88 | 38 | from openlp.core.ui.lib.filedialog import FileDialog | 37 | from openlp.core.ui.lib.filedialog import FileDialog |
90 | 39 | from openlp.core.common.languagemanager import get_natural_key | 38 | from openlp.plugins.songs.forms.editsongdialog import Ui_EditSongDialog |
91 | 39 | from openlp.plugins.songs.forms.editverseform import EditVerseForm | ||
92 | 40 | from openlp.plugins.songs.forms.mediafilesform import MediaFilesForm | ||
93 | 40 | from openlp.plugins.songs.lib import VerseType, clean_song | 41 | from openlp.plugins.songs.lib import VerseType, clean_song |
94 | 41 | from openlp.plugins.songs.lib.db import Book, Song, Author, AuthorType, Topic, MediaFile, SongBookEntry | 42 | from openlp.plugins.songs.lib.db import Book, Song, Author, AuthorType, Topic, MediaFile, SongBookEntry |
95 | 43 | from openlp.plugins.songs.lib.openlyricsxml import SongXML | ||
96 | 42 | from openlp.plugins.songs.lib.ui import SongStrings | 44 | from openlp.plugins.songs.lib.ui import SongStrings |
97 | 43 | from openlp.plugins.songs.lib.openlyricsxml import SongXML | ||
98 | 44 | from openlp.plugins.songs.forms.editsongdialog import Ui_EditSongDialog | ||
99 | 45 | from openlp.plugins.songs.forms.editverseform import EditVerseForm | ||
100 | 46 | from openlp.plugins.songs.forms.mediafilesform import MediaFilesForm | ||
101 | 47 | 45 | ||
102 | 48 | log = logging.getLogger(__name__) | 46 | log = logging.getLogger(__name__) |
103 | 49 | 47 | ||
104 | @@ -545,9 +543,9 @@ | |||
105 | 545 | songbook_entry.entry) | 543 | songbook_entry.entry) |
106 | 546 | self.audio_list_widget.clear() | 544 | self.audio_list_widget.clear() |
107 | 547 | for media in self.song.media_files: | 545 | for media in self.song.media_files: |
111 | 548 | media_file = QtWidgets.QListWidgetItem(os.path.split(media.file_name)[1]) | 546 | item = QtWidgets.QListWidgetItem(media.file_path.name) |
112 | 549 | media_file.setData(QtCore.Qt.UserRole, media.file_name) | 547 | item.setData(QtCore.Qt.UserRole, media.file_path) |
113 | 550 | self.audio_list_widget.addItem(media_file) | 548 | self.audio_list_widget.addItem(item) |
114 | 551 | self.title_edit.setFocus() | 549 | self.title_edit.setFocus() |
115 | 552 | # Hide or show the preview button. | 550 | # Hide or show the preview button. |
116 | 553 | self.preview_button.setVisible(preview) | 551 | self.preview_button.setVisible(preview) |
117 | @@ -927,12 +925,11 @@ | |||
118 | 927 | Loads file(s) from the filesystem. | 925 | Loads file(s) from the filesystem. |
119 | 928 | """ | 926 | """ |
120 | 929 | filters = '{text} (*)'.format(text=UiStrings().AllFiles) | 927 | filters = '{text} (*)'.format(text=UiStrings().AllFiles) |
123 | 930 | file_paths, selected_filter = FileDialog.getOpenFileNames( | 928 | file_paths, filter_used = FileDialog.getOpenFileNames( |
124 | 931 | self, translate('SongsPlugin.EditSongForm', 'Open File(s)'), Path(), filters) | 929 | parent=self, caption=translate('SongsPlugin.EditSongForm', 'Open File(s)'), filter=filters) |
125 | 932 | for file_path in file_paths: | 930 | for file_path in file_paths: |
129 | 933 | filename = path_to_str(file_path) | 931 | item = QtWidgets.QListWidgetItem(file_path.name) |
130 | 934 | item = QtWidgets.QListWidgetItem(os.path.split(str(filename))[1]) | 932 | item.setData(QtCore.Qt.UserRole, file_path) |
128 | 935 | item.setData(QtCore.Qt.UserRole, filename) | ||
131 | 936 | self.audio_list_widget.addItem(item) | 933 | self.audio_list_widget.addItem(item) |
132 | 937 | 934 | ||
133 | 938 | def on_audio_add_from_media_button_clicked(self): | 935 | def on_audio_add_from_media_button_clicked(self): |
134 | @@ -940,9 +937,9 @@ | |||
135 | 940 | Loads file(s) from the media plugin. | 937 | Loads file(s) from the media plugin. |
136 | 941 | """ | 938 | """ |
137 | 942 | if self.media_form.exec(): | 939 | if self.media_form.exec(): |
141 | 943 | for filename in self.media_form.get_selected_files(): | 940 | for file_path in self.media_form.get_selected_files(): |
142 | 944 | item = QtWidgets.QListWidgetItem(os.path.split(str(filename))[1]) | 941 | item = QtWidgets.QListWidgetItem(file_path.name) |
143 | 945 | item.setData(QtCore.Qt.UserRole, filename) | 942 | item.setData(QtCore.Qt.UserRole, file_path) |
144 | 946 | self.audio_list_widget.addItem(item) | 943 | self.audio_list_widget.addItem(item) |
145 | 947 | 944 | ||
146 | 948 | def on_audio_remove_button_clicked(self): | 945 | def on_audio_remove_button_clicked(self): |
147 | @@ -1066,34 +1063,33 @@ | |||
148 | 1066 | # Save the song here because we need a valid id for the audio files. | 1063 | # Save the song here because we need a valid id for the audio files. |
149 | 1067 | clean_song(self.manager, self.song) | 1064 | clean_song(self.manager, self.song) |
150 | 1068 | self.manager.save_object(self.song) | 1065 | self.manager.save_object(self.song) |
156 | 1069 | audio_files = [a.file_name for a in self.song.media_files] | 1066 | audio_paths = [a.file_path for a in self.song.media_files] |
157 | 1070 | log.debug(audio_files) | 1067 | log.debug(audio_paths) |
158 | 1071 | save_path = os.path.join(str(AppLocation.get_section_data_path(self.media_item.plugin.name)), 'audio', | 1068 | save_path = AppLocation.get_section_data_path(self.media_item.plugin.name) / 'audio' / str(self.song.id) |
159 | 1072 | str(self.song.id)) | 1069 | check_directory_exists(save_path) |
155 | 1073 | check_directory_exists(Path(save_path)) | ||
160 | 1074 | self.song.media_files = [] | 1070 | self.song.media_files = [] |
162 | 1075 | files = [] | 1071 | file_paths = [] |
163 | 1076 | for row in range(self.audio_list_widget.count()): | 1072 | for row in range(self.audio_list_widget.count()): |
164 | 1077 | item = self.audio_list_widget.item(row) | 1073 | item = self.audio_list_widget.item(row) |
170 | 1078 | filename = item.data(QtCore.Qt.UserRole) | 1074 | file_path = item.data(QtCore.Qt.UserRole) |
171 | 1079 | if not filename.startswith(save_path): | 1075 | if save_path not in file_path.parents: |
172 | 1080 | old_file, filename = filename, os.path.join(save_path, os.path.split(filename)[1]) | 1076 | old_file_path, file_path = file_path, save_path / file_path.name |
173 | 1081 | shutil.copyfile(old_file, filename) | 1077 | copyfile(old_file_path, file_path) |
174 | 1082 | files.append(filename) | 1078 | file_paths.append(file_path) |
175 | 1083 | media_file = MediaFile() | 1079 | media_file = MediaFile() |
177 | 1084 | media_file.file_name = filename | 1080 | media_file.file_path = file_path |
178 | 1085 | media_file.type = 'audio' | 1081 | media_file.type = 'audio' |
179 | 1086 | media_file.weight = row | 1082 | media_file.weight = row |
180 | 1087 | self.song.media_files.append(media_file) | 1083 | self.song.media_files.append(media_file) |
183 | 1088 | for audio in audio_files: | 1084 | for audio_path in audio_paths: |
184 | 1089 | if audio not in files: | 1085 | if audio_path not in file_paths: |
185 | 1090 | try: | 1086 | try: |
187 | 1091 | os.remove(audio) | 1087 | audio_path.unlink() |
188 | 1092 | except: | 1088 | except: |
191 | 1093 | log.exception('Could not remove file: {audio}'.format(audio=audio)) | 1089 | log.exception('Could not remove file: {audio}'.format(audio=audio_path)) |
192 | 1094 | if not files: | 1090 | if not file_paths: |
193 | 1095 | try: | 1091 | try: |
195 | 1096 | os.rmdir(save_path) | 1092 | save_path.rmdir() |
196 | 1097 | except OSError: | 1093 | except OSError: |
197 | 1098 | log.exception('Could not remove directory: {path}'.format(path=save_path)) | 1094 | log.exception('Could not remove directory: {path}'.format(path=save_path)) |
198 | 1099 | clean_song(self.manager, self.song) | 1095 | clean_song(self.manager, self.song) |
199 | 1100 | 1096 | ||
200 | === modified file 'openlp/plugins/songs/forms/mediafilesform.py' | |||
201 | --- openlp/plugins/songs/forms/mediafilesform.py 2017-06-04 12:14:23 +0000 | |||
202 | +++ openlp/plugins/songs/forms/mediafilesform.py 2017-09-30 23:24:21 +0000 | |||
203 | @@ -41,12 +41,19 @@ | |||
204 | 41 | QtCore.Qt.WindowCloseButtonHint) | 41 | QtCore.Qt.WindowCloseButtonHint) |
205 | 42 | self.setupUi(self) | 42 | self.setupUi(self) |
206 | 43 | 43 | ||
208 | 44 | def populate_files(self, files): | 44 | def populate_files(self, file_paths): |
209 | 45 | """ | ||
210 | 46 | :param list[openlp.core.common.path.Path] file_paths: | ||
211 | 47 | :return: | ||
212 | 48 | """ | ||
213 | 45 | self.file_list_widget.clear() | 49 | self.file_list_widget.clear() |
217 | 46 | for file in files: | 50 | for file_path in file_paths: |
218 | 47 | item = QtWidgets.QListWidgetItem(os.path.split(file)[1]) | 51 | item = QtWidgets.QListWidgetItem(file_path.name) |
219 | 48 | item.setData(QtCore.Qt.UserRole, file) | 52 | item.setData(QtCore.Qt.UserRole, file_path) |
220 | 49 | self.file_list_widget.addItem(item) | 53 | self.file_list_widget.addItem(item) |
221 | 50 | 54 | ||
222 | 51 | def get_selected_files(self): | 55 | def get_selected_files(self): |
223 | 56 | """ | ||
224 | 57 | :rtype: list[openlp.core.common.path.Path] | ||
225 | 58 | """ | ||
226 | 52 | return [item.data(QtCore.Qt.UserRole) for item in self.file_list_widget.selectedItems()] | 59 | return [item.data(QtCore.Qt.UserRole) for item in self.file_list_widget.selectedItems()] |
227 | 53 | 60 | ||
228 | === modified file 'openlp/plugins/songs/forms/songexportform.py' | |||
229 | --- openlp/plugins/songs/forms/songexportform.py 2017-05-30 18:42:35 +0000 | |||
230 | +++ openlp/plugins/songs/forms/songexportform.py 2017-09-30 23:24:21 +0000 | |||
231 | @@ -27,9 +27,10 @@ | |||
232 | 27 | 27 | ||
233 | 28 | from PyQt5 import QtCore, QtWidgets | 28 | from PyQt5 import QtCore, QtWidgets |
234 | 29 | 29 | ||
237 | 30 | from openlp.core.common import Registry, UiStrings, translate | 30 | from openlp.core.common import Registry, Settings, UiStrings, translate |
238 | 31 | from openlp.core.lib import create_separated_list, build_icon | 31 | from openlp.core.lib import create_separated_list |
239 | 32 | from openlp.core.lib.ui import critical_error_message_box | 32 | from openlp.core.lib.ui import critical_error_message_box |
240 | 33 | from openlp.core.ui.lib import PathEdit, PathType | ||
241 | 33 | from openlp.core.ui.lib.wizard import OpenLPWizard, WizardStrings | 34 | from openlp.core.ui.lib.wizard import OpenLPWizard, WizardStrings |
242 | 34 | from openlp.plugins.songs.lib.db import Song | 35 | from openlp.plugins.songs.lib.db import Song |
243 | 35 | from openlp.plugins.songs.lib.openlyricsexport import OpenLyricsExport | 36 | from openlp.plugins.songs.lib.openlyricsexport import OpenLyricsExport |
244 | @@ -76,7 +77,6 @@ | |||
245 | 76 | self.search_line_edit.textEdited.connect(self.on_search_line_edit_changed) | 77 | self.search_line_edit.textEdited.connect(self.on_search_line_edit_changed) |
246 | 77 | self.uncheck_button.clicked.connect(self.on_uncheck_button_clicked) | 78 | self.uncheck_button.clicked.connect(self.on_uncheck_button_clicked) |
247 | 78 | self.check_button.clicked.connect(self.on_check_button_clicked) | 79 | self.check_button.clicked.connect(self.on_check_button_clicked) |
248 | 79 | self.directory_button.clicked.connect(self.on_directory_button_clicked) | ||
249 | 80 | 80 | ||
250 | 81 | def add_custom_pages(self): | 81 | def add_custom_pages(self): |
251 | 82 | """ | 82 | """ |
252 | @@ -120,21 +120,15 @@ | |||
253 | 120 | self.grid_layout.setObjectName('range_layout') | 120 | self.grid_layout.setObjectName('range_layout') |
254 | 121 | self.selected_list_widget = QtWidgets.QListWidget(self.export_song_page) | 121 | self.selected_list_widget = QtWidgets.QListWidget(self.export_song_page) |
255 | 122 | self.selected_list_widget.setObjectName('selected_list_widget') | 122 | self.selected_list_widget.setObjectName('selected_list_widget') |
260 | 123 | self.grid_layout.addWidget(self.selected_list_widget, 1, 0, 1, 1) | 123 | self.grid_layout.addWidget(self.selected_list_widget, 1, 0, 1, 2) |
261 | 124 | # FIXME: self.horizontal_layout is already defined above?!?!? Replace with Path Eidt! | 124 | self.output_directory_path_edit = PathEdit( |
262 | 125 | self.horizontal_layout = QtWidgets.QHBoxLayout() | 125 | self.export_song_page, PathType.Directories, |
263 | 126 | self.horizontal_layout.setObjectName('horizontal_layout') | 126 | dialog_caption=translate('SongsPlugin.ExportWizardForm', 'Select Destination Folder'), show_revert=False) |
264 | 127 | self.output_directory_path_edit.path = Settings().value('songs/last directory export') | ||
265 | 127 | self.directory_label = QtWidgets.QLabel(self.export_song_page) | 128 | self.directory_label = QtWidgets.QLabel(self.export_song_page) |
266 | 128 | self.directory_label.setObjectName('directory_label') | 129 | self.directory_label.setObjectName('directory_label') |
276 | 129 | self.horizontal_layout.addWidget(self.directory_label) | 130 | self.grid_layout.addWidget(self.directory_label, 0, 0) |
277 | 130 | self.directory_line_edit = QtWidgets.QLineEdit(self.export_song_page) | 131 | self.grid_layout.addWidget(self.output_directory_path_edit, 0, 1) |
269 | 131 | self.directory_line_edit.setObjectName('directory_line_edit') | ||
270 | 132 | self.horizontal_layout.addWidget(self.directory_line_edit) | ||
271 | 133 | self.directory_button = QtWidgets.QToolButton(self.export_song_page) | ||
272 | 134 | self.directory_button.setIcon(build_icon(':/exports/export_load.png')) | ||
273 | 135 | self.directory_button.setObjectName('directory_button') | ||
274 | 136 | self.horizontal_layout.addWidget(self.directory_button) | ||
275 | 137 | self.grid_layout.addLayout(self.horizontal_layout, 0, 0, 1, 1) | ||
278 | 138 | self.export_song_layout.addLayout(self.grid_layout) | 132 | self.export_song_layout.addLayout(self.grid_layout) |
279 | 139 | self.addPage(self.export_song_page) | 133 | self.addPage(self.export_song_page) |
280 | 140 | 134 | ||
281 | @@ -188,11 +182,12 @@ | |||
282 | 188 | self.selected_list_widget.addItem(song) | 182 | self.selected_list_widget.addItem(song) |
283 | 189 | return True | 183 | return True |
284 | 190 | elif self.currentPage() == self.export_song_page: | 184 | elif self.currentPage() == self.export_song_page: |
286 | 191 | if not self.directory_line_edit.text(): | 185 | if not self.output_directory_path_edit.path: |
287 | 192 | critical_error_message_box( | 186 | critical_error_message_box( |
288 | 193 | translate('SongsPlugin.ExportWizardForm', 'No Save Location specified'), | 187 | translate('SongsPlugin.ExportWizardForm', 'No Save Location specified'), |
289 | 194 | translate('SongsPlugin.ExportWizardForm', 'You need to specify a directory.')) | 188 | translate('SongsPlugin.ExportWizardForm', 'You need to specify a directory.')) |
290 | 195 | return False | 189 | return False |
291 | 190 | Settings().setValue('songs/last directory export', self.output_directory_path_edit.path) | ||
292 | 196 | return True | 191 | return True |
293 | 197 | elif self.currentPage() == self.progress_page: | 192 | elif self.currentPage() == self.progress_page: |
294 | 198 | self.available_list_widget.clear() | 193 | self.available_list_widget.clear() |
295 | @@ -211,8 +206,6 @@ | |||
296 | 211 | self.finish_button.setVisible(False) | 206 | self.finish_button.setVisible(False) |
297 | 212 | self.cancel_button.setVisible(True) | 207 | self.cancel_button.setVisible(True) |
298 | 213 | self.available_list_widget.clear() | 208 | self.available_list_widget.clear() |
299 | 214 | self.selected_list_widget.clear() | ||
300 | 215 | self.directory_line_edit.clear() | ||
301 | 216 | self.search_line_edit.clear() | 209 | self.search_line_edit.clear() |
302 | 217 | # Load the list of songs. | 210 | # Load the list of songs. |
303 | 218 | self.application.set_busy_cursor() | 211 | self.application.set_busy_cursor() |
304 | @@ -247,7 +240,7 @@ | |||
305 | 247 | song.data(QtCore.Qt.UserRole) | 240 | song.data(QtCore.Qt.UserRole) |
306 | 248 | for song in find_list_widget_items(self.selected_list_widget) | 241 | for song in find_list_widget_items(self.selected_list_widget) |
307 | 249 | ] | 242 | ] |
309 | 250 | exporter = OpenLyricsExport(self, songs, self.directory_line_edit.text()) | 243 | exporter = OpenLyricsExport(self, songs, self.output_directory_path_edit.path) |
310 | 251 | try: | 244 | try: |
311 | 252 | if exporter.do_export(): | 245 | if exporter.do_export(): |
312 | 253 | self.progress_label.setText( | 246 | self.progress_label.setText( |
313 | @@ -291,15 +284,6 @@ | |||
314 | 291 | if not item.isHidden(): | 284 | if not item.isHidden(): |
315 | 292 | item.setCheckState(QtCore.Qt.Checked) | 285 | item.setCheckState(QtCore.Qt.Checked) |
316 | 293 | 286 | ||
317 | 294 | def on_directory_button_clicked(self): | ||
318 | 295 | """ | ||
319 | 296 | Called when the *directory_button* was clicked. Opens a dialog and writes | ||
320 | 297 | the path to *directory_line_edit*. | ||
321 | 298 | """ | ||
322 | 299 | self.get_folder( | ||
323 | 300 | translate('SongsPlugin.ExportWizardForm', 'Select Destination Folder'), | ||
324 | 301 | self.directory_line_edit, 'last directory export') | ||
325 | 302 | |||
326 | 303 | 287 | ||
327 | 304 | def find_list_widget_items(list_widget, text=''): | 288 | def find_list_widget_items(list_widget, text=''): |
328 | 305 | """ | 289 | """ |
329 | 306 | 290 | ||
330 | === modified file 'openlp/plugins/songs/forms/songimportform.py' | |||
331 | --- openlp/plugins/songs/forms/songimportform.py 2017-08-26 15:06:11 +0000 | |||
332 | +++ openlp/plugins/songs/forms/songimportform.py 2017-09-30 23:24:21 +0000 | |||
333 | @@ -22,15 +22,13 @@ | |||
334 | 22 | """ | 22 | """ |
335 | 23 | The song import functions for OpenLP. | 23 | The song import functions for OpenLP. |
336 | 24 | """ | 24 | """ |
337 | 25 | import codecs | ||
338 | 26 | import logging | 25 | import logging |
339 | 27 | import os | ||
340 | 28 | 26 | ||
341 | 29 | from PyQt5 import QtCore, QtWidgets | 27 | from PyQt5 import QtCore, QtWidgets |
342 | 30 | 28 | ||
343 | 31 | from openlp.core.common import RegistryProperties, Settings, UiStrings, translate | 29 | from openlp.core.common import RegistryProperties, Settings, UiStrings, translate |
344 | 32 | from openlp.core.common.path import path_to_str, str_to_path | ||
345 | 33 | from openlp.core.lib.ui import critical_error_message_box | 30 | from openlp.core.lib.ui import critical_error_message_box |
346 | 31 | from openlp.core.ui.lib import PathEdit, PathType | ||
347 | 34 | from openlp.core.ui.lib.filedialog import FileDialog | 32 | from openlp.core.ui.lib.filedialog import FileDialog |
348 | 35 | from openlp.core.ui.lib.wizard import OpenLPWizard, WizardStrings | 33 | from openlp.core.ui.lib.wizard import OpenLPWizard, WizardStrings |
349 | 36 | from openlp.plugins.songs.lib.importer import SongFormat, SongFormatSelect | 34 | from openlp.plugins.songs.lib.importer import SongFormat, SongFormatSelect |
350 | @@ -93,9 +91,7 @@ | |||
351 | 93 | self.format_widgets[song_format]['addButton'].clicked.connect(self.on_add_button_clicked) | 91 | self.format_widgets[song_format]['addButton'].clicked.connect(self.on_add_button_clicked) |
352 | 94 | self.format_widgets[song_format]['removeButton'].clicked.connect(self.on_remove_button_clicked) | 92 | self.format_widgets[song_format]['removeButton'].clicked.connect(self.on_remove_button_clicked) |
353 | 95 | else: | 93 | else: |
357 | 96 | self.format_widgets[song_format]['browseButton'].clicked.connect(self.on_browse_button_clicked) | 94 | self.format_widgets[song_format]['path_edit'].pathChanged.connect(self.on_path_edit_path_changed) |
355 | 97 | self.format_widgets[song_format]['file_path_edit'].textChanged.\ | ||
356 | 98 | connect(self.on_filepath_edit_text_changed) | ||
358 | 99 | 95 | ||
359 | 100 | def add_custom_pages(self): | 96 | def add_custom_pages(self): |
360 | 101 | """ | 97 | """ |
361 | @@ -155,7 +151,6 @@ | |||
362 | 155 | self.format_widgets[format_list]['removeButton'].setText( | 151 | self.format_widgets[format_list]['removeButton'].setText( |
363 | 156 | translate('SongsPlugin.ImportWizardForm', 'Remove File(s)')) | 152 | translate('SongsPlugin.ImportWizardForm', 'Remove File(s)')) |
364 | 157 | else: | 153 | else: |
365 | 158 | self.format_widgets[format_list]['browseButton'].setText(UiStrings().Browse) | ||
366 | 159 | f_label = 'Filename:' | 154 | f_label = 'Filename:' |
367 | 160 | if select_mode == SongFormatSelect.SingleFolder: | 155 | if select_mode == SongFormatSelect.SingleFolder: |
368 | 161 | f_label = 'Folder:' | 156 | f_label = 'Folder:' |
369 | @@ -172,16 +167,11 @@ | |||
370 | 172 | self.error_save_to_button.setText(translate('SongsPlugin.ImportWizardForm', 'Save to File')) | 167 | self.error_save_to_button.setText(translate('SongsPlugin.ImportWizardForm', 'Save to File')) |
371 | 173 | # Align all QFormLayouts towards each other. | 168 | # Align all QFormLayouts towards each other. |
372 | 174 | formats = [f for f in SongFormat.get_format_list() if 'filepathLabel' in self.format_widgets[f]] | 169 | formats = [f for f in SongFormat.get_format_list() if 'filepathLabel' in self.format_widgets[f]] |
374 | 175 | labels = [self.format_widgets[f]['filepathLabel'] for f in formats] | 170 | labels = [self.format_widgets[f]['filepathLabel'] for f in formats] + [self.format_label] |
375 | 176 | # Get max width of all labels | 171 | # Get max width of all labels |
384 | 177 | max_label_width = max(self.format_label.minimumSizeHint().width(), | 172 | max_label_width = max(labels, key=lambda label: label.minimumSizeHint().width()).minimumSizeHint().width() |
385 | 178 | max([label.minimumSizeHint().width() for label in labels])) | 173 | for label in labels: |
386 | 179 | self.format_spacer.changeSize(max_label_width, 0, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) | 174 | label.setFixedWidth(max_label_width) |
379 | 180 | spacers = [self.format_widgets[f]['filepathSpacer'] for f in formats] | ||
380 | 181 | for index, spacer in enumerate(spacers): | ||
381 | 182 | spacer.changeSize( | ||
382 | 183 | max_label_width - labels[index].minimumSizeHint().width(), 0, | ||
383 | 184 | QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) | ||
387 | 185 | # Align descriptionLabels with rest of layout | 175 | # Align descriptionLabels with rest of layout |
388 | 186 | for format_list in SongFormat.get_format_list(): | 176 | for format_list in SongFormat.get_format_list(): |
389 | 187 | if SongFormat.get(format_list, 'descriptionText') is not None: | 177 | if SongFormat.get(format_list, 'descriptionText') is not None: |
390 | @@ -209,13 +199,13 @@ | |||
391 | 209 | Settings().setValue('songs/last import type', this_format) | 199 | Settings().setValue('songs/last import type', this_format) |
392 | 210 | select_mode, class_, error_msg = SongFormat.get(this_format, 'selectMode', 'class', 'invalidSourceMsg') | 200 | select_mode, class_, error_msg = SongFormat.get(this_format, 'selectMode', 'class', 'invalidSourceMsg') |
393 | 211 | if select_mode == SongFormatSelect.MultipleFiles: | 201 | if select_mode == SongFormatSelect.MultipleFiles: |
395 | 212 | import_source = self.get_list_of_files(self.format_widgets[this_format]['file_list_widget']) | 202 | import_source = self.get_list_of_paths(self.format_widgets[this_format]['file_list_widget']) |
396 | 213 | error_title = UiStrings().IFSp | 203 | error_title = UiStrings().IFSp |
397 | 214 | focus_button = self.format_widgets[this_format]['addButton'] | 204 | focus_button = self.format_widgets[this_format]['addButton'] |
398 | 215 | else: | 205 | else: |
400 | 216 | import_source = self.format_widgets[this_format]['file_path_edit'].text() | 206 | import_source = self.format_widgets[this_format]['path_edit'].path |
401 | 217 | error_title = (UiStrings().IFSs if select_mode == SongFormatSelect.SingleFile else UiStrings().IFdSs) | 207 | error_title = (UiStrings().IFSs if select_mode == SongFormatSelect.SingleFile else UiStrings().IFdSs) |
403 | 218 | focus_button = self.format_widgets[this_format]['browseButton'] | 208 | focus_button = self.format_widgets[this_format]['path_edit'] |
404 | 219 | if not class_.is_valid_source(import_source): | 209 | if not class_.is_valid_source(import_source): |
405 | 220 | critical_error_message_box(error_title, error_msg) | 210 | critical_error_message_box(error_title, error_msg) |
406 | 221 | focus_button.setFocus() | 211 | focus_button.setFocus() |
407 | @@ -238,20 +228,23 @@ | |||
408 | 238 | if filters: | 228 | if filters: |
409 | 239 | filters += ';;' | 229 | filters += ';;' |
410 | 240 | filters += '{text} (*)'.format(text=UiStrings().AllFiles) | 230 | filters += '{text} (*)'.format(text=UiStrings().AllFiles) |
413 | 241 | file_paths, selected_filter = FileDialog.getOpenFileNames( | 231 | file_paths, filter_used = FileDialog.getOpenFileNames( |
414 | 242 | self, title, Settings().value(self.plugin.settings_section + '/last directory import'), filters) | 232 | self, title, |
415 | 233 | Settings().value(self.plugin.settings_section + '/last directory import'), filters) | ||
416 | 234 | for file_path in file_paths: | ||
417 | 235 | list_item = QtWidgets.QListWidgetItem(str(file_path)) | ||
418 | 236 | list_item.setData(QtCore.Qt.UserRole, file_path) | ||
419 | 237 | listbox.addItem(list_item) | ||
420 | 243 | if file_paths: | 238 | if file_paths: |
421 | 244 | file_names = [path_to_str(file_path) for file_path in file_paths] | ||
422 | 245 | listbox.addItems(file_names) | ||
423 | 246 | Settings().setValue(self.plugin.settings_section + '/last directory import', file_paths[0].parent) | 239 | Settings().setValue(self.plugin.settings_section + '/last directory import', file_paths[0].parent) |
424 | 247 | 240 | ||
426 | 248 | def get_list_of_files(self, list_box): | 241 | def get_list_of_paths(self, list_box): |
427 | 249 | """ | 242 | """ |
428 | 250 | Return a list of file from the list_box | 243 | Return a list of file from the list_box |
429 | 251 | 244 | ||
430 | 252 | :param list_box: The source list box | 245 | :param list_box: The source list box |
431 | 253 | """ | 246 | """ |
433 | 254 | return [list_box.item(i).text() for i in range(list_box.count())] | 247 | return [list_box.item(i).data(QtCore.Qt.UserRole) for i in range(list_box.count())] |
434 | 255 | 248 | ||
435 | 256 | def remove_selected_items(self, list_box): | 249 | def remove_selected_items(self, list_box): |
436 | 257 | """ | 250 | """ |
437 | @@ -263,20 +256,6 @@ | |||
438 | 263 | item = list_box.takeItem(list_box.row(item)) | 256 | item = list_box.takeItem(list_box.row(item)) |
439 | 264 | del item | 257 | del item |
440 | 265 | 258 | ||
441 | 266 | def on_browse_button_clicked(self): | ||
442 | 267 | """ | ||
443 | 268 | Browse for files or a directory. | ||
444 | 269 | """ | ||
445 | 270 | this_format = self.current_format | ||
446 | 271 | select_mode, format_name, ext_filter = SongFormat.get(this_format, 'selectMode', 'name', 'filter') | ||
447 | 272 | file_path_edit = self.format_widgets[this_format]['file_path_edit'] | ||
448 | 273 | if select_mode == SongFormatSelect.SingleFile: | ||
449 | 274 | self.get_file_name(WizardStrings.OpenTypeFile.format(file_type=format_name), | ||
450 | 275 | file_path_edit, 'last directory import', ext_filter) | ||
451 | 276 | elif select_mode == SongFormatSelect.SingleFolder: | ||
452 | 277 | self.get_folder( | ||
453 | 278 | WizardStrings.OpenTypeFolder.format(folder_name=format_name), file_path_edit, 'last directory import') | ||
454 | 279 | |||
455 | 280 | def on_add_button_clicked(self): | 259 | def on_add_button_clicked(self): |
456 | 281 | """ | 260 | """ |
457 | 282 | Add a file or directory. | 261 | Add a file or directory. |
458 | @@ -296,7 +275,7 @@ | |||
459 | 296 | self.remove_selected_items(self.format_widgets[self.current_format]['file_list_widget']) | 275 | self.remove_selected_items(self.format_widgets[self.current_format]['file_list_widget']) |
460 | 297 | self.source_page.completeChanged.emit() | 276 | self.source_page.completeChanged.emit() |
461 | 298 | 277 | ||
463 | 299 | def on_filepath_edit_text_changed(self): | 278 | def on_path_edit_path_changed(self): |
464 | 300 | """ | 279 | """ |
465 | 301 | Called when the content of the Filename/Folder edit box changes. | 280 | Called when the content of the Filename/Folder edit box changes. |
466 | 302 | """ | 281 | """ |
467 | @@ -317,8 +296,6 @@ | |||
468 | 317 | select_mode = SongFormat.get(format_list, 'selectMode') | 296 | select_mode = SongFormat.get(format_list, 'selectMode') |
469 | 318 | if select_mode == SongFormatSelect.MultipleFiles: | 297 | if select_mode == SongFormatSelect.MultipleFiles: |
470 | 319 | self.format_widgets[format_list]['file_list_widget'].clear() | 298 | self.format_widgets[format_list]['file_list_widget'].clear() |
471 | 320 | else: | ||
472 | 321 | self.format_widgets[format_list]['file_path_edit'].setText('') | ||
473 | 322 | self.error_report_text_edit.clear() | 299 | self.error_report_text_edit.clear() |
474 | 323 | self.error_report_text_edit.setHidden(True) | 300 | self.error_report_text_edit.setHidden(True) |
475 | 324 | self.error_copy_to_button.setHidden(True) | 301 | self.error_copy_to_button.setHidden(True) |
476 | @@ -341,14 +318,14 @@ | |||
477 | 341 | select_mode = SongFormat.get(source_format, 'selectMode') | 318 | select_mode = SongFormat.get(source_format, 'selectMode') |
478 | 342 | if select_mode == SongFormatSelect.SingleFile: | 319 | if select_mode == SongFormatSelect.SingleFile: |
479 | 343 | importer = self.plugin.import_songs(source_format, | 320 | importer = self.plugin.import_songs(source_format, |
481 | 344 | filename=self.format_widgets[source_format]['file_path_edit'].text()) | 321 | file_path=self.format_widgets[source_format]['path_edit'].path) |
482 | 345 | elif select_mode == SongFormatSelect.SingleFolder: | 322 | elif select_mode == SongFormatSelect.SingleFolder: |
483 | 346 | importer = self.plugin.import_songs(source_format, | 323 | importer = self.plugin.import_songs(source_format, |
485 | 347 | folder=self.format_widgets[source_format]['file_path_edit'].text()) | 324 | folder_path=self.format_widgets[source_format]['path_edit'].path) |
486 | 348 | else: | 325 | else: |
487 | 349 | importer = self.plugin.import_songs( | 326 | importer = self.plugin.import_songs( |
488 | 350 | source_format, | 327 | source_format, |
490 | 351 | filenames=self.get_list_of_files(self.format_widgets[source_format]['file_list_widget'])) | 328 | file_paths=self.get_list_of_paths(self.format_widgets[source_format]['file_list_widget'])) |
491 | 352 | importer.do_import() | 329 | importer.do_import() |
492 | 353 | self.progress_label.setText(WizardStrings.FinishedImport) | 330 | self.progress_label.setText(WizardStrings.FinishedImport) |
493 | 354 | 331 | ||
494 | @@ -366,18 +343,17 @@ | |||
495 | 366 | """ | 343 | """ |
496 | 367 | file_path, filter_used = FileDialog.getSaveFileName( | 344 | file_path, filter_used = FileDialog.getSaveFileName( |
497 | 368 | self, Settings().value(self.plugin.settings_section + '/last directory import')) | 345 | self, Settings().value(self.plugin.settings_section + '/last directory import')) |
499 | 369 | if not file_path: | 346 | if file_path is None: |
500 | 370 | return | 347 | return |
503 | 371 | with file_path.open('w', encoding='utf-8') as report_file: | 348 | file_path.write_text(self.error_report_text_edit.toPlainText(), encoding='utf-8') |
502 | 372 | report_file.write(self.error_report_text_edit.toPlainText()) | ||
504 | 373 | 349 | ||
505 | 374 | def add_file_select_item(self): | 350 | def add_file_select_item(self): |
506 | 375 | """ | 351 | """ |
507 | 376 | Add a file selection page. | 352 | Add a file selection page. |
508 | 377 | """ | 353 | """ |
509 | 378 | this_format = self.current_format | 354 | this_format = self.current_format |
512 | 379 | prefix, can_disable, description_text, select_mode = \ | 355 | format_name, prefix, can_disable, description_text, select_mode, filters = \ |
513 | 380 | SongFormat.get(this_format, 'prefix', 'canDisable', 'descriptionText', 'selectMode') | 356 | SongFormat.get(this_format, 'name', 'prefix', 'canDisable', 'descriptionText', 'selectMode', 'filter') |
514 | 381 | page = QtWidgets.QWidget() | 357 | page = QtWidgets.QWidget() |
515 | 382 | page.setObjectName(prefix + 'Page') | 358 | page.setObjectName(prefix + 'Page') |
516 | 383 | if can_disable: | 359 | if can_disable: |
517 | @@ -403,26 +379,23 @@ | |||
518 | 403 | if select_mode == SongFormatSelect.SingleFile or select_mode == SongFormatSelect.SingleFolder: | 379 | if select_mode == SongFormatSelect.SingleFile or select_mode == SongFormatSelect.SingleFolder: |
519 | 404 | file_path_layout = QtWidgets.QHBoxLayout() | 380 | file_path_layout = QtWidgets.QHBoxLayout() |
520 | 405 | file_path_layout.setObjectName(prefix + '_file_path_layout') | 381 | file_path_layout.setObjectName(prefix + '_file_path_layout') |
521 | 406 | file_path_layout.setContentsMargins(0, self.format_v_spacing, 0, 0) | ||
522 | 407 | file_path_label = QtWidgets.QLabel(import_widget) | 382 | file_path_label = QtWidgets.QLabel(import_widget) |
523 | 408 | file_path_label.setObjectName(prefix + 'FilepathLabel') | ||
524 | 409 | file_path_layout.addWidget(file_path_label) | 383 | file_path_layout.addWidget(file_path_label) |
534 | 410 | file_path_spacer = QtWidgets.QSpacerItem(0, 0, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) | 384 | if select_mode == SongFormatSelect.SingleFile: |
535 | 411 | file_path_layout.addSpacerItem(file_path_spacer) | 385 | path_type = PathType.Files |
536 | 412 | file_path_edit = QtWidgets.QLineEdit(import_widget) | 386 | dialog_caption = WizardStrings.OpenTypeFile.format(file_type=format_name) |
537 | 413 | file_path_edit.setObjectName(prefix + '_file_path_edit') | 387 | else: |
538 | 414 | file_path_layout.addWidget(file_path_edit) | 388 | path_type = PathType.Directories |
539 | 415 | browse_button = QtWidgets.QToolButton(import_widget) | 389 | dialog_caption = WizardStrings.OpenTypeFolder.format(folder_name=format_name) |
540 | 416 | browse_button.setIcon(self.open_icon) | 390 | path_edit = PathEdit( |
541 | 417 | browse_button.setObjectName(prefix + 'BrowseButton') | 391 | parent=import_widget, path_type=path_type, dialog_caption=dialog_caption, show_revert=False) |
542 | 418 | file_path_layout.addWidget(browse_button) | 392 | path_edit.filters = path_edit.filters + filters |
543 | 393 | path_edit.path = Settings().value(self.plugin.settings_section + '/last directory import') | ||
544 | 394 | file_path_layout.addWidget(path_edit) | ||
545 | 419 | import_layout.addLayout(file_path_layout) | 395 | import_layout.addLayout(file_path_layout) |
546 | 420 | import_layout.addSpacerItem(self.stack_spacer) | 396 | import_layout.addSpacerItem(self.stack_spacer) |
547 | 421 | self.format_widgets[this_format]['filepathLabel'] = file_path_label | 397 | self.format_widgets[this_format]['filepathLabel'] = file_path_label |
552 | 422 | self.format_widgets[this_format]['filepathSpacer'] = file_path_spacer | 398 | self.format_widgets[this_format]['path_edit'] = path_edit |
549 | 423 | self.format_widgets[this_format]['file_path_layout'] = file_path_layout | ||
550 | 424 | self.format_widgets[this_format]['file_path_edit'] = file_path_edit | ||
551 | 425 | self.format_widgets[this_format]['browseButton'] = browse_button | ||
553 | 426 | elif select_mode == SongFormatSelect.MultipleFiles: | 399 | elif select_mode == SongFormatSelect.MultipleFiles: |
554 | 427 | file_list_widget = QtWidgets.QListWidget(import_widget) | 400 | file_list_widget = QtWidgets.QListWidget(import_widget) |
555 | 428 | file_list_widget.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection) | 401 | file_list_widget.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection) |
556 | @@ -496,6 +469,8 @@ | |||
557 | 496 | * or if SingleFolder mode, the specified folder exists | 469 | * or if SingleFolder mode, the specified folder exists |
558 | 497 | 470 | ||
559 | 498 | When this method returns True, the wizard's Next button is enabled. | 471 | When this method returns True, the wizard's Next button is enabled. |
560 | 472 | |||
561 | 473 | :rtype: bool | ||
562 | 499 | """ | 474 | """ |
563 | 500 | wizard = self.wizard() | 475 | wizard = self.wizard() |
564 | 501 | this_format = wizard.current_format | 476 | this_format = wizard.current_format |
565 | @@ -505,10 +480,10 @@ | |||
566 | 505 | if wizard.format_widgets[this_format]['file_list_widget'].count() > 0: | 480 | if wizard.format_widgets[this_format]['file_list_widget'].count() > 0: |
567 | 506 | return True | 481 | return True |
568 | 507 | else: | 482 | else: |
570 | 508 | file_path = str(wizard.format_widgets[this_format]['file_path_edit'].text()) | 483 | file_path = wizard.format_widgets[this_format]['path_edit'].path |
571 | 509 | if file_path: | 484 | if file_path: |
573 | 510 | if select_mode == SongFormatSelect.SingleFile and os.path.isfile(file_path): | 485 | if select_mode == SongFormatSelect.SingleFile and file_path.is_file(): |
574 | 511 | return True | 486 | return True |
576 | 512 | elif select_mode == SongFormatSelect.SingleFolder and os.path.isdir(file_path): | 487 | elif select_mode == SongFormatSelect.SingleFolder and file_path.is_dir(): |
577 | 513 | return True | 488 | return True |
578 | 514 | return False | 489 | return False |
579 | 515 | 490 | ||
580 | === modified file 'openlp/plugins/songs/lib/__init__.py' | |||
581 | --- openlp/plugins/songs/lib/__init__.py 2017-08-03 17:54:40 +0000 | |||
582 | +++ openlp/plugins/songs/lib/__init__.py 2017-09-30 23:24:21 +0000 | |||
583 | @@ -534,13 +534,13 @@ | |||
584 | 534 | media_files = song_plugin.manager.get_all_objects(MediaFile, MediaFile.song_id == song_id) | 534 | media_files = song_plugin.manager.get_all_objects(MediaFile, MediaFile.song_id == song_id) |
585 | 535 | for media_file in media_files: | 535 | for media_file in media_files: |
586 | 536 | try: | 536 | try: |
588 | 537 | os.remove(media_file.file_name) | 537 | media_file.file_path.unlink() |
589 | 538 | except OSError: | 538 | except OSError: |
591 | 539 | log.exception('Could not remove file: {name}'.format(name=media_file.file_name)) | 539 | log.exception('Could not remove file: {name}'.format(name=media_file.file_path)) |
592 | 540 | try: | 540 | try: |
596 | 541 | save_path = os.path.join(str(AppLocation.get_section_data_path(song_plugin.name)), 'audio', str(song_id)) | 541 | save_path = AppLocation.get_section_data_path(song_plugin.name) / 'audio' / str(song_id) |
597 | 542 | if os.path.exists(save_path): | 542 | if save_path.exists(): |
598 | 543 | os.rmdir(save_path) | 543 | save_path.rmdir() |
599 | 544 | except OSError: | 544 | except OSError: |
600 | 545 | log.exception('Could not remove directory: {path}'.format(path=save_path)) | 545 | log.exception('Could not remove directory: {path}'.format(path=save_path)) |
601 | 546 | song_plugin.manager.delete_object(Song, song_id) | 546 | song_plugin.manager.delete_object(Song, song_id) |
602 | 547 | 547 | ||
603 | === modified file 'openlp/plugins/songs/lib/db.py' | |||
604 | --- openlp/plugins/songs/lib/db.py 2016-12-31 11:01:36 +0000 | |||
605 | +++ openlp/plugins/songs/lib/db.py 2017-09-30 23:24:21 +0000 | |||
606 | @@ -23,14 +23,15 @@ | |||
607 | 23 | The :mod:`db` module provides the database and schema that is the backend for | 23 | The :mod:`db` module provides the database and schema that is the backend for |
608 | 24 | the Songs plugin | 24 | the Songs plugin |
609 | 25 | """ | 25 | """ |
611 | 26 | 26 | from contextlib import suppress | |
612 | 27 | from sqlalchemy import Column, ForeignKey, Table, types | 27 | from sqlalchemy import Column, ForeignKey, Table, types |
613 | 28 | from sqlalchemy.orm import mapper, relation, reconstructor | 28 | from sqlalchemy.orm import mapper, relation, reconstructor |
614 | 29 | from sqlalchemy.sql.expression import func, text | 29 | from sqlalchemy.sql.expression import func, text |
615 | 30 | 30 | ||
617 | 31 | from openlp.core.lib.db import BaseModel, init_db | 31 | from openlp.core.common.applocation import AppLocation |
618 | 32 | from openlp.core.common.languagemanager import get_natural_key | 32 | from openlp.core.common.languagemanager import get_natural_key |
619 | 33 | from openlp.core.lib import translate | 33 | from openlp.core.lib import translate |
620 | 34 | from openlp.core.lib.db import BaseModel, PathType, init_db | ||
621 | 34 | 35 | ||
622 | 35 | 36 | ||
623 | 36 | class Author(BaseModel): | 37 | class Author(BaseModel): |
624 | @@ -238,7 +239,7 @@ | |||
625 | 238 | 239 | ||
626 | 239 | **media_files Table** | 240 | **media_files Table** |
627 | 240 | * id | 241 | * id |
629 | 241 | * file_name | 242 | * _file_path |
630 | 242 | * type | 243 | * type |
631 | 243 | 244 | ||
632 | 244 | **song_books Table** | 245 | **song_books Table** |
633 | @@ -305,7 +306,7 @@ | |||
634 | 305 | 'media_files', metadata, | 306 | 'media_files', metadata, |
635 | 306 | Column('id', types.Integer(), primary_key=True), | 307 | Column('id', types.Integer(), primary_key=True), |
636 | 307 | Column('song_id', types.Integer(), ForeignKey('songs.id'), default=None), | 308 | Column('song_id', types.Integer(), ForeignKey('songs.id'), default=None), |
638 | 308 | Column('file_name', types.Unicode(255), nullable=False), | 309 | Column('file_path', PathType, nullable=False), |
639 | 309 | Column('type', types.Unicode(64), nullable=False, default='audio'), | 310 | Column('type', types.Unicode(64), nullable=False, default='audio'), |
640 | 310 | Column('weight', types.Integer(), default=0) | 311 | Column('weight', types.Integer(), default=0) |
641 | 311 | ) | 312 | ) |
642 | 312 | 313 | ||
643 | === modified file 'openlp/plugins/songs/lib/importers/cclifile.py' | |||
644 | --- openlp/plugins/songs/lib/importers/cclifile.py 2016-12-31 11:01:36 +0000 | |||
645 | +++ openlp/plugins/songs/lib/importers/cclifile.py 2017-09-30 23:24:21 +0000 | |||
646 | @@ -19,11 +19,9 @@ | |||
647 | 19 | # with this program; if not, write to the Free Software Foundation, Inc., 59 # | 19 | # with this program; if not, write to the Free Software Foundation, Inc., 59 # |
648 | 20 | # Temple Place, Suite 330, Boston, MA 02111-1307 USA # | 20 | # Temple Place, Suite 330, Boston, MA 02111-1307 USA # |
649 | 21 | ############################################################################### | 21 | ############################################################################### |
650 | 22 | |||
651 | 23 | import logging | ||
652 | 24 | import os | ||
653 | 25 | import chardet | 22 | import chardet |
654 | 26 | import codecs | 23 | import codecs |
655 | 24 | import logging | ||
656 | 27 | 25 | ||
657 | 28 | from openlp.core.lib import translate | 26 | from openlp.core.lib import translate |
658 | 29 | from openlp.plugins.songs.lib import VerseType | 27 | from openlp.plugins.songs.lib import VerseType |
659 | @@ -48,7 +46,7 @@ | |||
660 | 48 | :param manager: The song manager for the running OpenLP installation. | 46 | :param manager: The song manager for the running OpenLP installation. |
661 | 49 | :param kwargs: The files to be imported. | 47 | :param kwargs: The files to be imported. |
662 | 50 | """ | 48 | """ |
664 | 51 | super(CCLIFileImport, self).__init__(manager, **kwargs) | 49 | super().__init__(manager, **kwargs) |
665 | 52 | 50 | ||
666 | 53 | def do_import(self): | 51 | def do_import(self): |
667 | 54 | """ | 52 | """ |
668 | @@ -56,37 +54,35 @@ | |||
669 | 56 | """ | 54 | """ |
670 | 57 | log.debug('Starting CCLI File Import') | 55 | log.debug('Starting CCLI File Import') |
671 | 58 | self.import_wizard.progress_bar.setMaximum(len(self.import_source)) | 56 | self.import_wizard.progress_bar.setMaximum(len(self.import_source)) |
686 | 59 | for filename in self.import_source: | 57 | for file_path in self.import_source: |
687 | 60 | filename = str(filename) | 58 | log.debug('Importing CCLI File: {name}'.format(name=file_path)) |
688 | 61 | log.debug('Importing CCLI File: {name}'.format(name=filename)) | 59 | if file_path.is_file(): |
689 | 62 | if os.path.isfile(filename): | 60 | with file_path.open('rb') as detect_file: |
690 | 63 | detect_file = open(filename, 'rb') | 61 | detect_content = detect_file.read(2048) |
691 | 64 | detect_content = detect_file.read(2048) | 62 | try: |
692 | 65 | try: | 63 | str(detect_content, 'utf-8') |
693 | 66 | str(detect_content, 'utf-8') | 64 | details = {'confidence': 1, 'encoding': 'utf-8'} |
694 | 67 | details = {'confidence': 1, 'encoding': 'utf-8'} | 65 | except UnicodeDecodeError: |
695 | 68 | except UnicodeDecodeError: | 66 | details = chardet.detect(detect_content) |
696 | 69 | details = chardet.detect(detect_content) | 67 | in_file = codecs.open(str(file_path), 'r', details['encoding']) |
697 | 70 | detect_file.close() | 68 | if not in_file.read(1) == '\ufeff': |
684 | 71 | infile = codecs.open(filename, 'r', details['encoding']) | ||
685 | 72 | if not infile.read(1) == '\ufeff': | ||
698 | 73 | # not UTF or no BOM was found | 69 | # not UTF or no BOM was found |
705 | 74 | infile.seek(0) | 70 | in_file.seek(0) |
706 | 75 | lines = infile.readlines() | 71 | lines = in_file.readlines() |
707 | 76 | infile.close() | 72 | in_file.close() |
708 | 77 | ext = os.path.splitext(filename)[1] | 73 | ext = file_path.suffix.lower() |
709 | 78 | if ext.lower() == '.usr' or ext.lower() == '.bin': | 74 | if ext == '.usr' or ext == '.bin': |
710 | 79 | log.info('SongSelect USR format file found: {name}'.format(name=filename)) | 75 | log.info('SongSelect USR format file found: {name}'.format(name=file_path)) |
711 | 80 | if not self.do_import_usr_file(lines): | 76 | if not self.do_import_usr_file(lines): |
715 | 81 | self.log_error(filename) | 77 | self.log_error(file_path) |
716 | 82 | elif ext.lower() == '.txt': | 78 | elif ext == '.txt': |
717 | 83 | log.info('SongSelect TEXT format file found: {name}'.format(name=filename)) | 79 | log.info('SongSelect TEXT format file found: {name}'.format(name=file_path)) |
718 | 84 | if not self.do_import_txt_file(lines): | 80 | if not self.do_import_txt_file(lines): |
720 | 85 | self.log_error(filename) | 81 | self.log_error(file_path) |
721 | 86 | else: | 82 | else: |
725 | 87 | self.log_error(filename, translate('SongsPlugin.CCLIFileImport', 'The file does not have a valid ' | 83 | self.log_error(file_path, translate('SongsPlugin.CCLIFileImport', |
726 | 88 | 'extension.')) | 84 | 'The file does not have a valid extension.')) |
727 | 89 | log.info('Extension {name} is not valid'.format(name=filename)) | 85 | log.info('Extension {name} is not valid'.format(name=file_path)) |
728 | 90 | if self.stop_import_flag: | 86 | if self.stop_import_flag: |
729 | 91 | return | 87 | return |
730 | 92 | 88 | ||
731 | 93 | 89 | ||
732 | === modified file 'openlp/plugins/songs/lib/importers/chordpro.py' | |||
733 | --- openlp/plugins/songs/lib/importers/chordpro.py 2017-02-26 21:14:49 +0000 | |||
734 | +++ openlp/plugins/songs/lib/importers/chordpro.py 2017-09-30 23:24:21 +0000 | |||
735 | @@ -47,12 +47,11 @@ | |||
736 | 47 | """ | 47 | """ |
737 | 48 | def do_import(self): | 48 | def do_import(self): |
738 | 49 | self.import_wizard.progress_bar.setMaximum(len(self.import_source)) | 49 | self.import_wizard.progress_bar.setMaximum(len(self.import_source)) |
740 | 50 | for filename in self.import_source: | 50 | for file_path in self.import_source: |
741 | 51 | if self.stop_import_flag: | 51 | if self.stop_import_flag: |
742 | 52 | return | 52 | return |
746 | 53 | song_file = open(filename, 'rt') | 53 | with file_path.open('rt') as song_file: |
747 | 54 | self.do_import_file(song_file) | 54 | self.do_import_file(song_file) |
745 | 55 | song_file.close() | ||
748 | 56 | 55 | ||
749 | 57 | def do_import_file(self, song_file): | 56 | def do_import_file(self, song_file): |
750 | 58 | """ | 57 | """ |
751 | 59 | 58 | ||
752 | === modified file 'openlp/plugins/songs/lib/importers/dreambeam.py' | |||
753 | --- openlp/plugins/songs/lib/importers/dreambeam.py 2016-12-31 11:01:36 +0000 | |||
754 | +++ openlp/plugins/songs/lib/importers/dreambeam.py 2017-09-30 23:24:21 +0000 | |||
755 | @@ -78,27 +78,29 @@ | |||
756 | 78 | 78 | ||
757 | 79 | def do_import(self): | 79 | def do_import(self): |
758 | 80 | """ | 80 | """ |
760 | 81 | Receive a single file or a list of files to import. | 81 | Receive a single file_path or a list of files to import. |
761 | 82 | """ | 82 | """ |
762 | 83 | if isinstance(self.import_source, list): | 83 | if isinstance(self.import_source, list): |
763 | 84 | self.import_wizard.progress_bar.setMaximum(len(self.import_source)) | 84 | self.import_wizard.progress_bar.setMaximum(len(self.import_source)) |
765 | 85 | for file in self.import_source: | 85 | for file_path in self.import_source: |
766 | 86 | if self.stop_import_flag: | 86 | if self.stop_import_flag: |
767 | 87 | return | 87 | return |
768 | 88 | self.set_defaults() | 88 | self.set_defaults() |
769 | 89 | parser = etree.XMLParser(remove_blank_text=True) | 89 | parser = etree.XMLParser(remove_blank_text=True) |
770 | 90 | try: | 90 | try: |
772 | 91 | parsed_file = etree.parse(open(file, 'r'), parser) | 91 | with file_path.open('r') as xml_file: |
773 | 92 | parsed_file = etree.parse(xml_file, parser) | ||
774 | 92 | except etree.XMLSyntaxError: | 93 | except etree.XMLSyntaxError: |
777 | 93 | log.exception('XML syntax error in file {name}'.format(name=file)) | 94 | log.exception('XML syntax error in file_path {name}'.format(name=file_path)) |
778 | 94 | self.log_error(file, SongStrings.XMLSyntaxError) | 95 | self.log_error(file_path, SongStrings.XMLSyntaxError) |
779 | 95 | continue | 96 | continue |
780 | 96 | xml = etree.tostring(parsed_file).decode() | 97 | xml = etree.tostring(parsed_file).decode() |
781 | 97 | song_xml = objectify.fromstring(xml) | 98 | song_xml = objectify.fromstring(xml) |
782 | 98 | if song_xml.tag != 'DreamSong': | 99 | if song_xml.tag != 'DreamSong': |
783 | 99 | self.log_error( | 100 | self.log_error( |
786 | 100 | file, | 101 | file_path, |
787 | 101 | translate('SongsPlugin.DreamBeamImport', 'Invalid DreamBeam song file. Missing DreamSong tag.')) | 102 | translate('SongsPlugin.DreamBeamImport', |
788 | 103 | 'Invalid DreamBeam song file_path. Missing DreamSong tag.')) | ||
789 | 102 | continue | 104 | continue |
790 | 103 | if hasattr(song_xml, 'Version'): | 105 | if hasattr(song_xml, 'Version'): |
791 | 104 | self.version = float(song_xml.Version.text) | 106 | self.version = float(song_xml.Version.text) |
792 | @@ -144,4 +146,4 @@ | |||
793 | 144 | else: | 146 | else: |
794 | 145 | self.parse_author(author_copyright) | 147 | self.parse_author(author_copyright) |
795 | 146 | if not self.finish(): | 148 | if not self.finish(): |
797 | 147 | self.log_error(file) | 149 | self.log_error(file_path) |
798 | 148 | 150 | ||
799 | === modified file 'openlp/plugins/songs/lib/importers/easyslides.py' | |||
800 | --- openlp/plugins/songs/lib/importers/easyslides.py 2017-01-12 21:31:01 +0000 | |||
801 | +++ openlp/plugins/songs/lib/importers/easyslides.py 2017-09-30 23:24:21 +0000 | |||
802 | @@ -47,7 +47,7 @@ | |||
803 | 47 | def do_import(self): | 47 | def do_import(self): |
804 | 48 | log.info('Importing EasySlides XML file {source}'.format(source=self.import_source)) | 48 | log.info('Importing EasySlides XML file {source}'.format(source=self.import_source)) |
805 | 49 | parser = etree.XMLParser(remove_blank_text=True, recover=True) | 49 | parser = etree.XMLParser(remove_blank_text=True, recover=True) |
807 | 50 | parsed_file = etree.parse(self.import_source, parser) | 50 | parsed_file = etree.parse(str(self.import_source), parser) |
808 | 51 | xml = etree.tostring(parsed_file).decode() | 51 | xml = etree.tostring(parsed_file).decode() |
809 | 52 | song_xml = objectify.fromstring(xml) | 52 | song_xml = objectify.fromstring(xml) |
810 | 53 | self.import_wizard.progress_bar.setMaximum(len(song_xml.Item)) | 53 | self.import_wizard.progress_bar.setMaximum(len(song_xml.Item)) |
811 | 54 | 54 | ||
812 | === modified file 'openlp/plugins/songs/lib/importers/easyworship.py' | |||
813 | --- openlp/plugins/songs/lib/importers/easyworship.py 2017-04-01 04:45:12 +0000 | |||
814 | +++ openlp/plugins/songs/lib/importers/easyworship.py 2017-09-30 23:24:21 +0000 | |||
815 | @@ -22,14 +22,15 @@ | |||
816 | 22 | """ | 22 | """ |
817 | 23 | The :mod:`easyworship` module provides the functionality for importing EasyWorship song databases into OpenLP. | 23 | The :mod:`easyworship` module provides the functionality for importing EasyWorship song databases into OpenLP. |
818 | 24 | """ | 24 | """ |
820 | 25 | 25 | import logging | |
821 | 26 | import os | 26 | import os |
822 | 27 | import re | ||
823 | 27 | import struct | 28 | import struct |
824 | 28 | import re | ||
825 | 29 | import zlib | 29 | import zlib |
827 | 30 | import logging | 30 | |
828 | 31 | import sqlite3 | 31 | import sqlite3 |
829 | 32 | 32 | ||
830 | 33 | from openlp.core.common.path import Path | ||
831 | 33 | from openlp.core.lib import translate | 34 | from openlp.core.lib import translate |
832 | 34 | from openlp.plugins.songs.lib import VerseType | 35 | from openlp.plugins.songs.lib import VerseType |
833 | 35 | from openlp.plugins.songs.lib import retrieve_windows_encoding, strip_rtf | 36 | from openlp.plugins.songs.lib import retrieve_windows_encoding, strip_rtf |
834 | @@ -76,9 +77,11 @@ | |||
835 | 76 | """ | 77 | """ |
836 | 77 | Determines the type of file to import and calls the appropiate method | 78 | Determines the type of file to import and calls the appropiate method |
837 | 78 | """ | 79 | """ |
839 | 79 | if self.import_source.lower().endswith('ews'): | 80 | self.import_source = Path(self.import_source) |
840 | 81 | ext = self.import_source.suffix.lower() | ||
841 | 82 | if ext == '.ews': | ||
842 | 80 | self.import_ews() | 83 | self.import_ews() |
844 | 81 | elif self.import_source.endswith('DB'): | 84 | elif ext == '.db': |
845 | 82 | self.import_db() | 85 | self.import_db() |
846 | 83 | else: | 86 | else: |
847 | 84 | self.import_sqlite_db() | 87 | self.import_sqlite_db() |
848 | @@ -91,11 +94,11 @@ | |||
849 | 91 | or here: http://wiki.openlp.org/Development:EasyWorship_EWS_Format | 94 | or here: http://wiki.openlp.org/Development:EasyWorship_EWS_Format |
850 | 92 | """ | 95 | """ |
851 | 93 | # Open ews file if it exists | 96 | # Open ews file if it exists |
853 | 94 | if not os.path.isfile(self.import_source): | 97 | if not self.import_source.is_file(): |
854 | 95 | log.debug('Given ews file does not exists.') | 98 | log.debug('Given ews file does not exists.') |
855 | 96 | return | 99 | return |
856 | 97 | # Make sure there is room for at least a header and one entry | 100 | # Make sure there is room for at least a header and one entry |
858 | 98 | if os.path.getsize(self.import_source) < 892: | 101 | if self.import_source.stat().st_size < 892: |
859 | 99 | log.debug('Given ews file is to small to contain valid data.') | 102 | log.debug('Given ews file is to small to contain valid data.') |
860 | 100 | return | 103 | return |
861 | 101 | # Take a stab at how text is encoded | 104 | # Take a stab at how text is encoded |
862 | @@ -104,7 +107,7 @@ | |||
863 | 104 | if not self.encoding: | 107 | if not self.encoding: |
864 | 105 | log.debug('No encoding set.') | 108 | log.debug('No encoding set.') |
865 | 106 | return | 109 | return |
867 | 107 | self.ews_file = open(self.import_source, 'rb') | 110 | self.ews_file = self.import_source.open('rb') |
868 | 108 | # EWS header, version '1.6'/' 3'/' 5': | 111 | # EWS header, version '1.6'/' 3'/' 5': |
869 | 109 | # Offset Field Data type Length Details | 112 | # Offset Field Data type Length Details |
870 | 110 | # -------------------------------------------------------------------------------------------------- | 113 | # -------------------------------------------------------------------------------------------------- |
871 | @@ -199,23 +202,22 @@ | |||
872 | 199 | Import the songs from the database | 202 | Import the songs from the database |
873 | 200 | """ | 203 | """ |
874 | 201 | # Open the DB and MB files if they exist | 204 | # Open the DB and MB files if they exist |
877 | 202 | import_source_mb = self.import_source.replace('.DB', '.MB') | 205 | import_source_mb = self.import_source.with_suffix('.MB') |
878 | 203 | if not os.path.isfile(self.import_source): | 206 | if not self.import_source.is_file(): |
879 | 204 | self.log_error(self.import_source, translate('SongsPlugin.EasyWorshipSongImport', | 207 | self.log_error(self.import_source, translate('SongsPlugin.EasyWorshipSongImport', |
880 | 205 | 'This file does not exist.')) | 208 | 'This file does not exist.')) |
881 | 206 | return | 209 | return |
883 | 207 | if not os.path.isfile(import_source_mb): | 210 | if not import_source_mb.is_file(): |
884 | 208 | self.log_error(self.import_source, translate('SongsPlugin.EasyWorshipSongImport', | 211 | self.log_error(self.import_source, translate('SongsPlugin.EasyWorshipSongImport', |
885 | 209 | 'Could not find the "Songs.MB" file. It must be in the same ' | 212 | 'Could not find the "Songs.MB" file. It must be in the same ' |
886 | 210 | 'folder as the "Songs.DB" file.')) | 213 | 'folder as the "Songs.DB" file.')) |
887 | 211 | return | 214 | return |
890 | 212 | db_size = os.path.getsize(self.import_source) | 215 | if self.import_source.stat().st_size < 0x800: |
889 | 213 | if db_size < 0x800: | ||
891 | 214 | self.log_error(self.import_source, translate('SongsPlugin.EasyWorshipSongImport', | 216 | self.log_error(self.import_source, translate('SongsPlugin.EasyWorshipSongImport', |
892 | 215 | 'This file is not a valid EasyWorship database.')) | 217 | 'This file is not a valid EasyWorship database.')) |
893 | 216 | return | 218 | return |
896 | 217 | db_file = open(self.import_source, 'rb') | 219 | db_file = self.import_source.open('rb') |
897 | 218 | self.memo_file = open(import_source_mb, 'rb') | 220 | self.memo_file = import_source_mb.open('rb') |
898 | 219 | # Don't accept files that are clearly not paradox files | 221 | # Don't accept files that are clearly not paradox files |
899 | 220 | record_size, header_size, block_size, first_block, num_fields = struct.unpack('<hhxb8xh17xh', db_file.read(35)) | 222 | record_size, header_size, block_size, first_block, num_fields = struct.unpack('<hhxb8xh17xh', db_file.read(35)) |
900 | 221 | if header_size != 0x800 or block_size < 1 or block_size > 4: | 223 | if header_size != 0x800 or block_size < 1 or block_size > 4: |
901 | @@ -340,52 +342,34 @@ | |||
902 | 340 | db_file.close() | 342 | db_file.close() |
903 | 341 | self.memo_file.close() | 343 | self.memo_file.close() |
904 | 342 | 344 | ||
905 | 343 | def _find_file(self, base_path, path_list): | ||
906 | 344 | """ | ||
907 | 345 | Find the specified file, with the option of the file being at any level in the specified directory structure. | ||
908 | 346 | |||
909 | 347 | :param base_path: the location search in | ||
910 | 348 | :param path_list: the targeted file, preceded by directories that may be their parents relative to the base_path | ||
911 | 349 | :return: path for targeted file | ||
912 | 350 | """ | ||
913 | 351 | target_file = '' | ||
914 | 352 | while len(path_list) > 0: | ||
915 | 353 | target_file = os.path.join(path_list[-1], target_file) | ||
916 | 354 | path_list = path_list[:len(path_list) - 1] | ||
917 | 355 | full_path = os.path.join(base_path, target_file) | ||
918 | 356 | full_path = full_path[:len(full_path) - 1] | ||
919 | 357 | if os.path.isfile(full_path): | ||
920 | 358 | return full_path | ||
921 | 359 | return '' | ||
922 | 360 | |||
923 | 361 | def import_sqlite_db(self): | 345 | def import_sqlite_db(self): |
924 | 362 | """ | 346 | """ |
925 | 363 | Import the songs from an EasyWorship 6 SQLite database | 347 | Import the songs from an EasyWorship 6 SQLite database |
926 | 364 | """ | 348 | """ |
930 | 365 | songs_db_path = self._find_file(self.import_source, ["Databases", "Data", "Songs.db"]) | 349 | songs_db_path = next(self.import_source.rglob('Songs.db'), None) |
931 | 366 | song_words_db_path = self._find_file(self.import_source, ["Databases", "Data", "SongWords.db"]) | 350 | song_words_db_path = next(self.import_source.rglob('SongWords.db'), None) |
932 | 367 | invalid_dir_msg = 'This does not appear to be a valid Easy Worship 6 database directory.' | 351 | invalid_dir_msg = translate('SongsPlugin.EasyWorshipSongImport', |
933 | 352 | 'This does not appear to be a valid Easy Worship 6 database directory.') | ||
934 | 353 | invalid_db_msg = translate('SongsPlugin.EasyWorshipSongImport', 'This is not a valid Easy Worship 6 database.') | ||
935 | 368 | # check to see if needed files are there | 354 | # check to see if needed files are there |
938 | 369 | if not os.path.isfile(songs_db_path): | 355 | if not (songs_db_path and songs_db_path.is_file()): |
939 | 370 | self.log_error(songs_db_path, translate('SongsPlugin.EasyWorshipSongImport', invalid_dir_msg)) | 356 | self.log_error(self.import_source, invalid_dir_msg) |
940 | 371 | return | 357 | return |
943 | 372 | if not os.path.isfile(song_words_db_path): | 358 | if not (song_words_db_path and song_words_db_path.is_file()): |
944 | 373 | self.log_error(song_words_db_path, translate('SongsPlugin.EasyWorshipSongImport', invalid_dir_msg)) | 359 | self.log_error(self.import_source, invalid_dir_msg) |
945 | 374 | return | 360 | return |
946 | 375 | # get database handles | 361 | # get database handles |
949 | 376 | songs_conn = sqlite3.connect(songs_db_path) | 362 | songs_conn = sqlite3.connect(str(songs_db_path)) |
950 | 377 | words_conn = sqlite3.connect(song_words_db_path) | 363 | words_conn = sqlite3.connect(str(song_words_db_path)) |
951 | 378 | if songs_conn is None or words_conn is None: | 364 | if songs_conn is None or words_conn is None: |
954 | 379 | self.log_error(self.import_source, translate('SongsPlugin.EasyWorshipSongImport', | 365 | self.log_error(self.import_source, invalid_db_msg) |
953 | 380 | 'This is not a valid Easy Worship 6 database.')) | ||
955 | 381 | songs_conn.close() | 366 | songs_conn.close() |
956 | 382 | words_conn.close() | 367 | words_conn.close() |
957 | 383 | return | 368 | return |
958 | 384 | songs_db = songs_conn.cursor() | 369 | songs_db = songs_conn.cursor() |
959 | 385 | words_db = words_conn.cursor() | 370 | words_db = words_conn.cursor() |
960 | 386 | if songs_conn is None or words_conn is None: | 371 | if songs_conn is None or words_conn is None: |
963 | 387 | self.log_error(self.import_source, translate('SongsPlugin.EasyWorshipSongImport', | 372 | self.log_error(self.import_source, invalid_db_msg) |
962 | 388 | 'This is not a valid Easy Worship 6 database.')) | ||
964 | 389 | songs_conn.close() | 373 | songs_conn.close() |
965 | 390 | words_conn.close() | 374 | words_conn.close() |
966 | 391 | return | 375 | return |
967 | 392 | 376 | ||
968 | === modified file 'openlp/plugins/songs/lib/importers/foilpresenter.py' | |||
969 | --- openlp/plugins/songs/lib/importers/foilpresenter.py 2017-05-30 18:42:35 +0000 | |||
970 | +++ openlp/plugins/songs/lib/importers/foilpresenter.py 2017-09-30 23:24:21 +0000 | |||
971 | @@ -82,10 +82,8 @@ | |||
972 | 82 | </kategorien> | 82 | </kategorien> |
973 | 83 | </foilpresenterfolie> | 83 | </foilpresenterfolie> |
974 | 84 | """ | 84 | """ |
975 | 85 | |||
976 | 86 | import logging | 85 | import logging |
977 | 87 | import re | 86 | import re |
978 | 88 | import os | ||
979 | 89 | 87 | ||
980 | 90 | from lxml import etree, objectify | 88 | from lxml import etree, objectify |
981 | 91 | 89 | ||
982 | @@ -121,10 +119,9 @@ | |||
983 | 121 | for file_path in self.import_source: | 119 | for file_path in self.import_source: |
984 | 122 | if self.stop_import_flag: | 120 | if self.stop_import_flag: |
985 | 123 | return | 121 | return |
988 | 124 | self.import_wizard.increment_progress_bar( | 122 | self.import_wizard.increment_progress_bar(WizardStrings.ImportingType.format(source=file_path.name)) |
987 | 125 | WizardStrings.ImportingType.format(source=os.path.basename(file_path))) | ||
989 | 126 | try: | 123 | try: |
991 | 127 | parsed_file = etree.parse(file_path, parser) | 124 | parsed_file = etree.parse(str(file_path), parser) |
992 | 128 | xml = etree.tostring(parsed_file).decode() | 125 | xml = etree.tostring(parsed_file).decode() |
993 | 129 | self.foil_presenter.xml_to_song(xml) | 126 | self.foil_presenter.xml_to_song(xml) |
994 | 130 | except etree.XMLSyntaxError: | 127 | except etree.XMLSyntaxError: |
995 | 131 | 128 | ||
996 | === modified file 'openlp/plugins/songs/lib/importers/lyrix.py' | |||
997 | --- openlp/plugins/songs/lib/importers/lyrix.py 2016-12-31 11:01:36 +0000 | |||
998 | +++ openlp/plugins/songs/lib/importers/lyrix.py 2017-09-30 23:24:21 +0000 | |||
999 | @@ -50,12 +50,11 @@ | |||
1000 | 50 | if not isinstance(self.import_source, list): | 50 | if not isinstance(self.import_source, list): |
1001 | 51 | return | 51 | return |
1002 | 52 | self.import_wizard.progress_bar.setMaximum(len(self.import_source)) | 52 | self.import_wizard.progress_bar.setMaximum(len(self.import_source)) |
1004 | 53 | for filename in self.import_source: | 53 | for file_path in self.import_source: |
1005 | 54 | if self.stop_import_flag: | 54 | if self.stop_import_flag: |
1006 | 55 | return | 55 | return |
1010 | 56 | song_file = open(filename, 'rt', encoding='cp1251') | 56 | with file_path.open('rt', encoding='cp1251') as song_file: |
1011 | 57 | self.do_import_file(song_file) | 57 | self.do_import_file(song_file) |
1009 | 58 | song_file.close() | ||
1012 | 59 | 58 | ||
1013 | 60 | def do_import_file(self, file): | 59 | def do_import_file(self, file): |
1014 | 61 | """ | 60 | """ |
1015 | 62 | 61 | ||
1016 | === modified file 'openlp/plugins/songs/lib/importers/openlp.py' | |||
1017 | --- openlp/plugins/songs/lib/importers/openlp.py 2017-05-30 18:42:35 +0000 | |||
1018 | +++ openlp/plugins/songs/lib/importers/openlp.py 2017-09-30 23:24:21 +0000 | |||
1019 | @@ -266,7 +266,7 @@ | |||
1020 | 266 | if has_media_files and song.media_files: | 266 | if has_media_files and song.media_files: |
1021 | 267 | for media_file in song.media_files: | 267 | for media_file in song.media_files: |
1022 | 268 | existing_media_file = self.manager.get_object_filtered( | 268 | existing_media_file = self.manager.get_object_filtered( |
1024 | 269 | MediaFile, MediaFile.file_name == media_file.file_name) | 269 | MediaFile, MediaFile.file_path == media_file.file_path) |
1025 | 270 | if existing_media_file: | 270 | if existing_media_file: |
1026 | 271 | new_song.media_files.append(existing_media_file) | 271 | new_song.media_files.append(existing_media_file) |
1027 | 272 | else: | 272 | else: |
1028 | 273 | 273 | ||
1029 | === modified file 'openlp/plugins/songs/lib/importers/openlyrics.py' | |||
1030 | --- openlp/plugins/songs/lib/importers/openlyrics.py 2017-05-30 18:42:35 +0000 | |||
1031 | +++ openlp/plugins/songs/lib/importers/openlyrics.py 2017-09-30 23:24:21 +0000 | |||
1032 | @@ -23,9 +23,7 @@ | |||
1033 | 23 | The :mod:`openlyrics` module provides the functionality for importing | 23 | The :mod:`openlyrics` module provides the functionality for importing |
1034 | 24 | songs which are saved as OpenLyrics files. | 24 | songs which are saved as OpenLyrics files. |
1035 | 25 | """ | 25 | """ |
1036 | 26 | |||
1037 | 27 | import logging | 26 | import logging |
1038 | 28 | import os | ||
1039 | 29 | 27 | ||
1040 | 30 | from lxml import etree | 28 | from lxml import etree |
1041 | 31 | 29 | ||
1042 | @@ -58,12 +56,11 @@ | |||
1043 | 58 | for file_path in self.import_source: | 56 | for file_path in self.import_source: |
1044 | 59 | if self.stop_import_flag: | 57 | if self.stop_import_flag: |
1045 | 60 | return | 58 | return |
1048 | 61 | self.import_wizard.increment_progress_bar( | 59 | self.import_wizard.increment_progress_bar(WizardStrings.ImportingType.format(source=file_path.name)) |
1047 | 62 | WizardStrings.ImportingType.format(source=os.path.basename(file_path))) | ||
1049 | 63 | try: | 60 | try: |
1050 | 64 | # Pass a file object, because lxml does not cope with some | 61 | # Pass a file object, because lxml does not cope with some |
1051 | 65 | # special characters in the path (see lp:757673 and lp:744337). | 62 | # special characters in the path (see lp:757673 and lp:744337). |
1053 | 66 | parsed_file = etree.parse(open(file_path, 'rb'), parser) | 63 | parsed_file = etree.parse(file_path.open('rb'), parser) |
1054 | 67 | xml = etree.tostring(parsed_file).decode() | 64 | xml = etree.tostring(parsed_file).decode() |
1055 | 68 | self.open_lyrics.xml_to_song(xml) | 65 | self.open_lyrics.xml_to_song(xml) |
1056 | 69 | except etree.XMLSyntaxError: | 66 | except etree.XMLSyntaxError: |
1057 | 70 | 67 | ||
1058 | === modified file 'openlp/plugins/songs/lib/importers/openoffice.py' | |||
1059 | --- openlp/plugins/songs/lib/importers/openoffice.py 2016-12-31 11:01:36 +0000 | |||
1060 | +++ openlp/plugins/songs/lib/importers/openoffice.py 2017-09-30 23:24:21 +0000 | |||
1061 | @@ -20,7 +20,6 @@ | |||
1062 | 20 | # Temple Place, Suite 330, Boston, MA 02111-1307 USA # | 20 | # Temple Place, Suite 330, Boston, MA 02111-1307 USA # |
1063 | 21 | ############################################################################### | 21 | ############################################################################### |
1064 | 22 | import logging | 22 | import logging |
1065 | 23 | import os | ||
1066 | 24 | import time | 23 | import time |
1067 | 25 | 24 | ||
1068 | 26 | from PyQt5 import QtCore | 25 | from PyQt5 import QtCore |
1069 | @@ -70,12 +69,11 @@ | |||
1070 | 70 | log.error(exc) | 69 | log.error(exc) |
1071 | 71 | return | 70 | return |
1072 | 72 | self.import_wizard.progress_bar.setMaximum(len(self.import_source)) | 71 | self.import_wizard.progress_bar.setMaximum(len(self.import_source)) |
1074 | 73 | for filename in self.import_source: | 72 | for file_path in self.import_source: |
1075 | 74 | if self.stop_import_flag: | 73 | if self.stop_import_flag: |
1076 | 75 | break | 74 | break |
1080 | 76 | filename = str(filename) | 75 | if file_path.is_file(): |
1081 | 77 | if os.path.isfile(filename): | 76 | self.open_ooo_file(file_path) |
1079 | 78 | self.open_ooo_file(filename) | ||
1082 | 79 | if self.document: | 77 | if self.document: |
1083 | 80 | self.process_ooo_document() | 78 | self.process_ooo_document() |
1084 | 81 | self.close_ooo_file() | 79 | self.close_ooo_file() |
1085 | @@ -144,12 +142,7 @@ | |||
1086 | 144 | Open the passed file in OpenOffice.org Impress | 142 | Open the passed file in OpenOffice.org Impress |
1087 | 145 | """ | 143 | """ |
1088 | 146 | self.file_path = file_path | 144 | self.file_path = file_path |
1095 | 147 | if is_win(): | 145 | url = file_path.as_uri() |
1090 | 148 | url = file_path.replace('\\', '/') | ||
1091 | 149 | url = url.replace(':', '|').replace(' ', '%20') | ||
1092 | 150 | url = 'file:///' + url | ||
1093 | 151 | else: | ||
1094 | 152 | url = uno.systemPathToFileUrl(file_path) | ||
1096 | 153 | properties = [] | 146 | properties = [] |
1097 | 154 | properties.append(self.create_property('Hidden', True)) | 147 | properties.append(self.create_property('Hidden', True)) |
1098 | 155 | properties = tuple(properties) | 148 | properties = tuple(properties) |
1099 | @@ -159,7 +152,7 @@ | |||
1100 | 159 | self.document.supportsService("com.sun.star.text.TextDocument"): | 152 | self.document.supportsService("com.sun.star.text.TextDocument"): |
1101 | 160 | self.close_ooo_file() | 153 | self.close_ooo_file() |
1102 | 161 | else: | 154 | else: |
1104 | 162 | self.import_wizard.increment_progress_bar('Processing file ' + file_path, 0) | 155 | self.import_wizard.increment_progress_bar('Processing file {file_path}'.format(file_path=file_path), 0) |
1105 | 163 | except AttributeError: | 156 | except AttributeError: |
1106 | 164 | log.exception("open_ooo_file failed: {url}".format(url=url)) | 157 | log.exception("open_ooo_file failed: {url}".format(url=url)) |
1107 | 165 | return | 158 | return |
1108 | 166 | 159 | ||
1109 | === modified file 'openlp/plugins/songs/lib/importers/opensong.py' | |||
1110 | --- openlp/plugins/songs/lib/importers/opensong.py 2017-02-26 21:14:49 +0000 | |||
1111 | +++ openlp/plugins/songs/lib/importers/opensong.py 2017-09-30 23:24:21 +0000 | |||
1112 | @@ -19,7 +19,6 @@ | |||
1113 | 19 | # with this program; if not, write to the Free Software Foundation, Inc., 59 # | 19 | # with this program; if not, write to the Free Software Foundation, Inc., 59 # |
1114 | 20 | # Temple Place, Suite 330, Boston, MA 02111-1307 USA # | 20 | # Temple Place, Suite 330, Boston, MA 02111-1307 USA # |
1115 | 21 | ############################################################################### | 21 | ############################################################################### |
1116 | 22 | |||
1117 | 23 | import logging | 22 | import logging |
1118 | 24 | import re | 23 | import re |
1119 | 25 | 24 | ||
1120 | @@ -116,12 +115,11 @@ | |||
1121 | 116 | if not isinstance(self.import_source, list): | 115 | if not isinstance(self.import_source, list): |
1122 | 117 | return | 116 | return |
1123 | 118 | self.import_wizard.progress_bar.setMaximum(len(self.import_source)) | 117 | self.import_wizard.progress_bar.setMaximum(len(self.import_source)) |
1125 | 119 | for filename in self.import_source: | 118 | for file_path in self.import_source: |
1126 | 120 | if self.stop_import_flag: | 119 | if self.stop_import_flag: |
1127 | 121 | return | 120 | return |
1131 | 122 | song_file = open(filename, 'rb') | 121 | with file_path.open('rb') as song_file: |
1132 | 123 | self.do_import_file(song_file) | 122 | self.do_import_file(song_file) |
1130 | 124 | song_file.close() | ||
1133 | 125 | 123 | ||
1134 | 126 | def do_import_file(self, file): | 124 | def do_import_file(self, file): |
1135 | 127 | """ | 125 | """ |
1136 | 128 | 126 | ||
1137 | === modified file 'openlp/plugins/songs/lib/importers/opspro.py' | |||
1138 | --- openlp/plugins/songs/lib/importers/opspro.py 2016-12-31 11:01:36 +0000 | |||
1139 | +++ openlp/plugins/songs/lib/importers/opspro.py 2017-09-30 23:24:21 +0000 | |||
1140 | @@ -231,16 +231,15 @@ | |||
1141 | 231 | xor_pattern_2k = (0xa1, 0xec, 0x7a, 0x9c, 0xe1, 0x28, 0x34, 0x8a, 0x73, 0x7b, 0xd2, 0xdf, 0x50) | 231 | xor_pattern_2k = (0xa1, 0xec, 0x7a, 0x9c, 0xe1, 0x28, 0x34, 0x8a, 0x73, 0x7b, 0xd2, 0xdf, 0x50) |
1142 | 232 | # Access97 XOR of the source | 232 | # Access97 XOR of the source |
1143 | 233 | xor_pattern_97 = (0x86, 0xfb, 0xec, 0x37, 0x5d, 0x44, 0x9c, 0xfa, 0xc6, 0x5e, 0x28, 0xe6, 0x13) | 233 | xor_pattern_97 = (0x86, 0xfb, 0xec, 0x37, 0x5d, 0x44, 0x9c, 0xfa, 0xc6, 0x5e, 0x28, 0xe6, 0x13) |
1154 | 234 | mdb = open(self.import_source, 'rb') | 234 | with self.import_source.open('rb') as mdb_file: |
1155 | 235 | mdb.seek(0x14) | 235 | mdb_file.seek(0x14) |
1156 | 236 | version = struct.unpack('B', mdb.read(1))[0] | 236 | version = struct.unpack('B', mdb_file.read(1))[0] |
1157 | 237 | # Get encrypted logo | 237 | # Get encrypted logo |
1158 | 238 | mdb.seek(0x62) | 238 | mdb_file.seek(0x62) |
1159 | 239 | EncrypFlag = struct.unpack('B', mdb.read(1))[0] | 239 | EncrypFlag = struct.unpack('B', mdb_file.read(1))[0] |
1160 | 240 | # Get encrypted password | 240 | # Get encrypted password |
1161 | 241 | mdb.seek(0x42) | 241 | mdb_file.seek(0x42) |
1162 | 242 | encrypted_password = mdb.read(26) | 242 | encrypted_password = mdb_file.read(26) |
1153 | 243 | mdb.close() | ||
1163 | 244 | # "Decrypt" the password based on the version | 243 | # "Decrypt" the password based on the version |
1164 | 245 | decrypted_password = '' | 244 | decrypted_password = '' |
1165 | 246 | if version < 0x01: | 245 | if version < 0x01: |
1166 | 247 | 246 | ||
1167 | === modified file 'openlp/plugins/songs/lib/importers/powerpraise.py' | |||
1168 | --- openlp/plugins/songs/lib/importers/powerpraise.py 2017-05-30 18:42:35 +0000 | |||
1169 | +++ openlp/plugins/songs/lib/importers/powerpraise.py 2017-09-30 23:24:21 +0000 | |||
1170 | @@ -23,8 +23,6 @@ | |||
1171 | 23 | The :mod:`powerpraiseimport` module provides the functionality for importing | 23 | The :mod:`powerpraiseimport` module provides the functionality for importing |
1172 | 24 | Powerpraise song files into the current database. | 24 | Powerpraise song files into the current database. |
1173 | 25 | """ | 25 | """ |
1174 | 26 | |||
1175 | 27 | import os | ||
1176 | 28 | from lxml import objectify | 26 | from lxml import objectify |
1177 | 29 | 27 | ||
1178 | 30 | from openlp.core.ui.lib.wizard import WizardStrings | 28 | from openlp.core.ui.lib.wizard import WizardStrings |
1179 | @@ -41,10 +39,10 @@ | |||
1180 | 41 | for file_path in self.import_source: | 39 | for file_path in self.import_source: |
1181 | 42 | if self.stop_import_flag: | 40 | if self.stop_import_flag: |
1182 | 43 | return | 41 | return |
1187 | 44 | self.import_wizard.increment_progress_bar( | 42 | self.import_wizard.increment_progress_bar(WizardStrings.ImportingType.format(source=file_path.name)) |
1188 | 45 | WizardStrings.ImportingType.format(source=os.path.basename(file_path))) | 43 | with file_path.open('rb') as xml_file: |
1189 | 46 | root = objectify.parse(open(file_path, 'rb')).getroot() | 44 | root = objectify.parse(xml_file).getroot() |
1190 | 47 | self.process_song(root) | 45 | self.process_song(root) |
1191 | 48 | 46 | ||
1192 | 49 | def process_song(self, root): | 47 | def process_song(self, root): |
1193 | 50 | self.set_defaults() | 48 | self.set_defaults() |
1194 | 51 | 49 | ||
1195 | === modified file 'openlp/plugins/songs/lib/importers/powersong.py' | |||
1196 | --- openlp/plugins/songs/lib/importers/powersong.py 2016-12-31 11:01:36 +0000 | |||
1197 | +++ openlp/plugins/songs/lib/importers/powersong.py 2017-09-30 23:24:21 +0000 | |||
1198 | @@ -72,10 +72,14 @@ | |||
1199 | 72 | Checks if source is a PowerSong 1.0 folder: | 72 | Checks if source is a PowerSong 1.0 folder: |
1200 | 73 | * is a directory | 73 | * is a directory |
1201 | 74 | * contains at least one \*.song file | 74 | * contains at least one \*.song file |
1202 | 75 | |||
1203 | 76 | :param openlp.core.common.path.Path import_source: Should be a Path object that fulfills the above criteria | ||
1204 | 77 | :return: If the source is valid | ||
1205 | 78 | :rtype: bool | ||
1206 | 75 | """ | 79 | """ |
1210 | 76 | if os.path.isdir(import_source): | 80 | if import_source.is_dir(): |
1211 | 77 | for file in os.listdir(import_source): | 81 | for file_path in import_source.iterdir(): |
1212 | 78 | if fnmatch.fnmatch(file, '*.song'): | 82 | if file_path.suffix == '.song': |
1213 | 79 | return True | 83 | return True |
1214 | 80 | return False | 84 | return False |
1215 | 81 | 85 | ||
1216 | 82 | 86 | ||
1217 | === modified file 'openlp/plugins/songs/lib/importers/presentationmanager.py' | |||
1218 | --- openlp/plugins/songs/lib/importers/presentationmanager.py 2017-05-30 18:42:35 +0000 | |||
1219 | +++ openlp/plugins/songs/lib/importers/presentationmanager.py 2017-09-30 23:24:21 +0000 | |||
1220 | @@ -23,13 +23,11 @@ | |||
1221 | 23 | The :mod:`presentationmanager` module provides the functionality for importing | 23 | The :mod:`presentationmanager` module provides the functionality for importing |
1222 | 24 | Presentationmanager song files into the current database. | 24 | Presentationmanager song files into the current database. |
1223 | 25 | """ | 25 | """ |
1224 | 26 | import os | ||
1225 | 27 | import re | 26 | import re |
1226 | 28 | 27 | ||
1227 | 29 | import chardet | ||
1228 | 30 | from lxml import objectify, etree | 28 | from lxml import objectify, etree |
1229 | 31 | 29 | ||
1231 | 32 | from openlp.core.common import translate | 30 | from openlp.core.common import get_file_encoding, translate |
1232 | 33 | from openlp.core.ui.lib.wizard import WizardStrings | 31 | from openlp.core.ui.lib.wizard import WizardStrings |
1233 | 34 | from .songimport import SongImport | 32 | from .songimport import SongImport |
1234 | 35 | 33 | ||
1235 | @@ -44,17 +42,14 @@ | |||
1236 | 44 | for file_path in self.import_source: | 42 | for file_path in self.import_source: |
1237 | 45 | if self.stop_import_flag: | 43 | if self.stop_import_flag: |
1238 | 46 | return | 44 | return |
1241 | 47 | self.import_wizard.increment_progress_bar( | 45 | self.import_wizard.increment_progress_bar(WizardStrings.ImportingType.format(source=file_path.name)) |
1240 | 48 | WizardStrings.ImportingType.format(source=os.path.basename(file_path))) | ||
1242 | 49 | try: | 46 | try: |
1244 | 50 | tree = etree.parse(file_path, parser=etree.XMLParser(recover=True)) | 47 | tree = etree.parse(str(file_path), parser=etree.XMLParser(recover=True)) |
1245 | 51 | except etree.XMLSyntaxError: | 48 | except etree.XMLSyntaxError: |
1246 | 52 | # Try to detect encoding and use it | 49 | # Try to detect encoding and use it |
1250 | 53 | file = open(file_path, mode='rb') | 50 | encoding = get_file_encoding(file_path)['encoding'] |
1248 | 54 | encoding = chardet.detect(file.read())['encoding'] | ||
1249 | 55 | file.close() | ||
1251 | 56 | # Open file with detected encoding and remove encoding declaration | 51 | # Open file with detected encoding and remove encoding declaration |
1253 | 57 | text = open(file_path, mode='r', encoding=encoding).read() | 52 | text = file_path.read_text(encoding=encoding) |
1254 | 58 | text = re.sub('.+\?>\n', '', text) | 53 | text = re.sub('.+\?>\n', '', text) |
1255 | 59 | try: | 54 | try: |
1256 | 60 | tree = etree.fromstring(text, parser=etree.XMLParser(recover=True)) | 55 | tree = etree.fromstring(text, parser=etree.XMLParser(recover=True)) |
1257 | @@ -80,6 +75,11 @@ | |||
1258 | 80 | return '' | 75 | return '' |
1259 | 81 | 76 | ||
1260 | 82 | def process_song(self, root, file_path): | 77 | def process_song(self, root, file_path): |
1261 | 78 | """ | ||
1262 | 79 | :param root: | ||
1263 | 80 | :param openlp.core.common.path.Path file_path: Path to the file to process | ||
1264 | 81 | :rtype: None | ||
1265 | 82 | """ | ||
1266 | 83 | self.set_defaults() | 83 | self.set_defaults() |
1267 | 84 | attrs = None | 84 | attrs = None |
1268 | 85 | if hasattr(root, 'attributes'): | 85 | if hasattr(root, 'attributes'): |
1269 | @@ -123,4 +123,4 @@ | |||
1270 | 123 | 123 | ||
1271 | 124 | self.verse_order_list = verse_order_list | 124 | self.verse_order_list = verse_order_list |
1272 | 125 | if not self.finish(): | 125 | if not self.finish(): |
1274 | 126 | self.log_error(os.path.basename(file_path)) | 126 | self.log_error(file_path.name) |
1275 | 127 | 127 | ||
1276 | === modified file 'openlp/plugins/songs/lib/importers/propresenter.py' | |||
1277 | --- openlp/plugins/songs/lib/importers/propresenter.py 2017-05-30 18:42:35 +0000 | |||
1278 | +++ openlp/plugins/songs/lib/importers/propresenter.py 2017-09-30 23:24:21 +0000 | |||
1279 | @@ -23,8 +23,6 @@ | |||
1280 | 23 | The :mod:`propresenter` module provides the functionality for importing | 23 | The :mod:`propresenter` module provides the functionality for importing |
1281 | 24 | ProPresenter song files into the current installation database. | 24 | ProPresenter song files into the current installation database. |
1282 | 25 | """ | 25 | """ |
1283 | 26 | |||
1284 | 27 | import os | ||
1285 | 28 | import base64 | 26 | import base64 |
1286 | 29 | import logging | 27 | import logging |
1287 | 30 | from lxml import objectify | 28 | from lxml import objectify |
1288 | @@ -47,11 +45,17 @@ | |||
1289 | 47 | if self.stop_import_flag: | 45 | if self.stop_import_flag: |
1290 | 48 | return | 46 | return |
1291 | 49 | self.import_wizard.increment_progress_bar( | 47 | self.import_wizard.increment_progress_bar( |
1295 | 50 | WizardStrings.ImportingType.format(source=os.path.basename(file_path))) | 48 | WizardStrings.ImportingType.format(source=file_path.name)) |
1296 | 51 | root = objectify.parse(open(file_path, 'rb')).getroot() | 49 | with file_path.open('rb') as xml_file: |
1297 | 52 | self.process_song(root, file_path) | 50 | root = objectify.parse(xml_file).getroot() |
1298 | 51 | self.process_song(root, file_path) | ||
1299 | 53 | 52 | ||
1301 | 54 | def process_song(self, root, filename): | 53 | def process_song(self, root, file_path): |
1302 | 54 | """ | ||
1303 | 55 | :param root: | ||
1304 | 56 | :param openlp.core.common.path.Path file_path: Path to the file thats being imported | ||
1305 | 57 | :rtype: None | ||
1306 | 58 | """ | ||
1307 | 55 | self.set_defaults() | 59 | self.set_defaults() |
1308 | 56 | 60 | ||
1309 | 57 | # Extract ProPresenter versionNumber | 61 | # Extract ProPresenter versionNumber |
1310 | @@ -64,9 +68,7 @@ | |||
1311 | 64 | # Title | 68 | # Title |
1312 | 65 | self.title = root.get('CCLISongTitle') | 69 | self.title = root.get('CCLISongTitle') |
1313 | 66 | if not self.title or self.title == '': | 70 | if not self.title or self.title == '': |
1317 | 67 | self.title = os.path.basename(filename) | 71 | self.title = file_path.stem |
1315 | 68 | if self.title[-5:-1] == '.pro': | ||
1316 | 69 | self.title = self.title[:-5] | ||
1318 | 70 | # Notes | 72 | # Notes |
1319 | 71 | self.comments = root.get('notes') | 73 | self.comments = root.get('notes') |
1320 | 72 | # Author | 74 | # Author |
1321 | 73 | 75 | ||
1322 | === modified file 'openlp/plugins/songs/lib/importers/songbeamer.py' | |||
1323 | --- openlp/plugins/songs/lib/importers/songbeamer.py 2017-08-25 20:03:25 +0000 | |||
1324 | +++ openlp/plugins/songs/lib/importers/songbeamer.py 2017-09-30 23:24:21 +0000 | |||
1325 | @@ -112,7 +112,7 @@ | |||
1326 | 112 | if not isinstance(self.import_source, list): | 112 | if not isinstance(self.import_source, list): |
1327 | 113 | return | 113 | return |
1328 | 114 | self.import_wizard.progress_bar.setMaximum(len(self.import_source)) | 114 | self.import_wizard.progress_bar.setMaximum(len(self.import_source)) |
1330 | 115 | for import_file in self.import_source: | 115 | for file_path in self.import_source: |
1331 | 116 | # TODO: check that it is a valid SongBeamer file | 116 | # TODO: check that it is a valid SongBeamer file |
1332 | 117 | if self.stop_import_flag: | 117 | if self.stop_import_flag: |
1333 | 118 | return | 118 | return |
1334 | @@ -120,20 +120,19 @@ | |||
1335 | 120 | self.current_verse = '' | 120 | self.current_verse = '' |
1336 | 121 | self.current_verse_type = VerseType.tags[VerseType.Verse] | 121 | self.current_verse_type = VerseType.tags[VerseType.Verse] |
1337 | 122 | self.chord_table = None | 122 | self.chord_table = None |
1340 | 123 | file_name = os.path.split(import_file)[1] | 123 | if file_path.is_file(): |
1339 | 124 | if os.path.isfile(import_file): | ||
1341 | 125 | # Detect the encoding | 124 | # Detect the encoding |
1343 | 126 | self.input_file_encoding = get_file_encoding(Path(import_file))['encoding'] | 125 | self.input_file_encoding = get_file_encoding(file_path)['encoding'] |
1344 | 127 | # The encoding should only be ANSI (cp1252), UTF-8, Unicode, Big-Endian-Unicode. | 126 | # The encoding should only be ANSI (cp1252), UTF-8, Unicode, Big-Endian-Unicode. |
1345 | 128 | # So if it doesn't start with 'u' we default to cp1252. See: | 127 | # So if it doesn't start with 'u' we default to cp1252. See: |
1346 | 129 | # https://forum.songbeamer.com/viewtopic.php?p=419&sid=ca4814924e37c11e4438b7272a98b6f2 | 128 | # https://forum.songbeamer.com/viewtopic.php?p=419&sid=ca4814924e37c11e4438b7272a98b6f2 |
1347 | 130 | if not self.input_file_encoding.lower().startswith('u'): | 129 | if not self.input_file_encoding.lower().startswith('u'): |
1348 | 131 | self.input_file_encoding = 'cp1252' | 130 | self.input_file_encoding = 'cp1252' |
1351 | 132 | infile = open(import_file, 'rt', encoding=self.input_file_encoding) | 131 | with file_path.open(encoding=self.input_file_encoding) as song_file: |
1352 | 133 | song_data = infile.readlines() | 132 | song_data = song_file.readlines() |
1353 | 134 | else: | 133 | else: |
1354 | 135 | continue | 134 | continue |
1356 | 136 | self.title = file_name.split('.sng')[0] | 135 | self.title = file_path.stem |
1357 | 137 | read_verses = False | 136 | read_verses = False |
1358 | 138 | # The first verse separator doesn't count, but the others does, so line count starts at -1 | 137 | # The first verse separator doesn't count, but the others does, so line count starts at -1 |
1359 | 139 | line_number = -1 | 138 | line_number = -1 |
1360 | @@ -185,7 +184,7 @@ | |||
1361 | 185 | # inserted by songbeamer, but are manually added headings. So restart the loop, and | 184 | # inserted by songbeamer, but are manually added headings. So restart the loop, and |
1362 | 186 | # count tags as lines. | 185 | # count tags as lines. |
1363 | 187 | self.set_defaults() | 186 | self.set_defaults() |
1365 | 188 | self.title = file_name.split('.sng')[0] | 187 | self.title = file_path.stem |
1366 | 189 | verse_tags_mode = VerseTagMode.ContainsNoTagsRestart | 188 | verse_tags_mode = VerseTagMode.ContainsNoTagsRestart |
1367 | 190 | read_verses = False | 189 | read_verses = False |
1368 | 191 | # The first verseseparator doesn't count, but the others does, so linecount starts at -1 | 190 | # The first verseseparator doesn't count, but the others does, so linecount starts at -1 |
1369 | @@ -207,7 +206,7 @@ | |||
1370 | 207 | self.replace_html_tags() | 206 | self.replace_html_tags() |
1371 | 208 | self.add_verse(self.current_verse, self.current_verse_type) | 207 | self.add_verse(self.current_verse, self.current_verse_type) |
1372 | 209 | if not self.finish(): | 208 | if not self.finish(): |
1374 | 210 | self.log_error(import_file) | 209 | self.log_error(file_path) |
1375 | 211 | 210 | ||
1376 | 212 | def insert_chords(self, line_number, line): | 211 | def insert_chords(self, line_number, line): |
1377 | 213 | """ | 212 | """ |
1378 | @@ -414,14 +413,15 @@ | |||
1379 | 414 | """ | 413 | """ |
1380 | 415 | # The path is relative to SongBeamers Song folder | 414 | # The path is relative to SongBeamers Song folder |
1381 | 416 | if is_win(): | 415 | if is_win(): |
1383 | 417 | user_doc_folder = os.path.expandvars('$DOCUMENTS') | 416 | user_doc_path = Path(os.path.expandvars('$DOCUMENTS')) |
1384 | 418 | elif is_macosx(): | 417 | elif is_macosx(): |
1386 | 419 | user_doc_folder = os.path.join(os.path.expanduser('~'), 'Documents') | 418 | user_doc_path = Path.home() / 'Documents' |
1387 | 420 | else: | 419 | else: |
1388 | 421 | # SongBeamer only runs on mac and win... | 420 | # SongBeamer only runs on mac and win... |
1389 | 422 | return | 421 | return |
1392 | 423 | audio_file_path = os.path.normpath(os.path.join(user_doc_folder, 'SongBeamer', 'Songs', audio_file_path)) | 422 | audio_file_path = user_doc_path / 'SongBeamer' / 'Songs' / audio_file_path |
1393 | 424 | if os.path.isfile(audio_file_path): | 423 | if audio_file_path.is_file(): |
1394 | 425 | self.add_media_file(audio_file_path) | 424 | self.add_media_file(audio_file_path) |
1395 | 426 | else: | 425 | else: |
1397 | 427 | log.debug('Could not import mediafile "%s" since it does not exists!' % audio_file_path) | 426 | log.debug('Could not import mediafile "{audio_file_path}" since it does not exists!' |
1398 | 427 | .format(audio_file_path=audio_file_path)) | ||
1399 | 428 | 428 | ||
1400 | === modified file 'openlp/plugins/songs/lib/importers/songimport.py' | |||
1401 | --- openlp/plugins/songs/lib/importers/songimport.py 2017-08-25 20:03:25 +0000 | |||
1402 | +++ openlp/plugins/songs/lib/importers/songimport.py 2017-09-30 23:24:21 +0000 | |||
1403 | @@ -22,13 +22,11 @@ | |||
1404 | 22 | 22 | ||
1405 | 23 | import logging | 23 | import logging |
1406 | 24 | import re | 24 | import re |
1407 | 25 | import shutil | ||
1408 | 26 | import os | ||
1409 | 27 | 25 | ||
1410 | 28 | from PyQt5 import QtCore | 26 | from PyQt5 import QtCore |
1411 | 29 | 27 | ||
1412 | 30 | from openlp.core.common import Registry, AppLocation, check_directory_exists, translate | 28 | from openlp.core.common import Registry, AppLocation, check_directory_exists, translate |
1414 | 31 | from openlp.core.common.path import Path | 29 | from openlp.core.common.path import copyfile |
1415 | 32 | from openlp.core.ui.lib.wizard import WizardStrings | 30 | from openlp.core.ui.lib.wizard import WizardStrings |
1416 | 33 | from openlp.plugins.songs.lib import clean_song, VerseType | 31 | from openlp.plugins.songs.lib import clean_song, VerseType |
1417 | 34 | from openlp.plugins.songs.lib.db import Song, Author, Topic, Book, MediaFile | 32 | from openlp.plugins.songs.lib.db import Song, Author, Topic, Book, MediaFile |
1418 | @@ -62,14 +60,14 @@ | |||
1419 | 62 | """ | 60 | """ |
1420 | 63 | self.manager = manager | 61 | self.manager = manager |
1421 | 64 | QtCore.QObject.__init__(self) | 62 | QtCore.QObject.__init__(self) |
1428 | 65 | if 'filename' in kwargs: | 63 | if 'file_path' in kwargs: |
1429 | 66 | self.import_source = kwargs['filename'] | 64 | self.import_source = kwargs['file_path'] |
1430 | 67 | elif 'filenames' in kwargs: | 65 | elif 'file_paths' in kwargs: |
1431 | 68 | self.import_source = kwargs['filenames'] | 66 | self.import_source = kwargs['file_paths'] |
1432 | 69 | elif 'folder' in kwargs: | 67 | elif 'folder_path' in kwargs: |
1433 | 70 | self.import_source = kwargs['folder'] | 68 | self.import_source = kwargs['folder_path'] |
1434 | 71 | else: | 69 | else: |
1436 | 72 | raise KeyError('Keyword arguments "filename[s]" or "folder" not supplied.') | 70 | raise KeyError('Keyword arguments "file_path[s]" or "folder_path" not supplied.') |
1437 | 73 | log.debug(self.import_source) | 71 | log.debug(self.import_source) |
1438 | 74 | self.import_wizard = None | 72 | self.import_wizard = None |
1439 | 75 | self.song = None | 73 | self.song = None |
1440 | @@ -270,13 +268,13 @@ | |||
1441 | 270 | return | 268 | return |
1442 | 271 | self.authors.append((author, type)) | 269 | self.authors.append((author, type)) |
1443 | 272 | 270 | ||
1445 | 273 | def add_media_file(self, filename, weight=0): | 271 | def add_media_file(self, file_path, weight=0): |
1446 | 274 | """ | 272 | """ |
1447 | 275 | Add a media file to the list | 273 | Add a media file to the list |
1448 | 276 | """ | 274 | """ |
1450 | 277 | if filename in [x[0] for x in self.media_files]: | 275 | if file_path in [x[0] for x in self.media_files]: |
1451 | 278 | return | 276 | return |
1453 | 279 | self.media_files.append((filename, weight)) | 277 | self.media_files.append((file_path, weight)) |
1454 | 280 | 278 | ||
1455 | 281 | def add_verse(self, verse_text, verse_def='v', lang=None): | 279 | def add_verse(self, verse_text, verse_def='v', lang=None): |
1456 | 282 | """ | 280 | """ |
1457 | @@ -403,29 +401,30 @@ | |||
1458 | 403 | self.manager.save_object(song) | 401 | self.manager.save_object(song) |
1459 | 404 | # Now loop through the media files, copy them to the correct location, | 402 | # Now loop through the media files, copy them to the correct location, |
1460 | 405 | # and save the song again. | 403 | # and save the song again. |
1463 | 406 | for filename, weight in self.media_files: | 404 | for file_path, weight in self.media_files: |
1464 | 407 | media_file = self.manager.get_object_filtered(MediaFile, MediaFile.file_name == filename) | 405 | media_file = self.manager.get_object_filtered(MediaFile, MediaFile.file_path == file_path) |
1465 | 408 | if not media_file: | 406 | if not media_file: |
1469 | 409 | if os.path.dirname(filename): | 407 | if file_path.parent: |
1470 | 410 | filename = self.copy_media_file(song.id, filename) | 408 | file_path = self.copy_media_file(song.id, file_path) |
1471 | 411 | song.media_files.append(MediaFile.populate(file_name=filename, weight=weight)) | 409 | song.media_files.append(MediaFile.populate(file_path=file_path, weight=weight)) |
1472 | 412 | self.manager.save_object(song) | 410 | self.manager.save_object(song) |
1473 | 413 | self.set_defaults() | 411 | self.set_defaults() |
1474 | 414 | return True | 412 | return True |
1475 | 415 | 413 | ||
1477 | 416 | def copy_media_file(self, song_id, filename): | 414 | def copy_media_file(self, song_id, file_path): |
1478 | 417 | """ | 415 | """ |
1479 | 418 | This method copies the media file to the correct location and returns | 416 | This method copies the media file to the correct location and returns |
1480 | 419 | the new file location. | 417 | the new file location. |
1481 | 420 | 418 | ||
1482 | 421 | :param song_id: | 419 | :param song_id: |
1484 | 422 | :param filename: The file to copy. | 420 | :param openlp.core.common.path.Path file_path: The file to copy. |
1485 | 421 | :return: The new location of the file | ||
1486 | 422 | :rtype: openlp.core.common.path.Path | ||
1487 | 423 | """ | 423 | """ |
1488 | 424 | if not hasattr(self, 'save_path'): | 424 | if not hasattr(self, 'save_path'): |
1496 | 425 | self.save_path = os.path.join(str(AppLocation.get_section_data_path(self.import_wizard.plugin.name)), | 425 | self.save_path = AppLocation.get_section_data_path(self.import_wizard.plugin.name) / 'audio' / str(song_id) |
1497 | 426 | 'audio', str(song_id)) | 426 | check_directory_exists(self.save_path) |
1498 | 427 | check_directory_exists(Path(self.save_path)) | 427 | if self.save_path not in file_path.parents: |
1499 | 428 | if not filename.startswith(self.save_path): | 428 | old_path, file_path = file_path, self.save_path / file_path.name |
1500 | 429 | old_file, filename = filename, os.path.join(self.save_path, os.path.split(filename)[1]) | 429 | copyfile(old_path, file_path) |
1501 | 430 | shutil.copyfile(old_file, filename) | 430 | return file_path |
1495 | 431 | return filename | ||
1502 | 432 | 431 | ||
1503 | === modified file 'openlp/plugins/songs/lib/importers/songpro.py' | |||
1504 | --- openlp/plugins/songs/lib/importers/songpro.py 2016-12-31 11:01:36 +0000 | |||
1505 | +++ openlp/plugins/songs/lib/importers/songpro.py 2017-09-30 23:24:21 +0000 | |||
1506 | @@ -25,6 +25,7 @@ | |||
1507 | 25 | """ | 25 | """ |
1508 | 26 | import re | 26 | import re |
1509 | 27 | 27 | ||
1510 | 28 | from openlp.core.common.path import Path | ||
1511 | 28 | from openlp.plugins.songs.lib import strip_rtf | 29 | from openlp.plugins.songs.lib import strip_rtf |
1512 | 29 | from openlp.plugins.songs.lib.importers.songimport import SongImport | 30 | from openlp.plugins.songs.lib.importers.songimport import SongImport |
1513 | 30 | 31 | ||
1514 | @@ -72,7 +73,8 @@ | |||
1515 | 72 | Receive a single file or a list of files to import. | 73 | Receive a single file or a list of files to import. |
1516 | 73 | """ | 74 | """ |
1517 | 74 | self.encoding = None | 75 | self.encoding = None |
1519 | 75 | with open(self.import_source, 'rt', errors='ignore') as songs_file: | 76 | self.import_source = Path(self.import_source) |
1520 | 77 | with self.import_source.open('rt', errors='ignore') as songs_file: | ||
1521 | 76 | self.import_wizard.progress_bar.setMaximum(0) | 78 | self.import_wizard.progress_bar.setMaximum(0) |
1522 | 77 | tag = '' | 79 | tag = '' |
1523 | 78 | text = '' | 80 | text = '' |
1524 | 79 | 81 | ||
1525 | === modified file 'openlp/plugins/songs/lib/importers/songshowplus.py' | |||
1526 | --- openlp/plugins/songs/lib/importers/songshowplus.py 2017-06-01 06:18:47 +0000 | |||
1527 | +++ openlp/plugins/songs/lib/importers/songshowplus.py 2017-09-30 23:24:21 +0000 | |||
1528 | @@ -23,7 +23,6 @@ | |||
1529 | 23 | The :mod:`songshowplus` module provides the functionality for importing SongShow Plus songs into the OpenLP | 23 | The :mod:`songshowplus` module provides the functionality for importing SongShow Plus songs into the OpenLP |
1530 | 24 | database. | 24 | database. |
1531 | 25 | """ | 25 | """ |
1532 | 26 | import os | ||
1533 | 27 | import logging | 26 | import logging |
1534 | 28 | import re | 27 | import re |
1535 | 29 | import struct | 28 | import struct |
1536 | @@ -93,97 +92,95 @@ | |||
1537 | 93 | if not isinstance(self.import_source, list): | 92 | if not isinstance(self.import_source, list): |
1538 | 94 | return | 93 | return |
1539 | 95 | self.import_wizard.progress_bar.setMaximum(len(self.import_source)) | 94 | self.import_wizard.progress_bar.setMaximum(len(self.import_source)) |
1541 | 96 | for file in self.import_source: | 95 | for file_path in self.import_source: |
1542 | 97 | if self.stop_import_flag: | 96 | if self.stop_import_flag: |
1543 | 98 | return | 97 | return |
1544 | 99 | self.ssp_verse_order_list = [] | 98 | self.ssp_verse_order_list = [] |
1545 | 100 | self.other_count = 0 | 99 | self.other_count = 0 |
1546 | 101 | self.other_list = {} | 100 | self.other_list = {} |
1632 | 102 | file_name = os.path.split(file)[1] | 101 | self.import_wizard.increment_progress_bar(WizardStrings.ImportingType.format(source=file_path.name), 0) |
1633 | 103 | self.import_wizard.increment_progress_bar(WizardStrings.ImportingType.format(source=file_name), 0) | 102 | with file_path.open('rb') as song_file: |
1634 | 104 | song_data = open(file, 'rb') | 103 | while True: |
1635 | 105 | while True: | 104 | block_key, = struct.unpack("I", song_file.read(4)) |
1636 | 106 | block_key, = struct.unpack("I", song_data.read(4)) | 105 | log.debug('block_key: %d' % block_key) |
1637 | 107 | log.debug('block_key: %d' % block_key) | 106 | # The file ends with 4 NULL's |
1638 | 108 | # The file ends with 4 NULL's | 107 | if block_key == 0: |
1639 | 109 | if block_key == 0: | 108 | break |
1640 | 110 | break | 109 | next_block_starts, = struct.unpack("I", song_file.read(4)) |
1641 | 111 | next_block_starts, = struct.unpack("I", song_data.read(4)) | 110 | next_block_starts += song_file.tell() |
1642 | 112 | next_block_starts += song_data.tell() | 111 | if block_key in (VERSE, CHORUS, BRIDGE): |
1643 | 113 | if block_key in (VERSE, CHORUS, BRIDGE): | 112 | null, verse_no, = struct.unpack("BB", song_file.read(2)) |
1644 | 114 | null, verse_no, = struct.unpack("BB", song_data.read(2)) | 113 | elif block_key == CUSTOM_VERSE: |
1645 | 115 | elif block_key == CUSTOM_VERSE: | 114 | null, verse_name_length, = struct.unpack("BB", song_file.read(2)) |
1646 | 116 | null, verse_name_length, = struct.unpack("BB", song_data.read(2)) | 115 | verse_name = self.decode(song_file.read(verse_name_length)) |
1647 | 117 | verse_name = self.decode(song_data.read(verse_name_length)) | 116 | length_descriptor_size, = struct.unpack("B", song_file.read(1)) |
1648 | 118 | length_descriptor_size, = struct.unpack("B", song_data.read(1)) | 117 | log.debug('length_descriptor_size: %d' % length_descriptor_size) |
1649 | 119 | log.debug('length_descriptor_size: %d' % length_descriptor_size) | 118 | # In the case of song_numbers the number is in the data from the |
1650 | 120 | # In the case of song_numbers the number is in the data from the | 119 | # current position to the next block starts |
1651 | 121 | # current position to the next block starts | 120 | if block_key == SONG_NUMBER: |
1652 | 122 | if block_key == SONG_NUMBER: | 121 | sn_bytes = song_file.read(length_descriptor_size - 1) |
1653 | 123 | sn_bytes = song_data.read(length_descriptor_size - 1) | 122 | self.song_number = int.from_bytes(sn_bytes, byteorder='little') |
1654 | 124 | self.song_number = int.from_bytes(sn_bytes, byteorder='little') | 123 | continue |
1655 | 125 | continue | 124 | # Detect if/how long the length descriptor is |
1656 | 126 | # Detect if/how long the length descriptor is | 125 | if length_descriptor_size == 12 or length_descriptor_size == 20: |
1657 | 127 | if length_descriptor_size == 12 or length_descriptor_size == 20: | 126 | length_descriptor, = struct.unpack("I", song_file.read(4)) |
1658 | 128 | length_descriptor, = struct.unpack("I", song_data.read(4)) | 127 | elif length_descriptor_size == 2: |
1659 | 129 | elif length_descriptor_size == 2: | 128 | length_descriptor = 1 |
1660 | 130 | length_descriptor = 1 | 129 | elif length_descriptor_size == 9: |
1661 | 131 | elif length_descriptor_size == 9: | 130 | length_descriptor = 0 |
1662 | 132 | length_descriptor = 0 | 131 | else: |
1663 | 133 | else: | 132 | length_descriptor, = struct.unpack("B", song_file.read(1)) |
1664 | 134 | length_descriptor, = struct.unpack("B", song_data.read(1)) | 133 | log.debug('length_descriptor: %d' % length_descriptor) |
1665 | 135 | log.debug('length_descriptor: %d' % length_descriptor) | 134 | data = song_file.read(length_descriptor) |
1666 | 136 | data = song_data.read(length_descriptor) | 135 | log.debug(data) |
1667 | 137 | log.debug(data) | 136 | if block_key == TITLE: |
1668 | 138 | if block_key == TITLE: | 137 | self.title = self.decode(data) |
1669 | 139 | self.title = self.decode(data) | 138 | elif block_key == AUTHOR: |
1670 | 140 | elif block_key == AUTHOR: | 139 | authors = self.decode(data).split(" / ") |
1671 | 141 | authors = self.decode(data).split(" / ") | 140 | for author in authors: |
1672 | 142 | for author in authors: | 141 | if author.find(",") != -1: |
1673 | 143 | if author.find(",") != -1: | 142 | author_parts = author.split(", ") |
1674 | 144 | author_parts = author.split(", ") | 143 | author = author_parts[1] + " " + author_parts[0] |
1675 | 145 | author = author_parts[1] + " " + author_parts[0] | 144 | self.parse_author(author) |
1676 | 146 | self.parse_author(author) | 145 | elif block_key == COPYRIGHT: |
1677 | 147 | elif block_key == COPYRIGHT: | 146 | self.add_copyright(self.decode(data)) |
1678 | 148 | self.add_copyright(self.decode(data)) | 147 | elif block_key == CCLI_NO: |
1679 | 149 | elif block_key == CCLI_NO: | 148 | # Try to get the CCLI number even if the field contains additional text |
1680 | 150 | # Try to get the CCLI number even if the field contains additional text | 149 | match = re.search(r'\d+', self.decode(data)) |
1681 | 151 | match = re.search(r'\d+', self.decode(data)) | 150 | if match: |
1682 | 152 | if match: | 151 | self.ccli_number = int(match.group()) |
1683 | 153 | self.ccli_number = int(match.group()) | 152 | else: |
1684 | 154 | else: | 153 | log.warning("Can't parse CCLI Number from string: {text}".format(text=self.decode(data))) |
1685 | 155 | log.warning("Can't parse CCLI Number from string: {text}".format(text=self.decode(data))) | 154 | elif block_key == VERSE: |
1686 | 156 | elif block_key == VERSE: | 155 | self.add_verse(self.decode(data), "{tag}{number}".format(tag=VerseType.tags[VerseType.Verse], |
1687 | 157 | self.add_verse(self.decode(data), "{tag}{number}".format(tag=VerseType.tags[VerseType.Verse], | 156 | number=verse_no)) |
1688 | 158 | number=verse_no)) | 157 | elif block_key == CHORUS: |
1689 | 159 | elif block_key == CHORUS: | 158 | self.add_verse(self.decode(data), "{tag}{number}".format(tag=VerseType.tags[VerseType.Chorus], |
1690 | 160 | self.add_verse(self.decode(data), "{tag}{number}".format(tag=VerseType.tags[VerseType.Chorus], | 159 | number=verse_no)) |
1691 | 161 | number=verse_no)) | 160 | elif block_key == BRIDGE: |
1692 | 162 | elif block_key == BRIDGE: | 161 | self.add_verse(self.decode(data), "{tag}{number}".format(tag=VerseType.tags[VerseType.Bridge], |
1693 | 163 | self.add_verse(self.decode(data), "{tag}{number}".format(tag=VerseType.tags[VerseType.Bridge], | 162 | number=verse_no)) |
1694 | 164 | number=verse_no)) | 163 | elif block_key == TOPIC: |
1695 | 165 | elif block_key == TOPIC: | 164 | self.topics.append(self.decode(data)) |
1696 | 166 | self.topics.append(self.decode(data)) | 165 | elif block_key == COMMENTS: |
1697 | 167 | elif block_key == COMMENTS: | 166 | self.comments = self.decode(data) |
1698 | 168 | self.comments = self.decode(data) | 167 | elif block_key == VERSE_ORDER: |
1699 | 169 | elif block_key == VERSE_ORDER: | 168 | verse_tag = self.to_openlp_verse_tag(self.decode(data), True) |
1700 | 170 | verse_tag = self.to_openlp_verse_tag(self.decode(data), True) | 169 | if verse_tag: |
1701 | 171 | if verse_tag: | 170 | if not isinstance(verse_tag, str): |
1702 | 172 | if not isinstance(verse_tag, str): | 171 | verse_tag = self.decode(verse_tag) |
1703 | 173 | verse_tag = self.decode(verse_tag) | 172 | self.ssp_verse_order_list.append(verse_tag) |
1704 | 174 | self.ssp_verse_order_list.append(verse_tag) | 173 | elif block_key == SONG_BOOK: |
1705 | 175 | elif block_key == SONG_BOOK: | 174 | self.song_book_name = self.decode(data) |
1706 | 176 | self.song_book_name = self.decode(data) | 175 | elif block_key == CUSTOM_VERSE: |
1707 | 177 | elif block_key == CUSTOM_VERSE: | 176 | verse_tag = self.to_openlp_verse_tag(verse_name) |
1708 | 178 | verse_tag = self.to_openlp_verse_tag(verse_name) | 177 | self.add_verse(self.decode(data), verse_tag) |
1709 | 179 | self.add_verse(self.decode(data), verse_tag) | 178 | else: |
1710 | 180 | else: | 179 | log.debug("Unrecognised blockKey: {key}, data: {data}".format(key=block_key, data=data)) |
1711 | 181 | log.debug("Unrecognised blockKey: {key}, data: {data}".format(key=block_key, data=data)) | 180 | song_file.seek(next_block_starts) |
1712 | 182 | song_data.seek(next_block_starts) | 181 | self.verse_order_list = self.ssp_verse_order_list |
1713 | 183 | self.verse_order_list = self.ssp_verse_order_list | 182 | if not self.finish(): |
1714 | 184 | song_data.close() | 183 | self.log_error(file_path) |
1630 | 185 | if not self.finish(): | ||
1631 | 186 | self.log_error(file) | ||
1715 | 187 | 184 | ||
1716 | 188 | def to_openlp_verse_tag(self, verse_name, ignore_unique=False): | 185 | def to_openlp_verse_tag(self, verse_name, ignore_unique=False): |
1717 | 189 | """ | 186 | """ |
1718 | 190 | 187 | ||
1719 | === modified file 'openlp/plugins/songs/lib/importers/sundayplus.py' | |||
1720 | --- openlp/plugins/songs/lib/importers/sundayplus.py 2016-12-31 11:01:36 +0000 | |||
1721 | +++ openlp/plugins/songs/lib/importers/sundayplus.py 2017-09-30 23:24:21 +0000 | |||
1722 | @@ -19,11 +19,8 @@ | |||
1723 | 19 | # with this program; if not, write to the Free Software Foundation, Inc., 59 # | 19 | # with this program; if not, write to the Free Software Foundation, Inc., 59 # |
1724 | 20 | # Temple Place, Suite 330, Boston, MA 02111-1307 USA # | 20 | # Temple Place, Suite 330, Boston, MA 02111-1307 USA # |
1725 | 21 | ############################################################################### | 21 | ############################################################################### |
1726 | 22 | |||
1727 | 23 | import os | 22 | import os |
1728 | 24 | import re | 23 | import re |
1729 | 25 | import logging | ||
1730 | 26 | |||
1731 | 27 | 24 | ||
1732 | 28 | from openlp.plugins.songs.lib import VerseType, retrieve_windows_encoding | 25 | from openlp.plugins.songs.lib import VerseType, retrieve_windows_encoding |
1733 | 29 | from openlp.plugins.songs.lib import strip_rtf | 26 | from openlp.plugins.songs.lib import strip_rtf |
1734 | @@ -60,12 +57,11 @@ | |||
1735 | 60 | 57 | ||
1736 | 61 | def do_import(self): | 58 | def do_import(self): |
1737 | 62 | self.import_wizard.progress_bar.setMaximum(len(self.import_source)) | 59 | self.import_wizard.progress_bar.setMaximum(len(self.import_source)) |
1739 | 63 | for filename in self.import_source: | 60 | for file_path in self.import_source: |
1740 | 64 | if self.stop_import_flag: | 61 | if self.stop_import_flag: |
1741 | 65 | return | 62 | return |
1745 | 66 | song_file = open(filename, 'rb') | 63 | with file_path.open('rb') as song_file: |
1746 | 67 | self.do_import_file(song_file) | 64 | self.do_import_file(song_file) |
1744 | 68 | song_file.close() | ||
1747 | 69 | 65 | ||
1748 | 70 | def do_import_file(self, file): | 66 | def do_import_file(self, file): |
1749 | 71 | """ | 67 | """ |
1750 | 72 | 68 | ||
1751 | === modified file 'openlp/plugins/songs/lib/importers/videopsalm.py' | |||
1752 | --- openlp/plugins/songs/lib/importers/videopsalm.py 2017-02-26 21:14:49 +0000 | |||
1753 | +++ openlp/plugins/songs/lib/importers/videopsalm.py 2017-09-30 23:24:21 +0000 | |||
1754 | @@ -22,13 +22,12 @@ | |||
1755 | 22 | """ | 22 | """ |
1756 | 23 | The :mod:`lyrix` module provides the functionality for importing songs which are | 23 | The :mod:`lyrix` module provides the functionality for importing songs which are |
1757 | 24 | exproted from Lyrix.""" | 24 | exproted from Lyrix.""" |
1759 | 25 | 25 | import json | |
1760 | 26 | import logging | 26 | import logging |
1761 | 27 | import json | ||
1762 | 28 | import os | ||
1763 | 29 | import re | 27 | import re |
1764 | 30 | 28 | ||
1765 | 31 | from openlp.core.common import translate, Settings | 29 | from openlp.core.common import translate, Settings |
1766 | 30 | from openlp.core.common.path import Path | ||
1767 | 32 | from openlp.plugins.songs.lib.importers.songimport import SongImport | 31 | from openlp.plugins.songs.lib.importers.songimport import SongImport |
1768 | 33 | from openlp.plugins.songs.lib.db import AuthorType | 32 | from openlp.plugins.songs.lib.db import AuthorType |
1769 | 34 | 33 | ||
1770 | @@ -50,11 +49,10 @@ | |||
1771 | 50 | """ | 49 | """ |
1772 | 51 | Process the VideoPsalm file - pass in a file-like object, not a file path. | 50 | Process the VideoPsalm file - pass in a file-like object, not a file path. |
1773 | 52 | """ | 51 | """ |
1774 | 52 | self.import_source = Path(self.import_source) | ||
1775 | 53 | self.set_defaults() | 53 | self.set_defaults() |
1776 | 54 | # Open SongBook file | ||
1777 | 55 | song_file = open(self.import_source, 'rt', encoding='utf-8-sig') | ||
1778 | 56 | try: | 54 | try: |
1780 | 57 | file_content = song_file.read() | 55 | file_content = self.import_source.read_text(encoding='utf-8-sig') |
1781 | 58 | processed_content = '' | 56 | processed_content = '' |
1782 | 59 | inside_quotes = False | 57 | inside_quotes = False |
1783 | 60 | # The VideoPsalm format is not valid json, it uses illegal line breaks and unquoted keys, this must be fixed | 58 | # The VideoPsalm format is not valid json, it uses illegal line breaks and unquoted keys, this must be fixed |
1784 | @@ -89,7 +87,7 @@ | |||
1785 | 89 | songs = songbook['Songs'] | 87 | songs = songbook['Songs'] |
1786 | 90 | self.import_wizard.progress_bar.setMaximum(len(songs)) | 88 | self.import_wizard.progress_bar.setMaximum(len(songs)) |
1787 | 91 | songbook_name = songbook['Text'] | 89 | songbook_name = songbook['Text'] |
1789 | 92 | media_folder = os.path.normpath(os.path.join(os.path.dirname(song_file.name), '..', 'Audio')) | 90 | media_path = Path('..', 'Audio') |
1790 | 93 | for song in songs: | 91 | for song in songs: |
1791 | 94 | self.song_book_name = songbook_name | 92 | self.song_book_name = songbook_name |
1792 | 95 | if 'Text' in song: | 93 | if 'Text' in song: |
1793 | @@ -114,7 +112,7 @@ | |||
1794 | 114 | if 'Theme' in song: | 112 | if 'Theme' in song: |
1795 | 115 | self.topics = song['Theme'].splitlines() | 113 | self.topics = song['Theme'].splitlines() |
1796 | 116 | if 'AudioFile' in song: | 114 | if 'AudioFile' in song: |
1798 | 117 | self.add_media_file(os.path.join(media_folder, song['AudioFile'])) | 115 | self.add_media_file(media_path / song['AudioFile']) |
1799 | 118 | if 'Memo1' in song: | 116 | if 'Memo1' in song: |
1800 | 119 | self.add_comment(song['Memo1']) | 117 | self.add_comment(song['Memo1']) |
1801 | 120 | if 'Memo2' in song: | 118 | if 'Memo2' in song: |
1802 | @@ -132,4 +130,5 @@ | |||
1803 | 132 | if not self.finish(): | 130 | if not self.finish(): |
1804 | 133 | self.log_error('Could not import {title}'.format(title=self.title)) | 131 | self.log_error('Could not import {title}'.format(title=self.title)) |
1805 | 134 | except Exception as e: | 132 | except Exception as e: |
1807 | 135 | self.log_error(song_file.name, translate('SongsPlugin.VideoPsalmImport', 'Error: {error}').format(error=e)) | 133 | self.log_error(self.import_source.name, |
1808 | 134 | translate('SongsPlugin.VideoPsalmImport', 'Error: {error}').format(error=e)) | ||
1809 | 136 | 135 | ||
1810 | === modified file 'openlp/plugins/songs/lib/importers/wordsofworship.py' | |||
1811 | --- openlp/plugins/songs/lib/importers/wordsofworship.py 2016-12-31 11:01:36 +0000 | |||
1812 | +++ openlp/plugins/songs/lib/importers/wordsofworship.py 2017-09-30 23:24:21 +0000 | |||
1813 | @@ -25,6 +25,7 @@ | |||
1814 | 25 | """ | 25 | """ |
1815 | 26 | import os | 26 | import os |
1816 | 27 | import logging | 27 | import logging |
1817 | 28 | from openlp.core.common.path import Path | ||
1818 | 28 | 29 | ||
1819 | 29 | from openlp.core.common import translate | 30 | from openlp.core.common import translate |
1820 | 30 | from openlp.plugins.songs.lib.importers.songimport import SongImport | 31 | from openlp.plugins.songs.lib.importers.songimport import SongImport |
1821 | @@ -100,62 +101,60 @@ | |||
1822 | 100 | """ | 101 | """ |
1823 | 101 | if isinstance(self.import_source, list): | 102 | if isinstance(self.import_source, list): |
1824 | 102 | self.import_wizard.progress_bar.setMaximum(len(self.import_source)) | 103 | self.import_wizard.progress_bar.setMaximum(len(self.import_source)) |
1826 | 103 | for source in self.import_source: | 104 | for file_path in self.import_source: |
1827 | 104 | if self.stop_import_flag: | 105 | if self.stop_import_flag: |
1828 | 105 | return | 106 | return |
1829 | 106 | self.set_defaults() | 107 | self.set_defaults() |
1885 | 107 | song_data = open(source, 'rb') | 108 | with file_path.open('rb') as song_data: |
1886 | 108 | if song_data.read(19).decode() != 'WoW File\nSong Words': | 109 | if song_data.read(19).decode() != 'WoW File\nSong Words': |
1887 | 109 | self.log_error(source, | 110 | self.log_error(file_path, |
1888 | 110 | translate('SongsPlugin.WordsofWorshipSongImport', | 111 | translate('SongsPlugin.WordsofWorshipSongImport', |
1889 | 111 | 'Invalid Words of Worship song file. Missing "{text}" ' | 112 | 'Invalid Words of Worship song file. Missing "{text}" ' |
1890 | 112 | 'header.').format(text='WoW File\\nSong Words')) | 113 | 'header.').format(text='WoW File\\nSong Words')) |
1891 | 113 | continue | 114 | continue |
1892 | 114 | # Seek to byte which stores number of blocks in the song | 115 | # Seek to byte which stores number of blocks in the song |
1893 | 115 | song_data.seek(56) | 116 | song_data.seek(56) |
1894 | 116 | no_of_blocks = ord(song_data.read(1)) | 117 | no_of_blocks = ord(song_data.read(1)) |
1895 | 117 | song_data.seek(66) | 118 | song_data.seek(66) |
1896 | 118 | if song_data.read(16).decode() != 'CSongDoc::CBlock': | 119 | if song_data.read(16).decode() != 'CSongDoc::CBlock': |
1897 | 119 | self.log_error(source, | 120 | self.log_error(file_path, |
1898 | 120 | translate('SongsPlugin.WordsofWorshipSongImport', | 121 | translate('SongsPlugin.WordsofWorshipSongImport', |
1899 | 121 | 'Invalid Words of Worship song file. Missing "{text}" ' | 122 | 'Invalid Words of Worship song file. Missing "{text}" ' |
1900 | 122 | 'string.').format(text='CSongDoc::CBlock')) | 123 | 'string.').format(text='CSongDoc::CBlock')) |
1901 | 123 | continue | 124 | continue |
1902 | 124 | # Seek to the beginning of the first block | 125 | # Seek to the beginning of the first block |
1903 | 125 | song_data.seek(82) | 126 | song_data.seek(82) |
1904 | 126 | for block in range(no_of_blocks): | 127 | for block in range(no_of_blocks): |
1905 | 127 | skip_char_at_end = True | 128 | skip_char_at_end = True |
1906 | 128 | self.lines_to_read = ord(song_data.read(4)[:1]) | 129 | self.lines_to_read = ord(song_data.read(4)[:1]) |
1907 | 129 | block_text = '' | 130 | block_text = '' |
1908 | 130 | while self.lines_to_read: | 131 | while self.lines_to_read: |
1909 | 131 | self.line_text = str(song_data.read(ord(song_data.read(1))), 'cp1252') | 132 | self.line_text = str(song_data.read(ord(song_data.read(1))), 'cp1252') |
1910 | 132 | if skip_char_at_end: | 133 | if skip_char_at_end: |
1911 | 133 | skip_char = ord(song_data.read(1)) | 134 | skip_char = ord(song_data.read(1)) |
1912 | 134 | # Check if we really should skip a char. In some wsg files we shouldn't | 135 | # Check if we really should skip a char. In some wsg files we shouldn't |
1913 | 135 | if skip_char != 0: | 136 | if skip_char != 0: |
1914 | 136 | song_data.seek(-1, os.SEEK_CUR) | 137 | song_data.seek(-1, os.SEEK_CUR) |
1915 | 137 | skip_char_at_end = False | 138 | skip_char_at_end = False |
1916 | 138 | if block_text: | 139 | if block_text: |
1917 | 139 | block_text += '\n' | 140 | block_text += '\n' |
1918 | 140 | block_text += self.line_text | 141 | block_text += self.line_text |
1919 | 141 | self.lines_to_read -= 1 | 142 | self.lines_to_read -= 1 |
1920 | 142 | block_type = BLOCK_TYPES[ord(song_data.read(4)[:1])] | 143 | block_type = BLOCK_TYPES[ord(song_data.read(4)[:1])] |
1921 | 143 | # Blocks are separated by 2 bytes, skip them, but not if | 144 | # Blocks are separated by 2 bytes, skip them, but not if |
1922 | 144 | # this is the last block! | 145 | # this is the last block! |
1923 | 145 | if block + 1 < no_of_blocks: | 146 | if block + 1 < no_of_blocks: |
1924 | 146 | song_data.seek(2, os.SEEK_CUR) | 147 | song_data.seek(2, os.SEEK_CUR) |
1925 | 147 | self.add_verse(block_text, block_type) | 148 | self.add_verse(block_text, block_type) |
1926 | 148 | # Now to extract the author | 149 | # Now to extract the author |
1927 | 149 | author_length = ord(song_data.read(1)) | 150 | author_length = ord(song_data.read(1)) |
1928 | 150 | if author_length: | 151 | if author_length: |
1929 | 151 | self.parse_author(str(song_data.read(author_length), 'cp1252')) | 152 | self.parse_author(str(song_data.read(author_length), 'cp1252')) |
1930 | 152 | # Finally the copyright | 153 | # Finally the copyright |
1931 | 153 | copyright_length = ord(song_data.read(1)) | 154 | copyright_length = ord(song_data.read(1)) |
1932 | 154 | if copyright_length: | 155 | if copyright_length: |
1933 | 155 | self.add_copyright(str(song_data.read(copyright_length), 'cp1252')) | 156 | self.add_copyright(str(song_data.read(copyright_length), 'cp1252')) |
1934 | 156 | file_name = os.path.split(source)[1] | 157 | # Get the song title |
1935 | 157 | # Get the song title | 158 | self.title = file_path.stem |
1936 | 158 | self.title = file_name.rpartition('.')[0] | 159 | if not self.finish(): |
1937 | 159 | song_data.close() | 160 | self.log_error(file_path) |
1883 | 160 | if not self.finish(): | ||
1884 | 161 | self.log_error(source) | ||
1938 | 162 | 161 | ||
1939 | === modified file 'openlp/plugins/songs/lib/importers/worshipassistant.py' | |||
1940 | --- openlp/plugins/songs/lib/importers/worshipassistant.py 2016-12-31 11:01:36 +0000 | |||
1941 | +++ openlp/plugins/songs/lib/importers/worshipassistant.py 2017-09-30 23:24:21 +0000 | |||
1942 | @@ -28,7 +28,7 @@ | |||
1943 | 28 | import logging | 28 | import logging |
1944 | 29 | import re | 29 | import re |
1945 | 30 | 30 | ||
1947 | 31 | from openlp.core.common import translate | 31 | from openlp.core.common import get_file_encoding, translate |
1948 | 32 | from openlp.plugins.songs.lib import VerseType | 32 | from openlp.plugins.songs.lib import VerseType |
1949 | 33 | from openlp.plugins.songs.lib.importers.songimport import SongImport | 33 | from openlp.plugins.songs.lib.importers.songimport import SongImport |
1950 | 34 | 34 | ||
1951 | @@ -81,19 +81,16 @@ | |||
1952 | 81 | Receive a CSV file to import. | 81 | Receive a CSV file to import. |
1953 | 82 | """ | 82 | """ |
1954 | 83 | # Get encoding | 83 | # Get encoding |
1968 | 84 | detect_file = open(self.import_source, 'rb') | 84 | encoding = get_file_encoding(self.import_source)['encoding'] |
1969 | 85 | detect_content = detect_file.read() | 85 | with self.import_source.open('r', encoding=encoding) as songs_file: |
1970 | 86 | details = chardet.detect(detect_content) | 86 | songs_reader = csv.DictReader(songs_file, escapechar='\\') |
1971 | 87 | detect_file.close() | 87 | try: |
1972 | 88 | songs_file = open(self.import_source, 'r', encoding=details['encoding']) | 88 | records = list(songs_reader) |
1973 | 89 | songs_reader = csv.DictReader(songs_file, escapechar='\\') | 89 | except csv.Error as e: |
1974 | 90 | try: | 90 | self.log_error(translate('SongsPlugin.WorshipAssistantImport', 'Error reading CSV file.'), |
1975 | 91 | records = list(songs_reader) | 91 | translate('SongsPlugin.WorshipAssistantImport', |
1976 | 92 | except csv.Error as e: | 92 | 'Line {number:d}: {error}').format(number=songs_reader.line_num, error=e)) |
1977 | 93 | self.log_error(translate('SongsPlugin.WorshipAssistantImport', 'Error reading CSV file.'), | 93 | return |
1965 | 94 | translate('SongsPlugin.WorshipAssistantImport', | ||
1966 | 95 | 'Line {number:d}: {error}').format(number=songs_reader.line_num, error=e)) | ||
1967 | 96 | return | ||
1978 | 97 | num_records = len(records) | 94 | num_records = len(records) |
1979 | 98 | log.info('{count} records found in CSV file'.format(count=num_records)) | 95 | log.info('{count} records found in CSV file'.format(count=num_records)) |
1980 | 99 | self.import_wizard.progress_bar.setMaximum(num_records) | 96 | self.import_wizard.progress_bar.setMaximum(num_records) |
1981 | @@ -185,4 +182,3 @@ | |||
1982 | 185 | self.log_error(translate('SongsPlugin.WorshipAssistantImport', | 182 | self.log_error(translate('SongsPlugin.WorshipAssistantImport', |
1983 | 186 | 'Record {count:d}').format(count=index) + | 183 | 'Record {count:d}').format(count=index) + |
1984 | 187 | (': "' + self.title + '"' if self.title else '')) | 184 | (': "' + self.title + '"' if self.title else '')) |
1985 | 188 | songs_file.close() | ||
1986 | 189 | 185 | ||
1987 | === modified file 'openlp/plugins/songs/lib/importers/zionworx.py' | |||
1988 | --- openlp/plugins/songs/lib/importers/zionworx.py 2016-12-31 11:01:36 +0000 | |||
1989 | +++ openlp/plugins/songs/lib/importers/zionworx.py 2017-09-30 23:24:21 +0000 | |||
1990 | @@ -76,7 +76,7 @@ | |||
1991 | 76 | Receive a CSV file (from a ZionWorx database dump) to import. | 76 | Receive a CSV file (from a ZionWorx database dump) to import. |
1992 | 77 | """ | 77 | """ |
1993 | 78 | # Encoding should always be ISO-8859-1 | 78 | # Encoding should always be ISO-8859-1 |
1995 | 79 | with open(self.import_source, 'rt', encoding='ISO-8859-1') as songs_file: | 79 | with self.import_source.open('rt', encoding='ISO-8859-1') as songs_file: |
1996 | 80 | field_names = ['SongNum', 'Title1', 'Title2', 'Lyrics', 'Writer', 'Copyright', 'Keywords', | 80 | field_names = ['SongNum', 'Title1', 'Title2', 'Lyrics', 'Writer', 'Copyright', 'Keywords', |
1997 | 81 | 'DefaultStyle'] | 81 | 'DefaultStyle'] |
1998 | 82 | songs_reader = csv.DictReader(songs_file, field_names) | 82 | songs_reader = csv.DictReader(songs_file, field_names) |
1999 | 83 | 83 | ||
2000 | === modified file 'openlp/plugins/songs/lib/mediaitem.py' | |||
2001 | --- openlp/plugins/songs/lib/mediaitem.py 2017-08-25 20:03:25 +0000 | |||
2002 | +++ openlp/plugins/songs/lib/mediaitem.py 2017-09-30 23:24:21 +0000 | |||
2003 | @@ -22,25 +22,24 @@ | |||
2004 | 22 | 22 | ||
2005 | 23 | import logging | 23 | import logging |
2006 | 24 | import os | 24 | import os |
2007 | 25 | import shutil | ||
2008 | 26 | 25 | ||
2009 | 27 | from PyQt5 import QtCore, QtWidgets | 26 | from PyQt5 import QtCore, QtWidgets |
2010 | 28 | from sqlalchemy.sql import and_, or_ | 27 | from sqlalchemy.sql import and_, or_ |
2011 | 29 | 28 | ||
2012 | 30 | from openlp.core.common import Registry, AppLocation, Settings, check_directory_exists, UiStrings, translate | 29 | from openlp.core.common import Registry, AppLocation, Settings, check_directory_exists, UiStrings, translate |
2014 | 31 | from openlp.core.common.path import Path | 30 | from openlp.core.common.languagemanager import get_natural_key |
2015 | 31 | from openlp.core.common.path import copyfile | ||
2016 | 32 | from openlp.core.lib import MediaManagerItem, ItemCapabilities, PluginStatus, ServiceItemContext, \ | 32 | from openlp.core.lib import MediaManagerItem, ItemCapabilities, PluginStatus, ServiceItemContext, \ |
2017 | 33 | check_item_selected, create_separated_list | 33 | check_item_selected, create_separated_list |
2018 | 34 | from openlp.core.lib.ui import create_widget_action | 34 | from openlp.core.lib.ui import create_widget_action |
2019 | 35 | from openlp.core.common.languagemanager import get_natural_key | ||
2020 | 36 | from openlp.plugins.songs.forms.editsongform import EditSongForm | 35 | from openlp.plugins.songs.forms.editsongform import EditSongForm |
2021 | 36 | from openlp.plugins.songs.forms.songexportform import SongExportForm | ||
2022 | 37 | from openlp.plugins.songs.forms.songimportform import SongImportForm | ||
2023 | 37 | from openlp.plugins.songs.forms.songmaintenanceform import SongMaintenanceForm | 38 | from openlp.plugins.songs.forms.songmaintenanceform import SongMaintenanceForm |
2024 | 38 | from openlp.plugins.songs.forms.songimportform import SongImportForm | ||
2025 | 39 | from openlp.plugins.songs.forms.songexportform import SongExportForm | ||
2026 | 40 | from openlp.plugins.songs.lib import VerseType, clean_string, delete_song | 39 | from openlp.plugins.songs.lib import VerseType, clean_string, delete_song |
2027 | 41 | from openlp.plugins.songs.lib.db import Author, AuthorType, Song, Book, MediaFile, SongBookEntry, Topic | 40 | from openlp.plugins.songs.lib.db import Author, AuthorType, Song, Book, MediaFile, SongBookEntry, Topic |
2028 | 41 | from openlp.plugins.songs.lib.openlyricsxml import OpenLyrics, SongXML | ||
2029 | 42 | from openlp.plugins.songs.lib.ui import SongStrings | 42 | from openlp.plugins.songs.lib.ui import SongStrings |
2030 | 43 | from openlp.plugins.songs.lib.openlyricsxml import OpenLyrics, SongXML | ||
2031 | 44 | 43 | ||
2032 | 45 | log = logging.getLogger(__name__) | 44 | log = logging.getLogger(__name__) |
2033 | 46 | 45 | ||
2034 | @@ -88,11 +87,11 @@ | |||
2035 | 88 | def _update_background_audio(self, song, item): | 87 | def _update_background_audio(self, song, item): |
2036 | 89 | song.media_files = [] | 88 | song.media_files = [] |
2037 | 90 | for i, bga in enumerate(item.background_audio): | 89 | for i, bga in enumerate(item.background_audio): |
2043 | 91 | dest_file = os.path.join( | 90 | dest_path =\ |
2044 | 92 | str(AppLocation.get_section_data_path(self.plugin.name)), 'audio', str(song.id), os.path.split(bga)[1]) | 91 | AppLocation.get_section_data_path(self.plugin.name) / 'audio' / str(song.id) / os.path.split(bga)[1] |
2045 | 93 | check_directory_exists(Path(os.path.split(dest_file)[0])) | 92 | check_directory_exists(dest_path.parent) |
2046 | 94 | shutil.copyfile(os.path.join(str(AppLocation.get_section_data_path('servicemanager')), bga), dest_file) | 93 | copyfile(AppLocation.get_section_data_path('servicemanager') / bga, dest_path) |
2047 | 95 | song.media_files.append(MediaFile.populate(weight=i, file_name=dest_file)) | 94 | song.media_files.append(MediaFile.populate(weight=i, file_path=dest_path)) |
2048 | 96 | self.plugin.manager.save_object(song, True) | 95 | self.plugin.manager.save_object(song, True) |
2049 | 97 | 96 | ||
2050 | 98 | def add_end_header_bar(self): | 97 | def add_end_header_bar(self): |
2051 | @@ -534,14 +533,13 @@ | |||
2052 | 534 | 'copy', 'For song cloning')) | 533 | 'copy', 'For song cloning')) |
2053 | 535 | # Copy audio files from the old to the new song | 534 | # Copy audio files from the old to the new song |
2054 | 536 | if len(old_song.media_files) > 0: | 535 | if len(old_song.media_files) > 0: |
2058 | 537 | save_path = os.path.join( | 536 | save_path = AppLocation.get_section_data_path(self.plugin.name) / 'audio' / str(new_song.id) |
2059 | 538 | str(AppLocation.get_section_data_path(self.plugin.name)), 'audio', str(new_song.id)) | 537 | check_directory_exists(save_path) |
2057 | 539 | check_directory_exists(Path(save_path)) | ||
2060 | 540 | for media_file in old_song.media_files: | 538 | for media_file in old_song.media_files: |
2063 | 541 | new_media_file_name = os.path.join(save_path, os.path.basename(media_file.file_name)) | 539 | new_media_file_path = save_path / media_file.file_path.name |
2064 | 542 | shutil.copyfile(media_file.file_name, new_media_file_name) | 540 | copyfile(media_file.file_path, new_media_file_path) |
2065 | 543 | new_media_file = MediaFile() | 541 | new_media_file = MediaFile() |
2067 | 544 | new_media_file.file_name = new_media_file_name | 542 | new_media_file.file_path = new_media_file_path |
2068 | 545 | new_media_file.type = media_file.type | 543 | new_media_file.type = media_file.type |
2069 | 546 | new_media_file.weight = media_file.weight | 544 | new_media_file.weight = media_file.weight |
2070 | 547 | new_song.media_files.append(new_media_file) | 545 | new_song.media_files.append(new_media_file) |
2071 | @@ -613,7 +611,7 @@ | |||
2072 | 613 | # Add the audio file to the service item. | 611 | # Add the audio file to the service item. |
2073 | 614 | if song.media_files: | 612 | if song.media_files: |
2074 | 615 | service_item.add_capability(ItemCapabilities.HasBackgroundAudio) | 613 | service_item.add_capability(ItemCapabilities.HasBackgroundAudio) |
2076 | 616 | service_item.background_audio = [m.file_name for m in song.media_files] | 614 | service_item.background_audio = [m.file_path for m in song.media_files] |
2077 | 617 | return True | 615 | return True |
2078 | 618 | 616 | ||
2079 | 619 | def generate_footer(self, item, song): | 617 | def generate_footer(self, item, song): |
2080 | 620 | 618 | ||
2081 | === modified file 'openlp/plugins/songs/lib/openlyricsexport.py' | |||
2082 | --- openlp/plugins/songs/lib/openlyricsexport.py 2017-08-25 20:03:25 +0000 | |||
2083 | +++ openlp/plugins/songs/lib/openlyricsexport.py 2017-09-30 23:24:21 +0000 | |||
2084 | @@ -24,12 +24,10 @@ | |||
2085 | 24 | format. | 24 | format. |
2086 | 25 | """ | 25 | """ |
2087 | 26 | import logging | 26 | import logging |
2088 | 27 | import os | ||
2089 | 28 | 27 | ||
2090 | 29 | from lxml import etree | 28 | from lxml import etree |
2091 | 30 | 29 | ||
2092 | 31 | from openlp.core.common import RegistryProperties, check_directory_exists, translate, clean_filename | 30 | from openlp.core.common import RegistryProperties, check_directory_exists, translate, clean_filename |
2093 | 32 | from openlp.core.common.path import Path | ||
2094 | 33 | from openlp.plugins.songs.lib.openlyricsxml import OpenLyrics | 31 | from openlp.plugins.songs.lib.openlyricsxml import OpenLyrics |
2095 | 34 | 32 | ||
2096 | 35 | log = logging.getLogger(__name__) | 33 | log = logging.getLogger(__name__) |
2097 | @@ -42,13 +40,16 @@ | |||
2098 | 42 | def __init__(self, parent, songs, save_path): | 40 | def __init__(self, parent, songs, save_path): |
2099 | 43 | """ | 41 | """ |
2100 | 44 | Initialise the export. | 42 | Initialise the export. |
2101 | 43 | |||
2102 | 44 | :param openlp.core.common.path.Path save_path: The directory to save the exported songs in | ||
2103 | 45 | :rtype: None | ||
2104 | 45 | """ | 46 | """ |
2105 | 46 | log.debug('initialise OpenLyricsExport') | 47 | log.debug('initialise OpenLyricsExport') |
2106 | 47 | self.parent = parent | 48 | self.parent = parent |
2107 | 48 | self.manager = parent.plugin.manager | 49 | self.manager = parent.plugin.manager |
2108 | 49 | self.songs = songs | 50 | self.songs = songs |
2109 | 50 | self.save_path = save_path | 51 | self.save_path = save_path |
2111 | 51 | check_directory_exists(Path(self.save_path)) | 52 | check_directory_exists(self.save_path) |
2112 | 52 | 53 | ||
2113 | 53 | def do_export(self): | 54 | def do_export(self): |
2114 | 54 | """ | 55 | """ |
2115 | @@ -69,15 +70,15 @@ | |||
2116 | 69 | author=', '.join([author.display_name for author in song.authors])) | 70 | author=', '.join([author.display_name for author in song.authors])) |
2117 | 70 | filename = clean_filename(filename) | 71 | filename = clean_filename(filename) |
2118 | 71 | # Ensure the filename isn't too long for some filesystems | 72 | # Ensure the filename isn't too long for some filesystems |
2120 | 72 | filename_with_ext = '{name}.xml'.format(name=filename[0:250 - len(self.save_path)]) | 73 | path_length = len(str(self.save_path)) |
2121 | 74 | filename_with_ext = '{name}.xml'.format(name=filename[0:250 - path_length]) | ||
2122 | 73 | # Make sure we're not overwriting an existing file | 75 | # Make sure we're not overwriting an existing file |
2123 | 74 | conflicts = 0 | 76 | conflicts = 0 |
2125 | 75 | while os.path.exists(os.path.join(self.save_path, filename_with_ext)): | 77 | while (self.save_path / filename_with_ext).exists(): |
2126 | 76 | conflicts += 1 | 78 | conflicts += 1 |
2129 | 77 | filename_with_ext = '{name}-{extra}.xml'.format(name=filename[0:247 - len(self.save_path)], | 79 | filename_with_ext = '{name}-{extra}.xml'.format(name=filename[0:247 - path_length], extra=conflicts) |
2128 | 78 | extra=conflicts) | ||
2130 | 79 | # Pass a file object, because lxml does not cope with some special | 80 | # Pass a file object, because lxml does not cope with some special |
2131 | 80 | # characters in the path (see lp:757673 and lp:744337). | 81 | # characters in the path (see lp:757673 and lp:744337). |
2134 | 81 | tree.write(open(os.path.join(self.save_path, filename_with_ext), 'wb'), encoding='utf-8', | 82 | with (self.save_path / filename_with_ext).open('wb') as out_file: |
2135 | 82 | xml_declaration=True, pretty_print=True) | 83 | tree.write(out_file, encoding='utf-8', xml_declaration=True, pretty_print=True) |
2136 | 83 | return True | 84 | return True |
2137 | 84 | 85 | ||
2138 | === modified file 'openlp/plugins/songs/lib/upgrade.py' | |||
2139 | --- openlp/plugins/songs/lib/upgrade.py 2017-06-10 05:57:00 +0000 | |||
2140 | +++ openlp/plugins/songs/lib/upgrade.py 2017-09-30 23:24:21 +0000 | |||
2141 | @@ -23,16 +23,20 @@ | |||
2142 | 23 | The :mod:`upgrade` module provides a way for the database and schema that is the | 23 | The :mod:`upgrade` module provides a way for the database and schema that is the |
2143 | 24 | backend for the Songs plugin | 24 | backend for the Songs plugin |
2144 | 25 | """ | 25 | """ |
2145 | 26 | import json | ||
2146 | 26 | import logging | 27 | import logging |
2147 | 27 | 28 | ||
2148 | 28 | from sqlalchemy import Table, Column, ForeignKey, types | 29 | from sqlalchemy import Table, Column, ForeignKey, types |
2149 | 29 | from sqlalchemy.sql.expression import func, false, null, text | 30 | from sqlalchemy.sql.expression import func, false, null, text |
2150 | 30 | 31 | ||
2151 | 32 | from openlp.core.common import AppLocation | ||
2152 | 31 | from openlp.core.common.db import drop_columns | 33 | from openlp.core.common.db import drop_columns |
2154 | 32 | from openlp.core.lib.db import get_upgrade_op | 34 | from openlp.core.common.json import OpenLPJsonEncoder |
2155 | 35 | from openlp.core.common.path import Path | ||
2156 | 36 | from openlp.core.lib.db import PathType, get_upgrade_op | ||
2157 | 33 | 37 | ||
2158 | 34 | log = logging.getLogger(__name__) | 38 | log = logging.getLogger(__name__) |
2160 | 35 | __version__ = 6 | 39 | __version__ = 7 |
2161 | 36 | 40 | ||
2162 | 37 | 41 | ||
2163 | 38 | # TODO: When removing an upgrade path the ftw-data needs updating to the minimum supported version | 42 | # TODO: When removing an upgrade path the ftw-data needs updating to the minimum supported version |
2164 | @@ -162,3 +166,28 @@ | |||
2165 | 162 | op.drop_column('songs', 'song_number') | 166 | op.drop_column('songs', 'song_number') |
2166 | 163 | # Finally, clean up our mess in people's databases | 167 | # Finally, clean up our mess in people's databases |
2167 | 164 | op.execute('DELETE FROM songs_songbooks WHERE songbook_id = 0') | 168 | op.execute('DELETE FROM songs_songbooks WHERE songbook_id = 0') |
2168 | 169 | |||
2169 | 170 | |||
2170 | 171 | def upgrade_7(session, metadata): | ||
2171 | 172 | """ | ||
2172 | 173 | Version 7 upgrade - Move file path from old db to JSON encoded path to new db. Upgrade added in 2.5 dev | ||
2173 | 174 | """ | ||
2174 | 175 | log.debug('Starting upgrade_7 for file_path to JSON') | ||
2175 | 176 | old_table = Table('media_files', metadata, autoload=True) | ||
2176 | 177 | if 'file_path' not in [col.name for col in old_table.c.values()]: | ||
2177 | 178 | op = get_upgrade_op(session) | ||
2178 | 179 | op.add_column('media_files', Column('file_path', PathType())) | ||
2179 | 180 | conn = op.get_bind() | ||
2180 | 181 | results = conn.execute('SELECT * FROM media_files') | ||
2181 | 182 | data_path = AppLocation.get_data_path() | ||
2182 | 183 | for row in results.fetchall(): | ||
2183 | 184 | file_path_json = json.dumps(Path(row.file_name), cls=OpenLPJsonEncoder, base_path=data_path) | ||
2184 | 185 | sql = 'UPDATE media_files SET file_path = \'{file_path_json}\' WHERE id = {id}'.format( | ||
2185 | 186 | file_path_json=file_path_json, id=row.id) | ||
2186 | 187 | conn.execute(sql) | ||
2187 | 188 | # Drop old columns | ||
2188 | 189 | if metadata.bind.url.get_dialect().name == 'sqlite': | ||
2189 | 190 | drop_columns(op, 'media_files', ['file_name', ]) | ||
2190 | 191 | else: | ||
2191 | 192 | op.drop_constraint('media_files', 'foreignkey') | ||
2192 | 193 | op.drop_column('media_files', 'filenames') | ||
2193 | 165 | 194 | ||
2194 | === modified file 'openlp/plugins/songs/reporting.py' | |||
2195 | --- openlp/plugins/songs/reporting.py 2017-09-07 21:52:39 +0000 | |||
2196 | +++ openlp/plugins/songs/reporting.py 2017-09-30 23:24:21 +0000 | |||
2197 | @@ -31,7 +31,6 @@ | |||
2198 | 31 | from openlp.core.ui.lib.filedialog import FileDialog | 31 | from openlp.core.ui.lib.filedialog import FileDialog |
2199 | 32 | from openlp.plugins.songs.lib.db import Song | 32 | from openlp.plugins.songs.lib.db import Song |
2200 | 33 | 33 | ||
2201 | 34 | |||
2202 | 35 | log = logging.getLogger(__name__) | 34 | log = logging.getLogger(__name__) |
2203 | 36 | 35 | ||
2204 | 37 | 36 | ||
2205 | @@ -58,9 +57,9 @@ | |||
2206 | 58 | report_file_path.with_suffix('.csv') | 57 | report_file_path.with_suffix('.csv') |
2207 | 59 | Registry().get('application').set_busy_cursor() | 58 | Registry().get('application').set_busy_cursor() |
2208 | 60 | try: | 59 | try: |
2210 | 61 | with report_file_path.open('wt') as file_handle: | 60 | with report_file_path.open('wt') as export_file: |
2211 | 62 | fieldnames = ('Title', 'Alternative Title', 'Copyright', 'Author(s)', 'Song Book', 'Topic') | 61 | fieldnames = ('Title', 'Alternative Title', 'Copyright', 'Author(s)', 'Song Book', 'Topic') |
2213 | 63 | writer = csv.DictWriter(file_handle, fieldnames=fieldnames, quoting=csv.QUOTE_ALL) | 62 | writer = csv.DictWriter(export_file, fieldnames=fieldnames, quoting=csv.QUOTE_ALL) |
2214 | 64 | headers = dict((n, n) for n in fieldnames) | 63 | headers = dict((n, n) for n in fieldnames) |
2215 | 65 | writer.writerow(headers) | 64 | writer.writerow(headers) |
2216 | 66 | song_list = plugin.manager.get_all_objects(Song) | 65 | song_list = plugin.manager.get_all_objects(Song) |
2217 | 67 | 66 | ||
2218 | === modified file 'openlp/plugins/songs/songsplugin.py' | |||
2219 | --- openlp/plugins/songs/songsplugin.py 2017-08-26 15:06:11 +0000 | |||
2220 | +++ openlp/plugins/songs/songsplugin.py 2017-09-30 23:24:21 +0000 | |||
2221 | @@ -37,7 +37,6 @@ | |||
2222 | 37 | from openlp.core.lib import Plugin, StringContent, build_icon | 37 | from openlp.core.lib import Plugin, StringContent, build_icon |
2223 | 38 | from openlp.core.lib.db import Manager | 38 | from openlp.core.lib.db import Manager |
2224 | 39 | from openlp.core.lib.ui import create_action | 39 | from openlp.core.lib.ui import create_action |
2225 | 40 | |||
2226 | 41 | from openlp.plugins.songs import reporting | 40 | from openlp.plugins.songs import reporting |
2227 | 42 | from openlp.plugins.songs.endpoint import api_songs_endpoint, songs_endpoint | 41 | from openlp.plugins.songs.endpoint import api_songs_endpoint, songs_endpoint |
2228 | 43 | from openlp.plugins.songs.forms.duplicatesongremovalform import DuplicateSongRemovalForm | 42 | from openlp.plugins.songs.forms.duplicatesongremovalform import DuplicateSongRemovalForm |
2229 | @@ -50,7 +49,6 @@ | |||
2230 | 50 | from openlp.plugins.songs.lib.mediaitem import SongSearch | 49 | from openlp.plugins.songs.lib.mediaitem import SongSearch |
2231 | 51 | from openlp.plugins.songs.lib.songstab import SongsTab | 50 | from openlp.plugins.songs.lib.songstab import SongsTab |
2232 | 52 | 51 | ||
2233 | 53 | |||
2234 | 54 | log = logging.getLogger(__name__) | 52 | log = logging.getLogger(__name__) |
2235 | 55 | __default_settings__ = { | 53 | __default_settings__ = { |
2236 | 56 | 'songs/db type': 'sqlite', | 54 | 'songs/db type': 'sqlite', |
2237 | @@ -340,7 +338,7 @@ | |||
2238 | 340 | progress.forceShow() | 338 | progress.forceShow() |
2239 | 341 | self.application.process_events() | 339 | self.application.process_events() |
2240 | 342 | for db in song_dbs: | 340 | for db in song_dbs: |
2242 | 343 | importer = OpenLPSongImport(self.manager, filename=db) | 341 | importer = OpenLPSongImport(self.manager, file_path=db) |
2243 | 344 | importer.do_import(progress) | 342 | importer.do_import(progress) |
2244 | 345 | self.application.process_events() | 343 | self.application.process_events() |
2245 | 346 | progress.setValue(song_count) | 344 | progress.setValue(song_count) |
2246 | 347 | 345 | ||
2247 | === modified file 'tests/functional/openlp_plugins/images/test_upgrade.py' | |||
2248 | --- tests/functional/openlp_plugins/images/test_upgrade.py 2017-09-24 19:33:07 +0000 | |||
2249 | +++ tests/functional/openlp_plugins/images/test_upgrade.py 2017-09-30 23:24:21 +0000 | |||
2250 | @@ -79,5 +79,6 @@ | |||
2251 | 79 | 2: Path('/', 'test', 'dir', 'image2.jpg'), | 79 | 2: Path('/', 'test', 'dir', 'image2.jpg'), |
2252 | 80 | 3: Path('/', 'test', 'dir', 'subdir', 'image3.jpg')} | 80 | 3: Path('/', 'test', 'dir', 'subdir', 'image3.jpg')} |
2253 | 81 | 81 | ||
2254 | 82 | self.assertEqual(len(upgraded_results), 3) | ||
2255 | 82 | for result in upgraded_results: | 83 | for result in upgraded_results: |
2256 | 83 | self.assertEqual(expected_result_data[result.id], result.file_path) | 84 | self.assertEqual(expected_result_data[result.id], result.file_path) |
2257 | 84 | 85 | ||
2258 | === modified file 'tests/functional/openlp_plugins/songs/test_chordproimport.py' | |||
2259 | --- tests/functional/openlp_plugins/songs/test_chordproimport.py 2017-05-11 20:24:20 +0000 | |||
2260 | +++ tests/functional/openlp_plugins/songs/test_chordproimport.py 2017-09-30 23:24:21 +0000 | |||
2261 | @@ -24,6 +24,8 @@ | |||
2262 | 24 | """ | 24 | """ |
2263 | 25 | import os | 25 | import os |
2264 | 26 | 26 | ||
2265 | 27 | from openlp.core.common.path import Path | ||
2266 | 28 | |||
2267 | 27 | from tests.helpers.songfileimport import SongImportTestHelper | 29 | from tests.helpers.songfileimport import SongImportTestHelper |
2268 | 28 | from unittest.mock import patch, MagicMock | 30 | from unittest.mock import patch, MagicMock |
2269 | 29 | 31 | ||
2270 | @@ -48,5 +50,5 @@ | |||
2271 | 48 | mocked_returned_settings.value.side_effect = lambda value: True if value == 'songs/enable chords' else False | 50 | mocked_returned_settings.value.side_effect = lambda value: True if value == 'songs/enable chords' else False |
2272 | 49 | mocked_settings.return_value = mocked_returned_settings | 51 | mocked_settings.return_value = mocked_returned_settings |
2273 | 50 | # Do the test import | 52 | # Do the test import |
2275 | 51 | self.file_import([os.path.join(TEST_PATH, 'swing-low.chordpro')], | 53 | self.file_import([Path(TEST_PATH, 'swing-low.chordpro')], |
2276 | 52 | self.load_external_result_data(os.path.join(TEST_PATH, 'swing-low.json'))) | 54 | self.load_external_result_data(os.path.join(TEST_PATH, 'swing-low.json'))) |
2277 | 53 | 55 | ||
2278 | === modified file 'tests/functional/openlp_plugins/songs/test_easyslidesimport.py' | |||
2279 | --- tests/functional/openlp_plugins/songs/test_easyslidesimport.py 2017-01-12 21:31:01 +0000 | |||
2280 | +++ tests/functional/openlp_plugins/songs/test_easyslidesimport.py 2017-09-30 23:24:21 +0000 | |||
2281 | @@ -21,9 +21,10 @@ | |||
2282 | 21 | """ | 21 | """ |
2283 | 22 | This module contains tests for the EasySlides song importer. | 22 | This module contains tests for the EasySlides song importer. |
2284 | 23 | """ | 23 | """ |
2285 | 24 | |||
2286 | 25 | import os | 24 | import os |
2287 | 26 | 25 | ||
2288 | 26 | from openlp.core.common.path import Path | ||
2289 | 27 | |||
2290 | 27 | from tests.helpers.songfileimport import SongImportTestHelper | 28 | from tests.helpers.songfileimport import SongImportTestHelper |
2291 | 28 | 29 | ||
2292 | 29 | TEST_PATH = os.path.abspath( | 30 | TEST_PATH = os.path.abspath( |
2293 | @@ -41,7 +42,7 @@ | |||
2294 | 41 | """ | 42 | """ |
2295 | 42 | Test that loading an EasySlides file works correctly on various files | 43 | Test that loading an EasySlides file works correctly on various files |
2296 | 43 | """ | 44 | """ |
2298 | 44 | self.file_import(os.path.join(TEST_PATH, 'amazing-grace.xml'), | 45 | self.file_import(Path(TEST_PATH, 'amazing-grace.xml'), |
2299 | 45 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) | 46 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) |
2301 | 46 | self.file_import(os.path.join(TEST_PATH, 'Export_2017-01-12_BB.xml'), | 47 | self.file_import(Path(TEST_PATH, 'Export_2017-01-12_BB.xml'), |
2302 | 47 | self.load_external_result_data(os.path.join(TEST_PATH, 'Export_2017-01-12_BB.json'))) | 48 | self.load_external_result_data(os.path.join(TEST_PATH, 'Export_2017-01-12_BB.json'))) |
2303 | 48 | 49 | ||
2304 | === modified file 'tests/functional/openlp_plugins/songs/test_ewimport.py' | |||
2305 | --- tests/functional/openlp_plugins/songs/test_ewimport.py 2017-05-22 19:07:07 +0000 | |||
2306 | +++ tests/functional/openlp_plugins/songs/test_ewimport.py 2017-09-30 23:24:21 +0000 | |||
2307 | @@ -97,7 +97,7 @@ | |||
2308 | 97 | _title_assignment_list = [] | 97 | _title_assignment_list = [] |
2309 | 98 | 98 | ||
2310 | 99 | def __init__(self, manager): | 99 | def __init__(self, manager): |
2312 | 100 | EasyWorshipSongImport.__init__(self, manager, filenames=[]) | 100 | EasyWorshipSongImport.__init__(self, manager, file_paths=[]) |
2313 | 101 | 101 | ||
2314 | 102 | @property | 102 | @property |
2315 | 103 | def title(self): | 103 | def title(self): |
2316 | @@ -180,7 +180,7 @@ | |||
2317 | 180 | mocked_manager = MagicMock() | 180 | mocked_manager = MagicMock() |
2318 | 181 | 181 | ||
2319 | 182 | # WHEN: An importer object is created | 182 | # WHEN: An importer object is created |
2321 | 183 | importer = EasyWorshipSongImport(mocked_manager, filenames=[]) | 183 | importer = EasyWorshipSongImport(mocked_manager, file_paths=[]) |
2322 | 184 | 184 | ||
2323 | 185 | # THEN: The importer object should not be None | 185 | # THEN: The importer object should not be None |
2324 | 186 | self.assertIsNotNone(importer, 'Import should not be none') | 186 | self.assertIsNotNone(importer, 'Import should not be none') |
2325 | @@ -192,7 +192,7 @@ | |||
2326 | 192 | # GIVEN: A mocked out SongImport class, a mocked out "manager" and a list of field descriptions. | 192 | # GIVEN: A mocked out SongImport class, a mocked out "manager" and a list of field descriptions. |
2327 | 193 | with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'): | 193 | with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'): |
2328 | 194 | mocked_manager = MagicMock() | 194 | mocked_manager = MagicMock() |
2330 | 195 | importer = EasyWorshipSongImport(mocked_manager, filenames=[]) | 195 | importer = EasyWorshipSongImport(mocked_manager, file_paths=[]) |
2331 | 196 | importer.field_descriptions = TEST_FIELD_DESCS | 196 | importer.field_descriptions = TEST_FIELD_DESCS |
2332 | 197 | 197 | ||
2333 | 198 | # WHEN: Called with a field name that exists | 198 | # WHEN: Called with a field name that exists |
2334 | @@ -210,7 +210,7 @@ | |||
2335 | 210 | # GIVEN: A mocked out SongImport class, a mocked out "manager" and a list of field descriptions | 210 | # GIVEN: A mocked out SongImport class, a mocked out "manager" and a list of field descriptions |
2336 | 211 | with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'): | 211 | with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'): |
2337 | 212 | mocked_manager = MagicMock() | 212 | mocked_manager = MagicMock() |
2339 | 213 | importer = EasyWorshipSongImport(mocked_manager, filenames=[]) | 213 | importer = EasyWorshipSongImport(mocked_manager, file_paths=[]) |
2340 | 214 | importer.field_descriptions = TEST_FIELD_DESCS | 214 | importer.field_descriptions = TEST_FIELD_DESCS |
2341 | 215 | 215 | ||
2342 | 216 | # WHEN: Called with a field name that does not exist | 216 | # WHEN: Called with a field name that does not exist |
2343 | @@ -229,7 +229,7 @@ | |||
2344 | 229 | with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'), \ | 229 | with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'), \ |
2345 | 230 | patch('openlp.plugins.songs.lib.importers.easyworship.struct') as mocked_struct: | 230 | patch('openlp.plugins.songs.lib.importers.easyworship.struct') as mocked_struct: |
2346 | 231 | mocked_manager = MagicMock() | 231 | mocked_manager = MagicMock() |
2348 | 232 | importer = EasyWorshipSongImport(mocked_manager, filenames=[]) | 232 | importer = EasyWorshipSongImport(mocked_manager, file_paths=[]) |
2349 | 233 | 233 | ||
2350 | 234 | # WHEN: db_set_record_struct is called with a list of field descriptions | 234 | # WHEN: db_set_record_struct is called with a list of field descriptions |
2351 | 235 | return_value = importer.db_set_record_struct(TEST_FIELD_DESCS) | 235 | return_value = importer.db_set_record_struct(TEST_FIELD_DESCS) |
2352 | @@ -246,7 +246,7 @@ | |||
2353 | 246 | # GIVEN: A mocked out SongImport class, a mocked out "manager", an encoding and some test data and known results | 246 | # GIVEN: A mocked out SongImport class, a mocked out "manager", an encoding and some test data and known results |
2354 | 247 | with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'): | 247 | with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'): |
2355 | 248 | mocked_manager = MagicMock() | 248 | mocked_manager = MagicMock() |
2357 | 249 | importer = EasyWorshipSongImport(mocked_manager, filenames=[]) | 249 | importer = EasyWorshipSongImport(mocked_manager, file_paths=[]) |
2358 | 250 | importer.encoding = TEST_DATA_ENCODING | 250 | importer.encoding = TEST_DATA_ENCODING |
2359 | 251 | importer.fields = TEST_FIELDS | 251 | importer.fields = TEST_FIELDS |
2360 | 252 | importer.field_descriptions = TEST_FIELD_DESCS | 252 | importer.field_descriptions = TEST_FIELD_DESCS |
2361 | @@ -270,7 +270,7 @@ | |||
2362 | 270 | with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'): | 270 | with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'): |
2363 | 271 | mocked_manager = MagicMock() | 271 | mocked_manager = MagicMock() |
2364 | 272 | mocked_memo_file = MagicMock() | 272 | mocked_memo_file = MagicMock() |
2366 | 273 | importer = EasyWorshipSongImport(mocked_manager, filenames=[]) | 273 | importer = EasyWorshipSongImport(mocked_manager, file_paths=[]) |
2367 | 274 | importer.memo_file = mocked_memo_file | 274 | importer.memo_file = mocked_memo_file |
2368 | 275 | importer.encoding = TEST_DATA_ENCODING | 275 | importer.encoding = TEST_DATA_ENCODING |
2369 | 276 | 276 | ||
2370 | @@ -294,44 +294,25 @@ | |||
2371 | 294 | else: | 294 | else: |
2372 | 295 | mocked_memo_file.seek.assert_any_call(call[0], call[1]) | 295 | mocked_memo_file.seek.assert_any_call(call[0], call[1]) |
2373 | 296 | 296 | ||
2374 | 297 | def test_do_import_source(self): | ||
2375 | 298 | """ | ||
2376 | 299 | Test the :mod:`do_import` module opens the correct files | ||
2377 | 300 | """ | ||
2378 | 301 | # GIVEN: A mocked out SongImport class, a mocked out "manager" | ||
2379 | 302 | with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'), \ | ||
2380 | 303 | patch('openlp.plugins.songs.lib.importers.easyworship.os.path') as mocked_os_path: | ||
2381 | 304 | mocked_manager = MagicMock() | ||
2382 | 305 | importer = EasyWorshipSongImport(mocked_manager, filenames=[]) | ||
2383 | 306 | mocked_os_path.isfile.side_effect = [True, False] | ||
2384 | 307 | |||
2385 | 308 | # WHEN: Supplied with an import source | ||
2386 | 309 | importer.import_source = 'Songs.DB' | ||
2387 | 310 | |||
2388 | 311 | # THEN: do_import should return None having called os.path.isfile | ||
2389 | 312 | self.assertIsNone(importer.do_import(), 'do_import should return None') | ||
2390 | 313 | mocked_os_path.isfile.assert_any_call('Songs.DB') | ||
2391 | 314 | mocked_os_path.isfile.assert_any_call('Songs.MB') | ||
2392 | 315 | |||
2393 | 316 | def test_do_import_source_invalid(self): | 297 | def test_do_import_source_invalid(self): |
2394 | 317 | """ | 298 | """ |
2395 | 318 | Test the :mod:`do_import` module produces an error when Songs.MB not found. | 299 | Test the :mod:`do_import` module produces an error when Songs.MB not found. |
2396 | 319 | """ | 300 | """ |
2397 | 320 | # GIVEN: A mocked out SongImport class, a mocked out "manager" | 301 | # GIVEN: A mocked out SongImport class, a mocked out "manager" |
2398 | 321 | with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'), \ | 302 | with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'), \ |
2400 | 322 | patch('openlp.plugins.songs.lib.importers.easyworship.os.path') as mocked_os_path: | 303 | patch('openlp.plugins.songs.lib.importers.easyworship.Path.is_file', side_effect=[True, False]): |
2401 | 323 | mocked_manager = MagicMock() | 304 | mocked_manager = MagicMock() |
2413 | 324 | importer = EasyWorshipSongImport(mocked_manager, filenames=[]) | 305 | importer = EasyWorshipSongImport(mocked_manager, file_paths=[]) |
2414 | 325 | importer.log_error = MagicMock() | 306 | with patch.object(importer, 'log_error') as mocked_log_error: |
2415 | 326 | mocked_os_path.isfile.side_effect = [True, False] | 307 | |
2416 | 327 | 308 | # WHEN: do_import is supplied with an import source (Songs.MB missing) | |
2417 | 328 | # WHEN: do_import is supplied with an import source (Songs.MB missing) | 309 | importer.import_source = 'Songs.DB' |
2418 | 329 | importer.import_source = 'Songs.DB' | 310 | importer.do_import() |
2419 | 330 | importer.do_import() | 311 | |
2420 | 331 | 312 | # THEN: do_import should have logged an error that the Songs.MB file could not be found. | |
2421 | 332 | # THEN: do_import should have logged an error that the Songs.MB file could not be found. | 313 | mocked_log_error.assert_any_call(importer.import_source, |
2422 | 333 | importer.log_error.assert_any_call(importer.import_source, 'Could not find the "Songs.MB" file. It must be ' | 314 | 'Could not find the "Songs.MB" file. It must be in the same folder as ' |
2423 | 334 | 'in the same folder as the "Songs.DB" file.') | 315 | 'the "Songs.DB" file.') |
2424 | 335 | 316 | ||
2425 | 336 | def test_do_import_database_validity(self): | 317 | def test_do_import_database_validity(self): |
2426 | 337 | """ | 318 | """ |
2427 | @@ -339,18 +320,19 @@ | |||
2428 | 339 | """ | 320 | """ |
2429 | 340 | # GIVEN: A mocked out SongImport class, os.path and a mocked out "manager" | 321 | # GIVEN: A mocked out SongImport class, os.path and a mocked out "manager" |
2430 | 341 | with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'), \ | 322 | with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'), \ |
2432 | 342 | patch('openlp.plugins.songs.lib.importers.easyworship.os.path') as mocked_os_path: | 323 | patch('openlp.plugins.songs.lib.importers.easyworship.Path.is_file', return_value=True), \ |
2433 | 324 | patch('openlp.plugins.songs.lib.importers.easyworship.Path.stat') as mocked_stat: | ||
2434 | 325 | |||
2435 | 343 | mocked_manager = MagicMock() | 326 | mocked_manager = MagicMock() |
2438 | 344 | importer = EasyWorshipSongImport(mocked_manager, filenames=[]) | 327 | importer = EasyWorshipSongImport(mocked_manager, file_paths=[]) |
2437 | 345 | mocked_os_path.isfile.return_value = True | ||
2439 | 346 | importer.import_source = 'Songs.DB' | 328 | importer.import_source = 'Songs.DB' |
2440 | 347 | 329 | ||
2441 | 348 | # WHEN: DB file size is less than 0x800 | 330 | # WHEN: DB file size is less than 0x800 |
2443 | 349 | mocked_os_path.getsize.return_value = 0x7FF | 331 | mocked_stat.return_value.st_size = 0x7FF |
2444 | 350 | 332 | ||
2446 | 351 | # THEN: do_import should return None having called os.path.isfile | 333 | # THEN: do_import should return None having called Path.stat() |
2447 | 352 | self.assertIsNone(importer.do_import(), 'do_import should return None when db_size is less than 0x800') | 334 | self.assertIsNone(importer.do_import(), 'do_import should return None when db_size is less than 0x800') |
2449 | 353 | mocked_os_path.getsize.assert_any_call('Songs.DB') | 335 | mocked_stat.assert_called_once_with() |
2450 | 354 | 336 | ||
2451 | 355 | def test_do_import_memo_validty(self): | 337 | def test_do_import_memo_validty(self): |
2452 | 356 | """ | 338 | """ |
2453 | @@ -358,13 +340,12 @@ | |||
2454 | 358 | """ | 340 | """ |
2455 | 359 | # GIVEN: A mocked out SongImport class, a mocked out "manager" | 341 | # GIVEN: A mocked out SongImport class, a mocked out "manager" |
2456 | 360 | with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'), \ | 342 | with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'), \ |
2459 | 361 | patch('openlp.plugins.songs.lib.importers.easyworship.os.path') as mocked_os_path, \ | 343 | patch('openlp.plugins.songs.lib.importers.easyworship.Path.is_file', return_value=True), \ |
2460 | 362 | patch('builtins.open') as mocked_open, \ | 344 | patch('openlp.plugins.songs.lib.importers.easyworship.Path.stat', **{'return_value.st_size': 0x800}), \ |
2461 | 345 | patch('openlp.plugins.songs.lib.importers.easyworship.Path.open') as mocked_open, \ | ||
2462 | 363 | patch('openlp.plugins.songs.lib.importers.easyworship.struct') as mocked_struct: | 346 | patch('openlp.plugins.songs.lib.importers.easyworship.struct') as mocked_struct: |
2463 | 364 | mocked_manager = MagicMock() | 347 | mocked_manager = MagicMock() |
2467 | 365 | importer = EasyWorshipSongImport(mocked_manager, filenames=[]) | 348 | importer = EasyWorshipSongImport(mocked_manager, file_paths=[]) |
2465 | 366 | mocked_os_path.isfile.return_value = True | ||
2466 | 367 | mocked_os_path.getsize.return_value = 0x800 | ||
2468 | 368 | importer.import_source = 'Songs.DB' | 349 | importer.import_source = 'Songs.DB' |
2469 | 369 | 350 | ||
2470 | 370 | # WHEN: Unpacking first 35 bytes of Memo file | 351 | # WHEN: Unpacking first 35 bytes of Memo file |
2471 | @@ -385,14 +366,14 @@ | |||
2472 | 385 | """ | 366 | """ |
2473 | 386 | # GIVEN: A mocked out SongImport class, a mocked out "manager" | 367 | # GIVEN: A mocked out SongImport class, a mocked out "manager" |
2474 | 387 | with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'), \ | 368 | with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'), \ |
2476 | 388 | patch('openlp.plugins.songs.lib.importers.easyworship.os.path') as mocked_os_path, \ | 369 | patch('openlp.plugins.songs.lib.importers.easyworship.Path.is_file', return_value=True), \ |
2477 | 370 | patch('openlp.plugins.songs.lib.importers.easyworship.Path.stat', **{'return_value.st_size': 0x800}), \ | ||
2478 | 371 | patch('openlp.plugins.songs.lib.importers.easyworship.Path.open'), \ | ||
2479 | 389 | patch('builtins.open'), patch('openlp.plugins.songs.lib.importers.easyworship.struct') as mocked_struct, \ | 372 | patch('builtins.open'), patch('openlp.plugins.songs.lib.importers.easyworship.struct') as mocked_struct, \ |
2481 | 390 | patch('openlp.plugins.songs.lib.importers.easyworship.retrieve_windows_encoding') as \ | 373 | patch('openlp.plugins.songs.lib.importers.easyworship.retrieve_windows_encoding') as \ |
2482 | 391 | mocked_retrieve_windows_encoding: | 374 | mocked_retrieve_windows_encoding: |
2483 | 392 | mocked_manager = MagicMock() | 375 | mocked_manager = MagicMock() |
2487 | 393 | importer = EasyWorshipSongImport(mocked_manager, filenames=[]) | 376 | importer = EasyWorshipSongImport(mocked_manager, file_paths=[]) |
2485 | 394 | mocked_os_path.isfile.return_value = True | ||
2486 | 395 | mocked_os_path.getsize.return_value = 0x800 | ||
2488 | 396 | importer.import_source = 'Songs.DB' | 377 | importer.import_source = 'Songs.DB' |
2489 | 397 | 378 | ||
2490 | 398 | # WHEN: Unpacking the code page | 379 | # WHEN: Unpacking the code page |
2491 | 399 | 380 | ||
2492 | === modified file 'tests/functional/openlp_plugins/songs/test_lyriximport.py' | |||
2493 | --- tests/functional/openlp_plugins/songs/test_lyriximport.py 2017-04-24 05:17:55 +0000 | |||
2494 | +++ tests/functional/openlp_plugins/songs/test_lyriximport.py 2017-09-30 23:24:21 +0000 | |||
2495 | @@ -22,7 +22,8 @@ | |||
2496 | 22 | This module contains tests for the LyriX song importer. | 22 | This module contains tests for the LyriX song importer. |
2497 | 23 | """ | 23 | """ |
2498 | 24 | import os | 24 | import os |
2500 | 25 | from unittest.mock import patch | 25 | |
2501 | 26 | from openlp.core.common.path import Path | ||
2502 | 26 | 27 | ||
2503 | 27 | from tests.helpers.songfileimport import SongImportTestHelper | 28 | from tests.helpers.songfileimport import SongImportTestHelper |
2504 | 28 | 29 | ||
2505 | @@ -41,9 +42,9 @@ | |||
2506 | 41 | """ | 42 | """ |
2507 | 42 | Test that loading an LyriX file works correctly on various files | 43 | Test that loading an LyriX file works correctly on various files |
2508 | 43 | """ | 44 | """ |
2510 | 44 | self.file_import([os.path.join(TEST_PATH, 'A06.TXT')], | 45 | self.file_import([Path(TEST_PATH, 'A06.TXT')], |
2511 | 45 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) | 46 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) |
2513 | 46 | self.file_import([os.path.join(TEST_PATH, 'A002.TXT')], | 47 | self.file_import([Path(TEST_PATH, 'A002.TXT')], |
2514 | 47 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace2.json'))) | 48 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace2.json'))) |
2516 | 48 | self.file_import([os.path.join(TEST_PATH, 'AO05.TXT')], | 49 | self.file_import([Path(TEST_PATH, 'AO05.TXT')], |
2517 | 49 | self.load_external_result_data(os.path.join(TEST_PATH, 'in die regterhand.json'))) | 50 | self.load_external_result_data(os.path.join(TEST_PATH, 'in die regterhand.json'))) |
2518 | 50 | 51 | ||
2519 | === modified file 'tests/functional/openlp_plugins/songs/test_mediashout.py' | |||
2520 | --- tests/functional/openlp_plugins/songs/test_mediashout.py 2017-04-24 05:17:55 +0000 | |||
2521 | +++ tests/functional/openlp_plugins/songs/test_mediashout.py 2017-09-30 23:24:21 +0000 | |||
2522 | @@ -51,7 +51,7 @@ | |||
2523 | 51 | """ | 51 | """ |
2524 | 52 | # GIVEN: A MediaShoutImport class | 52 | # GIVEN: A MediaShoutImport class |
2525 | 53 | # WHEN: It is created | 53 | # WHEN: It is created |
2527 | 54 | importer = MediaShoutImport(MagicMock(), filename='mediashout.db') | 54 | importer = MediaShoutImport(MagicMock(), file_path='mediashout.db') |
2528 | 55 | 55 | ||
2529 | 56 | # THEN: It should not be None | 56 | # THEN: It should not be None |
2530 | 57 | self.assertIsNotNone(importer) | 57 | self.assertIsNotNone(importer) |
2531 | @@ -62,7 +62,7 @@ | |||
2532 | 62 | Test that do_import exits early when unable to connect to the database | 62 | Test that do_import exits early when unable to connect to the database |
2533 | 63 | """ | 63 | """ |
2534 | 64 | # GIVEN: A MediaShoutImport instance | 64 | # GIVEN: A MediaShoutImport instance |
2536 | 65 | importer = MediaShoutImport(MagicMock(), filename='mediashout.db') | 65 | importer = MediaShoutImport(MagicMock(), file_path='mediashout.db') |
2537 | 66 | mocked_pyodbc.connect.side_effect = Exception('Unable to connect') | 66 | mocked_pyodbc.connect.side_effect = Exception('Unable to connect') |
2538 | 67 | 67 | ||
2539 | 68 | # WHEN: do_import is called | 68 | # WHEN: do_import is called |
2540 | @@ -89,7 +89,7 @@ | |||
2541 | 89 | group = GroupRecord('Hymns') | 89 | group = GroupRecord('Hymns') |
2542 | 90 | 90 | ||
2543 | 91 | # GIVEN: A MediaShoutImport instance and a bunch of stuff mocked out | 91 | # GIVEN: A MediaShoutImport instance and a bunch of stuff mocked out |
2545 | 92 | importer = MediaShoutImport(MagicMock(), filename='mediashout.db') | 92 | importer = MediaShoutImport(MagicMock(), file_path='mediashout.db') |
2546 | 93 | mocked_cursor = MagicMock() | 93 | mocked_cursor = MagicMock() |
2547 | 94 | mocked_cursor.fetchall.side_effect = [[song], [verse], [play_order], [theme], [group]] | 94 | mocked_cursor.fetchall.side_effect = [[song], [verse], [play_order], [theme], [group]] |
2548 | 95 | mocked_cursor.tables.fetchone.return_value = True | 95 | mocked_cursor.tables.fetchone.return_value = True |
2549 | @@ -124,7 +124,7 @@ | |||
2550 | 124 | song = SongRecord(1, 'Amazing Grace', 'William Wilberforce', 'Public Domain', 1, '654321', '') | 124 | song = SongRecord(1, 'Amazing Grace', 'William Wilberforce', 'Public Domain', 1, '654321', '') |
2551 | 125 | 125 | ||
2552 | 126 | # GIVEN: A MediaShoutImport instance and a bunch of stuff mocked out | 126 | # GIVEN: A MediaShoutImport instance and a bunch of stuff mocked out |
2554 | 127 | importer = MediaShoutImport(MagicMock(), filename='mediashout.db') | 127 | importer = MediaShoutImport(MagicMock(), file_path='mediashout.db') |
2555 | 128 | mocked_cursor = MagicMock() | 128 | mocked_cursor = MagicMock() |
2556 | 129 | mocked_cursor.fetchall.return_value = [song] | 129 | mocked_cursor.fetchall.return_value = [song] |
2557 | 130 | mocked_connection = MagicMock() | 130 | mocked_connection = MagicMock() |
2558 | @@ -158,7 +158,7 @@ | |||
2559 | 158 | play_order = PlayOrderRecord(0, 1, 1) | 158 | play_order = PlayOrderRecord(0, 1, 1) |
2560 | 159 | theme = ThemeRecord('Grace') | 159 | theme = ThemeRecord('Grace') |
2561 | 160 | group = GroupRecord('Hymns') | 160 | group = GroupRecord('Hymns') |
2563 | 161 | importer = MediaShoutImport(MagicMock(), filename='mediashout.db') | 161 | importer = MediaShoutImport(MagicMock(), file_path='mediashout.db') |
2564 | 162 | 162 | ||
2565 | 163 | # WHEN: A song is processed | 163 | # WHEN: A song is processed |
2566 | 164 | with patch.object(importer, 'set_defaults') as mocked_set_defaults, \ | 164 | with patch.object(importer, 'set_defaults') as mocked_set_defaults, \ |
2567 | @@ -200,7 +200,7 @@ | |||
2568 | 200 | play_order = PlayOrderRecord(0, 1, 1) | 200 | play_order = PlayOrderRecord(0, 1, 1) |
2569 | 201 | theme = ThemeRecord('Grace') | 201 | theme = ThemeRecord('Grace') |
2570 | 202 | group = GroupRecord('Hymns') | 202 | group = GroupRecord('Hymns') |
2572 | 203 | importer = MediaShoutImport(MagicMock(), filename='mediashout.db') | 203 | importer = MediaShoutImport(MagicMock(), file_path='mediashout.db') |
2573 | 204 | 204 | ||
2574 | 205 | # WHEN: A song is processed | 205 | # WHEN: A song is processed |
2575 | 206 | with patch.object(importer, 'set_defaults') as mocked_set_defaults, \ | 206 | with patch.object(importer, 'set_defaults') as mocked_set_defaults, \ |
2576 | 207 | 207 | ||
2577 | === modified file 'tests/functional/openlp_plugins/songs/test_openlpimporter.py' | |||
2578 | --- tests/functional/openlp_plugins/songs/test_openlpimporter.py 2017-04-24 05:17:55 +0000 | |||
2579 | +++ tests/functional/openlp_plugins/songs/test_openlpimporter.py 2017-09-30 23:24:21 +0000 | |||
2580 | @@ -48,7 +48,7 @@ | |||
2581 | 48 | mocked_manager = MagicMock() | 48 | mocked_manager = MagicMock() |
2582 | 49 | 49 | ||
2583 | 50 | # WHEN: An importer object is created | 50 | # WHEN: An importer object is created |
2585 | 51 | importer = OpenLPSongImport(mocked_manager, filenames=[]) | 51 | importer = OpenLPSongImport(mocked_manager, file_paths=[]) |
2586 | 52 | 52 | ||
2587 | 53 | # THEN: The importer object should not be None | 53 | # THEN: The importer object should not be None |
2588 | 54 | self.assertIsNotNone(importer, 'Import should not be none') | 54 | self.assertIsNotNone(importer, 'Import should not be none') |
2589 | @@ -61,7 +61,7 @@ | |||
2590 | 61 | with patch('openlp.plugins.songs.lib.importers.openlp.SongImport'): | 61 | with patch('openlp.plugins.songs.lib.importers.openlp.SongImport'): |
2591 | 62 | mocked_manager = MagicMock() | 62 | mocked_manager = MagicMock() |
2592 | 63 | mocked_import_wizard = MagicMock() | 63 | mocked_import_wizard = MagicMock() |
2594 | 64 | importer = OpenLPSongImport(mocked_manager, filenames=[]) | 64 | importer = OpenLPSongImport(mocked_manager, file_paths=[]) |
2595 | 65 | importer.import_wizard = mocked_import_wizard | 65 | importer.import_wizard = mocked_import_wizard |
2596 | 66 | importer.stop_import_flag = True | 66 | importer.stop_import_flag = True |
2597 | 67 | 67 | ||
2598 | 68 | 68 | ||
2599 | === modified file 'tests/functional/openlp_plugins/songs/test_openlyricsexport.py' | |||
2600 | --- tests/functional/openlp_plugins/songs/test_openlyricsexport.py 2017-04-24 05:17:55 +0000 | |||
2601 | +++ tests/functional/openlp_plugins/songs/test_openlyricsexport.py 2017-09-30 23:24:21 +0000 | |||
2602 | @@ -22,14 +22,14 @@ | |||
2603 | 22 | """ | 22 | """ |
2604 | 23 | This module contains tests for the OpenLyrics song importer. | 23 | This module contains tests for the OpenLyrics song importer. |
2605 | 24 | """ | 24 | """ |
2606 | 25 | import os | ||
2607 | 26 | import shutil | 25 | import shutil |
2608 | 27 | from tempfile import mkdtemp | 26 | from tempfile import mkdtemp |
2609 | 28 | from unittest import TestCase | 27 | from unittest import TestCase |
2610 | 29 | from unittest.mock import MagicMock, patch | 28 | from unittest.mock import MagicMock, patch |
2611 | 30 | 29 | ||
2612 | 30 | from openlp.core.common import Registry | ||
2613 | 31 | from openlp.core.common.path import Path, rmtree | ||
2614 | 31 | from openlp.plugins.songs.lib.openlyricsexport import OpenLyricsExport | 32 | from openlp.plugins.songs.lib.openlyricsexport import OpenLyricsExport |
2615 | 32 | from openlp.core.common import Registry | ||
2616 | 33 | 33 | ||
2617 | 34 | from tests.helpers.testmixin import TestMixin | 34 | from tests.helpers.testmixin import TestMixin |
2618 | 35 | 35 | ||
2619 | @@ -43,13 +43,13 @@ | |||
2620 | 43 | Create the registry | 43 | Create the registry |
2621 | 44 | """ | 44 | """ |
2622 | 45 | Registry.create() | 45 | Registry.create() |
2624 | 46 | self.temp_folder = mkdtemp() | 46 | self.temp_folder = Path(mkdtemp()) |
2625 | 47 | 47 | ||
2626 | 48 | def tearDown(self): | 48 | def tearDown(self): |
2627 | 49 | """ | 49 | """ |
2628 | 50 | Cleanup | 50 | Cleanup |
2629 | 51 | """ | 51 | """ |
2631 | 52 | shutil.rmtree(self.temp_folder) | 52 | rmtree(self.temp_folder) |
2632 | 53 | 53 | ||
2633 | 54 | def test_export_same_filename(self): | 54 | def test_export_same_filename(self): |
2634 | 55 | """ | 55 | """ |
2635 | @@ -73,7 +73,9 @@ | |||
2636 | 73 | ol_export.do_export() | 73 | ol_export.do_export() |
2637 | 74 | 74 | ||
2638 | 75 | # THEN: The exporter should have created 2 files | 75 | # THEN: The exporter should have created 2 files |
2643 | 76 | self.assertTrue(os.path.exists(os.path.join(self.temp_folder, | 76 | self.assertTrue((self.temp_folder / |
2644 | 77 | '%s (%s).xml' % (song.title, author.display_name)))) | 77 | '{title} ({display_name}).xml'.format( |
2645 | 78 | self.assertTrue(os.path.exists(os.path.join(self.temp_folder, | 78 | title=song.title, display_name=author.display_name)).exists()) |
2646 | 79 | '%s (%s)-1.xml' % (song.title, author.display_name)))) | 79 | self.assertTrue((self.temp_folder / |
2647 | 80 | '{title} ({display_name})-1.xml'.format( | ||
2648 | 81 | title=song.title, display_name=author.display_name)).exists()) | ||
2649 | 80 | 82 | ||
2650 | === modified file 'tests/functional/openlp_plugins/songs/test_openlyricsimport.py' | |||
2651 | --- tests/functional/openlp_plugins/songs/test_openlyricsimport.py 2017-06-06 20:58:12 +0000 | |||
2652 | +++ tests/functional/openlp_plugins/songs/test_openlyricsimport.py 2017-09-30 23:24:21 +0000 | |||
2653 | @@ -29,10 +29,11 @@ | |||
2654 | 29 | 29 | ||
2655 | 30 | from lxml import etree, objectify | 30 | from lxml import etree, objectify |
2656 | 31 | 31 | ||
2657 | 32 | from openlp.core.common import Registry, Settings | ||
2658 | 33 | from openlp.core.common.path import Path | ||
2659 | 32 | from openlp.plugins.songs.lib.importers.openlyrics import OpenLyricsImport | 34 | from openlp.plugins.songs.lib.importers.openlyrics import OpenLyricsImport |
2660 | 33 | from openlp.plugins.songs.lib.importers.songimport import SongImport | 35 | from openlp.plugins.songs.lib.importers.songimport import SongImport |
2661 | 34 | from openlp.plugins.songs.lib.openlyricsxml import OpenLyrics | 36 | from openlp.plugins.songs.lib.openlyricsxml import OpenLyrics |
2662 | 35 | from openlp.core.common import Registry, Settings | ||
2663 | 36 | 37 | ||
2664 | 37 | from tests.helpers.testmixin import TestMixin | 38 | from tests.helpers.testmixin import TestMixin |
2665 | 38 | 39 | ||
2666 | @@ -109,7 +110,7 @@ | |||
2667 | 109 | mocked_manager = MagicMock() | 110 | mocked_manager = MagicMock() |
2668 | 110 | 111 | ||
2669 | 111 | # WHEN: An importer object is created | 112 | # WHEN: An importer object is created |
2671 | 112 | importer = OpenLyricsImport(mocked_manager, filenames=[]) | 113 | importer = OpenLyricsImport(mocked_manager, file_paths=[]) |
2672 | 113 | 114 | ||
2673 | 114 | # THEN: The importer should be an instance of SongImport | 115 | # THEN: The importer should be an instance of SongImport |
2674 | 115 | self.assertIsInstance(importer, SongImport) | 116 | self.assertIsInstance(importer, SongImport) |
2675 | @@ -122,13 +123,13 @@ | |||
2676 | 122 | for song_file in SONG_TEST_DATA: | 123 | for song_file in SONG_TEST_DATA: |
2677 | 123 | mocked_manager = MagicMock() | 124 | mocked_manager = MagicMock() |
2678 | 124 | mocked_import_wizard = MagicMock() | 125 | mocked_import_wizard = MagicMock() |
2680 | 125 | importer = OpenLyricsImport(mocked_manager, filenames=[]) | 126 | importer = OpenLyricsImport(mocked_manager, file_paths=[]) |
2681 | 126 | importer.import_wizard = mocked_import_wizard | 127 | importer.import_wizard = mocked_import_wizard |
2682 | 127 | importer.open_lyrics = MagicMock() | 128 | importer.open_lyrics = MagicMock() |
2683 | 128 | importer.open_lyrics.xml_to_song = MagicMock() | 129 | importer.open_lyrics.xml_to_song = MagicMock() |
2684 | 129 | 130 | ||
2685 | 130 | # WHEN: Importing each file | 131 | # WHEN: Importing each file |
2687 | 131 | importer.import_source = [os.path.join(TEST_PATH, song_file)] | 132 | importer.import_source = [Path(TEST_PATH, song_file)] |
2688 | 132 | importer.do_import() | 133 | importer.do_import() |
2689 | 133 | 134 | ||
2690 | 134 | # THEN: The xml_to_song() method should have been called | 135 | # THEN: The xml_to_song() method should have been called |
2691 | 135 | 136 | ||
2692 | === modified file 'tests/functional/openlp_plugins/songs/test_openoffice.py' | |||
2693 | --- tests/functional/openlp_plugins/songs/test_openoffice.py 2017-04-24 05:17:55 +0000 | |||
2694 | +++ tests/functional/openlp_plugins/songs/test_openoffice.py 2017-09-30 23:24:21 +0000 | |||
2695 | @@ -54,7 +54,7 @@ | |||
2696 | 54 | mocked_manager = MagicMock() | 54 | mocked_manager = MagicMock() |
2697 | 55 | 55 | ||
2698 | 56 | # WHEN: An importer object is created | 56 | # WHEN: An importer object is created |
2700 | 57 | importer = OpenOfficeImport(mocked_manager, filenames=[]) | 57 | importer = OpenOfficeImport(mocked_manager, file_paths=[]) |
2701 | 58 | 58 | ||
2702 | 59 | # THEN: The importer object should not be None | 59 | # THEN: The importer object should not be None |
2703 | 60 | self.assertIsNotNone(importer, 'Import should not be none') | 60 | self.assertIsNotNone(importer, 'Import should not be none') |
2704 | @@ -66,7 +66,7 @@ | |||
2705 | 66 | """ | 66 | """ |
2706 | 67 | # GIVEN: A mocked out SongImport class, a mocked out "manager" and a document that raises an exception | 67 | # GIVEN: A mocked out SongImport class, a mocked out "manager" and a document that raises an exception |
2707 | 68 | mocked_manager = MagicMock() | 68 | mocked_manager = MagicMock() |
2709 | 69 | importer = OpenOfficeImport(mocked_manager, filenames=[]) | 69 | importer = OpenOfficeImport(mocked_manager, file_paths=[]) |
2710 | 70 | importer.document = MagicMock() | 70 | importer.document = MagicMock() |
2711 | 71 | importer.document.close = MagicMock(side_effect=Exception()) | 71 | importer.document.close = MagicMock(side_effect=Exception()) |
2712 | 72 | 72 | ||
2713 | 73 | 73 | ||
2714 | === modified file 'tests/functional/openlp_plugins/songs/test_opensongimport.py' | |||
2715 | --- tests/functional/openlp_plugins/songs/test_opensongimport.py 2017-05-11 20:24:20 +0000 | |||
2716 | +++ tests/functional/openlp_plugins/songs/test_opensongimport.py 2017-09-30 23:24:21 +0000 | |||
2717 | @@ -27,6 +27,7 @@ | |||
2718 | 27 | from unittest.mock import patch, MagicMock | 27 | from unittest.mock import patch, MagicMock |
2719 | 28 | 28 | ||
2720 | 29 | from openlp.core.common import Registry | 29 | from openlp.core.common import Registry |
2721 | 30 | from openlp.core.common.path import Path | ||
2722 | 30 | from openlp.plugins.songs.lib.importers.opensong import OpenSongImport | 31 | from openlp.plugins.songs.lib.importers.opensong import OpenSongImport |
2723 | 31 | 32 | ||
2724 | 32 | from tests.helpers.songfileimport import SongImportTestHelper | 33 | from tests.helpers.songfileimport import SongImportTestHelper |
2725 | @@ -52,15 +53,15 @@ | |||
2726 | 52 | mocked_returned_settings.value.side_effect = lambda value: True if value == 'songs/enable chords' else False | 53 | mocked_returned_settings.value.side_effect = lambda value: True if value == 'songs/enable chords' else False |
2727 | 53 | mocked_settings.return_value = mocked_returned_settings | 54 | mocked_settings.return_value = mocked_returned_settings |
2728 | 54 | # Do the test import | 55 | # Do the test import |
2730 | 55 | self.file_import([os.path.join(TEST_PATH, 'Amazing Grace')], | 56 | self.file_import([Path(TEST_PATH, 'Amazing Grace')], |
2731 | 56 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) | 57 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) |
2733 | 57 | self.file_import([os.path.join(TEST_PATH, 'Beautiful Garden Of Prayer')], | 58 | self.file_import([Path(TEST_PATH, 'Beautiful Garden Of Prayer')], |
2734 | 58 | self.load_external_result_data(os.path.join(TEST_PATH, 'Beautiful Garden Of Prayer.json'))) | 59 | self.load_external_result_data(os.path.join(TEST_PATH, 'Beautiful Garden Of Prayer.json'))) |
2736 | 59 | self.file_import([os.path.join(TEST_PATH, 'One, Two, Three, Four, Five')], | 60 | self.file_import([Path(TEST_PATH, 'One, Two, Three, Four, Five')], |
2737 | 60 | self.load_external_result_data(os.path.join(TEST_PATH, 'One, Two, Three, Four, Five.json'))) | 61 | self.load_external_result_data(os.path.join(TEST_PATH, 'One, Two, Three, Four, Five.json'))) |
2739 | 61 | self.file_import([os.path.join(TEST_PATH, 'Amazing Grace2')], | 62 | self.file_import([Path(TEST_PATH, 'Amazing Grace2')], |
2740 | 62 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) | 63 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) |
2742 | 63 | self.file_import([os.path.join(TEST_PATH, 'Amazing Grace with bad CCLI')], | 64 | self.file_import([Path(TEST_PATH, 'Amazing Grace with bad CCLI')], |
2743 | 64 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace without CCLI.json'))) | 65 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace without CCLI.json'))) |
2744 | 65 | 66 | ||
2745 | 66 | 67 | ||
2746 | @@ -83,7 +84,7 @@ | |||
2747 | 83 | mocked_manager = MagicMock() | 84 | mocked_manager = MagicMock() |
2748 | 84 | 85 | ||
2749 | 85 | # WHEN: An importer object is created | 86 | # WHEN: An importer object is created |
2751 | 86 | importer = OpenSongImport(mocked_manager, filenames=[]) | 87 | importer = OpenSongImport(mocked_manager, file_paths=[]) |
2752 | 87 | 88 | ||
2753 | 88 | # THEN: The importer object should not be None | 89 | # THEN: The importer object should not be None |
2754 | 89 | self.assertIsNotNone(importer, 'Import should not be none') | 90 | self.assertIsNotNone(importer, 'Import should not be none') |
2755 | @@ -96,7 +97,7 @@ | |||
2756 | 96 | with patch('openlp.plugins.songs.lib.importers.opensong.SongImport'): | 97 | with patch('openlp.plugins.songs.lib.importers.opensong.SongImport'): |
2757 | 97 | mocked_manager = MagicMock() | 98 | mocked_manager = MagicMock() |
2758 | 98 | mocked_import_wizard = MagicMock() | 99 | mocked_import_wizard = MagicMock() |
2760 | 99 | importer = OpenSongImport(mocked_manager, filenames=[]) | 100 | importer = OpenSongImport(mocked_manager, file_paths=[]) |
2761 | 100 | importer.import_wizard = mocked_import_wizard | 101 | importer.import_wizard = mocked_import_wizard |
2762 | 101 | importer.stop_import_flag = True | 102 | importer.stop_import_flag = True |
2763 | 102 | 103 | ||
2764 | @@ -117,7 +118,7 @@ | |||
2765 | 117 | with patch('openlp.plugins.songs.lib.importers.opensong.SongImport'): | 118 | with patch('openlp.plugins.songs.lib.importers.opensong.SongImport'): |
2766 | 118 | mocked_manager = MagicMock() | 119 | mocked_manager = MagicMock() |
2767 | 119 | mocked_import_wizard = MagicMock() | 120 | mocked_import_wizard = MagicMock() |
2769 | 120 | importer = OpenSongImport(mocked_manager, filenames=[]) | 121 | importer = OpenSongImport(mocked_manager, file_paths=[]) |
2770 | 121 | importer.import_wizard = mocked_import_wizard | 122 | importer.import_wizard = mocked_import_wizard |
2771 | 122 | importer.stop_import_flag = True | 123 | importer.stop_import_flag = True |
2772 | 123 | 124 | ||
2773 | 124 | 125 | ||
2774 | === modified file 'tests/functional/openlp_plugins/songs/test_opsproimport.py' | |||
2775 | --- tests/functional/openlp_plugins/songs/test_opsproimport.py 2017-04-24 05:17:55 +0000 | |||
2776 | +++ tests/functional/openlp_plugins/songs/test_opsproimport.py 2017-09-30 23:24:21 +0000 | |||
2777 | @@ -86,7 +86,7 @@ | |||
2778 | 86 | mocked_manager = MagicMock() | 86 | mocked_manager = MagicMock() |
2779 | 87 | 87 | ||
2780 | 88 | # WHEN: An importer object is created | 88 | # WHEN: An importer object is created |
2782 | 89 | importer = OPSProImport(mocked_manager, filenames=[]) | 89 | importer = OPSProImport(mocked_manager, file_paths=[]) |
2783 | 90 | 90 | ||
2784 | 91 | # THEN: The importer object should not be None | 91 | # THEN: The importer object should not be None |
2785 | 92 | self.assertIsNotNone(importer, 'Import should not be none') | 92 | self.assertIsNotNone(importer, 'Import should not be none') |
2786 | @@ -98,7 +98,7 @@ | |||
2787 | 98 | """ | 98 | """ |
2788 | 99 | # GIVEN: A mocked out SongImport class, a mocked out "manager" and a mocked song and lyrics entry | 99 | # GIVEN: A mocked out SongImport class, a mocked out "manager" and a mocked song and lyrics entry |
2789 | 100 | mocked_manager = MagicMock() | 100 | mocked_manager = MagicMock() |
2791 | 101 | importer = OPSProImport(mocked_manager, filenames=[]) | 101 | importer = OPSProImport(mocked_manager, file_paths=[]) |
2792 | 102 | importer.finish = MagicMock() | 102 | importer.finish = MagicMock() |
2793 | 103 | song, lyrics = _build_data('you are so faithfull.txt', False) | 103 | song, lyrics = _build_data('you are so faithfull.txt', False) |
2794 | 104 | 104 | ||
2795 | @@ -118,7 +118,7 @@ | |||
2796 | 118 | """ | 118 | """ |
2797 | 119 | # GIVEN: A mocked out SongImport class, a mocked out "manager" and a mocked song and lyrics entry | 119 | # GIVEN: A mocked out SongImport class, a mocked out "manager" and a mocked song and lyrics entry |
2798 | 120 | mocked_manager = MagicMock() | 120 | mocked_manager = MagicMock() |
2800 | 121 | importer = OPSProImport(mocked_manager, filenames=[]) | 121 | importer = OPSProImport(mocked_manager, file_paths=[]) |
2801 | 122 | importer.finish = MagicMock() | 122 | importer.finish = MagicMock() |
2802 | 123 | song, lyrics = _build_data('amazing grace.txt', False) | 123 | song, lyrics = _build_data('amazing grace.txt', False) |
2803 | 124 | 124 | ||
2804 | @@ -138,7 +138,7 @@ | |||
2805 | 138 | """ | 138 | """ |
2806 | 139 | # GIVEN: A mocked out SongImport class, a mocked out "manager" and a mocked song and lyrics entry | 139 | # GIVEN: A mocked out SongImport class, a mocked out "manager" and a mocked song and lyrics entry |
2807 | 140 | mocked_manager = MagicMock() | 140 | mocked_manager = MagicMock() |
2809 | 141 | importer = OPSProImport(mocked_manager, filenames=[]) | 141 | importer = OPSProImport(mocked_manager, file_paths=[]) |
2810 | 142 | importer.finish = MagicMock() | 142 | importer.finish = MagicMock() |
2811 | 143 | song, lyrics = _build_data('amazing grace2.txt', True) | 143 | song, lyrics = _build_data('amazing grace2.txt', True) |
2812 | 144 | 144 | ||
2813 | @@ -158,7 +158,7 @@ | |||
2814 | 158 | """ | 158 | """ |
2815 | 159 | # GIVEN: A mocked out SongImport class, a mocked out "manager" and a mocked song and lyrics entry | 159 | # GIVEN: A mocked out SongImport class, a mocked out "manager" and a mocked song and lyrics entry |
2816 | 160 | mocked_manager = MagicMock() | 160 | mocked_manager = MagicMock() |
2818 | 161 | importer = OPSProImport(mocked_manager, filenames=[]) | 161 | importer = OPSProImport(mocked_manager, file_paths=[]) |
2819 | 162 | importer.finish = MagicMock() | 162 | importer.finish = MagicMock() |
2820 | 163 | song, lyrics = _build_data('amazing grace3.txt', True) | 163 | song, lyrics = _build_data('amazing grace3.txt', True) |
2821 | 164 | 164 | ||
2822 | 165 | 165 | ||
2823 | === modified file 'tests/functional/openlp_plugins/songs/test_powerpraiseimport.py' | |||
2824 | --- tests/functional/openlp_plugins/songs/test_powerpraiseimport.py 2016-12-31 11:01:36 +0000 | |||
2825 | +++ tests/functional/openlp_plugins/songs/test_powerpraiseimport.py 2017-09-30 23:24:21 +0000 | |||
2826 | @@ -26,8 +26,9 @@ | |||
2827 | 26 | 26 | ||
2828 | 27 | import os | 27 | import os |
2829 | 28 | 28 | ||
2830 | 29 | from openlp.core.common.path import Path | ||
2831 | 30 | |||
2832 | 29 | from tests.helpers.songfileimport import SongImportTestHelper | 31 | from tests.helpers.songfileimport import SongImportTestHelper |
2833 | 30 | from openlp.core.common import Registry | ||
2834 | 31 | 32 | ||
2835 | 32 | TEST_PATH = os.path.abspath( | 33 | TEST_PATH = os.path.abspath( |
2836 | 33 | os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'powerpraisesongs')) | 34 | os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'powerpraisesongs')) |
2837 | @@ -44,7 +45,7 @@ | |||
2838 | 44 | """ | 45 | """ |
2839 | 45 | Test that loading a PowerPraise file works correctly | 46 | Test that loading a PowerPraise file works correctly |
2840 | 46 | """ | 47 | """ |
2842 | 47 | self.file_import([os.path.join(TEST_PATH, 'Naher, mein Gott zu Dir.ppl')], | 48 | self.file_import([Path(TEST_PATH, 'Naher, mein Gott zu Dir.ppl')], |
2843 | 48 | self.load_external_result_data(os.path.join(TEST_PATH, 'Naher, mein Gott zu Dir.json'))) | 49 | self.load_external_result_data(os.path.join(TEST_PATH, 'Naher, mein Gott zu Dir.json'))) |
2845 | 49 | self.file_import([os.path.join(TEST_PATH, 'You are so faithful.ppl')], | 50 | self.file_import([Path(TEST_PATH, 'You are so faithful.ppl')], |
2846 | 50 | self.load_external_result_data(os.path.join(TEST_PATH, 'You are so faithful.json'))) | 51 | self.load_external_result_data(os.path.join(TEST_PATH, 'You are so faithful.json'))) |
2847 | 51 | 52 | ||
2848 | === modified file 'tests/functional/openlp_plugins/songs/test_presentationmanagerimport.py' | |||
2849 | --- tests/functional/openlp_plugins/songs/test_presentationmanagerimport.py 2016-12-31 11:01:36 +0000 | |||
2850 | +++ tests/functional/openlp_plugins/songs/test_presentationmanagerimport.py 2017-09-30 23:24:21 +0000 | |||
2851 | @@ -22,9 +22,10 @@ | |||
2852 | 22 | """ | 22 | """ |
2853 | 23 | This module contains tests for the PresentationManager song importer. | 23 | This module contains tests for the PresentationManager song importer. |
2854 | 24 | """ | 24 | """ |
2855 | 25 | |||
2856 | 26 | import os | 25 | import os |
2857 | 27 | 26 | ||
2858 | 27 | from openlp.core.common.path import Path | ||
2859 | 28 | |||
2860 | 28 | from tests.helpers.songfileimport import SongImportTestHelper | 29 | from tests.helpers.songfileimport import SongImportTestHelper |
2861 | 29 | 30 | ||
2862 | 30 | TEST_PATH = os.path.abspath( | 31 | TEST_PATH = os.path.abspath( |
2863 | @@ -42,7 +43,7 @@ | |||
2864 | 42 | """ | 43 | """ |
2865 | 43 | Test that loading a PresentationManager file works correctly | 44 | Test that loading a PresentationManager file works correctly |
2866 | 44 | """ | 45 | """ |
2868 | 45 | self.file_import([os.path.join(TEST_PATH, 'Great Is Thy Faithfulness.sng')], | 46 | self.file_import([Path(TEST_PATH, 'Great Is Thy Faithfulness.sng')], |
2869 | 46 | self.load_external_result_data(os.path.join(TEST_PATH, 'Great Is Thy Faithfulness.json'))) | 47 | self.load_external_result_data(os.path.join(TEST_PATH, 'Great Is Thy Faithfulness.json'))) |
2871 | 47 | self.file_import([os.path.join(TEST_PATH, 'Amazing Grace.sng')], | 48 | self.file_import([Path(TEST_PATH, 'Amazing Grace.sng')], |
2872 | 48 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) | 49 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) |
2873 | 49 | 50 | ||
2874 | === modified file 'tests/functional/openlp_plugins/songs/test_propresenterimport.py' | |||
2875 | --- tests/functional/openlp_plugins/songs/test_propresenterimport.py 2016-12-31 11:01:36 +0000 | |||
2876 | +++ tests/functional/openlp_plugins/songs/test_propresenterimport.py 2017-09-30 23:24:21 +0000 | |||
2877 | @@ -23,9 +23,10 @@ | |||
2878 | 23 | The :mod:`propresenterimport` module provides the functionality for importing | 23 | The :mod:`propresenterimport` module provides the functionality for importing |
2879 | 24 | ProPresenter song files into the current installation database. | 24 | ProPresenter song files into the current installation database. |
2880 | 25 | """ | 25 | """ |
2881 | 26 | |||
2882 | 27 | import os | 26 | import os |
2883 | 28 | 27 | ||
2884 | 28 | from openlp.core.common.path import Path | ||
2885 | 29 | |||
2886 | 29 | from tests.helpers.songfileimport import SongImportTestHelper | 30 | from tests.helpers.songfileimport import SongImportTestHelper |
2887 | 30 | 31 | ||
2888 | 31 | TEST_PATH = os.path.abspath( | 32 | TEST_PATH = os.path.abspath( |
2889 | @@ -43,19 +44,19 @@ | |||
2890 | 43 | """ | 44 | """ |
2891 | 44 | Test that loading a ProPresenter 4 file works correctly | 45 | Test that loading a ProPresenter 4 file works correctly |
2892 | 45 | """ | 46 | """ |
2894 | 46 | self.file_import([os.path.join(TEST_PATH, 'Amazing Grace.pro4')], | 47 | self.file_import([Path(TEST_PATH, 'Amazing Grace.pro4')], |
2895 | 47 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) | 48 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) |
2896 | 48 | 49 | ||
2897 | 49 | def test_pro5_song_import(self): | 50 | def test_pro5_song_import(self): |
2898 | 50 | """ | 51 | """ |
2899 | 51 | Test that loading a ProPresenter 5 file works correctly | 52 | Test that loading a ProPresenter 5 file works correctly |
2900 | 52 | """ | 53 | """ |
2902 | 53 | self.file_import([os.path.join(TEST_PATH, 'Amazing Grace.pro5')], | 54 | self.file_import([Path(TEST_PATH, 'Amazing Grace.pro5')], |
2903 | 54 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) | 55 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) |
2904 | 55 | 56 | ||
2905 | 56 | def test_pro6_song_import(self): | 57 | def test_pro6_song_import(self): |
2906 | 57 | """ | 58 | """ |
2907 | 58 | Test that loading a ProPresenter 6 file works correctly | 59 | Test that loading a ProPresenter 6 file works correctly |
2908 | 59 | """ | 60 | """ |
2910 | 60 | self.file_import([os.path.join(TEST_PATH, 'Amazing Grace.pro6')], | 61 | self.file_import([Path(TEST_PATH, 'Amazing Grace.pro6')], |
2911 | 61 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) | 62 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) |
2912 | 62 | 63 | ||
2913 | === modified file 'tests/functional/openlp_plugins/songs/test_songbeamerimport.py' | |||
2914 | --- tests/functional/openlp_plugins/songs/test_songbeamerimport.py 2017-05-11 20:24:20 +0000 | |||
2915 | +++ tests/functional/openlp_plugins/songs/test_songbeamerimport.py 2017-09-30 23:24:21 +0000 | |||
2916 | @@ -26,8 +26,9 @@ | |||
2917 | 26 | from unittest import TestCase | 26 | from unittest import TestCase |
2918 | 27 | from unittest.mock import MagicMock, patch | 27 | from unittest.mock import MagicMock, patch |
2919 | 28 | 28 | ||
2920 | 29 | from openlp.core.common import Registry | ||
2921 | 30 | from openlp.core.common.path import Path | ||
2922 | 29 | from openlp.plugins.songs.lib.importers.songbeamer import SongBeamerImport, SongBeamerTypes | 31 | from openlp.plugins.songs.lib.importers.songbeamer import SongBeamerImport, SongBeamerTypes |
2923 | 30 | from openlp.core.common import Registry | ||
2924 | 31 | 32 | ||
2925 | 32 | from tests.helpers.songfileimport import SongImportTestHelper | 33 | from tests.helpers.songfileimport import SongImportTestHelper |
2926 | 33 | 34 | ||
2927 | @@ -51,18 +52,18 @@ | |||
2928 | 51 | mocked_returned_settings = MagicMock() | 52 | mocked_returned_settings = MagicMock() |
2929 | 52 | mocked_returned_settings.value.side_effect = lambda value: True if value == 'songs/enable chords' else False | 53 | mocked_returned_settings.value.side_effect = lambda value: True if value == 'songs/enable chords' else False |
2930 | 53 | mocked_settings.return_value = mocked_returned_settings | 54 | mocked_settings.return_value = mocked_returned_settings |
2932 | 54 | self.file_import([os.path.join(TEST_PATH, 'Amazing Grace.sng')], | 55 | self.file_import([Path(TEST_PATH, 'Amazing Grace.sng')], |
2933 | 55 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) | 56 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) |
2935 | 56 | self.file_import([os.path.join(TEST_PATH, 'Lobsinget dem Herrn.sng')], | 57 | self.file_import([Path(TEST_PATH, 'Lobsinget dem Herrn.sng')], |
2936 | 57 | self.load_external_result_data(os.path.join(TEST_PATH, 'Lobsinget dem Herrn.json'))) | 58 | self.load_external_result_data(os.path.join(TEST_PATH, 'Lobsinget dem Herrn.json'))) |
2938 | 58 | self.file_import([os.path.join(TEST_PATH, 'When I Call On You.sng')], | 59 | self.file_import([Path(TEST_PATH, 'When I Call On You.sng')], |
2939 | 59 | self.load_external_result_data(os.path.join(TEST_PATH, 'When I Call On You.json'))) | 60 | self.load_external_result_data(os.path.join(TEST_PATH, 'When I Call On You.json'))) |
2940 | 60 | 61 | ||
2941 | 61 | def test_cp1252_encoded_file(self): | 62 | def test_cp1252_encoded_file(self): |
2942 | 62 | """ | 63 | """ |
2943 | 63 | Test that a CP1252 encoded file get's decoded properly. | 64 | Test that a CP1252 encoded file get's decoded properly. |
2944 | 64 | """ | 65 | """ |
2946 | 65 | self.file_import([os.path.join(TEST_PATH, 'cp1252song.sng')], | 66 | self.file_import([Path(TEST_PATH, 'cp1252song.sng')], |
2947 | 66 | self.load_external_result_data(os.path.join(TEST_PATH, 'cp1252song.json'))) | 67 | self.load_external_result_data(os.path.join(TEST_PATH, 'cp1252song.json'))) |
2948 | 67 | 68 | ||
2949 | 68 | 69 | ||
2950 | @@ -78,7 +79,7 @@ | |||
2951 | 78 | self.song_import_patcher = patch('openlp.plugins.songs.lib.importers.songbeamer.SongImport') | 79 | self.song_import_patcher = patch('openlp.plugins.songs.lib.importers.songbeamer.SongImport') |
2952 | 79 | self.song_import_patcher.start() | 80 | self.song_import_patcher.start() |
2953 | 80 | mocked_manager = MagicMock() | 81 | mocked_manager = MagicMock() |
2955 | 81 | self.importer = SongBeamerImport(mocked_manager, filenames=[]) | 82 | self.importer = SongBeamerImport(mocked_manager, file_paths=[]) |
2956 | 82 | 83 | ||
2957 | 83 | def tearDown(self): | 84 | def tearDown(self): |
2958 | 84 | """ | 85 | """ |
2959 | @@ -95,7 +96,7 @@ | |||
2960 | 95 | mocked_manager = MagicMock() | 96 | mocked_manager = MagicMock() |
2961 | 96 | 97 | ||
2962 | 97 | # WHEN: An importer object is created | 98 | # WHEN: An importer object is created |
2964 | 98 | importer = SongBeamerImport(mocked_manager, filenames=[]) | 99 | importer = SongBeamerImport(mocked_manager, file_paths=[]) |
2965 | 99 | 100 | ||
2966 | 100 | # THEN: The importer object should not be None | 101 | # THEN: The importer object should not be None |
2967 | 101 | self.assertIsNotNone(importer, 'Import should not be none') | 102 | self.assertIsNotNone(importer, 'Import should not be none') |
2968 | 102 | 103 | ||
2969 | === modified file 'tests/functional/openlp_plugins/songs/test_songproimport.py' | |||
2970 | --- tests/functional/openlp_plugins/songs/test_songproimport.py 2016-12-31 11:01:36 +0000 | |||
2971 | +++ tests/functional/openlp_plugins/songs/test_songproimport.py 2017-09-30 23:24:21 +0000 | |||
2972 | @@ -23,9 +23,10 @@ | |||
2973 | 23 | The :mod:`songproimport` module provides the functionality for importing | 23 | The :mod:`songproimport` module provides the functionality for importing |
2974 | 24 | SongPro song files into the current installation database. | 24 | SongPro song files into the current installation database. |
2975 | 25 | """ | 25 | """ |
2976 | 26 | |||
2977 | 27 | import os | 26 | import os |
2978 | 28 | 27 | ||
2979 | 28 | from openlp.core.common.path import Path | ||
2980 | 29 | |||
2981 | 29 | from tests.helpers.songfileimport import SongImportTestHelper | 30 | from tests.helpers.songfileimport import SongImportTestHelper |
2982 | 30 | 31 | ||
2983 | 31 | TEST_PATH = os.path.abspath( | 32 | TEST_PATH = os.path.abspath( |
2984 | @@ -43,5 +44,5 @@ | |||
2985 | 43 | """ | 44 | """ |
2986 | 44 | Test that loading an SongPro file works correctly | 45 | Test that loading an SongPro file works correctly |
2987 | 45 | """ | 46 | """ |
2989 | 46 | self.file_import(os.path.join(TEST_PATH, 'amazing-grace.txt'), | 47 | self.file_import(Path(TEST_PATH, 'amazing-grace.txt'), |
2990 | 47 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) | 48 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) |
2991 | 48 | 49 | ||
2992 | === modified file 'tests/functional/openlp_plugins/songs/test_songselect.py' | |||
2993 | --- tests/functional/openlp_plugins/songs/test_songselect.py 2017-05-30 19:40:01 +0000 | |||
2994 | +++ tests/functional/openlp_plugins/songs/test_songselect.py 2017-09-30 23:24:21 +0000 | |||
2995 | @@ -31,6 +31,7 @@ | |||
2996 | 31 | from PyQt5 import QtWidgets | 31 | from PyQt5 import QtWidgets |
2997 | 32 | 32 | ||
2998 | 33 | from openlp.core import Registry | 33 | from openlp.core import Registry |
2999 | 34 | from openlp.core.common.path import Path | ||
3000 | 34 | from openlp.plugins.songs.forms.songselectform import SongSelectForm, SearchWorker | 35 | from openlp.plugins.songs.forms.songselectform import SongSelectForm, SearchWorker |
3001 | 35 | from openlp.plugins.songs.lib import Song | 36 | from openlp.plugins.songs.lib import Song |
3002 | 36 | from openlp.plugins.songs.lib.songselect import SongSelectImport, LOGIN_PAGE, LOGOUT_URL, BASE_URL | 37 | from openlp.plugins.songs.lib.songselect import SongSelectImport, LOGIN_PAGE, LOGOUT_URL, BASE_URL |
3003 | @@ -810,15 +811,15 @@ | |||
3004 | 810 | def __init__(self, *args, **kwargs): | 811 | def __init__(self, *args, **kwargs): |
3005 | 811 | self.importer_class_name = 'CCLIFileImport' | 812 | self.importer_class_name = 'CCLIFileImport' |
3006 | 812 | self.importer_module_name = 'cclifile' | 813 | self.importer_module_name = 'cclifile' |
3008 | 813 | super(TestSongSelectFileImport, self).__init__(*args, **kwargs) | 814 | super().__init__(*args, **kwargs) |
3009 | 814 | 815 | ||
3010 | 815 | def test_song_import(self): | 816 | def test_song_import(self): |
3011 | 816 | """ | 817 | """ |
3012 | 817 | Test that loading an OpenSong file works correctly on various files | 818 | Test that loading an OpenSong file works correctly on various files |
3013 | 818 | """ | 819 | """ |
3015 | 819 | self.file_import([os.path.join(TEST_PATH, 'TestSong.bin')], | 820 | self.file_import([Path(TEST_PATH, 'TestSong.bin')], |
3016 | 820 | self.load_external_result_data(os.path.join(TEST_PATH, 'TestSong-bin.json'))) | 821 | self.load_external_result_data(os.path.join(TEST_PATH, 'TestSong-bin.json'))) |
3018 | 821 | self.file_import([os.path.join(TEST_PATH, 'TestSong.txt')], | 822 | self.file_import([Path(TEST_PATH, 'TestSong.txt')], |
3019 | 822 | self.load_external_result_data(os.path.join(TEST_PATH, 'TestSong-txt.json'))) | 823 | self.load_external_result_data(os.path.join(TEST_PATH, 'TestSong-txt.json'))) |
3020 | 823 | 824 | ||
3021 | 824 | 825 | ||
3022 | 825 | 826 | ||
3023 | === modified file 'tests/functional/openlp_plugins/songs/test_songshowplusimport.py' | |||
3024 | --- tests/functional/openlp_plugins/songs/test_songshowplusimport.py 2017-04-24 05:17:55 +0000 | |||
3025 | +++ tests/functional/openlp_plugins/songs/test_songshowplusimport.py 2017-09-30 23:24:21 +0000 | |||
3026 | @@ -26,6 +26,7 @@ | |||
3027 | 26 | from unittest import TestCase | 26 | from unittest import TestCase |
3028 | 27 | from unittest.mock import patch, MagicMock | 27 | from unittest.mock import patch, MagicMock |
3029 | 28 | 28 | ||
3030 | 29 | from openlp.core.common.path import Path | ||
3031 | 29 | from openlp.plugins.songs.lib import VerseType | 30 | from openlp.plugins.songs.lib import VerseType |
3032 | 30 | from openlp.plugins.songs.lib.importers.songshowplus import SongShowPlusImport | 31 | from openlp.plugins.songs.lib.importers.songshowplus import SongShowPlusImport |
3033 | 31 | 32 | ||
3034 | @@ -46,13 +47,13 @@ | |||
3035 | 46 | """ | 47 | """ |
3036 | 47 | Test that loading a SongShow Plus file works correctly on various files | 48 | Test that loading a SongShow Plus file works correctly on various files |
3037 | 48 | """ | 49 | """ |
3039 | 49 | self.file_import([os.path.join(TEST_PATH, 'Amazing Grace.sbsong')], | 50 | self.file_import([Path(TEST_PATH, 'Amazing Grace.sbsong')], |
3040 | 50 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) | 51 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) |
3042 | 51 | self.file_import([os.path.join(TEST_PATH, 'Beautiful Garden Of Prayer.sbsong')], | 52 | self.file_import([Path(TEST_PATH, 'Beautiful Garden Of Prayer.sbsong')], |
3043 | 52 | self.load_external_result_data(os.path.join(TEST_PATH, 'Beautiful Garden Of Prayer.json'))) | 53 | self.load_external_result_data(os.path.join(TEST_PATH, 'Beautiful Garden Of Prayer.json'))) |
3045 | 53 | self.file_import([os.path.join(TEST_PATH, 'a mighty fortress is our god.sbsong')], | 54 | self.file_import([Path(TEST_PATH, 'a mighty fortress is our god.sbsong')], |
3046 | 54 | self.load_external_result_data(os.path.join(TEST_PATH, 'a mighty fortress is our god.json'))) | 55 | self.load_external_result_data(os.path.join(TEST_PATH, 'a mighty fortress is our god.json'))) |
3048 | 55 | self.file_import([os.path.join(TEST_PATH, 'cleanse-me.sbsong')], | 56 | self.file_import([Path(TEST_PATH, 'cleanse-me.sbsong')], |
3049 | 56 | self.load_external_result_data(os.path.join(TEST_PATH, 'cleanse-me.json'))) | 57 | self.load_external_result_data(os.path.join(TEST_PATH, 'cleanse-me.json'))) |
3050 | 57 | 58 | ||
3051 | 58 | 59 | ||
3052 | @@ -69,7 +70,7 @@ | |||
3053 | 69 | mocked_manager = MagicMock() | 70 | mocked_manager = MagicMock() |
3054 | 70 | 71 | ||
3055 | 71 | # WHEN: An importer object is created | 72 | # WHEN: An importer object is created |
3057 | 72 | importer = SongShowPlusImport(mocked_manager, filenames=[]) | 73 | importer = SongShowPlusImport(mocked_manager, file_paths=[]) |
3058 | 73 | 74 | ||
3059 | 74 | # THEN: The importer object should not be None | 75 | # THEN: The importer object should not be None |
3060 | 75 | self.assertIsNotNone(importer, 'Import should not be none') | 76 | self.assertIsNotNone(importer, 'Import should not be none') |
3061 | @@ -82,7 +83,7 @@ | |||
3062 | 82 | with patch('openlp.plugins.songs.lib.importers.songshowplus.SongImport'): | 83 | with patch('openlp.plugins.songs.lib.importers.songshowplus.SongImport'): |
3063 | 83 | mocked_manager = MagicMock() | 84 | mocked_manager = MagicMock() |
3064 | 84 | mocked_import_wizard = MagicMock() | 85 | mocked_import_wizard = MagicMock() |
3066 | 85 | importer = SongShowPlusImport(mocked_manager, filenames=[]) | 86 | importer = SongShowPlusImport(mocked_manager, file_paths=[]) |
3067 | 86 | importer.import_wizard = mocked_import_wizard | 87 | importer.import_wizard = mocked_import_wizard |
3068 | 87 | importer.stop_import_flag = True | 88 | importer.stop_import_flag = True |
3069 | 88 | 89 | ||
3070 | @@ -103,7 +104,7 @@ | |||
3071 | 103 | with patch('openlp.plugins.songs.lib.importers.songshowplus.SongImport'): | 104 | with patch('openlp.plugins.songs.lib.importers.songshowplus.SongImport'): |
3072 | 104 | mocked_manager = MagicMock() | 105 | mocked_manager = MagicMock() |
3073 | 105 | mocked_import_wizard = MagicMock() | 106 | mocked_import_wizard = MagicMock() |
3075 | 106 | importer = SongShowPlusImport(mocked_manager, filenames=[]) | 107 | importer = SongShowPlusImport(mocked_manager, file_paths=[]) |
3076 | 107 | importer.import_wizard = mocked_import_wizard | 108 | importer.import_wizard = mocked_import_wizard |
3077 | 108 | importer.stop_import_flag = True | 109 | importer.stop_import_flag = True |
3078 | 109 | 110 | ||
3079 | @@ -123,7 +124,7 @@ | |||
3080 | 123 | # GIVEN: A mocked out SongImport class, and a mocked out "manager" | 124 | # GIVEN: A mocked out SongImport class, and a mocked out "manager" |
3081 | 124 | with patch('openlp.plugins.songs.lib.importers.songshowplus.SongImport'): | 125 | with patch('openlp.plugins.songs.lib.importers.songshowplus.SongImport'): |
3082 | 125 | mocked_manager = MagicMock() | 126 | mocked_manager = MagicMock() |
3084 | 126 | importer = SongShowPlusImport(mocked_manager, filenames=[]) | 127 | importer = SongShowPlusImport(mocked_manager, file_paths=[]) |
3085 | 127 | 128 | ||
3086 | 128 | # WHEN: Supplied with the following arguments replicating verses being added | 129 | # WHEN: Supplied with the following arguments replicating verses being added |
3087 | 129 | test_values = [ | 130 | test_values = [ |
3088 | @@ -151,7 +152,7 @@ | |||
3089 | 151 | # GIVEN: A mocked out SongImport class, and a mocked out "manager" | 152 | # GIVEN: A mocked out SongImport class, and a mocked out "manager" |
3090 | 152 | with patch('openlp.plugins.songs.lib.importers.songshowplus.SongImport'): | 153 | with patch('openlp.plugins.songs.lib.importers.songshowplus.SongImport'): |
3091 | 153 | mocked_manager = MagicMock() | 154 | mocked_manager = MagicMock() |
3093 | 154 | importer = SongShowPlusImport(mocked_manager, filenames=[]) | 155 | importer = SongShowPlusImport(mocked_manager, file_paths=[]) |
3094 | 155 | 156 | ||
3095 | 156 | # WHEN: Supplied with the following arguments replicating a verse order being added | 157 | # WHEN: Supplied with the following arguments replicating a verse order being added |
3096 | 157 | test_values = [ | 158 | test_values = [ |
3097 | 158 | 159 | ||
3098 | === modified file 'tests/functional/openlp_plugins/songs/test_sundayplusimport.py' | |||
3099 | --- tests/functional/openlp_plugins/songs/test_sundayplusimport.py 2017-04-24 05:17:55 +0000 | |||
3100 | +++ tests/functional/openlp_plugins/songs/test_sundayplusimport.py 2017-09-30 23:24:21 +0000 | |||
3101 | @@ -24,6 +24,8 @@ | |||
3102 | 24 | import os | 24 | import os |
3103 | 25 | from unittest.mock import patch | 25 | from unittest.mock import patch |
3104 | 26 | 26 | ||
3105 | 27 | from openlp.core.common.path import Path | ||
3106 | 28 | |||
3107 | 27 | from tests.helpers.songfileimport import SongImportTestHelper | 29 | from tests.helpers.songfileimport import SongImportTestHelper |
3108 | 28 | 30 | ||
3109 | 29 | TEST_PATH = os.path.abspath( | 31 | TEST_PATH = os.path.abspath( |
3110 | @@ -44,5 +46,5 @@ | |||
3111 | 44 | with patch('openlp.plugins.songs.lib.importers.sundayplus.retrieve_windows_encoding') as \ | 46 | with patch('openlp.plugins.songs.lib.importers.sundayplus.retrieve_windows_encoding') as \ |
3112 | 45 | mocked_retrieve_windows_encoding: | 47 | mocked_retrieve_windows_encoding: |
3113 | 46 | mocked_retrieve_windows_encoding.return_value = 'cp1252' | 48 | mocked_retrieve_windows_encoding.return_value = 'cp1252' |
3115 | 47 | self.file_import([os.path.join(TEST_PATH, 'Amazing Grace.ptf')], | 49 | self.file_import([Path(TEST_PATH, 'Amazing Grace.ptf')], |
3116 | 48 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) | 50 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) |
3117 | 49 | 51 | ||
3118 | === modified file 'tests/functional/openlp_plugins/songs/test_videopsalm.py' | |||
3119 | --- tests/functional/openlp_plugins/songs/test_videopsalm.py 2017-05-11 20:24:20 +0000 | |||
3120 | +++ tests/functional/openlp_plugins/songs/test_videopsalm.py 2017-09-30 23:24:21 +0000 | |||
3121 | @@ -21,9 +21,10 @@ | |||
3122 | 21 | """ | 21 | """ |
3123 | 22 | This module contains tests for the VideoPsalm song importer. | 22 | This module contains tests for the VideoPsalm song importer. |
3124 | 23 | """ | 23 | """ |
3125 | 24 | |||
3126 | 25 | import os | 24 | import os |
3127 | 26 | 25 | ||
3128 | 26 | from openlp.core.common.path import Path | ||
3129 | 27 | |||
3130 | 27 | from tests.helpers.songfileimport import SongImportTestHelper | 28 | from tests.helpers.songfileimport import SongImportTestHelper |
3131 | 28 | from unittest.mock import patch, MagicMock | 29 | from unittest.mock import patch, MagicMock |
3132 | 29 | 30 | ||
3133 | @@ -48,7 +49,7 @@ | |||
3134 | 48 | mocked_returned_settings.value.side_effect = lambda value: True if value == 'songs/enable chords' else False | 49 | mocked_returned_settings.value.side_effect = lambda value: True if value == 'songs/enable chords' else False |
3135 | 49 | mocked_settings.return_value = mocked_returned_settings | 50 | mocked_settings.return_value = mocked_returned_settings |
3136 | 50 | # Do the test import | 51 | # Do the test import |
3138 | 51 | self.file_import(os.path.join(TEST_PATH, 'videopsalm-as-safe-a-stronghold.json'), | 52 | self.file_import(Path(TEST_PATH, 'videopsalm-as-safe-a-stronghold.json'), |
3139 | 52 | self.load_external_result_data(os.path.join(TEST_PATH, 'as-safe-a-stronghold.json'))) | 53 | self.load_external_result_data(os.path.join(TEST_PATH, 'as-safe-a-stronghold.json'))) |
3141 | 53 | self.file_import(os.path.join(TEST_PATH, 'videopsalm-as-safe-a-stronghold2.json'), | 54 | self.file_import(Path(TEST_PATH, 'videopsalm-as-safe-a-stronghold2.json'), |
3142 | 54 | self.load_external_result_data(os.path.join(TEST_PATH, 'as-safe-a-stronghold2.json'))) | 55 | self.load_external_result_data(os.path.join(TEST_PATH, 'as-safe-a-stronghold2.json'))) |
3143 | 55 | 56 | ||
3144 | === modified file 'tests/functional/openlp_plugins/songs/test_wordsofworshipimport.py' | |||
3145 | --- tests/functional/openlp_plugins/songs/test_wordsofworshipimport.py 2016-12-31 11:01:36 +0000 | |||
3146 | +++ tests/functional/openlp_plugins/songs/test_wordsofworshipimport.py 2017-09-30 23:24:21 +0000 | |||
3147 | @@ -22,9 +22,10 @@ | |||
3148 | 22 | """ | 22 | """ |
3149 | 23 | This module contains tests for the Words of Worship song importer. | 23 | This module contains tests for the Words of Worship song importer. |
3150 | 24 | """ | 24 | """ |
3151 | 25 | |||
3152 | 26 | import os | 25 | import os |
3153 | 27 | 26 | ||
3154 | 27 | from openlp.core.common.path import Path | ||
3155 | 28 | |||
3156 | 28 | from tests.helpers.songfileimport import SongImportTestHelper | 29 | from tests.helpers.songfileimport import SongImportTestHelper |
3157 | 29 | from openlp.plugins.songs.lib.importers.wordsofworship import WordsOfWorshipImport | 30 | from openlp.plugins.songs.lib.importers.wordsofworship import WordsOfWorshipImport |
3158 | 30 | 31 | ||
3159 | @@ -43,10 +44,10 @@ | |||
3160 | 43 | """ | 44 | """ |
3161 | 44 | Test that loading a Words of Worship file works correctly | 45 | Test that loading a Words of Worship file works correctly |
3162 | 45 | """ | 46 | """ |
3164 | 46 | self.file_import([os.path.join(TEST_PATH, 'Amazing Grace (6 Verses).wow-song')], | 47 | self.file_import([Path(TEST_PATH, 'Amazing Grace (6 Verses).wow-song')], |
3165 | 47 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace (6 Verses).json'))) | 48 | self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace (6 Verses).json'))) |
3167 | 48 | self.file_import([os.path.join(TEST_PATH, 'When morning gilds the skies.wsg')], | 49 | self.file_import([Path(TEST_PATH, 'When morning gilds the skies.wsg')], |
3168 | 49 | self.load_external_result_data(os.path.join(TEST_PATH, 'When morning gilds the skies.json'))) | 50 | self.load_external_result_data(os.path.join(TEST_PATH, 'When morning gilds the skies.json'))) |
3170 | 50 | self.file_import([os.path.join(TEST_PATH, 'Holy Holy Holy Lord God Almighty.wow-song')], | 51 | self.file_import([Path(TEST_PATH, 'Holy Holy Holy Lord God Almighty.wow-song')], |
3171 | 51 | self.load_external_result_data(os.path.join(TEST_PATH, | 52 | self.load_external_result_data(os.path.join(TEST_PATH, |
3172 | 52 | 'Holy Holy Holy Lord God Almighty.json'))) | 53 | 'Holy Holy Holy Lord God Almighty.json'))) |
3173 | 53 | 54 | ||
3174 | === modified file 'tests/functional/openlp_plugins/songs/test_worshipassistantimport.py' | |||
3175 | --- tests/functional/openlp_plugins/songs/test_worshipassistantimport.py 2016-12-31 11:01:36 +0000 | |||
3176 | +++ tests/functional/openlp_plugins/songs/test_worshipassistantimport.py 2017-09-30 23:24:21 +0000 | |||
3177 | @@ -23,9 +23,10 @@ | |||
3178 | 23 | The :mod:`worshipassistantimport` module provides the functionality for importing | 23 | The :mod:`worshipassistantimport` module provides the functionality for importing |
3179 | 24 | WorshipAssistant song files into the current installation database. | 24 | WorshipAssistant song files into the current installation database. |
3180 | 25 | """ | 25 | """ |
3181 | 26 | |||
3182 | 27 | import os | 26 | import os |
3183 | 28 | 27 | ||
3184 | 28 | from openlp.core.common.path import Path | ||
3185 | 29 | |||
3186 | 29 | from tests.helpers.songfileimport import SongImportTestHelper | 30 | from tests.helpers.songfileimport import SongImportTestHelper |
3187 | 30 | 31 | ||
3188 | 31 | TEST_PATH = os.path.abspath( | 32 | TEST_PATH = os.path.abspath( |
3189 | @@ -43,9 +44,9 @@ | |||
3190 | 43 | """ | 44 | """ |
3191 | 44 | Test that loading an Worship Assistant file works correctly | 45 | Test that loading an Worship Assistant file works correctly |
3192 | 45 | """ | 46 | """ |
3194 | 46 | self.file_import(os.path.join(TEST_PATH, 'du_herr.csv'), | 47 | self.file_import(Path(TEST_PATH, 'du_herr.csv'), |
3195 | 47 | self.load_external_result_data(os.path.join(TEST_PATH, 'du_herr.json'))) | 48 | self.load_external_result_data(os.path.join(TEST_PATH, 'du_herr.json'))) |
3197 | 48 | self.file_import(os.path.join(TEST_PATH, 'would_you_be_free.csv'), | 49 | self.file_import(Path(TEST_PATH, 'would_you_be_free.csv'), |
3198 | 49 | self.load_external_result_data(os.path.join(TEST_PATH, 'would_you_be_free.json'))) | 50 | self.load_external_result_data(os.path.join(TEST_PATH, 'would_you_be_free.json'))) |
3200 | 50 | self.file_import(os.path.join(TEST_PATH, 'would_you_be_free2.csv'), | 51 | self.file_import(Path(TEST_PATH, 'would_you_be_free2.csv'), |
3201 | 51 | self.load_external_result_data(os.path.join(TEST_PATH, 'would_you_be_free.json'))) | 52 | self.load_external_result_data(os.path.join(TEST_PATH, 'would_you_be_free.json'))) |
3202 | 52 | 53 | ||
3203 | === modified file 'tests/functional/openlp_plugins/songs/test_worshipcenterproimport.py' | |||
3204 | --- tests/functional/openlp_plugins/songs/test_worshipcenterproimport.py 2017-04-24 05:17:55 +0000 | |||
3205 | +++ tests/functional/openlp_plugins/songs/test_worshipcenterproimport.py 2017-09-30 23:24:21 +0000 | |||
3206 | @@ -55,7 +55,7 @@ | |||
3207 | 55 | _title_assignment_list = [] | 55 | _title_assignment_list = [] |
3208 | 56 | 56 | ||
3209 | 57 | def __init__(self, manager): | 57 | def __init__(self, manager): |
3211 | 58 | WorshipCenterProImport.__init__(self, manager, filenames=[]) | 58 | WorshipCenterProImport.__init__(self, manager, file_paths=[]) |
3212 | 59 | 59 | ||
3213 | 60 | @property | 60 | @property |
3214 | 61 | def title(self): | 61 | def title(self): |
3215 | @@ -153,7 +153,7 @@ | |||
3216 | 153 | mocked_manager = MagicMock() | 153 | mocked_manager = MagicMock() |
3217 | 154 | 154 | ||
3218 | 155 | # WHEN: An importer object is created | 155 | # WHEN: An importer object is created |
3220 | 156 | importer = WorshipCenterProImport(mocked_manager, filenames=[]) | 156 | importer = WorshipCenterProImport(mocked_manager, file_paths=[]) |
3221 | 157 | 157 | ||
3222 | 158 | # THEN: The importer object should not be None | 158 | # THEN: The importer object should not be None |
3223 | 159 | self.assertIsNotNone(importer, 'Import should not be none') | 159 | self.assertIsNotNone(importer, 'Import should not be none') |
3224 | @@ -170,7 +170,7 @@ | |||
3225 | 170 | mocked_manager = MagicMock() | 170 | mocked_manager = MagicMock() |
3226 | 171 | mocked_log_error = MagicMock() | 171 | mocked_log_error = MagicMock() |
3227 | 172 | mocked_translate.return_value = 'Translated Text' | 172 | mocked_translate.return_value = 'Translated Text' |
3229 | 173 | importer = WorshipCenterProImport(mocked_manager, filenames=[]) | 173 | importer = WorshipCenterProImport(mocked_manager, file_paths=[]) |
3230 | 174 | importer.log_error = mocked_log_error | 174 | importer.log_error = mocked_log_error |
3231 | 175 | importer.import_source = 'import_source' | 175 | importer.import_source = 'import_source' |
3232 | 176 | pyodbc_errors = [pyodbc.DatabaseError, pyodbc.IntegrityError, pyodbc.InternalError, pyodbc.OperationalError] | 176 | pyodbc_errors = [pyodbc.DatabaseError, pyodbc.IntegrityError, pyodbc.InternalError, pyodbc.OperationalError] |
3233 | 177 | 177 | ||
3234 | === modified file 'tests/functional/openlp_plugins/songs/test_zionworximport.py' | |||
3235 | --- tests/functional/openlp_plugins/songs/test_zionworximport.py 2017-04-24 05:17:55 +0000 | |||
3236 | +++ tests/functional/openlp_plugins/songs/test_zionworximport.py 2017-09-30 23:24:21 +0000 | |||
3237 | @@ -26,9 +26,10 @@ | |||
3238 | 26 | from unittest import TestCase | 26 | from unittest import TestCase |
3239 | 27 | from unittest.mock import MagicMock, patch | 27 | from unittest.mock import MagicMock, patch |
3240 | 28 | 28 | ||
3241 | 29 | from openlp.core.common import Registry | ||
3242 | 30 | from openlp.core.common.path import Path | ||
3243 | 29 | from openlp.plugins.songs.lib.importers.zionworx import ZionWorxImport | 31 | from openlp.plugins.songs.lib.importers.zionworx import ZionWorxImport |
3244 | 30 | from openlp.plugins.songs.lib.importers.songimport import SongImport | 32 | from openlp.plugins.songs.lib.importers.songimport import SongImport |
3245 | 31 | from openlp.core.common import Registry | ||
3246 | 32 | 33 | ||
3247 | 33 | from tests.helpers.songfileimport import SongImportTestHelper | 34 | from tests.helpers.songfileimport import SongImportTestHelper |
3248 | 34 | 35 | ||
3249 | @@ -55,7 +56,7 @@ | |||
3250 | 55 | mocked_manager = MagicMock() | 56 | mocked_manager = MagicMock() |
3251 | 56 | 57 | ||
3252 | 57 | # WHEN: An importer object is created | 58 | # WHEN: An importer object is created |
3254 | 58 | importer = ZionWorxImport(mocked_manager, filenames=[]) | 59 | importer = ZionWorxImport(mocked_manager, file_paths=[]) |
3255 | 59 | 60 | ||
3256 | 60 | # THEN: The importer should be an instance of SongImport | 61 | # THEN: The importer should be an instance of SongImport |
3257 | 61 | self.assertIsInstance(importer, SongImport) | 62 | self.assertIsInstance(importer, SongImport) |
3258 | @@ -72,5 +73,5 @@ | |||
3259 | 72 | """ | 73 | """ |
3260 | 73 | Test that loading an ZionWorx file works correctly on various files | 74 | Test that loading an ZionWorx file works correctly on various files |
3261 | 74 | """ | 75 | """ |
3263 | 75 | self.file_import(os.path.join(TEST_PATH, 'zionworx.csv'), | 76 | self.file_import(Path(TEST_PATH, 'zionworx.csv'), |
3264 | 76 | self.load_external_result_data(os.path.join(TEST_PATH, 'zionworx.json'))) | 77 | self.load_external_result_data(os.path.join(TEST_PATH, 'zionworx.json'))) |
3265 | 77 | 78 | ||
3266 | === modified file 'tests/helpers/songfileimport.py' | |||
3267 | --- tests/helpers/songfileimport.py 2017-04-24 05:17:55 +0000 | |||
3268 | +++ tests/helpers/songfileimport.py 2017-09-30 23:24:21 +0000 | |||
3269 | @@ -89,7 +89,7 @@ | |||
3270 | 89 | """ | 89 | """ |
3271 | 90 | Import the given file and check that it has imported correctly | 90 | Import the given file and check that it has imported correctly |
3272 | 91 | """ | 91 | """ |
3274 | 92 | importer = self.importer_class(self.mocked_manager, filenames=[source_file_name]) | 92 | importer = self.importer_class(self.mocked_manager, file_paths=[source_file_name]) |
3275 | 93 | importer.import_wizard = self.mocked_import_wizard | 93 | importer.import_wizard = self.mocked_import_wizard |
3276 | 94 | importer.stop_import_flag = False | 94 | importer.stop_import_flag = False |
3277 | 95 | importer.topics = [] | 95 | importer.topics = [] |