Item.move() now takes a library as an argument

--HG--
branch : device
This commit is contained in:
Adrian Sampson 2010-04-06 11:18:41 -07:00
parent c7f98ccde1
commit 628cfbffe2
3 changed files with 9 additions and 9 deletions

View file

@ -264,7 +264,7 @@ class Item(object):
#### dealing with files themselves ####
def move(self, copy=False):
def move(self, library, copy=False):
"""Move the item to its designated location within the library
directory (provided by destination()). Subdirectories are created as
needed. If the operation succeeds, the item's path field is updated to
@ -278,7 +278,7 @@ class Item(object):
Note that one should almost certainly call store() and library.save()
after this method in order to keep on-disk data consistent.
"""
dest = self.library.destination(self)
dest = library.destination(self)
# Create necessary ancestry for the move. Like os.renames but only
# halfway.
@ -685,7 +685,7 @@ class Library(BaseLibrary):
#FIXME make a deep copy of the item?
item.library = self
if copy:
item.move(copy=True)
item.move(self, copy=True)
# build essential parts of query
columns = ','.join([key for key in item_keys if key != 'id'])

2
bts
View file

@ -95,7 +95,7 @@ def tag_album(items, lib):
# Change metadata and add to library.
autotag.apply_metadata(items, info)
for item in items:
item.move(True)
item.move(lib, True)
item.add()
item.write()

View file

@ -52,23 +52,23 @@ class MoveTest(unittest.TestCase):
shutil.rmtree(self.libdir)
def test_move_arrives(self):
self.i.move()
self.i.move(self.lib)
self.assertTrue(os.path.exists(self.dest))
def test_move_departs(self):
self.i.move()
self.i.move(self.lib)
self.assertTrue(not os.path.exists(self.path))
def test_copy_arrives(self):
self.i.move(copy=True)
self.i.move(self.lib, copy=True)
self.assertTrue(os.path.exists(self.dest))
def test_copy_does_not_depart(self):
self.i.move(copy=True)
self.i.move(self.lib, copy=True)
self.assertTrue(os.path.exists(self.path))
def test_move_changes_path(self):
self.i.move()
self.i.move(self.lib)
self.assertEqual(self.i.path, beets.library._normpath(self.dest))
class WalkTest(unittest.TestCase):