From 2c9c418c6e92c97c8916d995048df6595b33c2ed Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Wed, 17 Apr 2019 03:01:12 +0200 Subject: [PATCH] Add basic type hints --- restic_volume_backup/containers.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/restic_volume_backup/containers.py b/restic_volume_backup/containers.py index 6a92b7d..5c07fbd 100644 --- a/restic_volume_backup/containers.py +++ b/restic_volume_backup/containers.py @@ -98,26 +98,27 @@ class Mount: self._container = container @property - def container(self): + def container(self) -> Container: return self._container @property - def type(self): + def type(self) -> str: + """bind/volume""" return self._data.get('Type') @property - def name(self): + def name(self) -> str: return self._data.get('Name') @property - def source(self): + def source(self) -> str: return self._data.get('Source') @property - def destination(self): + def destination(self) -> str: return self._data.get('Destination') - def mount_string(self): + def mount_string(self) -> str: if self.type == VOLUME_TYPE_VOLUME: return "- {}:{}:ro".format(self.name.split('_')[-1], self.destination) elif self.type == VOLUME_TYPE_BIND: @@ -125,10 +126,10 @@ class Mount: else: raise ValueError("Uknown volume type: {}".format(self.type)) - def __repr__(self): + def __repr__(self) -> str: return str(self) - def __str__(self): + def __str__(self) -> str: return str(self._data) def __hash__(self): @@ -147,6 +148,7 @@ class RunningContainers: all_containers = utils.list_containers() self.containers = [] self.this_container = None + self.backup_process_container = None # Find the container we are running in. # If we don't have this information we cannot continue @@ -195,7 +197,10 @@ class RunningContainers: # """Host mapped volumes""" # return set(mnt for mnt in self.gen_volumes(VOLUME_TYPE_BIND)) - def get_service(self, name): + def backup_process_running(self) -> bool: + return self.backup_process_container is not None + + def get_service(self, name) -> Container: for container in self.containers: if container.service_name == name: return container