Esempio n. 1
0
 def initialise(self):
     """
     Initialise variables when they cannot be initialised in the constructor.
     """
     self.song_maintenance_form = SongMaintenanceForm(self.plugin.manager, self)
     self.edit_song_form = EditSongForm(self, self.main_window, self.plugin.manager)
     self.open_lyrics = OpenLyrics(self.plugin.manager)
     self.search_text_edit.set_search_types([
         (SongSearch.Entire, ':/songs/song_search_all.png',
             translate('SongsPlugin.MediaItem', 'Entire Song'),
             translate('SongsPlugin.MediaItem', 'Search Entire Song...')),
         (SongSearch.Titles, ':/songs/song_search_title.png',
             translate('SongsPlugin.MediaItem', 'Titles'),
             translate('SongsPlugin.MediaItem', 'Search Titles...')),
         (SongSearch.Lyrics, ':/songs/song_search_lyrics.png',
             translate('SongsPlugin.MediaItem', 'Lyrics'),
             translate('SongsPlugin.MediaItem', 'Search Lyrics...')),
         (SongSearch.Authors, ':/songs/song_search_author.png', SongStrings.Authors,
             translate('SongsPlugin.MediaItem', 'Search Authors...')),
         (SongSearch.Topics, ':/songs/song_search_topic.png', SongStrings.Topics,
             translate('SongsPlugin.MediaItem', 'Search Topics...')),
         (SongSearch.Books, ':/songs/song_book_edit.png', SongStrings.SongBooks,
             translate('SongsPlugin.MediaItem', 'Search Songbooks...')),
         (SongSearch.Themes, ':/slides/slide_theme.png', UiStrings().Themes, UiStrings().SearchThemes),
         (SongSearch.Copyright, ':/songs/song_search_copy.png',
             translate('SongsPlugin.MediaItem', 'Copyright'),
             translate('SongsPlugin.MediaItem', 'Search Copyright...')),
         (SongSearch.CCLInumber, ':/songs/song_search_ccli.png',
             translate('SongsPlugin.MediaItem', 'CCLI number'),
             translate('SongsPlugin.MediaItem', 'Search CCLI number...'))
     ])
     self.search_text_edit.set_current_search_type(
         Settings().value('{section}/last search type'.format(section=self.settings_section)))
     self.config_update()
Esempio n. 2
0
 def __init__(self, manager, **kwargs):
     """
     Initialise the Open Lyrics importer.
     """
     log.debug('initialise OpenLyricsImport')
     super(OpenLyricsImport, self).__init__(manager, **kwargs)
     self.open_lyrics = OpenLyrics(self.manager)
Esempio n. 3
0
 def initialise(self):
     """
     Initialise variables when they cannot be initialised in the constructor.
     """
     self.song_maintenance_form = SongMaintenanceForm(self.plugin.manager, self)
     self.edit_song_form = EditSongForm(self, self.main_window, self.plugin.manager)
     self.open_lyrics = OpenLyrics(self.plugin.manager)
     self.search_text_edit.set_search_types([
         (SongSearch.Entire, UiIcons().music,
             translate('SongsPlugin.MediaItem', 'Entire Song'),
             translate('SongsPlugin.MediaItem', 'Search Entire Song...')),
         (SongSearch.Titles, UiIcons().search_text,
             translate('SongsPlugin.MediaItem', 'Titles'),
             translate('SongsPlugin.MediaItem', 'Search Titles...')),
         (SongSearch.Lyrics, UiIcons().search_lyrcs,
             translate('SongsPlugin.MediaItem', 'Lyrics'),
             translate('SongsPlugin.MediaItem', 'Search Lyrics...')),
         (SongSearch.Authors, UiIcons().user, SongStrings.Authors,
             translate('SongsPlugin.MediaItem', 'Search Authors...')),
         (SongSearch.Topics, UiIcons().theme, SongStrings.Topics,
             translate('SongsPlugin.MediaItem', 'Search Topics...')),
         (SongSearch.Books, UiIcons().address, SongStrings.SongBooks,
             translate('SongsPlugin.MediaItem', 'Search Songbooks...')),
         (SongSearch.Themes, UiIcons().theme, UiStrings().Themes, UiStrings().SearchThemes),
         (SongSearch.Copyright, UiIcons().copyright,
             translate('SongsPlugin.MediaItem', 'Copyright'),
             translate('SongsPlugin.MediaItem', 'Search Copyright...')),
         (SongSearch.CCLInumber, UiIcons().search_ccli,
             translate('SongsPlugin.MediaItem', 'CCLI number'),
             translate('SongsPlugin.MediaItem', 'Search CCLI number...'))
     ])
     self.config_update()
