Added SimpleConfig class to deal with simple config options added for fallback to other gui when missing deps
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from wallet import Wallet, format_satoshis, prompt_password
|
||||
from interface import WalletSynchronizer
|
||||
from interface import TcpStratumInterface
|
||||
from simple_config import SimpleConfig
|
||||
|
||||
40
lib/simple_config.py
Normal file
40
lib/simple_config.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
class SimpleConfig:
|
||||
default_options = {"gui": "lite"}
|
||||
|
||||
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")
|
||||
|
||||
def __init__(self):
|
||||
# Find electrum data folder
|
||||
if "HOME" in os.environ:
|
||||
self.config_folder = os.path.join(os.environ["HOME"], ".electrum")
|
||||
elif "LOCALAPPDATA" in os.environ:
|
||||
self.config_folder = os.path.join(os.environ["LOCALAPPDATA"], "Electrum")
|
||||
elif "APPDATA" in os.environ:
|
||||
self.config_folder = os.path.join(os.environ["APPDATA"], "Electrum")
|
||||
else:
|
||||
raise BaseException("No home directory found in environment variables.")
|
||||
|
||||
# Read the file
|
||||
if os.path.exists(self.config_file_path()):
|
||||
self.load_config()
|
||||
else:
|
||||
self.config = self.default_options
|
||||
self.save_config()
|
||||
|
||||
Reference in New Issue
Block a user