0
0
Fork 0
mirror of https://github.com/boltgolt/howdy.git synced 2024-09-19 09:51:19 +02:00

Added --plain argument for machine cli interaction

This commit is contained in:
boltgolt 2020-12-05 14:28:57 +01:00
parent f47978a3f4
commit 033ce00725
No known key found for this signature in database
GPG key ID: BECEC9937E1AAE26
4 changed files with 38 additions and 12 deletions

View file

@ -58,6 +58,12 @@ parser.add_argument(
help="Skip all questions.",
action="store_true")
# Add the --plain flag
parser.add_argument(
"--plain",
help="Print machine-friendly output.",
action="store_true")
# Overwrite the default help message so we can use a uppercase S
parser.add_argument(
"-h", "--help",

View file

@ -69,7 +69,9 @@ if len(encodings) > 3:
print("NOTICE: Each additional model slows down the face recognition engine slightly")
print("Press Ctrl+C to cancel\n")
print("Adding face model for the user " + user)
# Make clear what we are doing if not human
if not builtins.howdy_args.plain:
print("Adding face model for the user " + user)
# Set the default label
label = "Initial model"
@ -83,12 +85,17 @@ if builtins.howdy_args.y:
print('Using default label "%s" because of -y flag' % (label, ))
else:
# Ask the user for a custom label
label_in = input("Enter a label for this new model [" + label + "] (max 24 characters): ")
label_in = input("Enter a label for this new model [" + label + "]: ")
# Set the custom label (if any) and limit it to 24 characters
if label_in != "":
label = label_in[:24]
# Remove illegal characters
if "," in label:
print("NOTICE: Removing illegal character \",\" from model name")
label = label.replace(",", "")
# Prepare the metadata for insertion
insert_model = {
"time": int(time.time()),

View file

@ -28,20 +28,31 @@ except FileNotFoundError:
print("\n\tsudo howdy -U " + user + " add\n")
sys.exit(1)
# Print a header
print("Known face models for " + user + ":")
print("\n\t\033[1;29mID Date Label\033[0m")
# Print a header if we're not in plain mode
if not builtins.howdy_args.plain:
print("Known face models for " + user + ":")
print("\n\033[1;29mID Date Label\033[0m")
# Loop through all encodings and print info about them
for enc in encodings:
# Start with a tab and print the id
print("\t" + str(enc["id"]), end="")
# Print padding spaces after the id
# Start with the id
print(str(enc["id"]), end="")
# Add comma for machine reading
if builtins.howdy_args.plain:
print(",", end="")
# Print padding spaces after the id for a nice layout
else:
print((4 - len(str(enc["id"]))) * " ", end="")
# Format the time as ISO in the local timezone
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(enc["time"])), end="")
# Seperate with commas again for machines, spaces otherwise
print("," if builtins.howdy_args.plain else " ", end="")
# End with the label
print(" " + enc["label"])
print(enc["label"])
# Add a closing enter
print()

View file

@ -13,6 +13,8 @@ user = builtins.howdy_user
# Check if enough arguments have been passed
if builtins.howdy_args.argument is None:
print("Please add the ID of the model you want to remove as an argument")
print("For example:")
print("\n\thowdy remove 0\n")
print("You can find the IDs by running:")
print("\n\thowdy list\n")
sys.exit(1)
@ -48,7 +50,7 @@ for enc in encodings:
# Abort if the answer isn't yes
if (ans.lower() != "y"):
print('\nInerpeting as a "NO"')
print('\nInterpreting as a "NO"')
sys.exit()
# Add a padding empty line
@ -61,7 +63,7 @@ for enc in encodings:
# Abort if no matching id was found
if not found:
print("No model with ID " + builtins.howdy_args.argument + " exists for " + user)
sys.exit()
sys.exit(1)
# Remove the entire file if this encoding is the only one
if len(encodings) == 1: