Skip to content

Commit

Permalink
refactor: use only paths_factory
Browse files Browse the repository at this point in the history
  • Loading branch information
saidsay-so committed Jun 25, 2023
1 parent 54ba84e commit 1f8ee26
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 26 deletions.
7 changes: 3 additions & 4 deletions howdy/src/cli/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import configparser
import builtins
import numpy as np
import paths
import paths_factory

from recorders.video_capture import VideoCapture
Expand All @@ -31,7 +30,7 @@
# 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()):
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")
sys.exit(1)

Expand All @@ -55,9 +54,9 @@
encodings = []

# 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"))
os.makedirs(paths.user_models_dir)
os.makedirs(paths_factory.user_models_dir_path())

# To try read a premade encodings file if it exists
try:
Expand Down
3 changes: 1 addition & 2 deletions howdy/src/cli/clear.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os
import sys
import builtins
import paths
import paths_factory

from i18n import _
Expand All @@ -13,7 +12,7 @@
user = builtins.howdy_user

# 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"))
sys.exit(1)

Expand Down
3 changes: 1 addition & 2 deletions howdy/src/cli/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
import json
import time
import builtins
import paths
import paths_factory

from i18n import _

user = builtins.howdy_user

# 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("\n\tsudo howdy -U " + user + " add\n")
sys.exit(1)
Expand Down
3 changes: 1 addition & 2 deletions howdy/src/cli/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import os
import json
import builtins
import paths
import paths_factory

from i18n import _
Expand All @@ -22,7 +21,7 @@
sys.exit(1)

# 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("\n\thowdy add\n")
sys.exit(1)
Expand Down
3 changes: 1 addition & 2 deletions howdy/src/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import snapshot
import numpy as np
import _thread as thread
import paths
import paths_factory
from recorders.video_capture import VideoCapture
from i18n import _
Expand All @@ -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
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("\n\tcd " + str(paths.dlib_data_dir))
print("\n\tcd " + paths_factory.dlib_data_dir_path())
print("\tsudo ./install.sh\n")
lock.release()
exit(1)
Expand Down
37 changes: 23 additions & 14 deletions howdy/src/paths_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,41 @@
]


def shape_predictor_5_face_landmarks_path() -> PurePath:
return paths.dlib_data_dir / models[0]
def dlib_data_dir_path() -> str:
return str(paths.dlib_data_dir)


def mmod_human_face_detector_path() -> PurePath:
return paths.dlib_data_dir / models[1]
def shape_predictor_5_face_landmarks_path() -> str:
return str(paths.dlib_data_dir / models[0])


def dlib_face_recognition_resnet_model_v1_path() -> PurePath:
return paths.dlib_data_dir / models[2]
def mmod_human_face_detector_path() -> str:
return str(paths.dlib_data_dir / models[1])


def user_model_path(user: str) -> PurePath:
return paths.user_models_dir / f"{user}.dat"
def dlib_face_recognition_resnet_model_v1_path() -> str:
return str(paths.dlib_data_dir / models[2])


def config_file_path() -> PurePath:
return paths.config_dir / "config.ini"
def user_model_path(user: str) -> str:
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:
return paths.log_path / "snapshots"


def snapshot_path(snapshot: str) -> PurePath:
return snapshots_dir_path() / snapshot
def snapshot_path(snapshot: str) -> str:
return str(snapshots_dir_path() / snapshot)


def user_models_dir_path() -> str:
return str(paths.user_models_dir)


def logo_path() -> PurePath:
return paths.data_dir / "logo.png"
def logo_path() -> str:
return str(paths.data_dir / "logo.png")

0 comments on commit 1f8ee26

Please sign in to comment.