-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
28 lines (28 loc) · 1015 Bytes
/
config.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
import sys,os,json
path=os.path.join(*sys.executable.split(os.sep),'xes_user_configs').replace(':',':'+os.sep)
pid=sys.argv[0].split(os.sep)[-1].split('/')[0]
try:pid=str(int(pid))
except:exit()
try:os.mkdir(path)
except:pass
class Config:
def __init__(self,name:str=''):
try:os.mkdir(os.path.join(path,pid))
except:pass
self.path=os.path.join(path,pid,'')+name+'.json'
try:self.attrs=json.load(open(self.path,'r'))
except FileNotFoundError:
with open(self.path,'w+') as f:pass
self.attrs=dict()
__getitem__=lambda self,key:self.attrs[key]
def __setitem__(self,key,value):self.attrs[key]=value
def __delitem__(self,key):del self.attrs[key]
def save(self):
f=open(self.path,'w+')
f.write(json.dumps(self.attrs))
f.close()
def read(self):
try:self.attrs=json.load(open(self.path,'r'))
except FileNotFoundError:
with open(self.path,'w+') as f:pass
self.attrs=dict()