From c2cd97280583e662d72d1773e277322a2c66d4c0 Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Mon, 17 Apr 2023 14:02:07 +0000 Subject: [PATCH] refactor(services): add a generic storage counter --- selfprivacy_api/services/gitea/__init__.py | 2 +- selfprivacy_api/services/service.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/selfprivacy_api/services/gitea/__init__.py b/selfprivacy_api/services/gitea/__init__.py index a07ccd1..bb885a5 100644 --- a/selfprivacy_api/services/gitea/__init__.py +++ b/selfprivacy_api/services/gitea/__init__.py @@ -113,7 +113,7 @@ class Gitea(Service): def get_storage_usage() -> int: storage_usage = 0 for folder in Gitea.get_folders(): - storage_usage += get_storage_usage() + storage_usage += get_storage_usage(folder) return storage_usage @staticmethod diff --git a/selfprivacy_api/services/service.py b/selfprivacy_api/services/service.py index 192f98e..c5a7527 100644 --- a/selfprivacy_api/services/service.py +++ b/selfprivacy_api/services/service.py @@ -8,6 +8,8 @@ from selfprivacy_api.jobs import Job from selfprivacy_api.utils.block_devices import BlockDevice +from selfprivacy_api.services.generic_size_counter import get_storage_usage + class ServiceStatus(Enum): """Enum for service status""" @@ -120,10 +122,12 @@ class Service(ABC): def get_logs(): pass - @staticmethod - @abstractmethod - def get_storage_usage() -> int: - pass + @classmethod + def get_storage_usage(cls) -> int: + storage_used = 0 + for folder in cls.get_folders(): + storage_used += get_storage_usage(folder) + return storage_used @staticmethod @abstractmethod