passwdtools/configuration.py

31 lines
713 B
Python
Raw Normal View History

2019-03-11 16:29:14 +00:00
import json
2019-03-12 12:27:34 +00:00
class Config:
2019-03-11 16:29:14 +00:00
def __init__(self):
2019-03-12 12:27:34 +00:00
self.data = self.read()
2019-03-11 16:29:14 +00:00
2019-03-12 12:27:34 +00:00
def get_pwdfilename(self):
return self.data["pwdfile"]
def set_pwdfilename(self, pwdfilename):
self.data["pwdfilename"] = pwdfilename
self.write(self.data)
2019-03-12 12:27:34 +00:00
def get_secret(self):
return self.data["secret"]
def set_secret(self, secret):
self.data["secret"] = secret
self.write(self.data)
2019-03-12 12:27:34 +00:00
@staticmethod
def read():
with open('cfg/config.json', mode="r") as cfgfile:
return json.load(cfgfile)
@staticmethod
def write(keys):
with open('cfg/config.json', mode="w") as cfgfile:
cfgfile.write(json.dumps(keys))