calibre-debug --export-all-calibre-data allow specifying the export directory and libraries on the command line

This commit is contained in:
Kovid Goyal 2018-07-10 21:16:26 +05:30
parent 10d61771fb
commit 525f74d8c0
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 21 additions and 4 deletions

View File

@ -94,7 +94,10 @@ Everything after the -- is passed to the script.
' been created by a previous call to --explode-book. Be sure to' ' been created by a previous call to --explode-book. Be sure to'
' specify the same file type as was used when exploding.')) ' specify the same file type as was used when exploding.'))
parser.add_option('--export-all-calibre-data', default=False, action='store_true', parser.add_option('--export-all-calibre-data', default=False, action='store_true',
help=_('Export all calibre data (books/settings/plugins)')) help=_('Export all calibre data (books/settings/plugins). Normally, you will'
' be asked for the export dir and the libraries to export. You can also specify them'
' as command line arguments to skip the questions.'
' Use absolute paths for the export directory and libraries.'))
parser.add_option('--import-calibre-data', default=False, action='store_true', parser.add_option('--import-calibre-data', default=False, action='store_true',
help=_('Import previously exported calibre data')) help=_('Import previously exported calibre data'))
parser.add_option('-s', '--shutdown-running-calibre', default=False, parser.add_option('-s', '--shutdown-running-calibre', default=False,
@ -321,8 +324,9 @@ def main(args=sys.argv):
print 'Running', func.__name__, '...' print 'Running', func.__name__, '...'
func() func()
elif opts.export_all_calibre_data: elif opts.export_all_calibre_data:
args = args[1:]
from calibre.utils.exim import run_exporter from calibre.utils.exim import run_exporter
run_exporter() run_exporter(args=args)
elif opts.import_calibre_data: elif opts.import_calibre_data:
from calibre.utils.exim import run_importer from calibre.utils.exim import run_importer
run_importer() run_importer()

View File

@ -385,7 +385,20 @@ def cli_report(*args, **kw):
pass pass
def run_exporter(export_dir=None): def run_exporter(export_dir=None, args=None):
if args:
if len(args) < 2:
raise SystemExit('You must specify the export dir and libraries to export')
export_dir = args[0]
all_libraries = {os.path.normcase(os.path.abspath(path)):lus for path, lus in all_known_libraries().iteritems()}
libraries = {os.path.normcase(os.path.abspath(os.path.expanduser(path))) for path in args[1:]}
if libraries - set(all_libraries):
raise SystemExit('Unknown library: ' + tuple(libraries - all_libraries)[0])
libraries = {p: all_libraries[p] for p in libraries}
print('Exporting libraries:', ', '.join(sorted(libraries)), 'to:', export_dir)
export(export_dir, progress1=cli_report, progress2=cli_report, library_paths=libraries)
return
export_dir = export_dir or raw_input( export_dir = export_dir or raw_input(
'Enter path to an empty folder (all exported data will be saved inside it): ').decode( 'Enter path to an empty folder (all exported data will be saved inside it): ').decode(
filesystem_encoding).rstrip('\r') filesystem_encoding).rstrip('\r')
@ -397,7 +410,7 @@ def run_exporter(export_dir=None):
raise SystemExit('%s is not empty' % export_dir) raise SystemExit('%s is not empty' % export_dir)
library_paths = {} library_paths = {}
for lpath, lus in all_known_libraries().iteritems(): for lpath, lus in all_known_libraries().iteritems():
if raw_input('Export the library %s [y/n]: ' % lpath) == b'y': if raw_input('Export the library %s [y/n]: ' % lpath).strip().lower() == b'y':
library_paths[lpath] = lus library_paths[lpath] = lus
if library_paths: if library_paths:
export(export_dir, progress1=cli_report, progress2=cli_report, library_paths=library_paths) export(export_dir, progress1=cli_report, progress2=cli_report, library_paths=library_paths)