Beispiel #1
0
    def move_art(self, copy=False, link=False):
        """Move or copy any existing album art so that it remains in the
        same directory as the items.
        """
        old_art = self.artpath
        if not old_art:
            return

        new_art = self.art_destination(old_art)
        if new_art == old_art:
            return

        new_art = util.unique_path(new_art)
        log.debug(u'moving album art {0} to {1}',
                  util.displayable_path(old_art),
                  util.displayable_path(new_art))
        if copy:
            util.copy(old_art, new_art)
        elif link:
            util.link(old_art, new_art)
        else:
            util.move(old_art, new_art)
        self.artpath = new_art

        # Prune old path when moving.
        if not copy:
            util.prune_dirs(os.path.dirname(old_art),
                            self._db.directory)
Beispiel #2
0
    def move_art(self, copy=False, link=False):
        """Move or copy any existing album art so that it remains in the
        same directory as the items.
        """
        old_art = self.artpath
        if not old_art:
            return

        new_art = self.art_destination(old_art)
        if new_art == old_art:
            return

        new_art = util.unique_path(new_art)
        log.debug(u'moving album art {0} to {1}',
                  util.displayable_path(old_art),
                  util.displayable_path(new_art))
        if copy:
            util.copy(old_art, new_art)
        elif link:
            util.link(old_art, new_art)
        else:
            util.move(old_art, new_art)
        self.artpath = new_art

        # Prune old path when moving.
        if not copy:
            util.prune_dirs(os.path.dirname(old_art), self._db.directory)
Beispiel #3
0
    def move_file(self, dest, copy=False, link=False):
        """Moves or copies the item's file, updating the path value if
        the move succeeds. If a file exists at ``dest``, then it is
        slightly modified to be unique.
        """
        if not util.samefile(self.path, dest):
            dest = util.unique_path(dest)
        if copy:
            util.copy(self.path, dest)
            plugins.send("item_copied",
                         item=self,
                         source=self.path,
                         destination=dest)
        elif link:
            util.link(self.path, dest)
            plugins.send("item_linked",
                         item=self,
                         source=self.path,
                         destination=dest)
        else:
            plugins.send("before_item_moved",
                         item=self,
                         source=self.path,
                         destination=dest)
            util.move(self.path, dest)
            plugins.send("item_moved",
                         item=self,
                         source=self.path,
                         destination=dest)

        # Either copying or moving succeeded, so update the stored path.
        self.path = dest
Beispiel #4
0
    def set_art(self, path, copy=True):
        """Sets the album's cover art to the image at the given path.
        The image is copied (or moved) into place, replacing any
        existing art.

        Sends an 'art_set' event with `self` as the sole argument.
        """
        path = bytestring_path(path)
        oldart = self.artpath
        artdest = self.art_destination(path)

        if oldart and samefile(path, oldart):
            # Art already set.
            return
        elif samefile(path, artdest):
            # Art already in place.
            self.artpath = path
            return

        # Normal operation.
        if oldart == artdest:
            util.remove(oldart)
        artdest = util.unique_path(artdest)
        if copy:
            util.copy(path, artdest)
        else:
            util.move(path, artdest)
        self.artpath = artdest

        plugins.send('art_set', album=self)
Beispiel #5
0
    def set_art(self, path, copy=True):
        """Sets the album's cover art to the image at the given path.
        The image is copied (or moved) into place, replacing any
        existing art.
        """
        path = bytestring_path(path)
        oldart = self.artpath
        artdest = self.art_destination(path)

        if oldart and samefile(path, oldart):
            # Art already set.
            return
        elif samefile(path, artdest):
            # Art already in place.
            self.artpath = path
            return

        # Normal operation.
        if oldart == artdest:
            util.remove(oldart)
        artdest = util.unique_path(artdest)
        if copy:
            util.copy(path, artdest)
        else:
            util.move(path, artdest)
        self.artpath = artdest
