diff --git a/src/calibre/srv/library_broker.py b/src/calibre/srv/library_broker.py index 2cecc1da14..36d56fcccd 100644 --- a/src/calibre/srv/library_broker.py +++ b/src/calibre/srv/library_broker.py @@ -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): diff --git a/src/calibre/srv/standalone.py b/src/calibre/srv/standalone.py index 04938036c8..3376bbd767 100644 --- a/src/calibre/srv/standalone.py +++ b/src/calibre/srv/standalone.py @@ -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'))