Skip to content
Permalink
Browse files
calibre-debug --export-all-calibre-data allow specifying the export d…
…irectory and libraries on the command line
  • Loading branch information
kovidgoyal committed Jul 10, 2018
1 parent 10d6177 commit 525f74d8c01d6ff3584840bf23836c2d918bb6a1
Showing with 21 additions and 4 deletions.
  1. +6 −2 src/calibre/debug.py
  2. +15 −2 src/calibre/utils/exim.py
@@ -94,7 +94,10 @@ def option_parser():
' been created by a previous call to --explode-book. Be sure to'
' specify the same file type as was used when exploding.'))
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',
help=_('Import previously exported calibre data'))
parser.add_option('-s', '--shutdown-running-calibre', default=False,
@@ -321,8 +324,9 @@ def main(args=sys.argv):
print 'Running', func.__name__, '...'
func()
elif opts.export_all_calibre_data:
args = args[1:]
from calibre.utils.exim import run_exporter
run_exporter()
run_exporter(args=args)
elif opts.import_calibre_data:
from calibre.utils.exim import run_importer
run_importer()
@@ -385,7 +385,20 @@ def cli_report(*args, **kw):
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(
'Enter path to an empty folder (all exported data will be saved inside it): ').decode(
filesystem_encoding).rstrip('\r')
@@ -397,7 +410,7 @@ def run_exporter(export_dir=None):
raise SystemExit('%s is not empty' % export_dir)
library_paths = {}
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
if library_paths:
export(export_dir, progress1=cli_report, progress2=cli_report, library_paths=library_paths)

0 comments on commit 525f74d

Please sign in to comment.