From 315575aa564cff459d27afd1573d748a73ef3a64 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 15 Sep 2022 08:07:06 +0530 Subject: [PATCH] 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) --- src/calibre/gui2/main.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/calibre/gui2/main.py b/src/calibre/gui2/main.py index ad5bf14ab4..22e0f1f252 100644 --- a/src/calibre/gui2/main.py +++ b/src/calibre/gui2/main.py @@ -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'))