Added --plain argument for machine cli interaction
This commit is contained in:
parent
f47978a3f4
commit
033ce00725
4 changed files with 38 additions and 12 deletions
|
|
@ -58,6 +58,12 @@ parser.add_argument(
|
||||||
help="Skip all questions.",
|
help="Skip all questions.",
|
||||||
action="store_true")
|
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
|
# Overwrite the default help message so we can use a uppercase S
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-h", "--help",
|
"-h", "--help",
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,9 @@ if len(encodings) > 3:
|
||||||
print("NOTICE: Each additional model slows down the face recognition engine slightly")
|
print("NOTICE: Each additional model slows down the face recognition engine slightly")
|
||||||
print("Press Ctrl+C to cancel\n")
|
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
|
# Set the default label
|
||||||
label = "Initial model"
|
label = "Initial model"
|
||||||
|
|
@ -83,12 +85,17 @@ if builtins.howdy_args.y:
|
||||||
print('Using default label "%s" because of -y flag' % (label, ))
|
print('Using default label "%s" because of -y flag' % (label, ))
|
||||||
else:
|
else:
|
||||||
# Ask the user for a custom label
|
# 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
|
# Set the custom label (if any) and limit it to 24 characters
|
||||||
if label_in != "":
|
if label_in != "":
|
||||||
label = label_in[:24]
|
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
|
# Prepare the metadata for insertion
|
||||||
insert_model = {
|
insert_model = {
|
||||||
"time": int(time.time()),
|
"time": int(time.time()),
|
||||||
|
|
|
||||||
|
|
@ -28,20 +28,31 @@ except FileNotFoundError:
|
||||||
print("\n\tsudo howdy -U " + user + " add\n")
|
print("\n\tsudo howdy -U " + user + " add\n")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Print a header
|
# Print a header if we're not in plain mode
|
||||||
print("Known face models for " + user + ":")
|
if not builtins.howdy_args.plain:
|
||||||
print("\n\t\033[1;29mID Date Label\033[0m")
|
print("Known face models for " + user + ":")
|
||||||
|
print("\n\033[1;29mID Date Label\033[0m")
|
||||||
|
|
||||||
# Loop through all encodings and print info about them
|
# Loop through all encodings and print info about them
|
||||||
for enc in encodings:
|
for enc in encodings:
|
||||||
# Start with a tab and print the id
|
# Start with the id
|
||||||
print("\t" + str(enc["id"]), end="")
|
print(str(enc["id"]), end="")
|
||||||
# Print padding spaces after the id
|
|
||||||
print((4 - len(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
|
# Format the time as ISO in the local timezone
|
||||||
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(enc["time"])), end="")
|
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
|
# End with the label
|
||||||
print(" " + enc["label"])
|
print(enc["label"])
|
||||||
|
|
||||||
# Add a closing enter
|
# Add a closing enter
|
||||||
print()
|
print()
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ user = builtins.howdy_user
|
||||||
# Check if enough arguments have been passed
|
# Check if enough arguments have been passed
|
||||||
if builtins.howdy_args.argument is None:
|
if builtins.howdy_args.argument is None:
|
||||||
print("Please add the ID of the model you want to remove as an argument")
|
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("You can find the IDs by running:")
|
||||||
print("\n\thowdy list\n")
|
print("\n\thowdy list\n")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
@ -48,7 +50,7 @@ for enc in encodings:
|
||||||
|
|
||||||
# Abort if the answer isn't yes
|
# Abort if the answer isn't yes
|
||||||
if (ans.lower() != "y"):
|
if (ans.lower() != "y"):
|
||||||
print('\nInerpeting as a "NO"')
|
print('\nInterpreting as a "NO"')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
# Add a padding empty line
|
# Add a padding empty line
|
||||||
|
|
@ -61,7 +63,7 @@ for enc in encodings:
|
||||||
# Abort if no matching id was found
|
# Abort if no matching id was found
|
||||||
if not found:
|
if not found:
|
||||||
print("No model with ID " + builtins.howdy_args.argument + " exists for " + user)
|
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
|
# Remove the entire file if this encoding is the only one
|
||||||
if len(encodings) == 1:
|
if len(encodings) == 1:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue