Skip to content

Commit

Permalink
Merge 7a453f3 into 1c89cdb
Browse files Browse the repository at this point in the history
  • Loading branch information
gasull committed Mar 25, 2021
2 parents 1c89cdb + 7a453f3 commit 6a9380a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
3 changes: 2 additions & 1 deletion electroncash/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import base64
import datetime
import json
import os
import queue
import sys
import time
Expand Down Expand Up @@ -987,7 +988,7 @@ def add_global_options(parser):
group.add_argument("-v", "--verbose", action="store_true", dest="verbose", default=False, help="Show debugging information")
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 'electron_cash_data' directory")
group.add_argument("-w", "--wallet", dest="wallet_path", help="wallet path")
group.add_argument("-w", "--wallet", dest="wallet_path", help="wallet path", type=os.path.abspath)
group.add_argument("-wp", "--walletpassword", dest="wallet_password", default=None, help="Supply wallet password")
group.add_argument("--testnet", action="store_true", dest="testnet", default=False, help="Use Testnet")
group.add_argument("--testnet4", action="store_true", dest="testnet4", default=False, help="Use Testnet4")
Expand Down
29 changes: 20 additions & 9 deletions electroncash/simple_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,30 @@ def save_user_config(self):
f.write(s)
os.chmod(path, stat.S_IREAD | stat.S_IWRITE)

def get_new_wallet_directory(self):
"""Return the path to the directory where new wallets are saved.
If the program was started with the wallet path (-w or --wallet
argument), the directory of that wallet is used.
Else, the default wallet directory inside the user data directory
is used.
"""
# command line -w option
path = self.get('wallet_path')
return os.path.dirname(path) if path else os.path.join(self.path,
"wallets")

def get_wallet_path(self):
"""Set the path of the wallet."""
"""Return the path of the current wallet.
On program startup, this is either the wallet path specified on the
command line (-w or --wallet argument), or the wallet used the last
time the program was used, or by default a new wallet named
"default_wallet" in the user directory.
"""
# command line -w option
if self.get('wallet_path'):
return os.path.join(self.get('cwd', ''), self.get('wallet_path'))
return self.get('wallet_path')

# path in config file
path = self.get('default_wallet_path')
Expand All @@ -248,14 +266,7 @@ def get_wallet_path(self):
util.assert_datadir_available(self.path)
dirpath = os.path.join(self.path, "wallets")
make_dir(dirpath)

new_path = os.path.join(self.path, "wallets", "default_wallet")

# default path in pre 1.9 versions
old_path = os.path.join(self.path, "electrum.dat")
if os.path.exists(old_path) and not os.path.exists(new_path):
os.rename(old_path, new_path)

return new_path

def remove_from_recently_open(self, filename):
Expand Down
10 changes: 5 additions & 5 deletions electroncash_gui/qt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,15 +573,15 @@ def create_window_for_wallet(self, wallet):
return w

def get_wallet_folder(self):
''' may raise FileNotFoundError '''
"""Get path to directory containing the current wallet.
"""
return os.path.dirname(os.path.abspath(self.config.get_wallet_path()))

def get_new_wallet_path(self):
''' may raise FileNotFoundError '''
wallet_folder = self.get_wallet_folder()
"""Return path to a new wallet file to be created."""
wallet_folder = self.config.get_new_wallet_directory()
filename = get_new_wallet_name(wallet_folder)
full_path = os.path.join(wallet_folder, filename)
return full_path
return os.path.join(wallet_folder, filename)

def on_focus_change(self, ignored, new_focus_widget):
''' Remember the last wallet window that was activated because
Expand Down

0 comments on commit 6a9380a

Please sign in to comment.