Port calibredb show_metadata

This commit is contained in:
Kovid Goyal 2017-04-30 13:53:30 +05:30
parent 24523178f2
commit a0e0ae456a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -4,19 +4,54 @@
from __future__ import absolute_import, division, print_function, unicode_literals
readonly = False
import os
import sys
from calibre import prints
from calibre.ebooks.metadata.opf2 import OPFCreator
readonly = True
version = 0 # change this if you change signature of implementation()
def implementation(db, notify_changes, *args):
is_remote = notify_changes is not None
is_remote
def implementation(db, notify_changes, book_id):
with db.safe_read_lock:
if not db.has_id(book_id):
return
return db.get_metadata(book_id)
def option_parser(get_parser):
pass
parser = get_parser(
_(
'''
%prog show_metadata [options] id
Show the metadata stored in the calibre database for the book identified by id.
id is an id number from the search command.
'''
)
)
parser.add_option(
'--as-opf',
default=False,
action='store_true',
help=_('Print metadata in OPF form (XML)')
)
return parser
def main(opts, args, dbctx):
raise NotImplementedError('TODO: implement this')
if len(args) < 1:
raise SystemExit(_('You must specify an id'))
book_id = int(args[0])
mi = dbctx.run('show_metadata', book_id)
if mi is None:
raise SystemExit('Id #%d is not present in database.' % id)
if opts.as_opf:
mi = OPFCreator(os.getcwdu(), mi)
mi.render(sys.stdout)
else:
prints(unicode(mi))
return 0