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 sys
import time
import docker
from restic_volume_backup.config import Config
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()
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,
# auto_remove=True,
detach=True,
environment=enviroment,
environment=environment,
volumes=volumes,
working_dir=os.getcwd(),
tty=True,

View File

@ -1,6 +1,5 @@
import argparse
import pprint
import sys
from restic_volume_backup.config import Config
from restic_volume_backup.containers import RunningContainers
@ -25,12 +24,12 @@ def main():
def status(config, containers):
"""Outputs the backup config for the compse setup"""
"""Outputs the backup config for the compose setup"""
print()
print("Backup config for compose project '{}'".format(containers.this_container.project_name))
print("Current service:", containers.this_container.name)
print("Backup process :", containers.backup_process_container.name \
if containers.backup_process_container else 'Not Running')
print("Backup process :", containers.backup_process_container.name
if containers.backup_process_container else 'Not Running')
print("Backup running :", containers.backup_process_running)
print()
@ -52,7 +51,7 @@ def backup(config, containers):
"""Start backup"""
# Make sure we don't spawn multiple backup processes
if containers.backup_process_running:
raise ValueError("Backup process already running")
raise ValueError("Backup process already running")
print("Initializing repository")
@ -73,7 +72,7 @@ def backup(config, containers):
image=containers.this_container.image,
command='restic-volume-backup start-backup-process',
volumes=volumes,
enviroment=containers.this_container.environment,
environment=containers.this_container.environment,
labels={
"restic-volume-backup.backup_process": 'True',
"com.docker.compose.project": containers.this_container.project_name,
@ -83,7 +82,8 @@ def backup(config, containers):
def start_backup_process(config, containers):
"""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(
"Cannot run backup process in this container. Use backup command instead. "
"This will spawn a new container with the necessary mounts."
@ -99,6 +99,7 @@ def start_backup_process(config, containers):
exit(1)
def parse_args():
parser = argparse.ArgumentParser(prog='restic_volume_backup')
parser.add_argument(

View File

@ -6,7 +6,7 @@ class Config:
self.repository = os.environ['RESTIC_REPOSITORY']
self.password = os.environ['RESTIC_PASSWORD']
self.docker_base_url = os.environ.get('DOCKER_BASE_URL') or "unix://tmp/docker.sock"
if check:
self.check()

View File

@ -1,7 +1,4 @@
import os
import docker
import json
import pprint
from restic_volume_backup import utils
@ -28,7 +25,7 @@ class Container:
self._labels = self._config.get('Labels')
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._exclude = self._parse_pattern(self.get_label('restic-volume-backup.exclude'))
@ -43,7 +40,7 @@ class Container:
"""All configured env vars for the container"""
return self.get_config('Env', default=[])
property
@property
def volumes(self):
"""
Return volumes for the container in the following format:
@ -90,7 +87,7 @@ class Container:
return self._state.get('Running', False)
@property
def service_name(self) ->str:
def service_name(self) -> str:
"""Name of the container/service"""
return self.get_label('com.docker.compose.service', default='')
@ -189,7 +186,7 @@ class Mount:
@property
def name(self) -> str:
"""Name of the mount"""
"""Name of the mount"""
return self._data.get('Name')
@property
@ -199,7 +196,7 @@ class Mount:
@property
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')
def __repr__(self) -> str:
@ -209,13 +206,13 @@ class Mount:
return str(self._data)
def __hash__(self):
"""Uniquness for a volume"""
"""Uniqueness for a volume"""
if self.type == VOLUME_TYPE_VOLUME:
return hash(self.name)
elif self.type == VOLUME_TYPE_BIND:
return hash(self.source)
else:
raise ValueError("Uknown volume type: {}".format(self.type))
raise ValueError("Unknown volume type: {}".format(self.type))
class RunningContainers:
@ -243,8 +240,9 @@ class RunningContainers:
if container.is_backup_process_container:
self.backup_process_container = container
# Detect containers beloging to the current compose setup
if container.project_name == self.this_container.project_name and not container.is_oneoff:
# Detect containers belonging to the current compose setup
if (container.project_name == self.this_container.project_name
and not container.is_oneoff):
if container.id != self.this_container.id:
self.containers.append(container)

View File

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

View File

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