Browse Source

Added SimpleConfig class to deal with simple config options added for fallback to other gui when missing deps

283
Maran 13 years ago
parent
commit
3252b5ae4e
  1. 11
      electrum
  2. 1
      lib/__init__.py
  3. 40
      lib/simple_config.py

11
electrum

@ -40,8 +40,9 @@ try:
from lib import Wallet, WalletSynchronizer, format_satoshis, mnemonic, prompt_password
except ImportError:
from electrum import Wallet, WalletSynchronizer, format_satoshis, mnemonic, prompt_password
from decimal import Decimal
from lib import SimpleConfig
known_commands = {
'help':'Prints this help',
@ -101,9 +102,12 @@ protected_commands = ['payto', 'password', 'mktx', 'seed', 'import','signmessage
if __name__ == '__main__':
# Load simple config class
simple_config = SimpleConfig()
usage = "usage: %prog [options] command\nCommands: "+ (', '.join(known_commands))
parser = optparse.OptionParser(prog=usage)
parser.add_option("-g", "--gui", dest="gui", default="lite", help="gui")
parser.add_option("-g", "--gui", dest="gui", default=simple_config.config["gui"], help="gui")
parser.add_option("-w", "--wallet", dest="wallet_path", help="wallet path (default: electrum.dat)")
parser.add_option("-o", "--offline", action="store_true", dest="offline", default=False, help="remain offline")
parser.add_option("-a", "--all", action="store_true", dest="show_all", default=False, help="show all addresses")
@ -115,6 +119,7 @@ if __name__ == '__main__':
parser.add_option("-r", "--remote", dest="remote_url", default=None, help="URL of a remote wallet")
options, args = parser.parse_args()
wallet = Wallet()
wallet.set_path(options.wallet_path)
wallet.read()
@ -161,6 +166,8 @@ if __name__ == '__main__':
error_message = QErrorMessage()
error_message.setFixedSize(350,200)
error_message.showMessage("<p>Sorry, the Electrum 'Lite GUI' requires Qt >= 4.7 to run. The pro GUI will be started instead.</p><p>Check your distributions packages for upgrades.</p>")
simple_config.config["gui"] = "qt"
simple_config.save_config
app.exec_()
try:

1
lib/__init__.py

@ -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

@ -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()
Loading…
Cancel
Save