mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-10-23 18:49:36 +00:00

* Support for repository store. * Fix api * part 1 of restruct and migrate pathlib * Migrate p2 * fix lint / cleanups * fix lint p2 * fix lint p3
22 lines
500 B
Python
22 lines
500 B
Python
"""Util addons functions."""
|
|
import hashlib
|
|
import re
|
|
|
|
RE_SLUGIFY = re.compile(r'[^a-z0-9_]+')
|
|
RE_SHA1 = re.compile(r"[a-f0-9]{8}")
|
|
|
|
|
|
def get_hash_from_repository(name):
|
|
"""Generate a hash from repository."""
|
|
key = name.lower().encode()
|
|
return hashlib.sha1(key).hexdigest()[:8]
|
|
|
|
|
|
def extract_hash_from_path(path):
|
|
"""Extract repo id from path."""
|
|
repo_dir = path.parts[-1]
|
|
|
|
if not RE_SHA1.match(repo_dir):
|
|
return get_hash_from_repository(repo_dir)
|
|
return repo_dir
|