calibre-server.exe: If no libraries are specified, use all the libraries known to the GUI

This commit is contained in:
Kovid Goyal 2017-05-14 22:04:02 +05:30
parent 0bddbb67ad
commit c5de98a8b1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 15 additions and 8 deletions

View File

@ -128,15 +128,21 @@ class LibraryBroker(object):
EXPIRED_AGE = 300 # seconds
def load_gui_libraries(gprefs=None):
if gprefs is None:
from calibre.utils.config import JSONConfig
gprefs = JSONConfig('gui')
stats = gprefs.get('library_usage_stats', {})
return sorted(stats, key=stats.get, reverse=True)
class GuiLibraryBroker(LibraryBroker):
def __init__(self, db):
from calibre.gui2 import gprefs
stats = gprefs.get('library_usage_stats', {})
libraries = sorted(stats, key=stats.get, reverse=True)
self.last_used_times = defaultdict(lambda: -EXPIRED_AGE)
self.gui_library_id = None
LibraryBroker.__init__(self, libraries)
LibraryBroker.__init__(self, load_gui_libraries(gprefs))
self.gui_library_changed(db)
def init_library(self, library_path, is_default_library):

View File

@ -12,6 +12,7 @@ from functools import partial
from calibre import as_unicode, prints
from calibre.constants import plugins, iswindows, preferred_encoding
from calibre.srv.loop import ServerLoop
from calibre.srv.library_broker import load_gui_libraries
from calibre.srv.bonjour import BonJour
from calibre.srv.opts import opts_to_parser
from calibre.srv.http_response import create_http_handler
@ -245,11 +246,10 @@ def create_option_parser():
parser=opts_to_parser('%prog '+ _(
'''[options] [path to library folder...]
Start the calibre Content server. The calibre Content server
exposes your calibre libraries over the internet. You can specify
the path to the library folders as arguments to %prog. If you do
not specify any paths, the library last opened (if any) in the main calibre
program will be used.
Start the calibre Content server. The calibre Content server exposes your
calibre libraries over the internet. You can specify the path to the library
folders as arguments to %prog. If you do not specify any paths, all the
libraries that the main calibre program knows about will be used.
'''
))
parser.add_option(
@ -293,6 +293,7 @@ def main(args=sys.argv):
for lib in libraries:
if not lib or not LibraryDatabase.exists_at(lib):
raise SystemExit(_('There is no calibre library at: %s') % lib)
libraries = libraries or load_gui_libraries()
if not libraries:
if not prefs['library_path']:
raise SystemExit(_('You must specify at least one calibre library'))