[Openlp-core] [Merge] lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp
The proposal to merge lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp has been updated. Status: Needs review => Merged For more details, see: https://code.launchpad.net/~phill-ridout/openlp/wow_import_fixes/+merge/369468 -- Your team OpenLP Core is subscribed to branch lp:openlp. ___ Mailing list: https://launchpad.net/~openlp-core Post to : openlp-core@lists.launchpad.net Unsubscribe : https://launchpad.net/~openlp-core More help : https://help.launchpad.net/ListHelp
[Openlp-core] [Merge] lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp
The proposal to merge lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp has been updated. Commit message changed to: Fix up and improve the Words Of Worship importer For more details, see: https://code.launchpad.net/~phill-ridout/openlp/wow_import_fixes/+merge/369468 -- Your team OpenLP Core is subscribed to branch lp:openlp. ___ Mailing list: https://launchpad.net/~openlp-core Post to : openlp-core@lists.launchpad.net Unsubscribe : https://launchpad.net/~openlp-core More help : https://help.launchpad.net/ListHelp
Re: [Openlp-core] [Merge] lp:~john+ubuntu-g/openlp/singingthefaith into lp:openlp
A few in-line comments. Also you don't need to use parenthesis around the expressions in the if statements. Diff comments: > > === added file 'openlp/plugins/songs/lib/importers/singingthefaith.py' > --- openlp/plugins/songs/lib/importers/singingthefaith.py 1970-01-01 > 00:00:00 + > +++ openlp/plugins/songs/lib/importers/singingthefaith.py 2019-06-27 > 12:35:49 + > @@ -0,0 +1,389 @@ > +# -*- coding: utf-8 -*- > +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 > softtabstop=4 > + > +### > +# OpenLP - Open Source Lyrics Projection > # > +# > --- # > +# Copyright (c) 2008-2019 OpenLP Developers > # > +# > --- # > +# This program is free software; you can redistribute it and/or modify it > # > +# under the terms of the GNU General Public License as published by the Free > # > +# Software Foundation; version 2 of the License. > # > +# > # > +# This program is distributed in the hope that it will be useful, but > WITHOUT # > +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or > # > +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for > # > +# more details. > # > +# > # > +# You should have received a copy of the GNU General Public License along > # > +# with this program; if not, write to the Free Software Foundation, Inc., 59 > # > +# Temple Place, Suite 330, Boston, MA 02111-1307 USA > # > +### > +""" > +The :mod:`singingthefaith` module provides the functionality for importing > songs which are > +exported from Singing The Faith - an Authorised songbook for the Methodist > Church of > +Great Britain.""" > + > + > +import logging > +import re > + > +import os > + > +from openlp.core.common.i18n import translate > +from openlp.plugins.songs.lib.importers.songimport import SongImport > + > +log = logging.getLogger(__name__) > + > + > +class SingingTheFaithImport(SongImport): > +""" > +Import songs exported from SingingTheFaith > +""" > + > +hints_available = False > +checks_needed = True > +hintline = {} > +hintfile_version = '0' > +hint_verseOrder = '' > +hint_songtitle = '' > +hint_comments = '' > +hint_ignoreIndent = False > + > +def __init__(self, manager, **kwargs): No need to re implement __init__ here as its not doing anything > +""" > +Initialise the class. > +""" > +super(SingingTheFaithImport, self).__init__(manager, **kwargs) > + > +def do_import(self): > +""" > +Receive a single file or a list of files to import. > +""" > +if not isinstance(self.import_source, list): > +return > +self.import_wizard.progress_bar.setMaximum(len(self.import_source)) > +for filename in self.import_source: file_path would be more descriptive, as it should be a Path object here... > +if self.stop_import_flag: > +return > +song_file = open(filename, 'rt', encoding='cp1251') a context manager here would be better as it would close the file even if an exception were raised. Also the Path object has the open method built (https://docs.python.org/3/library/pathlib.html#pathlib.Path.open) in Ex.: with file_path.open('rt', encoding='cp1251'): > +self.do_import_file(song_file) > +song_file.close() > + > +def do_import_file(self, file): > +""" > +Process the SingingTheFaith file - pass in a file-like object, not a > file path. > +""" > +singingTheFaithVersion = 1 > +self.set_defaults() > +# Setup variables > +line_number = 0 > +old_indent = 0 > +chorus_indent = 5 # It might be 6, but we test for >= > +song_title = 'STF000 -' > +song_number = '0' > +ccli = '0' > +current_verse = '' > +current_verse_type = 'v' > +current_verse_number = 1 > +has_chorus = False > +chorus_written = False > +verses = [] > +author = '' > +copyright = '' > +check_flag = 'z'# Prepended to title, remove if we think > import should be OK > + > + > +self.add_comment("Imported with Singing The Faith Importer v > "+str(singingTheFaithVersion)) > + > +# Get the file_song_number - so we can use it for hints >
Re: [Openlp-core] [Merge] lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp
Review: Approve -- https://code.launchpad.net/~phill-ridout/openlp/wow_import_fixes/+merge/369468 Your team OpenLP Core is subscribed to branch lp:openlp. ___ Mailing list: https://launchpad.net/~openlp-core Post to : openlp-core@lists.launchpad.net Unsubscribe : https://launchpad.net/~openlp-core More help : https://help.launchpad.net/ListHelp
[Openlp-core] macOS Test Results: Passed
macOS tests passed! -- https://code.launchpad.net/~phill-ridout/openlp/wow_import_fixes/+merge/369468 Your team OpenLP Core is subscribed to branch lp:openlp. ___ Mailing list: https://launchpad.net/~openlp-core Post to : openlp-core@lists.launchpad.net Unsubscribe : https://launchpad.net/~openlp-core More help : https://help.launchpad.net/ListHelp
[Openlp-core] Linting: Passed
Linting passed! -- https://code.launchpad.net/~phill-ridout/openlp/wow_import_fixes/+merge/369468 Your team OpenLP Core is subscribed to branch lp:openlp. ___ Mailing list: https://launchpad.net/~openlp-core Post to : openlp-core@lists.launchpad.net Unsubscribe : https://launchpad.net/~openlp-core More help : https://help.launchpad.net/ListHelp
[Openlp-core] Linux Test Results: Passed
Linux tests passed! -- https://code.launchpad.net/~phill-ridout/openlp/wow_import_fixes/+merge/369468 Your team OpenLP Core is subscribed to branch lp:openlp. ___ Mailing list: https://launchpad.net/~openlp-core Post to : openlp-core@lists.launchpad.net Unsubscribe : https://launchpad.net/~openlp-core More help : https://help.launchpad.net/ListHelp
[Openlp-core] [Merge] lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp
Phill has proposed merging lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp. Requested reviews: Tim Bentley (trb143) For more details, see: https://code.launchpad.net/~phill-ridout/openlp/wow_import_fixes/+merge/369468 -- Your team OpenLP Core is subscribed to branch lp:openlp. === modified file 'openlp/core/common/i18n.py' --- openlp/core/common/i18n.py 2019-04-13 13:00:22 + +++ openlp/core/common/i18n.py 2019-06-28 19:29:36 + @@ -385,7 +385,8 @@ self.Error = translate('OpenLP.Ui', 'Error') self.Export = translate('OpenLP.Ui', 'Export') self.File = translate('OpenLP.Ui', 'File') -self.FontSizePtUnit = translate('OpenLP.Ui', 'pt', 'Abbreviated font pointsize unit') +self.FileCorrupt = translate('OpenLP.Ui', 'File appears to be corrupt.') +self.FontSizePtUnit = translate('OpenLP.Ui', 'pt', 'Abbreviated font point size unit') self.Help = translate('OpenLP.Ui', 'Help') self.Hours = translate('OpenLP.Ui', 'h', 'The abbreviated unit for hours') self.IFdSs = translate('OpenLP.Ui', 'Invalid Folder Selected', 'Singular') === modified file 'openlp/core/lib/__init__.py' --- openlp/core/lib/__init__.py 2019-06-11 19:48:34 + +++ openlp/core/lib/__init__.py 2019-06-28 19:29:36 + @@ -24,15 +24,23 @@ OpenLP work. """ import logging +import os +from enum import IntEnum from pathlib import Path from PyQt5 import QtCore, QtGui, QtWidgets -from openlp.core.common.i18n import translate +from openlp.core.common.i18n import UiStrings, translate log = logging.getLogger(__name__ + '.__init__') +class DataType(IntEnum): +U8 = 1 +U16 = 2 +U32 = 4 + + class ServiceItemContext(object): """ The context in which a Service Item is being generated @@ -397,3 +405,48 @@ else: list_to_string = '' return list_to_string + + +def read_or_fail(file_object, length): +""" +Ensure that the data read is as the exact length requested. Otherwise raise an OSError. + +:param io.IOBase file_object: The file-lke object ot read from. +:param int length: The length of the data to read. +:return: The data read. +""" +data = file_object.read(length) +if len(data) != length: +raise OSError(UiStrings().FileCorrupt) +return data + + +def read_int(file_object, data_type, endian='big'): +""" +Read the correct amount of data from a file-like object to decode it to the specified type. + +:param io.IOBase file_object: The file-like object to read from. +:param DataType data_type: A member from the :enum:`DataType` +:param endian: The endianess of the data to be read +:return int: The decoded int +""" +data = read_or_fail(file_object, data_type) +return int.from_bytes(data, endian) + + +def seek_or_fail(file_object, offset, how=os.SEEK_SET): +""" +See to a set position and return an error if the cursor has not moved to that position. + +:param io.IOBase file_object: The file-like object to attempt to seek. +:param int offset: The offset / position to seek by / to. +:param [os.SEEK_CUR | os.SEEK_SET how: Currently only supports os.SEEK_CUR (0) or os.SEEK_SET (1) +:return int: The new position in the file. +""" +if how not in (os.SEEK_CUR, os.SEEK_SET): +raise NotImplementedError +prev_pos = file_object.tell() +new_pos = file_object.seek(offset, how) +if how == os.SEEK_SET and new_pos != offset or how == os.SEEK_CUR and new_pos != prev_pos + offset: +raise OSError(UiStrings().FileCorrupt) +return new_pos === modified file 'openlp/core/ui/formattingtagcontroller.py' --- openlp/core/ui/formattingtagcontroller.py 2019-04-13 13:00:22 + +++ openlp/core/ui/formattingtagcontroller.py 2019-06-28 19:29:36 + @@ -84,7 +84,7 @@ 'desc': desc, 'start tag': '{{{tag}}}'.format(tag=tag), 'start html': start_html, -'end tag': '{{{tag}}}'.format(tag=tag), +'end tag': '{{/{tag}}}'.format(tag=tag), 'end html': end_html, 'protected': False, 'temporary': False === modified file 'openlp/core/widgets/edits.py' --- openlp/core/widgets/edits.py 2019-05-22 20:46:51 + +++ openlp/core/widgets/edits.py 2019-06-28 19:29:36 + @@ -353,7 +353,7 @@ :rtype: None """ if self._path != path: -self._path = path +self.path = path self.pathChanged.emit(path) === modified file 'openlp/plugins/songs/lib/importers/wordsofworship.py' --- openlp/plugins/songs/lib/importers/wordsofworship.py 2019-04-13 13:00:22 + +++ openlp/plugins/songs/lib/importers/wordsofworship.py 2019-06-28 19:29:36 + @@ -26,7 +26,8 @@ import logging import os -from openlp.core.common.i18n import translate +from openlp.core.common.i18n import UiStrings, translate +from openlp.core.lib import DataType, read_int, read_or_fail, seek_or_fail from
[Openlp-core] [Merge] lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp
The proposal to merge lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp has been updated. Status: Needs review => Superseded For more details, see: https://code.launchpad.net/~phill-ridout/openlp/wow_import_fixes/+merge/369467 -- Your team OpenLP Core is subscribed to branch lp:openlp. ___ Mailing list: https://launchpad.net/~openlp-core Post to : openlp-core@lists.launchpad.net Unsubscribe : https://launchpad.net/~openlp-core More help : https://help.launchpad.net/ListHelp
[Openlp-core] [Merge] lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp
Phill has proposed merging lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp. Requested reviews: Tim Bentley (trb143) For more details, see: https://code.launchpad.net/~phill-ridout/openlp/wow_import_fixes/+merge/369467 -- Your team OpenLP Core is subscribed to branch lp:openlp. === modified file 'openlp/core/common/i18n.py' --- openlp/core/common/i18n.py 2019-04-13 13:00:22 + +++ openlp/core/common/i18n.py 2019-06-28 19:28:41 + @@ -385,7 +385,8 @@ self.Error = translate('OpenLP.Ui', 'Error') self.Export = translate('OpenLP.Ui', 'Export') self.File = translate('OpenLP.Ui', 'File') -self.FontSizePtUnit = translate('OpenLP.Ui', 'pt', 'Abbreviated font pointsize unit') +self.FileCorrupt = translate('OpenLP.Ui', 'File appears to be corrupt.') +self.FontSizePtUnit = translate('OpenLP.Ui', 'pt', 'Abbreviated font point size unit') self.Help = translate('OpenLP.Ui', 'Help') self.Hours = translate('OpenLP.Ui', 'h', 'The abbreviated unit for hours') self.IFdSs = translate('OpenLP.Ui', 'Invalid Folder Selected', 'Singular') === modified file 'openlp/core/lib/__init__.py' --- openlp/core/lib/__init__.py 2019-06-11 19:48:34 + +++ openlp/core/lib/__init__.py 2019-06-28 19:28:41 + @@ -24,15 +24,23 @@ OpenLP work. """ import logging +import os +from enum import IntEnum from pathlib import Path from PyQt5 import QtCore, QtGui, QtWidgets -from openlp.core.common.i18n import translate +from openlp.core.common.i18n import UiStrings, translate log = logging.getLogger(__name__ + '.__init__') +class DataType(IntEnum): +U8 = 1 +U16 = 2 +U32 = 4 + + class ServiceItemContext(object): """ The context in which a Service Item is being generated @@ -397,3 +405,48 @@ else: list_to_string = '' return list_to_string + + +def read_or_fail(file_object, length): +""" +Ensure that the data read is as the exact length requested. Otherwise raise an OSError. + +:param io.IOBase file_object: The file-lke object ot read from. +:param int length: The length of the data to read. +:return: The data read. +""" +data = file_object.read(length) +if len(data) != length: +raise OSError(UiStrings().FileCorrupt) +return data + + +def read_int(file_object, data_type, endian='big'): +""" +Read the correct amount of data from a file-like object to decode it to the specified type. + +:param io.IOBase file_object: The file-like object to read from. +:param DataType data_type: A member from the :enum:`DataType` +:param endian: The endianess of the data to be read +:return int: The decoded int +""" +data = read_or_fail(file_object, data_type) +return int.from_bytes(data, endian) + + +def seek_or_fail(file_object, offset, how=os.SEEK_SET): +""" +See to a set position and return an error if the cursor has not moved to that position. + +:param io.IOBase file_object: The file-like object to attempt to seek. +:param int offset: The offset / position to seek by / to. +:param [os.SEEK_CUR | os.SEEK_SET how: Currently only supports os.SEEK_CUR (0) or os.SEEK_SET (1) +:return int: The new position in the file. +""" +if how not in (os.SEEK_CUR, os.SEEK_SET): +raise NotImplementedError +prev_pos = file_object.tell() +new_pos = file_object.seek(offset, how) +if how == os.SEEK_SET and new_pos != offset or how == os.SEEK_CUR and new_pos != prev_pos + offset: +raise OSError(UiStrings().FileCorrupt) +return new_pos === modified file 'openlp/core/ui/formattingtagcontroller.py' --- openlp/core/ui/formattingtagcontroller.py 2019-04-13 13:00:22 + +++ openlp/core/ui/formattingtagcontroller.py 2019-06-28 19:28:41 + @@ -84,7 +84,7 @@ 'desc': desc, 'start tag': '{{{tag}}}'.format(tag=tag), 'start html': start_html, -'end tag': '{{{tag}}}'.format(tag=tag), +'end tag': '{{/{tag}}}'.format(tag=tag), 'end html': end_html, 'protected': False, 'temporary': False === modified file 'openlp/core/widgets/edits.py' --- openlp/core/widgets/edits.py 2019-05-22 20:46:51 + +++ openlp/core/widgets/edits.py 2019-06-28 19:28:41 + @@ -353,7 +353,7 @@ :rtype: None """ if self._path != path: -self._path = path +self.path = path self.pathChanged.emit(path) === modified file 'openlp/plugins/songs/lib/importers/wordsofworship.py' --- openlp/plugins/songs/lib/importers/wordsofworship.py 2019-04-13 13:00:22 + +++ openlp/plugins/songs/lib/importers/wordsofworship.py 2019-06-28 19:28:41 + @@ -26,7 +26,8 @@ import logging import os -from openlp.core.common.i18n import translate +from openlp.core.common.i18n import UiStrings, translate +from openlp.core.lib import DataType, read_int, read_or_fail, seek_or_fail from
[Openlp-core] [Merge] lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp
The proposal to merge lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp has been updated. Status: Needs review => Superseded For more details, see: https://code.launchpad.net/~phill-ridout/openlp/wow_import_fixes/+merge/369466 -- Your team OpenLP Core is subscribed to branch lp:openlp. ___ Mailing list: https://launchpad.net/~openlp-core Post to : openlp-core@lists.launchpad.net Unsubscribe : https://launchpad.net/~openlp-core More help : https://help.launchpad.net/ListHelp
[Openlp-core] [Merge] lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp
Phill has proposed merging lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp. Requested reviews: Tim Bentley (trb143) For more details, see: https://code.launchpad.net/~phill-ridout/openlp/wow_import_fixes/+merge/369466 -- Your team OpenLP Core is subscribed to branch lp:openlp. === modified file 'openlp/core/common/i18n.py' --- openlp/core/common/i18n.py 2019-04-13 13:00:22 + +++ openlp/core/common/i18n.py 2019-06-28 19:27:37 + @@ -385,7 +385,8 @@ self.Error = translate('OpenLP.Ui', 'Error') self.Export = translate('OpenLP.Ui', 'Export') self.File = translate('OpenLP.Ui', 'File') -self.FontSizePtUnit = translate('OpenLP.Ui', 'pt', 'Abbreviated font pointsize unit') +self.FileCorrupt = translate('OpenLP.Ui', 'File appears to be corrupt.') +self.FontSizePtUnit = translate('OpenLP.Ui', 'pt', 'Abbreviated font point size unit') self.Help = translate('OpenLP.Ui', 'Help') self.Hours = translate('OpenLP.Ui', 'h', 'The abbreviated unit for hours') self.IFdSs = translate('OpenLP.Ui', 'Invalid Folder Selected', 'Singular') === modified file 'openlp/core/lib/__init__.py' --- openlp/core/lib/__init__.py 2019-06-11 19:48:34 + +++ openlp/core/lib/__init__.py 2019-06-28 19:27:37 + @@ -24,15 +24,23 @@ OpenLP work. """ import logging +import os +from enum import IntEnum from pathlib import Path from PyQt5 import QtCore, QtGui, QtWidgets -from openlp.core.common.i18n import translate +from openlp.core.common.i18n import UiStrings, translate log = logging.getLogger(__name__ + '.__init__') +class DataType(IntEnum): +U8 = 1 +U16 = 2 +U32 = 4 + + class ServiceItemContext(object): """ The context in which a Service Item is being generated @@ -397,3 +405,48 @@ else: list_to_string = '' return list_to_string + + +def read_or_fail(file_object, length): +""" +Ensure that the data read is as the exact length requested. Otherwise raise an OSError. + +:param io.IOBase file_object: The file-lke object ot read from. +:param int length: The length of the data to read. +:return: The data read. +""" +data = file_object.read(length) +if len(data) != length: +raise OSError(UiStrings().FileCorrupt) +return data + + +def read_int(file_object, data_type, endian='big'): +""" +Read the correct amount of data from a file-like object to decode it to the specified type. + +:param io.IOBase file_object: The file-like object to read from. +:param DataType data_type: A member from the :enum:`DataType` +:param endian: The endianess of the data to be read +:return int: The decoded int +""" +data = read_or_fail(file_object, data_type) +return int.from_bytes(data, endian) + + +def seek_or_fail(file_object, offset, how=os.SEEK_SET): +""" +See to a set position and return an error if the cursor has not moved to that position. + +:param io.IOBase file_object: The file-like object to attempt to seek. +:param int offset: The offset / position to seek by / to. +:param [os.SEEK_CUR | os.SEEK_SET how: Currently only supports os.SEEK_CUR (0) or os.SEEK_SET (1) +:return int: The new position in the file. +""" +if how not in (os.SEEK_CUR, os.SEEK_SET): +raise NotImplementedError +prev_pos = file_object.tell() +new_pos = file_object.seek(offset, how) +if how == os.SEEK_SET and new_pos != offset or how == os.SEEK_CUR and new_pos != prev_pos + offset: +raise OSError(UiStrings().FileCorrupt) +return new_pos === modified file 'openlp/core/ui/formattingtagcontroller.py' --- openlp/core/ui/formattingtagcontroller.py 2019-04-13 13:00:22 + +++ openlp/core/ui/formattingtagcontroller.py 2019-06-28 19:27:37 + @@ -84,7 +84,7 @@ 'desc': desc, 'start tag': '{{{tag}}}'.format(tag=tag), 'start html': start_html, -'end tag': '{{{tag}}}'.format(tag=tag), +'end tag': '{{/{tag}}}'.format(tag=tag), 'end html': end_html, 'protected': False, 'temporary': False === modified file 'openlp/core/widgets/edits.py' --- openlp/core/widgets/edits.py 2019-05-22 20:46:51 + +++ openlp/core/widgets/edits.py 2019-06-28 19:27:37 + @@ -353,7 +353,7 @@ :rtype: None """ if self._path != path: -self._path = path +self.path = path self.pathChanged.emit(path) === modified file 'openlp/plugins/songs/lib/importers/wordsofworship.py' --- openlp/plugins/songs/lib/importers/wordsofworship.py 2019-04-13 13:00:22 + +++ openlp/plugins/songs/lib/importers/wordsofworship.py 2019-06-28 19:27:37 + @@ -26,7 +26,8 @@ import logging import os -from openlp.core.common.i18n import translate +from openlp.core.common.i18n import UiStrings, translate +from openlp.core.lib import DataType, read_int, read_or_fail, seek_or_fail from
[Openlp-core] [Merge] lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp
The proposal to merge lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp has been updated. Status: Needs review => Superseded For more details, see: https://code.launchpad.net/~phill-ridout/openlp/wow_import_fixes/+merge/369463 -- Your team OpenLP Core is subscribed to branch lp:openlp. ___ Mailing list: https://launchpad.net/~openlp-core Post to : openlp-core@lists.launchpad.net Unsubscribe : https://launchpad.net/~openlp-core More help : https://help.launchpad.net/ListHelp
Re: [Openlp-core] [Merge] lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp
Review: Approve -- https://code.launchpad.net/~phill-ridout/openlp/wow_import_fixes/+merge/369463 Your team OpenLP Core is subscribed to branch lp:openlp. ___ Mailing list: https://launchpad.net/~openlp-core Post to : openlp-core@lists.launchpad.net Unsubscribe : https://launchpad.net/~openlp-core More help : https://help.launchpad.net/ListHelp
[Openlp-core] [Merge] lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp
Phill has proposed merging lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp. Requested reviews: OpenLP Core (openlp-core) For more details, see: https://code.launchpad.net/~phill-ridout/openlp/wow_import_fixes/+merge/369463 -- Your team OpenLP Core is requested to review the proposed merge of lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp. === modified file 'openlp/core/common/i18n.py' --- openlp/core/common/i18n.py 2019-04-13 13:00:22 + +++ openlp/core/common/i18n.py 2019-06-28 18:40:35 + @@ -385,7 +385,8 @@ self.Error = translate('OpenLP.Ui', 'Error') self.Export = translate('OpenLP.Ui', 'Export') self.File = translate('OpenLP.Ui', 'File') -self.FontSizePtUnit = translate('OpenLP.Ui', 'pt', 'Abbreviated font pointsize unit') +self.FileCorrupt = translate('OpenLP.Ui', 'File appears to be corrupt.') +self.FontSizePtUnit = translate('OpenLP.Ui', 'pt', 'Abbreviated font point size unit') self.Help = translate('OpenLP.Ui', 'Help') self.Hours = translate('OpenLP.Ui', 'h', 'The abbreviated unit for hours') self.IFdSs = translate('OpenLP.Ui', 'Invalid Folder Selected', 'Singular') === modified file 'openlp/core/lib/__init__.py' --- openlp/core/lib/__init__.py 2019-06-11 19:48:34 + +++ openlp/core/lib/__init__.py 2019-06-28 18:40:35 + @@ -24,15 +24,23 @@ OpenLP work. """ import logging +import os +from enum import IntEnum from pathlib import Path from PyQt5 import QtCore, QtGui, QtWidgets -from openlp.core.common.i18n import translate +from openlp.core.common.i18n import UiStrings, translate log = logging.getLogger(__name__ + '.__init__') +class DataType(IntEnum): +U8 = 1 +U16 = 2 +U32 = 4 + + class ServiceItemContext(object): """ The context in which a Service Item is being generated @@ -397,3 +405,48 @@ else: list_to_string = '' return list_to_string + + +def read_or_fail(file_object, length): +""" +Ensure that the data read is as the exact length requested. Otherwise raise an OSError. + +:param io.IOBase file_object: The file-lke object ot read from. +:param int length: The length of the data to read. +:return: The data read. +""" +data = file_object.read(length) +if len(data) != length: +raise OSError(UiStrings().FileCorrupt) +return data + + +def read_int(file_object, data_type, endian='big'): +""" +Read the correct amount of data from a file-like object to decode it to the specified type. + +:param io.IOBase file_object: The file-like object to read from. +:param DataType data_type: A member from the :enum:`DataType` +:param endian: The endianess of the data to be read +:return int: The decoded int +""" +data = read_or_fail(file_object, data_type) +return int.from_bytes(data, endian) + + +def seek_or_fail(file_object, offset, how=os.SEEK_SET): +""" +See to a set position and return an error if the cursor has not moved to that position. + +:param io.IOBase file_object: The file-like object to attempt to seek. +:param int offset: The offset / position to seek by / to. +:param [os.SEEK_CUR | os.SEEK_SET how: Currently only supports os.SEEK_CUR (0) or os.SEEK_SET (1) +:return int: The new position in the file. +""" +if how not in (os.SEEK_CUR, os.SEEK_SET): +raise NotImplementedError +prev_pos = file_object.tell() +new_pos = file_object.seek(offset, how) +if how == os.SEEK_SET and new_pos != offset or how == os.SEEK_CUR and new_pos != prev_pos + offset: +raise OSError(UiStrings().FileCorrupt) +return new_pos === modified file 'openlp/core/ui/formattingtagcontroller.py' --- openlp/core/ui/formattingtagcontroller.py 2019-04-13 13:00:22 + +++ openlp/core/ui/formattingtagcontroller.py 2019-06-28 18:40:35 + @@ -84,7 +84,7 @@ 'desc': desc, 'start tag': '{{{tag}}}'.format(tag=tag), 'start html': start_html, -'end tag': '{{{tag}}}'.format(tag=tag), +'end tag': '{{/{tag}}}'.format(tag=tag), 'end html': end_html, 'protected': False, 'temporary': False === modified file 'openlp/core/widgets/edits.py' --- openlp/core/widgets/edits.py 2019-05-22 20:46:51 + +++ openlp/core/widgets/edits.py 2019-06-28 18:40:35 + @@ -353,7 +353,7 @@ :rtype: None """ if self._path != path: -self._path = path +self.path = path self.pathChanged.emit(path) === modified file 'openlp/plugins/songs/lib/importers/wordsofworship.py' --- openlp/plugins/songs/lib/importers/wordsofworship.py 2019-04-13 13:00:22 + +++ openlp/plugins/songs/lib/importers/wordsofworship.py 2019-06-28 18:40:35 + @@ -26,7 +26,8 @@ import logging import os -from openlp.core.common.i18n import translate +from openlp.core.common.i18n import UiStrings, translate +from op
[Openlp-core] macOS Test Results: Passed
macOS tests passed! -- https://code.launchpad.net/~phill-ridout/openlp/wow_import_fixes/+merge/369463 Your team OpenLP Core is requested to review the proposed merge of lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp. ___ Mailing list: https://launchpad.net/~openlp-core Post to : openlp-core@lists.launchpad.net Unsubscribe : https://launchpad.net/~openlp-core More help : https://help.launchpad.net/ListHelp
[Openlp-core] Linting: Passed
Linting passed! -- https://code.launchpad.net/~phill-ridout/openlp/wow_import_fixes/+merge/369463 Your team OpenLP Core is requested to review the proposed merge of lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp. ___ Mailing list: https://launchpad.net/~openlp-core Post to : openlp-core@lists.launchpad.net Unsubscribe : https://launchpad.net/~openlp-core More help : https://help.launchpad.net/ListHelp
[Openlp-core] [Merge] lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp
Phill has proposed merging lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp. Requested reviews: OpenLP Core (openlp-core) For more details, see: https://code.launchpad.net/~phill-ridout/openlp/wow_import_fixes/+merge/369462 -- Your team OpenLP Core is requested to review the proposed merge of lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp. === modified file 'openlp/core/common/i18n.py' --- openlp/core/common/i18n.py 2019-04-13 13:00:22 + +++ openlp/core/common/i18n.py 2019-06-28 18:31:26 + @@ -385,7 +385,8 @@ self.Error = translate('OpenLP.Ui', 'Error') self.Export = translate('OpenLP.Ui', 'Export') self.File = translate('OpenLP.Ui', 'File') -self.FontSizePtUnit = translate('OpenLP.Ui', 'pt', 'Abbreviated font pointsize unit') +self.FileCorrupt = translate('OpenLP.Ui', 'File appears to be corrupt.') +self.FontSizePtUnit = translate('OpenLP.Ui', 'pt', 'Abbreviated font point size unit') self.Help = translate('OpenLP.Ui', 'Help') self.Hours = translate('OpenLP.Ui', 'h', 'The abbreviated unit for hours') self.IFdSs = translate('OpenLP.Ui', 'Invalid Folder Selected', 'Singular') === modified file 'openlp/core/lib/__init__.py' --- openlp/core/lib/__init__.py 2019-06-11 19:48:34 + +++ openlp/core/lib/__init__.py 2019-06-28 18:31:26 + @@ -24,15 +24,23 @@ OpenLP work. """ import logging +import os +from enum import IntEnum from pathlib import Path from PyQt5 import QtCore, QtGui, QtWidgets -from openlp.core.common.i18n import translate +from openlp.core.common.i18n import UiStrings, translate log = logging.getLogger(__name__ + '.__init__') +class DataType(IntEnum): +U8 = 1 +U16 = 2 +U32 = 4 + + class ServiceItemContext(object): """ The context in which a Service Item is being generated @@ -397,3 +405,48 @@ else: list_to_string = '' return list_to_string + + +def read_or_fail(file_object, length): +""" +Ensure that the data read is as the exact length requested. Otherwise raise an OSError. + +:param io.IOBase file_object: The file-lke object ot read from. +:param int length: The length of the data to read. +:return: The data read. +""" +data = file_object.read(length) +if len(data) != length: +raise OSError(UiStrings().FileCorrupt) +return data + + +def read_int(file_object, data_type, endian='big'): +""" +Read the correct amount of data from a file-like object to decode it to the specified type. + +:param io.IOBase file_object: The file-like object to read from. +:param DataType data_type: A member from the :enum:`DataType` +:param endian: The endianess of the data to be read +:return int: The decoded int +""" +data = read_or_fail(file_object, data_type) +return int.from_bytes(data, endian) + + +def seek_or_fail(file_object, offset, how=os.SEEK_SET): +""" +See to a set position and return an error if the cursor has not moved to that position. + +:param io.IOBase file_object: The file-like object to attempt to seek. +:param int offset: The offset / position to seek by / to. +:param [os.SEEK_CUR | os.SEEK_SET how: Currently only supports os.SEEK_CUR (0) or os.SEEK_SET (1) +:return int: The new position in the file. +""" +if how not in (os.SEEK_CUR, os.SEEK_SET): +raise NotImplementedError +prev_pos = file_object.tell() +new_pos = file_object.seek(offset, how) +if how == os.SEEK_SET and new_pos != offset or how == os.SEEK_CUR and new_pos != prev_pos + offset: +raise OSError(UiStrings().FileCorrupt) +return new_pos === modified file 'openlp/core/ui/formattingtagcontroller.py' --- openlp/core/ui/formattingtagcontroller.py 2019-04-13 13:00:22 + +++ openlp/core/ui/formattingtagcontroller.py 2019-06-28 18:31:26 + @@ -84,7 +84,7 @@ 'desc': desc, 'start tag': '{{{tag}}}'.format(tag=tag), 'start html': start_html, -'end tag': '{{{tag}}}'.format(tag=tag), +'end tag': '{{/{tag}}}'.format(tag=tag), 'end html': end_html, 'protected': False, 'temporary': False === modified file 'openlp/core/widgets/edits.py' --- openlp/core/widgets/edits.py 2019-05-22 20:46:51 + +++ openlp/core/widgets/edits.py 2019-06-28 18:31:26 + @@ -353,7 +353,7 @@ :rtype: None """ if self._path != path: -self._path = path +self.path = path self.pathChanged.emit(path) === modified file 'openlp/plugins/songs/lib/importers/wordsofworship.py' --- openlp/plugins/songs/lib/importers/wordsofworship.py 2019-04-13 13:00:22 + +++ openlp/plugins/songs/lib/importers/wordsofworship.py 2019-06-28 18:31:26 + @@ -26,7 +26,8 @@ import logging import os -from openlp.core.common.i18n import translate +from openlp.core.common.i18n import UiStrings, translate +from op
[Openlp-core] Linux Test Results: Passed
Linux tests passed! -- https://code.launchpad.net/~phill-ridout/openlp/wow_import_fixes/+merge/369463 Your team OpenLP Core is requested to review the proposed merge of lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp. ___ Mailing list: https://launchpad.net/~openlp-core Post to : openlp-core@lists.launchpad.net Unsubscribe : https://launchpad.net/~openlp-core More help : https://help.launchpad.net/ListHelp
[Openlp-core] [Merge] lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp
The proposal to merge lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp has been updated. Status: Needs review => Superseded For more details, see: https://code.launchpad.net/~phill-ridout/openlp/wow_import_fixes/+merge/369462 -- Your team OpenLP Core is requested to review the proposed merge of lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp. ___ Mailing list: https://launchpad.net/~openlp-core Post to : openlp-core@lists.launchpad.net Unsubscribe : https://launchpad.net/~openlp-core More help : https://help.launchpad.net/ListHelp
[Openlp-core] Linting: Failed
Linting failed, please see https://ci.openlp.io/job/MP-03-Linting/127/ for more details -- https://code.launchpad.net/~phill-ridout/openlp/wow_import_fixes/+merge/369462 Your team OpenLP Core is requested to review the proposed merge of lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp. ___ Mailing list: https://launchpad.net/~openlp-core Post to : openlp-core@lists.launchpad.net Unsubscribe : https://launchpad.net/~openlp-core More help : https://help.launchpad.net/ListHelp
[Openlp-core] Linux Test Results: Passed
Linux tests passed! -- https://code.launchpad.net/~phill-ridout/openlp/wow_import_fixes/+merge/369462 Your team OpenLP Core is requested to review the proposed merge of lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp. ___ Mailing list: https://launchpad.net/~openlp-core Post to : openlp-core@lists.launchpad.net Unsubscribe : https://launchpad.net/~openlp-core More help : https://help.launchpad.net/ListHelp
[Openlp-core] [Merge] lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp
The proposal to merge lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp has been updated. Status: Work in progress => Superseded For more details, see: https://code.launchpad.net/~phill-ridout/openlp/wow_import_fixes/+merge/369460 -- Your team OpenLP Core is requested to review the proposed merge of lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp. ___ Mailing list: https://launchpad.net/~openlp-core Post to : openlp-core@lists.launchpad.net Unsubscribe : https://launchpad.net/~openlp-core More help : https://help.launchpad.net/ListHelp
[Openlp-core] Linux Test Results: Failed
Linux tests failed, please see https://ci.openlp.io/job/MP-02-Linux_Tests/192/ for more details -- https://code.launchpad.net/~phill-ridout/openlp/wow_import_fixes/+merge/369460 Your team OpenLP Core is requested to review the proposed merge of lp:~phill-ridout/openlp/wow_import_fixes into lp:openlp. ___ Mailing list: https://launchpad.net/~openlp-core Post to : openlp-core@lists.launchpad.net Unsubscribe : https://launchpad.net/~openlp-core More help : https://help.launchpad.net/ListHelp