mirror of
https://github.com/boltgolt/howdy.git
synced 2024-09-19 09:51:19 +02:00
Put all path variables into a separate module.
This makes it easier for downstream packagers to customize where howdy installs its files.
This commit is contained in:
parent
c17a834a52
commit
488176adae
12 changed files with 61 additions and 56 deletions
|
@ -8,6 +8,7 @@ import json
|
|||
import configparser
|
||||
import builtins
|
||||
import numpy as np
|
||||
import paths
|
||||
|
||||
from recorders.video_capture import VideoCapture
|
||||
from i18n import _
|
||||
|
@ -26,39 +27,36 @@ except ImportError as err:
|
|||
# OpenCV needs to be imported after dlib
|
||||
import cv2
|
||||
|
||||
# Define the absolute path to the config directory
|
||||
config_path = "/etc/howdy"
|
||||
|
||||
# Test if at lest 1 of the data files is there and abort if it's not
|
||||
if not os.path.isfile(config_path + "/dlib-data/shape_predictor_5_face_landmarks.dat"):
|
||||
if not os.path.isfile(paths.dlib_data_dir + "shape_predictor_5_face_landmarks.dat"):
|
||||
print(_("Data files have not been downloaded, please run the following commands:"))
|
||||
print("\n\tcd " + config_path + "/dlib-data")
|
||||
print("\n\tcd " + paths.dlib_data_dir)
|
||||
print("\tsudo ./install.sh\n")
|
||||
sys.exit(1)
|
||||
|
||||
# Read config from disk
|
||||
config = configparser.ConfigParser()
|
||||
config.read(config_path + "/config.ini")
|
||||
config.read(paths.config_dir + "/config.ini")
|
||||
|
||||
use_cnn = config.getboolean("core", "use_cnn", fallback=False)
|
||||
if use_cnn:
|
||||
face_detector = dlib.cnn_face_detection_model_v1(config_path + "/dlib-data/mmod_human_face_detector.dat")
|
||||
face_detector = dlib.cnn_face_detection_model_v1(paths.dlib_data_dir + "mmod_human_face_detector.dat")
|
||||
else:
|
||||
face_detector = dlib.get_frontal_face_detector()
|
||||
|
||||
pose_predictor = dlib.shape_predictor(config_path + "/dlib-data/shape_predictor_5_face_landmarks.dat")
|
||||
face_encoder = dlib.face_recognition_model_v1(config_path + "/dlib-data/dlib_face_recognition_resnet_model_v1.dat")
|
||||
pose_predictor = dlib.shape_predictor(paths.dlib_data_dir + "shape_predictor_5_face_landmarks.dat")
|
||||
face_encoder = dlib.face_recognition_model_v1(paths.dlib_data_dir + "dlib_face_recognition_resnet_model_v1.dat")
|
||||
|
||||
user = builtins.howdy_user
|
||||
# The permanent file to store the encoded model in
|
||||
enc_file = config_path + "/models/" + user + ".dat"
|
||||
enc_file = paths.user_models_dir + user + ".dat"
|
||||
# Known encodings
|
||||
encodings = []
|
||||
|
||||
# Make the ./models folder if it doesn't already exist
|
||||
if not os.path.exists(config_path + "/models"):
|
||||
if not os.path.exists(paths.user_models_dir):
|
||||
print(_("No face model folder found, creating one"))
|
||||
os.makedirs(config_path + "/models")
|
||||
os.makedirs(paths.user_models_dir)
|
||||
|
||||
# To try read a premade encodings file if it exists
|
||||
try:
|
||||
|
|
|
@ -4,21 +4,20 @@
|
|||
import os
|
||||
import sys
|
||||
import builtins
|
||||
import paths
|
||||
|
||||
from i18n import _
|
||||
|
||||
# Get the full path to this file
|
||||
path = "/etc/howdy/models"
|
||||
# Get the passed user
|
||||
user = builtins.howdy_user
|
||||
|
||||
# Check if the models folder is there
|
||||
if not os.path.exists(path):
|
||||
if not os.path.exists(paths.user_models_dir):
|
||||
print(_("No models created yet, can't clear them if they don't exist"))
|
||||
sys.exit(1)
|
||||
|
||||
# Check if the user has a models file to delete
|
||||
if not os.path.isfile(path + "/" + user + ".dat"):
|
||||
if not os.path.isfile(paths.user_models_dir + user + ".dat"):
|
||||
print(_("{} has no models or they have been cleared already").format(user))
|
||||
sys.exit(1)
|
||||
|
||||
|
@ -34,5 +33,5 @@ if not builtins.howdy_args.y:
|
|||
sys.exit(1)
|
||||
|
||||
# Delete otherwise
|
||||
os.remove(path + "/" + user + ".dat")
|
||||
os.remove(paths.user_models_dir + user + ".dat")
|
||||
print(_("\nModels cleared"))
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
# Import required modules
|
||||
import os
|
||||
import subprocess
|
||||
import paths
|
||||
|
||||
from i18n import _
|
||||
|
||||
|
@ -19,4 +20,4 @@ elif os.path.isfile("/etc/alternatives/editor"):
|
|||
editor = "/etc/alternatives/editor"
|
||||
|
||||
# Open the editor as a subprocess and fork it
|
||||
subprocess.call([editor, "/etc/howdy/config.ini"])
|
||||
subprocess.call([editor, paths.config_dir + "config.ini"])
|
||||
|
|
|
@ -6,11 +6,12 @@ import os
|
|||
import builtins
|
||||
import fileinput
|
||||
import configparser
|
||||
import paths
|
||||
|
||||
from i18n import _
|
||||
|
||||
# Get the absolute filepath
|
||||
config_path = os.path.dirname("/etc/howdy") + "/config.ini"
|
||||
config_path = os.path.dirname(paths.config_dir) + "/config.ini"
|
||||
|
||||
# Read config from disk
|
||||
config = configparser.ConfigParser()
|
||||
|
|
|
@ -6,21 +6,20 @@ import os
|
|||
import json
|
||||
import time
|
||||
import builtins
|
||||
import paths
|
||||
|
||||
from i18n import _
|
||||
|
||||
# Get the absolute path and the username
|
||||
path = "/etc/howdy"
|
||||
user = builtins.howdy_user
|
||||
|
||||
# Check if the models file has been created yet
|
||||
if not os.path.exists(path + "/models"):
|
||||
if not os.path.exists(paths.user_models_dir):
|
||||
print(_("Face models have not been initialized yet, please run:"))
|
||||
print("\n\tsudo howdy -U " + user + " add\n")
|
||||
sys.exit(1)
|
||||
|
||||
# Path to the models file
|
||||
enc_file = path + "/models/" + user + ".dat"
|
||||
enc_file = paths.user_models_dir + user + ".dat"
|
||||
|
||||
# Try to load the models file and abort if the user does not have it yet
|
||||
try:
|
||||
|
|
|
@ -5,11 +5,10 @@ import sys
|
|||
import os
|
||||
import json
|
||||
import builtins
|
||||
import paths
|
||||
|
||||
from i18n import _
|
||||
|
||||
# Get the absolute path and the username
|
||||
path = "/etc/howdy"
|
||||
user = builtins.howdy_user
|
||||
|
||||
# Check if enough arguments have been passed
|
||||
|
@ -22,13 +21,13 @@ if not builtins.howdy_args.arguments:
|
|||
sys.exit(1)
|
||||
|
||||
# Check if the models file has been created yet
|
||||
if not os.path.exists(path + "/models"):
|
||||
if not os.path.exists(paths.user_models_dir):
|
||||
print(_("Face models have not been initialized yet, please run:"))
|
||||
print("\n\thowdy add\n")
|
||||
sys.exit(1)
|
||||
|
||||
# Path to the models file
|
||||
enc_file = path + "/models/" + user + ".dat"
|
||||
enc_file = paths.user_models_dir + user + ".dat"
|
||||
|
||||
# Try to load the models file and abort if the user does not have it yet
|
||||
try:
|
||||
|
@ -72,7 +71,7 @@ if not found:
|
|||
|
||||
# Remove the entire file if this encoding is the only one
|
||||
if len(encodings) == 1:
|
||||
os.remove(path + "/models/" + user + ".dat")
|
||||
os.remove(paths.user_models_dir + user + ".dat")
|
||||
print(_("Removed last model, howdy disabled for user"))
|
||||
else:
|
||||
# A place holder to contain the encodings that will remain
|
||||
|
|
|
@ -5,11 +5,12 @@ import sys
|
|||
import os
|
||||
import builtins
|
||||
import fileinput
|
||||
import paths
|
||||
|
||||
from i18n import _
|
||||
|
||||
# Get the absolute filepath
|
||||
config_path = os.path.dirname("/etc/howdy") + "/config.ini"
|
||||
config_path = os.path.dirname(paths.config_dir) + "/config.ini"
|
||||
|
||||
# Check if enough arguments have been passed
|
||||
if len(builtins.howdy_args.arguments) < 2:
|
||||
|
|
|
@ -5,15 +5,14 @@ import os
|
|||
import configparser
|
||||
import datetime
|
||||
import snapshot
|
||||
import paths
|
||||
from recorders.video_capture import VideoCapture
|
||||
|
||||
from i18n import _
|
||||
|
||||
path = "/etc/howdy"
|
||||
|
||||
# Read the config
|
||||
config = configparser.ConfigParser()
|
||||
config.read(path + "/config.ini")
|
||||
config.read(paths.config_dir + "config.ini")
|
||||
|
||||
# Start video capture
|
||||
video_capture = VideoCapture(config)
|
||||
|
|
|
@ -10,6 +10,7 @@ import time
|
|||
import dlib
|
||||
import cv2
|
||||
import numpy as np
|
||||
import paths
|
||||
|
||||
from i18n import _
|
||||
from recorders.video_capture import VideoCapture
|
||||
|
@ -19,7 +20,7 @@ path = "/etc/howdy"
|
|||
|
||||
# Read config from disk
|
||||
config = configparser.ConfigParser()
|
||||
config.read(path + "/config.ini")
|
||||
config.read(paths.config_dir + "config.ini")
|
||||
|
||||
if config.get("video", "recording_plugin", fallback="opencv") != "opencv":
|
||||
print(_("Howdy has been configured to use a recorder which doesn't support the test command yet, aborting"))
|
||||
|
@ -59,20 +60,20 @@ use_cnn = config.getboolean('core', 'use_cnn', fallback=False)
|
|||
|
||||
if use_cnn:
|
||||
face_detector = dlib.cnn_face_detection_model_v1(
|
||||
path + "/dlib-data/mmod_human_face_detector.dat"
|
||||
paths.dlib_data_dir + "mmod_human_face_detector.dat"
|
||||
)
|
||||
else:
|
||||
face_detector = dlib.get_frontal_face_detector()
|
||||
|
||||
pose_predictor = dlib.shape_predictor(path + "/dlib-data/shape_predictor_5_face_landmarks.dat")
|
||||
face_encoder = dlib.face_recognition_model_v1(path + "/dlib-data/dlib_face_recognition_resnet_model_v1.dat")
|
||||
pose_predictor = dlib.shape_predictor(paths.dlib_data_dir + "shape_predictor_5_face_landmarks.dat")
|
||||
face_encoder = dlib.face_recognition_model_v1(paths.dlib_data_dir + "dlib_face_recognition_resnet_model_v1.dat")
|
||||
|
||||
encodings = []
|
||||
models = None
|
||||
|
||||
try:
|
||||
user = builtins.howdy_user
|
||||
models = json.load(open(path + "/models/" + user + ".dat"))
|
||||
models = json.load(open(paths.user_models_dir + user + ".dat"))
|
||||
|
||||
for model in models:
|
||||
encodings += model["data"]
|
||||
|
|
|
@ -23,6 +23,7 @@ import subprocess
|
|||
import snapshot
|
||||
import numpy as np
|
||||
import _thread as thread
|
||||
import paths
|
||||
|
||||
# Allow imports from the local howdy folder
|
||||
sys.path.append('/lib/security/howdy')
|
||||
|
@ -48,22 +49,22 @@ def init_detector(lock):
|
|||
global face_detector, pose_predictor, face_encoder
|
||||
|
||||
# Test if at lest 1 of the data files is there and abort if it's not
|
||||
if not os.path.isfile(PATH + "/dlib-data/shape_predictor_5_face_landmarks.dat"):
|
||||
if not os.path.isfile(paths.dlib_data_dir + "shape_predictor_5_face_landmarks.dat"):
|
||||
print(_("Data files have not been downloaded, please run the following commands:"))
|
||||
print("\n\tcd " + PATH + "/dlib-data")
|
||||
print("\n\tcd " + paths.dlib_data_dir)
|
||||
print("\tsudo ./install.sh\n")
|
||||
lock.release()
|
||||
exit(1)
|
||||
|
||||
# Use the CNN detector if enabled
|
||||
if use_cnn:
|
||||
face_detector = dlib.cnn_face_detection_model_v1(PATH + "/dlib-data/mmod_human_face_detector.dat")
|
||||
face_detector = dlib.cnn_face_detection_model_v1(paths.dlib_data_dir + "mmod_human_face_detector.dat")
|
||||
else:
|
||||
face_detector = dlib.get_frontal_face_detector()
|
||||
|
||||
# Start the others regardless
|
||||
pose_predictor = dlib.shape_predictor(PATH + "/dlib-data/shape_predictor_5_face_landmarks.dat")
|
||||
face_encoder = dlib.face_recognition_model_v1(PATH + "/dlib-data/dlib_face_recognition_resnet_model_v1.dat")
|
||||
pose_predictor = dlib.shape_predictor(paths.dlib_data_dir + "shape_predictor_5_face_landmarks.dat")
|
||||
face_encoder = dlib.face_recognition_model_v1(paths.dlib_data_dir + "dlib_face_recognition_resnet_model_v1.dat")
|
||||
|
||||
# Note the time it took to initialize detectors
|
||||
timings["ll"] = time.time() - timings["ll"]
|
||||
|
@ -103,9 +104,6 @@ def send_to_ui(type, message):
|
|||
if len(sys.argv) < 2:
|
||||
exit(12)
|
||||
|
||||
# Get the absolute path to the config directory
|
||||
PATH = "/etc/howdy"
|
||||
|
||||
# The username of the user being authenticated
|
||||
user = sys.argv[1]
|
||||
# The model file contents
|
||||
|
@ -129,7 +127,7 @@ face_encoder = None
|
|||
|
||||
# Try to load the face model from the models folder
|
||||
try:
|
||||
models = json.load(open(PATH + "/models/" + user + ".dat"))
|
||||
models = json.load(open(paths.user_models_dir + user + ".dat"))
|
||||
|
||||
for model in models:
|
||||
encodings += model["data"]
|
||||
|
@ -142,7 +140,7 @@ if len(models) < 1:
|
|||
|
||||
# Read config from disk
|
||||
config = configparser.ConfigParser()
|
||||
config.read(PATH + "/config.ini")
|
||||
config.read(paths.config_dir + "config.ini")
|
||||
|
||||
# Get all config values needed
|
||||
use_cnn = config.getboolean("core", "use_cnn", fallback=False)
|
||||
|
|
12
howdy/src/paths.py
Normal file
12
howdy/src/paths.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
# Define the absolute path to the config directory
|
||||
config_dir = "/etc/howdy/"
|
||||
|
||||
# Define the absolute path to the DLib models data directory
|
||||
dlib_data_dir = config_dir + "/dlib-data/"
|
||||
|
||||
# Define the absolute path to the Howdy user models directory
|
||||
user_models_dir = config_dir + "/models/"
|
||||
|
||||
# Define path to any howdy logs
|
||||
log_path = "/var/log/howdy"
|
|
@ -49,19 +49,16 @@ def generate(frames, text_lines):
|
|||
|
||||
line_number += 1
|
||||
|
||||
# Define path to any howdy logs
|
||||
log_path = "/var/log/howdy"
|
||||
|
||||
# Made sure a snapshot folder exist
|
||||
if not os.path.exists(log_path):
|
||||
os.makedirs(log_path)
|
||||
if not os.path.exists(log_path + "/snapshots"):
|
||||
os.makedirs(log_path + "/snapshots")
|
||||
if not os.path.exists(paths.log_path):
|
||||
os.makedirs(paths.log_path)
|
||||
if not os.path.exists(paths.log_path + "/snapshots"):
|
||||
os.makedirs(paths.log_path + "/snapshots")
|
||||
|
||||
# Generate a filename based on the current time
|
||||
filename = datetime.datetime.utcnow().strftime("%Y%m%dT%H%M%S.jpg")
|
||||
# Write the image to that file
|
||||
cv2.imwrite(log_path + "/snapshots/" + filename, snap)
|
||||
cv2.imwrite(paths.log_path + "/snapshots/" + filename, snap)
|
||||
|
||||
# Return the saved file location
|
||||
return log_path + "/snapshots/" + filename
|
||||
return paths.log_path + "/snapshots/" + filename
|
||||
|
|
Loading…
Reference in a new issue