1
Fork 0
This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
dotfile-automator/project/utils.py

33 lines
740 B
Python

import os
from yaml import load
try:
from yaml import CLoader as Loader
except ImportError:
from yaml import Loader
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
USER_CONFIG_DIR = "~/.dfa.yml"
def get_config_data(filename):
try:
config_file = open(filename)
return load(config_file, Loader=Loader)
except FileNotFoundError:
return []
DEFAULT_CONFIG = get_config_data(os.path.join(BASE_DIR, 'config', 'defaults.yml'))
USER_CONFIG = get_config_data(os.path.expanduser(USER_CONFIG_DIR))
def get_config(key):
if USER_CONFIG and key in USER_CONFIG:
return USER_CONFIG[key]
elif DEFAULT_CONFIG and key in DEFAULT_CONFIG:
return DEFAULT_CONFIG[key]
return None