updating to latest

This commit is contained in:
root
2021-11-04 01:18:18 -04:00
parent f92b773514
commit 7eadb4c49c
153 changed files with 19015 additions and 5168 deletions

View File

@@ -0,0 +1 @@
"""Initialize HACS utils."""

View File

@@ -0,0 +1,7 @@
"""Util to decode content from the github API."""
from base64 import b64decode
def decode_content(content: str) -> str:
"""Decode content."""
return b64decode(bytearray(content, "utf-8")).decode()

View File

@@ -0,0 +1,19 @@
"""Custom logger for HACS."""
# pylint: disable=invalid-name
import logging
import os
from ..const import PACKAGE_NAME
_HACSLogger: logging.Logger = logging.getLogger(PACKAGE_NAME)
if "GITHUB_ACTION" in os.environ:
logging.basicConfig(
format="::%(levelname)s:: %(message)s",
level="DEBUG",
)
def getLogger(_name: str = None) -> logging.Logger:
"""Return a Logger instance."""
return _HACSLogger

View File

@@ -0,0 +1,21 @@
"""Path utils"""
from __future__ import annotations
from pathlib import Path
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from ..hacsbase.hacs import Hacs
def is_safe(hacs: Hacs, path: str | Path) -> bool:
"""Helper to check if path is safe to remove."""
paths = [
Path(f"{hacs.core.config_path}/{hacs.configuration.appdaemon_path}"),
Path(f"{hacs.core.config_path}/{hacs.configuration.netdaemon_path}"),
Path(f"{hacs.core.config_path}/{hacs.configuration.plugin_path}"),
Path(f"{hacs.core.config_path}/{hacs.configuration.python_script_path}"),
Path(f"{hacs.core.config_path}/{hacs.configuration.theme_path}"),
Path(f"{hacs.core.config_path}/custom_components/"),
]
return Path(path) not in paths

View File

@@ -0,0 +1,15 @@
"""Version utils."""
from functools import lru_cache
from awesomeversion import AwesomeVersion, AwesomeVersionException
@lru_cache(maxsize=1024)
def version_left_higher_then_right(left: str, right: str) -> bool:
"""Return a bool if source is newer than target, will also be true if identical."""
try:
return AwesomeVersion(left) >= AwesomeVersion(right)
except AwesomeVersionException:
return False