From 6253e71a47eaec8bca8fb21d10200d6677370cef Mon Sep 17 00:00:00 2001 From: Greg Gauthier Date: Mon, 18 Mar 2019 15:28:32 +0000 Subject: [PATCH] put cfgfile into its own class --- cfgfile.py | 14 ++++++++++++++ configuration.py | 18 +++++------------- 2 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 cfgfile.py diff --git a/cfgfile.py b/cfgfile.py new file mode 100644 index 0000000..a5559ad --- /dev/null +++ b/cfgfile.py @@ -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)) diff --git a/configuration.py b/configuration.py index 939aded..51a90a6 100644 --- a/configuration.py +++ b/configuration.py @@ -1,29 +1,21 @@ -import json +from cfgfile import CfgFile class Config: def __init__(self): - self.cfg_file = '/Volumes/GMGAUTHIER/keys/pwdtools/config.json' - self.data = self.read() + self.cfgfile = CfgFile() + self.data = self.cfgfile.read() def get_pwdfilename(self): return self.data["pwdfilename"] def set_pwdfilename(self, pwdfilename): self.data["pwdfilename"] = pwdfilename - self.write(self.data) + self.cfgfile.write(self.data) def get_secret(self): return self.data["secret"] def set_secret(self, secret): self.data["secret"] = secret - self.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)) + self.cfgfile.write(self.data)