mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 19:44:15 +02:00
gem selector sketch
This commit is contained in:
33
bauh/core/config.py
Normal file
33
bauh/core/config.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
from bauh import __app_name__
|
||||
from bauh.api.constants import HOME_PATH
|
||||
|
||||
CONFIG_PATH = '{}/.config/{}'.format(HOME_PATH, __app_name__)
|
||||
FILE_PATH = '{}/config.json'.format(CONFIG_PATH)
|
||||
|
||||
|
||||
class Configuration:
|
||||
|
||||
def __init__(self, gems: List[str]):
|
||||
self.gems = gems
|
||||
|
||||
|
||||
def read() -> Configuration:
|
||||
if os.path.exists(FILE_PATH):
|
||||
with open(FILE_PATH) as f:
|
||||
config_file = f.read()
|
||||
|
||||
return Configuration(**json.loads(config_file))
|
||||
|
||||
return Configuration(gems=None)
|
||||
|
||||
|
||||
def save(config: Configuration):
|
||||
Path(CONFIG_PATH).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
with open(FILE_PATH, 'w+') as f:
|
||||
f.write(json.dumps(config.__dict__, indent=2))
|
||||
Reference in New Issue
Block a user