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

Proposed by Phill
Status: Merged
Approved by: Raoul Snyman
Approved revision: 2783
Merged at revision: 2786
Proposed branch: lp:~phill-ridout/openlp/pathlib9
Merge into: lp:openlp
Diff against target: 2016 lines (+307/-416)
19 files modified
openlp/plugins/bibles/forms/bibleimportform.py (+98/-188)
openlp/plugins/bibles/lib/bibleimport.py (+14/-14)
openlp/plugins/bibles/lib/biblestab.py (+2/-2)
openlp/plugins/bibles/lib/db.py (+18/-16)
openlp/plugins/bibles/lib/importers/__init__.py (+0/-21)
openlp/plugins/bibles/lib/importers/csvbible.py (+12/-11)
openlp/plugins/bibles/lib/importers/opensong.py (+6/-5)
openlp/plugins/bibles/lib/importers/osis.py (+4/-4)
openlp/plugins/bibles/lib/importers/sword.py (+1/-1)
openlp/plugins/bibles/lib/importers/wordproject.py (+11/-16)
openlp/plugins/bibles/lib/importers/zefania.py (+4/-4)
openlp/plugins/bibles/lib/manager.py (+9/-10)
tests/functional/openlp_plugins/bibles/test_bibleimport.py (+24/-23)
tests/functional/openlp_plugins/bibles/test_csvimport.py (+29/-20)
tests/functional/openlp_plugins/bibles/test_opensongimport.py (+18/-17)
tests/functional/openlp_plugins/bibles/test_osisimport.py (+26/-25)
tests/functional/openlp_plugins/bibles/test_swordimport.py (+2/-2)
tests/functional/openlp_plugins/bibles/test_wordprojectimport.py (+23/-32)
tests/functional/openlp_plugins/bibles/test_zefaniaimport.py (+6/-5)
To merge this branch: bzr merge lp:~phill-ridout/openlp/pathlib9
Reviewer Review Type Date Requested Status
Tim Bentley Approve
Raoul Snyman Approve
Review via email: mp+333718@code.launchpad.net

This proposal supersedes a proposal from 2017-10-11.

Description of the change

Add this to your merge proposal:
--------------------------------------------------------------------------------
lp:~phill-ridout/openlp/pathlib9 (revision 2783)
https://ci.openlp.io/job/Branch-01-Pull/2286/ [WAITING]
[RUNNING]
[SUCCESS]
https://ci.openlp.io/job/Branch-02-Functional-Tests/2187/ [WAITING]
[RUNNING]
[SUCCESS]
https://ci.openlp.io/job/Branch-03-Interface-Tests/2068/ [WAITING]
[RUNNING]
[SUCCESS]
https://ci.openlp.io/job/Branch-04a-Code_Analysis/1396/ [WAITING]
[RUNNING]
[SUCCESS]
https://ci.openlp.io/job/Branch-04b-Test_Coverage/1221/ [WAITING]
[RUNNING]
[SUCCESS]
https://ci.openlp.io/job/Branch-04c-Code_Analysis2/351/ [WAITING]
[RUNNING]
[SUCCESS]
https://ci.openlp.io/job/Branch-05-AppVeyor-Tests/183/ [WAITING]
[RUNNING]
[FAILURE]
Stopping after failure, see https://ci.openlp.io/job/Branch-05-AppVeyor-Tests/183/console for more details

To post a comment you must log in.
Revision history for this message
Phill (phill-ridout) wrote : Posted in a previous version of this proposal

Superfly, when you get a mo, could you tell me if 1048, 1828, 1860, 1892 are acceptable, or if I've got it wrong?

Revision history for this message
Tim Bentley (trb143) wrote : Posted in a previous version of this proposal

Looks good but subject answers from superfly.

review: Approve
Revision history for this message
Raoul Snyman (raoul-snyman) wrote : Posted in a previous version of this proposal

I think there's one instance you need to change. Please see my comments below for more guidance.

