Port calibredb backup_metadata

This commit is contained in:
Kovid Goyal 2017-05-02 11:15:58 +05:30
parent 4080609d8c
commit 43cacd5916
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 54 additions and 7 deletions

View File

@ -4,19 +4,66 @@
from __future__ import absolute_import, division, print_function, unicode_literals from __future__ import absolute_import, division, print_function, unicode_literals
readonly = False from calibre import prints
readonly = True
version = 0 # change this if you change signature of implementation() version = 0 # change this if you change signature of implementation()
no_remote = True
def implementation(db, notify_changes, *args): def implementation(db, notify_changes, *args):
is_remote = notify_changes is not None raise NotImplementedError()
is_remote
def option_parser(get_parser, args): def option_parser(get_parser, args):
pass parser = get_parser(
_(
'''\
%prog backup_metadata [options]
Backup the metadata stored in the database into individual OPF files in each
books directory. This normally happens automatically, but you can run this
command to force re-generation of the OPF files, with the --all option.
Note that there is normally no need to do this, as the OPF files are backed up
automatically, every time metadata is changed.
'''
)
)
parser.add_option(
'--all',
default=False,
action='store_true',
help=_(
'Normally, this command only operates on books that have'
' out of date OPF files. This option makes it operate on all'
' books.'
)
)
return parser
class BackupProgress(object):
def __init__(self):
self.total = 0
self.count = 0
def __call__(self, book_id, mi, ok):
if mi is True:
self.total = book_id
else:
self.count += 1
prints(
u'%.1f%% %s - %s' % ((self.count * 100) / float(self.total), book_id,
getattr(mi, 'title', 'Unknown'))
)
def main(opts, args, dbctx): def main(opts, args, dbctx):
raise NotImplementedError('TODO: implement this') db = dbctx.db
book_ids = None
if opts.all:
book_ids = db.all_ids()
db.dump_metadata(book_ids=book_ids, callback=BackupProgress())
return 0 return 0

View File

@ -22,8 +22,8 @@ COMMANDS = (
'list', 'add', 'remove', 'add_format', 'remove_format', 'show_metadata', 'list', 'add', 'remove', 'add_format', 'remove_format', 'show_metadata',
'set_metadata', 'export', 'catalog', 'saved_searches', 'add_custom_column', 'set_metadata', 'export', 'catalog', 'saved_searches', 'add_custom_column',
'custom_columns', 'remove_custom_column', 'set_custom', 'restore_database', 'custom_columns', 'remove_custom_column', 'set_custom', 'restore_database',
'check_library', 'check_library', 'list_categories', 'backup_metadata',
# 'list_categories', 'backup_metadata', 'clone', 'embed_metadata', 'search' # 'clone', 'embed_metadata', 'search'
) )