put cfgfile into its own class

This commit is contained in:
Greg Gauthier 2019-03-18 15:28:32 +00:00
parent 7d17d77d77
commit 6253e71a47
2 changed files with 19 additions and 13 deletions

14
cfgfile.py Normal file
View File

@ -0,0 +1,14 @@
import json
class CfgFile:
def __init__(self):
self.cfg_file = '/Volumes/GMGAUTHIER/keys/pwdtools/config.json'
def read(self):
with open(self.cfg_file, mode="r") as cfgfile:
return json.load(cfgfile)
def write(self, keys):
with open(self.cfg_file, mode="w") as cfgfile:
cfgfile.write(json.dumps(keys))

View File

@ -1,29 +1,21 @@
import json from cfgfile import CfgFile
class Config: class Config:
def __init__(self): def __init__(self):
self.cfg_file = '/Volumes/GMGAUTHIER/keys/pwdtools/config.json' self.cfgfile = CfgFile()
self.data = self.read() self.data = self.cfgfile.read()
def get_pwdfilename(self): def get_pwdfilename(self):
return self.data["pwdfilename"] return self.data["pwdfilename"]
def set_pwdfilename(self, pwdfilename): def set_pwdfilename(self, pwdfilename):
self.data["pwdfilename"] = pwdfilename self.data["pwdfilename"] = pwdfilename
self.write(self.data) self.cfgfile.write(self.data)
def get_secret(self): def get_secret(self):
return self.data["secret"] return self.data["secret"]
def set_secret(self, secret): def set_secret(self, secret):
self.data["secret"] = secret self.data["secret"] = secret
self.write(self.data) self.cfgfile.write(self.data)
def read(self):
with open(self.cfg_file, mode="r") as cfgfile:
return json.load(cfgfile)
def write(self, keys):
with open(self.cfg_file, mode="w") as cfgfile:
cfgfile.write(json.dumps(keys))