Esempio n. 4
0
 def do_export(self):
     """
     Export the songs.
     """
     log.debug('started OpenLyricsExport')
     open_lyrics = OpenLyrics(self.manager)
     self.parent.progress_bar.setMaximum(len(self.songs))
     for song in self.songs:
         self.application.process_events()
         if self.parent.stop_export_flag:
             return False
         self.parent.increment_progress_bar(
             translate('SongsPlugin.OpenLyricsExport', 'Exporting "%s"...') % song.title)
         xml = open_lyrics.song_to_xml(song)
         tree = etree.ElementTree(etree.fromstring(xml.encode()))
         filename = '%s (%s)' % (song.title, ', '.join([author.display_name for author in song.authors]))
         filename = clean_filename(filename)
         # Ensure the filename isn't too long for some filesystems
         filename_with_ext = '%s.xml' % filename[0:250 - len(self.save_path)]
         # Make sure we're not overwriting an existing file
         conflicts = 0
         while os.path.exists(os.path.join(self.save_path, filename_with_ext)):
             conflicts += 1
             filename_with_ext = '%s-%d.xml' % (filename[0:247 - len(self.save_path)], conflicts)
         # Pass a file object, because lxml does not cope with some special
         # characters in the path (see lp:757673 and lp:744337).
         tree.write(open(os.path.join(self.save_path, filename_with_ext), 'wb'), encoding='utf-8',
                    xml_declaration=True, pretty_print=True)
     return True
Esempio n. 5
0
 def do_export(self):
     """
     Export the songs.
     """
     log.debug('started OpenLyricsExport')
     open_lyrics = OpenLyrics(self.manager)
     self.parent.progress_bar.setMaximum(len(self.songs))
     for song in self.songs:
         self.application.process_events()
         if self.parent.stop_export_flag:
             return False
         self.parent.increment_progress_bar(
             translate('SongsPlugin.OpenLyricsExport', 'Exporting "{title}"...').format(title=song.title))
         xml = open_lyrics.song_to_xml(song)
         tree = etree.ElementTree(etree.fromstring(xml.encode()))
         filename = '{title} ({author})'.format(title=song.title,
                                                author=', '.join([author.display_name for author in song.authors]))
         filename = clean_filename(filename)
         # Ensure the filename isn't too long for some filesystems
         path_length = len(str(self.save_path))
         filename_with_ext = '{name}.xml'.format(name=filename[0:250 - path_length])
         # Make sure we're not overwriting an existing file
         conflicts = 0
         while (self.save_path / filename_with_ext).exists():
             conflicts += 1
             filename_with_ext = '{name}-{extra}.xml'.format(name=filename[0:247 - path_length], extra=conflicts)
         # Pass a file object, because lxml does not cope with some special
         # characters in the path (see lp:757673 and lp:744337).
         with (self.save_path / filename_with_ext).open('wb') as out_file:
             tree.write(out_file, encoding='utf-8', xml_declaration=True, pretty_print=True)
     return True
Esempio n. 6
0
    def test_process_songbooks(self):
        """
        Test that _process_songbooks works
        """
        # GIVEN: A OpenLyric XML with songbooks and a mocked out manager
        with patch('openlp.plugins.songs.lib.openlyricsxml.Book'):
            mocked_manager = MagicMock()
            mocked_manager.get_object_filtered.return_value = None
            ol = OpenLyrics(mocked_manager)
            properties_xml = objectify.fromstring(songbook_xml)
            mocked_song = MagicMock()

            # WHEN: processing the songbook xml
            ol._process_songbooks(properties_xml, mocked_song)

            # THEN: add_songbook_entry should have been called twice
            assert mocked_song.method_calls[0][1][1] == '48'
            assert mocked_song.method_calls[1][1][1] == '445 A'
Esempio n. 7
0
    def test_process_author(self):
        """
        Test that _process_authors works
        """
        # GIVEN: A OpenLyric XML with authors and a mocked out manager
        with patch('openlp.plugins.songs.lib.openlyricsxml.Author'):
            mocked_manager = MagicMock()
            mocked_manager.get_object_filtered.return_value = None
            ol = OpenLyrics(mocked_manager)
            properties_xml = objectify.fromstring(author_xml)
            mocked_song = MagicMock()

            # WHEN: processing the author xml
            ol._process_authors(properties_xml, mocked_song)

            # THEN: add_author should have been called twice
            assert mocked_song.method_calls[0][1][1] == 'words+music'
            assert mocked_song.method_calls[1][1][1] == 'words'
Esempio n. 8
0
    def test_process_formatting_tags(self):
        """
        Test that _process_formatting_tags works
        """
        # GIVEN: A OpenLyric XML with formatting tags and a mocked out manager
        mocked_manager = MagicMock()
        Settings().setValue('formattingTags/html_tags', json.dumps(start_tags))
        ol = OpenLyrics(mocked_manager)
        parser = etree.XMLParser(remove_blank_text=True)
        parsed_file = etree.parse((TEST_PATH / 'duchu-tags.xml').open('rb'),
                                  parser)
        xml = etree.tostring(parsed_file).decode()
        song_xml = objectify.fromstring(xml)

        # WHEN: processing the formatting tags
        ol._process_formatting_tags(song_xml, False)

        # THEN: New tags should have been saved
        assert json.loads(json.dumps(result_tags)) == json.loads(str(Settings().value('formattingTags/html_tags'))), \
            'The formatting tags should contain both the old and the new'