mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
calibre-server.exe: If no libraries are specified, use all the libraries known to the GUI
This commit is contained in:
parent
0bddbb67ad
commit
c5de98a8b1
@ -128,15 +128,21 @@ class LibraryBroker(object):
|
|||||||
EXPIRED_AGE = 300 # seconds
|
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):
|
class GuiLibraryBroker(LibraryBroker):
|
||||||
|
|
||||||
def __init__(self, db):
|
def __init__(self, db):
|
||||||
from calibre.gui2 import gprefs
|
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.last_used_times = defaultdict(lambda: -EXPIRED_AGE)
|
||||||
self.gui_library_id = None
|
self.gui_library_id = None
|
||||||
LibraryBroker.__init__(self, libraries)
|
LibraryBroker.__init__(self, load_gui_libraries(gprefs))
|
||||||
self.gui_library_changed(db)
|
self.gui_library_changed(db)
|
||||||
|
|
||||||
def init_library(self, library_path, is_default_library):
|
def init_library(self, library_path, is_default_library):
|
||||||
|
@ -12,6 +12,7 @@ from functools import partial
|
|||||||
from calibre import as_unicode, prints
|
from calibre import as_unicode, prints
|
||||||
from calibre.constants import plugins, iswindows, preferred_encoding
|
from calibre.constants import plugins, iswindows, preferred_encoding
|
||||||
from calibre.srv.loop import ServerLoop
|
from calibre.srv.loop import ServerLoop
|
||||||
|
from calibre.srv.library_broker import load_gui_libraries
|
||||||
from calibre.srv.bonjour import BonJour
|
from calibre.srv.bonjour import BonJour
|
||||||
from calibre.srv.opts import opts_to_parser
|
from calibre.srv.opts import opts_to_parser
|
||||||
from calibre.srv.http_response import create_http_handler
|
from calibre.srv.http_response import create_http_handler
|
||||||
@ -245,11 +246,10 @@ def create_option_parser():
|
|||||||
parser=opts_to_parser('%prog '+ _(
|
parser=opts_to_parser('%prog '+ _(
|
||||||
'''[options] [path to library folder...]
|
'''[options] [path to library folder...]
|
||||||
|
|
||||||
Start the calibre Content server. The calibre Content server
|
Start the calibre Content server. The calibre Content server exposes your
|
||||||
exposes your calibre libraries over the internet. You can specify
|
calibre libraries over the internet. You can specify the path to the library
|
||||||
the path to the library folders as arguments to %prog. If you do
|
folders as arguments to %prog. If you do not specify any paths, all the
|
||||||
not specify any paths, the library last opened (if any) in the main calibre
|
libraries that the main calibre program knows about will be used.
|
||||||
program will be used.
|
|
||||||
'''
|
'''
|
||||||
))
|
))
|
||||||
parser.add_option(
|
parser.add_option(
|
||||||
@ -293,6 +293,7 @@ def main(args=sys.argv):
|
|||||||
for lib in libraries:
|
for lib in libraries:
|
||||||
if not lib or not LibraryDatabase.exists_at(lib):
|
if not lib or not LibraryDatabase.exists_at(lib):
|
||||||
raise SystemExit(_('There is no calibre library at: %s') % lib)
|
raise SystemExit(_('There is no calibre library at: %s') % lib)
|
||||||
|
libraries = libraries or load_gui_libraries()
|
||||||
if not libraries:
|
if not libraries:
|
||||||
if not prefs['library_path']:
|
if not prefs['library_path']:
|
||||||
raise SystemExit(_('You must specify at least one calibre library'))
|
raise SystemExit(_('You must specify at least one calibre library'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user