#743 - Trying to fix this.

This commit is contained in:
ccostan
2020-05-21 18:48:00 -04:00
parent cf3764e3e4
commit 5c7334bc05
42 changed files with 863 additions and 513 deletions

View File

@@ -6,7 +6,7 @@ from datetime import timedelta
from homeassistant.helpers.event import async_call_later, async_track_time_interval
from aiogithubapi import AIOGitHubException, AIOGitHubRatelimit
from aiogithubapi import AIOGitHubAPIException, AIOGitHubAPIRatelimitException
from integrationhelper import Logger
from queueman import QueueManager
@@ -115,7 +115,7 @@ class Hacs:
"""Get repository by ID."""
try:
for repository in self.repositories:
if repository.information.uid == repository_id:
if str(repository.data.id) == str(repository_id):
return repository
except Exception: # pylint: disable=broad-except
pass
@@ -131,11 +131,9 @@ class Hacs:
pass
return None
def is_known(self, repository_full_name):
def is_known(self, repository_id):
"""Return a bool if the repository is known."""
return repository_full_name.lower() in [
x.data.full_name.lower() for x in self.repositories
]
return str(repository_id) in [str(x.data.id) for x in self.repositories]
@property
def sorted_by_name(self):
@@ -156,8 +154,6 @@ class Hacs:
self.system.status.background_task = True
await self.hass.async_add_executor_job(setup_extra_stores)
self.hass.bus.async_fire("hacs/status", {})
self.logger.debug(self.github.ratelimits.remaining)
self.logger.debug(self.github.ratelimits.reset_utc)
await self.handle_critical_repositories_startup()
await self.handle_critical_repositories()
@@ -186,7 +182,6 @@ class Hacs:
await self.prosess_queue()
self.system.status.startup = False
self.system.status.new = False
self.system.status.background_task = False
self.hass.bus.async_fire("hacs/status", {})
await self.data.async_write()
@@ -216,7 +211,7 @@ class Hacs:
try:
critical = await self.data_repo.get_contents("critical")
critical = json.loads(critical.content)
except AIOGitHubException:
except AIOGitHubAPIException:
pass
if not critical:
@@ -290,11 +285,10 @@ class Hacs:
)
self.system.status.background_task = True
self.hass.bus.async_fire("hacs/status", {})
self.logger.debug(self.github.ratelimits.remaining)
self.logger.debug(self.github.ratelimits.reset_utc)
for repository in self.repositories:
if (
repository.status.installed
repository.data.installed
and repository.data.category in self.common.categories
):
self.queue.add(self.factory.safe_update(repository))
@@ -311,8 +305,7 @@ class Hacs:
await self.hass.async_add_executor_job(setup_extra_stores)
self.system.status.background_task = True
self.hass.bus.async_fire("hacs/status", {})
self.logger.debug(self.github.ratelimits.remaining)
self.logger.debug(self.github.ratelimits.reset_utc)
for repository in self.repositories:
if repository.data.category in self.common.categories:
self.queue.add(self.factory.safe_common_update(repository))
@@ -329,9 +322,9 @@ class Hacs:
"""Clear out blaclisted repositories."""
need_to_save = False
for removed in removed_repositories:
if self.is_known(removed.repository):
repository = self.get_by_name(removed.repository)
if repository.status.installed and removed.removal_type != "critical":
repository = self.get_by_name(removed.repository)
if repository is not None:
if repository.data.installed and removed.removal_type != "critical":
self.logger.warning(
f"You have {repository.data.full_name} installed with HACS "
+ f"this repository has been removed, please consider removing it. "
@@ -354,11 +347,6 @@ class Hacs:
org = await get_default_repos_orgs(self.github, category)
for repo in org:
repositories[category].append(repo)
for category in repositories:
for repo in repositories[category]:
if repo not in self.common.default:
self.common.default.append(repo)
return repositories
async def load_known_repositories(self):
@@ -378,6 +366,11 @@ class Hacs:
for repo in repositories[category]:
if is_removed(repo):
continue
if self.is_known(repo):
repository = self.get_by_name(repo)
if repository is not None:
if str(repository.data.id) not in self.common.default:
self.common.default.append(str(repository.data.id))
else:
continue
continue
self.queue.add(self.factory.safe_register(repo, category))

View File

@@ -25,8 +25,8 @@ class Configuration:
plugin_path: str = "www/community/"
python_script_path: str = "python_scripts/"
python_script: bool = False
sidepanel_icon: str = "mdi:alpha-c-box"
sidepanel_title: str = "Community"
sidepanel_icon: str = "hacs:hacs"
sidepanel_title: str = "HACS"
theme_path: str = "themes/"
theme: bool = False
token: str = None
@@ -50,7 +50,7 @@ class Configuration:
logger.debug(f"{key}: {config[key]}")
@staticmethod
def from_dict(configuration: dict, options: dict):
def from_dict(configuration: dict, options: dict = None):
"""Set attributes from dicts."""
if isinstance(options, bool) or isinstance(configuration.get("options"), bool):
raise HacsException("Configuration is not valid.")

View File

@@ -42,28 +42,39 @@ class HacsData:
repository_manifest = repository.repository_manifest.manifest
else:
repository_manifest = None
content[repository.information.uid] = {
data = {
"authors": repository.data.authors,
"category": repository.data.category,
"description": repository.data.description,
"downloads": repository.releases.downloads,
"domain": repository.data.domain,
"downloads": repository.data.downloads,
"full_name": repository.data.full_name,
"first_install": repository.status.first_install,
"hide": repository.status.hide,
"installed_commit": repository.versions.installed_commit,
"installed": repository.status.installed,
"last_commit": repository.versions.available_commit,
"last_release_tag": repository.versions.available,
"last_updated": repository.information.last_updated,
"installed_commit": repository.data.installed_commit,
"installed": repository.data.installed,
"last_commit": repository.data.last_commit,
"last_release_tag": repository.data.last_version,
"last_updated": repository.data.last_updated,
"name": repository.data.name,
"new": repository.status.new,
"new": repository.data.new,
"repository_manifest": repository_manifest,
"selected_tag": repository.status.selected_tag,
"show_beta": repository.status.show_beta,
"selected_tag": repository.data.selected_tag,
"show_beta": repository.data.show_beta,
"stars": repository.data.stargazers_count,
"topics": repository.data.topics,
"version_installed": repository.versions.installed,
"version_installed": repository.data.installed_version,
}
if data:
if repository.data.installed and (
repository.data.installed_commit
or repository.data.installed_version
):
await async_save_to_store(
self.hacs.hass,
f"hacs/{repository.data.id}.hacs",
repository.data.to_json(),
)
content[str(repository.data.id)] = data
await async_save_to_store(self.hacs.hass, "repositories", content)
self.hacs.hass.bus.async_fire("hacs/repository", {})
@@ -79,6 +90,7 @@ class HacsData:
self.hacs.system.status.new = True
return True
self.logger.info("Restore started")
self.hacs.system.status.new = False
# Hacs
self.hacs.configuration.frontend_mode = hacs.get("view", "Grid")
@@ -88,21 +100,40 @@ class HacsData:
# Repositories
for entry in repositories:
repo = repositories[entry]
if not self.hacs.is_known(repo["full_name"]):
if not self.hacs.is_known(entry):
await register_repository(
repo["full_name"], repo["category"], False
)
repository = self.hacs.get_by_name(repo["full_name"])
if repository is None:
self.logger.error(f"Did not find {repo['full_name']}")
repository = [
x
for x in self.hacs.repositories
if str(x.data.id) == str(entry)
or x.data.full_name == repo["full_name"]
]
if not repository:
self.logger.error(f"Did not find {repo['full_name']} ({entry})")
continue
repository = repository[0]
# Restore repository attributes
repository.information.uid = entry
repository.data.id = entry
await self.hacs.hass.async_add_executor_job(
restore_repository_data, repository, repo
)
restored = await async_load_from_store(
self.hacs.hass, f"hacs/{entry}.hacs"
)
if restored:
repository.data.update_data(restored)
if not repository.data.installed:
repository.logger.debug(
"Should be installed but is not... Fixing that!"
)
repository.data.installed = True
self.logger.info("Restore done")
except Exception as exception: # pylint: disable=broad-except
self.logger.critical(f"[{exception}] Restore Failed!")
@@ -117,27 +148,28 @@ def restore_repository_data(
repository.data.authors = repository_data.get("authors", [])
repository.data.description = repository_data.get("description")
repository.releases.last_release_object_downloads = repository_data.get("downloads")
repository.information.last_updated = repository_data.get("last_updated")
repository.data.last_updated = repository_data.get("last_updated")
repository.data.topics = repository_data.get("topics", [])
repository.data.domain = repository_data.get("domain", None)
repository.data.stargazers_count = repository_data.get("stars", 0)
repository.releases.last_release = repository_data.get("last_release_tag")
repository.status.hide = repository_data.get("hide", False)
repository.status.installed = repository_data.get("installed", False)
repository.status.new = repository_data.get("new", True)
repository.status.selected_tag = repository_data.get("selected_tag")
repository.status.show_beta = repository_data.get("show_beta", False)
repository.versions.available = repository_data.get("last_release_tag")
repository.versions.available_commit = repository_data.get("last_commit")
repository.versions.installed = repository_data.get("version_installed")
repository.versions.installed_commit = repository_data.get("installed_commit")
repository.data.hide = repository_data.get("hide", False)
repository.data.installed = repository_data.get("installed", False)
repository.data.new = repository_data.get("new", True)
repository.data.selected_tag = repository_data.get("selected_tag")
repository.data.show_beta = repository_data.get("show_beta", False)
repository.data.last_version = repository_data.get("last_release_tag")
repository.data.last_commit = repository_data.get("last_commit")
repository.data.installed_version = repository_data.get("version_installed")
repository.data.installed_commit = repository_data.get("installed_commit")
repository.repository_manifest = HacsManifest.from_dict(
repository_data.get("repository_manifest", {})
)
if repository.status.installed:
if repository.data.installed:
repository.status.first_install = False
if repository_data["full_name"] == "hacs/integration":
repository.versions.installed = VERSION
repository.status.installed = True
repository.data.installed_version = VERSION
repository.data.installed = True

View File

@@ -3,7 +3,7 @@ import logging
import time
from datetime import timedelta
import asyncio
from aiogithubapi import AIOGitHubException
from aiogithubapi import AIOGitHubAPIException
from custom_components.hacs.hacsbase.exceptions import HacsException
from custom_components.hacs.helpers.register_repository import register_repository
@@ -48,7 +48,7 @@ class HacsTaskFactory:
async with max_concurrent_tasks:
try:
await repository.common_update()
except (AIOGitHubException, HacsException) as exception:
except (AIOGitHubAPIException, HacsException) as exception:
logger.error("%s - %s", repository.data.full_name, exception)
# Due to GitHub ratelimits we need to sleep a bit
@@ -58,7 +58,7 @@ class HacsTaskFactory:
async with max_concurrent_tasks:
try:
await repository.update_repository()
except (AIOGitHubException, HacsException) as exception:
except (AIOGitHubAPIException, HacsException) as exception:
logger.error("%s - %s", repository.data.full_name, exception)
# Due to GitHub ratelimits we need to sleep a bit
@@ -68,7 +68,7 @@ class HacsTaskFactory:
async with max_concurrent_tasks:
try:
await register_repository(repo, category)
except (AIOGitHubException, HacsException) as exception:
except (AIOGitHubAPIException, HacsException) as exception:
logger.error("%s - %s", repo, exception)
# Due to GitHub ratelimits we need to sleep a bit