Nytt argument för att peka ut andOTP-filen direkt
This commit is contained in:
16
totp.py
16
totp.py
@@ -26,6 +26,7 @@ def get_arguments():
|
|||||||
parser.add_argument("site", nargs="*")
|
parser.add_argument("site", nargs="*")
|
||||||
default_cfg_path = os.environ['HOME'] + '/.totprc'
|
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("-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()
|
args = parser.parse_args()
|
||||||
return args
|
return args
|
||||||
@@ -74,13 +75,13 @@ def read_config(args):
|
|||||||
if not os.path.isfile(config.get('totp', 'andOTPfile')):
|
if not os.path.isfile(config.get('totp', 'andOTPfile')):
|
||||||
die("The file %s does not exist" % 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
|
# Open and parse the data file
|
||||||
try:
|
try:
|
||||||
with open(config.get('totp', 'andOTPfile')) as filen:
|
with open(andOTPfile) as filen:
|
||||||
data = json.load(filen)
|
data = json.load(filen)
|
||||||
except:
|
except:
|
||||||
die("Error parsing JSON, corrupt andOTP-file?")
|
die("Error parsing JSON, corrupt andOTP-file?")
|
||||||
@@ -129,9 +130,12 @@ class TOTP():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
args = get_arguments() # Get args from cmdline
|
args = get_arguments() # Get args from cmdline
|
||||||
cfg = read_config(args) # Read from the cfg file
|
if args.andOTP:
|
||||||
data = read_file(cfg) # Open the data file
|
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
|
if not args.site: # Show a menu if no input
|
||||||
while True:
|
while True:
|
||||||
|
|||||||
Reference in New Issue
Block a user