From 6f06d25db53003382d5ec0343468360326a80f49 Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Thu, 5 Dec 2019 11:09:36 +0100 Subject: [PATCH] pep8 --- src/restic_compose_backup/alerts/__init__.py | 3 +-- src/restic_compose_backup/alerts/discord.py | 3 +-- src/restic_compose_backup/cli.py | 5 +++-- src/restic_compose_backup/commands.py | 6 +++--- src/restic_compose_backup/containers.py | 4 ++-- src/restic_compose_backup/log.py | 1 + src/restic_compose_backup/restic.py | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/restic_compose_backup/alerts/__init__.py b/src/restic_compose_backup/alerts/__init__.py index 6c33513..44ed7ef 100644 --- a/src/restic_compose_backup/alerts/__init__.py +++ b/src/restic_compose_backup/alerts/__init__.py @@ -2,7 +2,6 @@ import logging from restic_compose_backup.alerts.smtp import SMTPAlert from restic_compose_backup.alerts.discord import DiscordWebhookAlert -from restic_compose_backup.config import Config logger = logging.getLogger(__name__) @@ -37,7 +36,7 @@ def configured_alert_types(): for cls in BACKENDS: instance = cls.create_from_env() - logger.debug("Alert backend '%s' configured: %s", cls.name, instance != None) + logger.debug("Alert backend '%s' configured: %s", cls.name, instance is not None) if instance: entires.append(instance) diff --git a/src/restic_compose_backup/alerts/discord.py b/src/restic_compose_backup/alerts/discord.py index fc6ce48..efc6965 100644 --- a/src/restic_compose_backup/alerts/discord.py +++ b/src/restic_compose_backup/alerts/discord.py @@ -1,6 +1,5 @@ import os import logging -from urllib.parse import urlparse import requests from restic_compose_backup.alerts.base import BaseAlert @@ -41,6 +40,6 @@ class DiscordWebhookAlert(BaseAlert): } response = requests.post(self.url, params={'wait': True}, json=data) if response.status_code not in self.success_codes: - log.error("Discord webhook failed: %s: %s", response.status_code, response.content) + logger.error("Discord webhook failed: %s: %s", response.status_code, response.content) else: logger.info('Discord webhook successful') diff --git a/src/restic_compose_backup/cli.py b/src/restic_compose_backup/cli.py index c59c193..71f9bff 100644 --- a/src/restic_compose_backup/cli.py +++ b/src/restic_compose_backup/cli.py @@ -1,5 +1,4 @@ import argparse -import pprint import logging from restic_compose_backup import ( @@ -63,7 +62,8 @@ def status(config, containers): ping = instance.ping() logger.info(' - %s (is_ready=%s)', instance.container_type, ping == 0) if ping != 0: - logger.error("Database '%s' in service %s cannot be reached", instance.container_type, container.service_name) + logger.error("Database '%s' in service %s cannot be reached", + instance.container_type, container.service_name) if len(backup_containers) == 0: logger.info("No containers in the project has 'restic-compose-backup.enabled' label") @@ -185,6 +185,7 @@ def cleanup(config, containers): prune_result = restic.prune(config.repository) return forget_result == 0 and prune_result == 0 + def snapshots(config, containers): """Display restic snapshots""" stdout, stderr = restic.snapshots(config.repository, last=True) diff --git a/src/restic_compose_backup/commands.py b/src/restic_compose_backup/commands.py index 8773b58..706dd85 100644 --- a/src/restic_compose_backup/commands.py +++ b/src/restic_compose_backup/commands.py @@ -6,7 +6,7 @@ logger = logging.getLogger(__name__) def test(): - return run_command(['ls', '/volumes']) + return run(['ls', '/volumes']) def ping_mysql(host, port, username) -> int: @@ -23,7 +23,7 @@ def ping_mysql(host, port, username) -> int: ]) -def ping_mariadb(host, port, username): #, password) -> int: +def ping_mariadb(host, port, username) -> int: """Check if the mariadb is up and can be reached""" return run([ 'mysqladmin', @@ -43,7 +43,7 @@ def ping_postgres(host, port, username, password) -> int: "pg_isready", f"--host={host}", f"--port={port}", - f"--username={username}", + f"--username={username}", ]) diff --git a/src/restic_compose_backup/containers.py b/src/restic_compose_backup/containers.py index 490e807..d54c9dc 100644 --- a/src/restic_compose_backup/containers.py +++ b/src/restic_compose_backup/containers.py @@ -68,7 +68,7 @@ class Container: def get_config_env(self, name) -> str: """Get a config environment variable by name""" # convert to dict and fetch env var by name - data = {i[0:i.find('=')]: i[i.find('=')+1:] for i in self.environment} + data = {i[0:i.find('=')]: i[i.find('=') + 1:] for i in self.environment} return data.get(name) def set_config_env(self, name, value): @@ -169,7 +169,7 @@ class Container: return self._labels.get(name, None) def filter_mounts(self): - """Get all mounts for this container matching include/exclude filters""" + """Get all mounts for this container matching include/exclude filters""" filtered = [] if not self.volume_backup_enabled: diff --git a/src/restic_compose_backup/log.py b/src/restic_compose_backup/log.py index 8e6de70..4c3e82b 100644 --- a/src/restic_compose_backup/log.py +++ b/src/restic_compose_backup/log.py @@ -13,6 +13,7 @@ LOG_LEVELS = { 'error': logging.ERROR, } + def setup(level: str = 'warning'): """Set up logging""" level = level or "" diff --git a/src/restic_compose_backup/restic.py b/src/restic_compose_backup/restic.py index 938f995..aaa2cb8 100644 --- a/src/restic_compose_backup/restic.py +++ b/src/restic_compose_backup/restic.py @@ -63,7 +63,7 @@ def backup_from_stdin(repository: str, filename: str, source_command: List[str]) def snapshots(repository: str, last=True) -> Tuple[str, str]: args = ["snapshots"] if last: - args.append('--last') + args.append('--last') return commands.run_capture_std(restic(repository, args))