forked from TouchTone/pyjsit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preferences.py
87 lines (46 loc) · 1.32 KB
/
preferences.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Trivial preferences manager
import json
from log import *
# Global preferences dicts
allprefs = {}
changedprefs = set()
def setValue(module, name, value):
if not allprefs.has_key(module):
allprefs[module] = {}
modprefs = allprefs[module]
modprefs[name] = value
changedprefs.add(module + ":" + name)
def pref(module, name):
if not allprefs.has_key(module):
allprefs[module] = {}
modprefs = allprefs[module]
if not modprefs.has_key(name):
modprefs[name] = None
return modprefs[name]
def prefOrVal(module, name, val):
v = pref(module, name)
if v != None:
return v
return val
def load(file):
global allprefs
log(INFO)
if isinstance(file, str):
try:
file = open(file, "r")
except KeyError,e:
allprefs = {}
return
allprefs = json.load(file)
def save(file):
log(INFO)
if isinstance(file, str):
file = open(file, "w")
json.dump(allprefs, file, sort_keys=True, indent=2)
changedprefs = set()
def changed():
log(DEBUG, "changed: %s\n" % changedprefs)
if len(changedprefs) == 0:
return None
ret = ", ".join(changedprefs)
return ret