]> Frank Brehm's Git Trees - pixelpark/puppetmaster-webhooks.git/commitdiff
Applying flake8 rules and bugfixing
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 6 Sep 2018 15:15:58 +0000 (17:15 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 6 Sep 2018 15:15:58 +0000 (17:15 +0200)
lib/webhooks/get_forge_modules.py
lib/webhooks/module_list.py
lib/webhooks/puppetfile.py
lib/webhooks/show_modules.py

index 0a021d042ac784722f040bfe1b4c23d01e195c1c..18bc2f8a858a22e6b45dec197b97839a5f1d7fc9 100644 (file)
@@ -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}
index 499e0157be939713d5fdb39069781d06aecd2853..97da10d2a629ec9182a73ecff6da60d290b2eaa5 100644 (file)
@@ -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'
     """
 
index 797da366ccca282f1d2f074b2a6bd5d60019f0e8..70880a3687c43571db8eaccc4f7f71577ae8198e 100644 (file)
@@ -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."""
index 0a29a952b98bb3e006e2c0abed22eaa8f10e7793..27726dead276e0824e33584710e2bf12f51e8464 100644 (file)
@@ -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('      <th rowspan="2" class="l h confluenceTh">Name</th>')
         self.print_out('      <th rowspan="2" class="l h confluenceTh">Vollständiger Name</th>')
         self.print_out('      <th rowspan="2" class="h confluenceTh">Repository</th>')
-        self.print_out('      <th rowspan="2" class="h confluenceTh">Homepage bei Puppet Forge</th>')
+        self.print_out(
+            '      <th rowspan="2" class="h confluenceTh">Homepage bei Puppet Forge</th>')
         self.print_out('      <th colspan="4" class="h confluenceTh">Version</th>')
         self.print_out('      <th rowspan="2" class="h confluenceTh">Letzter Check</th>')
         self.print_out('    </tr><tr>')