reformat simple_config to comply with electrum and create config dir if it doesnt exist.
This commit is contained in:
parent
af3fe1722b
commit
15eb4d7cb8
|
@ -3,36 +3,40 @@ import os
|
||||||
from util import user_dir
|
from util import user_dir
|
||||||
|
|
||||||
class SimpleConfig:
|
class SimpleConfig:
|
||||||
default_options = {"gui": "lite"}
|
|
||||||
|
|
||||||
def set_key(self, key, value, save = True):
|
default_options = {"gui": "lite"}
|
||||||
self.config[key] = value
|
|
||||||
if save == True:
|
def __init__(self):
|
||||||
self.save_config()
|
# Find electrum data folder
|
||||||
|
self.config_folder = user_dir()
|
||||||
def save_config(self):
|
# Read the file
|
||||||
f = open(self.config_file_path(), "w+")
|
if os.path.exists(self.config_file_path()):
|
||||||
f.write(json.dumps(self.config))
|
self.load_config()
|
||||||
|
else:
|
||||||
def load_config(self):
|
self.config = self.default_options
|
||||||
f = open(self.config_file_path(), "r")
|
# Make config directory if it does not yet exist.
|
||||||
file_contents = f.read()
|
if not os.path.exists(self.config_folder):
|
||||||
if file_contents:
|
os.mkdir(self.config_folder)
|
||||||
self.config = json.loads(file_contents)
|
self.save_config()
|
||||||
else:
|
|
||||||
self.config = self.default_options
|
|
||||||
self.save_config()
|
|
||||||
|
|
||||||
def config_file_path(self):
|
|
||||||
return "%s" % (self.config_folder + "/config.json")
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
# Find electrum data folder
|
|
||||||
self.config_folder = user_dir()
|
|
||||||
# Read the file
|
|
||||||
if os.path.exists(self.config_file_path()):
|
|
||||||
self.load_config()
|
|
||||||
else:
|
|
||||||
self.config = self.default_options
|
|
||||||
self.save_config()
|
|
||||||
|
|
||||||
|
def set_key(self, key, value, save = True):
|
||||||
|
self.config[key] = value
|
||||||
|
if save == True:
|
||||||
|
self.save_config()
|
||||||
|
|
||||||
|
def save_config(self):
|
||||||
|
f = open(self.config_file_path(), "w+")
|
||||||
|
f.write(json.dumps(self.config))
|
||||||
|
|
||||||
|
def load_config(self):
|
||||||
|
f = open(self.config_file_path(), "r")
|
||||||
|
file_contents = f.read()
|
||||||
|
if file_contents:
|
||||||
|
self.config = json.loads(file_contents)
|
||||||
|
else:
|
||||||
|
self.config = self.default_options
|
||||||
|
self.save_config()
|
||||||
|
|
||||||
|
def config_file_path(self):
|
||||||
|
return "%s" % (self.config_folder + "/config.json")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue