From 944668dd610aa8a15c0cccf681fa509fd50106f9 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 3 Jan 2019 18:11:34 +0100 Subject: [PATCH] Applying flake8 rules --- deploy.py | 4 +--- lib/webhooks/__init__.py | 2 +- lib/webhooks/base_app.py | 10 ++++++---- lib/webhooks/deploy.py | 4 ++-- lib/webhooks/get_forge_modules.py | 9 --------- lib/webhooks/get_module_changes.py | 5 +---- lib/webhooks/r10k.py | 6 +----- lib/webhooks/show_modules.py | 9 ++------- r10k_hook.py | 1 - show-modules-html.py | 3 +-- show-modules-txt.py | 3 +-- show-modules.py | 3 +-- 12 files changed, 17 insertions(+), 42 deletions(-) diff --git a/deploy.py b/deploy.py index bdd8f46..be941c9 100755 --- a/deploy.py +++ b/deploy.py @@ -2,10 +2,8 @@ # -*- coding: utf-8 -*- # Standard modules -import os import sys import logging -import pathlib from pathlib import Path @@ -17,7 +15,7 @@ libdir = base_dir.joinpath('lib') sys.path.insert(0, str(libdir)) -from webhooks.deploy import WebhookDeployApp +from webhooks.deploy import WebhookDeployApp # noqa MY_APPNAME = my_path.stem LOG = logging.getLogger(MY_APPNAME) diff --git a/lib/webhooks/__init__.py b/lib/webhooks/__init__.py index 27cb436..9898ebc 100644 --- a/lib/webhooks/__init__.py +++ b/lib/webhooks/__init__.py @@ -1,6 +1,6 @@ #!/bin/env python3 # -*- coding: utf-8 -*- -__version__ = '1.4.6' +__version__ = '1.4.7' # vim: ts=4 et list diff --git a/lib/webhooks/base_app.py b/lib/webhooks/base_app.py index 217789a..48b1726 100644 --- a/lib/webhooks/base_app.py +++ b/lib/webhooks/base_app.py @@ -32,13 +32,11 @@ from email.message import EmailMessage import six import yaml import pytz -import pathlib # Own modules from fb_tools.common import pp, to_bytes, to_bool -from fb_tools.obj import FbBaseObject from fb_tools.handler import BaseHandler -from fb_tools.errors import FbAppError +from fb_tools.errors import FbAppError, FunctionNotImplementedError from fb_tools.app import BaseApplication from . import __version__ as __pkg_version__ @@ -64,6 +62,7 @@ DEFAULT_TO_SENDER = 'Puppet <{}>'.format(DEFAULT_TO_EMAIL) _ = XLATOR.gettext ngettext = XLATOR.ngettext + # ============================================================================= class BaseHookError(FbAppError): """ @@ -72,6 +71,7 @@ class BaseHookError(FbAppError): pass + # ============================================================================= class UncriticalHookError(BaseHookError): """ @@ -97,6 +97,7 @@ class DataDirOptionAction(argparse.Action, UncriticalHookError): setattr(namespace, self.dest, data_dir) + # ============================================================================= class LogDirOptionAction(argparse.Action, UncriticalHookError): @@ -107,12 +108,13 @@ class LogDirOptionAction(argparse.Action, UncriticalHookError): msg = _("Logging directory {!r} does not exists.").format(str(log_dir)) raise argparse.ArgumentError(self, msg) - if not data_dir.is_dir(): + if not log_dir.is_dir(): msg = _("Path to logging directory {!r} is not a directory.").format(str(log_dir)) raise argparse.ArgumentError(self, msg) setattr(namespace, self.dest, log_dir) + # ============================================================================= class BaseHookApp(BaseApplication): """ diff --git a/lib/webhooks/deploy.py b/lib/webhooks/deploy.py index 78a0082..b1a55e9 100644 --- a/lib/webhooks/deploy.py +++ b/lib/webhooks/deploy.py @@ -11,7 +11,6 @@ from __future__ import absolute_import # Standard modules import os import logging -import textwrap import copy import pipes import pathlib @@ -19,7 +18,7 @@ import pathlib # Third party modules # Own modules -from fb_tools.common import pp, to_str +from fb_tools.common import pp from . import __version__ @@ -305,6 +304,7 @@ class WebhookDeployApp(BaseHookApp): finally: os.chdir(cur_dir) + # ============================================================================= if __name__ == "__main__": diff --git a/lib/webhooks/get_forge_modules.py b/lib/webhooks/get_forge_modules.py index 05ba0e4..fad0de9 100644 --- a/lib/webhooks/get_forge_modules.py +++ b/lib/webhooks/get_forge_modules.py @@ -11,7 +11,6 @@ from __future__ import absolute_import # Standard modules import os import logging -import textwrap import json import glob import datetime @@ -27,7 +26,6 @@ from operator import itemgetter # Third party modules import six import yaml -import babel from babel.dates import format_datetime, LOCALTZ @@ -184,8 +182,6 @@ class GetForgeModulesApp(BaseHookApp): def run_hook(self): """Main routine.""" - my_loc = babel.core.default_locale() - d = datetime.datetime.now(LOCALTZ) dt = format_datetime(d, 'yyyy-MM-dd HH:mm:ss z', tzinfo=LOCALTZ) @@ -268,13 +264,8 @@ class GetForgeModulesApp(BaseHookApp): LOG.info(_("Reading metadata files of environment {!r} ...").format(env)) - #pattern = os.path.join(self.puppet_root_env_dir, env, 'modules', '*') - #if self.verbose > 2: - # LOG.debug("Globbing pattern for module directories: {!r}".format(str(pattern))) - modules_dir = self.puppet_root_env_dir / env / 'modules' - #for module_dir in glob.glob(str(pattern)): for module_dir in modules_dir.glob('*'): module_info = self.get_meta_module_info(module_dir, env) if module_info: diff --git a/lib/webhooks/get_module_changes.py b/lib/webhooks/get_module_changes.py index 6070ed8..412992a 100644 --- a/lib/webhooks/get_module_changes.py +++ b/lib/webhooks/get_module_changes.py @@ -10,15 +10,12 @@ from __future__ import absolute_import # Standard modules import logging -import textwrap import datetime import re -import time from distutils.version import LooseVersion # Third party modules -import babel from babel.dates import format_datetime, LOCALTZ # Own modules @@ -41,6 +38,7 @@ class GetModuleChangesError(BaseHookError): pass + # ============================================================================= class InvalidEnvironmentError(GetModuleChangesError): @@ -154,7 +152,6 @@ class GetModuleChangesApp(BaseHookApp): super(GetModuleChangesApp, self).post_init() self.read_stdin = False - # self.no_error_mail = True self.initialized = True # ------------------------------------------------------------------------- diff --git a/lib/webhooks/r10k.py b/lib/webhooks/r10k.py index 5e8faf2..95f5a01 100644 --- a/lib/webhooks/r10k.py +++ b/lib/webhooks/r10k.py @@ -12,7 +12,6 @@ from __future__ import absolute_import import sys import os import logging -import textwrap import locale import pipes import urllib.parse @@ -23,9 +22,6 @@ import pathlib import requests # Own modules -from fb_tools.common import to_str -from fb_tools.handler import BaseHandler - from . import __version__ from .base_app import BaseHookApp @@ -233,7 +229,7 @@ class R10kHookApp(BaseHookApp): bname = self.puppetmaster_host + '.pem' key_file = self.puppetmaster_ssl_dir / 'private_keys' / bname cert_file = self.puppetmaster_ssl_dir / 'certs' / bname - ca_file = self.puppetmaster_ssl_dir / 'certs' /'ca.pem' + ca_file = self.puppetmaster_ssl_dir / 'certs' / 'ca.pem' cert = (str(cert_file), str(key_file)) session = requests.Session() diff --git a/lib/webhooks/show_modules.py b/lib/webhooks/show_modules.py index 3e3445f..7643fb7 100644 --- a/lib/webhooks/show_modules.py +++ b/lib/webhooks/show_modules.py @@ -11,7 +11,6 @@ from __future__ import absolute_import # Standard modules import logging -import textwrap import json import datetime import re @@ -40,11 +39,13 @@ class ShowModulesError(BaseHookError): pass + # ============================================================================= class ShowModulesUncriticalError(ShowModulesError, UncriticalHookError): pass + # ============================================================================= class ShowModulesApp(BaseHookApp): """ @@ -296,9 +297,6 @@ class ShowModulesApp(BaseHookApp): self.print_out(" ") self.print_out("") - plural_e = 'e' - if nr_modules == 1: - plural_e = '' msg = "
" + ngettext( "Found total {sb}one module{eb}.", "Found total {sb}{nr} modules{eb}.", nr_modules).format( @@ -364,9 +362,6 @@ class ShowModulesApp(BaseHookApp): if self.verbose > 2: LOG.debug("Zeilen-Template:\n{}".format(tpl)) - plural_e = 'e' - if nr_modules == 1: - plural_e = '' msg = "\n" + ngettext( "Found total {sb}one module{eb}.", "Found total {sb}{nr} modules{eb}.", nr_modules).format( diff --git a/r10k_hook.py b/r10k_hook.py index f565482..1cf1999 100755 --- a/r10k_hook.py +++ b/r10k_hook.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- # Standard modules -import os import sys import logging diff --git a/show-modules-html.py b/show-modules-html.py index a9c1450..56ff57b 100755 --- a/show-modules-html.py +++ b/show-modules-html.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- # Standard modules -import os import sys import logging @@ -16,7 +15,7 @@ libdir = base_dir.joinpath('lib') sys.path.insert(0, str(libdir)) -from webhooks.show_modules import ShowModulesApp +from webhooks.show_modules import ShowModulesApp # noqa MY_APPNAME = my_path.stem LOG = logging.getLogger(MY_APPNAME) diff --git a/show-modules-txt.py b/show-modules-txt.py index ed48a7d..07fe102 100755 --- a/show-modules-txt.py +++ b/show-modules-txt.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- # Standard modules -import os import sys import logging @@ -16,7 +15,7 @@ libdir = base_dir.joinpath('lib') sys.path.insert(0, str(libdir)) -from webhooks.show_modules import ShowModulesApp +from webhooks.show_modules import ShowModulesApp # noqa MY_APPNAME = my_path.stem LOG = logging.getLogger(MY_APPNAME) diff --git a/show-modules.py b/show-modules.py index 9d75371..d6ccae5 100755 --- a/show-modules.py +++ b/show-modules.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- # Standard modules -import os import sys import logging @@ -16,7 +15,7 @@ libdir = base_dir.joinpath('lib') sys.path.insert(0, str(libdir)) -from webhooks.show_modules import ShowModulesApp +from webhooks.show_modules import ShowModulesApp # noqa MY_APPNAME = my_path.stem LOG = logging.getLogger(MY_APPNAME) -- 2.39.5