コード例 #1
0
def start_camera_worker(host,
                        port,
                        scripts_base,
                        hostname=None,
                        port_range=None,
                        mode=0,
                        web_server=config.DEFAULT_WEB_SERVER,
                        web_server_args={}):

    if hostname:
        _logger.warning("Using custom hostname '%s'." % hostname)

    config_manager = CameraConfigManager(config_provider=TransientConfig())
    user_scripts_manager = UserScriptsManager(scripts_base)
    camera_instance_manager = CameraInstanceManager(config_manager,
                                                    user_scripts_manager,
                                                    hostname=hostname,
                                                    port_range=port_range,
                                                    mode=mode)

    app = bottle.Bottle()

    register_camera_rest_interface(app=app,
                                   instance_manager=camera_instance_manager)

    try:
        bottle.run(app=app,
                   server=validate_web_server(web_server),
                   host=host,
                   port=port,
                   **web_server_args)
    finally:
        # Close the external processor when terminating the web server.
        camera_instance_manager.stop_all_instances()
コード例 #2
0
def start_pipeline_server(host,
                          port,
                          config_base,
                          background_base,
                          scripts_base,
                          cam_server_api_address,
                          hostname=None,
                          port_range=None,
                          web_server=config.DEFAULT_WEB_SERVER,
                          web_server_args={}):

    # Check if config directory exists
    if not os.path.isdir(config_base):
        _logger.error("Configuration directory '%s' does not exist." %
                      config_base)
        exit(-1)

    if not os.path.isdir(background_base):
        _logger.error("Background image directory '%s' does not exist." %
                      background_base)
        exit(-1)

    if not os.path.isdir(scripts_base):
        _logger.error("Scripts directory '%s' does not exist." % scripts_base)
        exit(-1)

    if hostname:
        _logger.warning("Using custom hostname '%s'." % hostname)

    cam_server_client = CamClient(cam_server_api_address)
    config_manager = PipelineConfigManager(
        config_provider=ConfigFileStorage(config_base))
    background_manager = BackgroundImageManager(background_base)
    user_scripts_manager = UserScriptsManager(scripts_base)
    pipeline_instance_manager = PipelineInstanceManager(config_manager,
                                                        background_manager,
                                                        user_scripts_manager,
                                                        cam_server_client,
                                                        hostname=hostname,
                                                        port_range=port_range)

    app = bottle.Bottle()

    register_pipeline_rest_interface(
        app=app, instance_manager=pipeline_instance_manager)

    try:
        bottle.run(app=app,
                   server=validate_web_server(web_server),
                   host=host,
                   port=port,
                   **web_server_args)
    finally:
        # Close the external processor when terminating the web server.
        pipeline_instance_manager.stop_all_instances()
コード例 #3
0
def start_camera_server(host,
                        port,
                        config_base,
                        scripts_base,
                        hostname=None,
                        port_range=None,
                        mode=0,
                        web_server=config.DEFAULT_WEB_SERVER,
                        web_server_args={}):

    # Check if config directory exists
    if not os.path.isdir(config_base):
        _logger.error("Configuration directory '%s' does not exist." %
                      config_base)
        exit(-1)

    if hostname:
        _logger.warning("Using custom hostname '%s'." % hostname)

    config_manager = CameraConfigManager(
        config_provider=ConfigFileStorage(config_base))
    user_scripts_manager = UserScriptsManager(scripts_base)
    camera_instance_manager = CameraInstanceManager(config_manager,
                                                    user_scripts_manager,
                                                    hostname=hostname,
                                                    port_range=port_range,
                                                    mode=mode)

    app = bottle.Bottle()

    register_camera_rest_interface(app=app,
                                   instance_manager=camera_instance_manager)

    try:
        bottle.run(app=app,
                   server=validate_web_server(web_server),
                   host=host,
                   port=port,
                   **web_server_args)
    finally:
        # Close the external processor when terminating the web server.
        camera_instance_manager.stop_all_instances()
コード例 #4
0
    def test_scripts_manager(self):
        require_folder("user_scripts/")

        scripts_manager = UserScriptsManager("user_scripts/")

        script_name = "Test.py"
        script_content = "print('Hello world')"
        scripts_manager.save_script(script_name, script_content)
        try:
            scripts = scripts_manager.get_scripts()
            self.assertIn(script_name, scripts)

            ret = scripts_manager.get_script(script_name)
            self.assertEqual(ret, script_content)
        finally:
            os.remove(os.path.join(scripts_manager.scripts_folder,
                                   "Test.py"), )
コード例 #5
0
def start_pipeline_manager(host, port, server_config, config_base, background_base, background_files_days_to_live,
                           scripts_base, cam_server_api_address, client_timeout=None, info_update_timeout=None,
                           web_server=config.DEFAULT_WEB_SERVER, web_server_args={}):


    # Check if config directory exists
    if not os.path.isdir(config_base):
        _logger.error("Configuration directory '%s' does not exist." % config_base)
        exit(-1)

    if not os.path.isdir(background_base):
        _logger.error("Background image directory '%s' does not exist." % background_base)
        exit(-1)

    if not os.path.isdir(scripts_base):
        _logger.error("Scripts directory '%s' does not exist." % scripts_base)
        exit(-1)

    cam_server_client = CamClient(cam_server_api_address)
    config_manager = PipelineConfigManager(config_provider=ConfigFileStorage(config_base))
    background_manager = BackgroundImageManager(background_base)
    user_scripts_manager = UserScriptsManager(scripts_base)

    app = bottle.Bottle()

    proxy = PipelineManager(config_manager, background_manager,user_scripts_manager,
                            cam_server_client, server_config, int(background_files_days_to_live),
                            float(client_timeout) if client_timeout else None,
                            float(info_update_timeout) if info_update_timeout else None)
    register_pipeline_rest_interface(app=app, instance_manager=proxy)
    proxy.register_rest_interface(app)
    proxy.register_management_page(app)
    try:
        bottle.run(app=app, server=validate_web_server(web_server), host=host, port=port, **web_server_args)
    finally:
        #cleanup
        pass
コード例 #6
0
def start_camera_manager(host,
                         port,
                         server_config,
                         config_base,
                         scripts_base,
                         client_timeout=None,
                         info_update_timeout=None,
                         web_server=config.DEFAULT_WEB_SERVER,
                         web_server_args={}):
    if not os.path.isdir(config_base):
        _logger.error("Configuration directory '%s' does not exist." %
                      config_base)
        exit(-1)

    config_manager = CameraConfigManager(
        config_provider=ConfigFileStorage(config_base))
    user_scripts_manager = UserScriptsManager(scripts_base)

    app = bottle.Bottle()

    proxy = CameraManager(
        config_manager, user_scripts_manager, server_config,
        float(client_timeout) if client_timeout else None,
        float(info_update_timeout) if info_update_timeout else None)
    register_camera_rest_interface(app=app, instance_manager=proxy)
    proxy.register_rest_interface(app)
    proxy.register_management_page(app)

    try:
        bottle.run(app=app,
                   server=validate_web_server(web_server),
                   host=host,
                   port=port,
                   **web_server_args)
    finally:
        #clenup
        pass