mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-13 20:26:29 +00:00
Fix defaults for builds (#2675)
This commit is contained in:
parent
169c7ec004
commit
09203f67b2
@ -14,6 +14,7 @@ from ..const import (
|
||||
META_ADDON,
|
||||
)
|
||||
from ..coresys import CoreSys, CoreSysAttributes
|
||||
from ..exceptions import ConfigurationFileError
|
||||
from ..utils.common import FileConfiguration, find_one_filetype
|
||||
from .validate import SCHEMA_BUILD_CONFIG
|
||||
|
||||
@ -29,12 +30,14 @@ class AddonBuild(FileConfiguration, CoreSysAttributes):
|
||||
self.coresys: CoreSys = coresys
|
||||
self.addon = addon
|
||||
|
||||
super().__init__(
|
||||
find_one_filetype(
|
||||
try:
|
||||
build_file = find_one_filetype(
|
||||
self.addon.path_location, "build", FILE_SUFFIX_CONFIGURATION
|
||||
),
|
||||
SCHEMA_BUILD_CONFIG,
|
||||
)
|
||||
)
|
||||
except ConfigurationFileError:
|
||||
build_file = self.addon.path_location / "build.json"
|
||||
|
||||
super().__init__(build_file, SCHEMA_BUILD_CONFIG)
|
||||
|
||||
def save_data(self):
|
||||
"""Ignore save function."""
|
||||
|
@ -61,11 +61,11 @@ class StoreData(CoreSysAttributes):
|
||||
slug = extract_hash_from_path(path)
|
||||
|
||||
# exists repository json
|
||||
repository_file = find_one_filetype(
|
||||
path, "repository", FILE_SUFFIX_CONFIGURATION
|
||||
)
|
||||
|
||||
if repository_file is None:
|
||||
try:
|
||||
repository_file = find_one_filetype(
|
||||
path, "repository", FILE_SUFFIX_CONFIGURATION
|
||||
)
|
||||
except ConfigurationFileError:
|
||||
_LOGGER.warning("No repository information exists at %s", path)
|
||||
return
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""Common utils."""
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional
|
||||
from typing import Any, Dict, List
|
||||
|
||||
import voluptuous as vol
|
||||
from voluptuous.humanize import humanize_error
|
||||
@ -15,14 +15,12 @@ _LOGGER: logging.Logger = logging.getLogger(__name__)
|
||||
_DEFAULT: Dict[str, Any] = {}
|
||||
|
||||
|
||||
def find_one_filetype(
|
||||
path: Path, filename: str, filetypes: List[str]
|
||||
) -> Optional[Path]:
|
||||
def find_one_filetype(path: Path, filename: str, filetypes: List[str]) -> Path:
|
||||
"""Find first file matching filetypes."""
|
||||
for file in path.glob(f"**/{filename}.*"):
|
||||
if file.suffix in filetypes:
|
||||
return file
|
||||
return None
|
||||
raise ConfigurationFileError(f"{path!s}/{filename}.({filetypes}) not exists!")
|
||||
|
||||
|
||||
def read_json_or_yaml_file(path: Path) -> dict:
|
||||
|
21
tests/utils/test_common.py
Normal file
21
tests/utils/test_common.py
Normal file
@ -0,0 +1,21 @@
|
||||
"""Test common."""
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from supervisor.exceptions import ConfigurationFileError
|
||||
from supervisor.utils.common import find_one_filetype
|
||||
|
||||
|
||||
def test_not_found(tmp_path):
|
||||
"""Test default."""
|
||||
with pytest.raises(ConfigurationFileError):
|
||||
find_one_filetype(tmp_path, "test", [".json"])
|
||||
|
||||
|
||||
def test_with_found(tmp_path):
|
||||
"""Test default."""
|
||||
test_file = Path(tmp_path, "test.json")
|
||||
test_file.write_text("found")
|
||||
|
||||
assert find_one_filetype(tmp_path, "test", [".json"]) == test_file
|
@ -1,5 +1,9 @@
|
||||
"""test yaml."""
|
||||
|
||||
import pytest
|
||||
|
||||
from supervisor.const import FILE_SUFFIX_CONFIGURATION
|
||||
from supervisor.exceptions import ConfigurationFileError
|
||||
from supervisor.utils.common import find_one_filetype, read_json_or_yaml_file
|
||||
from supervisor.utils.json import write_json_file
|
||||
from supervisor.utils.yaml import read_yaml_file, write_yaml_file
|
||||
@ -32,8 +36,8 @@ def test_get_file_from_type(tmp_path):
|
||||
|
||||
tempfile = tmp_path / "test.config"
|
||||
write_yaml_file(tempfile, {"test": "test"})
|
||||
found = find_one_filetype(tmp_path, "test4", FILE_SUFFIX_CONFIGURATION)
|
||||
assert not found
|
||||
with pytest.raises(ConfigurationFileError):
|
||||
find_one_filetype(tmp_path, "test4", FILE_SUFFIX_CONFIGURATION)
|
||||
|
||||
|
||||
def test_read_json_or_yaml_file(tmp_path):
|
||||
|
Loading…
x
Reference in New Issue
Block a user