Finish list_categories (forgot to implement the -r option)

This commit is contained in:
Charles Haley 2010-10-08 09:58:17 +01:00
parent 2793c31ac7
commit 8203f53354

View File

@ -1025,7 +1025,7 @@ information is the equivalent of what is shown in the tags pane.
parser.add_option('-q', '--quote', default='"', parser.add_option('-q', '--quote', default='"',
help=_('The character to put around the category value in CSV mode. ' help=_('The character to put around the category value in CSV mode. '
'Default is quotes (").')) 'Default is quotes (").'))
parser.add_option('-r', '--categories', default=None, dest='report', parser.add_option('-r', '--categories', default='', dest='report',
help=_("Comma-separated list of category lookup names.\n" help=_("Comma-separated list of category lookup names.\n"
"Default: all")) "Default: all"))
parser.add_option('-w', '--line-width', default=-1, type=int, parser.add_option('-w', '--line-width', default=-1, type=int,
@ -1052,8 +1052,10 @@ def command_list_categories(args, dbpath):
db = LibraryDatabase2(dbpath) db = LibraryDatabase2(dbpath)
category_data = db.get_categories() category_data = db.get_categories()
data = [] data = []
report_on = [c.strip() for c in opts.report.split(',') if c.strip()]
categories = [k for k in category_data.keys() categories = [k for k in category_data.keys()
if db.metadata_for_field(k)['kind'] not in ['user', 'search']] if db.metadata_for_field(k)['kind'] not in ['user', 'search'] and
(not report_on or k in report_on)]
categories.sort(cmp=lambda x,y: cmp(x if x[0] != '#' else x[1:], categories.sort(cmp=lambda x,y: cmp(x if x[0] != '#' else x[1:],
y if y[0] != '#' else y[1:])) y if y[0] != '#' else y[1:]))