passwdtools/configuration.py

30 lines
755 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):
self.cfg_file = '/Volumes/GMGAUTHIER/keys/pwdtools/config.json'
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):
2019-03-12 15:32:12 +00:00
return self.data["pwdfilename"]
2019-03-12 12:27:34 +00:00
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
def read(self):
with open(self.cfg_file, mode="r") as cfgfile:
2019-03-12 12:27:34 +00:00
return json.load(cfgfile)
def write(self, keys):
with open(self.cfg_file, mode="w") as cfgfile:
2019-03-12 12:27:34 +00:00
cfgfile.write(json.dumps(keys))