Initial commit
This commit is contained in:
32
ackit/settings.py
Normal file
32
ackit/settings.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""Small JSON settings file shared by the CLI and the editor (user config folder)."""
|
||||
import json
|
||||
import os
|
||||
|
||||
from .paths import user_dir
|
||||
|
||||
DEFAULTS = {"game_dir": None, "store_root": None, "full_backup": True, "language": None,
|
||||
"input_device": None, "output_device": None, "last_dir": None,
|
||||
"background_enabled": True, "background_opacity": 0.1}
|
||||
OBSOLETE = ("theme", "background_image")
|
||||
|
||||
|
||||
def path():
|
||||
return os.path.join(user_dir("config"), "settings.json")
|
||||
|
||||
|
||||
def load():
|
||||
s = dict(DEFAULTS)
|
||||
try:
|
||||
s.update(json.load(open(path(), encoding="utf-8")))
|
||||
except (OSError, ValueError):
|
||||
pass
|
||||
for k in OBSOLETE:
|
||||
s.pop(k, None)
|
||||
return s
|
||||
|
||||
|
||||
def save(s):
|
||||
tmp = path() + ".tmp"
|
||||
with open(tmp, "w", encoding="utf-8") as f:
|
||||
json.dump(s, f, indent=1)
|
||||
os.replace(tmp, path())
|
||||
Reference in New Issue
Block a user