From a8b9153e7b35ab6e38c0c19c5e50ebe834b0d024 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 15 Feb 2017 16:51:10 +0100 Subject: [PATCH] Applied flake8 rules --- deploy.py | 5 +-- lib/webhooks/__init__.py | 2 +- lib/webhooks/base_app.py | 8 ++--- lib/webhooks/common.py | 1 - lib/webhooks/deploy.py | 68 ++-------------------------------------- lib/webhooks/r10k.py | 11 +++---- r10k_hook-new.py | 5 +-- 7 files changed, 12 insertions(+), 88 deletions(-) diff --git a/deploy.py b/deploy.py index 32317a3..4e209aa 100755 --- a/deploy.py +++ b/deploy.py @@ -12,10 +12,7 @@ libdir = os.path.join(basedir, 'lib') sys.path.insert(0, libdir) - -import webhooks - -from webhooks.deploy import WebhookDeployApp +from webhooks.deploy import WebhookDeployApp # noqa MY_APPNAME = 'deploy' LOG = logging.getLogger(MY_APPNAME) diff --git a/lib/webhooks/__init__.py b/lib/webhooks/__init__.py index 7e33420..f111991 100644 --- a/lib/webhooks/__init__.py +++ b/lib/webhooks/__init__.py @@ -1,6 +1,6 @@ #!/bin/env python3 # -*- coding: utf-8 -*- -__version__ = '0.5.1' +__version__ = '0.5.2' # vim: ts=4 et list diff --git a/lib/webhooks/base_app.py b/lib/webhooks/base_app.py index a8f8a7e..3d5ab95 100644 --- a/lib/webhooks/base_app.py +++ b/lib/webhooks/base_app.py @@ -12,7 +12,6 @@ import sys import os import logging import re -import textwrap import datetime import json import smtplib @@ -26,7 +25,7 @@ import yaml # Own modules import webhooks -from webhooks.common import pp, to_bytes, to_str, to_bool +from webhooks.common import pp, to_bytes, to_bool __version__ = webhooks.__version__ LOG = logging.getLogger(__name__) @@ -204,7 +203,6 @@ class BaseHookApp(object): # ------------------------------------------------------------------------- def do_arg_parser(self): - arg_parser = argparse.ArgumentParser( description=self.description, add_help=False, @@ -470,7 +468,6 @@ class BaseHookApp(object): sys.stderr.flush() os.dup2(se.fileno(), sys.stderr.fileno()) - #sys.stderr.write("Trying to open logfile {!r} ...\n".format(self.logfile)) # we are in a CGI environment if os.path.isdir(self.log_directory) and os.access(self.log_directory, os.W_OK): lh_file = logging.FileHandler( @@ -556,6 +553,8 @@ class BaseHookApp(object): if self.special_chars_re.search(self.name): msg = "Project {!r}: Received special characters in module name".format( self.full_name) + LOG.error(msg) + self.error_data.append(msg) return False committers = [] @@ -674,4 +673,3 @@ if __name__ == "__main__": # ============================================================================= # vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 list - diff --git a/lib/webhooks/common.py b/lib/webhooks/common.py index 75b2b04..fef2002 100644 --- a/lib/webhooks/common.py +++ b/lib/webhooks/common.py @@ -142,7 +142,6 @@ def to_str(obj, encoding='utf-8'): return to_unicode(obj, encoding) - # ============================================================================= def to_bool(value): """ diff --git a/lib/webhooks/deploy.py b/lib/webhooks/deploy.py index 1f9527c..7df4749 100644 --- a/lib/webhooks/deploy.py +++ b/lib/webhooks/deploy.py @@ -8,27 +8,19 @@ """ # Standard modules -import sys import os import logging -import re import textwrap -import datetime -import json -import traceback import copy import pipes import subprocess -import smtplib -from email.message import EmailMessage # Third party modules -import yaml # Own modules import webhooks -from webhooks.common import pp, to_bytes, to_str, to_bool +from webhooks.common import pp, to_str from webhooks.base_app import BaseHookApp @@ -77,7 +69,6 @@ class WebhookDeployApp(BaseHookApp): return res - # ------------------------------------------------------------------------- def evaluate_config(self, config, yaml_file): @@ -132,7 +123,7 @@ class WebhookDeployApp(BaseHookApp): 'modified': ['lib/webhooks/deploy.py'], 'removed': [], 'timestamp': '2017-01-25T11:20:47+01:00', - 'url': 'https://git.pixelpark.com/ppadmin/puppetmaster-webhooks/commit/257b9...' + 'url': 'https://git.pixelpark.com/ppadmin/puppetmaster-webhooks/commit/257b...' } ], 'event_name': 'push', @@ -210,9 +201,7 @@ class WebhookDeployApp(BaseHookApp): LOG.info("Deploying Hiera working directory ...") - ns = 'puppet' pname = 'hiera' - full_name = ns + '/' + pname parent_dir = '/www/data/puppet-hiera' if 'parent_dir' in cfg and cfg['parent_dir']: parent_dir = cfg['parent_dir'] @@ -238,59 +227,6 @@ class WebhookDeployApp(BaseHookApp): return self.ensure_workingdir(parent_dir, workdir) - # ------------------------------------------------------------------------- - def deploy_puppet_modules(self): - - LOG.info("Deploying puppet modules working directory ...") - - ns = 'puppet' - pname = cfg['name'] - full_name = ns + '/' + pname - parent_dir = self.default_parent_dir - if 'parent_dir' in cfg and cfg['parent_dir']: - parent_dir = cfg['parent_dir'] - - if not os.access(parent_dir, os.F_OK): - msg = "Parent directory {d!r} of project {p!r} does not exists.".format( - d=parent_dir, p=full_name) - LOG.error(msg) - self.error_data.append(msg) - return True - - if not os.path.isdir(parent_dir): - msg = ("Path for parent directory {d!r} for project {p!r} " - "is not a directory.").format(d=parent_dir, p=full_name) - LOG.error(msg) - self.error_data.append(msg) - return True - - env_branch = 'undefined' - if self.dev_re.match(self.ref): - env_branch = 'development' - elif self.ref == 'master': - env_branch = 'test' - full_path_branch = os.path.join(parent_dir, env_branch) - if not os.access(full_path_branch, os.F_OK): - msg = "Branch directory {d!r} of project {p!r} does not exists.".format( - d=full_path_branch, p=full_name) - LOG.error(msg) - self.error_data.append(msg) - return True - - modules_dir = os.path.join(full_path_branch, 'modules') - if not os.access(modules_dir, os.F_OK): - msg = "Modules directory {d!r} of project {p!r} does not exists.".format( - d=modules_dir, p=full_name) - LOG.error(msg) - self.error_data.append(msg) - return True - - branc2clone = None - if env_branch =='test': - branc2clone = 'master' - - return self.ensure_workingdir(parent_dir=modules_dir, workdir=pname, branch=branc2clone) - # ------------------------------------------------------------------------- def deploy(self, cfg): diff --git a/lib/webhooks/r10k.py b/lib/webhooks/r10k.py index 98ed864..489382c 100644 --- a/lib/webhooks/r10k.py +++ b/lib/webhooks/r10k.py @@ -11,21 +11,18 @@ import sys import os import logging -import re import textwrap -import datetime import locale import pipes import subprocess import urllib.parse # Third party modules -import yaml # Own modules import webhooks -from webhooks.common import pp, to_bytes, to_str, to_bool +from webhooks.common import pp, to_str, to_bool from webhooks.base_app import BaseHookApp @@ -143,8 +140,8 @@ class R10kHookApp(BaseHookApp): try: self.puppetmaster_api_port = int(ppm_cfg['api_port']) except Exception as e: - msg = "Invalid port {p!r} for puppetmaster API in {f!r} found.".format( - p=ppm_cfg['api_port'], f=yaml_file) + msg = "Invalid port {p!r} for puppetmaster API in {f!r} found: {e}".format( + p=ppm_cfg['api_port'], f=yaml_file, e=e) self.error_data.append(msg) if 'api_path' in ppm_cfg and ppm_cfg['api_path']: self.puppetmaster_api_path = ppm_cfg['api_path'] @@ -185,7 +182,7 @@ class R10kHookApp(BaseHookApp): self.puppetmaster_ssl_dir, 'certs', 'ca.pem') path = ( - self.puppetmaster_api_path + '/environment-cache?environment=' + + self.puppetmaster_api_path + '/environment-cache?environment=' + urllib.parse.quote(self.ref)) url = 'https://{h}:{po}{pa}'.format( h=self.puppetmaster_host, po=self.puppetmaster_api_port, pa=path) diff --git a/r10k_hook-new.py b/r10k_hook-new.py index b7a3189..a8baaaf 100755 --- a/r10k_hook-new.py +++ b/r10k_hook-new.py @@ -12,10 +12,7 @@ libdir = os.path.join(basedir, 'lib') sys.path.insert(0, libdir) - -import webhooks - -from webhooks.r10k import R10kHookApp +from webhooks.r10k import R10kHookApp # noqa MY_APPNAME = 'r10k-hook' LOG = logging.getLogger(MY_APPNAME) -- 2.39.5