From 8a7f47dfcdc2d5027a2b0b48029f00aa7743f1a7 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Mon, 26 Apr 2021 18:00:56 +0200 Subject: [PATCH] Three lint errors remain. --- app/specs/container.py | 5 ++--- app/specs/directory.py | 3 +-- app/specs/spec.py | 6 ++++-- app/specs/volume.py | 20 +++++++++++++++++++- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/app/specs/container.py b/app/specs/container.py index 7bc2a95..79d4d3a 100644 --- a/app/specs/container.py +++ b/app/specs/container.py @@ -23,8 +23,7 @@ class ContainerSpec(Spec): mountpoint: str, notify=None, ): - """ - Create a new ContainerSpec object. + """Create a new ContainerSpec object. Args: name: name of the spec (used as an identifier) @@ -36,7 +35,7 @@ class ContainerSpec(Spec): perform a specified backup and output this data to stdout. This output then gets piped to a backup file. extension: the extension of the backup files. - mountpoint: + mountpoint: I don't actually know, this never gets used notify: notifier object (may be None) """ super().__init__(name, destination, limit, extension, notify) diff --git a/app/specs/directory.py b/app/specs/directory.py index 17048a7..34a92e8 100644 --- a/app/specs/directory.py +++ b/app/specs/directory.py @@ -26,8 +26,7 @@ class DirectorySpec(Spec): extension: str, notify=None, ): - """ - Initialize a new DirectorySpec object. + """Initialize a new DirectorySpec object. Args: name: name of the spec diff --git a/app/specs/spec.py b/app/specs/spec.py index d5e0b26..8ba1e28 100644 --- a/app/specs/spec.py +++ b/app/specs/spec.py @@ -41,7 +41,8 @@ class Spec: name: name of the spec destination: directory where the backups shall reside limit: max amount of backups - notifier: notifier object + extension: file extension of the backup files + notify: notifier object to send IFTT notifications """ self.name = name self.destination = Path(destination) @@ -119,5 +120,6 @@ class Spec: def to_dict(self): """Export the class as a dictionary. - This function should be imnplemented by the subclasses.""" + This function should be imnplemented by the subclasses. + """ raise NotImplementedError() diff --git a/app/specs/volume.py b/app/specs/volume.py index f6f0980..27d6e7c 100644 --- a/app/specs/volume.py +++ b/app/specs/volume.py @@ -1,3 +1,6 @@ +"""Module defining a Docker volume-based spec.""" + + from .spec import Spec from typing import Union from pathlib import Path @@ -25,6 +28,18 @@ class VolumeSpec(Spec): extension: str, notify=None, ): + """Initialize a new VolumeSpec object. + + Args: + name: name of the spec + volume: Docker volume to back up + image: base image to use to run backup command + destination: where to store the backup files + limit: max backup files to keep + command: backup command to run within the base image + extension: file extension of the backup files + notify: Notifier object + """ super().__init__(name, destination, limit, extension, notify) self.volume = volume @@ -32,6 +47,7 @@ class VolumeSpec(Spec): self.command = command def backup(self): + """Create a new backup.""" # Remove excess backups self.remove_backups() @@ -40,8 +56,10 @@ class VolumeSpec(Spec): datetime.now().strftime("%Y-%m-%d_%H-%M-%S"), self.extension ) + base_cmd = "docker run --rm -v '{}:/from' -v '{}:/to' -w /from '{}' {}" + process = subprocess.run( - "docker run --rm -v '{}:/from' -v '{}:/to' -w /from '{}' {}".format( + base_cmd.format( self.volume, self.destination, self.image,