mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Port calibredb saved_searches
This commit is contained in:
parent
02aa7f1be0
commit
f0155f4b2a
@ -7,16 +7,70 @@ from __future__ import absolute_import, division, print_function, unicode_litera
|
||||
readonly = False
|
||||
version = 0 # change this if you change signature of implementation()
|
||||
|
||||
from calibre import prints
|
||||
|
||||
def implementation(db, notify_changes, *args):
|
||||
is_remote = notify_changes is not None
|
||||
is_remote
|
||||
|
||||
def implementation(db, notify_changes, action, *args):
|
||||
if action == 'list':
|
||||
with db.safe_read_lock:
|
||||
names = db.saved_search_names()
|
||||
return {n: db.saved_search_lookup(n) for n in names}
|
||||
if action == 'add':
|
||||
name, val = args
|
||||
db.saved_search_add(name, val)
|
||||
return
|
||||
if action == 'remove':
|
||||
name = args[0]
|
||||
db.saved_search_delete(name)
|
||||
return
|
||||
|
||||
|
||||
def option_parser(get_parser, args):
|
||||
pass
|
||||
parser = get_parser(
|
||||
_(
|
||||
'''\
|
||||
%prog saved_searches [options] (list|add|remove)
|
||||
|
||||
Manage the saved searches stored in this database.
|
||||
If you try to add a query with a name that already exists, it will be
|
||||
replaced.
|
||||
|
||||
Syntax for adding:
|
||||
|
||||
%prog saved_searches add search_name search_expression
|
||||
|
||||
Syntax for removing:
|
||||
|
||||
%prog saved_searches remove search_name
|
||||
'''
|
||||
)
|
||||
)
|
||||
return parser
|
||||
|
||||
|
||||
def main(opts, args, dbctx):
|
||||
raise NotImplementedError('TODO: implement this')
|
||||
args = args or ['list']
|
||||
if args[0] == 'list':
|
||||
for name, value in dbctx.run('saved_searches', 'list').iteritems():
|
||||
prints(_('Name:'), name)
|
||||
prints(_('Search string:'), value)
|
||||
print()
|
||||
elif args[0] == 'add':
|
||||
if len(args) < 3:
|
||||
raise SystemExit(_('Error: You must specify a name and a search string'))
|
||||
dbctx.run('saved_searches', 'add', args[1], args[2])
|
||||
prints(args[1], _('added'))
|
||||
elif args[0] == 'remove':
|
||||
if len(args) < 2:
|
||||
raise SystemExit(_('Error: You must specify a name'))
|
||||
dbctx.run('saved_searches', 'remove', args[1])
|
||||
prints(args[1], _('removed'))
|
||||
else:
|
||||
raise SystemExit(
|
||||
_(
|
||||
'Error: Action %s not recognized, must be one '
|
||||
'of: (add|remove|list)'
|
||||
) % args[0]
|
||||
)
|
||||
|
||||
return 0
|
||||
|
@ -21,7 +21,8 @@ from calibre.utils.serialize import MSGPACK_MIME
|
||||
COMMANDS = (
|
||||
'list', 'add', 'remove', 'add_format', 'remove_format', 'show_metadata',
|
||||
'set_metadata', 'export', 'catalog',
|
||||
# 'saved_searches', 'add_custom_column',
|
||||
'saved_searches',
|
||||
# 'add_custom_column',
|
||||
# 'custom_columns', 'remove_custom_column', 'set_custom', 'restore_database',
|
||||
# 'check_library', 'list_categories', 'backup_metadata', 'clone', 'embed_metadata',
|
||||
# 'search'
|
||||
|
Loading…
x
Reference in New Issue
Block a user