Exemple #1
0
    def save_to_path(self, path):
        """
        Save content to path.

        :param path:    Path (str)
        """
        with io_open(path, mode="w") as handle:
            handle.write(yaml_ordered_dump(self.content))
Exemple #2
0
def test_dump():
    """Test ordered_dump function."""
    content = {
        "one": {
            "two": ["a", "b", "c"],
            "three": 1,
            "four": ["a", "b", "c"]
        },
        "two": ["pouet"],
        "aaa": None,
    }

    dump = yaml_ordered_dump(content)
    assert dump.startswith("aaa: null\n")
Exemple #3
0
def renderer_render_template_inplace(content, environment_data=None):
    """
    Render a Jinja template in-place, using environment data.

    :param content:              Template content (dict)
    :param environment_data:     Environment data (dict?) (default: None)
    :rtype: Template data (str)
    """
    environment_data = environment_data if environment_data else {}
    string_content = yaml_ordered_dump(content)

    template = Template(string_content)
    template_output = template.render(**environment_data)

    return template_output
Exemple #4
0
def env_set_env_value(env_path, key, value):
    """
    Set environment value from file at `env_path`.

    :param env_path:    Environment path (str)
    :param key:         Key (str)
    :param value:       Value (any)
    """
    with io_open(env_path, mode="r") as handle:
        content = yaml_ordered_load(handle)

    if content["environment"] is None:
        content["environment"] = {}
    content["environment"][key] = value

    with io_open(env_path, mode="w") as handle:
        handle.write(yaml_ordered_dump(content))
Exemple #5
0
    def save(self):
        """Save."""
        project_file_path = database_get_database_path(self.project_path)

        with io_open(project_file_path, encoding="utf-8", mode="w") as handle:
            handle.write(yaml_ordered_dump(self.serialize()))
Exemple #6
0
 def save(self):
     """Save session."""
     session_file = self.get_paths().get_user_session_file_path()
     with io_open(session_file, mode="w") as handle:
         handle.write(yaml_ordered_dump(self.session_data))