diff --git a/openlp/plugins/songs/lib/cclifileimport.py b/openlp/plugins/songs/lib/cclifileimport.py index cb543ff25..e15f898ab 100644 --- a/openlp/plugins/songs/lib/cclifileimport.py +++ b/openlp/plugins/songs/lib/cclifileimport.py @@ -165,7 +165,7 @@ class CCLIFileImport(SongImport): elif line.startswith(u'Themes='): song_topics = line[7:].strip() elif line.startswith(u'[S A'): - self.ccli_number = line[4:-3].strip() + self.ccliNumber = line[4:-3].strip() elif line.startswith(u'Fields='): # Fields contain single line indicating verse, chorus, etc, # /t delimited, same as with words field. store seperately @@ -204,7 +204,7 @@ class CCLIFileImport(SongImport): verse_type = VerseType.Tags[VerseType.Other] verse_text = verse_lines[1] if len(verse_text) > 0: - self.add_verse(verse_text, verse_type) + self.addVerse(verse_text, verse_type) check_first_verse_line = False # Handle multiple authors author_list = song_author.split(u'/') @@ -213,9 +213,9 @@ class CCLIFileImport(SongImport): for author in author_list: separated = author.split(u',') if len(separated) > 1: - self.add_author(u' '.join(reversed(separated))) + self.addAuthor(u' '.join(reversed(separated))) else: - self.add_author(author) + self.addAuthor(author) self.topics = [topic.strip() for topic in song_topics.split(u'/t')] return self.finish() @@ -264,7 +264,7 @@ class CCLIFileImport(SongImport): continue elif verse_start: if verse_text: - self.add_verse(verse_text, verse_type) + self.addVerse(verse_text, verse_type) verse_text = u'' verse_start = False else: @@ -278,7 +278,7 @@ class CCLIFileImport(SongImport): if clean_line.startswith(u'CCLI'): line_number += 1 ccli_parts = clean_line.split(' ') - self.ccli_number = ccli_parts[len(ccli_parts) - 1] + self.ccliNumber = ccli_parts[len(ccli_parts) - 1] elif not verse_start: # We have the verse descriptor verse_desc_parts = clean_line.split(u' ') @@ -333,5 +333,5 @@ class CCLIFileImport(SongImport): if len(author_list) < 2: author_list = song_author.split(u'|') # Clean spaces before and after author names. - [self.add_author(author_name.strip()) for author_name in author_list] + [self.addAuthor(author_name.strip()) for author_name in author_list] return self.finish() diff --git a/openlp/plugins/songs/lib/easislidesimport.py b/openlp/plugins/songs/lib/easislidesimport.py index 1825565c1..6d3bde025 100644 --- a/openlp/plugins/songs/lib/easislidesimport.py +++ b/openlp/plugins/songs/lib/easislidesimport.py @@ -65,34 +65,34 @@ class EasiSlidesImport(SongImport): for song in song_xml.Item: if self.stopImportFlag: return - self._parse_song(song) + self._parseSong(song) - def _parse_song(self, song): + def _parseSong(self, song): self._success = True - self._add_unicode_attribute(u'title', song.Title1, True) + self._addUnicodeAttribute(u'title', song.Title1, True) if hasattr(song, u'Title2'): - self._add_unicode_attribute(u'alternate_title', song.Title2) + self._addUnicodeAttribute(u'alternateTitle', song.Title2) if hasattr(song, u'SongNumber'): - self._add_unicode_attribute(u'song_number', song.SongNumber) - if self.song_number == u'0': - self.song_number = u'' - self._add_authors(song) + self._addUnicodeAttribute(u'songNumber', song.SongNumber) + if self.songNumber == u'0': + self.songNumber = u'' + self._addAuthors(song) if hasattr(song, u'Copyright'): - self._add_copyright(song.Copyright) + self._addCopyright(song.Copyright) if hasattr(song, u'LicenceAdmin1'): - self._add_copyright(song.LicenceAdmin1) + self._addCopyright(song.LicenceAdmin1) if hasattr(song, u'LicenceAdmin2'): - self._add_copyright(song.LicenceAdmin2) + self._addCopyright(song.LicenceAdmin2) if hasattr(song, u'BookReference'): - self._add_unicode_attribute(u'song_book_name', song.BookReference) - self._parse_and_add_lyrics(song) + self._addUnicodeAttribute(u'songBookName', song.BookReference) + self._parseAndAddLyrics(song) if self._success: if not self.finish(): self.logError(song.Title1 if song.Title1 else u'') else: self.setDefaults() - def _add_unicode_attribute(self, self_attribute, import_attribute, + def _addUnicodeAttribute(self, self_attribute, import_attribute, mandatory=False): """ Add imported values to the song model converting them to unicode at the @@ -119,7 +119,7 @@ class EasiSlidesImport(SongImport): if mandatory: self._success = False - def _add_authors(self, song): + def _addAuthors(self, song): try: authors = unicode(song.Writer).split(u',') self.authors = \ @@ -130,7 +130,7 @@ class EasiSlidesImport(SongImport): except AttributeError: pass - def _add_copyright(self, element): + def _addCopyright(self, element): """ Add a piece of copyright to the total copyright information for the song. @@ -139,14 +139,14 @@ class EasiSlidesImport(SongImport): The imported variable to get the data from. """ try: - self.add_copyright(unicode(element).strip()) + self.addCopyright(unicode(element).strip()) except UnicodeDecodeError: log.exception(u'Unicode error on decoding copyright: %s' % element) self._success = False except AttributeError: pass - def _parse_and_add_lyrics(self, song): + def _parseAndAddLyrics(self, song): try: lyrics = unicode(song.Contents).strip() except UnicodeDecodeError: @@ -295,7 +295,7 @@ class EasiSlidesImport(SongImport): else: continue if tag in versetags: - self.verse_order_list.append(tag) + self.verseOrderList.append(tag) else: log.info(u'Got order item %s, which is not in versetags,' u'dropping item from presentation order', tag) diff --git a/openlp/plugins/songs/lib/ewimport.py b/openlp/plugins/songs/lib/ewimport.py index 2dff9dddb..e89fbc4a0 100644 --- a/openlp/plugins/songs/lib/ewimport.py +++ b/openlp/plugins/songs/lib/ewimport.py @@ -49,15 +49,15 @@ def strip_rtf(blob, encoding): control = False clear_text = [] control_word = [] - - # workaround for \tx bug: remove one pair of curly braces + + # workaround for \tx bug: remove one pair of curly braces # if \tx is encountered match = RTF_STRIPPING_REGEX.search(blob) if match: # start and end indices of match are curly braces - filter them out - blob = ''.join([blob[i] for i in xrange(len(blob)) + blob = ''.join([blob[i] for i in xrange(len(blob)) if i != match.start() and i !=match.end()]) - + for c in blob: if control: # for delimiters, set control to False @@ -166,13 +166,13 @@ class EasyWorshipSongImport(SongImport): if db_size < 0x800: return db_file = open(self.importSource, 'rb') - self.memo_file = open(import_source_mb, 'rb') + self.memoFile = open(import_source_mb, 'rb') # Don't accept files that are clearly not paradox files record_size, header_size, block_size, first_block, num_fields \ = struct.unpack(' 4: db_file.close() - self.memo_file.close() + self.memoFile.close() return # Take a stab at how text is encoded self.encoding = u'cp1252' @@ -218,16 +218,16 @@ class EasyWorshipSongImport(SongImport): field_info, i * 2) field_descs.append(FieldDescEntry(field_name, field_type, field_size)) - self.set_record_struct(field_descs) + self.setRecordStruct(field_descs) # Pick out the field description indexes we will need try: success = True - fi_title = self.find_field(u'Title') - fi_author = self.find_field(u'Author') - fi_copy = self.find_field(u'Copyright') - fi_admin = self.find_field(u'Administrator') - fi_words = self.find_field(u'Words') - fi_ccli = self.find_field(u'Song Number') + fi_title = self.findField(u'Title') + fi_author = self.findField(u'Author') + fi_copy = self.findField(u'Copyright') + fi_admin = self.findField(u'Administrator') + fi_words = self.findField(u'Words') + fi_ccli = self.findField(u'Song Number') except IndexError: # This is the wrong table success = False @@ -244,13 +244,13 @@ class EasyWorshipSongImport(SongImport): raw_record = db_file.read(record_size) self.fields = self.record_struct.unpack(raw_record) self.setDefaults() - self.title = self.get_field(fi_title) + self.title = self.getField(fi_title) # Get remaining fields. - copy = self.get_field(fi_copy) - admin = self.get_field(fi_admin) - ccli = self.get_field(fi_ccli) - authors = self.get_field(fi_author) - words = self.get_field(fi_words) + copy = self.getField(fi_copy) + admin = self.getField(fi_admin) + ccli = self.getField(fi_ccli) + authors = self.getField(fi_author) + words = self.getField(fi_words) # Set the SongImport object members. if copy: self.copyright = copy @@ -261,7 +261,7 @@ class EasyWorshipSongImport(SongImport): unicode(translate('SongsPlugin.EasyWorshipSongImport', 'Administered by %s')) % admin if ccli: - self.ccli_number = ccli + self.ccliNumber = ccli if authors: # Split up the authors author_list = authors.split(u'/') @@ -270,7 +270,7 @@ class EasyWorshipSongImport(SongImport): if len(author_list) < 2: author_list = authors.split(u',') for author_name in author_list: - self.add_author(author_name.strip()) + self.addAuthor(author_name.strip()) if words: # Format the lyrics words = strip_rtf(words, self.encoding) @@ -281,9 +281,9 @@ class EasyWorshipSongImport(SongImport): continue verse_split = verse.split(u'\n', 1) first_line_is_tag = False - # EW tags: verse, chorus, pre-chorus, bridge, tag, + # EW tags: verse, chorus, pre-chorus, bridge, tag, # intro, ending, slide - for type in VerseType.Names+[u'tag', u'slide']: + for type in VerseType.Names+[u'tag', u'slide']: type = type.lower() ew_tag = verse_split[0].strip().lower() if ew_tag.startswith(type): @@ -293,7 +293,7 @@ class EasyWorshipSongImport(SongImport): first_line_is_tag = True number_found = False # check if tag is followed by number and/or note - if len(ew_tag) > len(type): + if len(ew_tag) > len(type): match = NUMBER_REGEX.search(ew_tag) if match: number = match.group() @@ -305,8 +305,9 @@ class EasyWorshipSongImport(SongImport): if not number_found: verse_type += u'1' break - self.add_verse( - verse_split[-1].strip() if first_line_is_tag else verse, + self.addVerse( + verse_split[-1].strip() \ + if first_line_is_tag else verse, verse_type) if len(self.comments) > 5: self.comments += unicode( @@ -318,10 +319,10 @@ class EasyWorshipSongImport(SongImport): if not self.finish(): self.logError(self.importSource) db_file.close() - self.memo_file.close() + self.memoFile.close() def find_field(self, field_name): - return [i for i, x in enumerate(self.field_descs) + return [i for i, x in enumerate(self.fieldDescs) if x.name == field_name][0] def set_record_struct(self, field_descs): @@ -351,12 +352,12 @@ class EasyWorshipSongImport(SongImport): fsl.append('Q') else: fsl.append('%ds' % field_desc.size) - self.record_struct = struct.Struct(''.join(fsl)) - self.field_descs = field_descs + self.recordStruct = struct.Struct(''.join(fsl)) + self.fieldDescs = field_descs def get_field(self, field_desc_index): field = self.fields[field_desc_index] - field_desc = self.field_descs[field_desc_index] + field_desc = self.fieldDescs[field_desc_index] # Return None in case of 'blank' entries if isinstance(field, str): if len(field.rstrip('\0')) == 0: @@ -382,18 +383,18 @@ class EasyWorshipSongImport(SongImport): struct.unpack_from(' 63: return u'' - self.memo_file.seek(11 + (5 * sub_block), os.SEEK_CUR) - sub_block_start, = struct.unpack('B', self.memo_file.read(1)) - self.memo_file.seek(block_start + (sub_block_start * 16)) + self.memoFile.seek(11 + (5 * sub_block), os.SEEK_CUR) + sub_block_start, = struct.unpack('B', self.memoFile.read(1)) + self.memoFile.seek(block_start + (sub_block_start * 16)) else: return u'' - return self.memo_file.read(blob_size) + return self.memoFile.read(blob_size) else: return 0 diff --git a/openlp/plugins/songs/lib/oooimport.py b/openlp/plugins/songs/lib/oooimport.py index 02ba23a0a..4a97e43b0 100644 --- a/openlp/plugins/songs/lib/oooimport.py +++ b/openlp/plugins/songs/lib/oooimport.py @@ -59,7 +59,7 @@ class OooImport(SongImport): """ SongImport.__init__(self, manager, **kwargs) self.document = None - self.process_started = False + self.processStarted = False def doImport(self): if not isinstance(self.importSource, list): @@ -79,10 +79,10 @@ class OooImport(SongImport): break filename = unicode(filename) if os.path.isfile(filename): - self.open_ooo_file(filename) + self.openOooFile(filename) if self.document: - self.process_ooo_document() - self.close_ooo_file() + self.processOooDocument() + self.closeOooFile() else: self.logError(self.filepath, translate('SongsPlugin.SongImport', @@ -90,27 +90,27 @@ class OooImport(SongImport): else: self.logError(self.filepath, translate('SongsPlugin.SongImport', 'File not found')) - self.close_ooo() + self.closeOoo() - def process_ooo_document(self): + def processOooDocument(self): """ Handle the import process for OpenOffice files. This method facilitates allowing subclasses to handle specific types of OpenOffice files. """ if self.document.supportsService( "com.sun.star.presentation.PresentationDocument"): - self.process_pres() + self.processPres() if self.document.supportsService("com.sun.star.text.TextDocument"): - self.process_doc() + self.processDoc() - def start_ooo(self): + def startOoo(self): """ Start OpenOffice.org process TODO: The presentation/Impress plugin may already have it running """ if os.name == u'nt': - self.start_ooo_process() - self.desktop = self.ooo_manager.createInstance( + self.startOooProcess() + self.desktop = self.oooManager.createInstance( u'com.sun.star.frame.Desktop') else: context = uno.getComponentContext() @@ -123,7 +123,7 @@ class OooImport(SongImport): uno_instance = get_uno_instance(resolver) except NoConnectException: log.exception("Failed to resolve uno connection") - self.start_ooo_process() + self.startOooProcess() loop += 1 else: manager = uno_instance.ServiceManager @@ -132,22 +132,22 @@ class OooImport(SongImport): return raise - def start_ooo_process(self): + def startOooProcess(self): try: if os.name == u'nt': - self.ooo_manager = Dispatch(u'com.sun.star.ServiceManager') - self.ooo_manager._FlagAsMethod(u'Bridge_GetStruct') - self.ooo_manager._FlagAsMethod(u'Bridge_GetValueObject') + self.oooManager = Dispatch(u'com.sun.star.ServiceManager') + self.oooManager._FlagAsMethod(u'Bridge_GetStruct') + self.oooManager._FlagAsMethod(u'Bridge_GetValueObject') else: cmd = get_uno_command() process = QtCore.QProcess() process.startDetached(cmd) process.waitForStarted() - self.process_started = True + self.processStarted = True except: log.exception("start_ooo_process failed") - def open_ooo_file(self, filepath): + def openOooFile(self, filepath): """ Open the passed file in OpenOffice.org Impress """ @@ -166,7 +166,7 @@ class OooImport(SongImport): if not self.document.supportsService( "com.sun.star.presentation.PresentationDocument") and not \ self.document.supportsService("com.sun.star.text.TextDocument"): - self.close_ooo_file() + self.closeOooFile() else: self.importWizard.incrementProgressBar( u'Processing file ' + filepath, 0) @@ -174,21 +174,21 @@ class OooImport(SongImport): log.exception("open_ooo_file failed: %s", url) return - def close_ooo_file(self): + def closeOooFile(self): """ Close file. """ self.document.close(True) self.document = None - def close_ooo(self): + def closeOoo(self): """ Close OOo. But only if we started it and not on windows """ - if self.process_started: + if self.processStarted: self.desktop.terminate() - def process_pres(self): + def processPres(self): """ Process the file """ @@ -209,10 +209,10 @@ class OooImport(SongImport): if slidetext.strip() == u'': slidetext = u'\f' text += slidetext - self.process_songs_text(text) + self.processSongsText(text) return - def process_doc(self): + def processDoc(self): """ Process the doc file, a paragraph at a time """ @@ -231,16 +231,16 @@ class OooImport(SongImport): if textportion.BreakType in (PAGE_AFTER, PAGE_BOTH): paratext += u'\f' text += paratext + u'\n' - self.process_songs_text(text) + self.processSongsText(text) - def process_songs_text(self, text): - songtexts = self.tidy_text(text).split(u'\f') + def processSongsText(self, text): + songtexts = self.tidyText(text).split(u'\f') self.setDefaults() for songtext in songtexts: if songtext.strip(): - self.process_song_text(songtext.strip()) - if self.check_complete(): + self.processSongText(songtext.strip()) + if self.checkComplete(): self.finish() self.setDefaults() - if self.check_complete(): + if self.checkComplete(): self.finish() diff --git a/openlp/plugins/songs/lib/opensongimport.py b/openlp/plugins/songs/lib/opensongimport.py index da2f33ada..da5809095 100644 --- a/openlp/plugins/songs/lib/opensongimport.py +++ b/openlp/plugins/songs/lib/opensongimport.py @@ -130,9 +130,9 @@ class OpenSongImport(SongImport): root = tree.getroot() fields = dir(root) decode = { - u'copyright': self.add_copyright, + u'copyright': self.addCopyright, u'ccli': u'ccli_number', - u'author': self.parse_author, + u'author': self.parseAuthor, u'title': u'title', u'aka': u'alternate_title', u'hymn_number': u'song_number' @@ -214,7 +214,7 @@ class OpenSongImport(SongImport): verses[verse_tag][verse_num][inst] = [] our_verse_order.append([verse_tag, verse_num, inst]) # Tidy text and remove the ____s from extended words - this_line = self.tidy_text(this_line) + this_line = self.tidyText(this_line) this_line = this_line.replace(u'_', u'') this_line = this_line.replace(u'|', u'\n') verses[verse_tag][verse_num][inst].append(this_line) @@ -223,9 +223,9 @@ class OpenSongImport(SongImport): for (verse_tag, verse_num, inst) in our_verse_order: verse_def = u'%s%s' % (verse_tag, verse_num) lines = u'\n'.join(verses[verse_tag][verse_num][inst]) - self.add_verse(lines, verse_def) + self.addVerse(lines, verse_def) if not self.verses: - self.add_verse('') + self.addVerse('') # figure out the presentation order, if present if u'presentation' in fields and root.presentation: order = unicode(root.presentation) @@ -246,7 +246,7 @@ class OpenSongImport(SongImport): verse_def = u'%s%s' % (verse_tag, verse_num) if verses.has_key(verse_tag) and \ verses[verse_tag].has_key(verse_num): - self.verse_order_list.append(verse_def) + self.verseOrderList.append(verse_def) else: log.info(u'Got order %s but not in verse tags, dropping' u'this item from presentation order', verse_def) diff --git a/openlp/plugins/songs/lib/sofimport.py b/openlp/plugins/songs/lib/sofimport.py index b0c60e3d6..6294f211e 100644 --- a/openlp/plugins/songs/lib/sofimport.py +++ b/openlp/plugins/songs/lib/sofimport.py @@ -83,18 +83,18 @@ class SofImport(OooImport): OooImport.__init__(self, manager, **kwargs) self.song = False - def process_ooo_document(self): + def processOooDocument(self): """ Handle the import process for SoF files. """ - self.process_sof_file() + self.processSofFile() - def process_sof_file(self): + def processSofFile(self): """ Process the RTF file, a paragraph at a time """ - self.blanklines = 0 - self.new_song() + self.blankLines = 0 + self.newSong() try: paragraphs = self.document.getText().createEnumeration() while paragraphs.hasMoreElements(): @@ -102,13 +102,13 @@ class SofImport(OooImport): return paragraph = paragraphs.nextElement() if paragraph.supportsService("com.sun.star.text.Paragraph"): - self.process_paragraph(paragraph) + self.processParagraph(paragraph) except RuntimeException as exc: log.exception(u'Error processing file: %s', exc) if not self.finish(): self.logError(self.filepath) - def process_paragraph(self, paragraph): + def processParagraph(self, paragraph): """ Process a paragraph. In the first book, a paragraph is a single line. In the latter ones @@ -124,26 +124,26 @@ class SofImport(OooImport): while textportions.hasMoreElements(): textportion = textportions.nextElement() if textportion.BreakType in (PAGE_BEFORE, PAGE_BOTH): - self.process_paragraph_text(text) - self.new_song() + self.processParagraphText(text) + self.newSong() text = u'' text += self.process_textportion(textportion) if textportion.BreakType in (PAGE_AFTER, PAGE_BOTH): - self.process_paragraph_text(text) - self.new_song() + self.processParagraphText(text) + self.newSong() text = u'' - self.process_paragraph_text(text) + self.processParagraphText(text) - def process_paragraph_text(self, text): + def processParagraphText(self, text): """ Split the paragraph text into multiple lines and process """ for line in text.split(u'\n'): - self.process_paragraph_line(line) - if self.blanklines > 2: - self.new_song() + self.processParagraphLine(line) + if self.blankLines > 2: + self.newSong() - def process_paragraph_line(self, text): + def processParagraphLine(self, text): """ Process a single line. Throw away that text which isn't relevant, i.e. stuff that appears at the end of the song. @@ -151,16 +151,16 @@ class SofImport(OooImport): """ text = text.strip() if text == u'': - self.blanklines += 1 - if self.blanklines > 1: + self.blankLines += 1 + if self.blankLines > 1: return if self.title != u'': - self.finish_verse() + self.finishVerse() return - self.blanklines = 0 - if self.skip_to_close_bracket: + self.blankLines = 0 + if self.skipToCloseBracket: if text.endswith(u')'): - self.skip_to_close_bracket = False + self.skipToCloseBracket = False return if text.startswith(u'CCL Licence'): self.italics = False @@ -169,24 +169,24 @@ class SofImport(OooImport): return if text.startswith(u'(NB.') or text.startswith(u'(Regrettably') \ or text.startswith(u'(From'): - self.skip_to_close_bracket = True + self.skipToCloseBracket = True return if text.startswith(u'Copyright'): - self.add_copyright(text) + self.addCopyright(text) return if text == u'(Repeat)': - self.finish_verse() - self.repeat_verse() + self.finishVerse() + self.repeatVerse() return if self.title == u'': if self.copyright == u'': - self.add_sof_author(text) + self.addSofAuthor(text) else: - self.add_copyright(text) + self.addCopyright(text) return - self.add_verse_line(text) + self.addVerseLine(text) - def process_textportion(self, textportion): + def processTextPortion(self, textportion): """ Process a text portion. Here we just get the text and detect if it's bold or italics. If it's bold then its a song number or song title. @@ -199,53 +199,53 @@ class SofImport(OooImport): return text if textportion.CharWeight == BOLD: boldtext = text.strip() - if boldtext.isdigit() and self.song_number == '': - self.add_songnumber(boldtext) + if boldtext.isdigit() and self.songNumber == '': + self.addSongNumber(boldtext) return u'' if self.title == u'': text = self.uncap_text(text) - self.add_title(text) + self.addTitle(text) return text if text.strip().startswith(u'('): return text self.italics = (textportion.CharPosture == ITALIC) return text - def new_song(self): + def newSong(self): """ A change of song. Store the old, create a new ... but only if the last song was complete. If not, stick with it """ if self.song: - self.finish_verse() - if not self.check_complete(): + self.finishVerse() + if not self.checkComplete(): return self.finish() self.song = True self.setDefaults() - self.skip_to_close_bracket = False - self.is_chorus = False + self.skipToCloseBracket = False + self.isChorus = False self.italics = False - self.currentverse = u'' + self.currentVerse = u'' - def add_songnumber(self, song_no): + def addSongNumber(self, song_no): """ Add a song number, store as alternate title. Also use the song number to work out which songbook we're in """ - self.song_number = song_no - self.alternate_title = song_no + u'.' - self.song_book_pub = u'Kingsway Publications' + self.songNumber = song_no + self.alternateTitle = song_no + u'.' + self.songBook_pub = u'Kingsway Publications' if int(song_no) <= 640: - self.song_book = u'Songs of Fellowship 1' + self.songBook = u'Songs of Fellowship 1' elif int(song_no) <= 1150: - self.song_book = u'Songs of Fellowship 2' + self.songBook = u'Songs of Fellowship 2' elif int(song_no) <= 1690: - self.song_book = u'Songs of Fellowship 3' + self.songBook = u'Songs of Fellowship 3' else: - self.song_book = u'Songs of Fellowship 4' + self.songBook = u'Songs of Fellowship 4' - def add_title(self, text): + def addTitle(self, text): """ Add the title to the song. Strip some leading/trailing punctuation that we don't want in a title @@ -258,7 +258,7 @@ class SofImport(OooImport): self.title = title self.importWizard.incrementProgressBar(u'Processing song ' + title, 0) - def add_sof_author(self, text): + def addSofAuthor(self, text): """ Add the author. OpenLP stores them individually so split by 'and', '&' and comma. @@ -266,42 +266,42 @@ class SofImport(OooImport): "Mr Smith" and "Mrs Smith". """ text = text.replace(u' and ', u' & ') - self.parse_author(text) + self.parseAuthor(text) - def add_verse_line(self, text): + def addVerseLine(self, text): """ Add a line to the current verse. If the formatting has changed and we're beyond the second line of first verse, then this indicates a change of verse. Italics are a chorus """ - if self.italics != self.is_chorus and ((len(self.verses) > 0) or - (self.currentverse.count(u'\n') > 1)): - self.finish_verse() + if self.italics != self.isChorus and ((len(self.verses) > 0) or + (self.currentVerse.count(u'\n') > 1)): + self.finishVerse() if self.italics: - self.is_chorus = True - self.currentverse += text + u'\n' + self.isChorus = True + self.currentVerse += text + u'\n' - def finish_verse(self): + def finishVerse(self): """ Verse is finished, store it. Note in book 1+2, some songs are formatted incorrectly. Here we try and split songs with missing line breaks into the correct number of verses. """ - if self.currentverse.strip() == u'': + if self.currentVerse.strip() == u'': return - if self.is_chorus: + if self.isChorus: versetag = u'C' splitat = None else: versetag = u'V' - splitat = self.verse_splits(self.song_number) + splitat = self.verseSplits(self.songNumber) if splitat: ln = 0 verse = u'' - for line in self.currentverse.split(u'\n'): + for line in self.currentVerse.split(u'\n'): ln += 1 if line == u'' or ln > splitat: - self.add_sof_verse(verse, versetag) + self.addSofVerse(verse, versetag) ln = 0 if line: verse = line + u'\n' @@ -310,19 +310,19 @@ class SofImport(OooImport): else: verse += line + u'\n' if verse: - self.add_sof_verse(verse, versetag) + self.addSofVerse(verse, versetag) else: - self.add_sof_verse(self.currentverse, versetag) - self.currentverse = u'' - self.is_chorus = False + self.addSofVerse(self.currentVerse, versetag) + self.currentVerse = u'' + self.isChorus = False - def add_sof_verse(self, lyrics, tag): - self.add_verse(lyrics, tag) - if not self.is_chorus and u'C1' in self.verse_order_list_generated: - self.verse_order_list_generated.append(u'C1') - self.verse_order_list_generated_useful = True + def addSofVerse(self, lyrics, tag): + self.addVerse(lyrics, tag) + if not self.isChorus and u'C1' in self.verseOrderListGenerated: + self.verseOrderListGenerated.append(u'C1') + self.verseOrderListGenerated_useful = True - def uncap_text(self, text): + def uncapText(self, text): """ Words in the title are in all capitals, so we lowercase them. However some of these words, e.g. referring to God need a leading @@ -348,7 +348,7 @@ class SofImport(OooImport): text = u''.join(textarr) return text - def verse_splits(self, song_number): + def verseSplits(self, song_number): """ Because someone at Kingsway forgot to check the 1+2 RTF file, some verses were not formatted correctly. diff --git a/openlp/plugins/songs/lib/songbeamerimport.py b/openlp/plugins/songs/lib/songbeamerimport.py index 327f08d11..2ed900544 100644 --- a/openlp/plugins/songs/lib/songbeamerimport.py +++ b/openlp/plugins/songs/lib/songbeamerimport.py @@ -91,7 +91,7 @@ class SongBeamerImport(SongImport): (re.compile(u''), u''), (re.compile(u''), u'') ] - + def __init__(self, manager, **kwargs): """ Initialise the Song Beamer importer. @@ -110,8 +110,8 @@ class SongBeamerImport(SongImport): if self.stopImportFlag: return self.setDefaults() - self.current_verse = u'' - self.current_verse_type = VerseType.Tags[VerseType.Verse] + self.currentVerse = u'' + self.currentVerseType = VerseType.Tags[VerseType.Verse] read_verses = False file_name = os.path.split(file)[1] if os.path.isfile(file): @@ -119,48 +119,48 @@ class SongBeamerImport(SongImport): details = chardet.detect(detect_file.read()) detect_file.close() infile = codecs.open(file, u'r', details['encoding']) - songData = infile.readlines() + song_data = infile.readlines() infile.close() else: continue self.title = file_name.split('.sng')[0] read_verses = False - for line in songData: + for line in song_data: # Just make sure that the line is of the type 'Unicode'. line = unicode(line).strip() if line.startswith(u'#') and not read_verses: - self.parse_tags(line) + self.parseTags(line) elif line.startswith(u'---'): - if self.current_verse: - self.replace_html_tags() - self.add_verse(self.current_verse, - self.current_verse_type) - self.current_verse = u'' - self.current_verse_type = VerseType.Tags[VerseType.Verse] + if self.currentVerse: + self.replaceHtmlTags() + self.addVerse(self.currentVerse, + self.currentVerseType) + self.currentVerse = u'' + self.currentVerseType = VerseType.Tags[VerseType.Verse] read_verses = True verse_start = True elif read_verses: if verse_start: verse_start = False - if not self.check_verse_marks(line): - self.current_verse = line + u'\n' + if not self.checkVerseMarks(line): + self.currentVerse = line + u'\n' else: - self.current_verse += line + u'\n' - if self.current_verse: - self.replace_html_tags() - self.add_verse(self.current_verse, self.current_verse_type) + self.currentVerse += line + u'\n' + if self.currentVerse: + self.replaceHtmlTags() + self.addVerse(self.currentVerse, self.currentVerseType) if not self.finish(): self.logError(file) - def replace_html_tags(self): + def replaceHtmlTags(self): """ This can be called to replace SongBeamer's specific (html) tags with OpenLP's specific (html) tags. """ for pair in SongBeamerImport.HTML_TAG_PAIRS: - self.current_verse = pair[0].sub(pair[1], self.current_verse) + self.currentVerse = pair[0].sub(pair[1], self.currentVerse) - def parse_tags(self, line): + def parseTags(self, line): """ Parses a meta data line. @@ -176,11 +176,11 @@ class SongBeamerImport(SongImport): if not tag_val[0] or not tag_val[1]: return if tag_val[0] == u'#(c)': - self.add_copyright(tag_val[1]) + self.addCopyright(tag_val[1]) elif tag_val[0] == u'#AddCopyrightInfo': pass elif tag_val[0] == u'#Author': - self.parse_author(tag_val[1]) + self.parseAuthor(tag_val[1]) elif tag_val[0] == u'#BackgroundImage': pass elif tag_val[0] == u'#Bible': @@ -188,7 +188,7 @@ class SongBeamerImport(SongImport): elif tag_val[0] == u'#Categories': self.topics = tag_val[1].split(',') elif tag_val[0] == u'#CCLI': - self.ccli_number = tag_val[1] + self.ccliNumber = tag_val[1] elif tag_val[0] == u'#Chords': pass elif tag_val[0] == u'#ChurchSongID': @@ -220,7 +220,7 @@ class SongBeamerImport(SongImport): elif tag_val[0] == u'#LangCount': pass elif tag_val[0] == u'#Melody': - self.parse_author(tag_val[1]) + self.parseAuthor(tag_val[1]) elif tag_val[0] == u'#NatCopyright': pass elif tag_val[0] == u'#OTitle': @@ -235,10 +235,10 @@ class SongBeamerImport(SongImport): song_book_pub = tag_val[1] elif tag_val[0] == u'#Songbook' or tag_val[0] == u'#SongBook': book_data = tag_val[1].split(u'/') - self.song_book_name = book_data[0].strip() + self.songBookName = book_data[0].strip() if len(book_data) == 2: number = book_data[1].strip() - self.song_number = number if number.isdigit() else u'' + self.songNumber = number if number.isdigit() else u'' elif tag_val[0] == u'#Speed': pass elif tag_val[0] == u'Tempo': @@ -269,7 +269,7 @@ class SongBeamerImport(SongImport): # TODO: add the verse order. pass - def check_verse_marks(self, line): + def checkVerseMarks(self, line): """ Check and add the verse's MarkType. Returns ``True`` if the given line contains a correct verse mark otherwise ``False``. @@ -279,10 +279,10 @@ class SongBeamerImport(SongImport): """ marks = line.split(u' ') if len(marks) <= 2 and marks[0] in SongBeamerTypes.MarkTypes: - self.current_verse_type = SongBeamerTypes.MarkTypes[marks[0]] + self.currentVerseType = SongBeamerTypes.MarkTypes[marks[0]] if len(marks) == 2: # If we have a digit, we append it to current_verse_type. if marks[1].isdigit(): - self.current_verse_type += marks[1] + self.currentVerseType += marks[1] return True return False