From d9e23fdb5c556595b24253901856b16aa3ac0d4a Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Mon, 3 Mar 2025 15:24:05 +1300 Subject: [PATCH] [dashboard] Rename trash/delete to archive (#8357) --- esphome/dashboard/web_server.py | 36 +++++++++++++++++++++++---------- esphome/storage_json.py | 4 ++++ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/esphome/dashboard/web_server.py b/esphome/dashboard/web_server.py index f7888ce6ed..9c20cf4f58 100644 --- a/esphome/dashboard/web_server.py +++ b/esphome/dashboard/web_server.py @@ -39,7 +39,12 @@ from yaml.nodes import Node from esphome import const, platformio_api, yaml_util from esphome.helpers import get_bool_env, mkdir_p -from esphome.storage_json import StorageJSON, ext_storage_path, trash_storage_path +from esphome.storage_json import ( + StorageJSON, + archive_storage_path, + ext_storage_path, + trash_storage_path, +) from esphome.util import get_serial_ports, shlex_quote from esphome.yaml_util import FastestAvailableSafeLoader @@ -936,16 +941,16 @@ class EditRequestHandler(BaseHandler): self.set_status(200) -class DeleteRequestHandler(BaseHandler): +class ArchiveRequestHandler(BaseHandler): @authenticated @bind_config def post(self, configuration: str | None = None) -> None: config_file = settings.rel_path(configuration) storage_path = ext_storage_path(configuration) - trash_path = trash_storage_path() - mkdir_p(trash_path) - shutil.move(config_file, os.path.join(trash_path, configuration)) + archive_path = archive_storage_path() + mkdir_p(archive_path) + shutil.move(config_file, os.path.join(archive_path, configuration)) storage_json = StorageJSON.load(storage_path) if storage_json is not None: @@ -953,16 +958,16 @@ class DeleteRequestHandler(BaseHandler): name = storage_json.name build_folder = os.path.join(settings.config_dir, name) if build_folder is not None: - shutil.rmtree(build_folder, os.path.join(trash_path, name)) + shutil.rmtree(build_folder, os.path.join(archive_path, name)) -class UndoDeleteRequestHandler(BaseHandler): +class UnArchiveRequestHandler(BaseHandler): @authenticated @bind_config def post(self, configuration: str | None = None) -> None: config_file = settings.rel_path(configuration) - trash_path = trash_storage_path() - shutil.move(os.path.join(trash_path, configuration), config_file) + archive_path = archive_storage_path() + shutil.move(os.path.join(archive_path, configuration), config_file) class LoginHandler(BaseHandler): @@ -1203,8 +1208,10 @@ def make_app(debug=get_bool_env(ENV_DEV)) -> tornado.web.Application: (f"{rel}download.bin", DownloadBinaryRequestHandler), (f"{rel}serial-ports", SerialPortRequestHandler), (f"{rel}ping", PingRequestHandler), - (f"{rel}delete", DeleteRequestHandler), - (f"{rel}undo-delete", UndoDeleteRequestHandler), + (f"{rel}delete", ArchiveRequestHandler), + (f"{rel}undo-delete", UnArchiveRequestHandler), + (f"{rel}archive", ArchiveRequestHandler), + (f"{rel}unarchive", UnArchiveRequestHandler), (f"{rel}wizard", WizardRequestHandler), (f"{rel}static/(.*)", StaticFileHandler, {"path": get_static_path()}), (f"{rel}devices", ListDevicesHandler), @@ -1229,6 +1236,13 @@ def start_web_server( config_dir: str, ) -> None: """Start the web server listener.""" + + trash_path = trash_storage_path() + if os.path.exists(trash_path): + _LOGGER.info("Renaming 'trash' folder to 'archive'") + archive_path = archive_storage_path() + shutil.move(trash_path, archive_path) + if socket is None: _LOGGER.info( "Starting dashboard web server on http://%s:%s and configuration dir %s...", diff --git a/esphome/storage_json.py b/esphome/storage_json.py index 97cf9ceadd..fa9fe43d4d 100644 --- a/esphome/storage_json.py +++ b/esphome/storage_json.py @@ -36,6 +36,10 @@ def trash_storage_path() -> str: return CORE.relative_config_path("trash") +def archive_storage_path() -> str: + return CORE.relative_config_path("archive") + + class StorageJSON: def __init__( self,