refactor(services): make a default implementation of enable/disable

This commit is contained in:
Houkime 2023-10-20 16:05:12 +00:00
parent 23cc33b9d9
commit e1083f3221

View file

@ -12,6 +12,7 @@ from selfprivacy_api.services.generic_size_counter import get_storage_usage
from selfprivacy_api.services.owned_path import OwnedPath from selfprivacy_api.services.owned_path import OwnedPath
from selfprivacy_api import utils from selfprivacy_api import utils
from selfprivacy_api.utils.waitloop import wait_until_true from selfprivacy_api.utils.waitloop import wait_until_true
from selfprivacy_api.utils import ReadUserData, WriteUserData, get_domain
DEFAULT_START_STOP_TIMEOUT = 5 * 60 DEFAULT_START_STOP_TIMEOUT = 5 * 60
@ -137,17 +138,24 @@ class Service(ABC):
"""The status of the service, reported by systemd.""" """The status of the service, reported by systemd."""
pass pass
@staticmethod # But they do not really enable?
@abstractmethod @classmethod
def enable(): def enable(cls):
"""Enable the service. Usually this means enabling systemd unit.""" """Enable the service. Usually this means enabling systemd unit."""
pass name = cls.get_id()
with WriteUserData() as user_data:
if "gitea" not in user_data:
user_data[name] = {}
user_data[name]["enable"] = True
@staticmethod @classmethod
@abstractmethod def disable(cls):
def disable():
"""Disable the service. Usually this means disabling systemd unit.""" """Disable the service. Usually this means disabling systemd unit."""
pass name = cls.get_id()
with WriteUserData() as user_data:
if "gitea" not in user_data:
user_data[name] = {}
user_data[name]["enable"] = False
@staticmethod @staticmethod
@abstractmethod @abstractmethod