mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-12 22:25:24 +03:00
Updates existing configurations by modifying the format of environment variables.
This commit is contained in:
parent
0190fbc1b0
commit
056fa47cf9
@ -3,6 +3,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
from typing import Optional, Union
|
from typing import Optional, Union
|
||||||
|
|
||||||
@ -13,7 +14,7 @@ from frigate.util.services import get_video_properties
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
CURRENT_CONFIG_VERSION = 0.14
|
CURRENT_CONFIG_VERSION = 0.15
|
||||||
|
|
||||||
|
|
||||||
def migrate_frigate_config(config_file: str):
|
def migrate_frigate_config(config_file: str):
|
||||||
@ -55,6 +56,13 @@ def migrate_frigate_config(config_file: str):
|
|||||||
os.path.join(EXPORT_DIR, file), os.path.join(EXPORT_DIR, new_name)
|
os.path.join(EXPORT_DIR, file), os.path.join(EXPORT_DIR, new_name)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if previous_version < 0.15:
|
||||||
|
logger.info(f"Migrating frigate config from {previous_version} to 0.15...")
|
||||||
|
new_config = migrate_015(config)
|
||||||
|
with open(config_file, "w") as f:
|
||||||
|
yaml.dump(new_config, f)
|
||||||
|
previous_version = 0.15
|
||||||
|
|
||||||
logger.info("Finished frigate config migration...")
|
logger.info("Finished frigate config migration...")
|
||||||
|
|
||||||
|
|
||||||
@ -144,6 +152,36 @@ def migrate_014(config: dict[str, dict[str, any]]) -> dict[str, dict[str, any]]:
|
|||||||
return new_config
|
return new_config
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_015(config: dict[str, dict[str, any]]) -> dict[str, dict[str, any]]:
|
||||||
|
"""Handle migrating frigate config to 0.15"""
|
||||||
|
|
||||||
|
def update_placeholders(value):
|
||||||
|
pattern = re.compile(r"(\"|')?\{FRIGATE_[^\}]+\}(\"|')?")
|
||||||
|
if isinstance(value, str):
|
||||||
|
return pattern.sub(replacer, value)
|
||||||
|
elif isinstance(value, dict):
|
||||||
|
return {k: update_placeholders(v) for k, v in value.items()}
|
||||||
|
elif isinstance(value, list):
|
||||||
|
return [update_placeholders(v) for v in value]
|
||||||
|
return value
|
||||||
|
|
||||||
|
def replacer(match):
|
||||||
|
matched_string = match.group(0)
|
||||||
|
# Remove surrounding quotes if they exist
|
||||||
|
if matched_string.startswith(("'", '"')):
|
||||||
|
matched_string = matched_string[1:]
|
||||||
|
if matched_string.endswith(("'", '"')):
|
||||||
|
matched_string = matched_string[:-1]
|
||||||
|
# Replace the prefix
|
||||||
|
return '${' + matched_string[1:]
|
||||||
|
|
||||||
|
new_config = config.copy()
|
||||||
|
new_config = update_placeholders(new_config)
|
||||||
|
new_config["version"] = 0.15
|
||||||
|
|
||||||
|
return new_config
|
||||||
|
|
||||||
|
|
||||||
def get_relative_coordinates(
|
def get_relative_coordinates(
|
||||||
mask: Optional[Union[str, list]], frame_shape: tuple[int, int]
|
mask: Optional[Union[str, list]], frame_shape: tuple[int, int]
|
||||||
) -> Union[str, list]:
|
) -> Union[str, list]:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user