mirror of
https://github.com/subutux/rmapy.git
synced 2025-12-10 15:35:34 +00:00
initial commit
This commit is contained in:
32
rmapi/config.py
Normal file
32
rmapi/config.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from pathlib import Path
|
||||
from yaml import load as yml_load
|
||||
from yaml import dump as yml_dump
|
||||
|
||||
|
||||
def load() -> dict:
|
||||
"""
|
||||
Load the .rmapi config file
|
||||
"""
|
||||
|
||||
config_file_path = Path.joinpath(Path.home(), ".rmapi")
|
||||
config = {}
|
||||
if Path.exists(config_file_path):
|
||||
with open(config_file_path, 'r') as config_file:
|
||||
config = dict(yml_load(config_file.read()))
|
||||
|
||||
return config
|
||||
|
||||
|
||||
def dump(config: dict) -> True:
|
||||
"""
|
||||
Dump config to the .rmapi config file
|
||||
"""
|
||||
|
||||
config_file_path = Path.joinpath(Path.home(), ".rmapi")
|
||||
|
||||
with open(config_file_path, 'w') as config_file:
|
||||
config_file.write(yml_dump(config))
|
||||
|
||||
return True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user