Example #1
0
def create_config(rundate, pipeline, session):
    """Create the configuration of a Where analysis

    """
    # Create a new configuration and copy all and pipeline sections
    cfg_path = _config_path(rundate, pipeline, session)
    cfg = mg_config.Configuration(pipeline)
    cfg.update_from_config_section(config.where.all, section=pipeline)
    cfg.update_from_config_section(config.where[pipeline], section=pipeline)
    cfg.write_to_file(cfg_path, metadata=False)

    # Update configuration settings from library
    for section in read_from_library(rundate, pipeline, session):
        cfg.update_from_config_section(section, section.name)

    # Write updated configuration to file
    cfg.write_to_file(cfg_path, metadata=False)
    log.info(
        f"Creating new configuration at '{cfg_path}' based on {', '.join(cfg.sources)}"
    )

    # Add new dependent sections from newly created config
    add_sections(rundate, pipeline, session)

    # Add timestamp and creation note
    add_timestamp(rundate, pipeline, session, "created")
Example #2
0
def config_file():
    """A test configuration read from file"""
    cfg = config.Configuration("file")
    cfg_path = pathlib.Path(__file__).parent / "test_config.conf"
    cfg.update_from_file(cfg_path)
    cfg_vars = dict(var_1="one", var_2="two")
    cfg.update_vars(cfg_vars)
    return cfg
Example #3
0
def config_options():
    """A test configuration based on (mocked) command line options"""
    cfg = config.Configuration("options")
    cfg_argv = [
        sys.argv[0],
        "not_an_option",
        "--section_1:foo=bar",
        "--section_1:pi=3.14",
        "--section_2:foo=baz",
        "--just_a_flag",
        "--non_existing_config:section_1:foo=none",
        "--options:section_3:name=options",
        "--section_1:pi=3.1415",
    ]
    remember_sys_argv, sys.argv = sys.argv, cfg_argv
    cfg.update_from_options(allow_new=True)
    sys.argv = remember_sys_argv
    return cfg
Example #4
0
def store_config_to_library(rundate, pipeline, session):
    cfg = _read_config(rundate, pipeline, session)
    if not cfg.write_to_library.bool:
        return

    file_vars = config.create_file_vars(rundate, pipeline, session)
    lib_path = files.path("config_library", file_vars=file_vars)
    lib_cfg = mg_config.Configuration("library")

    for section in cfg.sections:
        for key, entry in section.items(
        ):  # Todo: Make ConfigurationSection iterable
            if "library" in entry.meta or "library" in config.where.get(
                    key, section=section.name, default="").meta:
                lib_cfg.update(section.name,
                               key,
                               entry.str,
                               source=entry.source)
                # Todo: Only store entries different from default (issue: profiles?)

    lib_cfg.write_to_file(lib_path)
Example #5
0
def config_dict(gps_dict):
    """A test configuration based on a dictionary"""
    cfg = config.Configuration("dictionary")
    cfg.update_from_dict(gps_dict, section="gps")
    return cfg