mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-11-12 20:40:21 +00:00
* Improve gdbus error handling * Fix logging type * Detect no dbus * Fix issue with complex * Update hassio/dbus/__init__.py Co-Authored-By: Franck Nijhof <frenck@frenck.nl> * Update hassio/dbus/hostname.py Co-Authored-By: Franck Nijhof <frenck@frenck.nl> * Update hassio/dbus/rauc.py Co-Authored-By: Franck Nijhof <frenck@frenck.nl> * Update hassio/dbus/systemd.py Co-Authored-By: Franck Nijhof <frenck@frenck.nl> * Fix black
24 lines
604 B
Python
24 lines
604 B
Python
"""Util add-ons functions."""
|
|
import hashlib
|
|
import logging
|
|
from pathlib import Path
|
|
import re
|
|
|
|
RE_SHA1 = re.compile(r"[a-f0-9]{8}")
|
|
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
|
|
|
|
|
def get_hash_from_repository(name: str) -> str:
|
|
"""Generate a hash from repository."""
|
|
key = name.lower().encode()
|
|
return hashlib.sha1(key).hexdigest()[:8]
|
|
|
|
|
|
def extract_hash_from_path(path: Path) -> str:
|
|
"""Extract repo id from path."""
|
|
repository_dir = path.parts[-1]
|
|
|
|
if not RE_SHA1.match(repository_dir):
|
|
return get_hash_from_repository(repository_dir)
|
|
return repository_dir
|