-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstorage.py
37 lines (30 loc) · 898 Bytes
/
storage.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
import os
from pathlib import Path
import json
storageDir=str(Path.home())+os.sep+".nebulagui"
storagePath = storageDir+os.sep+"settings.json"
Path(storageDir).mkdir(parents=True, exist_ok=True)
if not os.path.exists(storagePath):
f = open(storagePath, "w")
f.write("{}")
f.close()
class Storage():
def add(self, key, value):
values=self.getValues()
values[key] = value
self.storeValues(values)
def get(self, key):
values=self.getValues()
return values[key]
def getValues(self):
f = open(storagePath, "r")
return json.load(f)
def storeValues(self, values):
f = open(storagePath, "w")
f.write(json.dumps(values))
f.close()
def exists(self, key):
for jKey in self.getValues().keys():
if key == jKey:
return True
return False