-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlabelmaker_prefs.py
More file actions
44 lines (33 loc) · 1.2 KB
/
labelmaker_prefs.py
File metadata and controls
44 lines (33 loc) · 1.2 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
import json
import os
PREFS_FILE = os.path.join(os.path.expanduser("~"), ".nuke", "labelmaker_prefs.json")
DEFAULTS = {
"personal_config_path": os.path.join(os.path.expanduser("~"), ".nuke", "labelmaker_config.json"),
"labelmaker_enabled": True,
"always_show_all": False,
"colorize_disable": False,
"use_base_config": True,
"deoverlap_enabled": True,
}
class LabelmakerPrefs:
def __init__(self, prefs_file=PREFS_FILE):
self._prefs_file = prefs_file
self._prefs = self._load()
def _load(self):
if os.path.exists(self._prefs_file):
with open(self._prefs_file, "r") as f:
loaded = json.load(f)
return {**DEFAULTS, **loaded}
return dict(DEFAULTS)
def get(self, key):
if key == "use_base_config" and os.environ.get("LABELMAKER_DISABLE_BASE_CONFIG") == "1":
return False
return self._prefs.get(key, DEFAULTS.get(key))
def set(self, key, value):
self._prefs[key] = value
def save(self):
with open(self._prefs_file, "w") as f:
json.dump(self._prefs, f, indent=2)
def reload(self):
self._prefs = self._load()
prefs_singleton = LabelmakerPrefs()