Nytt argument för att peka ut andOTP-filen direkt

This commit is contained in:
2018-07-14 12:34:38 +02:00
parent af80b53402
commit 091a73b2bf

14
totp.py
View File

@@ -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?")
@@ -130,8 +131,11 @@ 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
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: