Rework include/exclude
This commit is contained in:
parent
4a88cd04da
commit
5a9378441c
|
@ -18,8 +18,21 @@ class Container:
|
||||||
self.names = data.get('Names', [])
|
self.names = data.get('Names', [])
|
||||||
self.mounts = [Mount(mnt, container=self) for mnt in data.get('Mounts')]
|
self.mounts = [Mount(mnt, container=self) for mnt in data.get('Mounts')]
|
||||||
|
|
||||||
self.include = self.labels.get('restic-volume-backup.enabled', '').split(',')
|
self.include = self._parse_pattern(self.labels.get('restic-volume-backup.include'))
|
||||||
self.exlude = self.labels.get('restic-volume-backup.exclude', '').split(',')
|
self.exclude = self._parse_pattern(self.labels.get('restic-volume-backup.exclude'))
|
||||||
|
|
||||||
|
def _parse_pattern(self, value):
|
||||||
|
if not value:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if type(value) is not str:
|
||||||
|
return None
|
||||||
|
|
||||||
|
value = value.strip()
|
||||||
|
if len(value) == 0:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return value.split(',')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def backup_enabled(self):
|
def backup_enabled(self):
|
||||||
|
@ -43,19 +56,23 @@ class Container:
|
||||||
|
|
||||||
def filter_mounts(self):
|
def filter_mounts(self):
|
||||||
"""Get all mounts for this container matching filters"""
|
"""Get all mounts for this container matching filters"""
|
||||||
for mount in self.mounts:
|
filtered = []
|
||||||
if self.include:
|
if self.include:
|
||||||
|
for mount in self.mounts:
|
||||||
for pattern in self.include:
|
for pattern in self.include:
|
||||||
if pattern in mount.source:
|
if pattern in mount.source:
|
||||||
yield mount
|
break
|
||||||
continue
|
else:
|
||||||
elif self.exlude:
|
continue
|
||||||
for pattern in self.exlude:
|
|
||||||
if pattern in mount.source:
|
filtered.append(mount)
|
||||||
continue
|
|
||||||
yield mount
|
elif self.exclude:
|
||||||
else:
|
pass
|
||||||
yield mount
|
else:
|
||||||
|
return self.mounts
|
||||||
|
|
||||||
|
return filtered
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
return {
|
return {
|
||||||
|
@ -179,16 +196,3 @@ class RunningContainers:
|
||||||
return container
|
return container
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def print_services(self):
|
|
||||||
print()
|
|
||||||
print("Backup config for compose project '{}'".format(self.this_container.project_name))
|
|
||||||
print()
|
|
||||||
|
|
||||||
for container in self.containers:
|
|
||||||
print('service: {}'.format(container.service_name))
|
|
||||||
mounts = container.filter_mounts()
|
|
||||||
for mount in mounts:
|
|
||||||
print(' - {}'.format(mount.source))
|
|
||||||
|
|
||||||
print()
|
|
Loading…
Reference in New Issue