Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize handling of config files #15451

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 4 additions & 22 deletions frigate/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
from frigate.api.defs.request.app_body import AppConfigSetBody
from frigate.api.defs.tags import Tags
from frigate.config import FrigateConfig
from frigate.const import CONFIG_DIR
from frigate.models import Event, Timeline
from frigate.util.builtin import (
clean_camera_user_pass,
get_tz_modifiers,
update_yaml_from_url,
)
from frigate.util.config import find_config_file
from frigate.util.services import (
ffprobe_stream,
get_nvidia_driver_info,
Expand Down Expand Up @@ -147,13 +147,7 @@ def config(request: Request):

@router.get("/config/raw")
def config_raw():
config_file = os.environ.get("CONFIG_FILE", "/config/config.yml")

# Check if we can use .yaml instead of .yml
config_file_yaml = config_file.replace(".yml", ".yaml")

if os.path.isfile(config_file_yaml):
config_file = config_file_yaml
config_file = find_config_file()

if not os.path.isfile(config_file):
return JSONResponse(
Expand Down Expand Up @@ -198,13 +192,7 @@ def config_save(save_option: str, body: Any = Body(media_type="text/plain")):

# Save the config to file
try:
config_file = os.environ.get("CONFIG_FILE", "/config/config.yml")

# Check if we can use .yaml instead of .yml
config_file_yaml = config_file.replace(".yml", ".yaml")

if os.path.isfile(config_file_yaml):
config_file = config_file_yaml
config_file = find_config_file()

with open(config_file, "w") as f:
f.write(new_config)
Expand Down Expand Up @@ -253,13 +241,7 @@ def config_save(save_option: str, body: Any = Body(media_type="text/plain")):

@router.put("/config/set")
def config_set(request: Request, body: AppConfigSetBody):
config_file = os.environ.get("CONFIG_FILE", f"{CONFIG_DIR}/config.yml")

# Check if we can use .yaml instead of .yml
config_file_yaml = config_file.replace(".yml", ".yaml")

if os.path.isfile(config_file_yaml):
config_file = config_file_yaml
config_file = find_config_file()

with open(config_file, "r") as f:
old_raw_config = f.read()
Expand Down
9 changes: 3 additions & 6 deletions frigate/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
)
from frigate.util.config import (
StreamInfoRetriever,
find_config_file,
get_relative_coordinates,
migrate_frigate_config,
)
Expand Down Expand Up @@ -67,7 +68,6 @@

yaml = YAML()

DEFAULT_CONFIG_FILE = "/config/config.yml"
DEFAULT_CONFIG = """
mqtt:
enabled: False
Expand Down Expand Up @@ -638,16 +638,13 @@ def ensure_zones_and_cameras_have_different_names(cls, v: Dict[str, CameraConfig

@classmethod
def load(cls, **kwargs):
config_path = os.environ.get("CONFIG_FILE", DEFAULT_CONFIG_FILE)

if not os.path.isfile(config_path):
config_path = config_path.replace("yml", "yaml")
config_path = find_config_file()

# No configuration file found, create one.
new_config = False
if not os.path.isfile(config_path):
logger.info("No config file found, saving default config")
config_path = DEFAULT_CONFIG_FILE
config_path = config_path
new_config = True
else:
# Check if the config file needs to be migrated.
Expand Down
6 changes: 3 additions & 3 deletions frigate/detectors/plugins/rknn.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,17 @@ def download_model(self, filename):
def check_config(self, config):
if (config.model.width != 320) or (config.model.height != 320):
raise Exception(
"Make sure to set the model width and height to 320 in your config.yml."
"Make sure to set the model width and height to 320 in your config."
)

if config.model.input_pixel_format != "bgr":
raise Exception(
'Make sure to set the model input_pixel_format to "bgr" in your config.yml.'
'Make sure to set the model input_pixel_format to "bgr" in your config.'
)

if config.model.input_tensor != "nhwc":
raise Exception(
'Make sure to set the model input_tensor to "nhwc" in your config.yml.'
'Make sure to set the model input_tensor to "nhwc" in your config.'
)

def detect_raw(self, tensor_input):
Expand Down
11 changes: 2 additions & 9 deletions frigate/ptz/autotrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import copy
import logging
import os
import queue
import threading
import time
Expand All @@ -29,11 +28,11 @@
AUTOTRACKING_ZOOM_EDGE_THRESHOLD,
AUTOTRACKING_ZOOM_IN_HYSTERESIS,
AUTOTRACKING_ZOOM_OUT_HYSTERESIS,
CONFIG_DIR,
)
from frigate.ptz.onvif import OnvifController
from frigate.track.tracked_object import TrackedObject
from frigate.util.builtin import update_yaml_file
from frigate.util.config import find_config_file
from frigate.util.image import SharedMemoryFrameManager, intersection_over_union

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -328,13 +327,7 @@ def _autotracker_setup(self, camera_config: CameraConfig, camera: str):
self.autotracker_init[camera] = True

def _write_config(self, camera):
config_file = os.environ.get("CONFIG_FILE", f"{CONFIG_DIR}/config.yml")

# Check if we can use .yaml instead of .yml
config_file_yaml = config_file.replace(".yml", ".yaml")

if os.path.isfile(config_file_yaml):
config_file = config_file_yaml
config_file = find_config_file()

logger.debug(
f"{camera}: Writing new config with autotracker motion coefficients: {self.config.cameras[camera].onvif.autotracking.movement_weights}"
Expand Down
10 changes: 10 additions & 0 deletions frigate/util/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
logger = logging.getLogger(__name__)

CURRENT_CONFIG_VERSION = "0.15-0"
DEFAULT_CONFIG_FILE = "/config/config.yml"


def find_config_file() -> str:
config_path = os.environ.get("CONFIG_FILE", DEFAULT_CONFIG_FILE)

if not os.path.isfile(config_path):
config_path = config_path.replace("yml", "yaml")

return config_path


def migrate_frigate_config(config_file: str):
Expand Down
Loading