Example #1
0
 def __init__(self, libraries, opts):
     log = access_log = None
     log_size = opts.max_log_size * 1024 * 1024
     if opts.log:
         log = RotatingLog(opts.log, max_size=log_size)
     if opts.access_log:
         access_log = RotatingLog(opts.access_log, max_size=log_size)
     self.handler = Handler(libraries, opts)
     if opts.custom_list_template:
         with lopen(os.path.expanduser(opts.custom_list_template), 'rb') as f:
             self.handler.router.ctx.custom_list_template = json.load(f)
     if opts.search_the_net_urls:
         with lopen(os.path.expanduser(opts.search_the_net_urls), 'rb') as f:
             self.handler.router.ctx.search_the_net_urls = json.load(f)
     plugins = []
     if opts.use_bonjour:
         plugins.append(BonJour(wait_for_stop=max(0, opts.shutdown_timeout - 0.2)))
     self.loop = ServerLoop(
         create_http_handler(self.handler.dispatch),
         opts=opts,
         log=log,
         access_log=access_log,
         plugins=plugins)
     self.handler.set_log(self.loop.log)
     self.handler.set_jobs_manager(self.loop.jobs_manager)
     self.serve_forever = self.loop.serve_forever
     self.stop = self.loop.stop
     if is_running_from_develop:
         from calibre.utils.rapydscript import compile_srv
         compile_srv()
Example #2
0
 def __init__(self, libraries, opts):
     log = None
     if opts.log:
         log = RotatingLog(opts.log, max_size=opts.max_log_size)
     self.handler = Handler(libraries, opts)
     plugins = []
     if opts.use_bonjour:
         plugins.append(BonJour())
     self.loop = ServerLoop(create_http_handler(self.handler.dispatch), opts=opts, log=log, plugins=plugins)
     self.handler.set_log(self.loop.log)
     self.serve_forever = self.loop.serve_forever
     self.stop = self.loop.stop
Example #3
0
    def test_bonjour(self):
        'Test advertising via BonJour'
        from calibre.srv.bonjour import BonJour
        from zeroconf import Zeroconf
        b = BonJour(wait_for_stop=False)
        with TestServer(lambda data:(data.path[0] + data.read()), plugins=(b,), shutdown_timeout=5) as server:
            self.assertTrue(b.started.wait(5), 'BonJour not started')
            self.ae(b.advertised_port, server.address[1])
            service = b.services[0]
            self.ae(service.type, '_calibre._tcp.local.')
            r = Zeroconf()
            info = r.get_service_info(service.type, service.name)
            self.assertIsNotNone(info)
            self.ae(info.text, b'\npath=/opds')

        self.assertTrue(b.stopped.wait(5), 'BonJour not stopped')
Example #4
0
 def __init__(self, library_broker, notify_changes):
     opts = server_config()
     lp, lap = log_paths()
     try:
         os.makedirs(cache_dir())
     except EnvironmentError as err:
         if err.errno != errno.EEXIST:
             raise
     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(library_broker, opts, notify_changes=notify_changes)
     plugins = self.plugins = []
     if opts.use_bonjour:
         plugins.append(BonJour())
     self.opts = opts
     self.log, self.access_log = log, access_log
     self.handler.set_log(self.log)
Example #5
0
 def __init__(self, libraries, opts):
     log = None
     if opts.log:
         log = RotatingLog(opts.log, max_size=opts.max_log_size)
     self.handler = Handler(libraries, opts)
     plugins = []
     if opts.use_bonjour:
         plugins.append(BonJour())
     self.loop = ServerLoop(create_http_handler(self.handler.dispatch),
                            opts=opts,
                            log=log,
                            plugins=plugins)
     self.handler.set_log(self.loop.log)
     self.serve_forever = self.loop.serve_forever
     self.stop = self.loop.stop
     _df = os.environ.get('CALIBRE_DEVELOP_FROM', None)
     if _df and os.path.exists(_df):
         from calibre.utils.rapydscript import compile_srv
         compile_srv()
Example #6
0
 def __init__(self, library_broker, notify_changes):
     opts = server_config()
     lp, lap = log_paths()
     try:
         os.makedirs(cache_dir())
     except OSError as err:
         if err.errno != errno.EEXIST:
             raise
     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(library_broker, opts, notify_changes=notify_changes)
     plugins = self.plugins = []
     if opts.use_bonjour:
         plugins.append(BonJour(wait_for_stop=max(0, opts.shutdown_timeout - 0.2)))
     self.opts = opts
     self.log, self.access_log = log, access_log
     self.handler.set_log(self.log)
     self.handler.router.ctx.custom_list_template = custom_list_template()
     self.handler.router.ctx.search_the_net_urls = search_the_net_urls()
Example #7
0
 def __init__(self, libraries, opts):
     log = access_log = None
     log_size = opts.max_log_size * 1024 * 1024
     if opts.log:
         log = RotatingLog(opts.log, max_size=log_size)
     if opts.access_log:
         access_log = RotatingLog(opts.access_log, max_size=log_size)
     self.handler = Handler(libraries, opts)
     plugins = []
     if opts.use_bonjour:
         plugins.append(BonJour())
     self.loop = ServerLoop(create_http_handler(self.handler.dispatch),
                            opts=opts,
                            log=log,
                            access_log=access_log,
                            plugins=plugins)
     self.handler.set_log(self.loop.log)
     self.handler.set_jobs_manager(self.loop.jobs_manager)
     self.serve_forever = self.loop.serve_forever
     self.stop = self.loop.stop
     if is_running_from_develop:
         from calibre.utils.rapydscript import compile_srv
         compile_srv()
Example #8
0
 def __init__(self, library_broker, notify_changes):
     opts = server_config()
     lp, lap = log_paths()
     try:
         os.makedirs(cache_dir())
     except EnvironmentError as err:
         if err.errno != errno.EEXIST:
             raise
     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(library_broker,
                            opts,
                            notify_changes=notify_changes)
     plugins = self.plugins = []
     if opts.use_bonjour:
         plugins.append(BonJour())
     self.opts = opts
     self.log, self.access_log = log, access_log
     self.handler.set_log(self.log)
     _df = os.environ.get('CALIBRE_DEVELOP_FROM', None)
     if _df and os.path.exists(_df):
         from calibre.utils.rapydscript import compile_srv
         compile_srv()