From 170cf1923ebd6e615d5a71fddb77605a9e3db347 Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Fri, 14 Apr 2023 10:18:21 +0000 Subject: [PATCH] refactor(services): rename get_location() to get_drive() --- selfprivacy_api/backup/__init__.py | 4 ++-- selfprivacy_api/graphql/common_types/service.py | 4 ++-- selfprivacy_api/services/bitwarden/__init__.py | 2 +- selfprivacy_api/services/generic_service_mover.py | 2 +- selfprivacy_api/services/gitea/__init__.py | 2 +- selfprivacy_api/services/jitsi/__init__.py | 2 +- selfprivacy_api/services/mailserver/__init__.py | 2 +- selfprivacy_api/services/nextcloud/__init__.py | 2 +- selfprivacy_api/services/ocserv/__init__.py | 2 +- selfprivacy_api/services/pleroma/__init__.py | 2 +- selfprivacy_api/services/service.py | 2 +- selfprivacy_api/services/test_service/__init__.py | 2 +- tests/test_graphql/test_backup.py | 6 +++--- 13 files changed, 17 insertions(+), 17 deletions(-) diff --git a/selfprivacy_api/backup/__init__.py b/selfprivacy_api/backup/__init__.py index 674abf0..72d6168 100644 --- a/selfprivacy_api/backup/__init__.py +++ b/selfprivacy_api/backup/__init__.py @@ -194,7 +194,7 @@ class Backups: @staticmethod def back_up(service: Service): """The top-level function to back up a service""" - folder = service.get_location() + folder = service.get_drive() repo_name = service.get_id() service.pre_backup() @@ -238,7 +238,7 @@ class Backups: @staticmethod def restore_service_from_snapshot(service: Service, snapshot_id: str): repo_name = service.get_id() - folder = service.get_location() + folder = service.get_drive() Backups.provider().backuper.restore_from_backup(repo_name, snapshot_id, folder) diff --git a/selfprivacy_api/graphql/common_types/service.py b/selfprivacy_api/graphql/common_types/service.py index 61ed5af..8f27386 100644 --- a/selfprivacy_api/graphql/common_types/service.py +++ b/selfprivacy_api/graphql/common_types/service.py @@ -17,7 +17,7 @@ def get_usages(root: "StorageVolume") -> list["StorageUsageInterface"]: service=service_to_graphql_service(service), title=service.get_display_name(), used_space=str(service.get_storage_usage()), - volume=get_volume_by_id(service.get_location()), + volume=get_volume_by_id(service.get_drive()), ) for service in get_services_by_location(root.name) ] @@ -81,7 +81,7 @@ def get_storage_usage(root: "Service") -> ServiceStorageUsage: service=service_to_graphql_service(service), title=service.get_display_name(), used_space=str(service.get_storage_usage()), - volume=get_volume_by_id(service.get_location()), + volume=get_volume_by_id(service.get_drive()), ) diff --git a/selfprivacy_api/services/bitwarden/__init__.py b/selfprivacy_api/services/bitwarden/__init__.py index 76f9912..32fce39 100644 --- a/selfprivacy_api/services/bitwarden/__init__.py +++ b/selfprivacy_api/services/bitwarden/__init__.py @@ -119,7 +119,7 @@ class Bitwarden(Service): return storage_usage @staticmethod - def get_location() -> str: + def get_drive() -> str: with ReadUserData() as user_data: if user_data.get("useBinds", False): return user_data.get("bitwarden", {}).get("location", "sda1") diff --git a/selfprivacy_api/services/generic_service_mover.py b/selfprivacy_api/services/generic_service_mover.py index 6c1b426..148ac1a 100644 --- a/selfprivacy_api/services/generic_service_mover.py +++ b/selfprivacy_api/services/generic_service_mover.py @@ -44,7 +44,7 @@ def move_service( ) return # Check if we are on the same volume - old_volume = service.get_location() + old_volume = service.get_drive() if old_volume == volume.name: Jobs.update( job=job, diff --git a/selfprivacy_api/services/gitea/__init__.py b/selfprivacy_api/services/gitea/__init__.py index f5d889a..7c9a558 100644 --- a/selfprivacy_api/services/gitea/__init__.py +++ b/selfprivacy_api/services/gitea/__init__.py @@ -117,7 +117,7 @@ class Gitea(Service): return storage_usage @staticmethod - def get_location() -> str: + def get_drive() -> str: with ReadUserData() as user_data: if user_data.get("useBinds", False): return user_data.get("gitea", {}).get("location", "sda1") diff --git a/selfprivacy_api/services/jitsi/__init__.py b/selfprivacy_api/services/jitsi/__init__.py index 50ff4a9..4258272 100644 --- a/selfprivacy_api/services/jitsi/__init__.py +++ b/selfprivacy_api/services/jitsi/__init__.py @@ -114,7 +114,7 @@ class Jitsi(Service): return storage_usage @staticmethod - def get_location() -> str: + def get_drive() -> str: return "sda1" @staticmethod diff --git a/selfprivacy_api/services/mailserver/__init__.py b/selfprivacy_api/services/mailserver/__init__.py index 1fe5333..9555571 100644 --- a/selfprivacy_api/services/mailserver/__init__.py +++ b/selfprivacy_api/services/mailserver/__init__.py @@ -102,7 +102,7 @@ class MailServer(Service): return get_storage_usage("/var/vmail") @staticmethod - def get_location() -> str: + def get_drive() -> str: with utils.ReadUserData() as user_data: if user_data.get("useBinds", False): return user_data.get("mailserver", {}).get("location", "sda1") diff --git a/selfprivacy_api/services/nextcloud/__init__.py b/selfprivacy_api/services/nextcloud/__init__.py index 115432d..9041651 100644 --- a/selfprivacy_api/services/nextcloud/__init__.py +++ b/selfprivacy_api/services/nextcloud/__init__.py @@ -124,7 +124,7 @@ class Nextcloud(Service): return get_storage_usage("/var/lib/nextcloud") @staticmethod - def get_location() -> str: + def get_drive() -> str: """Get the name of disk where Nextcloud is installed.""" with ReadUserData() as user_data: if user_data.get("useBinds", False): diff --git a/selfprivacy_api/services/ocserv/__init__.py b/selfprivacy_api/services/ocserv/__init__.py index 34720d6..92a1a4a 100644 --- a/selfprivacy_api/services/ocserv/__init__.py +++ b/selfprivacy_api/services/ocserv/__init__.py @@ -93,7 +93,7 @@ class Ocserv(Service): return "" @staticmethod - def get_location() -> str: + def get_drive() -> str: return "sda1" @staticmethod diff --git a/selfprivacy_api/services/pleroma/__init__.py b/selfprivacy_api/services/pleroma/__init__.py index aa16dcc..2aafd33 100644 --- a/selfprivacy_api/services/pleroma/__init__.py +++ b/selfprivacy_api/services/pleroma/__init__.py @@ -105,7 +105,7 @@ class Pleroma(Service): return storage_usage @staticmethod - def get_location() -> str: + def get_drive() -> str: with ReadUserData() as user_data: if user_data.get("useBinds", False): return user_data.get("pleroma", {}).get("location", "sda1") diff --git a/selfprivacy_api/services/service.py b/selfprivacy_api/services/service.py index f191149..3f1f4af 100644 --- a/selfprivacy_api/services/service.py +++ b/selfprivacy_api/services/service.py @@ -132,7 +132,7 @@ class Service(ABC): @staticmethod @abstractmethod - def get_location() -> str: + def get_drive() -> str: pass @abstractmethod diff --git a/selfprivacy_api/services/test_service/__init__.py b/selfprivacy_api/services/test_service/__init__.py index 0118dbc..822348c 100644 --- a/selfprivacy_api/services/test_service/__init__.py +++ b/selfprivacy_api/services/test_service/__init__.py @@ -107,7 +107,7 @@ class DummyService(Service): return storage_usage @classmethod - def get_location(cls) -> str: + def get_drive(cls) -> str: return cls.location @staticmethod diff --git a/tests/test_graphql/test_backup.py b/tests/test_graphql/test_backup.py index 4d4f421..d33cde1 100644 --- a/tests/test_graphql/test_backup.py +++ b/tests/test_graphql/test_backup.py @@ -44,7 +44,7 @@ def raw_dummy_service(tmpdir, backups): with open(testfile_path, "w") as file: file.write(TESTFILE_BODY) - # we need this to not change get_location() much + # we need this to not change get_drive() much class TestDummyService(DummyService, location=service_dir): pass @@ -143,7 +143,7 @@ def test_one_snapshot(backups, dummy_service): def test_backup_returns_snapshot(backups, dummy_service): - service_folder = dummy_service.get_location() + service_folder = dummy_service.get_drive() provider = Backups.provider() name = dummy_service.get_id() snapshot = provider.backuper.start_backup(service_folder, name) @@ -154,7 +154,7 @@ def test_backup_returns_snapshot(backups, dummy_service): def test_restore(backups, dummy_service): - service_folder = dummy_service.get_location() + service_folder = dummy_service.get_drive() file_to_nuke = listdir(service_folder)[0] assert file_to_nuke is not None path_to_nuke = path.join(service_folder, file_to_nuke)