示例#1
0
def _configure(env_work_dir=None):
    """Load configuration settings.

    :returns config dict if configuration was loaded without issues.
            None or a specific exception otherwise.
    """
    assert env_work_dir, 'Working directory required.'
    assert os.path.exists(env_work_dir), \
        'working directory invalid: {}'.format(env_work_dir)

    config_manager.stop()

    def logging_config_handler(config):
        # configure logging
        logging_config = None
        if config:
            logging_config = config.get('logging', None)
        _configure_logging(logging_config)

    config_manager.register_handler(logging_config_handler)

    def timeline_config_handler(config):
        # configure pipeline timeline event log
        timeline_config = None
        if config:
            timeline_config = config.get('timeline', None)
        timeline.configure_timeline(timeline_config)

    config_manager.register_handler(timeline_config_handler)

    config_manager.load(env_work_dir)

    return config_manager.get()
示例#2
0
def test_config_getters():

    config_manager.stop()
    config_manager.CONFIG_FILE = 'test-config2.yaml'
    _dir = os.path.dirname(os.path.abspath(__file__))
    config_manager.load(_dir)

    assert config_manager.get_ai_models() is not None
    assert config_manager.get_ai_model("image_detection") is not None

    assert config_manager.get_sources() is not None
    assert config_manager.get_source("front_door_camera") is not None

    assert config_manager.get_data_dir() is not None
示例#3
0
def test_reload():

    config_manager.CONFIG_FILE = 'test-config.1.yaml'
    _dir = os.path.dirname(os.path.abspath(__file__))
    config = {"logging": {"level": "INFO"}}
    config_file = os.path.join(_dir, config_manager.CONFIG_FILE)

    # write 1
    write_config(config_file, config)

    config1 = config_manager.load(_dir)

    assert config["logging"]["level"] == config1["logging"]["level"]

    watcher = Watch()

    config_manager.register_handler(watcher.on_change)

    config2 = {"logging": {"level": "WARN"}}

    # write 2
    config_manager.save(config2)

    # wait for polling to happen
    wait = 3
    while not watcher.changed:
        sleep(.5)
        wait -= 1
        if wait == 0:
            raise Exception("Failed to detect change")

    config3 = config_manager.get()

    assert config["logging"]["level"] == watcher.config["logging"]["level"]
    assert config["logging"]["level"] == config3["logging"]["level"]
def get_test_config():
    config_manager.stop()
    config_manager.CONFIG_FILE = 'test-sources.yaml'
    _dir = os.path.dirname(os.path.abspath(__file__))
    config = config_manager.load(_dir)
    assert config is not None
    return config
示例#5
0
def test_callback():

    config_manager.CONFIG_FILE = 'test-config.2.yaml'
    _dir = os.path.dirname(os.path.abspath(__file__))
    config = {"test": True}
    config_file = os.path.join(_dir, config_manager.CONFIG_FILE)

    write_config(config_file, config)
    config_manager.load(_dir)

    watcher = Watch()

    config_manager.register_handler(watcher.on_change)
    write_config(config_file, config)

    # wait for polling to happen
    wait = 3
    while not watcher.changed:
        sleep(.5)
        wait -= 1
        if wait == 0:
            raise Exception("Failed to detect change")

    assert watcher.changed
示例#6
0
def _configure(env_work_dir=None):
    """Load configuration settings.

    :returns config dict if configuration was loaded without issues.
            None or a specific exception otherwise.
    """
    assert env_work_dir, 'Working directory required.'
    assert os.path.exists(env_work_dir), \
        'working directory invalid: {}'.format(env_work_dir)

    config_manager.stop()

    config = config_manager.load(env_work_dir)
    if config is None:
        return None

    def logging_config_handler(event: ConfigChangedEvent):
        # configure logging
        log.info("Reconfiguring logging")
        _configure_logging(config.get("logging"))

    def timeline_config_handler(event: ConfigChangedEvent):
        # configure pipeline timeline event log
        log.info("Reconfiguring pipeline timeline event log")
        timeline.configure_timeline(config.get("timeline"))

    # set callback to react to specific configuration changes
    if config.get("logging", None) is not None:
        config.get("logging").add_callback(logging_config_handler)

    if config.get("timeline", None) is not None:
        config.get("timeline").add_callback(timeline_config_handler)

    # initialize logging
    logging_config_handler(None)
    timeline_config_handler(None)

    return config
示例#7
0
def test_clean_stop():
    config_manager.CONFIG_FILE = 'test-config.yaml'
    _dir = os.path.dirname(os.path.abspath(__file__))
    config_manager.load(_dir)
    config_manager.stop()
    assert config_manager.watch_thread is None