Skip to content

Commit

Permalink
Use a different configuration directory to Electrum
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil Booth committed Jul 31, 2017
1 parent dea5b6d commit 0fc02cc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/commands.py
Expand Up @@ -805,7 +805,7 @@ def add_network_options(parser):
def add_global_options(parser):
group = parser.add_argument_group('global options')
group.add_argument("-v", "--verbose", action="store_true", dest="verbose", default=False, help="Show debugging information")
group.add_argument("-D", "--dir", dest="electrum_path", help="electrum directory")
group.add_argument("-D", "--dir", dest="electron_cash_path", help="electron cash directory")
group.add_argument("-P", "--portable", action="store_true", dest="portable", default=False, help="Use local 'electrum_data' directory")
group.add_argument("-w", "--wallet", dest="wallet_path", help="wallet path")
group.add_argument("--testnet", action="store_true", dest="testnet", default=False, help="Use Testnet")
Expand Down
25 changes: 17 additions & 8 deletions lib/simple_config.py
Expand Up @@ -2,13 +2,14 @@
import json
import threading
import os
import shutil

from copy import deepcopy
from util import user_dir, print_error, print_msg, print_stderr, PrintError

from bitcoin import MAX_FEE_RATE, FEE_TARGETS

SYSTEM_CONFIG_PATH = "/etc/electrum.conf"
SYSTEM_CONFIG_PATH = "/etc/electron-cash.conf"

config = None

Expand Down Expand Up @@ -74,9 +75,9 @@ def __init__(self, options={}, read_system_config_function=None,
set_config(self)

def electrum_path(self):
# Read electrum_path from command line / system configuration
# Read electrum_cash_path from command line / system configuration
# Otherwise use the user's default data directory.
path = self.get('electrum_path')
path = self.get('electron_cash_path')
if path is None:
path = self.user_dir()

Expand All @@ -89,9 +90,17 @@ def electrum_path(self):
if not os.path.exists(path):
if os.path.islink(path):
raise BaseException('Dangling link: ' + path)
os.mkdir(path)

self.print_error("electrum directory", path)
self.print_error("Making directory {} and copying wallets".format(path))
os.makedirs(path)
electrum_path = user_dir(True)
if self.get('testnet'):
electrum_path = os.path.join(electrum_path, 'testnet')
elif self.get('nolnet'):
electrum_path = os.path.join(electrum_path, 'nolnet')
if os.path.exists(electrum_path):
# Deliberately don't copy config
shutil.copytree(os.path.join(electrum_path, 'wallets'), os.path.join(path, 'wallets'))
self.print_error("electron-cash directory", path)
return path

def fixup_config_keys(self, config, keypairs):
Expand Down Expand Up @@ -251,7 +260,7 @@ def read_system_config(path=SYSTEM_CONFIG_PATH):
try:
import ConfigParser
except ImportError:
print "cannot parse electrum.conf. please install ConfigParser"
print "cannot parse electron-cash.conf. please install ConfigParser"
return

p = ConfigParser.ConfigParser()
Expand All @@ -265,7 +274,7 @@ def read_system_config(path=SYSTEM_CONFIG_PATH):
return result

def read_user_config(path):
"""Parse and store the user config settings in electrum.conf into user_config[]."""
"""Parse and store the user config settings in electron-cash.conf into user_config[]."""
if not path:
return {}
config_path = os.path.join(path, "config")
Expand Down
8 changes: 4 additions & 4 deletions lib/util.py
Expand Up @@ -238,15 +238,15 @@ def android_check_data_dir():
def get_headers_dir(config):
return android_headers_dir() if 'ANDROID_DATA' in os.environ else config.path

def user_dir():
def user_dir(electrum=False):
if 'ANDROID_DATA' in os.environ:
return android_check_data_dir()
elif os.name == 'posix':
return os.path.join(os.environ["HOME"], ".electrum")
return os.path.join(os.environ["HOME"], ".electrum" if electrum else ".electron-cash" )
elif "APPDATA" in os.environ:
return os.path.join(os.environ["APPDATA"], "Electrum")
return os.path.join(os.environ["APPDATA"], "Electrum" if electrum else "ElectronCash")
elif "LOCALAPPDATA" in os.environ:
return os.path.join(os.environ["LOCALAPPDATA"], "Electrum")
return os.path.join(os.environ["LOCALAPPDATA"], "Electrum" if electrum else "ElectronCash")
else:
#raise Exception("No home directory found in environment variables.")
return
Expand Down

0 comments on commit 0fc02cc

Please sign in to comment.