38 lines
1 KiB
Python
Executable file
38 lines
1 KiB
Python
Executable file
import json
|
|
import logging
|
|
import os
|
|
|
|
|
|
def setup_gui_directory(gui_cache_home, gui_config_home, gui_config_file):
|
|
os.makedirs(gui_cache_home, exist_ok=True)
|
|
os.makedirs(gui_config_home, exist_ok=True)
|
|
|
|
if not os.path.exists(gui_config_file):
|
|
default_config = {
|
|
"logging": {
|
|
"gui_logging_enabled": False,
|
|
"log_level": "INFO"
|
|
}
|
|
}
|
|
with open(gui_config_file, 'w') as f:
|
|
json.dump(default_config, f, indent=4)
|
|
|
|
|
|
def load_gui_config(gui_config_file):
|
|
try:
|
|
with open(gui_config_file, 'r') as f:
|
|
return json.load(f)
|
|
except FileNotFoundError:
|
|
return None
|
|
except json.JSONDecodeError:
|
|
logging.error("Invalid GUI config file format")
|
|
return None
|
|
|
|
|
|
def save_gui_config(gui_config_file, config):
|
|
with open(gui_config_file, 'w') as f:
|
|
json.dump(config, f, indent=4)
|
|
|
|
|
|
def default_gui_config():
|
|
return {"logging": {"gui_logging_enabled": False, "log_level": "INFO"}}
|