mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-10-05 17:59:30 +00:00

* Add API layout for snapshot
* Update api
* Add support for export/import docker images
* Move restore into addon
* Add restore to addon
* Fix lint
* fix lint
* cleanup
* init object
* fix executor
* cleanup
* Change flow of init
* Revert "Change flow of init"
This reverts commit 6b3215e44c
.
* allow restore from none
* forward working
* add size
* add context for snapshot
* add init function to set meta data
* update local addon on load
* add more validate and optimaze code
* Optimaze code for restore data
* add validate layer
* Add more function to snapshot / cleanup others
* finish snapshot function
* Cleanup config / optimaze code
* Finish snapshot on core
* Some improvments first object for api
* finish
* fix lint p1
* fix lint p2
* fix lint p3
* fix async with
* fix lint p4
* fix lint p5
* fix p6
* make staticmethod
* fix schema
* fix parse system data
* fix bugs
* fix get function
* extend snapshot/restore
* add type
* fix lint
* move to gz / xz is to slow
* move to gz / xz is to slow p2
* Fix config folder
* small compresslevel for more speed
* fix lint
* fix load
* fix tar stream
* fix tar stream p2
* fix parse
* fix partial
* fix start hass
* fix rep
* fix set
* fix real
* fix generator
* Cleanup old image
* add log
* fix lint
* fix lint p2
* fix load from tar
36 lines
916 B
Python
36 lines
916 B
Python
"""Util addons functions."""
|
|
import hashlib
|
|
import logging
|
|
import re
|
|
|
|
RE_SHA1 = re.compile(r"[a-f0-9]{8}")
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
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
|
|
|
|
|
|
def check_installed(method):
|
|
"""Wrap function with check if addon is installed."""
|
|
async def wrap_check(addon, *args, **kwargs):
|
|
"""Return False if not installed or the function."""
|
|
if not addon.is_installed:
|
|
_LOGGER.error("Addon %s is not installed", addon.slug)
|
|
return False
|
|
return await method(addon, *args, **kwargs)
|
|
|
|
return wrap_check
|