예제 #1
0
def start_record_server(host,
                        port,
                        config_directory,
                        cam_server_api_address,
                        hostname=None):
    if not os.path.isdir(config_directory):
        _logger.error("Configuration directory '%s' does not exist." %
                      config_directory)
        exit(-1)

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

    # TODO: Do something with the hostname.

    app = bottle.Bottle()

    cam_client = CamClient(cam_server_api_address)
    config_manager = CamRecordConfigManager(
        config_provider=ConfigFileStorage(config_directory))

    instance_manager = CamRecordInstanceManager(cam_client=cam_client,
                                                config_manager=config_manager)
    instance_manager.start_all_cameras()

    register_rest_interface(app, instance_manager)

    try:
        bottle.run(app=app, host=host, port=port)
    finally:
        instance_manager.stop_all_cameras()
def start_camera_proxy(host,
                       port,
                       server_config,
                       config_base,
                       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))

    app = bottle.Bottle()

    proxy = CameraProxy(config_manager, server_config)
    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
예제 #3
0
def verify_pipeline_configs(folder, background_folder):
    if not os.path.isdir(background_folder):
        _logger.error("Specified background folder '%s' does not exist.",
                      background_folder)
        background_manager = None
    else:
        background_manager = BackgroundImageManager(background_folder)

    _logger.info("Verifying pipeline configs in folder '%s'.", folder)

    config_manager = PipelineConfigManager(
        config_provider=ConfigFileStorage(folder))

    for pipeline_name in config_manager.get_pipeline_list():
        try:
            pipeline = config_manager.load_pipeline(pipeline_name)

            if background_manager:
                background_manager.get_background(pipeline.get_background_id())

        except:
            _logger.exception("Error while trying to load pipeline '%s'",
                              pipeline_name)

    _logger.info("Pipeline configs verification completed.")
def start_camera_server(host, port, config_base, hostname=None):

    # 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))
    camera_instance_manager = CameraInstanceManager(config_manager,
                                                    hostname=hostname)

    app = bottle.Bottle()

    register_camera_rest_interface(app=app,
                                   instance_manager=camera_instance_manager)

    try:
        bottle.run(app=app, host=host, port=port)
    finally:
        # Close the external processor when terminating the web server.
        camera_instance_manager.stop_all_instances()
예제 #5
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()
def verify_camera_configs(folder):
    _logger.info("Verifying camera configs in folder '%s'.", folder)

    config_manager = CameraConfigManager(config_provider=ConfigFileStorage(folder))

    for camera_name in config_manager.get_camera_list():
        try:
            config_manager.load_camera(camera_name)
        except:
            _logger.exception("Error while trying to load camera '%s'", camera_name)

    _logger.info("Camera configs verification completed.")
 def test_aliases(self):
     aliases = {
         'cam4': 'camera_example_4',
         'camera4': 'simulation4',
         'cam3': 'camera_example_3',
         'c4': 'simulation4',
         'c2': 'simulation2',
         'camera2': 'simulation2',
         'c1': 'simulation',
         'camera1': 'simulation'
     }
     test_base_dir = os.path.split(os.path.abspath(__file__))[0]
     config_base = os.path.join(test_base_dir, "camera_config/")
     config_manager = CameraConfigManager(
         config_provider=ConfigFileStorage(config_base))
     print(config_manager.get_camera_aliases())
     self.assertDictEqual(config_manager.get_camera_aliases(), aliases,
                          "Aliases not as expected")
