From e373f28358f51e0e859d8ff6e5b0f30388f522ce Mon Sep 17 00:00:00 2001 From: Egor fureunoir Gorbunov Date: Tue, 5 Aug 2025 21:08:32 +0300 Subject: [PATCH] Features: 1) Introduced `AbsoluteFTPStorage` class for path customization in FTP storage; 2) Updated dbbackup settings to use `AbsoluteFTPStorage` for FTP storage configurations. Fixes: 1) Corrected `DBBACKUP_PATH` default to ensure proper backup directory structure. Extra: 1) Minor cleanup in FTP storage configuration handling. --- evibes/ftpstorage.py | 11 +++++++++++ evibes/settings/dbbackup.py | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 evibes/ftpstorage.py diff --git a/evibes/ftpstorage.py b/evibes/ftpstorage.py new file mode 100644 index 00000000..78165461 --- /dev/null +++ b/evibes/ftpstorage.py @@ -0,0 +1,11 @@ +from urllib.parse import urlparse + +from storages.backends.ftp import FTPStorage + + +class AbsoluteFTPStorage(FTPStorage): # type: ignore + def _get_config(self): + cfg = super()._get_config() + url = urlparse(self.location) + cfg["path"] = url.path or cfg["path"] + return cfg diff --git a/evibes/settings/dbbackup.py b/evibes/settings/dbbackup.py index f0278262..cec40f83 100644 --- a/evibes/settings/dbbackup.py +++ b/evibes/settings/dbbackup.py @@ -13,7 +13,7 @@ if getenv("DBBACKUP_HOST") and getenv("DBBACKUP_USER") and getenv("DBBACKUP_PASS dbbackup_server_type = getenv("DBBACKUP_TYPE", "sftp") project_name = getenv("EVIBES_PROJECT_NAME", "evibes_common").lower().replace(" ", "_") - raw_path = getenv("DBBACKUP_PATH", f"backups/{project_name}") + raw_path = getenv("DBBACKUP_PATH", f"/backups/{project_name}/") cleaned = raw_path.strip("/") remote_dir = f"{cleaned}/" @@ -35,13 +35,13 @@ if getenv("DBBACKUP_HOST") and getenv("DBBACKUP_USER") and getenv("DBBACKUP_PASS } case "ftp": - DBBACKUP_STORAGE = "storages.backends.ftp.FTPStorage" + DBBACKUP_STORAGE = "evibes.ftpstorage.AbsoluteFTPStorage" DBBACKUP_STORAGE_OPTIONS = { "location": ( f"ftp://{getenv('DBBACKUP_USER')}:" f"{getenv('DBBACKUP_PASS')}@" f"{getenv('DBBACKUP_HOST')}:21/" - f"{remote_dir}" + f"{raw_path}" ), }