From 9326075f46edf3268f37353615dfa1f79b785488 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 6 Sep 2018 17:15:58 +0200 Subject: [PATCH] Applying flake8 rules and bugfixing --- lib/webhooks/get_forge_modules.py | 3 +- lib/webhooks/module_list.py | 14 +--- lib/webhooks/puppetfile.py | 9 +-- lib/webhooks/show_modules.py | 128 +++++++++++++++++------------- 4 files changed, 78 insertions(+), 76 deletions(-) diff --git a/lib/webhooks/get_forge_modules.py b/lib/webhooks/get_forge_modules.py index 0a021d0..18bc2f8 100644 --- a/lib/webhooks/get_forge_modules.py +++ b/lib/webhooks/get_forge_modules.py @@ -13,7 +13,6 @@ import os import logging import textwrap import json -import re import glob import datetime import fcntl @@ -81,7 +80,7 @@ class GetForgeModulesApp(BaseHookApp): self.forge_uri = self.default_forge_uri self.http_timeout = self.default_http_timeout self.modules = None - self_do_forge = True + self._do_forge = True self.description = textwrap.dedent('''\ Collects information about all used Puppet Modules from {url} diff --git a/lib/webhooks/module_list.py b/lib/webhooks/module_list.py index 499e015..97da10d 100644 --- a/lib/webhooks/module_list.py +++ b/lib/webhooks/module_list.py @@ -10,13 +10,6 @@ from __future__ import absolute_import # Standard modules import logging -import re -import copy -import warnings -import time -import datetime - -from operator import itemgetter, attrgetter from collections import MutableMapping @@ -25,14 +18,11 @@ from functools import cmp_to_key # Third party modules # Own modules -from .common import pp, to_str, to_bool, is_sequence - -from .obj import BaseObjectError from .obj import BaseObject from .module_info import ModuleInfo -__version__ = '0.1.3' +__version__ = '0.1.4' LOG = logging.getLogger(__name__) @@ -43,7 +33,7 @@ class ModuleInfoDict(MutableMapping, BaseObject): It works like a dict. i.e.: modules = ModuleInfoDict(ModuleInfo(full_name='puppet-mongodb', ...)) - and + and modules['puppet-mongodb'] returns a ModuleInfo object for puppet module 'puppet-mongodb' """ diff --git a/lib/webhooks/puppetfile.py b/lib/webhooks/puppetfile.py index 797da36..70880a3 100644 --- a/lib/webhooks/puppetfile.py +++ b/lib/webhooks/puppetfile.py @@ -13,10 +13,6 @@ from __future__ import absolute_import import logging import os import re -import copy -import warnings -import time -import datetime import pwd import grp @@ -24,8 +20,6 @@ import grp import six # Own modules -from .common import pp, to_str, to_bool, is_sequence - from .obj import BaseObjectError from .obj import BaseObject @@ -33,7 +27,7 @@ from .module_info import ModuleInfo from .module_list import ModuleInfoDict -__version__ = '0.3.2' +__version__ = '0.3.3' LOG = logging.getLogger(__name__) @@ -44,7 +38,6 @@ class PuppetfileError(BaseObjectError): pass - # ============================================================================= class Puppetfile(BaseObject): """Class for encapsulating a Puppetfile of a r10k environment.""" diff --git a/lib/webhooks/show_modules.py b/lib/webhooks/show_modules.py index 0a29a95..27726de 100644 --- a/lib/webhooks/show_modules.py +++ b/lib/webhooks/show_modules.py @@ -25,7 +25,7 @@ import yaml # Own modules from . import __version__ -from .common import pp, to_str, is_sequence +from .common import pp, is_sequence from .base_app import BaseHookError, BaseHookApp @@ -114,64 +114,83 @@ class ShowModulesApp(BaseHookApp): # ------------------------------------------------------------------------- def init_filters(self): - if 'vendor' in self.query: - q_vendors = [] - if is_sequence(self.query['vendor']): - for vendor in self.query['vendor']: - v = vendor.strip().lower() - if v and v not in q_vendors: - q_vendors.append(v) - else: - v = self.query['vendor'].strip().lower() + self._init_filter_vendor() + self._init_filter_name() + self._init_filter_re() + + # ------------------------------------------------------------------------- + def _init_filter_vendor(self): + + if 'vendor' not in self.query: + return + + q_vendors = [] + if is_sequence(self.query['vendor']): + for vendor in self.query['vendor']: + v = vendor.strip().lower() if v and v not in q_vendors: q_vendors.append(v) - if q_vendors: - if self.filters is None: - self.filters = {} - self.filters['vendor'] = q_vendors - - if 'name' in self.query: - q_names = [] - if is_sequence(self.query['name']): - for name in self.query['name']: - v = name.strip().lower() - if v and v not in q_names: - q_names.append(v) - else: - v = self.query['name'].strip().lower() + else: + v = self.query['vendor'].strip().lower() + if v and v not in q_vendors: + q_vendors.append(v) + if q_vendors: + if self.filters is None: + self.filters = {} + self.filters['vendor'] = q_vendors + + # ------------------------------------------------------------------------- + def _init_filter_name(self): + + if 'name' not in self.query: + return + + q_names = [] + if is_sequence(self.query['name']): + for name in self.query['name']: + v = name.strip().lower() if v and v not in q_names: q_names.append(v) - if q_names: - if self.filters is None: - self.filters = {} - self.filters['name'] = q_names - - if 're' in self.query: - q_re = [] - if is_sequence(self.query['re']): - for regex in self.query['re']: - v = regex.strip() - if v: - q_re.append(v) - else: - v = self.query['re'].strip() + else: + v = self.query['name'].strip().lower() + if v and v not in q_names: + q_names.append(v) + if q_names: + if self.filters is None: + self.filters = {} + self.filters['name'] = q_names + + # ------------------------------------------------------------------------- + def _init_filter_re(self): + + if 're' not in self.query: + return + + q_re = [] + if is_sequence(self.query['re']): + for regex in self.query['re']: + v = regex.strip() if v: q_re.append(v) - if q_re: - if self.filters is None: - self.filters = {} - for regex in q_re: - regex_compiled = None - try: - regex_compiled = re.compile(regex, re.IGNORECASE) - except Exception as e: - LOG.error("{c}: Invalid regular expression {r!r}: {e}".format( - c=e.__class__.__name__, r=regex, e=e)) - else: - if 're' not in self.filters: - self.filters['re'] = [] - if regex_compiled not in self.filters['re']: - self.filters['re'].append(regex_compiled) + else: + v = self.query['re'].strip() + if v: + q_re.append(v) + if q_re: + if self.filters is None: + self.filters = {} + for regex in q_re: + regex_compiled = None + try: + regex_compiled = re.compile(regex, re.IGNORECASE) + except Exception as e: + LOG.error("{c}: Invalid regular expression {r!r}: {e}".format( + c=e.__class__.__name__, r=regex, e=e)) + else: + if 're' not in self.filters: + self.filters['re'] = [] + if regex_compiled not in self.filters['re']: + self.filters['re'].append(regex_compiled) # ------------------------------------------------------------------------- def run(self): @@ -234,7 +253,8 @@ class ShowModulesApp(BaseHookApp): self.print_out(' Name') self.print_out(' Vollständiger Name') self.print_out(' Repository') - self.print_out(' Homepage bei Puppet Forge') + self.print_out( + ' Homepage bei Puppet Forge') self.print_out(' Version') self.print_out(' Letzter Check') self.print_out(' ') -- 2.39.5