예제 #8
0
def start_pipeline_proxy(host,
                         port,
                         server_config,
                         config_base,
                         background_base,
                         scripts_base,
                         cam_server_api_address,
                         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)

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

    app = bottle.Bottle()

    proxy = PipelineProxy(config_manager, background_manager,
                          cam_server_client, server_config)
    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:
        #clenup
        pass
    def test_groups(self):
        groups = {
            'Photonics': [
                'camera_example_4', 'camera_example_3', 'simulation4',
                'simulation2'
            ],
            'Test':
            ['camera_example_4', 'simulation4', 'simulation2', 'simulation'],
            'Electrons': ['camera_example_2', 'simulation'],
            '2Pulses': ['simulation4']
        }

        test_base_dir = os.path.split(os.path.abspath(__file__))[0]
        config_base = os.path.join(test_base_dir, "camera_config/")
        config_manager = CameraConfigManager(
            config_provider=ConfigFileStorage(config_base))
        print(config_manager.get_camera_groups())
        self.assertDictEqual(config_manager.get_camera_groups(), groups,
                             "Groups not as expected")
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()
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
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
예제 #13
0
    def setUp(self):
        test_base_dir = os.path.split(os.path.abspath(__file__))[0]
        self.config_folder = os.path.join(test_base_dir, "camera_config/")
        self.file_storage = ConfigFileStorage(config_folder=self.config_folder)

        self.config_to_save_name = "test_config"
예제 #14
0
class ConfigFileStorageTest(unittest.TestCase):
    def setUp(self):
        test_base_dir = os.path.split(os.path.abspath(__file__))[0]
        self.config_folder = os.path.join(test_base_dir, "camera_config/")
        self.file_storage = ConfigFileStorage(config_folder=self.config_folder)

        self.config_to_save_name = "test_config"

    def tearDown(self):
        try:
            self.file_storage.delete_config(self.config_to_save_name)
        except:
            pass

    def test_list_configs(self):
        expected_config_files = set([
            "camera_example_1", "camera_example_2", "camera_example_3",
            "camera_example_4", "simulation", "simulation2"
        ])
        available_configs_1 = self.file_storage.get_available_configs()
        #self.assertSetEqual(set(available_configs_1), expected_config_files,
        #                    "Available configs not as expected.")
        for file in expected_config_files:
            self.assertIn(file, available_configs_1,
                          "Not getting expected config file: " + file)

    def test_get_config(self):
        config_example_1 = self.file_storage.get_config("camera_example_1")

        expected_config_example_1 = {
            "name": "camera_example_1",
            "source": "EPICS_example_1",
            "source_type": "epics",
            "mirror_x": True,
            "mirror_y": True,
            "rotate": 1,
            "camera_calibration": None
        }

        self.assertDictEqual(config_example_1, expected_config_example_1,
                             "Config not as it should be.")

    def test_set_config(self):
        config_to_save = {
            "name": "test_config",
            "source": "test",
            "source_type": "epics",
            "mirror_x": True,
            "mirror_y": False,
            "rotate": 4
        }

        self.file_storage.save_config(self.config_to_save_name, config_to_save)
        stored_config = self.file_storage.get_config(self.config_to_save_name)

        self.assertDictEqual(stored_config, config_to_save,
                             "Saved and stored configs do not match.")

        config_to_modify_and_save = {
            "name": "invalid_name",
            "source": "test",
            "source_type": "epics",
            "mirror_x": True,
            "mirror_y": False,
            "rotate": 4
        }

        self.file_storage.save_config(self.config_to_save_name,
                                      config_to_modify_and_save)
        stored_config = self.file_storage.get_config(self.config_to_save_name)

        self.assertEqual(stored_config["name"], self.config_to_save_name,
                         "Config name not modified as expected.")

    def test_delete_config(self):
        config_to_save = {
            "name": "test_config",
            "source": "test",
            "source_type": "epics",
            "mirror_x": True,
            "mirror_y": False,
            "rotate": 4
        }

        self.file_storage.save_config(self.config_to_save_name, config_to_save)

        self.assertTrue(
            self.config_to_save_name
            in self.file_storage.get_available_configs(),
            "New config not present in available configs.")

        self.file_storage.delete_config(self.config_to_save_name)

        self.assertFalse(
            self.config_to_save_name
            in self.file_storage.get_available_configs(),
            "New config was not deleted.")
예제 #15
0
def get_config(path, name):
    from cam_server.instance_management.configuration import ConfigFileStorage
    cfg = ConfigFileStorage(path)
    return cfg.get_config(name)