store contacts in a separate file, shared between wallets
This commit is contained in:
30
lib/util.py
30
lib/util.py
@@ -397,3 +397,33 @@ class QueuePipe:
|
||||
def send_all(self, requests):
|
||||
for request in requests:
|
||||
self.send(request)
|
||||
|
||||
|
||||
|
||||
class StoreDict(dict):
|
||||
|
||||
def __init__(self, config, name):
|
||||
self.config = config
|
||||
self.path = os.path.join(self.config.path, name)
|
||||
self.load()
|
||||
|
||||
def load(self):
|
||||
try:
|
||||
with open(self.path, 'r') as f:
|
||||
self.update(json.loads(f.read()))
|
||||
except:
|
||||
pass
|
||||
|
||||
def save(self):
|
||||
with open(self.path, 'w') as f:
|
||||
s = json.dumps(self, indent=4, sort_keys=True)
|
||||
r = f.write(s)
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
dict.__setitem__(self, key, value)
|
||||
self.save()
|
||||
|
||||
def pop(self, key):
|
||||
if key in self.keys():
|
||||
dict.pop(self, key)
|
||||
self.save()
|
||||
|
||||
Reference in New Issue
Block a user