Files
icon-color-tool/config.py
T
2026-08-03 16:52:16 -04:00

46 lines
1.5 KiB
Python

import os
import sys
import subprocess
from pathlib import Path
import tomllib
def get_config_dir():
xdg_config = os.environ.get('XDG_CONFIG_HOME', os.path.expanduser('~/.config'))
return Path(xdg_config) / 'svg-color-tool'
def generate_default_config(config_path: Path):
default_path = os.path.expanduser("~/.local/share/breeze-icons")
config_content = f"""[settings]
breeze_path = "{default_path}"
"""
config_path.parent.mkdir(parents=True, exist_ok=True)
with open(config_path, "w") as f:
f.write(config_content)
def ensure_breeze_repo(breeze_path: str):
path = Path(breeze_path)
if not path.exists() or not any(path.iterdir()):
print(f"Breeze icons not found at {path}. Cloning repository...")
path.mkdir(parents=True, exist_ok=True)
subprocess.run(["git", "clone", "--depth", "1", "https://github.com/KDE/breeze-icons.git", str(path)], check=True)
def load_config():
env_path = os.environ.get('BREEZE_ICONS_PATH')
if env_path:
ensure_breeze_repo(env_path)
return env_path
config_dir = get_config_dir()
config_file = config_dir / 'config.toml'
if not config_file.exists():
generate_default_config(config_file)
with open(config_file, "rb") as f:
config_data = tomllib.load(f)
breeze_path = config_data.get('settings', {}).get('breeze_path', os.path.expanduser("~/.local/share/breeze-icons"))
breeze_path = os.path.expanduser(breeze_path)
ensure_breeze_repo(breeze_path)
return breeze_path