diff --git a/beets/library.py b/beets/library.py index 2b2a48cdb..01f688a34 100644 --- a/beets/library.py +++ b/beets/library.py @@ -104,18 +104,6 @@ def _ancestry(path): out.insert(0, path) return out -def _walk_files(path): - """Like os.walk, but only yields the files in the directory tree. The full - pathnames to the files (under path) are given. Also, if path is a file, - _walk_files just yields that. - """ - if os.path.isfile(path): - yield path - else: - for root, dirs, files in os.walk(path): - for filebase in files: - yield os.path.join(root, filebase) - def _components(path): """Return a list of the path components in path. For instance, _components('/a/b/c') == ['a', 'b', 'c']. @@ -624,21 +612,6 @@ class BaseLibrary(object): return sorted(out, compare) - ### convenience methods ### - - def add_path(self, path, copy=False): - path = _unicode_path(path) - items = [] - for f in _walk_files(path): - try: - item = Item.from_path(_normpath(f)) - except FileTypeError: - log.warn(f + ' of unknown type, skipping') - except UnreadableFileError: - log.error(f + ' is unreadable, skipping') - self.add(item, copy) - - class Library(BaseLibrary): """A music library using an SQLite database as a metadata store.""" def __init__(self, path='library.blb', diff --git a/beets/ui/__init__.py b/beets/ui/__init__.py index 2d06737fc..48ed7f615 100644 --- a/beets/ui/__init__.py +++ b/beets/ui/__init__.py @@ -18,7 +18,6 @@ CLI commands are implemented in the ui.commands module. """ import os -import logging import locale import optparse import textwrap diff --git a/test/test_db.py b/test/test_db.py index 67af71b9b..3c8a8039a 100644 --- a/test/test_db.py +++ b/test/test_db.py @@ -105,7 +105,8 @@ class AddTest(unittest.TestCase): self.assertEqual(new_grouping, self.i.grouping) def test_library_add_path_inserts_row(self): - self.lib.add_path(os.path.join('rsrc', 'full.mp3')) + i = beets.library.Item.from_path(os.path.join('rsrc', 'full.mp3')) + self.lib.add(i) new_grouping = self.lib.conn.execute('select grouping from items ' 'where composer="the composer"').fetchone()['grouping'] self.assertEqual(new_grouping, self.i.grouping) diff --git a/test/test_files.py b/test/test_files.py index 2c0024307..8be524141 100644 --- a/test/test_files.py +++ b/test/test_files.py @@ -68,66 +68,6 @@ class MoveTest(unittest.TestCase): def test_move_changes_path(self): self.i.move(self.lib) self.assertEqual(self.i.path, beets.library._normpath(self.dest)) - -class WalkTest(unittest.TestCase): - def setUp(self): - # create a directory structure for testing - self.base = join('rsrc', 'temp_walk') - os.mkdir(self.base) - mkfile(join(self.base, 'file')) - os.mkdir(join(self.base, 'dir1')) - mkfile(join(self.base, 'dir1', 'dir1f1')) - mkfile(join(self.base, 'dir1', 'dir1f2')) - os.mkdir(join(self.base, 'dir2')) - mkfile(join(self.base, 'dir2', 'dir2f')) - os.mkdir(join(self.base, 'dir2', 'dir2dir')) - mkfile(join(self.base, 'dir2', 'dir2dir', 'dir2dirf')) - def tearDown(self): - shutil.rmtree(self.base) - - def test_walk_single_file(self): - path = join(self.base, 'file') - s = set(beets.library._walk_files(path)) - self.assertTrue(path in s) - s.remove(path) - self.assertTrue(not s) # s is empty (i.e., contains nothing else) - - def test_walk_flat_directory(self): - path = join(self.base, 'dir1') - s = set(beets.library._walk_files(path)) - for f in (join(path, 'dir1f1'), - join(path, 'dir1f2')): - self.assertTrue(f in s) - s.remove(f) - self.assertTrue(not s) - - def test_walk_hierarchy(self): - path = join(self.base, 'dir2') - s = set(beets.library._walk_files(path)) - for f in (join(path, 'dir2f'), - join(path, 'dir2dir', 'dir2dirf')): - self.assertTrue(f in s) - s.remove(f) - self.assertTrue(not s) - -class AddTest(unittest.TestCase): - def setUp(self): - self.dir = os.path.join('rsrc', 'test_lib') - self.lib = beets.library.Library(':memory:') - self.lib.directory = self.dir - self.lib.path_format = 'item' - def tearDown(self): - if os.path.exists(self.dir): - shutil.rmtree(self.dir) - - def test_library_add_path_copies(self): - self.lib.add_path(os.path.join('rsrc', 'full.mp3'), copy=True) - self.assertTrue(os.path.isfile(os.path.join(self.dir, 'item.mp3'))) - - def test_add_path_enforces_unicode_pathnames(self): - self.lib.add_path(os.path.join('rsrc', 'full.mp3')) - item = self.lib.get().next() - self.assertTrue(isinstance(item.path, unicode)) class HelperTest(unittest.TestCase): def test_ancestry_works_on_file(self):