Added file explorer
This commit is contained in:
@@ -1 +1,2 @@
|
||||
from .settings import Config
|
||||
from .paths import PathsConfig
|
||||
|
||||
@@ -13,3 +13,10 @@ class ConfigModel:
|
||||
out_micro: str
|
||||
restream: bool
|
||||
direct_stream: bool
|
||||
|
||||
|
||||
@dataclass_json
|
||||
@dataclass(frozen=True)
|
||||
class PathsModel:
|
||||
first_browser_path: str
|
||||
second_browser_path: str
|
||||
|
||||
43
modules/config/paths.py
Normal file
43
modules/config/paths.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from modules.config.model import PathsModel
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
class PathsConfig:
|
||||
@staticmethod
|
||||
def default():
|
||||
return {
|
||||
"first_browser_path": "",
|
||||
"second_browser_path": ""
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def fix() -> None:
|
||||
try:
|
||||
with open("data/config.path", "w") as file:
|
||||
json.dump(PathsConfig.default(), file)
|
||||
except FileNotFoundError:
|
||||
if not os.path.exists('data'):
|
||||
os.mkdir('data')
|
||||
PathsConfig.fix()
|
||||
|
||||
@staticmethod
|
||||
def get() -> PathsModel:
|
||||
try:
|
||||
with open("data/config.path", "r") as file:
|
||||
return PathsModel.from_dict(json.load(file))
|
||||
except:
|
||||
PathsConfig.fix()
|
||||
return PathsConfig.get()
|
||||
|
||||
@staticmethod
|
||||
def update(key: str, value: str | None) -> dict:
|
||||
with open("data/config.path", "r") as file:
|
||||
settings = json.load(file)
|
||||
|
||||
settings[key] = value
|
||||
|
||||
with open("data/config.path", "w") as file:
|
||||
json.dump(settings, file)
|
||||
|
||||
return settings
|
||||
Reference in New Issue
Block a user