Ignore all files and directories that starts with . (#3094)

* Ignore all files and directories that starts with .

* pylint

* Check all parts
This commit is contained in:
Joakim Sørensen 2021-09-01 12:50:44 +02:00 committed by GitHub
parent 4ea3695982
commit 966b962ccf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 5 deletions

View File

@ -1,7 +1,7 @@
"""Init file for Supervisor add-on data."""
import logging
from pathlib import Path
from typing import Any, Dict
from typing import Any, Dict, Optional
import voluptuous as vol
from voluptuous.humanize import humanize_error
@ -86,15 +86,14 @@ class StoreData(CoreSysAttributes):
self.repositories[slug] = repository_info
self._read_addons_folder(path, slug)
def _read_addons_folder(self, path: Path, repository: Dict) -> None:
"""Read data from add-ons folder."""
def _find_addons(self, path: Path, repository: Dict) -> Optional[list[Path]]:
"""Find add-ons in the path."""
try:
# Generate a list without artefact, safe for corruptions
addon_list = [
addon
for addon in path.glob("**/config.*")
if ".git" not in addon.parts
and ".github" not in addon.parts
if not [part for part in addon.parts if part.startswith(".")]
and addon.suffix in FILE_SUFFIX_CONFIGURATION
]
except OSError as err:
@ -110,6 +109,12 @@ class StoreData(CoreSysAttributes):
_LOGGER.critical(
"Can't process %s because of Filesystem issues: %s", repository, err
)
return None
return addon_list
def _read_addons_folder(self, path: Path, repository: Dict) -> None:
"""Read data from add-ons folder."""
if not (addon_list := self._find_addons(path, repository)):
return
for addon in addon_list:

View File

@ -0,0 +1,24 @@
"""Test that we are reading add-on files correctly."""
from pathlib import Path
from unittest.mock import patch
from supervisor.coresys import CoreSys
def test_read_addon_files(coresys: CoreSys):
"""Test that we are reading add-on files correctly."""
with patch(
"pathlib.Path.glob",
return_value=[
Path("addon/config.yml"),
Path(".git/config.yml"),
Path("somepath/.git/config.yml"),
Path("somepath/deeper_in_the_structure/.github/config.yml"),
Path(".github/config.yml"),
Path(".circleci/config.yml"),
],
):
addon_list = coresys.store.data._find_addons(Path("test"), {})
assert len(addon_list) == 1
assert str(addon_list[0]) == "addon/config.yml"