mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-24 13:01:28 +00:00
refactor(services): rename get_location() to get_drive()
This commit is contained in:
parent
5101f41437
commit
170cf1923e
|
@ -194,7 +194,7 @@ class Backups:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def back_up(service: Service):
|
def back_up(service: Service):
|
||||||
"""The top-level function to back up a service"""
|
"""The top-level function to back up a service"""
|
||||||
folder = service.get_location()
|
folder = service.get_drive()
|
||||||
repo_name = service.get_id()
|
repo_name = service.get_id()
|
||||||
|
|
||||||
service.pre_backup()
|
service.pre_backup()
|
||||||
|
@ -238,7 +238,7 @@ class Backups:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def restore_service_from_snapshot(service: Service, snapshot_id: str):
|
def restore_service_from_snapshot(service: Service, snapshot_id: str):
|
||||||
repo_name = service.get_id()
|
repo_name = service.get_id()
|
||||||
folder = service.get_location()
|
folder = service.get_drive()
|
||||||
|
|
||||||
Backups.provider().backuper.restore_from_backup(repo_name, snapshot_id, folder)
|
Backups.provider().backuper.restore_from_backup(repo_name, snapshot_id, folder)
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ def get_usages(root: "StorageVolume") -> list["StorageUsageInterface"]:
|
||||||
service=service_to_graphql_service(service),
|
service=service_to_graphql_service(service),
|
||||||
title=service.get_display_name(),
|
title=service.get_display_name(),
|
||||||
used_space=str(service.get_storage_usage()),
|
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)
|
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),
|
service=service_to_graphql_service(service),
|
||||||
title=service.get_display_name(),
|
title=service.get_display_name(),
|
||||||
used_space=str(service.get_storage_usage()),
|
used_space=str(service.get_storage_usage()),
|
||||||
volume=get_volume_by_id(service.get_location()),
|
volume=get_volume_by_id(service.get_drive()),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -119,7 +119,7 @@ class Bitwarden(Service):
|
||||||
return storage_usage
|
return storage_usage
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_location() -> str:
|
def get_drive() -> str:
|
||||||
with ReadUserData() as user_data:
|
with ReadUserData() as user_data:
|
||||||
if user_data.get("useBinds", False):
|
if user_data.get("useBinds", False):
|
||||||
return user_data.get("bitwarden", {}).get("location", "sda1")
|
return user_data.get("bitwarden", {}).get("location", "sda1")
|
||||||
|
|
|
@ -44,7 +44,7 @@ def move_service(
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
# Check if we are on the same volume
|
# Check if we are on the same volume
|
||||||
old_volume = service.get_location()
|
old_volume = service.get_drive()
|
||||||
if old_volume == volume.name:
|
if old_volume == volume.name:
|
||||||
Jobs.update(
|
Jobs.update(
|
||||||
job=job,
|
job=job,
|
||||||
|
|
|
@ -117,7 +117,7 @@ class Gitea(Service):
|
||||||
return storage_usage
|
return storage_usage
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_location() -> str:
|
def get_drive() -> str:
|
||||||
with ReadUserData() as user_data:
|
with ReadUserData() as user_data:
|
||||||
if user_data.get("useBinds", False):
|
if user_data.get("useBinds", False):
|
||||||
return user_data.get("gitea", {}).get("location", "sda1")
|
return user_data.get("gitea", {}).get("location", "sda1")
|
||||||
|
|
|
@ -114,7 +114,7 @@ class Jitsi(Service):
|
||||||
return storage_usage
|
return storage_usage
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_location() -> str:
|
def get_drive() -> str:
|
||||||
return "sda1"
|
return "sda1"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -102,7 +102,7 @@ class MailServer(Service):
|
||||||
return get_storage_usage("/var/vmail")
|
return get_storage_usage("/var/vmail")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_location() -> str:
|
def get_drive() -> str:
|
||||||
with utils.ReadUserData() as user_data:
|
with utils.ReadUserData() as user_data:
|
||||||
if user_data.get("useBinds", False):
|
if user_data.get("useBinds", False):
|
||||||
return user_data.get("mailserver", {}).get("location", "sda1")
|
return user_data.get("mailserver", {}).get("location", "sda1")
|
||||||
|
|
|
@ -124,7 +124,7 @@ class Nextcloud(Service):
|
||||||
return get_storage_usage("/var/lib/nextcloud")
|
return get_storage_usage("/var/lib/nextcloud")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_location() -> str:
|
def get_drive() -> str:
|
||||||
"""Get the name of disk where Nextcloud is installed."""
|
"""Get the name of disk where Nextcloud is installed."""
|
||||||
with ReadUserData() as user_data:
|
with ReadUserData() as user_data:
|
||||||
if user_data.get("useBinds", False):
|
if user_data.get("useBinds", False):
|
||||||
|
|
|
@ -93,7 +93,7 @@ class Ocserv(Service):
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_location() -> str:
|
def get_drive() -> str:
|
||||||
return "sda1"
|
return "sda1"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -105,7 +105,7 @@ class Pleroma(Service):
|
||||||
return storage_usage
|
return storage_usage
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_location() -> str:
|
def get_drive() -> str:
|
||||||
with ReadUserData() as user_data:
|
with ReadUserData() as user_data:
|
||||||
if user_data.get("useBinds", False):
|
if user_data.get("useBinds", False):
|
||||||
return user_data.get("pleroma", {}).get("location", "sda1")
|
return user_data.get("pleroma", {}).get("location", "sda1")
|
||||||
|
|
|
@ -132,7 +132,7 @@ class Service(ABC):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_location() -> str:
|
def get_drive() -> str:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
|
|
@ -107,7 +107,7 @@ class DummyService(Service):
|
||||||
return storage_usage
|
return storage_usage
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_location(cls) -> str:
|
def get_drive(cls) -> str:
|
||||||
return cls.location
|
return cls.location
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -44,7 +44,7 @@ def raw_dummy_service(tmpdir, backups):
|
||||||
with open(testfile_path, "w") as file:
|
with open(testfile_path, "w") as file:
|
||||||
file.write(TESTFILE_BODY)
|
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):
|
class TestDummyService(DummyService, location=service_dir):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ def test_one_snapshot(backups, dummy_service):
|
||||||
|
|
||||||
|
|
||||||
def test_backup_returns_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()
|
provider = Backups.provider()
|
||||||
name = dummy_service.get_id()
|
name = dummy_service.get_id()
|
||||||
snapshot = provider.backuper.start_backup(service_folder, name)
|
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):
|
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]
|
file_to_nuke = listdir(service_folder)[0]
|
||||||
assert file_to_nuke is not None
|
assert file_to_nuke is not None
|
||||||
path_to_nuke = path.join(service_folder, file_to_nuke)
|
path_to_nuke = path.join(service_folder, file_to_nuke)
|
||||||
|
|
Loading…
Reference in a new issue