mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Port calibredb backup_metadata
This commit is contained in:
parent
4080609d8c
commit
43cacd5916
@ -4,19 +4,66 @@
|
||||
|
||||
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()
|
||||
no_remote = True
|
||||
|
||||
|
||||
def implementation(db, notify_changes, *args):
|
||||
is_remote = notify_changes is not None
|
||||
is_remote
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
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):
|
||||
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
|
||||
|
@ -22,8 +22,8 @@ COMMANDS = (
|
||||
'list', 'add', 'remove', 'add_format', 'remove_format', 'show_metadata',
|
||||
'set_metadata', 'export', 'catalog', 'saved_searches', 'add_custom_column',
|
||||
'custom_columns', 'remove_custom_column', 'set_custom', 'restore_database',
|
||||
'check_library',
|
||||
# 'list_categories', 'backup_metadata', 'clone', 'embed_metadata', 'search'
|
||||
'check_library', 'list_categories', 'backup_metadata',
|
||||
# 'clone', 'embed_metadata', 'search'
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user