From 146d48b9b802d0959d47fe128497ce63138a470e Mon Sep 17 00:00:00 2001 From: Peter Date: Wed, 17 Jan 2018 14:42:34 +0100 Subject: [PATCH] Allow user to specify alternate wallet and config filenames as arguments --- cryptop/cryptop.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/cryptop/cryptop.py b/cryptop/cryptop.py index 0a60032..667cd4b 100644 --- a/cryptop/cryptop.py +++ b/cryptop/cryptop.py @@ -10,11 +10,10 @@ import requests import requests_cache +import argparse # GLOBALS! BASEDIR = os.path.join(os.path.expanduser('~'), '.cryptop') -DATAFILE = os.path.join(BASEDIR, 'wallet.json') -CONFFILE = os.path.join(BASEDIR, 'config.ini') CONFIG = configparser.ConfigParser() COIN_FORMAT = re.compile('[A-Z]{2,5},\d{0,}\.?\d{0,}') @@ -254,11 +253,30 @@ def mainc(stdscr): global COLUMN COLUMN = (COLUMN + 1) % len(SORTS) +# Allow user to specify wallet and config filenames as arguments +def handleargs(): + global DATAFILE, CONFFILE + parser = argparse.ArgumentParser() + parser.add_argument("-w", "--wallet", type=str, help="Specify wallet filename") + parser.add_argument("-c", "--config", type=str, help="Specify config filename") + args = parser.parse_args() + if args.wallet: + DATAFILE = os.path.join(BASEDIR, args.wallet) + else: + DATAFILE = os.path.join(BASEDIR, 'wallet.json') + if args.config: + CONFFILE = os.path.join(BASEDIR, args.config) + else: + CONFFILE = os.path.join(BASEDIR, 'config.ini') + + print ('Wallet path:', str(DATAFILE)) + print ('Config path:', str(CONFFILE)) + def main(): if os.path.isfile(BASEDIR): sys.exit('Please remove your old configuration file at {}'.format(BASEDIR)) os.makedirs(BASEDIR, exist_ok=True) - + handleargs() global CONFIG CONFIG = read_configuration(CONFFILE) locale.setlocale(locale.LC_MONETARY, CONFIG['locale'].get('monetary', ''))