示例#1
0
def run_windows_service(config):
    import waitress
    import webbrowser
    from winservice import SysTrayIcon
    ws_server = WebSocketServer(port=5001)
    setup_app(config)
    setup_logging(config)
    setup_task_queue(config)
    setup_signals(ws_server)

    consumer = Consumer(task_queue)

    def on_quit(systray):
        consumer.shutdown()
        ws_server.stop()
        if app.config['mode'] in ('processor', 'full'):
            discovery_listener.stop()

    # Start task consumer
    consumer.start()
    # Start websocket server
    ws_server.start()

    listening_port = config['web']['port'].get(int)
    if app.config['mode'] in ('processor', 'full'):
        discovery_listener = DiscoveryListener(listening_port)
        discovery_listener.start()

    server_thread = Thread(target=waitress.serve, args=(app,),
                           kwargs=dict(port=listening_port, threads=16))
    server_thread.daemon = True
    server_thread.start()

    open_browser = lambda x: webbrowser.open_new_tab("http://127.0.0.1:{0}"
                                                     .format(listening_port))
    menu_options = (('Open in browser', None, open_browser),)

    SysTrayIcon(
        icon=os.path.join(os.path.dirname(sys.argv[0]), 'spreads.ico'),
        hover_text="Spreads Web Service",
        menu_options=menu_options,
        on_quit=on_quit,
        default_menu_index=1,
        on_click=open_browser)
示例#2
0
def run_windows_service(config):
    import waitress
    import webbrowser
    from winservice import SysTrayIcon
    ws_server = WebSocketServer(port=5001)
    setup_app(config)
    setup_logging(config)
    setup_task_queue(config)
    setup_signals(ws_server)

    consumer = Consumer(task_queue)

    def on_quit(systray):
        consumer.shutdown()
        ws_server.stop()
        if app.config['mode'] in ('processor', 'full'):
            discovery_listener.stop()

    # Start task consumer
    consumer.start()
    # Start websocket server
    ws_server.start()

    listening_port = config['web']['port'].get(int)
    if app.config['mode'] in ('processor', 'full'):
        discovery_listener = DiscoveryListener(listening_port)
        discovery_listener.start()

    server_thread = Thread(target=waitress.serve,
                           args=(app, ),
                           kwargs=dict(port=listening_port, threads=16))
    server_thread.daemon = True
    server_thread.start()

    open_browser = lambda x: webbrowser.open_new_tab("http://127.0.0.1:{0}".
                                                     format(listening_port))
    menu_options = (('Open in browser', None, open_browser), )

    SysTrayIcon(icon=os.path.join(os.path.dirname(sys.argv[0]), 'spreads.ico'),
                hover_text="Spreads Web Service",
                menu_options=menu_options,
                on_quit=on_quit,
                default_menu_index=1,
                on_click=open_browser)
示例#3
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()
示例#4
0
def run_server(config):
    ws_server = WebSocketServer(port=5001)
    setup_app(config)
    setup_logging(config)
    setup_signals(ws_server)

    # Initialize huey task queue
    global task_queue
    db_location = os.path.join(config.config_dir(), 'queue.db')
    task_queue = SqliteHuey(location=db_location)
    consumer = Consumer(task_queue)

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

    # Start task consumer
    consumer.start()
    # Start websocket server
    ws_server.start()

    try:
        import waitress
        # NOTE: We spin up this obscene number of threads since we have
        #       some long-polling going on, which will always block
        #       one worker thread.
        waitress.serve(app, port=5000, threads=16)
    finally:
        consumer.shutdown()
        ws_server.stop()
示例#5
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()
示例#6
0
def run_server(config):
    ws_server = WebSocketServer(port=5001)
    setup_app(config)
    setup_logging(config)
    setup_signals(ws_server)

    # Initialize huey task queue
    global task_queue
    db_location = config.cfg_path.parent / 'queue.db'
    task_queue = SqliteHuey(location=unicode(db_location))
    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}:5000".format(ip_address))
        except plugin.DeviceException:
            logger.warn("No devices could be found at startup.")

    # Start task consumer
    consumer.start()
    # Start websocket server
    ws_server.start()

    try:
        import waitress
        # NOTE: We spin up this obscene number of threads since we have
        #       some long-polling going on, which will always block
        #       one worker thread.
        waitress.serve(app, port=5000, threads=16)
    finally:
        consumer.shutdown()
        ws_server.stop()