dedup query-joining code

This commit is contained in:
Adrian Sampson 2010-04-09 23:07:20 -07:00
parent 2281bcd4e5
commit 60e945a516

12
bts
View file

@ -109,6 +109,11 @@ def tag_album(items, lib, copy=True, write=True):
if write: if write:
item.write() item.write()
def make_query(criteria):
"""Make query string for the list of criteria."""
return ' '.join(criteria).strip() or None
class BeetsApp(cmdln.Cmdln): class BeetsApp(cmdln.Cmdln):
name = "bts" name = "bts"
@ -188,10 +193,7 @@ class BeetsApp(cmdln.Cmdln):
${cmd_usage} ${cmd_usage}
${cmd_option_list} ${cmd_option_list}
""" """
q = ' '.join(criteria) q = make_query(criteria)
if not q.strip():
q = None # no criteria => match anything
if opts.album: if opts.album:
for artist, album in self.lib.albums(query=q): for artist, album in self.lib.albums(query=q):
_print(artist + ' - ' + album) _print(artist + ' - ' + album)
@ -210,7 +212,7 @@ class BeetsApp(cmdln.Cmdln):
${cmd_usage} ${cmd_usage}
${cmd_option_list} ${cmd_option_list}
""" """
q = ' '.join(criteria).strip() or None q = make_query(criteria)
# Get the matching items. # Get the matching items.
if opts.album: if opts.album: