-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpix_config.py
More file actions
50 lines (40 loc) · 1.3 KB
/
Copy pathpix_config.py
File metadata and controls
50 lines (40 loc) · 1.3 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
modules/pix_config.py
Gerenciador de configurações do PixieCat.
Created by psyhusk
"""
import json
from pathlib import Path
CONFIG_DIR = Path.home() / ".pixiecat"
CONFIG_FILE = CONFIG_DIR / "config.json"
DEFAULTS = {
"tema": "violeta",
"salvar_historico": True,
"dir_relatorios": str(Path.home() / "Documentos"),
"version": "1.0.0",
"author": "psyhusk",
}
class PixConfig:
"""Carrega e salva configurações do PixieCat em ~/.pixiecat/config.json."""
def __init__(self):
CONFIG_DIR.mkdir(parents=True, exist_ok=True)
self._cfg = self._load()
def _load(self) -> dict:
if CONFIG_FILE.exists():
try:
data = json.loads(CONFIG_FILE.read_text(encoding="utf-8"))
return {**DEFAULTS, **data}
except Exception:
pass
self._save(DEFAULTS)
return dict(DEFAULTS)
def _save(self, cfg: dict):
CONFIG_FILE.write_text(json.dumps(cfg, indent=2, ensure_ascii=False),
encoding="utf-8")
def get(self, key: str, default=None):
return self._cfg.get(key, default)
def set(self, key: str, value):
self._cfg[key] = value
self._save(self._cfg)