mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 10:59:40 +00:00
Make backup file names more user friendly (#136928)
* Make backup file names more user friendly * Strip backup name * Strip backup name * Underscores
This commit is contained in:
@@ -20,6 +20,7 @@ from securetar import SecureTarError, SecureTarFile, SecureTarReadError
|
||||
from homeassistant.backup_restore import password_to_key
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.util import dt as dt_util
|
||||
from homeassistant.util.json import JsonObjectType, json_loads_object
|
||||
from homeassistant.util.thread import ThreadWithException
|
||||
|
||||
@@ -117,6 +118,14 @@ def read_backup(backup_path: Path) -> AgentBackup:
|
||||
)
|
||||
|
||||
|
||||
def suggested_filename(backup: AgentBackup) -> str:
|
||||
"""Suggest a filename for the backup."""
|
||||
date = dt_util.parse_datetime(backup.date, raise_on_error=True)
|
||||
return "_".join(
|
||||
f"{backup.name} - {date.strftime('%Y-%m-%d %H.%M %S%f')}.tar".split()
|
||||
)
|
||||
|
||||
|
||||
def validate_password(path: Path, password: str | None) -> bool:
|
||||
"""Validate the password."""
|
||||
with tarfile.open(path, "r:", bufsize=BUF_SIZE) as backup_file:
|
||||
|
||||
Reference in New Issue
Block a user