pep8 and spelling errors

This commit is contained in:
Einar Forselv 2019-11-12 12:39:49 +01:00
parent 1fbdb89141
commit 4b9748a0c8
6 changed files with 23 additions and 27 deletions

View file

@ -1,13 +1,11 @@
import os import os
import sys
import time
import docker import docker
from restic_volume_backup.config import Config from restic_volume_backup.config import Config
def run(image: str = None, command: str = None, volumes: dict = None, def run(image: str = None, command: str = None, volumes: dict = None,
enviroment: dict = None, labels: dict = None): environment: dict = None, labels: dict = None):
config = Config() config = Config()
client = docker.DockerClient(base_url=config.docker_base_url) client = docker.DockerClient(base_url=config.docker_base_url)
@ -17,7 +15,7 @@ def run(image: str = None, command: str = None, volumes: dict = None,
labels=labels, labels=labels,
# auto_remove=True, # auto_remove=True,
detach=True, detach=True,
environment=enviroment, environment=environment,
volumes=volumes, volumes=volumes,
working_dir=os.getcwd(), working_dir=os.getcwd(),
tty=True, tty=True,

View file

@ -1,6 +1,5 @@
import argparse import argparse
import pprint import pprint
import sys
from restic_volume_backup.config import Config from restic_volume_backup.config import Config
from restic_volume_backup.containers import RunningContainers from restic_volume_backup.containers import RunningContainers
@ -25,11 +24,11 @@ def main():
def status(config, containers): def status(config, containers):
"""Outputs the backup config for the compse setup""" """Outputs the backup config for the compose setup"""
print() print()
print("Backup config for compose project '{}'".format(containers.this_container.project_name)) print("Backup config for compose project '{}'".format(containers.this_container.project_name))
print("Current service:", containers.this_container.name) print("Current service:", containers.this_container.name)
print("Backup process :", containers.backup_process_container.name \ print("Backup process :", containers.backup_process_container.name
if containers.backup_process_container else 'Not Running') if containers.backup_process_container else 'Not Running')
print("Backup running :", containers.backup_process_running) print("Backup running :", containers.backup_process_running)
@ -73,7 +72,7 @@ def backup(config, containers):
image=containers.this_container.image, image=containers.this_container.image,
command='restic-volume-backup start-backup-process', command='restic-volume-backup start-backup-process',
volumes=volumes, volumes=volumes,
enviroment=containers.this_container.environment, environment=containers.this_container.environment,
labels={ labels={
"restic-volume-backup.backup_process": 'True', "restic-volume-backup.backup_process": 'True',
"com.docker.compose.project": containers.this_container.project_name, "com.docker.compose.project": containers.this_container.project_name,
@ -83,7 +82,8 @@ def backup(config, containers):
def start_backup_process(config, containers): def start_backup_process(config, containers):
"""Start the backup process container""" """Start the backup process container"""
if not containers.backup_process_container or containers.this_container == containers.backup_process_container is False: if (not containers.backup_process_container
or containers.this_container == containers.backup_process_container is False):
print( print(
"Cannot run backup process in this container. Use backup command instead. " "Cannot run backup process in this container. Use backup command instead. "
"This will spawn a new container with the necessary mounts." "This will spawn a new container with the necessary mounts."
@ -99,6 +99,7 @@ def start_backup_process(config, containers):
exit(1) exit(1)
def parse_args(): def parse_args():
parser = argparse.ArgumentParser(prog='restic_volume_backup') parser = argparse.ArgumentParser(prog='restic_volume_backup')
parser.add_argument( parser.add_argument(

View file

@ -1,7 +1,4 @@
import os import os
import docker
import json
import pprint
from restic_volume_backup import utils from restic_volume_backup import utils
@ -28,7 +25,7 @@ class Container:
self._labels = self._config.get('Labels') self._labels = self._config.get('Labels')
if self._labels is None: if self._labels is None:
raise ValueError('Container mtea missing Config->Labels') raise ValueError('Container meta missing Config->Labels')
self._include = self._parse_pattern(self.get_label('restic-volume-backup.include')) self._include = self._parse_pattern(self.get_label('restic-volume-backup.include'))
self._exclude = self._parse_pattern(self.get_label('restic-volume-backup.exclude')) self._exclude = self._parse_pattern(self.get_label('restic-volume-backup.exclude'))
@ -43,7 +40,7 @@ class Container:
"""All configured env vars for the container""" """All configured env vars for the container"""
return self.get_config('Env', default=[]) return self.get_config('Env', default=[])
property @property
def volumes(self): def volumes(self):
""" """
Return volumes for the container in the following format: Return volumes for the container in the following format:
@ -199,7 +196,7 @@ class Mount:
@property @property
def destination(self) -> str: def destination(self) -> str:
"""Destionatin path for the volume mount in the container""" """Destination path for the volume mount in the container"""
return self._data.get('Destination') return self._data.get('Destination')
def __repr__(self) -> str: def __repr__(self) -> str:
@ -209,13 +206,13 @@ class Mount:
return str(self._data) return str(self._data)
def __hash__(self): def __hash__(self):
"""Uniquness for a volume""" """Uniqueness for a volume"""
if self.type == VOLUME_TYPE_VOLUME: if self.type == VOLUME_TYPE_VOLUME:
return hash(self.name) return hash(self.name)
elif self.type == VOLUME_TYPE_BIND: elif self.type == VOLUME_TYPE_BIND:
return hash(self.source) return hash(self.source)
else: else:
raise ValueError("Uknown volume type: {}".format(self.type)) raise ValueError("Unknown volume type: {}".format(self.type))
class RunningContainers: class RunningContainers:
@ -243,8 +240,9 @@ class RunningContainers:
if container.is_backup_process_container: if container.is_backup_process_container:
self.backup_process_container = container self.backup_process_container = container
# Detect containers beloging to the current compose setup # Detect containers belonging to the current compose setup
if container.project_name == self.this_container.project_name and not container.is_oneoff: if (container.project_name == self.this_container.project_name
and not container.is_oneoff):
if container.id != self.this_container.id: if container.id != self.this_container.id:
self.containers.append(container) self.containers.append(container)

View file

@ -1,5 +1,4 @@
import os from subprocess import Popen, PIPE
from subprocess import Popen, PIPE, check_call
def init_repo(repository): def init_repo(repository):

View file

@ -14,7 +14,7 @@ class ResticBackupTests(unittest.TestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
"""Set up basic enviroment variables""" """Set up basic environment variables"""
os.environ['RESTIC_REPOSITORY'] = "test" os.environ['RESTIC_REPOSITORY'] = "test"
os.environ['RESTIC_PASSWORD'] = "password" os.environ['RESTIC_PASSWORD'] = "password"