Merge branch 'fallback'
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
|
||||
|
||||
38
lib/simple_config.py
Normal file
38
lib/simple_config.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import json
|
||||
import os
|
||||
from lib.util import user_dir
|
||||
|
||||
class SimpleConfig:
|
||||
default_options = {"gui": "lite"}
|
||||
|
||||
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")
|
||||
|
||||
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()
|
||||
|
||||
10
lib/util.py
10
lib/util.py
@@ -8,6 +8,16 @@ def print_error(*args):
|
||||
sys.stderr.write(" ".join(args) + "\n")
|
||||
sys.stderr.flush()
|
||||
|
||||
def user_dir():
|
||||
if "HOME" in os.environ:
|
||||
return os.path.join(os.environ["HOME"], ".electrum")
|
||||
elif "LOCALAPPDATA" in os.environ:
|
||||
return os.path.join(os.environ["LOCALAPPDATA"], "Electrum")
|
||||
elif "APPDATA" in os.environ:
|
||||
return os.path.join(os.environ["APPDATA"], "Electrum")
|
||||
else:
|
||||
raise BaseException("No home directory found in environment variables.")
|
||||
|
||||
def appdata_dir():
|
||||
"""Find the path to the application data directory; add an electrum folder and return path."""
|
||||
if platform.system() == "Windows":
|
||||
|
||||
@@ -32,6 +32,7 @@ import ecdsa
|
||||
|
||||
from ecdsa.util import string_to_number, number_to_string
|
||||
from util import print_error
|
||||
from util import user_dir
|
||||
|
||||
############ functions from pywallet #####################
|
||||
|
||||
@@ -365,14 +366,8 @@ class Wallet:
|
||||
return
|
||||
# Look for wallet file in the default data directory.
|
||||
# Keeps backwards compatibility.
|
||||
if "HOME" in os.environ:
|
||||
wallet_dir = os.path.join(os.environ["HOME"], ".electrum")
|
||||
elif "LOCALAPPDATA" in os.environ:
|
||||
wallet_dir = os.path.join(os.environ["LOCALAPPDATA"], "Electrum")
|
||||
elif "APPDATA" in os.environ:
|
||||
wallet_dir = os.path.join(os.environ["APPDATA"], "Electrum")
|
||||
else:
|
||||
raise BaseException("No home directory found in environment variables.")
|
||||
wallet_dir = user_dir()
|
||||
|
||||
# Make wallet directory if it does not yet exist.
|
||||
if not os.path.exists(wallet_dir):
|
||||
os.mkdir(wallet_dir)
|
||||
|
||||
Reference in New Issue
Block a user