Exemple #1
0
def force_set_config(dotted_path: str, value: Any) -> None:
    """
    Set an AEA config without validation.

    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.

    :return: None.
    """
    settings_keys, file_path, _ = handle_dotted_path(dotted_path)

    settings = {}
    with open(file_path, "r") as f:
        settings = yaml.safe_load(f)

    _nested_set(settings, settings_keys, value)

    with open(file_path, "w") as f:
        yaml.dump(settings, f, default_flow_style=False)
Exemple #2
0
 def _handle_dotted_path(
     self, ) -> Tuple[List[str], Path, ConfigLoader, Optional[ComponentId]]:
     """Handle dotted path."""
     try:
         return handle_dotted_path(self.dotted_path,
                                   self.agent_config.author)
     except AEAException as e:
         raise click.ClickException(*e.args)
Exemple #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"))
Exemple #4
0
    def convert(self, value, param, ctx):
        """Separate the path between path to resource and json path to attribute.

        Allowed values:
            '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
        """
        try:
            (
                json_path,
                path_to_resource_configuration,
                config_loader,
            ) = handle_dotted_path(value)
        except AEAException as e:
            self.fail(str(e))
        else:
            ctx.obj.set_config("configuration_file_path",
                               path_to_resource_configuration)
            ctx.obj.set_config("configuration_loader", config_loader)
            return json_path