50 lines
1.0 KiB
Python
50 lines
1.0 KiB
Python
"""Toolbelt settings module.
|
|
|
|
All code related to working with the ~/.autonomic/settings.yml file. This file
|
|
is useful for storing information for future lookup when dealing with
|
|
repetitive cooperative tasks.
|
|
"""
|
|
|
|
from typing import Dict
|
|
|
|
from autonomic.config import CONFIG_YAML
|
|
from autonomic.utils import yaml_dump, yaml_load
|
|
|
|
|
|
def add(yaml: Dict[str, str]):
|
|
"""Add YAML to the settings file."""
|
|
from autonomic.command.init import create_configuration
|
|
|
|
create_configuration()
|
|
settings = yaml_load(CONFIG_YAML)
|
|
|
|
if settings is None:
|
|
settings = {}
|
|
|
|
for key in yaml:
|
|
settings[key] = yaml[key]
|
|
|
|
yaml_dump(CONFIG_YAML, settings)
|
|
|
|
|
|
def remove(key):
|
|
"""Remove key from the settings file."""
|
|
settings = yaml_load(CONFIG_YAML)
|
|
|
|
if settings is None:
|
|
return
|
|
|
|
settings.pop(key, None)
|
|
|
|
yaml_dump(CONFIG_YAML, settings)
|
|
|
|
|
|
def get(key):
|
|
"""Retrieve settings key."""
|
|
settings = yaml_load(CONFIG_YAML)
|
|
|
|
try:
|
|
return settings[key]
|
|
except Exception:
|
|
return None
|