This repository has been archived on 2020-06-17. You can view files and clone it, but cannot push or open issues or pull requests.
autonomic/autonomic/settings.py

33 lines
714 B
Python
Raw Normal View History

2020-04-11 19:10:29 +00:00
"""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 autonomic.config import CONFIG_YAML
from autonomic.utils import yaml_dump, yaml_load
def add(data):
"""Add values to the settings file."""
settings = yaml_load(CONFIG_YAML)
if settings is None:
settings = {}
for key in data:
settings[key] = data[key]
yaml_dump(CONFIG_YAML, settings)
def get(key):
"""Retrieve setting values."""
settings = yaml_load(CONFIG_YAML)
try:
return settings[key]
except Exception:
return None