File size: 1,495 Bytes
03d9a71 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
import json
import os
from pathlib import Path
from scripts.lib.lobe_log import LobeLog
EXTENSION_FOLDER = Path(__file__).parent.parent.parent
CONFIG_FILENAME = Path(EXTENSION_FOLDER, "lobe_theme_config.json")
LobeLog.debug(f"EXTENSION_FOLDER: {EXTENSION_FOLDER}")
LobeLog.debug(f"CONFIG_FILENAME: {CONFIG_FILENAME}")
class LobeConfig:
def __init__(self):
self.config_file = CONFIG_FILENAME
self.config = None
self.load_config()
def load_config(self):
if os.path.exists(self.config_file):
LobeLog.debug(f"Loading config from {self.config_file}")
with open(self.config_file, 'r') as f:
self.config = json.load(f)
else:
LobeLog.debug(f"Config file not found")
self.config = LobeConfig.default()
def is_empty(self):
return "empty" in self.config and self.config['empty']
def json(self):
return json.dumps(self.config)
def delete(self):
if os.path.exists(self.config_file):
os.remove(self.config_file)
self.config = LobeConfig.default()
return True
return False
def save(self, settings):
self.config = settings
with open(self.config_file, 'w') as f:
f.write(json.dumps(self.config, indent=2))
f.close()
@staticmethod
def default():
# default config is handled from client side @see src/store/index.tsx
return {'empty': True}
|