When running calibre with the --with-library command line flag and calibre is already running, switch to the specified library in calibre. Fixes #1989631 [[Enhancement] do a library switch in calibre via the command line](https://bugs.launchpad.net/calibre/+bug/1989631)

This commit is contained in:
Kovid Goyal 2022-09-15 08:07:06 +05:30
parent 4429815b6b
commit 315575aa56
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -492,6 +492,9 @@ def communicate(opts, args, retry_communicate=False):
else:
if len(args) > 1:
args[1:] = [os.path.abspath(x) if os.path.exists(x) else x for x in args[1:]]
if opts.with_library and os.path.isdir(os.path.expanduser(opts.with_library)):
library_id = os.path.basename(opts.with_library).replace(' ', '_').encode('utf-8').hex()
args.insert(1, 'calibre://switch-library/_hex_-' + library_id)
import json
if not send_message(b'launched:'+as_bytes(json.dumps(args)), retry_communicate=retry_communicate):
raise SystemExit(_('Failed to contact running instance of calibre'))