Beispiel #6
0
 def move(self, dest, copy=False):
     """Moves or copies the item's file, updating the path value if
     the move succeeds. If a file exists at ``dest``, then it is
     slightly modified to be unique.
     """
     if not util.samefile(self.path, dest):
         dest = util.unique_path(dest)
     if copy:
         util.copy(self.path, dest)
     else:
         util.move(self.path, dest)
         
     # Either copying or moving succeeded, so update the stored path.
     self.path = dest
Beispiel #7
0
 def move(self, dest, copy=False):
     """Moves or copies the item's file, updating the path value if
     the move succeeds. If a file exists at ``dest``, then it is
     slightly modified to be unique.
     """
     if not util.samefile(self.path, dest):
         dest = util.unique_path(dest)
     if copy:
         util.copy(self.path, dest)
     else:
         util.move(self.path, dest)
         
     # Either copying or moving succeeded, so update the stored path.
     self.path = dest
Beispiel #8
0
    def move_file(self, dest, copy=False, link=False):
        """Moves or copies the item's file, updating the path value if
        the move succeeds. If a file exists at ``dest``, then it is
        slightly modified to be unique.
        """
        if not util.samefile(self.path, dest):
            dest = util.unique_path(dest)
        if copy:
            util.copy(self.path, dest)
            plugins.send("item_copied", item=self, source=self.path, destination=dest)
        elif link:
            util.link(self.path, dest)
            plugins.send("item_linked", item=self, source=self.path, destination=dest)
        else:
            plugins.send("before_item_moved", item=self, source=self.path, destination=dest)
            util.move(self.path, dest)
            plugins.send("item_moved", item=self, source=self.path, destination=dest)

        # Either copying or moving succeeded, so update the stored path.
        self.path = dest
Beispiel #9
0
    def set_art(self, path):
        """Sets the album's cover art to the image at the given path.
        The image is copied into place, replacing any existing art.
        """
        path = bytestring_path(path)
        oldart = self.artpath
        artdest = self.art_destination(path)

        if oldart and samefile(path, oldart):
            # Art already set.
            return
        elif samefile(path, artdest):
            # Art already in place.
            self.artpath = path
            return

        # Normal operation.
        if oldart == artdest:
            util.soft_remove(oldart)
        artdest = util.unique_path(artdest)
        util.copy(path, artdest)
        self.artpath = artdest
Beispiel #10
0
 def test_conflicting_file_appends_1(self):
     path = util.unique_path(os.path.join(self.base, 'y.mp3'))
     self.assertEqual(path, os.path.join(self.base, 'y.1.mp3'))
Beispiel #11
0
 def test_conflicting_file_with_number_increases_number(self):
     path = util.unique_path(os.path.join(self.base, 'x.1.mp3'))
     self.assertEqual(path, os.path.join(self.base, 'x.3.mp3'))
Beispiel #12
0
 def test_new_file_unchanged(self):
     path = util.unique_path(os.path.join(self.base, 'z.mp3'))
     self.assertEqual(path, os.path.join(self.base, 'z.mp3'))
Beispiel #13
0
 def test_conflicting_file_appends_higher_number(self):
     path = util.unique_path(os.path.join(self.base, 'x.mp3'))
     self.assertEqual(path, os.path.join(self.base, 'x.3.mp3'))
Beispiel #14
0
 def test_conflicting_file_appends_1(self):
     path = util.unique_path(os.path.join(self.base, 'y.mp3'))
     self.assertEqual(path, os.path.join(self.base, 'y.1.mp3'))
Beispiel #15
0
 def test_new_file_unchanged(self):
     path = util.unique_path(os.path.join(self.base, 'z.mp3'))
     self.assertEqual(path, os.path.join(self.base, 'z.mp3'))
Beispiel #16
0
 def test_conflicting_file_with_number_increases_number(self):
     path = util.unique_path(os.path.join(self.base, 'x.1.mp3'))
     self.assertEqual(path, os.path.join(self.base, 'x.3.mp3'))
Beispiel #17
0
 def test_conflicting_file_appends_higher_number(self):
     path = util.unique_path(os.path.join(self.base, 'x.mp3'))
     self.assertEqual(path, os.path.join(self.base, 'x.3.mp3'))