mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
calibre-debug --export-all-calibre-data allow specifying the export directory and libraries on the command line
This commit is contained in:
parent
10d61771fb
commit
525f74d8c0
@ -94,7 +94,10 @@ Everything after the -- is passed to the script.
|
||||
' 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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user