Beispiel #1
0
def test_yaml_dump_load():
    """Test yaml dump/load works."""
    data = OrderedDict({"a": 12, "b": None})
    stream = io.StringIO()
    yaml_dump(data, stream)
    stream.seek(0)
    loaded_data = yaml_load(stream)
    assert loaded_data == data
def sort_configuration_file(config: PackageConfiguration):
    """Sort the order of the fields in the configuration files."""
    # load config file to get ignore patterns, dump again immediately to impose ordering
    assert config.directory is not None
    configuration_filepath = config.directory / config.default_configuration_filename
    if config.package_type == PackageType.AGENT:
        json_data = config.ordered_json
        component_configurations = json_data.pop("component_configurations")
        yaml_dump_all([json_data] + component_configurations,
                      configuration_filepath.open("w"))
    else:
        yaml_dump(config.ordered_json, configuration_filepath.open("w"))
Beispiel #3
0
def nested_set_config(
    dotted_path: str, value: Any, author: str = DEFAULT_AUTHOR
) -> None:
    """
    Set an AEA config with nested values.

    Run from agent's directory.

    Allowed dotted_path:
        'agent.an_attribute_name'
        'protocols.my_protocol.an_attribute_name'
        'connections.my_connection.an_attribute_name'
        'contracts.my_contract.an_attribute_name'
        'skills.my_skill.an_attribute_name'
        'vendor.author.[protocols|connections|skills].package_name.attribute_name

    :param dotted_path: dotted path to a setting.
    :param value: a value to assign. Must be of yaml serializable type.
    :param author: the author name, used to parse the dotted path.

    :return: None.
    """
    settings_keys, config_file_path, config_loader, _ = handle_dotted_path(
        dotted_path, author
    )

    with config_file_path.open() as fp:
        config = config_loader.load(fp)

    _nested_set(config, settings_keys, value)

    if config.package_type == PackageType.AGENT:
        json_data = config.ordered_json
        component_configurations = json_data.pop("component_configurations")
        yaml_dump_all(
            [json_data] + component_configurations, config_file_path.open("w")
        )
    else:
        yaml_dump(config.ordered_json, config_file_path.open("w"))
Beispiel #4
0
 def _dump_component_config(self, configuration: T,
                            file_pointer: TextIO) -> None:
     """Dump component configuration."""
     result = configuration.ordered_json
     self.validate(result)
     yaml_dump(result, file_pointer)