From 2311cc789001ea9a90890d1ea45fe571d24c3f7e Mon Sep 17 00:00:00 2001 From: Moul <moul@moul.re> Date: Thu, 6 May 2021 23:16:51 +0200 Subject: [PATCH] [mod] #160: examples: Allow to pass files path in f() prompt as arg Reduce usage message Add missing exits --- examples/load_binary_encrypted_message.py | 19 ++++++++----------- examples/load_binary_signed_message.py | 19 ++++++++----------- examples/load_credentials_file.py | 15 ++++++++------- examples/load_scuttlebutt_file.py | 15 ++++++++------- 4 files changed, 32 insertions(+), 36 deletions(-) diff --git a/examples/load_binary_encrypted_message.py b/examples/load_binary_encrypted_message.py index 1853cafa..a8a3060c 100644 --- a/examples/load_binary_encrypted_message.py +++ b/examples/load_binary_encrypted_message.py @@ -21,17 +21,14 @@ import sys from duniterpy.key import SigningKey -def load_binary_encrypted_message(): - if len(sys.argv) < 2: - print( - """ - Usage: - python decrypt_message.py ENCRYPTED_MESSAGE_FILEPATH - """ - ) - - # capture encrypted message filepath argument - signed_message_path = sys.argv[1] +def load_binary_encrypted_message(signed_message_path=None): + if not signed_message_path: + if len(sys.argv) < 2: + print("Usage: python decrypt_message.py ENCRYPTED_MESSAGE_FILEPATH") + sys.exit(1) + + # capture encrypted message filepath argument + signed_message_path = sys.argv[1] # prompt hidden user entry salt = getpass.getpass("Enter your passphrase (salt): ") diff --git a/examples/load_binary_signed_message.py b/examples/load_binary_signed_message.py index 857390fa..3031e35e 100644 --- a/examples/load_binary_signed_message.py +++ b/examples/load_binary_signed_message.py @@ -19,17 +19,14 @@ import sys from duniterpy.key import VerifyingKey -def load_binary_signed_message(): - if len(sys.argv) < 2: - print( - """ - Usage: - python verify_signed_message.py SIGNED_MESSAGE_FILEPATH - """ - ) - - # capture signed message filepath argument - signed_message_path = sys.argv[1] +def load_binary_signed_message(signed_message_path=None): + if not signed_message_path: + if len(sys.argv) < 2: + print("Usage: python verify_signed_message.py SIGNED_MESSAGE_FILEPATH") + sys.exit(1) + + # capture signed message filepath argument + signed_message_path = sys.argv[1] # ask public key of the signer pubkeyBase58 = input("Enter public key of the message issuer: ") diff --git a/examples/load_credentials_file.py b/examples/load_credentials_file.py index 70e6a49f..997213c8 100644 --- a/examples/load_credentials_file.py +++ b/examples/load_credentials_file.py @@ -19,13 +19,14 @@ import sys from duniterpy.key import SigningKey -def load_credentials_file(): - if len(sys.argv) < 2: - print("Usage: python load_credentials_file.py FILEPATH") - sys.exit(1) - - # capture filepath argument - credentials_filepath = sys.argv[1] +def load_credentials_file(credentials_filepath=None): + if not credentials_filepath: + if len(sys.argv) < 2: + print("Usage: python load_credentials_file.py FILEPATH") + sys.exit(1) + + # capture filepath argument + credentials_filepath = sys.argv[1] # create SigningKey instance from file signing_key_instance = SigningKey.from_credentials_file( diff --git a/examples/load_scuttlebutt_file.py b/examples/load_scuttlebutt_file.py index 48cff9a8..dcfd38c2 100644 --- a/examples/load_scuttlebutt_file.py +++ b/examples/load_scuttlebutt_file.py @@ -19,13 +19,14 @@ import sys from duniterpy.key import SigningKey -def load_scuttlebutt_file(): - if len(sys.argv) < 2: - print("Usage: python load_scuttlebutt_file.py FILEPATH") - sys.exit(1) - - # capture filepath argument - scuttlebutt_filepath = sys.argv[1] +def load_scuttlebutt_file(scuttlebutt_filepath=None): + if not scuttlebutt_filepath: + if len(sys.argv) < 2: + print("Usage: python load_scuttlebutt_file.py FILEPATH") + sys.exit(1) + + # capture filepath argument + scuttlebutt_filepath = sys.argv[1] # create SigningKey instance from file signing_key_instance = SigningKey.from_ssb_file( -- GitLab