1
0

reformat simple_config to comply with electrum and create config dir if it doesnt exist.

This commit is contained in:
Amir Taaki
2012-09-19 16:47:39 +01:00
parent af3fe1722b
commit 15eb4d7cb8

View File

@@ -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:
self.save_config()
def save_config(self): def __init__(self):
f = open(self.config_file_path(), "w+") # Find electrum data folder
f.write(json.dumps(self.config)) 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
# Make config directory if it does not yet exist.
if not os.path.exists(self.config_folder):
os.mkdir(self.config_folder)
self.save_config()
def load_config(self): def set_key(self, key, value, save = True):
f = open(self.config_file_path(), "r") self.config[key] = value
file_contents = f.read() if save == True:
if file_contents: self.save_config()
self.config = json.loads(file_contents)
else:
self.config = self.default_options
self.save_config()
def config_file_path(self): def save_config(self):
return "%s" % (self.config_folder + "/config.json") f = open(self.config_file_path(), "w+")
f.write(json.dumps(self.config))
def __init__(self): def load_config(self):
# Find electrum data folder f = open(self.config_file_path(), "r")
self.config_folder = user_dir() file_contents = f.read()
# Read the file if file_contents:
if os.path.exists(self.config_file_path()): self.config = json.loads(file_contents)
self.load_config() else:
else: self.config = self.default_options
self.config = self.default_options self.save_config()
self.save_config()
def config_file_path(self):
return "%s" % (self.config_folder + "/config.json")