]> Frank Brehm's Git Trees - pixelpark/puppetmaster-webhooks.git/commitdiff
Adding new command line parameter --no-forge to get-forge-modules
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 6 Sep 2018 12:51:27 +0000 (14:51 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 6 Sep 2018 12:51:27 +0000 (14:51 +0200)
lib/webhooks/__init__.py
lib/webhooks/base_app.py
lib/webhooks/get_forge_modules.py

index 1fc3a9f6a2493a17a329887ecff196216b64314e..abf952173cde5cff5760063015f31042cc852b1e 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/env python3
 # -*- coding: utf-8 -*-
 
-__version__ = '0.11.3'
+__version__ = '0.11.4'
 
 # vim: ts=4 et list
index 552648d7fdd886e4b068d166b7365f3e75db713d..2da9c3a125cb7bf43c82dd5727d494e13df804e8 100644 (file)
@@ -293,42 +293,58 @@ class BaseHookApp(BaseObject):
             add_help=False,
         )
 
-        arg_parser.add_argument(
+        self._init_arg_parser(arg_parser)
+
+        self._perform_args(arg_parser)
+
+    # -------------------------------------------------------------------------
+    def init_arg_parser(self, arg_parser):
+
+        pass
+
+    # -------------------------------------------------------------------------
+    def _init_arg_parser(self, arg_parser):
+
+        self.init_arg_parser(arg_parser)
+
+        general_group = arg_parser.add_argument_group('General options')
+
+        general_group.add_argument(
             "-N", "--no-error-mail", action='store_true', dest='no_error_mail',
             help="Don't send error messages in case of some exceptions.",
         )
 
-        arg_parser.add_argument(
+        general_group.add_argument(
             "-D", '--data', '--data-dir', metavar='DIR', dest='data_dir',
             help="Data directory, default: {!r}.".format(self.data_dir),
         )
 
-        arg_parser.add_argument(
+        general_group.add_argument(
             "-v", "--verbose", action="count", dest='verbose',
             help='Increase the verbosity level',
         )
 
-        arg_parser.add_argument(
+        general_group.add_argument(
             '-s', '--simulate', '--test', action='store_true', dest='simulate',
             help="Simulation mode, nothing is really done.",
         )
 
-        arg_parser.add_argument(
+        general_group.add_argument(
             "-C", '--cgi', action='store_true', dest='cgi',
             help='Enforces behaviour as called as a CGI script.',
         )
 
-        arg_parser.add_argument(
+        general_group.add_argument(
             "-h", "--help", action='help', dest='help',
             help='Show this help message and exit'
         )
 
-        arg_parser.add_argument(
+        general_group.add_argument(
             "--usage", action='store_true', dest='usage',
             help="Display brief usage message and exit"
         )
 
-        arg_parser.add_argument(
+        general_group.add_argument(
             "-V", '--version', action='version',
             version='Version of %(prog)s: {}'.format(self.version),
             help="Show program's version number and exit"
@@ -339,6 +355,9 @@ class BaseHookApp(BaseObject):
             help="An optional query string like on HTTP GET requests."
         )
 
+    # -------------------------------------------------------------------------
+    def _perform_args(self, arg_parser):
+
         self.cmdline_args = arg_parser.parse_args()
 
         if self.cmdline_args.usage:
@@ -376,6 +395,13 @@ class BaseHookApp(BaseObject):
             except ValueError as e:
                 LOG.error(str(e))
 
+        self.perform_args(arg_parser)
+
+    # -------------------------------------------------------------------------
+    def perform_args(self, arg_parser):
+
+        pass
+
     # -------------------------------------------------------------------------
     def _get_query(self):
 
index 7824b997660720a4ed378df508731e95f196584d..0a021d042ac784722f040bfe1b4c23d01e195c1c 100644 (file)
@@ -33,7 +33,7 @@ from six import reraise
 # Own modules
 from . import __version__
 
-from .common import pp, to_bytes
+from .common import pp, to_bytes, to_bool
 
 from .base_app import BaseHookError, BaseHookApp
 
@@ -81,6 +81,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.description = textwrap.dedent('''\
             Collects information about all used Puppet Modules from {url}
@@ -94,6 +95,31 @@ class GetForgeModulesApp(BaseHookApp):
         self.modules = ModuleInfoDict(
             appname=self.appname, verbose=self.verbose, base_dir=self.base_dir)
 
+    # -----------------------------------------------------------
+    @property
+    def do_forge(self):
+        """Flag for simulation mode."""
+        return getattr(self, '_do_forge', True)
+
+    @do_forge.setter
+    def do_forge(self, value):
+        self._do_forge = to_bool(value)
+
+    # -------------------------------------------------------------------------
+    def init_arg_parser(self, arg_parser):
+
+        arg_parser.add_argument(
+            '--no-forge', action='store_true', dest='no_forge',
+            help="Don't get module information from Puppet forge.",
+        )
+
+    # -------------------------------------------------------------------------
+    def perform_args(self, arg_parser):
+
+        if self.cmdline_args.no_forge:
+            sys.stderr.write("\nDon't get module information from Puppet forge.\n\n")
+            self.do_forge = False
+
     # -------------------------------------------------------------------------
     def post_init(self):
 
@@ -118,6 +144,7 @@ class GetForgeModulesApp(BaseHookApp):
         res['max_http_timeout'] = self.max_http_timeout
         res['default_puppet_root_env_dir'] = self.default_puppet_root_env_dir
         res['open_args'] = self.open_args
+        res['do_forge'] = self.do_forge
 
         return res
 
@@ -170,7 +197,8 @@ class GetForgeModulesApp(BaseHookApp):
                 six.reraise(*sys.exc_info())
         self.init_puppet_environments()
         self.collect_local_modules()
-        self.get_forge_information()
+        if self.do_forge:
+            self.get_forge_information()
 
         if self.verbose > 2:
             LOG.debug("Found modules:\n{}".format(pp(self.modules.as_list())))