updating to latest
This commit is contained in:
30
custom_components/hacs/helpers/methods/__init__.py
Normal file
30
custom_components/hacs/helpers/methods/__init__.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# pylint: disable=missing-class-docstring,missing-module-docstring,missing-function-docstring,no-member
|
||||
from custom_components.hacs.helpers.methods.installation import (
|
||||
RepositoryMethodInstall,
|
||||
RepositoryMethodPostInstall,
|
||||
RepositoryMethodPreInstall,
|
||||
)
|
||||
from custom_components.hacs.helpers.methods.registration import (
|
||||
RepositoryMethodPostRegistration,
|
||||
RepositoryMethodPreRegistration,
|
||||
RepositoryMethodRegistration,
|
||||
)
|
||||
from custom_components.hacs.helpers.methods.reinstall_if_needed import (
|
||||
RepositoryMethodReinstallIfNeeded,
|
||||
)
|
||||
|
||||
|
||||
class RepositoryHelperMethods(
|
||||
RepositoryMethodReinstallIfNeeded,
|
||||
RepositoryMethodInstall,
|
||||
RepositoryMethodPostInstall,
|
||||
RepositoryMethodPreInstall,
|
||||
RepositoryMethodPreRegistration,
|
||||
RepositoryMethodRegistration,
|
||||
RepositoryMethodPostRegistration,
|
||||
):
|
||||
"""Collection of repository methods that are nested to all repositories."""
|
||||
|
||||
|
||||
class HacsHelperMethods:
|
||||
"""Helper class for HACS methods"""
|
||||
113
custom_components/hacs/helpers/methods/installation.py
Normal file
113
custom_components/hacs/helpers/methods/installation.py
Normal file
@@ -0,0 +1,113 @@
|
||||
# pylint: disable=missing-class-docstring,missing-module-docstring,missing-function-docstring,no-member
|
||||
from abc import ABC
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
from custom_components.hacs.exceptions import HacsException
|
||||
from custom_components.hacs.helpers.functions.download import download_content
|
||||
from custom_components.hacs.helpers.functions.version_to_install import (
|
||||
version_to_install,
|
||||
)
|
||||
from custom_components.hacs.operational.backup import Backup, BackupNetDaemon
|
||||
from custom_components.hacs.share import get_hacs
|
||||
|
||||
|
||||
class RepositoryMethodPreInstall(ABC):
|
||||
async def async_pre_install(self) -> None:
|
||||
pass
|
||||
|
||||
async def _async_pre_install(self) -> None:
|
||||
self.logger.info("Running pre installation steps")
|
||||
await self.async_pre_install()
|
||||
self.logger.info("Pre installation steps completed")
|
||||
|
||||
|
||||
class RepositoryMethodInstall(ABC):
|
||||
async def async_install(self) -> None:
|
||||
await self._async_pre_install()
|
||||
self.logger.info("Running installation steps")
|
||||
await async_install_repository(self)
|
||||
self.logger.info("Installation steps completed")
|
||||
await self._async_post_install()
|
||||
|
||||
|
||||
class RepositoryMethodPostInstall(ABC):
|
||||
async def async_post_installation(self) -> None:
|
||||
pass
|
||||
|
||||
async def _async_post_install(self) -> None:
|
||||
self.logger.info("Running post installation steps")
|
||||
await self.async_post_installation()
|
||||
self.data.new = False
|
||||
self.hacs.hass.bus.async_fire(
|
||||
"hacs/repository",
|
||||
{"id": 1337, "action": "install", "repository": self.data.full_name},
|
||||
)
|
||||
self.logger.info("Post installation steps completed")
|
||||
|
||||
|
||||
async def async_install_repository(repository):
|
||||
"""Common installation steps of the repository."""
|
||||
hacs = get_hacs()
|
||||
persistent_directory = None
|
||||
await repository.update_repository()
|
||||
if repository.content.path.local is None:
|
||||
raise HacsException("repository.content.path.local is None")
|
||||
repository.validate.errors = []
|
||||
|
||||
if not repository.can_install:
|
||||
raise HacsException("The version of Home Assistant is not compatible with this version")
|
||||
|
||||
version = version_to_install(repository)
|
||||
if version == repository.data.default_branch:
|
||||
repository.ref = version
|
||||
else:
|
||||
repository.ref = f"tags/{version}"
|
||||
|
||||
if repository.data.installed and repository.data.category == "netdaemon":
|
||||
persistent_directory = await hacs.hass.async_add_executor_job(BackupNetDaemon, repository)
|
||||
await hacs.hass.async_add_executor_job(persistent_directory.create)
|
||||
|
||||
elif repository.data.persistent_directory:
|
||||
if os.path.exists(
|
||||
f"{repository.content.path.local}/{repository.data.persistent_directory}"
|
||||
):
|
||||
persistent_directory = Backup(
|
||||
f"{repository.content.path.local}/{repository.data.persistent_directory}",
|
||||
tempfile.gettempdir() + "/hacs_persistent_directory/",
|
||||
)
|
||||
await hacs.hass.async_add_executor_job(persistent_directory.create)
|
||||
|
||||
if repository.data.installed and not repository.content.single:
|
||||
backup = Backup(repository.content.path.local)
|
||||
await hacs.hass.async_add_executor_job(backup.create)
|
||||
|
||||
if repository.data.zip_release and version != repository.data.default_branch:
|
||||
await repository.download_zip_files(repository.validate)
|
||||
else:
|
||||
await download_content(repository)
|
||||
|
||||
if repository.validate.errors:
|
||||
for error in repository.validate.errors:
|
||||
repository.logger.error(error)
|
||||
if repository.data.installed and not repository.content.single:
|
||||
await hacs.hass.async_add_executor_job(backup.restore)
|
||||
|
||||
if repository.data.installed and not repository.content.single:
|
||||
await hacs.hass.async_add_executor_job(backup.cleanup)
|
||||
|
||||
if persistent_directory is not None:
|
||||
await hacs.hass.async_add_executor_job(persistent_directory.restore)
|
||||
await hacs.hass.async_add_executor_job(persistent_directory.cleanup)
|
||||
|
||||
if repository.validate.success:
|
||||
if repository.data.full_name not in repository.hacs.common.installed:
|
||||
if repository.data.full_name == "hacs/integration":
|
||||
repository.hacs.common.installed.append(repository.data.full_name)
|
||||
repository.data.installed = True
|
||||
repository.data.installed_commit = repository.data.last_commit
|
||||
|
||||
if version == repository.data.default_branch:
|
||||
repository.data.installed_version = None
|
||||
else:
|
||||
repository.data.installed_version = version
|
||||
41
custom_components/hacs/helpers/methods/registration.py
Normal file
41
custom_components/hacs/helpers/methods/registration.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# pylint: disable=missing-class-docstring,missing-module-docstring,missing-function-docstring,no-member, attribute-defined-outside-init
|
||||
from abc import ABC
|
||||
|
||||
from custom_components.hacs.validate import async_run_repository_checks
|
||||
|
||||
|
||||
class RepositoryMethodPreRegistration(ABC):
|
||||
async def async_pre_registration(self):
|
||||
pass
|
||||
|
||||
|
||||
class RepositoryMethodRegistration(ABC):
|
||||
async def registration(self, ref=None) -> None:
|
||||
self.logger.warning("'registration' is deprecated, use 'async_registration' instead")
|
||||
await self.async_registration(ref)
|
||||
|
||||
async def async_registration(self, ref=None) -> None:
|
||||
# Run local pre registration steps.
|
||||
await self.async_pre_registration()
|
||||
|
||||
if ref is not None:
|
||||
self.data.selected_tag = ref
|
||||
self.ref = ref
|
||||
self.force_branch = True
|
||||
|
||||
if not await self.validate_repository():
|
||||
return False
|
||||
|
||||
# Run common registration steps.
|
||||
await self.common_registration()
|
||||
|
||||
# Set correct local path
|
||||
self.content.path.local = self.localpath
|
||||
|
||||
# Run local post registration steps.
|
||||
await self.async_post_registration()
|
||||
|
||||
|
||||
class RepositoryMethodPostRegistration(ABC):
|
||||
async def async_post_registration(self):
|
||||
await async_run_repository_checks(self)
|
||||
@@ -0,0 +1,12 @@
|
||||
# pylint: disable=missing-class-docstring,missing-module-docstring,missing-function-docstring,no-member
|
||||
from abc import ABC
|
||||
|
||||
from custom_components.hacs.helpers.functions.path_exsist import async_path_exsist
|
||||
|
||||
|
||||
class RepositoryMethodReinstallIfNeeded(ABC):
|
||||
async def async_reinstall_if_needed(self) -> None:
|
||||
if self.data.installed:
|
||||
if not await async_path_exsist(self.content.path.local):
|
||||
self.logger.error("Missing from local FS, should be reinstalled.")
|
||||
# await self.async_install()
|
||||
Reference in New Issue
Block a user