mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-11 13:45:25 +03:00
Update config version to be stored inside of the config
This commit is contained in:
parent
63d81bef45
commit
fc032cff9b
@ -1355,6 +1355,7 @@ class FrigateConfig(FrigateBaseModel):
|
|||||||
default_factory=TimestampStyleConfig,
|
default_factory=TimestampStyleConfig,
|
||||||
title="Global timestamp style configuration.",
|
title="Global timestamp style configuration.",
|
||||||
)
|
)
|
||||||
|
version: Optional[float] = Field(default=None, title="Current config version.")
|
||||||
|
|
||||||
def runtime_config(self, plus_api: PlusApi = None) -> FrigateConfig:
|
def runtime_config(self, plus_api: PlusApi = None) -> FrigateConfig:
|
||||||
"""Merge camera config with globals."""
|
"""Merge camera config with globals."""
|
||||||
|
|||||||
@ -17,16 +17,13 @@ CURRENT_CONFIG_VERSION = 0.14
|
|||||||
def migrate_frigate_config(config_file: str):
|
def migrate_frigate_config(config_file: str):
|
||||||
"""handle migrating the frigate config."""
|
"""handle migrating the frigate config."""
|
||||||
logger.info("Checking if frigate config needs migration...")
|
logger.info("Checking if frigate config needs migration...")
|
||||||
version_file = os.path.join(CONFIG_DIR, ".version")
|
|
||||||
|
|
||||||
if not os.path.isfile(version_file):
|
yaml = YAML()
|
||||||
previous_version = 0.13
|
yaml.indent(mapping=2, sequence=4, offset=2)
|
||||||
else:
|
with open(config_file, "r") as f:
|
||||||
with open(version_file) as f:
|
config: dict[str, dict[str, any]] = yaml.load(f)
|
||||||
try:
|
|
||||||
previous_version = float(f.readline())
|
previous_version = config.get("version", 0.13)
|
||||||
except Exception:
|
|
||||||
previous_version = 0.13
|
|
||||||
|
|
||||||
if previous_version == CURRENT_CONFIG_VERSION:
|
if previous_version == CURRENT_CONFIG_VERSION:
|
||||||
logger.info("frigate config does not need migration...")
|
logger.info("frigate config does not need migration...")
|
||||||
@ -35,11 +32,6 @@ def migrate_frigate_config(config_file: str):
|
|||||||
logger.info("copying config as backup...")
|
logger.info("copying config as backup...")
|
||||||
shutil.copy(config_file, os.path.join(CONFIG_DIR, "backup_config.yaml"))
|
shutil.copy(config_file, os.path.join(CONFIG_DIR, "backup_config.yaml"))
|
||||||
|
|
||||||
yaml = YAML()
|
|
||||||
yaml.indent(mapping=2, sequence=4, offset=2)
|
|
||||||
with open(config_file, "r") as f:
|
|
||||||
config: dict[str, dict[str, any]] = yaml.load(f)
|
|
||||||
|
|
||||||
if previous_version < 0.14:
|
if previous_version < 0.14:
|
||||||
logger.info(f"Migrating frigate config from {previous_version} to 0.14...")
|
logger.info(f"Migrating frigate config from {previous_version} to 0.14...")
|
||||||
new_config = migrate_014(config)
|
new_config = migrate_014(config)
|
||||||
@ -57,9 +49,6 @@ 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)
|
||||||
)
|
)
|
||||||
|
|
||||||
with open(version_file, "w") as f:
|
|
||||||
f.write(str(CURRENT_CONFIG_VERSION))
|
|
||||||
|
|
||||||
logger.info("Finished frigate config migration...")
|
logger.info("Finished frigate config migration...")
|
||||||
|
|
||||||
|
|
||||||
@ -141,6 +130,7 @@ def migrate_014(config: dict[str, dict[str, any]]) -> dict[str, dict[str, any]]:
|
|||||||
|
|
||||||
new_config["cameras"][name] = camera_config
|
new_config["cameras"][name] = camera_config
|
||||||
|
|
||||||
|
new_config["version"] = 0.14
|
||||||
return new_config
|
return new_config
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user