From 091a73b2bf10d84a3c3e33bf5b84a8c77bfee8e9 Mon Sep 17 00:00:00 2001 From: Fredrik Wahlberg Date: Sat, 14 Jul 2018 12:34:38 +0200 Subject: [PATCH] =?UTF-8?q?Nytt=20argument=20f=C3=B6r=20att=20peka=20ut=20?= =?UTF-8?q?andOTP-filen=20direkt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- totp.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/totp.py b/totp.py index d84858c..0624850 100755 --- a/totp.py +++ b/totp.py @@ -26,6 +26,7 @@ def get_arguments(): parser.add_argument("site", nargs="*") default_cfg_path = os.environ['HOME'] + '/.totprc' parser.add_argument("-c", "--config", default=default_cfg_path, help='Path to config-file. Defaults to ~/.totprc') + parser.add_argument("-a", "--andOTP", help='Path to andOTP backup file') args = parser.parse_args() return args @@ -74,13 +75,13 @@ def read_config(args): if not os.path.isfile(config.get('totp', 'andOTPfile')): die("The file %s does not exist" % config.get('totp', 'andOTPfile')) - return config + return config.get('totp', 'andOTPfile') -def read_file(config): +def read_file(andOTPfile): # Open and parse the data file try: - with open(config.get('totp', 'andOTPfile')) as filen: + with open(andOTPfile) as filen: data = json.load(filen) except: die("Error parsing JSON, corrupt andOTP-file?") @@ -129,9 +130,12 @@ class TOTP(): if __name__ == '__main__': - args = get_arguments() # Get args from cmdline - cfg = read_config(args) # Read from the cfg file - data = read_file(cfg) # Open the data file + args = get_arguments() # Get args from cmdline + if args.andOTP: + andOTPfile = args.andOTP + else: + andOTPfile = read_config(args) # Read from the cfg file + data = read_file(andOTPfile) # Open the data file if not args.site: # Show a menu if no input while True: