-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.py
33 lines (27 loc) · 829 Bytes
/
settings.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
import json
import threading
from pathlib import Path
class Config:
def __init__(self):
self._lock = threading.Lock()
self.config = dict()
def save(self, filename):
self._lock.acquire()
json.dump(self.config, open(filename, 'w'))
self._lock.release()
def getValue(self, name, default):
self._lock.acquire()
if name not in self.config.keys():
self.config[name] = default
copy = self.config[name]
self._lock.release()
return copy
def setValue(self, name, value):
self._lock.acquire()
self.config[name] = value
self._lock.release()
def load(self, filename):
self._lock.acquire()
self.config = json.load(open(Path(filename)))
self._lock.release()
return self