Alexa Media Player ADDED - #421 - Added some test Notifications. (HA restart targetted notification)

This commit is contained in:
ccostan
2020-05-03 16:23:17 -04:00
parent 0c8345389b
commit 457bc114e8
41 changed files with 315 additions and 126 deletions

View File

@@ -1,7 +1,9 @@
"""Helpers to download repository content."""
import os
import pathlib
import tempfile
import zipfile
from queueman import QueueManager, concurrent
from custom_components.hacs.hacsbase.exceptions import HacsException
from custom_components.hacs.handler.download import async_download_file, async_save_file
from custom_components.hacs.helpers.filters import filter_content_return_one_of_type
@@ -123,6 +125,8 @@ async def download_zip(repository, validate):
) as zip_file:
zip_file.extractall(repository.content.path.local)
os.remove(f"{tempfile.gettempdir()}/{repository.data.filename}")
if result:
repository.logger.info(f"download of {content.name} complete")
continue
@@ -135,6 +139,7 @@ async def download_zip(repository, validate):
async def download_content(repository):
"""Download the content of a directory."""
queue = QueueManager()
contents = gather_files_to_download(repository)
repository.logger.debug(repository.data.filename)
if not contents:
@@ -144,38 +149,44 @@ async def download_content(repository):
if repository.data.content_in_root and repository.data.filename:
if content.name != repository.data.filename:
continue
repository.logger.debug(f"Downloading {content.name}")
queue.add(dowload_repository_content(repository, content))
await queue.execute()
filecontent = await async_download_file(content.download_url)
if filecontent is None:
repository.validate.errors.append(f"[{content.name}] was not downloaded.")
continue
@concurrent(10)
async def dowload_repository_content(repository, content):
"""Download content."""
repository.logger.debug(f"Downloading {content.name}")
# Save the content of the file.
if repository.content.single or content.path is None:
local_directory = repository.content.path.local
filecontent = await async_download_file(content.download_url)
else:
_content_path = content.path
if not repository.data.content_in_root:
_content_path = _content_path.replace(
f"{repository.content.path.remote}", ""
)
local_directory = f"{repository.content.path.local}/{_content_path}"
local_directory = local_directory.split("/")
del local_directory[-1]
local_directory = "/".join(local_directory)
# Check local directory
pathlib.Path(local_directory).mkdir(parents=True, exist_ok=True)
local_file_path = (f"{local_directory}/{content.name}").replace("//", "/")
result = await async_save_file(local_file_path, filecontent)
if result:
repository.logger.info(f"download of {content.name} complete")
continue
if filecontent is None:
repository.validate.errors.append(f"[{content.name}] was not downloaded.")
return
# Save the content of the file.
if repository.content.single or content.path is None:
local_directory = repository.content.path.local
else:
_content_path = content.path
if not repository.data.content_in_root:
_content_path = _content_path.replace(
f"{repository.content.path.remote}", ""
)
local_directory = f"{repository.content.path.local}/{_content_path}"
local_directory = local_directory.split("/")
del local_directory[-1]
local_directory = "/".join(local_directory)
# Check local directory
pathlib.Path(local_directory).mkdir(parents=True, exist_ok=True)
local_file_path = (f"{local_directory}/{content.name}").replace("//", "/")
result = await async_save_file(local_file_path, filecontent)
if result:
repository.logger.info(f"download of {content.name} complete")
return
repository.validate.errors.append(f"[{content.name}] was not downloaded.")

View File

@@ -30,7 +30,9 @@ async def get_info_md_content(repository):
info = info.content.replace("<svg", "<disabled").replace("</svg", "</disabled")
return render_template(info, repository)
except (AIOGitHubException, Exception): # pylint: disable=broad-except
return ""
if repository.hacs.action:
raise HacsException("No info file found")
return ""
async def get_repository(session, token, repository_full_name):
@@ -84,11 +86,19 @@ async def get_integration_manifest(repository):
repository.data.manifest_name = manifest["name"]
repository.data.homeassistant = manifest.get("homeassistant")
if repository.hacs.action:
if manifest.get("documentation") is None:
raise HacsException("manifest.json is missing documentation")
if manifest.get("homeassistant") is not None:
raise HacsException(
"The homeassistant key in manifest.json is no longer valid"
)
# Set local path
repository.content.path.local = repository.localpath
except KeyError as exception:
raise HacsException(f"Missing expected key {exception} in 'manifest.json'")
raise HacsException(f"Missing expected key {exception} in '{manifest_path}'")
def find_file_name(repository):

View File

@@ -11,6 +11,8 @@ async def install_repository(repository):
"""Common installation steps of the repository."""
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:
@@ -94,7 +96,7 @@ async def reload_after_install(repository):
elif repository.data.category == "netdaemon":
try:
await repository.hacs.hass.services.async_call(
"hassio", "addon_restart", {"addon": "e466aeb3_netdaemon"}
"hassio", "addon_restart", {"addon": "c6a2317c_netdaemon"}
)
except Exception: # pylint: disable=broad-except
pass

View File

@@ -5,11 +5,14 @@ from custom_components.hacs.hacsbase.exceptions import (
HacsException,
HacsExpectedException,
)
from queueman import concurrent
async def register_repository(full_name, category, check=True):
# @concurrent(15, 5)
async def register_repository(full_name, category, check=True, ref=None, action=False):
"""Register a repository."""
hacs = get_hacs()
hacs.action = action
from custom_components.hacs.repositories import (
RERPOSITORY_CLASSES,
) # To hanle import error
@@ -24,26 +27,32 @@ async def register_repository(full_name, category, check=True):
repository = RERPOSITORY_CLASSES[category](full_name)
if check:
try:
await repository.registration()
await repository.registration(ref)
if hacs.system.status.new:
repository.status.new = False
if repository.validate.errors:
hacs.common.skip.append(repository.data.full_name)
if not hacs.system.status.startup:
hacs.logger.error(f"Validation for {full_name} failed.")
if hacs.action:
raise HacsException(f"Validation for {full_name} failed.")
return repository.validate.errors
repository.logger.info("Registration complete")
if hacs.action:
repository.logger.info("Validation complete")
else:
repository.logger.info("Registration complete")
except AIOGitHubException as exception:
hacs.common.skip.append(repository.data.full_name)
raise HacsException(f"Validation for {full_name} failed with {exception}.")
hacs.hass.bus.async_fire(
"hacs/repository",
{
"id": 1337,
"action": "registration",
"repository": repository.data.full_name,
"repository_id": repository.information.uid,
},
)
if hacs.hass is not None:
hacs.hass.bus.async_fire(
"hacs/repository",
{
"id": 1337,
"action": "registration",
"repository": repository.data.full_name,
"repository_id": repository.information.uid,
},
)
hacs.repositories.append(repository)

View File

@@ -61,17 +61,19 @@ async def common_update_data(repository):
x.tag_name for x in releases if not x.draft
]
repository.versions.available = next(iter(releases)).tag_name
for release in releases:
if release.tag_name == repository.ref:
assets = release.assets
if assets:
downloads = next(iter(assets)).attributes.get("download_count")
repository.releases.downloads = downloads
except (AIOGitHubException, HacsException):
repository.releases.releases = False
repository.ref = version_to_install(repository)
if not repository.force_branch:
repository.ref = version_to_install(repository)
if repository.releases.releases:
for release in releases:
if release.tag_name == repository.ref:
assets = release.assets
if assets:
downloads = next(iter(assets)).attributes.get("download_count")
repository.releases.downloads = downloads
repository.logger.debug(
f"Running checks against {repository.ref.replace('tags/', '')}"