1
0

store contacts in a separate file, shared between wallets

This commit is contained in:
ThomasV
2015-04-23 12:16:46 +02:00
parent 065145e557
commit e8189490e9
4 changed files with 71 additions and 73 deletions

View File

@@ -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()