automatically detect path queries containing / (finishes #146)

This commit is contained in:
Adrian Sampson 2011-06-26 00:25:39 -07:00
parent fcc2744ac5
commit 7f206baae5
3 changed files with 29 additions and 2 deletions

5
NEWS
View file

@ -9,6 +9,11 @@
now matches the entire phrase. To match in specified fields, use
a construction like this:
beet ls "artist:the knife"
* Queries can match items from the library by directory. A 'path:'
prefix is optional; any query containing a path separator (/ on
POSIX systems) is assumed to be a path query. Running
"beet ls path/to/music" will show all the music in your library
under the specified directory.
* Album art is now automatically discovered and copied from the
imported directories when available.
* The release label for albums and tracks is now fetched from

View file

@ -420,8 +420,14 @@ class CollectionQuery(Query):
if not res:
continue
key, pattern = res
if key is None: # no key specified; match any field
subqueries.append(AnySubstringQuery(pattern, default_fields))
if key is None: # No key specified.
if os.sep in pattern:
# This looks like a path.
subqueries.append(PathQuery(pattern))
else:
# Match any field.
subqueries.append(AnySubstringQuery(pattern,
default_fields))
elif key.lower() == 'comp': # a boolean field
subqueries.append(BooleanQuery(key.lower(), pattern))
elif key.lower() == 'path':

View file

@ -258,6 +258,22 @@ class PathQueryTest(unittest.TestCase, AssertsMixin):
self.assert_matched(results, 'path item')
self.assert_done(results)
def test_slashed_query_matches_path(self):
q = '/a/b'
results = self.lib.items(q)
self.assert_matched(results, 'path item')
self.assert_done(results)
def test_non_slashed_does_not_match_path(self):
q = 'c.mp3'
results = self.lib.items(q)
self.assert_done(results)
def test_slashes_in_explicit_field_does_not_match_path(self):
q = 'title:/a/b'
results = self.lib.items(q)
self.assert_done(results)
class BrowseTest(unittest.TestCase, AssertsMixin):
def setUp(self):
self.lib = beets.library.Library(