updating to latest
This commit is contained in:
1
custom_components/hacs/utils/__init__.py
Normal file
1
custom_components/hacs/utils/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Initialize HACS utils."""
|
||||
7
custom_components/hacs/utils/decode.py
Normal file
7
custom_components/hacs/utils/decode.py
Normal 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()
|
||||
19
custom_components/hacs/utils/logger.py
Normal file
19
custom_components/hacs/utils/logger.py
Normal 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
|
||||
21
custom_components/hacs/utils/path.py
Normal file
21
custom_components/hacs/utils/path.py
Normal 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
|
||||
15
custom_components/hacs/utils/version.py
Normal file
15
custom_components/hacs/utils/version.py
Normal 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
|
||||
Reference in New Issue
Block a user