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

refactor: use only paths_factory

This commit is contained in:
Sayafdine Said 2023-06-25 18:45:17 +02:00
parent 54ba84e033
commit 1f8ee26d3d
No known key found for this signature in database
GPG key ID: 7567D43648C6E2F4
6 changed files with 30 additions and 26 deletions

View file

@ -8,7 +8,6 @@ import json
import configparser import configparser
import builtins import builtins
import numpy as np import numpy as np
import paths
import paths_factory import paths_factory
from recorders.video_capture import VideoCapture from recorders.video_capture import VideoCapture
@ -31,7 +30,7 @@ import cv2
# Test if at lest 1 of the data files is there and abort if it's not # Test if at lest 1 of the data files is there and abort if it's not
if not os.path.isfile(paths_factory.shape_predictor_5_face_landmarks_path()): if not os.path.isfile(paths_factory.shape_predictor_5_face_landmarks_path()):
print(_("Data files have not been downloaded, please run the following commands:")) print(_("Data files have not been downloaded, please run the following commands:"))
print("\n\tcd " + str(paths.dlib_data_dir)) print("\n\tcd " + paths_factory.dlib_data_dir_path())
print("\tsudo ./install.sh\n") print("\tsudo ./install.sh\n")
sys.exit(1) sys.exit(1)
@ -55,9 +54,9 @@ enc_file = str(paths_factory.user_model_path(user))
encodings = [] encodings = []
# Make the ./models folder if it doesn't already exist # Make the ./models folder if it doesn't already exist
if not os.path.exists(paths.user_models_dir): if not os.path.exists(paths_factory.user_models_dir_path()):
print(_("No face model folder found, creating one")) print(_("No face model folder found, creating one"))
os.makedirs(paths.user_models_dir) os.makedirs(paths_factory.user_models_dir_path())
# To try read a premade encodings file if it exists # To try read a premade encodings file if it exists
try: try:

View file

@ -4,7 +4,6 @@
import os import os
import sys import sys
import builtins import builtins
import paths
import paths_factory import paths_factory
from i18n import _ from i18n import _
@ -13,7 +12,7 @@ from i18n import _
user = builtins.howdy_user user = builtins.howdy_user
# Check if the models folder is there # Check if the models folder is there
if not os.path.exists(paths.user_models_dir): if not os.path.exists(paths_factory.user_models_dir_path()):
print(_("No models created yet, can't clear them if they don't exist")) print(_("No models created yet, can't clear them if they don't exist"))
sys.exit(1) sys.exit(1)

View file

@ -6,7 +6,6 @@ import os
import json import json
import time import time
import builtins import builtins
import paths
import paths_factory import paths_factory
from i18n import _ from i18n import _
@ -14,7 +13,7 @@ from i18n import _
user = builtins.howdy_user user = builtins.howdy_user
# Check if the models file has been created yet # Check if the models file has been created yet
if not os.path.exists(paths.user_models_dir): if not os.path.exists(paths_factory.user_models_dir_path()):
print(_("Face models have not been initialized yet, please run:")) print(_("Face models have not been initialized yet, please run:"))
print("\n\tsudo howdy -U " + user + " add\n") print("\n\tsudo howdy -U " + user + " add\n")
sys.exit(1) sys.exit(1)

View file

@ -5,7 +5,6 @@ import sys
import os import os
import json import json
import builtins import builtins
import paths
import paths_factory import paths_factory
from i18n import _ from i18n import _
@ -22,7 +21,7 @@ if not builtins.howdy_args.arguments:
sys.exit(1) sys.exit(1)
# Check if the models file has been created yet # Check if the models file has been created yet
if not os.path.exists(paths.user_models_dir): if not os.path.exists(paths_factory.user_models_dir_path()):
print(_("Face models have not been initialized yet, please run:")) print(_("Face models have not been initialized yet, please run:"))
print("\n\thowdy add\n") print("\n\thowdy add\n")
sys.exit(1) sys.exit(1)

View file

@ -23,7 +23,6 @@ import subprocess
import snapshot import snapshot
import numpy as np import numpy as np
import _thread as thread import _thread as thread
import paths
import paths_factory import paths_factory
from recorders.video_capture import VideoCapture from recorders.video_capture import VideoCapture
from i18n import _ from i18n import _
@ -48,7 +47,7 @@ def init_detector(lock):
# Test if at lest 1 of the data files is there and abort if it's not # Test if at lest 1 of the data files is there and abort if it's not
if not os.path.isfile(str(paths_factory.shape_predictor_5_face_landmarks_path())): if not os.path.isfile(str(paths_factory.shape_predictor_5_face_landmarks_path())):
print(_("Data files have not been downloaded, please run the following commands:")) print(_("Data files have not been downloaded, please run the following commands:"))
print("\n\tcd " + str(paths.dlib_data_dir)) print("\n\tcd " + paths_factory.dlib_data_dir_path())
print("\tsudo ./install.sh\n") print("\tsudo ./install.sh\n")
lock.release() lock.release()
exit(1) exit(1)

View file

@ -8,32 +8,41 @@ models = [
] ]
def shape_predictor_5_face_landmarks_path() -> PurePath: def dlib_data_dir_path() -> str:
return paths.dlib_data_dir / models[0] return str(paths.dlib_data_dir)
def mmod_human_face_detector_path() -> PurePath: def shape_predictor_5_face_landmarks_path() -> str:
return paths.dlib_data_dir / models[1] return str(paths.dlib_data_dir / models[0])
def dlib_face_recognition_resnet_model_v1_path() -> PurePath: def mmod_human_face_detector_path() -> str:
return paths.dlib_data_dir / models[2] return str(paths.dlib_data_dir / models[1])
def user_model_path(user: str) -> PurePath: def dlib_face_recognition_resnet_model_v1_path() -> str:
return paths.user_models_dir / f"{user}.dat" return str(paths.dlib_data_dir / models[2])
def config_file_path() -> PurePath: def user_model_path(user: str) -> str:
return paths.config_dir / "config.ini" return str(paths.user_models_dir / f"{user}.dat")
def config_file_path() -> str:
return str(paths.config_dir / "config.ini")
def snapshots_dir_path() -> PurePath: def snapshots_dir_path() -> PurePath:
return paths.log_path / "snapshots" return paths.log_path / "snapshots"
def snapshot_path(snapshot: str) -> PurePath: def snapshot_path(snapshot: str) -> str:
return snapshots_dir_path() / snapshot return str(snapshots_dir_path() / snapshot)
def logo_path() -> PurePath:
return paths.data_dir / "logo.png" def user_models_dir_path() -> str:
return str(paths.user_models_dir)
def logo_path() -> str:
return str(paths.data_dir / "logo.png")