Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

Allow execution from any filepath #670

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

Allow execution from any filepath #670

wants to merge 1 commit into from

Conversation

Empty2k12
Copy link
Contributor

Until now you had to go go into the folder containing wallet-tool, yg or any other of the tools to use them. This commit solves this (at least for wallet-tool, log creation and everywhere the Wallet class is used).

You can now execute joinmarket from any filepath using a command like this
python ~/Desktop/JoinmarketDev/yield-generator-basic.py wallet.json

I am not sure if I have missed any code where the folder is being assumed.

To figure you the filepath a python function has been used. For all files in the /joinmarket/ subfolder the subfolder name is being stripped using [:-11]. Additionally the method to get the filepath returns a tuple and the actual filepath is accessed using the index.

I am not sure if this is best practice, since my knowledge in Python is still limited. Please suggest missing cases and code improvements!

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.05%) to 82.384% when pulling bdf7f67 on Empty2k12:develop into 72537e2 on JoinMarket-Org:develop.

self.path = None
self.index_cache = [[0, 0]] * self.max_mix_depth
path = os.path.join('wallets', filename)
path = os.path.join(dirname[0][:-11], 'wallets', filename)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using -11 and split here is fragile. Probably better to do something like:

dirname = os.path.dirname(os.path.abspath(__file__))
wallet_path = os.path.join(dirname, '..', 'wallets', filename)

Although I think moving wallet and log dir to configuration variables would probably be better still

@@ -270,14 +270,16 @@ def cus_print(s):
elif method == 'listwallets':
# Fetch list of wallets
possible_wallets = []
for (dirpath, dirnames, filenames) in os.walk('wallets'):
dirname = os.path.split(os.path.abspath(__file__))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to above, use join instead of split:

dirname = os.path.dirname(os.path.abspath(__file__))
wallet_dir = os.path.join(dirname, 'wallets')

possible_wallets.extend(filenames)
# Breaking as we only want the top dir, not subdirs
break
# For each possible wallet file, read json to list
walletjsons = []
for possible_wallet in possible_wallets:
fd = open(os.path.join('wallets', possible_wallet), 'r')
dirname = os.path.split(os.path.abspath(__file__))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants