0
0
Fork 0
mirror of https://github.com/boltgolt/howdy.git synced 2024-10-17 10:06:53 +02:00
howdy/cli.py

42 lines
1.1 KiB
Python
Raw Normal View History

2018-02-08 01:11:47 +01:00
#!/usr/bin/env python3
2018-02-13 23:22:13 +01:00
# CLI directly called by running the howdy command
# Import required modules
2018-02-08 01:11:47 +01:00
import sys
2018-02-13 22:03:03 +01:00
import os
2018-02-08 01:11:47 +01:00
2018-02-13 23:22:13 +01:00
# Check if the minimum of 3 arugemnts has been met and print help otherwise
2018-02-13 22:03:03 +01:00
if (len(sys.argv) < 3):
print("Howdy IR face recognition help")
import cli.help
sys.exit()
2018-02-13 23:22:13 +01:00
# The command given
2018-02-13 22:03:03 +01:00
cmd = sys.argv[2]
2018-02-13 23:22:13 +01:00
# Requre sudo for comamnds that need root rights to read the model files
2018-02-13 22:03:03 +01:00
if cmd in ["list", "add", "remove", "clear"] and os.getenv("SUDO_USER") is None:
print("Please run this command with sudo")
sys.exit()
2018-02-08 01:11:47 +01:00
2018-02-13 23:22:13 +01:00
# Call the right files for the given command
2018-02-08 01:11:47 +01:00
if cmd == "list":
2018-02-10 15:09:49 +01:00
import cli.list
elif cmd == "help":
2018-02-13 22:03:03 +01:00
print("Howdy IR face recognition")
import cli.help
elif cmd == "add":
import cli.add
2018-02-13 22:22:02 +01:00
elif cmd == "remove":
import cli.remove
2018-02-13 22:03:03 +01:00
elif cmd == "clear":
import cli.clear
else:
2018-02-13 23:22:13 +01:00
# If the comand is invalid, check if the user hasn't swapped the username and command
2018-02-13 22:03:03 +01:00
if sys.argv[1] in ["list", "add", "remove", "clear", "help"]:
print("Usage: howdy <user> <command>")
else:
print('Unknown command "' + cmd + '"')
import cli.help