refactor(services): rename get_location() to get_drive()

restic-rewrite-api
Houkime 2023-04-14 10:18:21 +00:00
parent 0ae4192081
commit 1b1052d205
13 changed files with 17 additions and 17 deletions

View File

@ -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)

View File

@ -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()),
)

View File

@ -118,7 +118,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")

View File

@ -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,

View File

@ -116,7 +116,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")

View File

@ -116,7 +116,7 @@ class Jitsi(Service):
return storage_usage
@staticmethod
def get_location() -> str:
def get_drive() -> str:
return "sda1"
@staticmethod

View File

@ -101,7 +101,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")

View File

@ -123,7 +123,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):

View File

@ -93,7 +93,7 @@ class Ocserv(Service):
return ""
@staticmethod
def get_location() -> str:
def get_drive() -> str:
return "sda1"
@staticmethod

View File

@ -104,7 +104,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")

View File

@ -132,7 +132,7 @@ class Service(ABC):
@staticmethod
@abstractmethod
def get_location() -> str:
def get_drive() -> str:
pass
@abstractmethod

View File

@ -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

View File

@ -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)