Exemplo n.º 1
0
 def on_clone_click(self):
     """
     Clone a Song
     """
     log.debug('on_clone_click')
     if check_item_selected(self.list_view, UiStrings().SelectEdit):
         self.edit_item = self.list_view.currentItem()
         item_id = self.edit_item.data(QtCore.Qt.UserRole)
         old_song = self.plugin.manager.get_object(Song, item_id)
         song_xml = self.open_lyrics.song_to_xml(old_song)
         new_song = self.open_lyrics.xml_to_song(song_xml)
         new_song.title = '{title} <{text}>'.format(title=new_song.title,
                                                    text=translate('SongsPlugin.MediaItem',
                                                                   'copy', 'For song cloning'))
         # Copy audio files from the old to the new song
         if len(old_song.media_files) > 0:
             save_path = AppLocation.get_section_data_path(self.plugin.name) / 'audio' / str(new_song.id)
             create_paths(save_path)
             for media_file in old_song.media_files:
                 new_media_file_path = save_path / media_file.file_path.name
                 copyfile(media_file.file_path, new_media_file_path)
                 new_media_file = MediaFile()
                 new_media_file.file_path = new_media_file_path
                 new_media_file.type = media_file.type
                 new_media_file.weight = media_file.weight
                 new_song.media_files.append(new_media_file)
         self.plugin.manager.save_object(new_song)
     self.on_song_list_load()
Exemplo n.º 2
0
    def _write_theme(self, theme, image_source_path=None, image_destination_path=None):
        """
        Writes the theme to the disk and handles the background image if necessary

        :param Theme theme: The theme data object.
        :param openlp.core.common.path.Path image_source_path: Where the theme image is currently located.
        :param openlp.core.common.path.Path image_destination_path: Where the Theme Image is to be saved to
        :rtype: None
        """
        name = theme.theme_name
        theme_pretty = theme.export_theme(self.theme_path)
        theme_dir = self.theme_path / name
        create_paths(theme_dir)
        theme_path = theme_dir / '{file_name}.json'.format(file_name=name)
        try:
                theme_path.write_text(theme_pretty)
        except OSError:
            self.log_exception('Saving theme to file failed')
        if image_source_path and image_destination_path:
            if self.old_background_image_path and image_destination_path != self.old_background_image_path:
                delete_file(self.old_background_image_path)
            if image_source_path != image_destination_path:
                try:
                    copyfile(image_source_path, image_destination_path)
                except OSError:
                    self.log_exception('Failed to save theme image')
        self.generate_and_save_image(name, theme)
Exemplo n.º 3
0
 def _update_background_audio(self, song, item):
     song.media_files = []
     for i, bga in enumerate(item.background_audio):
         dest_path =\
             AppLocation.get_section_data_path(self.plugin.name) / 'audio' / str(song.id) / os.path.split(bga)[1]
         create_paths(dest_path.parent)
         copyfile(AppLocation.get_section_data_path('servicemanager') / bga, dest_path)
         song.media_files.append(MediaFile.populate(weight=i, file_path=dest_path))
     self.plugin.manager.save_object(song, True)
Exemplo n.º 4
0
    def test_copyfile_optional_params(self):
        """
        Test :func:`openlp.core.common.path.copyfile` when follow_symlinks is set to false
        """
        # GIVEN: A mocked :func:`shutil.copyfile`
        with patch('openlp.core.common.path.shutil.copyfile',
                   return_value='') as mocked_shutil_copyfile:

            # WHEN: Calling :func:`openlp.core.common.path.copyfile` with :param:`follow_symlinks` set to False
            copyfile(Path('source', 'test', 'path'),
                     Path('destination', 'test', 'path'),
                     follow_symlinks=False)

            # THEN: :func:`shutil.copyfile` should have been called with the optional parameters, with out any of the
            #       values being modified
            mocked_shutil_copyfile.assert_called_once_with(
                ANY, ANY, follow_symlinks=False)
Exemplo n.º 5
0
    def copy_media_file(self, song_id, file_path):
        """
        This method copies the media file to the correct location and returns
        the new file location.

        :param song_id:
        :param openlp.core.common.path.Path file_path: The file to copy.
        :return: The new location of the file
        :rtype: openlp.core.common.path.Path
        """
        if not hasattr(self, 'save_path'):
            self.save_path = AppLocation.get_section_data_path(
                self.import_wizard.plugin.name) / 'audio' / str(song_id)
        create_paths(self.save_path)
        if self.save_path not in file_path.parents:
            old_path, file_path = file_path, self.save_path / file_path.name
            copyfile(old_path, file_path)
        return file_path
Exemplo n.º 6
0
    def test_copyfile(self):
        """
        Test :func:`openlp.core.common.path.copyfile`
        """
        # GIVEN: A mocked :func:`shutil.copyfile` which returns a test path as a string
        with patch(
                'openlp.core.common.path.shutil.copyfile',
                return_value=os.path.join('destination', 'test',
                                          'path')) as mocked_shutil_copyfile:

            # WHEN: Calling :func:`openlp.core.common.path.copyfile` with the src and dst parameters as Path object
            #       types
            result = copyfile(Path('source', 'test', 'path'),
                              Path('destination', 'test', 'path'))

            # THEN: :func:`shutil.copyfile` should have been called with the str equivalents of the Path objects.
            #       :func:`openlp.core.common.path.copyfile` should return the str type result of calling
            #       :func:`shutil.copyfile` as a Path object.
            mocked_shutil_copyfile.assert_called_once_with(
                os.path.join('source', 'test', 'path'),
                os.path.join('destination', 'test', 'path'))
            assert result == Path('destination', 'test', 'path')