Merge branch 'fallback'
This commit is contained in:
commit
3f499d7048
29
electrum
29
electrum
@ -40,8 +40,9 @@ try:
|
|||||||
from lib import Wallet, WalletSynchronizer, format_satoshis, mnemonic, prompt_password
|
from lib import Wallet, WalletSynchronizer, format_satoshis, mnemonic, prompt_password
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from electrum import Wallet, WalletSynchronizer, format_satoshis, mnemonic, prompt_password
|
from electrum import Wallet, WalletSynchronizer, format_satoshis, mnemonic, prompt_password
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
from lib import SimpleConfig
|
||||||
|
|
||||||
known_commands = {
|
known_commands = {
|
||||||
'help':'Prints this help',
|
'help':'Prints this help',
|
||||||
@ -101,9 +102,12 @@ protected_commands = ['payto', 'password', 'mktx', 'seed', 'import','signmessage
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
|
# Load simple config class
|
||||||
|
simple_config = SimpleConfig()
|
||||||
|
|
||||||
usage = "usage: %prog [options] command\nCommands: "+ (', '.join(known_commands))
|
usage = "usage: %prog [options] command\nCommands: "+ (', '.join(known_commands))
|
||||||
parser = optparse.OptionParser(prog=usage)
|
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("-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("-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")
|
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")
|
parser.add_option("-r", "--remote", dest="remote_url", default=None, help="URL of a remote wallet")
|
||||||
options, args = parser.parse_args()
|
options, args = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
wallet = Wallet()
|
wallet = Wallet()
|
||||||
wallet.set_path(options.wallet_path)
|
wallet.set_path(options.wallet_path)
|
||||||
wallet.read()
|
wallet.read()
|
||||||
@ -157,17 +162,19 @@ if __name__ == '__main__':
|
|||||||
qtVersion = qVersion()
|
qtVersion = qVersion()
|
||||||
if not(int(qtVersion[0]) >= 4 and int(qtVersion[2]) >= 7):
|
if not(int(qtVersion[0]) >= 4 and int(qtVersion[2]) >= 7):
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
|
QMessageBox.warning(None,"Could not start Lite GUI.", "Electrum was unable to load the 'Lite GUI' because it needs Qt version >= 4.7.\nElectrum is now setup to load the Pro GUI.")
|
||||||
|
|
||||||
error_message = QErrorMessage()
|
simple_config.set_key("gui", "qt")
|
||||||
error_message.setFixedSize(350,200)
|
|
||||||
error_message.showMessage("<p>Sorry, Electrum requires Qt >= 4.7 to run.</p><p>Check your distributions packages or download it at http://qt.nokia.com/downloads</p>")
|
try:
|
||||||
app.exec_()
|
import lib.gui_qt as gui
|
||||||
sys.exit(0)
|
except ImportError:
|
||||||
|
import electrum.gui_qt as gui
|
||||||
#use the lite version if no toolkit specified
|
else:
|
||||||
try:
|
#use the lite version if no toolkit specified
|
||||||
|
try:
|
||||||
import lib.gui_lite as gui
|
import lib.gui_lite as gui
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import electrum.gui_lite as gui
|
import electrum.gui_lite as gui
|
||||||
else:
|
else:
|
||||||
sys.exit("Error: Unknown GUI: " + options.gui)
|
sys.exit("Error: Unknown GUI: " + options.gui)
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
from wallet import Wallet, format_satoshis, prompt_password
|
from wallet import Wallet, format_satoshis, prompt_password
|
||||||
from interface import WalletSynchronizer
|
from interface import WalletSynchronizer
|
||||||
from interface import TcpStratumInterface
|
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.write(" ".join(args) + "\n")
|
||||||
sys.stderr.flush()
|
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():
|
def appdata_dir():
|
||||||
"""Find the path to the application data directory; add an electrum folder and return path."""
|
"""Find the path to the application data directory; add an electrum folder and return path."""
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
|
|||||||
@ -32,6 +32,7 @@ import ecdsa
|
|||||||
|
|
||||||
from ecdsa.util import string_to_number, number_to_string
|
from ecdsa.util import string_to_number, number_to_string
|
||||||
from util import print_error
|
from util import print_error
|
||||||
|
from util import user_dir
|
||||||
|
|
||||||
############ functions from pywallet #####################
|
############ functions from pywallet #####################
|
||||||
|
|
||||||
@ -365,14 +366,8 @@ class Wallet:
|
|||||||
return
|
return
|
||||||
# Look for wallet file in the default data directory.
|
# Look for wallet file in the default data directory.
|
||||||
# Keeps backwards compatibility.
|
# Keeps backwards compatibility.
|
||||||
if "HOME" in os.environ:
|
wallet_dir = user_dir()
|
||||||
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.")
|
|
||||||
# Make wallet directory if it does not yet exist.
|
# Make wallet directory if it does not yet exist.
|
||||||
if not os.path.exists(wallet_dir):
|
if not os.path.exists(wallet_dir):
|
||||||
os.mkdir(wallet_dir)
|
os.mkdir(wallet_dir)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user