review: Needs Fixing
Revision history for this message
Raoul Snyman (raoul-snyman) :
review: Approve
Revision history for this message
Tim Bentley (trb143) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openlp/plugins/bibles/forms/bibleimportform.py'
2--- openlp/plugins/bibles/forms/bibleimportform.py 2017-10-23 22:09:57 +0000
3+++ openlp/plugins/bibles/forms/bibleimportform.py 2017-11-14 23:03:10 +0000
4@@ -23,7 +23,6 @@
5 The bible import functions for OpenLP
6 """
7 import logging
8-import os
9 import urllib.error
10 from lxml import etree
11
12@@ -41,6 +40,7 @@
13 from openlp.core.lib.db import delete_database
14 from openlp.core.lib.exceptions import ValidationError
15 from openlp.core.lib.ui import critical_error_message_box
16+from openlp.core.widgets.edits import PathEdit
17 from openlp.core.widgets.wizard import OpenLPWizard, WizardStrings
18 from openlp.plugins.bibles.lib.db import clean_filename
19 from openlp.plugins.bibles.lib.importers.http import CWExtract, BGExtract, BSExtract
20@@ -122,15 +122,9 @@
21 Set up the signals used in the bible importer.
22 """
23 self.web_source_combo_box.currentIndexChanged.connect(self.on_web_source_combo_box_index_changed)
24- self.osis_browse_button.clicked.connect(self.on_osis_browse_button_clicked)
25- self.csv_books_button.clicked.connect(self.on_csv_books_browse_button_clicked)
26- self.csv_verses_button.clicked.connect(self.on_csv_verses_browse_button_clicked)
27- self.open_song_browse_button.clicked.connect(self.on_open_song_browse_button_clicked)
28- self.zefania_browse_button.clicked.connect(self.on_zefania_browse_button_clicked)
29- self.wordproject_browse_button.clicked.connect(self.on_wordproject_browse_button_clicked)
30 self.web_update_button.clicked.connect(self.on_web_update_button_clicked)
31- self.sword_browse_button.clicked.connect(self.on_sword_browse_button_clicked)
32- self.sword_zipbrowse_button.clicked.connect(self.on_sword_zipbrowse_button_clicked)
33+ self.sword_folder_path_edit.pathChanged.connect(self.on_sword_folder_path_edit_path_changed)
34+ self.sword_zipfile_path_edit.pathChanged.connect(self.on_sword_zipfile_path_edit_path_changed)
35
36 def add_custom_pages(self):
37 """
38@@ -161,17 +155,12 @@
39 self.osis_layout.setObjectName('OsisLayout')
40 self.osis_file_label = QtWidgets.QLabel(self.osis_widget)
41 self.osis_file_label.setObjectName('OsisFileLabel')
42- self.osis_file_layout = QtWidgets.QHBoxLayout()
43- self.osis_file_layout.setObjectName('OsisFileLayout')
44- self.osis_file_edit = QtWidgets.QLineEdit(self.osis_widget)
45- self.osis_file_edit.setSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred)
46- self.osis_file_edit.setObjectName('OsisFileEdit')
47- self.osis_file_layout.addWidget(self.osis_file_edit)
48- self.osis_browse_button = QtWidgets.QToolButton(self.osis_widget)
49- self.osis_browse_button.setIcon(self.open_icon)
50- self.osis_browse_button.setObjectName('OsisBrowseButton')
51- self.osis_file_layout.addWidget(self.osis_browse_button)
52- self.osis_layout.addRow(self.osis_file_label, self.osis_file_layout)
53+ self.osis_path_edit = PathEdit(
54+ self.osis_widget,
55+ default_path=Settings().value('bibles/last directory import'),
56+ dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.OSIS),
57+ show_revert=False)
58+ self.osis_layout.addRow(self.osis_file_label, self.osis_path_edit)
59 self.osis_layout.setItem(1, QtWidgets.QFormLayout.LabelRole, self.spacer)
60 self.select_stack.addWidget(self.osis_widget)
61 self.csv_widget = QtWidgets.QWidget(self.select_page)
62@@ -181,30 +170,27 @@
63 self.csv_layout.setObjectName('CsvLayout')
64 self.csv_books_label = QtWidgets.QLabel(self.csv_widget)
65 self.csv_books_label.setObjectName('CsvBooksLabel')
66- self.csv_books_layout = QtWidgets.QHBoxLayout()
67- self.csv_books_layout.setObjectName('CsvBooksLayout')
68- self.csv_books_edit = QtWidgets.QLineEdit(self.csv_widget)
69- self.csv_books_edit.setSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred)
70- self.csv_books_edit.setObjectName('CsvBooksEdit')
71- self.csv_books_layout.addWidget(self.csv_books_edit)
72- self.csv_books_button = QtWidgets.QToolButton(self.csv_widget)
73- self.csv_books_button.setIcon(self.open_icon)
74- self.csv_books_button.setObjectName('CsvBooksButton')
75- self.csv_books_layout.addWidget(self.csv_books_button)
76- self.csv_layout.addRow(self.csv_books_label, self.csv_books_layout)
77+ self.csv_books_path_edit = PathEdit(
78+ self.csv_widget,
79+ default_path=Settings().value('bibles/last directory import'),
80+ dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.CSV),
81+ show_revert=False,
82+ )
83+ self.csv_books_path_edit.filters = \
84+ '{name} (*.csv)'.format(name=translate('BiblesPlugin.ImportWizardForm', 'CSV File'))
85+ self.csv_layout.addRow(self.csv_books_label, self.csv_books_path_edit)
86 self.csv_verses_label = QtWidgets.QLabel(self.csv_widget)
87 self.csv_verses_label.setObjectName('CsvVersesLabel')
88- self.csv_verses_layout = QtWidgets.QHBoxLayout()
89- self.csv_verses_layout.setObjectName('CsvVersesLayout')
90- self.csv_verses_edit = QtWidgets.QLineEdit(self.csv_widget)
91- self.csv_verses_edit.setSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred)
92- self.csv_verses_edit.setObjectName('CsvVersesEdit')
93- self.csv_verses_layout.addWidget(self.csv_verses_edit)
94- self.csv_verses_button = QtWidgets.QToolButton(self.csv_widget)
95- self.csv_verses_button.setIcon(self.open_icon)
96- self.csv_verses_button.setObjectName('CsvVersesButton')
97- self.csv_verses_layout.addWidget(self.csv_verses_button)
98- self.csv_layout.addRow(self.csv_verses_label, self.csv_verses_layout)
99+ self.csv_verses_path_edit = PathEdit(
100+ self.csv_widget,
101+ default_path=Settings().value('bibles/last directory import'),
102+ dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.CSV),
103+ show_revert=False,
104+ )
105+ self.csv_verses_path_edit.filters = \
106+ '{name} (*.csv)'.format(name=translate('BiblesPlugin.ImportWizardForm', 'CSV File'))
107+ self.csv_layout.addRow(self.csv_books_label, self.csv_books_path_edit)
108+ self.csv_layout.addRow(self.csv_verses_label, self.csv_verses_path_edit)
109 self.csv_layout.setItem(3, QtWidgets.QFormLayout.LabelRole, self.spacer)
110 self.select_stack.addWidget(self.csv_widget)
111 self.open_song_widget = QtWidgets.QWidget(self.select_page)
112@@ -214,17 +200,13 @@
113 self.open_song_layout.setObjectName('OpenSongLayout')
114 self.open_song_file_label = QtWidgets.QLabel(self.open_song_widget)
115 self.open_song_file_label.setObjectName('OpenSongFileLabel')
116- self.open_song_file_layout = QtWidgets.QHBoxLayout()
117- self.open_song_file_layout.setObjectName('OpenSongFileLayout')
118- self.open_song_file_edit = QtWidgets.QLineEdit(self.open_song_widget)
119- self.open_song_file_edit.setSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred)
120- self.open_song_file_edit.setObjectName('OpenSongFileEdit')
121- self.open_song_file_layout.addWidget(self.open_song_file_edit)
122- self.open_song_browse_button = QtWidgets.QToolButton(self.open_song_widget)
123- self.open_song_browse_button.setIcon(self.open_icon)
124- self.open_song_browse_button.setObjectName('OpenSongBrowseButton')
125- self.open_song_file_layout.addWidget(self.open_song_browse_button)
126- self.open_song_layout.addRow(self.open_song_file_label, self.open_song_file_layout)
127+ self.open_song_path_edit = PathEdit(
128+ self.open_song_widget,
129+ default_path=Settings().value('bibles/last directory import'),
130+ dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.OS),
131+ show_revert=False,
132+ )
133+ self.open_song_layout.addRow(self.open_song_file_label, self.open_song_path_edit)
134 self.open_song_layout.setItem(1, QtWidgets.QFormLayout.LabelRole, self.spacer)
135 self.select_stack.addWidget(self.open_song_widget)
136 self.web_tab_widget = QtWidgets.QTabWidget(self.select_page)
137@@ -292,17 +274,14 @@
138 self.zefania_layout.setObjectName('ZefaniaLayout')
139 self.zefania_file_label = QtWidgets.QLabel(self.zefania_widget)
140 self.zefania_file_label.setObjectName('ZefaniaFileLabel')
141- self.zefania_file_layout = QtWidgets.QHBoxLayout()
142- self.zefania_file_layout.setObjectName('ZefaniaFileLayout')
143- self.zefania_file_edit = QtWidgets.QLineEdit(self.zefania_widget)
144- self.zefania_file_edit.setObjectName('ZefaniaFileEdit')
145- self.zefania_file_layout.addWidget(self.zefania_file_edit)
146- self.zefania_browse_button = QtWidgets.QToolButton(self.zefania_widget)
147- self.zefania_browse_button.setIcon(self.open_icon)
148- self.zefania_browse_button.setObjectName('ZefaniaBrowseButton')
149- self.zefania_file_layout.addWidget(self.zefania_browse_button)
150- self.zefania_layout.addRow(self.zefania_file_label, self.zefania_file_layout)
151- self.zefania_layout.setItem(5, QtWidgets.QFormLayout.LabelRole, self.spacer)
152+ self.zefania_path_edit = PathEdit(
153+ self.zefania_widget,
154+ default_path=Settings().value('bibles/last directory import'),
155+ dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.ZEF),
156+ show_revert=False,
157+ )
158+ self.zefania_layout.addRow(self.zefania_file_label, self.zefania_path_edit)
159+ self.zefania_layout.setItem(2, QtWidgets.QFormLayout.LabelRole, self.spacer)
160 self.select_stack.addWidget(self.zefania_widget)
161 self.sword_widget = QtWidgets.QWidget(self.select_page)
162 self.sword_widget.setObjectName('SwordWidget')
163@@ -318,16 +297,13 @@
164 self.sword_folder_label = QtWidgets.QLabel(self.sword_folder_tab)
165 self.sword_folder_label.setObjectName('SwordSourceLabel')
166 self.sword_folder_label.setObjectName('SwordFolderLabel')
167- self.sword_folder_edit = QtWidgets.QLineEdit(self.sword_folder_tab)
168- self.sword_folder_edit.setSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred)
169- self.sword_folder_edit.setObjectName('SwordFolderEdit')
170- self.sword_browse_button = QtWidgets.QToolButton(self.sword_folder_tab)
171- self.sword_browse_button.setIcon(self.open_icon)
172- self.sword_browse_button.setObjectName('SwordBrowseButton')
173- self.sword_folder_layout = QtWidgets.QHBoxLayout()
174- self.sword_folder_layout.addWidget(self.sword_folder_edit)
175- self.sword_folder_layout.addWidget(self.sword_browse_button)
176- self.sword_folder_tab_layout.addRow(self.sword_folder_label, self.sword_folder_layout)
177+ self.sword_folder_path_edit = PathEdit(
178+ self.sword_folder_tab,
179+ default_path=Settings().value('bibles/last directory import'),
180+ dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.SWORD),
181+ show_revert=False,
182+ )
183+ self.sword_folder_tab_layout.addRow(self.sword_folder_label, self.sword_folder_path_edit)
184 self.sword_bible_label = QtWidgets.QLabel(self.sword_folder_tab)
185 self.sword_bible_label.setObjectName('SwordBibleLabel')
186 self.sword_bible_combo_box = QtWidgets.QComboBox(self.sword_folder_tab)
187@@ -342,16 +318,13 @@
188 self.sword_zip_layout.setObjectName('SwordZipLayout')
189 self.sword_zipfile_label = QtWidgets.QLabel(self.sword_zip_tab)
190 self.sword_zipfile_label.setObjectName('SwordZipFileLabel')
191- self.sword_zipfile_edit = QtWidgets.QLineEdit(self.sword_zip_tab)
192- self.sword_zipfile_edit.setSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred)
193- self.sword_zipfile_edit.setObjectName('SwordZipFileEdit')
194- self.sword_zipbrowse_button = QtWidgets.QToolButton(self.sword_zip_tab)
195- self.sword_zipbrowse_button.setIcon(self.open_icon)
196- self.sword_zipbrowse_button.setObjectName('SwordZipBrowseButton')
197- self.sword_zipfile_layout = QtWidgets.QHBoxLayout()
198- self.sword_zipfile_layout.addWidget(self.sword_zipfile_edit)
199- self.sword_zipfile_layout.addWidget(self.sword_zipbrowse_button)
200- self.sword_zip_layout.addRow(self.sword_zipfile_label, self.sword_zipfile_layout)
201+ self.sword_zipfile_path_edit = PathEdit(
202+ self.sword_zip_tab,
203+ default_path=Settings().value('bibles/last directory import'),
204+ dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.SWORD),
205+ show_revert=False,
206+ )
207+ self.sword_zip_layout.addRow(self.sword_zipfile_label, self.sword_zipfile_path_edit)
208 self.sword_zipbible_label = QtWidgets.QLabel(self.sword_folder_tab)
209 self.sword_zipbible_label.setObjectName('SwordZipBibleLabel')
210 self.sword_zipbible_combo_box = QtWidgets.QComboBox(self.sword_zip_tab)
211@@ -372,18 +345,13 @@
212 self.wordproject_layout.setObjectName('WordProjectLayout')
213 self.wordproject_file_label = QtWidgets.QLabel(self.wordproject_widget)
214 self.wordproject_file_label.setObjectName('WordProjectFileLabel')
215- self.wordproject_file_layout = QtWidgets.QHBoxLayout()
216- self.wordproject_file_layout.setObjectName('WordProjectFileLayout')
217- self.wordproject_file_edit = QtWidgets.QLineEdit(self.wordproject_widget)
218- self.wordproject_file_edit.setSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred)
219- self.wordproject_file_edit.setObjectName('WordProjectFileEdit')
220- self.wordproject_file_layout.addWidget(self.wordproject_file_edit)
221- self.wordproject_browse_button = QtWidgets.QToolButton(self.wordproject_widget)
222- self.wordproject_browse_button.setIcon(self.open_icon)
223- self.wordproject_browse_button.setObjectName('WordProjectBrowseButton')
224- self.wordproject_file_layout.addWidget(self.wordproject_browse_button)
225- self.wordproject_layout.addRow(self.wordproject_file_label, self.wordproject_file_layout)
226- self.wordproject_layout.setItem(5, QtWidgets.QFormLayout.LabelRole, self.spacer)
227+ self.wordproject_path_edit = PathEdit(
228+ self.wordproject_widget,
229+ default_path=Settings().value('bibles/last directory import'),
230+ dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.WordProject),
231+ show_revert=False)
232+ self.wordproject_layout.addRow(self.wordproject_file_label, self.wordproject_path_edit)
233+ self.wordproject_layout.setItem(1, QtWidgets.QFormLayout.LabelRole, self.spacer)
234 self.select_stack.addWidget(self.wordproject_widget)
235 self.select_page_layout.addLayout(self.select_stack)
236 self.addPage(self.select_page)
237@@ -468,8 +436,6 @@
238 self.sword_bible_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Bibles:'))
239 self.sword_folder_label.setText(translate('BiblesPlugin.ImportWizardForm', 'SWORD data folder:'))
240 self.sword_zipfile_label.setText(translate('BiblesPlugin.ImportWizardForm', 'SWORD zip-file:'))
241- self.sword_folder_edit.setPlaceholderText(translate('BiblesPlugin.ImportWizardForm',
242- 'Defaults to the standard SWORD data folder'))
243 self.sword_zipbible_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Bibles:'))
244 self.sword_tab_widget.setTabText(self.sword_tab_widget.indexOf(self.sword_folder_tab),
245 translate('BiblesPlugin.ImportWizardForm', 'Import from folder'))
246@@ -518,7 +484,7 @@
247 if self.field('source_format') == BibleFormat.OSIS:
248 if not self.field('osis_location'):
249 critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.OSIS)
250- self.osis_file_edit.setFocus()
251+ self.osis_path_edit.setFocus()
252 return False
253 elif self.field('source_format') == BibleFormat.CSV:
254 if not self.field('csv_booksfile'):
255@@ -538,18 +504,18 @@
256 elif self.field('source_format') == BibleFormat.OpenSong:
257 if not self.field('opensong_file'):
258 critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.OS)
259- self.open_song_file_edit.setFocus()
260+ self.open_song_path_edit.setFocus()
261 return False
262 elif self.field('source_format') == BibleFormat.Zefania:
263 if not self.field('zefania_file'):
264 critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.ZEF)
265- self.zefania_file_edit.setFocus()
266+ self.zefania_path_edit.setFocus()
267 return False
268 elif self.field('source_format') == BibleFormat.WordProject:
269 if not self.field('wordproject_file'):
270 critical_error_message_box(UiStrings().NFSs,
271 WizardStrings.YouSpecifyFile % WizardStrings.WordProject)
272- self.wordproject_file_edit.setFocus()
273+ self.wordproject_path_edit.setFocus()
274 return False
275 elif self.field('source_format') == BibleFormat.WebDownload:
276 # If count is 0 the bible list has not yet been downloaded
277@@ -563,7 +529,7 @@
278 if not self.field('sword_folder_path') and self.sword_bible_combo_box.count() == 0:
279 critical_error_message_box(UiStrings().NFSs,
280 WizardStrings.YouSpecifyFolder % WizardStrings.SWORD)
281- self.sword_folder_edit.setFocus()
282+ self.sword_folder_path_edit.setFocus()
283 return False
284 key = self.sword_bible_combo_box.itemData(self.sword_bible_combo_box.currentIndex())
285 if 'description' in self.pysword_folder_modules_json[key]:
286@@ -575,7 +541,7 @@
287 elif self.sword_tab_widget.currentIndex() == self.sword_tab_widget.indexOf(self.sword_zip_tab):
288 if not self.field('sword_zip_path'):
289 critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.SWORD)
290- self.sword_zipfile_edit.setFocus()
291+ self.sword_zipfile_path_edit.setFocus()
292 return False
293 key = self.sword_zipbible_combo_box.itemData(self.sword_zipbible_combo_box.currentIndex())
294 if 'description' in self.pysword_zip_modules_json[key]:
295@@ -586,7 +552,6 @@
296 elif self.currentPage() == self.license_details_page:
297 license_version = self.field('license_version')
298 license_copyright = self.field('license_copyright')
299- path = str(AppLocation.get_section_data_path('bibles'))
300 if not license_version:
301 critical_error_message_box(
302 UiStrings().EmptyField,
303@@ -608,7 +573,7 @@
304 'existing one.'))
305 self.version_name_edit.setFocus()
306 return False
307- elif os.path.exists(os.path.join(path, clean_filename(license_version))):
308+ elif (AppLocation.get_section_data_path('bibles') / clean_filename(license_version)).exists():
309 critical_error_message_box(
310 translate('BiblesPlugin.ImportWizardForm', 'Bible Exists'),
311 translate('BiblesPlugin.ImportWizardForm', 'This Bible already exists. Please import '
312@@ -631,57 +596,6 @@
313 bibles.sort(key=get_locale_key)
314 self.web_translation_combo_box.addItems(bibles)
315
316- def on_osis_browse_button_clicked(self):
317- """
318- Show the file open dialog for the OSIS file.
319- """
320- self.get_file_name(WizardStrings.OpenTypeFile % WizardStrings.OSIS, self.osis_file_edit,
321- 'last directory import')
322-
323- def on_csv_books_browse_button_clicked(self):
324- """
325- Show the file open dialog for the books CSV file.
326- """
327- # TODO: Verify format() with varible template
328- self.get_file_name(
329- WizardStrings.OpenTypeFile % WizardStrings.CSV,
330- self.csv_books_edit,
331- 'last directory import',
332- '{name} (*.csv)'.format(name=translate('BiblesPlugin.ImportWizardForm', 'CSV File')))
333-
334- def on_csv_verses_browse_button_clicked(self):
335- """
336- Show the file open dialog for the verses CSV file.
337- """
338- # TODO: Verify format() with variable template
339- self.get_file_name(WizardStrings.OpenTypeFile % WizardStrings.CSV, self.csv_verses_edit,
340- 'last directory import',
341- '{name} (*.csv)'.format(name=translate('BiblesPlugin.ImportWizardForm', 'CSV File')))
342-
343- def on_open_song_browse_button_clicked(self):
344- """
345- Show the file open dialog for the OpenSong file.
346- """
347- # TODO: Verify format() with variable template
348- self.get_file_name(WizardStrings.OpenTypeFile % WizardStrings.OS, self.open_song_file_edit,
349- 'last directory import')
350-
351- def on_zefania_browse_button_clicked(self):
352- """
353- Show the file open dialog for the Zefania file.
354- """
355- # TODO: Verify format() with variable template
356- self.get_file_name(WizardStrings.OpenTypeFile % WizardStrings.ZEF, self.zefania_file_edit,
357- 'last directory import')
358-
359- def on_wordproject_browse_button_clicked(self):
360- """
361- Show the file open dialog for the WordProject file.
362- """
363- # TODO: Verify format() with variable template
364- self.get_file_name(WizardStrings.OpenTypeFile % WizardStrings.WordProject, self.wordproject_file_edit,
365- 'last directory import')
366-
367 def on_web_update_button_clicked(self):
368 """
369 Download list of bibles from Crosswalk, BibleServer and BibleGateway.
370@@ -718,15 +632,13 @@
371 self.web_update_button.setEnabled(True)
372 self.web_progress_bar.setVisible(False)
373
374- def on_sword_browse_button_clicked(self):
375+ def on_sword_folder_path_edit_path_changed(self, new_path):
376 """
377 Show the file open dialog for the SWORD folder.
378 """
379- self.get_folder(WizardStrings.OpenTypeFolder % WizardStrings.SWORD, self.sword_folder_edit,
380- 'last directory import')
381- if self.sword_folder_edit.text():
382+ if new_path:
383 try:
384- self.pysword_folder_modules = modules.SwordModules(self.sword_folder_edit.text())
385+ self.pysword_folder_modules = modules.SwordModules(str(new_path))
386 self.pysword_folder_modules_json = self.pysword_folder_modules.parse_modules()
387 bible_keys = self.pysword_folder_modules_json.keys()
388 self.sword_bible_combo_box.clear()
389@@ -735,15 +647,13 @@
390 except:
391 self.sword_bible_combo_box.clear()
392
393- def on_sword_zipbrowse_button_clicked(self):
394+ def on_sword_zipfile_path_edit_path_changed(self, new_path):
395 """
396 Show the file open dialog for a SWORD zip-file.
397 """
398- self.get_file_name(WizardStrings.OpenTypeFile % WizardStrings.SWORD, self.sword_zipfile_edit,
399- 'last directory import')
400- if self.sword_zipfile_edit.text():
401+ if new_path:
402 try:
403- self.pysword_zip_modules = modules.SwordModules(self.sword_zipfile_edit.text())
404+ self.pysword_zip_modules = modules.SwordModules(str(new_path))
405 self.pysword_zip_modules_json = self.pysword_zip_modules.parse_modules()
406 bible_keys = self.pysword_zip_modules_json.keys()
407 self.sword_zipbible_combo_box.clear()
408@@ -757,16 +667,16 @@
409 Register the bible import wizard fields.
410 """
411 self.select_page.registerField('source_format', self.format_combo_box)
412- self.select_page.registerField('osis_location', self.osis_file_edit)
413- self.select_page.registerField('csv_booksfile', self.csv_books_edit)
414- self.select_page.registerField('csv_versefile', self.csv_verses_edit)
415- self.select_page.registerField('opensong_file', self.open_song_file_edit)
416- self.select_page.registerField('zefania_file', self.zefania_file_edit)
417- self.select_page.registerField('wordproject_file', self.wordproject_file_edit)
418+ self.select_page.registerField('osis_location', self.osis_path_edit, 'path', PathEdit.pathChanged)
419+ self.select_page.registerField('csv_booksfile', self.csv_books_path_edit, 'path', PathEdit.pathChanged)
420+ self.select_page.registerField('csv_versefile', self.csv_verses_path_edit, 'path', PathEdit.pathChanged)
421+ self.select_page.registerField('opensong_file', self.open_song_path_edit, 'path', PathEdit.pathChanged)
422+ self.select_page.registerField('zefania_file', self.zefania_path_edit, 'path', PathEdit.pathChanged)
423+ self.select_page.registerField('wordproject_file', self.wordproject_path_edit, 'path', PathEdit.pathChanged)
424 self.select_page.registerField('web_location', self.web_source_combo_box)
425 self.select_page.registerField('web_biblename', self.web_translation_combo_box)
426- self.select_page.registerField('sword_folder_path', self.sword_folder_edit)
427- self.select_page.registerField('sword_zip_path', self.sword_zipfile_edit)
428+ self.select_page.registerField('sword_folder_path', self.sword_folder_path_edit, 'path', PathEdit.pathChanged)
429+ self.select_page.registerField('sword_zip_path', self.sword_zipfile_path_edit, 'path', PathEdit.pathChanged)
430 self.select_page.registerField('proxy_server', self.web_server_edit)
431 self.select_page.registerField('proxy_username', self.web_user_edit)
432 self.select_page.registerField('proxy_password', self.web_password_edit)
433@@ -785,13 +695,13 @@
434 self.finish_button.setVisible(False)
435 self.cancel_button.setVisible(True)
436 self.setField('source_format', 0)
437- self.setField('osis_location', '')
438- self.setField('csv_booksfile', '')
439- self.setField('csv_versefile', '')
440- self.setField('opensong_file', '')
441- self.setField('zefania_file', '')
442- self.setField('sword_folder_path', '')
443- self.setField('sword_zip_path', '')
444+ self.setField('osis_location', None)
445+ self.setField('csv_booksfile', None)
446+ self.setField('csv_versefile', None)
447+ self.setField('opensong_file', None)
448+ self.setField('zefania_file', None)
449+ self.setField('sword_folder_path', None)
450+ self.setField('sword_zip_path', None)
451 self.setField('web_location', WebDownload.Crosswalk)
452 self.setField('web_biblename', self.web_translation_combo_box.currentIndex())
453 self.setField('proxy_server', settings.value('proxy address'))
454@@ -833,16 +743,16 @@
455 if bible_type == BibleFormat.OSIS:
456 # Import an OSIS bible.
457 importer = self.manager.import_bible(BibleFormat.OSIS, name=license_version,
458- filename=self.field('osis_location'))
459+ file_path=self.field('osis_location'))
460 elif bible_type == BibleFormat.CSV:
461 # Import a CSV bible.
462 importer = self.manager.import_bible(BibleFormat.CSV, name=license_version,
463- booksfile=self.field('csv_booksfile'),
464- versefile=self.field('csv_versefile'))
465+ books_path=self.field('csv_booksfile'),
466+ verse_path=self.field('csv_versefile'))
467 elif bible_type == BibleFormat.OpenSong:
468 # Import an OpenSong bible.
469 importer = self.manager.import_bible(BibleFormat.OpenSong, name=license_version,
470- filename=self.field('opensong_file'))
471+ file_path=self.field('opensong_file'))
472 elif bible_type == BibleFormat.WebDownload:
473 # Import a bible from the web.
474 self.progress_bar.setMaximum(1)
475@@ -861,11 +771,11 @@
476 elif bible_type == BibleFormat.Zefania:
477 # Import a Zefania bible.
478 importer = self.manager.import_bible(BibleFormat.Zefania, name=license_version,
479- filename=self.field('zefania_file'))
480+ file_path=self.field('zefania_file'))
481 elif bible_type == BibleFormat.WordProject:
482 # Import a WordProject bible.
483 importer = self.manager.import_bible(BibleFormat.WordProject, name=license_version,
484- filename=self.field('wordproject_file'))
485+ file_path=self.field('wordproject_file'))
486 elif bible_type == BibleFormat.SWORD:
487 # Import a SWORD bible.
488 if self.sword_tab_widget.currentIndex() == self.sword_tab_widget.indexOf(self.sword_folder_tab):
489
490=== modified file 'openlp/plugins/bibles/lib/bibleimport.py'
491--- openlp/plugins/bibles/lib/bibleimport.py 2017-10-29 06:01:25 +0000
492+++ openlp/plugins/bibles/lib/bibleimport.py 2017-11-14 23:03:10 +0000
493@@ -37,23 +37,23 @@
494 """
495 def __init__(self, *args, **kwargs):
496 super().__init__(*args, **kwargs)
497- self.filename = kwargs['filename'] if 'filename' in kwargs else None
498+ self.file_path = kwargs.get('file_path')
499 self.wizard = None
500 self.stop_import_flag = False
501 Registry().register_function('openlp_stop_wizard', self.stop_import)
502
503 @staticmethod
504- def is_compressed(file):
505+ def is_compressed(file_path):
506 """
507 Check if the supplied file is compressed
508
509- :param file: A path to the file to check
510+ :param file_path: A path to the file to check
511 """
512- if is_zipfile(file):
513+ if is_zipfile(str(file_path)):
514 critical_error_message_box(
515 message=translate('BiblesPlugin.BibleImport',
516 'The file "{file}" you supplied is compressed. You must decompress it before import.'
517- ).format(file=file))
518+ ).format(file=file_path))
519 return True
520 return False
521
522@@ -143,24 +143,24 @@
523 self.log_debug('No book name supplied. Falling back to guess_id')
524 book_ref_id = guess_id
525 if not book_ref_id:
526- raise ValidationError(msg='Could not resolve book_ref_id in "{}"'.format(self.filename))
527+ raise ValidationError(msg='Could not resolve book_ref_id in "{}"'.format(self.file_path))
528 book_details = BiblesResourcesDB.get_book_by_id(book_ref_id)
529 if book_details is None:
530 raise ValidationError(msg='book_ref_id: {book_ref} Could not be found in the BibleResourcesDB while '
531- 'importing {file}'.format(book_ref=book_ref_id, file=self.filename))
532+ 'importing {file}'.format(book_ref=book_ref_id, file=self.file_path))
533 return self.create_book(name, book_ref_id, book_details['testament_id'])
534
535- def parse_xml(self, filename, use_objectify=False, elements=None, tags=None):
536+ def parse_xml(self, file_path, use_objectify=False, elements=None, tags=None):
537 """
538 Parse and clean the supplied file by removing any elements or tags we don't use.
539- :param filename: The filename of the xml file to parse. Str
540+ :param file_path: The filename of the xml file to parse. Str
541 :param use_objectify: Use the objectify parser rather than the etree parser. (Bool)
542 :param elements: A tuple of element names (Str) to remove along with their content.
543 :param tags: A tuple of element names (Str) to remove, preserving their content.
544 :return: The root element of the xml document
545 """
546 try:
547- with open(filename, 'rb') as import_file:
548+ with file_path.open('rb') as import_file:
549 # NOTE: We don't need to do any of the normal encoding detection here, because lxml does it's own
550 # encoding detection, and the two mechanisms together interfere with each other.
551 if not use_objectify:
552@@ -207,17 +207,17 @@
553 self.log_debug('Stopping import')
554 self.stop_import_flag = True
555
556- def validate_xml_file(self, filename, tag):
557+ def validate_xml_file(self, file_path, tag):
558 """
559 Validate the supplied file
560
561- :param filename: The supplied file
562+ :param file_path: The supplied file
563 :param tag: The expected root tag type
564 :return: True if valid. ValidationError is raised otherwise.
565 """
566- if BibleImport.is_compressed(filename):
567+ if BibleImport.is_compressed(file_path):
568 raise ValidationError(msg='Compressed file')
569- bible = self.parse_xml(filename, use_objectify=True)
570+ bible = self.parse_xml(file_path, use_objectify=True)
571 if bible is None:
572 raise ValidationError(msg='Error when opening file')
573 root_tag = bible.tag.lower()
574
575=== modified file 'openlp/plugins/bibles/lib/biblestab.py'
576--- openlp/plugins/bibles/lib/biblestab.py 2017-10-07 07:05:07 +0000
577+++ openlp/plugins/bibles/lib/biblestab.py 2017-11-14 23:03:10 +0000
578@@ -41,11 +41,11 @@
579 """
580 log.info('Bible Tab loaded')
581
582- def _init_(self, parent, title, visible_title, icon_path):
583+ def _init_(self, *args, **kwargs):
584 self.paragraph_style = True
585 self.show_new_chapters = False
586 self.display_style = 0
587- super(BiblesTab, self).__init__(parent, title, visible_title, icon_path)
588+ super().__init__(*args, **kwargs)
589
590 def setupUi(self):
591 self.setObjectName('BiblesTab')
592
593=== modified file 'openlp/plugins/bibles/lib/db.py'
594--- openlp/plugins/bibles/lib/db.py 2017-10-28 10:04:09 +0000
595+++ openlp/plugins/bibles/lib/db.py 2017-11-14 23:03:10 +0000
596@@ -35,6 +35,7 @@
597 from openlp.core.common import clean_filename
598 from openlp.core.common.applocation import AppLocation
599 from openlp.core.common.i18n import translate
600+from openlp.core.common.path import Path
601 from openlp.core.lib.db import BaseModel, init_db, Manager
602 from openlp.core.lib.ui import critical_error_message_box
603 from openlp.plugins.bibles.lib import BibleStrings, LanguageSelection, upgrade
604@@ -129,10 +130,15 @@
605 :param parent:
606 :param kwargs:
607 ``path``
608- The path to the bible database file.
609+ The path to the bible database file. Type: openlp.core.common.path.Path
610
611 ``name``
612 The name of the database. This is also used as the file name for SQLite databases.
613+
614+ ``file``
615+ Type: openlp.core.common.path.Path
616+
617+ :rtype: None
618 """
619 log.info('BibleDB loaded')
620 self._setup(parent, **kwargs)
621@@ -145,20 +151,20 @@
622 self.session = None
623 if 'path' not in kwargs:
624 raise KeyError('Missing keyword argument "path".')
625+ self.path = kwargs['path']
626 if 'name' not in kwargs and 'file' not in kwargs:
627 raise KeyError('Missing keyword argument "name" or "file".')
628 if 'name' in kwargs:
629 self.name = kwargs['name']
630 if not isinstance(self.name, str):
631 self.name = str(self.name, 'utf-8')
632- self.file = clean_filename(self.name) + '.sqlite'
633+ # TODO: To path object
634+ file_path = Path(clean_filename(self.name) + '.sqlite')
635 if 'file' in kwargs:
636- self.file = kwargs['file']
637- Manager.__init__(self, 'bibles', init_schema, self.file, upgrade)
638+ file_path = kwargs['file']
639+ Manager.__init__(self, 'bibles', init_schema, file_path, upgrade)
640 if self.session and 'file' in kwargs:
641 self.get_name()
642- if 'path' in kwargs:
643- self.path = kwargs['path']
644 self._is_web_bible = None
645
646 def get_name(self):
647@@ -470,9 +476,9 @@
648 Return the cursor object. Instantiate one if it doesn't exist yet.
649 """
650 if BiblesResourcesDB.cursor is None:
651- file_path = os.path.join(str(AppLocation.get_directory(AppLocation.PluginsDir)),
652- 'bibles', 'resources', 'bibles_resources.sqlite')
653- conn = sqlite3.connect(file_path)
654+ file_path = \
655+ AppLocation.get_directory(AppLocation.PluginsDir) / 'bibles' / 'resources' / 'bibles_resources.sqlite'
656+ conn = sqlite3.connect(str(file_path))
657 BiblesResourcesDB.cursor = conn.cursor()
658 return BiblesResourcesDB.cursor
659
660@@ -758,17 +764,13 @@
661 If necessary loads up the database and creates the tables if the database doesn't exist.
662 """
663 if AlternativeBookNamesDB.cursor is None:
664- file_path = os.path.join(
665- str(AppLocation.get_directory(AppLocation.DataDir)), 'bibles', 'alternative_book_names.sqlite')
666- if not os.path.exists(file_path):
667+ file_path = AppLocation.get_directory(AppLocation.DataDir) / 'bibles' / 'alternative_book_names.sqlite'
668+ AlternativeBookNamesDB.conn = sqlite3.connect(str(file_path))
669+ if not file_path.exists():
670 # create new DB, create table alternative_book_names
671- AlternativeBookNamesDB.conn = sqlite3.connect(file_path)
672 AlternativeBookNamesDB.conn.execute(
673 'CREATE TABLE alternative_book_names(id INTEGER NOT NULL, '
674 'book_reference_id INTEGER, language_id INTEGER, name VARCHAR(50), PRIMARY KEY (id))')
675- else:
676- # use existing DB
677- AlternativeBookNamesDB.conn = sqlite3.connect(file_path)
678 AlternativeBookNamesDB.cursor = AlternativeBookNamesDB.conn.cursor()
679 return AlternativeBookNamesDB.cursor
680
681
682=== added file 'openlp/plugins/bibles/lib/importers/__init__.py'
683--- openlp/plugins/bibles/lib/importers/__init__.py 1970-01-01 00:00:00 +0000
684+++ openlp/plugins/bibles/lib/importers/__init__.py 2017-11-14 23:03:10 +0000
685@@ -0,0 +1,24 @@
686+# -*- coding: utf-8 -*-
687+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
688+
689+###############################################################################
690+# OpenLP - Open Source Lyrics Projection #
691+# --------------------------------------------------------------------------- #
692+# Copyright (c) 2008-2017 OpenLP Developers #
693+# --------------------------------------------------------------------------- #
694+# This program is free software; you can redistribute it and/or modify it #
695+# under the terms of the GNU General Public License as published by the Free #
696+# Software Foundation; version 2 of the License. #
697+# #
698+# This program is distributed in the hope that it will be useful, but WITHOUT #
699+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
700+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
701+# more details. #
702+# #
703+# You should have received a copy of the GNU General Public License along #
704+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
705+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
706+###############################################################################
707+"""
708+The :mod:`~openlp.plugins.bibles.lib.importers` module contains importers for the Bibles plugin.
709+"""
710
711=== removed file 'openlp/plugins/bibles/lib/importers/__init__.py'
712--- openlp/plugins/bibles/lib/importers/__init__.py 2017-10-23 22:09:57 +0000
713+++ openlp/plugins/bibles/lib/importers/__init__.py 1970-01-01 00:00:00 +0000
714@@ -1,21 +0,0 @@
715-# -*- coding: utf-8 -*-
716-# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
717-
718-###############################################################################
719-# OpenLP - Open Source Lyrics Projection #
720-# --------------------------------------------------------------------------- #
721-# Copyright (c) 2008-2017 OpenLP Developers #
722-# --------------------------------------------------------------------------- #
723-# This program is free software; you can redistribute it and/or modify it #
724-# under the terms of the GNU General Public License as published by the Free #
725-# Software Foundation; version 2 of the License. #
726-# #
727-# This program is distributed in the hope that it will be useful, but WITHOUT #
728-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
729-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
730-# more details. #
731-# #
732-# You should have received a copy of the GNU General Public License along #
733-# with this program; if not, write to the Free Software Foundation, Inc., 59 #
734-# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
735-###############################################################################
736
737=== modified file 'openlp/plugins/bibles/lib/importers/csvbible.py'
738--- openlp/plugins/bibles/lib/importers/csvbible.py 2017-10-07 07:05:07 +0000
739+++ openlp/plugins/bibles/lib/importers/csvbible.py 2017-11-14 23:03:10 +0000
740@@ -73,8 +73,8 @@
741 """
742 super().__init__(*args, **kwargs)
743 self.log_info(self.__class__.__name__)
744- self.books_file = kwargs['booksfile']
745- self.verses_file = kwargs['versefile']
746+ self.books_path = kwargs['books_path']
747+ self.verses_path = kwargs['verse_path']
748
749 @staticmethod
750 def get_book_name(name, books):
751@@ -92,21 +92,22 @@
752 return book_name
753
754 @staticmethod
755- def parse_csv_file(filename, results_tuple):
756+ def parse_csv_file(file_path, results_tuple):
757 """
758 Parse the supplied CSV file.
759
760- :param filename: The name of the file to parse. Str
761- :param results_tuple: The namedtuple to use to store the results. namedtuple
762- :return: An iterable yielding namedtuples of type results_tuple
763+ :param openlp.core.common.path.Path file_path: The name of the file to parse.
764+ :param namedtuple results_tuple: The namedtuple to use to store the results.
765+ :return: An list of namedtuples of type results_tuple
766+ :rtype: list[namedtuple]
767 """
768 try:
769- encoding = get_file_encoding(Path(filename))['encoding']
770- with open(filename, 'r', encoding=encoding, newline='') as csv_file:
771+ encoding = get_file_encoding(file_path)['encoding']
772+ with file_path.open('r', encoding=encoding, newline='') as csv_file:
773 csv_reader = csv.reader(csv_file, delimiter=',', quotechar='"')
774 return [results_tuple(*line) for line in csv_reader]
775 except (OSError, csv.Error):
776- raise ValidationError(msg='Parsing "{file}" failed'.format(file=filename))
777+ raise ValidationError(msg='Parsing "{file}" failed'.format(file=file_path))
778
779 def process_books(self, books):
780 """
781@@ -159,12 +160,12 @@
782 self.language_id = self.get_language(bible_name)
783 if not self.language_id:
784 return False
785- books = self.parse_csv_file(self.books_file, Book)
786+ books = self.parse_csv_file(self.books_path, Book)
787 self.wizard.progress_bar.setValue(0)
788 self.wizard.progress_bar.setMinimum(0)
789 self.wizard.progress_bar.setMaximum(len(books))
790 book_list = self.process_books(books)
791- verses = self.parse_csv_file(self.verses_file, Verse)
792+ verses = self.parse_csv_file(self.verses_path, Verse)
793 self.wizard.progress_bar.setValue(0)
794 self.wizard.progress_bar.setMaximum(len(books) + 1)
795 self.process_verses(verses, book_list)
796
797=== modified file 'openlp/plugins/bibles/lib/importers/opensong.py'
798--- openlp/plugins/bibles/lib/importers/opensong.py 2016-12-31 11:01:36 +0000
799+++ openlp/plugins/bibles/lib/importers/opensong.py 2017-11-14 23:03:10 +0000
800@@ -46,7 +46,8 @@
801
802 :param number: The raw data from the xml
803 :param previous_number: The previous chapter number
804- :return: Number of current chapter. (Int)
805+ :return: Number of current chapter.
806+ :rtype: int
807 """
808 if number:
809 return int(number.split()[-1])
810@@ -132,13 +133,13 @@
811 :param bible_name: The name of the bible being imported
812 :return: True if import completed, False if import was unsuccessful
813 """
814- self.log_debug('Starting OpenSong import from "{name}"'.format(name=self.filename))
815- self.validate_xml_file(self.filename, 'bible')
816- bible = self.parse_xml(self.filename, use_objectify=True)
817+ self.log_debug('Starting OpenSong import from "{name}"'.format(name=self.file_path))
818+ self.validate_xml_file(self.file_path, 'bible')
819+ bible = self.parse_xml(self.file_path, use_objectify=True)
820 if bible is None:
821 return False
822 # No language info in the opensong format, so ask the user
823- self.language_id = self.get_language_id(bible_name=self.filename)
824+ self.language_id = self.get_language_id(bible_name=str(self.file_path))
825 if not self.language_id:
826 return False
827 self.process_books(bible.b)
828
829=== modified file 'openlp/plugins/bibles/lib/importers/osis.py'
830--- openlp/plugins/bibles/lib/importers/osis.py 2016-12-31 11:01:36 +0000
831+++ openlp/plugins/bibles/lib/importers/osis.py 2017-11-14 23:03:10 +0000
832@@ -159,14 +159,14 @@
833 """
834 Loads a Bible from file.
835 """
836- self.log_debug('Starting OSIS import from "{name}"'.format(name=self.filename))
837- self.validate_xml_file(self.filename, '{http://www.bibletechnologies.net/2003/osis/namespace}osis')
838- bible = self.parse_xml(self.filename, elements=REMOVABLE_ELEMENTS, tags=REMOVABLE_TAGS)
839+ self.log_debug('Starting OSIS import from "{name}"'.format(name=self.file_path))
840+ self.validate_xml_file(self.file_path, '{http://www.bibletechnologies.net/2003/osis/namespace}osis')
841+ bible = self.parse_xml(self.file_path, elements=REMOVABLE_ELEMENTS, tags=REMOVABLE_TAGS)
842 if bible is None:
843 return False
844 # Find bible language
845 language = bible.xpath("//ns:osisText/@xml:lang", namespaces=NS)
846- self.language_id = self.get_language_id(language[0] if language else None, bible_name=self.filename)
847+ self.language_id = self.get_language_id(language[0] if language else None, bible_name=str(self.file_path))
848 if not self.language_id:
849 return False
850 self.process_books(bible)
851
852=== modified file 'openlp/plugins/bibles/lib/importers/sword.py'
853--- openlp/plugins/bibles/lib/importers/sword.py 2017-10-07 07:05:07 +0000
854+++ openlp/plugins/bibles/lib/importers/sword.py 2017-11-14 23:03:10 +0000
855@@ -60,7 +60,7 @@
856 bible = pysword_modules.get_bible_from_module(self.sword_key)
857 language = pysword_module_json['lang']
858 language = language[language.find('.') + 1:]
859- language_id = self.get_language_id(language, bible_name=self.filename)
860+ language_id = self.get_language_id(language, bible_name=str(self.file_path))
861 if not language_id:
862 return False
863 books = bible.get_structure().get_books()
864
865=== modified file 'openlp/plugins/bibles/lib/importers/wordproject.py'
866--- openlp/plugins/bibles/lib/importers/wordproject.py 2016-12-31 11:01:36 +0000
867+++ openlp/plugins/bibles/lib/importers/wordproject.py 2017-11-14 23:03:10 +0000
868@@ -19,15 +19,14 @@
869 # with this program; if not, write to the Free Software Foundation, Inc., 59 #
870 # Temple Place, Suite 330, Boston, MA 02111-1307 USA #
871 ###############################################################################
872-import os
873+import logging
874 import re
875-import logging
876-from codecs import open as copen
877 from tempfile import TemporaryDirectory
878 from zipfile import ZipFile
879
880 from bs4 import BeautifulSoup, Tag, NavigableString
881
882+from openlp.core.common.path import Path
883 from openlp.plugins.bibles.lib.bibleimport import BibleImport
884
885 BOOK_NUMBER_PATTERN = re.compile(r'\[(\d+)\]')
886@@ -51,9 +50,9 @@
887 Unzip the file to a temporary directory
888 """
889 self.tmp = TemporaryDirectory()
890- zip_file = ZipFile(os.path.abspath(self.filename))
891- zip_file.extractall(self.tmp.name)
892- self.base_dir = os.path.join(self.tmp.name, os.path.splitext(os.path.basename(self.filename))[0])
893+ with ZipFile(str(self.file_path)) as zip_file:
894+ zip_file.extractall(self.tmp.name)
895+ self.base_path = Path(self.tmp.name, self.file_path.stem)
896
897 def process_books(self):
898 """
899@@ -62,8 +61,7 @@
900 :param bible_data: parsed xml
901 :return: None
902 """
903- with copen(os.path.join(self.base_dir, 'index.htm'), encoding='utf-8', errors='ignore') as index_file:
904- page = index_file.read()
905+ page = (self.base_path / 'index.htm').read_text(encoding='utf-8', errors='ignore')
906 soup = BeautifulSoup(page, 'lxml')
907 bible_books = soup.find('div', 'textOptions').find_all('li')
908 book_count = len(bible_books)
909@@ -93,9 +91,7 @@
910 :return: None
911 """
912 log.debug(book_link)
913- book_file = os.path.join(self.base_dir, os.path.normpath(book_link))
914- with copen(book_file, encoding='utf-8', errors='ignore') as f:
915- page = f.read()
916+ page = (self.base_path / book_link).read_text(encoding='utf-8', errors='ignore')
917 soup = BeautifulSoup(page, 'lxml')
918 header_div = soup.find('div', 'textHeader')
919 chapters_p = header_div.find('p')
920@@ -114,9 +110,8 @@
921 """
922 Get the verses for a particular book
923 """
924- chapter_file_name = os.path.join(self.base_dir, '{:02d}'.format(book_number), '{}.htm'.format(chapter_number))
925- with copen(chapter_file_name, encoding='utf-8', errors='ignore') as chapter_file:
926- page = chapter_file.read()
927+ chapter_file_path = self.base_path / '{:02d}'.format(book_number) / '{}.htm'.format(chapter_number)
928+ page = chapter_file_path.read_text(encoding='utf-8', errors='ignore')
929 soup = BeautifulSoup(page, 'lxml')
930 text_body = soup.find('div', 'textBody')
931 if text_body:
932@@ -158,9 +153,9 @@
933 """
934 Loads a Bible from file.
935 """
936- self.log_debug('Starting WordProject import from "{name}"'.format(name=self.filename))
937+ self.log_debug('Starting WordProject import from "{name}"'.format(name=self.file_path))
938 self._unzip_file()
939- self.language_id = self.get_language_id(None, bible_name=self.filename)
940+ self.language_id = self.get_language_id(None, bible_name=str(self.file_path))
941 result = False
942 if self.language_id:
943 self.process_books()
944
945=== modified file 'openlp/plugins/bibles/lib/importers/zefania.py'
946--- openlp/plugins/bibles/lib/importers/zefania.py 2017-10-07 07:05:07 +0000
947+++ openlp/plugins/bibles/lib/importers/zefania.py 2017-11-14 23:03:10 +0000
948@@ -45,13 +45,13 @@
949 """
950 Loads a Bible from file.
951 """
952- log.debug('Starting Zefania import from "{name}"'.format(name=self.filename))
953+ log.debug('Starting Zefania import from "{name}"'.format(name=self.file_path))
954 success = True
955 try:
956- xmlbible = self.parse_xml(self.filename, elements=REMOVABLE_ELEMENTS, tags=REMOVABLE_TAGS)
957+ xmlbible = self.parse_xml(self.file_path, elements=REMOVABLE_ELEMENTS, tags=REMOVABLE_TAGS)
958 # Find bible language
959 language = xmlbible.xpath("/XMLBIBLE/INFORMATION/language/text()")
960- language_id = self.get_language_id(language[0] if language else None, bible_name=self.filename)
961+ language_id = self.get_language_id(language[0] if language else None, bible_name=str(self.file_path))
962 if not language_id:
963 return False
964 no_of_books = int(xmlbible.xpath('count(//BIBLEBOOK)'))
965@@ -69,7 +69,7 @@
966 log.debug('Could not find a name, will use number, basically a guess.')
967 book_ref_id = int(bnumber)
968 if not book_ref_id:
969- log.error('Importing books from "{name}" failed'.format(name=self.filename))
970+ log.error('Importing books from "{name}" failed'.format(name=self.file_path))
971 return False
972 book_details = BiblesResourcesDB.get_book_by_id(book_ref_id)
973 db_book = self.create_book(book_details['name'], book_ref_id, book_details['testament_id'])
974
975=== modified file 'openlp/plugins/bibles/lib/manager.py'
976--- openlp/plugins/bibles/lib/manager.py 2017-10-23 22:09:57 +0000
977+++ openlp/plugins/bibles/lib/manager.py 2017-11-14 23:03:10 +0000
978@@ -19,7 +19,6 @@
979 # with this program; if not, write to the Free Software Foundation, Inc., 59 #
980 # Temple Place, Suite 330, Boston, MA 02111-1307 USA #
981 ###############################################################################
982-
983 import logging
984
985 from openlp.core.common import delete_file
986@@ -115,7 +114,7 @@
987 self.settings_section = 'bibles'
988 self.web = 'Web'
989 self.db_cache = None
990- self.path = str(AppLocation.get_section_data_path(self.settings_section))
991+ self.path = AppLocation.get_section_data_path(self.settings_section)
992 self.proxy_name = Settings().value(self.settings_section + '/proxy name')
993 self.suffix = '.sqlite'
994 self.import_wizard = None
995@@ -128,20 +127,20 @@
996 of HTTPBible is loaded instead of the BibleDB class.
997 """
998 log.debug('Reload bibles')
999- files = [str(file) for file in AppLocation.get_files(self.settings_section, self.suffix)]
1000- if 'alternative_book_names.sqlite' in files:
1001- files.remove('alternative_book_names.sqlite')
1002- log.debug('Bible Files {text}'.format(text=files))
1003+ file_paths = AppLocation.get_files(self.settings_section, self.suffix)
1004+ if Path('alternative_book_names.sqlite') in file_paths:
1005+ file_paths.remove(Path('alternative_book_names.sqlite'))
1006+ log.debug('Bible Files {text}'.format(text=file_paths))
1007 self.db_cache = {}
1008- for filename in files:
1009- bible = BibleDB(self.parent, path=self.path, file=filename)
1010+ for file_path in file_paths:
1011+ bible = BibleDB(self.parent, path=self.path, file=file_path)
1012 if not bible.session:
1013 continue
1014 name = bible.get_name()
1015 # Remove corrupted files.
1016 if name is None:
1017 bible.session.close_all()
1018- delete_file(Path(self.path, filename))
1019+ delete_file(self.path / file_path)
1020 continue
1021 log.debug('Bible Name: "{name}"'.format(name=name))
1022 self.db_cache[name] = bible
1023@@ -150,7 +149,7 @@
1024 source = self.db_cache[name].get_object(BibleMeta, 'download_source')
1025 download_name = self.db_cache[name].get_object(BibleMeta, 'download_name').value
1026 meta_proxy = self.db_cache[name].get_object(BibleMeta, 'proxy_server')
1027- web_bible = HTTPBible(self.parent, path=self.path, file=filename, download_source=source.value,
1028+ web_bible = HTTPBible(self.parent, path=self.path, file=file_path, download_source=source.value,
1029 download_name=download_name)
1030 if meta_proxy:
1031 web_bible.proxy_server = meta_proxy.value
1032
1033=== modified file 'tests/functional/openlp_plugins/bibles/test_bibleimport.py'
1034--- tests/functional/openlp_plugins/bibles/test_bibleimport.py 2017-10-29 06:01:25 +0000
1035+++ tests/functional/openlp_plugins/bibles/test_bibleimport.py 2017-11-14 23:03:10 +0000
1036@@ -30,6 +30,7 @@
1037 from PyQt5.QtWidgets import QDialog
1038
1039 from openlp.core.common.i18n import Language
1040+from openlp.core.common.path import Path
1041 from openlp.core.lib.exceptions import ValidationError
1042 from openlp.plugins.bibles.lib.bibleimport import BibleImport
1043 from openlp.plugins.bibles.lib.db import BibleDB
1044@@ -48,7 +49,7 @@
1045 b' <data><unsupported>Test<x>data</x><y>to</y>discard</unsupported></data>\n'
1046 b'</root>'
1047 )
1048- self.open_patcher = patch('builtins.open')
1049+ self.open_patcher = patch.object(Path, 'open')
1050 self.addCleanup(self.open_patcher.stop)
1051 self.mocked_open = self.open_patcher.start()
1052 self.critical_error_message_box_patcher = \
1053@@ -74,8 +75,8 @@
1054 # WHEN: Creating an instance of BibleImport with no key word arguments
1055 instance = BibleImport(MagicMock())
1056
1057- # THEN: The filename attribute should be None
1058- assert instance.filename is None
1059+ # THEN: The file_path attribute should be None
1060+ assert instance.file_path is None
1061 assert isinstance(instance, BibleDB)
1062
1063 def test_init_kwargs_set(self):
1064@@ -84,11 +85,11 @@
1065 """
1066 # GIVEN: A patched BibleDB._setup, BibleImport class and mocked parent
1067 # WHEN: Creating an instance of BibleImport with selected key word arguments
1068- kwargs = {'filename': 'bible.xml'}
1069+ kwargs = {'file_path': 'bible.xml'}
1070 instance = BibleImport(MagicMock(), **kwargs)
1071
1072- # THEN: The filename keyword should be set to bible.xml
1073- assert instance.filename == 'bible.xml'
1074+ # THEN: The file_path keyword should be set to bible.xml
1075+ assert instance.file_path == 'bible.xml'
1076 assert isinstance(instance, BibleDB)
1077
1078 @patch.object(BibleDB, '_setup')
1079@@ -361,7 +362,7 @@
1080 instance.wizard = MagicMock()
1081
1082 # WHEN: Calling parse_xml
1083- result = instance.parse_xml('file.tst')
1084+ result = instance.parse_xml(Path('file.tst'))
1085
1086 # THEN: The result returned should contain the correct data, and should be an instance of eetree_Element
1087 assert etree.tostring(result) == b'<root>\n <data><div>Test<p>data</p><a>to</a>keep</div></data>\n' \
1088@@ -378,7 +379,7 @@
1089 instance.wizard = MagicMock()
1090
1091 # WHEN: Calling parse_xml
1092- result = instance.parse_xml('file.tst', use_objectify=True)
1093+ result = instance.parse_xml(Path('file.tst'), use_objectify=True)
1094
1095 # THEN: The result returned should contain the correct data, and should be an instance of ObjectifiedElement
1096 assert etree.tostring(result) == b'<root><data><div>Test<p>data</p><a>to</a>keep</div></data>' \
1097@@ -396,7 +397,7 @@
1098 instance.wizard = MagicMock()
1099
1100 # WHEN: Calling parse_xml, with a test file
1101- result = instance.parse_xml('file.tst', elements=elements)
1102+ result = instance.parse_xml(Path('file.tst'), elements=elements)
1103
1104 # THEN: The result returned should contain the correct data
1105 assert etree.tostring(result) == \
1106@@ -413,7 +414,7 @@
1107 instance.wizard = MagicMock()
1108
1109 # WHEN: Calling parse_xml, with a test file
1110- result = instance.parse_xml('file.tst', tags=tags)
1111+ result = instance.parse_xml(Path('file.tst'), tags=tags)
1112
1113 # THEN: The result returned should contain the correct data
1114 assert etree.tostring(result) == b'<root>\n <data>Testdatatokeep</data>\n <data><unsupported>Test' \
1115@@ -431,7 +432,7 @@
1116 instance.wizard = MagicMock()
1117
1118 # WHEN: Calling parse_xml, with a test file
1119- result = instance.parse_xml('file.tst', elements=elements, tags=tags)
1120+ result = instance.parse_xml(Path('file.tst'), elements=elements, tags=tags)
1121
1122 # THEN: The result returned should contain the correct data
1123 assert etree.tostring(result) == b'<root>\n <data>Testdatatokeep</data>\n <data/>\n</root>'
1124@@ -446,10 +447,10 @@
1125 exception.filename = 'file.tst'
1126 exception.strerror = 'No such file or directory'
1127 self.mocked_open.side_effect = exception
1128- importer = BibleImport(MagicMock(), path='.', name='.', filename='')
1129+ importer = BibleImport(MagicMock(), path='.', name='.', file_path=None)
1130
1131 # WHEN: Calling parse_xml
1132- result = importer.parse_xml('file.tst')
1133+ result = importer.parse_xml(Path('file.tst'))
1134
1135 # THEN: parse_xml should have caught the error, informed the user and returned None
1136 mocked_log_exception.assert_called_once_with('Opening file.tst failed.')
1137@@ -468,10 +469,10 @@
1138 exception.filename = 'file.tst'
1139 exception.strerror = 'Permission denied'
1140 self.mocked_open.side_effect = exception
1141- importer = BibleImport(MagicMock(), path='.', name='.', filename='')
1142+ importer = BibleImport(MagicMock(), path='.', name='.', file_path=None)
1143
1144 # WHEN: Calling parse_xml
1145- result = importer.parse_xml('file.tst')
1146+ result = importer.parse_xml(Path('file.tst'))
1147
1148 # THEN: parse_xml should have caught the error, informed the user and returned None
1149 mocked_log_exception.assert_called_once_with('Opening file.tst failed.')
1150@@ -485,7 +486,7 @@
1151 Test set_current_chapter
1152 """
1153 # GIVEN: An instance of BibleImport and a mocked wizard
1154- importer = BibleImport(MagicMock(), path='.', name='.', filename='')
1155+ importer = BibleImport(MagicMock(), path='.', name='.', file_path=None)
1156 importer.wizard = MagicMock()
1157
1158 # WHEN: Calling set_current_chapter
1159@@ -500,7 +501,7 @@
1160 Test that validate_xml_file raises a ValidationError when is_compressed returns True
1161 """
1162 # GIVEN: A mocked parse_xml which returns None
1163- importer = BibleImport(MagicMock(), path='.', name='.', filename='')
1164+ importer = BibleImport(MagicMock(), path='.', name='.', file_path=None)
1165
1166 # WHEN: Calling is_compressed
1167 # THEN: ValidationError should be raised, with the message 'Compressed file'
1168@@ -515,7 +516,7 @@
1169 Test that validate_xml_file raises a ValidationError when parse_xml returns None
1170 """
1171 # GIVEN: A mocked parse_xml which returns None
1172- importer = BibleImport(MagicMock(), path='.', name='.', filename='')
1173+ importer = BibleImport(MagicMock(), path='.', name='.', file_path=None)
1174
1175 # WHEN: Calling validate_xml_file
1176 # THEN: ValidationError should be raised, with the message 'Error when opening file'
1177@@ -531,7 +532,7 @@
1178 Test that validate_xml_file returns True with valid XML
1179 """
1180 # GIVEN: Some test data with an OpenSong Bible "bible" root tag
1181- importer = BibleImport(MagicMock(), path='.', name='.', filename='')
1182+ importer = BibleImport(MagicMock(), path='.', name='.', file_path=None)
1183
1184 # WHEN: Calling validate_xml_file
1185 result = importer.validate_xml_file('file.name', 'bible')
1186@@ -546,7 +547,7 @@
1187 Test that validate_xml_file raises a ValidationError with an OpenSong root tag
1188 """
1189 # GIVEN: Some test data with an Zefania root tag and an instance of BibleImport
1190- importer = BibleImport(MagicMock(), path='.', name='.', filename='')
1191+ importer = BibleImport(MagicMock(), path='.', name='.', file_path=None)
1192
1193 # WHEN: Calling validate_xml_file
1194 # THEN: ValidationError should be raised, and the critical error message box should was called informing
1195@@ -566,7 +567,7 @@
1196 # GIVEN: Some test data with an Zefania root tag and an instance of BibleImport
1197 mocked_parse_xml.return_value = objectify.fromstring(
1198 '<osis xmlns=\'http://www.bibletechnologies.net/2003/OSIS/namespace\'></osis>')
1199- importer = BibleImport(MagicMock(), path='.', name='.', filename='')
1200+ importer = BibleImport(MagicMock(), path='.', name='.', file_path=None)
1201
1202 # WHEN: Calling validate_xml_file
1203 # THEN: ValidationError should be raised, and the critical error message box should was called informing
1204@@ -584,7 +585,7 @@
1205 Test that validate_xml_file raises a ValidationError with an Zefania root tag
1206 """
1207 # GIVEN: Some test data with an Zefania root tag and an instance of BibleImport
1208- importer = BibleImport(MagicMock(), path='.', name='.', filename='')
1209+ importer = BibleImport(MagicMock(), path='.', name='.', file_path=None)
1210
1211 # WHEN: Calling validate_xml_file
1212 # THEN: ValidationError should be raised, and the critical error message box should was called informing
1213@@ -602,7 +603,7 @@
1214 Test that validate_xml_file raises a ValidationError with an unknown root tag
1215 """
1216 # GIVEN: Some test data with an unknown root tag and an instance of BibleImport
1217- importer = BibleImport(MagicMock(), path='.', name='.', filename='')
1218+ importer = BibleImport(MagicMock(), path='.', name='.', file_path=None)
1219
1220 # WHEN: Calling validate_xml_file
1221 # THEN: ValidationError should be raised, and the critical error message box should was called informing
1222
1223=== modified file 'tests/functional/openlp_plugins/bibles/test_csvimport.py'
1224--- tests/functional/openlp_plugins/bibles/test_csvimport.py 2017-10-29 06:01:25 +0000
1225+++ tests/functional/openlp_plugins/bibles/test_csvimport.py 2017-11-14 23:03:10 +0000
1226@@ -29,6 +29,7 @@
1227 from unittest import TestCase
1228 from unittest.mock import ANY, MagicMock, PropertyMock, call, patch
1229
1230+from openlp.core.common.path import Path
1231 from openlp.core.lib.exceptions import ValidationError
1232 from openlp.plugins.bibles.lib.bibleimport import BibleImport
1233 from openlp.plugins.bibles.lib.importers.csvbible import Book, CSVBible, Verse
1234@@ -59,12 +60,13 @@
1235 mocked_manager = MagicMock()
1236
1237 # WHEN: An importer object is created
1238- importer = CSVBible(mocked_manager, path='.', name='.', booksfile='books.csv', versefile='verse.csv')
1239+ importer = \
1240+ CSVBible(mocked_manager, path='.', name='.', books_path=Path('books.csv'), verse_path=Path('verse.csv'))
1241
1242 # THEN: The importer should be an instance of BibleImport
1243 self.assertIsInstance(importer, BibleImport)
1244- self.assertEqual(importer.books_file, 'books.csv')
1245- self.assertEqual(importer.verses_file, 'verse.csv')
1246+ self.assertEqual(importer.books_path, Path('books.csv'))
1247+ self.assertEqual(importer.verses_path, Path('verse.csv'))
1248
1249 def test_book_namedtuple(self):
1250 """
1251@@ -134,17 +136,17 @@
1252
1253 with patch('openlp.plugins.bibles.lib.importers.csvbible.get_file_encoding',
1254 return_value={'encoding': 'utf-8', 'confidence': 0.99}),\
1255- patch('openlp.plugins.bibles.lib.importers.csvbible.open', create=True) as mocked_open,\
1256+ patch('openlp.plugins.bibles.lib.importers.csvbible.Path.open', create=True) as mocked_open,\
1257 patch('openlp.plugins.bibles.lib.importers.csvbible.csv.reader',
1258 return_value=iter(test_data)) as mocked_reader:
1259
1260 # WHEN: Calling the CSVBible parse_csv_file method with a file name and TestTuple
1261- result = CSVBible.parse_csv_file('file.csv', TestTuple)
1262+ result = CSVBible.parse_csv_file(Path('file.csv'), TestTuple)
1263
1264 # THEN: A list of TestTuple instances with the parsed data should be returned
1265 self.assertEqual(result, [TestTuple('1', 'Line 1', 'Data 1'), TestTuple('2', 'Line 2', 'Data 2'),
1266 TestTuple('3', 'Line 3', 'Data 3')])
1267- mocked_open.assert_called_once_with('file.csv', 'r', encoding='utf-8', newline='')
1268+ mocked_open.assert_called_once_with('r', encoding='utf-8', newline='')
1269 mocked_reader.assert_called_once_with(ANY, delimiter=',', quotechar='"')
1270
1271 def test_parse_csv_file_oserror(self):
1272@@ -154,12 +156,12 @@
1273 # GIVEN: Mocked a mocked open object which raises an OSError
1274 with patch('openlp.plugins.bibles.lib.importers.csvbible.get_file_encoding',
1275 return_value={'encoding': 'utf-8', 'confidence': 0.99}),\
1276- patch('openlp.plugins.bibles.lib.importers.csvbible.open', side_effect=OSError, create=True):
1277+ patch('openlp.plugins.bibles.lib.importers.csvbible.Path.open', side_effect=OSError, create=True):
1278
1279 # WHEN: Calling CSVBible.parse_csv_file
1280 # THEN: A ValidationError should be raised
1281 with self.assertRaises(ValidationError) as context:
1282- CSVBible.parse_csv_file('file.csv', None)
1283+ CSVBible.parse_csv_file(Path('file.csv'), None)
1284 self.assertEqual(context.exception.msg, 'Parsing "file.csv" failed')
1285
1286 def test_parse_csv_file_csverror(self):
1287@@ -169,13 +171,13 @@
1288 # GIVEN: Mocked a csv.reader which raises an csv.Error
1289 with patch('openlp.plugins.bibles.lib.importers.csvbible.get_file_encoding',
1290 return_value={'encoding': 'utf-8', 'confidence': 0.99}),\
1291- patch('openlp.plugins.bibles.lib.importers.csvbible.open', create=True),\
1292+ patch('openlp.plugins.bibles.lib.importers.csvbible.Path.open', create=True),\
1293 patch('openlp.plugins.bibles.lib.importers.csvbible.csv.reader', side_effect=csv.Error):
1294
1295 # WHEN: Calling CSVBible.parse_csv_file
1296 # THEN: A ValidationError should be raised
1297 with self.assertRaises(ValidationError) as context:
1298- CSVBible.parse_csv_file('file.csv', None)
1299+ CSVBible.parse_csv_file(Path('file.csv'), None)
1300 self.assertEqual(context.exception.msg, 'Parsing "file.csv" failed')
1301
1302 def test_process_books_stopped_import(self):
1303@@ -185,7 +187,8 @@
1304 # GIVEN: An instance of CSVBible with the stop_import_flag set to True
1305 mocked_manager = MagicMock()
1306 with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'):
1307- importer = CSVBible(mocked_manager, path='.', name='.', booksfile='books.csv', versefile='verse.csv')
1308+ importer = CSVBible(mocked_manager, path='.', name='.', books_path=Path('books.csv'),
1309+ verse_path=Path('verse.csv'))
1310 type(importer).application = PropertyMock()
1311 importer.stop_import_flag = True
1312 importer.wizard = MagicMock()
1313@@ -205,7 +208,8 @@
1314 mocked_manager = MagicMock()
1315 with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'),\
1316 patch('openlp.plugins.bibles.lib.importers.csvbible.translate'):
1317- importer = CSVBible(mocked_manager, path='.', name='.', booksfile='books.csv', versefile='verse.csv')
1318+ importer = CSVBible(mocked_manager, path='.', name='.', books_path=Path('books.csv'),
1319+ verse_path=Path('verse.csv'))
1320 importer.find_and_create_book = MagicMock()
1321 importer.language_id = 10
1322 importer.stop_import_flag = False
1323@@ -229,7 +233,8 @@
1324 # GIVEN: An instance of CSVBible with the stop_import_flag set to True
1325 mocked_manager = MagicMock()
1326 with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'):
1327- importer = CSVBible(mocked_manager, path='.', name='.', booksfile='books.csv', versefile='verse.csv')
1328+ importer = CSVBible(mocked_manager, path='.', name='.', books_path=Path('books.csv'),
1329+ verse_path=Path('verse.csv'))
1330 importer.get_book_name = MagicMock()
1331 importer.session = MagicMock()
1332 importer.stop_import_flag = True
1333@@ -250,7 +255,8 @@
1334 mocked_manager = MagicMock()
1335 with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'),\
1336 patch('openlp.plugins.bibles.lib.importers.csvbible.translate'):
1337- importer = CSVBible(mocked_manager, path='.', name='.', booksfile='books.csv', versefile='verse.csv')
1338+ importer = CSVBible(mocked_manager, path='.', name='.', books_path=Path('books.csv'),
1339+ verse_path=Path('verse.csv'))
1340 importer.create_verse = MagicMock()
1341 importer.get_book = MagicMock(return_value=Book('1', '1', '1. Mosebog', '1Mos'))
1342 importer.get_book_name = MagicMock(return_value='1. Mosebog')
1343@@ -281,7 +287,8 @@
1344 # GIVEN: An instance of CSVBible and a mocked get_language which simulates the user cancelling the language box
1345 mocked_manager = MagicMock()
1346 with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'):
1347- importer = CSVBible(mocked_manager, path='.', name='.', booksfile='books.csv', versefile='verse.csv')
1348+ importer = CSVBible(mocked_manager, path='.', name='.', books_path=Path('books.csv'),
1349+ verse_path=Path('verse.csv'))
1350 importer.get_language = MagicMock(return_value=None)
1351
1352 # WHEN: Calling do_import
1353@@ -298,7 +305,8 @@
1354 # GIVEN: An instance of CSVBible
1355 mocked_manager = MagicMock()
1356 with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'):
1357- importer = CSVBible(mocked_manager, path='.', name='.', booksfile='books.csv', versefile='verses.csv')
1358+ importer = CSVBible(mocked_manager, path='.', name='.', books_path=Path('books.csv'),
1359+ verse_path=Path('verses.csv'))
1360 importer.get_language = MagicMock(return_value=10)
1361 importer.parse_csv_file = MagicMock(side_effect=[['Book 1'], ['Verse 1']])
1362 importer.process_books = MagicMock(return_value=['Book 1'])
1363@@ -312,7 +320,8 @@
1364
1365 # THEN: parse_csv_file should be called twice,
1366 # and True should be returned.
1367- self.assertEqual(importer.parse_csv_file.mock_calls, [call('books.csv', Book), call('verses.csv', Verse)])
1368+ self.assertEqual(importer.parse_csv_file.mock_calls,
1369+ [call(Path('books.csv'), Book), call(Path('verses.csv'), Verse)])
1370 importer.process_books.assert_called_once_with(['Book 1'])
1371 importer.process_verses.assert_called_once_with(['Verse 1'], ['Book 1'])
1372 self.assertTrue(result)
1373@@ -325,12 +334,12 @@
1374 # get_book_ref_id_by_name, create_verse, create_book, session and get_language.
1375 result_file = open(os.path.join(TEST_PATH, 'dk1933.json'), 'rb')
1376 test_data = json.loads(result_file.read().decode())
1377- books_file = os.path.join(TEST_PATH, 'dk1933-books.csv')
1378- verses_file = os.path.join(TEST_PATH, 'dk1933-verses.csv')
1379+ books_file = Path(TEST_PATH, 'dk1933-books.csv')
1380+ verses_file = Path(TEST_PATH, 'dk1933-verses.csv')
1381 with patch('openlp.plugins.bibles.lib.importers.csvbible.CSVBible.application'):
1382 mocked_manager = MagicMock()
1383 mocked_import_wizard = MagicMock()
1384- importer = CSVBible(mocked_manager, path='.', name='.', booksfile=books_file, versefile=verses_file)
1385+ importer = CSVBible(mocked_manager, path='.', name='.', books_path=books_file, verse_path=verses_file)
1386 importer.wizard = mocked_import_wizard
1387 importer.get_book_ref_id_by_name = MagicMock()
1388 importer.create_verse = MagicMock()
1389
1390=== modified file 'tests/functional/openlp_plugins/bibles/test_opensongimport.py'
1391--- tests/functional/openlp_plugins/bibles/test_opensongimport.py 2017-10-29 06:01:25 +0000
1392+++ tests/functional/openlp_plugins/bibles/test_opensongimport.py 2017-11-14 23:03:10 +0000
1393@@ -29,6 +29,7 @@
1394
1395 from lxml import objectify
1396
1397+from openlp.core.common.path import Path
1398 from openlp.core.common.registry import Registry
1399 from openlp.plugins.bibles.lib.importers.opensong import OpenSongBible, get_text, parse_chapter_number
1400 from openlp.plugins.bibles.lib.bibleimport import BibleImport
1401@@ -64,7 +65,7 @@
1402 mocked_manager = MagicMock()
1403
1404 # WHEN: An importer object is created
1405- importer = OpenSongBible(mocked_manager, path='.', name='.', filename='')
1406+ importer = OpenSongBible(mocked_manager, path='.', name='.', file_path=None)
1407
1408 # THEN: The importer should be an instance of BibleDB
1409 self.assertIsInstance(importer, BibleImport)
1410@@ -126,7 +127,7 @@
1411 Test parse_verse_number when supplied with a valid verse number
1412 """
1413 # GIVEN: An instance of OpenSongBible, the number 15 represented as a string and an instance of OpenSongBible
1414- importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')
1415+ importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
1416
1417 # WHEN: Calling parse_verse_number
1418 result = importer.parse_verse_number('15', 0)
1419@@ -139,7 +140,7 @@
1420 Test parse_verse_number when supplied with a verse range
1421 """
1422 # GIVEN: An instance of OpenSongBible, and the range 24-26 represented as a string
1423- importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')
1424+ importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
1425
1426 # WHEN: Calling parse_verse_number
1427 result = importer.parse_verse_number('24-26', 0)
1428@@ -152,7 +153,7 @@
1429 Test parse_verse_number when supplied with a invalid verse number
1430 """
1431 # GIVEN: An instance of OpenSongBible, a non numeric string represented as a string
1432- importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')
1433+ importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
1434
1435 # WHEN: Calling parse_verse_number
1436 result = importer.parse_verse_number('invalid', 41)
1437@@ -165,7 +166,7 @@
1438 Test parse_verse_number when the verse number is an empty string. (Bug #1074727)
1439 """
1440 # GIVEN: An instance of OpenSongBible, an empty string, and the previous verse number set as 14
1441- importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')
1442+ importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
1443 # WHEN: Calling parse_verse_number
1444 result = importer.parse_verse_number('', 14)
1445
1446@@ -178,7 +179,7 @@
1447 """
1448 with patch.object(OpenSongBible, 'log_warning')as mocked_log_warning:
1449 # GIVEN: An instanceofOpenSongBible, a Tuple, and the previous verse number set as 12
1450- importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')
1451+ importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
1452
1453 # WHEN: Calling parse_verse_number
1454 result = importer.parse_verse_number((1, 2, 3), 12)
1455@@ -193,7 +194,7 @@
1456 Test process_books when stop_import is set to True
1457 """
1458 # GIVEN: An instance of OpenSongBible
1459- importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')
1460+ importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
1461
1462 # WHEN: stop_import_flag is set to True
1463 importer.stop_import_flag = True
1464@@ -209,7 +210,7 @@
1465 # GIVEN: An instance of OpenSongBible Importer and two mocked books
1466 self.mocked_find_and_create_book.side_effect = ['db_book1', 'db_book2']
1467 with patch.object(OpenSongBible, 'process_chapters') as mocked_process_chapters:
1468- importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')
1469+ importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
1470
1471 book1 = MagicMock()
1472 book1.attrib = {'n': 'Name1'}
1473@@ -236,7 +237,7 @@
1474 Test process_chapters when stop_import is set to True
1475 """
1476 # GIVEN: An isntance of OpenSongBible
1477- importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')
1478+ importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
1479 importer.parse_chapter_number = MagicMock()
1480
1481 # WHEN: stop_import_flag is set to True
1482@@ -252,7 +253,7 @@
1483 Test process_chapters when it completes
1484 """
1485 # GIVEN: An instance of OpenSongBible
1486- importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')
1487+ importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
1488 importer.wizard = MagicMock()
1489
1490 # WHEN: called with some valid data
1491@@ -284,7 +285,7 @@
1492 Test process_verses when stop_import is set to True
1493 """
1494 # GIVEN: An isntance of OpenSongBible
1495- importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')
1496+ importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
1497 importer.parse_verse_number = MagicMock()
1498
1499 # WHEN: stop_import_flag is set to True
1500@@ -303,7 +304,7 @@
1501 patch.object(OpenSongBible, 'parse_verse_number',
1502 **{'side_effect': [1, 2]}) as mocked_parse_verse_number:
1503 # GIVEN: An instance of OpenSongBible
1504- importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')
1505+ importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
1506 importer.wizard = MagicMock()
1507
1508 # WHEN: called with some valid data
1509@@ -338,7 +339,7 @@
1510 patch.object(OpenSongBible, 'validate_xml_file'), \
1511 patch.object(OpenSongBible, 'parse_xml', return_value=None), \
1512 patch.object(OpenSongBible, 'get_language_id') as mocked_language_id:
1513- importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')
1514+ importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
1515
1516 # WHEN: Calling do_import
1517 result = importer.do_import()
1518@@ -357,7 +358,7 @@
1519 patch.object(OpenSongBible, 'parse_xml'), \
1520 patch.object(OpenSongBible, 'get_language_id', return_value=False), \
1521 patch.object(OpenSongBible, 'process_books') as mocked_process_books:
1522- importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')
1523+ importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
1524
1525 # WHEN: Calling do_import
1526 result = importer.do_import()
1527@@ -376,7 +377,7 @@
1528 patch.object(OpenSongBible, 'parse_xml'), \
1529 patch.object(OpenSongBible, 'get_language_id', return_value=10), \
1530 patch.object(OpenSongBible, 'process_books'):
1531- importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')
1532+ importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
1533
1534 # WHEN: Calling do_import
1535 result = importer.do_import()
1536@@ -406,7 +407,7 @@
1537 with patch('openlp.plugins.bibles.lib.importers.opensong.OpenSongBible.application'):
1538 mocked_manager = MagicMock()
1539 mocked_import_wizard = MagicMock()
1540- importer = OpenSongBible(mocked_manager, path='.', name='.', filename='')
1541+ importer = OpenSongBible(mocked_manager, path='.', name='.', file_path=None)
1542 importer.wizard = mocked_import_wizard
1543 importer.get_book_ref_id_by_name = MagicMock()
1544 importer.create_verse = MagicMock()
1545@@ -416,7 +417,7 @@
1546 importer.get_language.return_value = 'Danish'
1547
1548 # WHEN: Importing bible file
1549- importer.filename = os.path.join(TEST_PATH, bible_file)
1550+ importer.file_path = Path(TEST_PATH, bible_file)
1551 importer.do_import()
1552
1553 # THEN: The create_verse() method should have been called with each verse in the file.
1554
1555=== modified file 'tests/functional/openlp_plugins/bibles/test_osisimport.py'
1556--- tests/functional/openlp_plugins/bibles/test_osisimport.py 2017-10-29 06:01:25 +0000
1557+++ tests/functional/openlp_plugins/bibles/test_osisimport.py 2017-11-14 23:03:10 +0000
1558@@ -27,6 +27,7 @@
1559 from unittest import TestCase
1560 from unittest.mock import MagicMock, call, patch
1561
1562+from openlp.core.common.path import Path
1563 from openlp.plugins.bibles.lib.bibleimport import BibleImport
1564 from openlp.plugins.bibles.lib.db import BibleDB
1565 from openlp.plugins.bibles.lib.importers.osis import OSISBible
1566@@ -63,7 +64,7 @@
1567 mocked_manager = MagicMock()
1568
1569 # WHEN: An importer object is created
1570- importer = OSISBible(mocked_manager, path='.', name='.', filename='')
1571+ importer = OSISBible(mocked_manager, path='.', name='.', file_path=None)
1572
1573 # THEN: The importer should be an instance of BibleDB
1574 self.assertIsInstance(importer, BibleDB)
1575@@ -73,7 +74,7 @@
1576 Test process_books when stop_import is set to True
1577 """
1578 # GIVEN: An instance of OSISBible adn some mocked data
1579- importer = OSISBible(MagicMock(), path='.', name='.', filename='')
1580+ importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
1581 mocked_data = MagicMock(**{'xpath.return_value': ['Book']})
1582
1583 # WHEN: stop_import_flag is set to True and process_books is called
1584@@ -90,7 +91,7 @@
1585 # GIVEN: An instance of OSISBible Importer and two mocked books
1586 self.mocked_find_and_create_book.side_effect = ['db_book1', 'db_book2']
1587 with patch.object(OSISBible, 'process_chapters') as mocked_process_chapters:
1588- importer = OSISBible(MagicMock(), path='.', name='.', filename='')
1589+ importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
1590
1591 book1 = MagicMock()
1592 book1.get.return_value = 'Name1'
1593@@ -128,7 +129,7 @@
1594 test_chapter = MagicMock()
1595 test_chapter.__iter__.return_value = [test_verse]
1596 test_chapter.get.side_effect = lambda x: {'osisID': '1.2.4', 'sID': '999'}.get(x)
1597- importer = OSISBible(MagicMock(), path='.', name='.', filename='')
1598+ importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
1599
1600 # WHEN: Calling process_chapters
1601 importer.process_chapters(test_book, [test_chapter])
1602@@ -155,7 +156,7 @@
1603 test_chapter = MagicMock()
1604 test_chapter.__iter__.return_value = [test_verse]
1605 test_chapter.get.side_effect = lambda x: {'osisID': '1.2.4', 'sID': '999'}.get(x)
1606- importer = OSISBible(MagicMock(), path='.', name='.', filename='')
1607+ importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
1608
1609 # WHEN: Calling process_chapters
1610 importer.process_chapters(test_book, [test_chapter])
1611@@ -180,7 +181,7 @@
1612 test_chapter.get.side_effect = lambda x: {'osisID': '1.2.4'}.get(x)
1613
1614 # WHEN: Calling process_chapters
1615- importer = OSISBible(MagicMock(), path='.', name='.', filename='')
1616+ importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
1617 importer.process_chapters(test_book, [test_chapter])
1618
1619 # THEN: neither set_current_chapter or process_verse should have been called
1620@@ -201,7 +202,7 @@
1621 test_chapter = MagicMock()
1622 test_chapter.tag = '{http://www.bibletechnologies.net/2003/OSIS/namespace}chapter'
1623 test_chapter.get.side_effect = lambda x: {'osisID': '1.2.4', 'sID': '999'}.get(x)
1624- importer = OSISBible(MagicMock(), path='.', name='.', filename='')
1625+ importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
1626
1627 # WHEN: Calling process_chapters
1628 importer.process_chapters(test_book, [test_chapter])
1629@@ -228,7 +229,7 @@
1630 test_verse.text = 'Verse Text'
1631
1632 # WHEN: Calling process_chapters
1633- importer = OSISBible(MagicMock(), path='.', name='.', filename='')
1634+ importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
1635 importer.process_chapters(test_book, [test_verse])
1636
1637 # THEN: process_verse should have been called with the test data
1638@@ -245,7 +246,7 @@
1639 test_verse.get.side_effect = lambda x: {}.get(x)
1640 test_verse.tail = 'Verse Text'
1641 test_verse.text = None
1642- importer = OSISBible(MagicMock(), path='.', name='.', filename='')
1643+ importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
1644
1645 # WHEN: Calling process_verse with the test data
1646 importer.process_verse(test_book, 2, test_verse)
1647@@ -264,7 +265,7 @@
1648 test_verse.get.side_effect = lambda x: {}.get(x)
1649 test_verse.tail = 'Verse Text'
1650 test_verse.text = None
1651- importer = OSISBible(MagicMock(), path='.', name='.', filename='')
1652+ importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
1653
1654 # WHEN: Calling process_verse with the test data
1655 importer.process_verse(test_book, 2, test_verse)
1656@@ -282,7 +283,7 @@
1657 test_verse.tail = None
1658 test_verse.text = None
1659 test_verse.get.side_effect = lambda x: {'osisID': '1.2.4', 'sID': '999'}.get(x)
1660- importer = OSISBible(MagicMock(), path='.', name='.', filename='')
1661+ importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
1662
1663 # WHEN: Calling process_verse with the test data
1664 importer.process_verse(test_book, 2, test_verse, use_milestones=True)
1665@@ -301,7 +302,7 @@
1666 test_verse.tail = 'Verse Text'
1667 test_verse.text = None
1668 test_verse.get.side_effect = lambda x: {'osisID': '1.2.4', 'sID': '999'}.get(x)
1669- importer = OSISBible(MagicMock(), path='.', name='.', filename='')
1670+ importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
1671
1672 # WHEN: Calling process_verse with the test data
1673 importer.process_verse(test_book, 2, test_verse, use_milestones=True)
1674@@ -320,7 +321,7 @@
1675 test_verse.tail = '\n ' # Whitespace
1676 test_verse.text = None
1677 test_verse.get.side_effect = lambda x: {'osisID': '1.2.4', 'sID': '999'}.get(x)
1678- importer = OSISBible(MagicMock(), path='.', name='.', filename='')
1679+ importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
1680
1681 # WHEN: Calling process_verse with the test data
1682 importer.process_verse(test_book, 2, test_verse)
1683@@ -339,7 +340,7 @@
1684 test_verse.tail = '\n ' # Whitespace
1685 test_verse.text = 'Verse Text'
1686 test_verse.get.side_effect = lambda x: {'osisID': '1.2.4', 'sID': '999'}.get(x)
1687- importer = OSISBible(MagicMock(), path='.', name='.', filename='')
1688+ importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
1689
1690 # WHEN: Calling process_verse with the test data
1691 importer.process_verse(test_book, 2, test_verse)
1692@@ -356,7 +357,7 @@
1693 patch.object(OSISBible, 'validate_xml_file'), \
1694 patch.object(OSISBible, 'parse_xml', return_value=None), \
1695 patch.object(OSISBible, 'get_language_id') as mocked_language_id:
1696- importer = OSISBible(MagicMock(), path='.', name='.', filename='')
1697+ importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
1698
1699 # WHEN: Calling do_import
1700 result = importer.do_import()
1701@@ -375,7 +376,7 @@
1702 patch.object(OSISBible, 'parse_xml'), \
1703 patch.object(OSISBible, 'get_language_id', **{'return_value': False}), \
1704 patch.object(OSISBible, 'process_books') as mocked_process_books:
1705- importer = OSISBible(MagicMock(), path='.', name='.', filename='')
1706+ importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
1707
1708 # WHEN: Calling do_import
1709 result = importer.do_import()
1710@@ -394,7 +395,7 @@
1711 patch.object(OSISBible, 'parse_xml'), \
1712 patch.object(OSISBible, 'get_language_id', **{'return_value': 10}), \
1713 patch.object(OSISBible, 'process_books'):
1714- importer = OSISBible(MagicMock(), path='.', name='.', filename='')
1715+ importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
1716
1717 # WHEN: Calling do_import
1718 result = importer.do_import()
1719@@ -427,7 +428,7 @@
1720 with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'):
1721 mocked_manager = MagicMock()
1722 mocked_import_wizard = MagicMock()
1723- importer = OSISBible(mocked_manager, path='.', name='.', filename='')
1724+ importer = OSISBible(mocked_manager, path='.', name='.', file_path=None)
1725 importer.wizard = mocked_import_wizard
1726 importer.get_book_ref_id_by_name = MagicMock()
1727 importer.create_verse = MagicMock()
1728@@ -437,7 +438,7 @@
1729 importer.get_language.return_value = 'Danish'
1730
1731 # WHEN: Importing bible file
1732- importer.filename = os.path.join(TEST_PATH, bible_file)
1733+ importer.file_path = Path(TEST_PATH, bible_file)
1734 importer.do_import()
1735
1736 # THEN: The create_verse() method should have been called with each verse in the file.
1737@@ -457,7 +458,7 @@
1738 with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'):
1739 mocked_manager = MagicMock()
1740 mocked_import_wizard = MagicMock()
1741- importer = OSISBible(mocked_manager, path='.', name='.', filename='')
1742+ importer = OSISBible(mocked_manager, path='.', name='.', file_path=None)
1743 importer.wizard = mocked_import_wizard
1744 importer.get_book_ref_id_by_name = MagicMock()
1745 importer.create_verse = MagicMock()
1746@@ -467,7 +468,7 @@
1747 importer.get_language.return_value = 'English'
1748
1749 # WHEN: Importing bible file
1750- importer.filename = os.path.join(TEST_PATH, bible_file)
1751+ importer.file_path = Path(TEST_PATH, bible_file)
1752 importer.do_import()
1753
1754 # THEN: The create_verse() method should have been called with each verse in the file.
1755@@ -487,7 +488,7 @@
1756 with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'):
1757 mocked_manager = MagicMock()
1758 mocked_import_wizard = MagicMock()
1759- importer = OSISBible(mocked_manager, path='.', name='.', filename='')
1760+ importer = OSISBible(mocked_manager, path='.', name='.', file_path=None)
1761 importer.wizard = mocked_import_wizard
1762 importer.get_book_ref_id_by_name = MagicMock()
1763 importer.create_verse = MagicMock()
1764@@ -497,7 +498,7 @@
1765 importer.get_language.return_value = 'English'
1766
1767 # WHEN: Importing bible file
1768- importer.filename = os.path.join(TEST_PATH, bible_file)
1769+ importer.file_path = Path(TEST_PATH, bible_file)
1770 importer.do_import()
1771
1772 # THEN: The create_verse() method should have been called with each verse in the file.
1773@@ -517,7 +518,7 @@
1774 with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'):
1775 mocked_manager = MagicMock()
1776 mocked_import_wizard = MagicMock()
1777- importer = OSISBible(mocked_manager, path='.', name='.', filename='')
1778+ importer = OSISBible(mocked_manager, path='.', name='.', file_path=None)
1779 importer.wizard = mocked_import_wizard
1780 importer.get_book_ref_id_by_name = MagicMock()
1781 importer.create_verse = MagicMock()
1782@@ -527,7 +528,7 @@
1783 importer.get_language.return_value = 'Danish'
1784
1785 # WHEN: Importing bible file
1786- importer.filename = os.path.join(TEST_PATH, bible_file)
1787+ importer.file_path = Path(TEST_PATH, bible_file)
1788 importer.do_import()
1789
1790 # THEN: The create_verse() method should have been called with each verse in the file.
1791
1792=== modified file 'tests/functional/openlp_plugins/bibles/test_swordimport.py'
1793--- tests/functional/openlp_plugins/bibles/test_swordimport.py 2017-04-24 05:17:55 +0000
1794+++ tests/functional/openlp_plugins/bibles/test_swordimport.py 2017-11-14 23:03:10 +0000
1795@@ -64,7 +64,7 @@
1796 mocked_manager = MagicMock()
1797
1798 # WHEN: An importer object is created
1799- importer = SwordBible(mocked_manager, path='.', name='.', filename='', sword_key='', sword_path='')
1800+ importer = SwordBible(mocked_manager, path='.', name='.', file_path=None, sword_key='', sword_path='')
1801
1802 # THEN: The importer should be an instance of BibleDB
1803 self.assertIsInstance(importer, BibleDB)
1804@@ -80,7 +80,7 @@
1805 # Also mocked pysword structures
1806 mocked_manager = MagicMock()
1807 mocked_import_wizard = MagicMock()
1808- importer = SwordBible(mocked_manager, path='.', name='.', filename='', sword_key='', sword_path='')
1809+ importer = SwordBible(mocked_manager, path='.', name='.', file_path=None, sword_key='', sword_path='')
1810 result_file = open(os.path.join(TEST_PATH, 'dk1933.json'), 'rb')
1811 test_data = json.loads(result_file.read().decode())
1812 importer.wizard = mocked_import_wizard
1813
1814=== modified file 'tests/functional/openlp_plugins/bibles/test_wordprojectimport.py'
1815--- tests/functional/openlp_plugins/bibles/test_wordprojectimport.py 2017-04-24 05:17:55 +0000
1816+++ tests/functional/openlp_plugins/bibles/test_wordprojectimport.py 2017-11-14 23:03:10 +0000
1817@@ -26,6 +26,7 @@
1818 from unittest import TestCase
1819 from unittest.mock import MagicMock, patch, call
1820
1821+from openlp.core.common.path import Path
1822 from openlp.plugins.bibles.lib.importers.wordproject import WordProjectBible
1823
1824
1825@@ -48,19 +49,17 @@
1826 self.addCleanup(self.manager_patcher.stop)
1827 self.manager_patcher.start()
1828
1829- @patch('openlp.plugins.bibles.lib.importers.wordproject.os')
1830- @patch('openlp.plugins.bibles.lib.importers.wordproject.copen')
1831- def test_process_books(self, mocked_open, mocked_os):
1832+ @patch.object(Path, 'read_text')
1833+ def test_process_books(self, mocked_read_text):
1834 """
1835 Test the process_books() method
1836 """
1837 # GIVEN: A WordProject importer and a bunch of mocked things
1838- importer = WordProjectBible(MagicMock(), path='.', name='.', filename='kj.zip')
1839- importer.base_dir = ''
1840+ importer = WordProjectBible(MagicMock(), path='.', name='.', file_path=Path('kj.zip'))
1841+ importer.base_path = Path()
1842 importer.stop_import_flag = False
1843 importer.language_id = 'en'
1844- mocked_open.return_value.__enter__.return_value.read.return_value = INDEX_PAGE
1845- mocked_os.path.join.side_effect = lambda *x: ''.join(x)
1846+ mocked_read_text.return_value = INDEX_PAGE
1847
1848 # WHEN: process_books() is called
1849 with patch.object(importer, 'find_and_create_book') as mocked_find_and_create_book, \
1850@@ -69,26 +68,22 @@
1851 importer.process_books()
1852
1853 # THEN: The right methods should have been called
1854- mocked_os.path.join.assert_called_once_with('', 'index.htm')
1855- mocked_open.assert_called_once_with('index.htm', encoding='utf-8', errors='ignore')
1856+ mocked_read_text.assert_called_once_with(encoding='utf-8', errors='ignore')
1857 assert mocked_find_and_create_book.call_count == 66, 'There should be 66 books'
1858 assert mocked_process_chapters.call_count == 66, 'There should be 66 books'
1859 assert mocked_session.commit.call_count == 66, 'There should be 66 books'
1860
1861- @patch('openlp.plugins.bibles.lib.importers.wordproject.os')
1862- @patch('openlp.plugins.bibles.lib.importers.wordproject.copen')
1863- def test_process_chapters(self, mocked_open, mocked_os):
1864+ @patch.object(Path, 'read_text')
1865+ def test_process_chapters(self, mocked_read_text):
1866 """
1867 Test the process_chapters() method
1868 """
1869 # GIVEN: A WordProject importer and a bunch of mocked things
1870- importer = WordProjectBible(MagicMock(), path='.', name='.', filename='kj.zip')
1871- importer.base_dir = ''
1872+ importer = WordProjectBible(MagicMock(), path='.', name='.', file_path=Path('kj.zip'))
1873+ importer.base_path = Path()
1874 importer.stop_import_flag = False
1875 importer.language_id = 'en'
1876- mocked_open.return_value.__enter__.return_value.read.return_value = CHAPTER_PAGE
1877- mocked_os.path.join.side_effect = lambda *x: ''.join(x)
1878- mocked_os.path.normpath.side_effect = lambda x: x
1879+ mocked_read_text.return_value = CHAPTER_PAGE
1880 mocked_db_book = MagicMock()
1881 mocked_db_book.name = 'Genesis'
1882 book_id = 1
1883@@ -102,24 +97,21 @@
1884 # THEN: The right methods should have been called
1885 expected_set_current_chapter_calls = [call('Genesis', ch) for ch in range(1, 51)]
1886 expected_process_verses_calls = [call(mocked_db_book, 1, ch) for ch in range(1, 51)]
1887- mocked_os.path.join.assert_called_once_with('', '01/1.htm')
1888- mocked_open.assert_called_once_with('01/1.htm', encoding='utf-8', errors='ignore')
1889+ mocked_read_text.assert_called_once_with(encoding='utf-8', errors='ignore')
1890 assert mocked_set_current_chapter.call_args_list == expected_set_current_chapter_calls
1891 assert mocked_process_verses.call_args_list == expected_process_verses_calls
1892
1893- @patch('openlp.plugins.bibles.lib.importers.wordproject.os')
1894- @patch('openlp.plugins.bibles.lib.importers.wordproject.copen')
1895- def test_process_verses(self, mocked_open, mocked_os):
1896+ @patch.object(Path, 'read_text')
1897+ def test_process_verses(self, mocked_read_text):
1898 """
1899 Test the process_verses() method
1900 """
1901 # GIVEN: A WordProject importer and a bunch of mocked things
1902- importer = WordProjectBible(MagicMock(), path='.', name='.', filename='kj.zip')
1903- importer.base_dir = ''
1904+ importer = WordProjectBible(MagicMock(), path='.', name='.', file_path=Path('kj.zip'))
1905+ importer.base_path = Path()
1906 importer.stop_import_flag = False
1907 importer.language_id = 'en'
1908- mocked_open.return_value.__enter__.return_value.read.return_value = CHAPTER_PAGE
1909- mocked_os.path.join.side_effect = lambda *x: '/'.join(x)
1910+ mocked_read_text.return_value = CHAPTER_PAGE
1911 mocked_db_book = MagicMock()
1912 mocked_db_book.name = 'Genesis'
1913 book_number = 1
1914@@ -130,8 +122,7 @@
1915 importer.process_verses(mocked_db_book, book_number, chapter_number)
1916
1917 # THEN: All the right methods should have been called
1918- mocked_os.path.join.assert_called_once_with('', '01', '1.htm')
1919- mocked_open.assert_called_once_with('/01/1.htm', encoding='utf-8', errors='ignore')
1920+ mocked_read_text.assert_called_once_with(encoding='utf-8', errors='ignore')
1921 assert mocked_process_verse.call_count == 31
1922
1923 def test_process_verse(self):
1924@@ -139,7 +130,7 @@
1925 Test the process_verse() method
1926 """
1927 # GIVEN: An importer and a mocked method
1928- importer = WordProjectBible(MagicMock(), path='.', name='.', filename='kj.zip')
1929+ importer = WordProjectBible(MagicMock(), path='.', name='.', file_path=Path('kj.zip'))
1930 mocked_db_book = MagicMock()
1931 mocked_db_book.id = 1
1932 chapter_number = 1
1933@@ -158,7 +149,7 @@
1934 Test the process_verse() method when there's no text
1935 """
1936 # GIVEN: An importer and a mocked method
1937- importer = WordProjectBible(MagicMock(), path='.', name='.', filename='kj.zip')
1938+ importer = WordProjectBible(MagicMock(), path='.', name='.', file_path=Path('kj.zip'))
1939 mocked_db_book = MagicMock()
1940 mocked_db_book.id = 1
1941 chapter_number = 1
1942@@ -177,7 +168,7 @@
1943 Test the do_import() method
1944 """
1945 # GIVEN: An importer and mocked methods
1946- importer = WordProjectBible(MagicMock(), path='.', name='.', filename='kj.zip')
1947+ importer = WordProjectBible(MagicMock(), path='.', name='.', file_path='kj.zip')
1948
1949 # WHEN: do_import() is called
1950 with patch.object(importer, '_unzip_file') as mocked_unzip_file, \
1951@@ -199,7 +190,7 @@
1952 Test the do_import() method when the language is not available
1953 """
1954 # GIVEN: An importer and mocked methods
1955- importer = WordProjectBible(MagicMock(), path='.', name='.', filename='kj.zip')
1956+ importer = WordProjectBible(MagicMock(), path='.', name='.', file_path='kj.zip')
1957
1958 # WHEN: do_import() is called
1959 with patch.object(importer, '_unzip_file') as mocked_unzip_file, \
1960
1961=== modified file 'tests/functional/openlp_plugins/bibles/test_zefaniaimport.py'
1962--- tests/functional/openlp_plugins/bibles/test_zefaniaimport.py 2017-04-24 05:17:55 +0000
1963+++ tests/functional/openlp_plugins/bibles/test_zefaniaimport.py 2017-11-14 23:03:10 +0000
1964@@ -27,6 +27,7 @@
1965 from unittest import TestCase
1966 from unittest.mock import MagicMock, patch
1967
1968+from openlp.core.common.path import Path
1969 from openlp.plugins.bibles.lib.importers.zefania import ZefaniaBible
1970 from openlp.plugins.bibles.lib.db import BibleDB
1971
1972@@ -55,7 +56,7 @@
1973 mocked_manager = MagicMock()
1974
1975 # WHEN: An importer object is created
1976- importer = ZefaniaBible(mocked_manager, path='.', name='.', filename='')
1977+ importer = ZefaniaBible(mocked_manager, path='.', name='.', file_path=None)
1978
1979 # THEN: The importer should be an instance of BibleDB
1980 self.assertIsInstance(importer, BibleDB)
1981@@ -72,7 +73,7 @@
1982 with patch('openlp.plugins.bibles.lib.importers.zefania.ZefaniaBible.application'):
1983 mocked_manager = MagicMock()
1984 mocked_import_wizard = MagicMock()
1985- importer = ZefaniaBible(mocked_manager, path='.', name='.', filename='')
1986+ importer = ZefaniaBible(mocked_manager, path='.', name='.', file_path=None)
1987 importer.wizard = mocked_import_wizard
1988 importer.create_verse = MagicMock()
1989 importer.create_book = MagicMock()
1990@@ -81,7 +82,7 @@
1991 importer.get_language.return_value = 'Danish'
1992
1993 # WHEN: Importing bible file
1994- importer.filename = os.path.join(TEST_PATH, bible_file)
1995+ importer.file_path = Path(TEST_PATH, bible_file)
1996 importer.do_import()
1997
1998 # THEN: The create_verse() method should have been called with each verse in the file.
1999@@ -102,7 +103,7 @@
2000 with patch('openlp.plugins.bibles.lib.importers.zefania.ZefaniaBible.application'):
2001 mocked_manager = MagicMock()
2002 mocked_import_wizard = MagicMock()
2003- importer = ZefaniaBible(mocked_manager, path='.', name='.', filename='')
2004+ importer = ZefaniaBible(mocked_manager, path='.', name='.', file_path=None)
2005 importer.wizard = mocked_import_wizard
2006 importer.create_verse = MagicMock()
2007 importer.create_book = MagicMock()
2008@@ -111,7 +112,7 @@
2009 importer.get_language.return_value = 'Russian'
2010
2011 # WHEN: Importing bible file
2012- importer.filename = os.path.join(TEST_PATH, bible_file)
2013+ importer.file_path = Path(TEST_PATH, bible_file)
2014 importer.do_import()
2015
2016 # THEN: The create_verse() method should have been called with each verse in the file.