Port code for start/stop of CS to use new server

This commit is contained in:
Kovid Goyal 2017-04-10 20:22:36 +05:30
parent 2e84a2e1a9
commit 37e19d411a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 10 additions and 8 deletions

View File

@ -224,7 +224,7 @@ class ConnectShareAction(InterfaceAction):
if self.gui.content_server is None:
self.gui.start_content_server()
else:
self.gui.content_server.threaded_exit()
self.gui.content_server.stop()
self.stopping_msg = info_dialog(self.gui, _('Stopping'),
_('Stopping server, this could take up to a minute, please wait...'),
show_copy_button=False)

View File

@ -470,15 +470,14 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
self.iactions['Connect Share'].set_smartdevice_action_state()
def start_content_server(self, check_started=True):
from calibre.library.server.main import start_threaded_server
from calibre.library.server import server_config
self.content_server = start_threaded_server(
self.library_view.model().db, server_config().parse())
from calibre.srv.embedded import Server
self.content_server = Server(self.library_broker)
self.content_server.state_callback = Dispatcher(
self.iactions['Connect Share'].content_server_state_changed)
if check_started:
self.content_server.start_failure_callback = \
Dispatcher(self.content_server_start_failed)
self.content_server.start()
def content_server_start_failed(self, msg):
error_dialog(self, _('Failed to start Content server'),

View File

@ -13,6 +13,7 @@ from calibre.srv.handler import Handler
from calibre.srv.http_response import create_http_handler
from calibre.srv.loop import ServerLoop
from calibre.srv.utils import RotatingLog
from calibre.srv.opts import server_config
def log_paths():
@ -26,12 +27,13 @@ class Server(object):
loop = current_thread = exception = None
state_callback = start_failure_callback = None
def __init__(self, opts):
def __init__(self, library_broker):
opts = server_config()
lp, lap = log_paths()
log_size = opts.max_log_size * 1024 * 1024
log = RotatingLog(lp, max_size=log_size)
access_log = RotatingLog(lap, max_size=log_size)
self.handler = Handler(libraries, opts)
self.handler = Handler(library_broker, opts)
plugins = self.plugins = []
if opts.use_bonjour:
plugins.append(BonJour())
@ -70,6 +72,7 @@ class Server(object):
t.start()
def serve_forever(self):
self.exception = None
if self.state_callback is not None:
try:
self.state_callback(True)

View File

@ -27,7 +27,7 @@ class Context(object):
def __init__(self, libraries, opts, testing=False):
self.opts = opts
self.library_broker = LibraryBroker(libraries)
self.library_broker = libraries if isinstance(libraries, LibraryBroker) else LibraryBroker(libraries)
self.testing = testing
self.lock = Lock()
self.user_manager = UserManager(opts.userdb)