コード例 #1
0
ファイル: app.py プロジェクト: DIYBookScanner/spreads
    def run_server(self):
        """ Run the web application. """
        self.setup_logging()
        self.setup_task_queue()
        self.setup_signals()
        self.setup_tornado()

        self._listening_port = self.config['port'].get(int)

        self._ip_address = get_ip_address()
        try:
            device_driver = plugin.get_driver(self.global_config['driver']
                                              .get())
            should_display_ip = (app.config['standalone'] and
                                 self._ip_address and
                                 plugin.DeviceFeatures.CAN_DISPLAY_TEXT in
                                 device_driver.features)
        except ConfigError:
            if self.config['mode'] not in ('scanner', 'full'):
                should_display_ip = False
            raise ConfigError(
                "You need to specify a value for `driver`.\n"
                "Either run `spread [gui]configure` or edit the configuration "
                "file.")

        if should_display_ip:
            # Every 30 seconds, see if there are devices attached and display
            # IP address and port on them, then disable the callback
            self._display_callback = PeriodicCallback(
                self.display_ip, 30*10**3)
            # Run once immediately
            self.display_ip()

        # Start task consumer
        self.consumer.start()

        # Start discovery listener
        if app.config['mode'] in ('processor', 'full'):
            discovery_listener = DiscoveryListener(self._listening_port)
            discovery_listener.start()

        # Spin up WSGI server
        self.application.listen(self._listening_port)

        try:
            IOLoop.instance().start()
        finally:
            # Shut everything down that is still running in the background
            self.consumer.shutdown()
            if app.config['mode'] in ('processor', 'full'):
                discovery_listener.stop()
コード例 #2
0
ファイル: app.py プロジェクト: labexp/spreads
    def run_server(self):
        """ Run the web application. """
        self.setup_logging()
        self.setup_task_queue()
        self.setup_signals()
        self.setup_tornado()

        self._listening_port = self.config['port'].get(int)

        self._ip_address = get_ip_address()
        try:
            device_driver = plugin.get_driver(self.global_config['driver']
                                              .get())
            should_display_ip = (app.config['standalone'] and self._ip_address
                                 and plugin.DeviceFeatures.CAN_DISPLAY_TEXT in
                                 device_driver.features)
        except ConfigError:
            if self.config['mode'] not in ('scanner', 'full'):
                should_display_ip = False
            raise ConfigError(
                "You need to specify a value for `driver`.\n"
                "Either run `spread [gui]configure` or edit the configuration "
                "file.")

        if should_display_ip:
            # Every 30 seconds, see if there are devices attached and display
            # IP address and port on them, then disable the callback
            self._display_callback = PeriodicCallback(
                self.display_ip, 30*10**3)
            # Run once immediately
            self.display_ip()

        # Start task consumer
        self.consumer.start()

        # Start discovery listener
        if app.config['mode'] in ('processor', 'full'):
            discovery_listener = DiscoveryListener(self._listening_port)
            discovery_listener.start()

        # Spin up WSGI server
        self.application.listen(self._listening_port)

        try:
            IOLoop.instance().start()
        finally:
            # Shut everything down that is still running in the background
            self.consumer.shutdown()
            if app.config['mode'] in ('processor', 'full'):
                discovery_listener.stop()
コード例 #3
0
ファイル: __init__.py プロジェクト: jamescr/spreads
def run_server(config):
    listening_port = config['web']['port'].get(int)
    ws_server = WebSocketServer(port=listening_port+1)
    setup_app(config)
    setup_logging(config)
    setup_task_queue(config)
    setup_signals(ws_server)

    consumer = Consumer(task_queue)

    ip_address = get_ip_address()
    if (app.config['standalone'] and ip_address
            and config['driver'].get() == 'chdkcamera'):
        # Display the address of the web interface on the camera displays
        try:
            for cam in plugin.get_devices(config):
                cam.show_textbox(
                    "\n    You can now access the web interface at:"
                    "\n\n\n         http://{0}:{1}"
                    .format(ip_address, listening_port))
        except plugin.DeviceException:
            logger.warn("No devices could be found at startup.")

    # Start task consumer
    consumer.start()
    # Start websocket server
    ws_server.start()
    if app.config['mode'] in ('processor', 'full'):
        discovery_listener = DiscoveryListener(listening_port)
        discovery_listener.start()

    try:
        import waitress
        waitress.serve(app, port=listening_port)
    finally:
        consumer.shutdown()
        ws_server.stop()
        if app.config['mode'] in ('processor', 'full'):
            discovery_listener.stop()
コード例 #4
0
def run_server(config):
    listening_port = config['web']['port'].get(int)
    ws_server = WebSocketServer(port=listening_port + 1)
    setup_app(config)
    setup_logging(config)
    setup_task_queue(config)
    setup_signals(ws_server)

    consumer = Consumer(task_queue)

    ip_address = get_ip_address()
    if (app.config['standalone'] and ip_address
            and config['driver'].get() == 'chdkcamera'):
        # Display the address of the web interface on the camera displays
        try:
            for cam in plugin.get_devices(config):
                cam.show_textbox(
                    "\n    You can now access the web interface at:"
                    "\n\n\n         http://{0}:{1}".format(
                        ip_address, listening_port))
        except plugin.DeviceException:
            logger.warn("No devices could be found at startup.")

    # Start task consumer
    consumer.start()
    # Start websocket server
    ws_server.start()
    if app.config['mode'] in ('processor', 'full'):
        discovery_listener = DiscoveryListener(listening_port)
        discovery_listener.start()

    try:
        import waitress
        waitress.serve(app, port=listening_port)
    finally:
        consumer.shutdown()
        ws_server.stop()
        if app.config['mode'] in ('processor', 'full'):
            discovery_listener.stop()