1
Fork 0
This commit is contained in:
Jake Howard 2015-12-03 22:43:42 +00:00
parent a083894c57
commit f3dfedeb2a
2 changed files with 6 additions and 2 deletions

View file

@ -22,7 +22,7 @@ def set(key, value):
key = " ".join(key) key = " ".join(key)
status = config.set(key, value) status = config.set(key, value)
if status == "SUCCESS": if status == "SUCCESS":
print("Repo set to", repo) print("{} set to {}".format(key, value))
return 0 return 0
elif status == "NO_KEY": elif status == "NO_KEY":
print("Key {} not found".format(key)) print("Key {} not found".format(key))

View file

@ -11,6 +11,7 @@ BASE_DIR = os.path.dirname(os.path.abspath(__file__))
USER_CONFIG_DIR = os.path.expanduser("~/.dfa.yml") USER_CONFIG_DIR = os.path.expanduser("~/.dfa.yml")
DEFAULT_CONFIG_DIR = os.path.join(BASE_DIR, 'defaults.yml') DEFAULT_CONFIG_DIR = os.path.join(BASE_DIR, 'defaults.yml')
def get_config_data(filename): def get_config_data(filename):
try: try:
with open(filename) as config_file: with open(filename) as config_file:
@ -18,16 +19,18 @@ def get_config_data(filename):
except FileNotFoundError: except FileNotFoundError:
return {} return {}
def write_user_config(refresh_after=False): def write_user_config(refresh_after=False):
try: try:
with open(USER_CONFIG_DIR, 'w') as config_file: with open(USER_CONFIG_DIR, 'w') as config_file:
dump(USER_CONFIG, config_file, indent=4, default_flow_style=False) dump(USER_CONFIG, config_file, indent=4, default_flow_style=False, Dumper=Dumper)
return "SUCCESS" return "SUCCESS"
except Exception as e: except Exception as e:
return e return e
DEFAULT_CONFIG = get_config_data(DEFAULT_CONFIG_DIR) DEFAULT_CONFIG = get_config_data(DEFAULT_CONFIG_DIR)
USER_CONFIG = get_config_data(os.path.expanduser(USER_CONFIG_DIR)) USER_CONFIG = get_config_data(os.path.expanduser(USER_CONFIG_DIR))
@ -38,6 +41,7 @@ def get(key):
return DEFAULT_CONFIG[key] return DEFAULT_CONFIG[key]
return None return None
def set(key, value, refresh_after=False): def set(key, value, refresh_after=False):
if key not in DEFAULT_CONFIG: if key not in DEFAULT_CONFIG:
return "NO_KEY" return "NO_KEY"