]> Frank Brehm's Git Trees - pixelpark/puppetmaster-webhooks.git/commitdiff
Moving option 'simulate' to lib/webhooks/base_app.py
authorFrank Brehm <frank.brehm@pixelpark.com>
Fri, 20 Oct 2017 13:15:08 +0000 (15:15 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Fri, 20 Oct 2017 13:15:08 +0000 (15:15 +0200)
lib/webhooks/__init__.py
lib/webhooks/base_app.py
lib/webhooks/r10k.py

index 77c24cfb6902f11696a61f8bfc6ef7739a4b8e2e..dbc1d16874a038aba99f2b4c79ce7abde4e47af2 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/env python3
 # -*- coding: utf-8 -*-
 
-__version__ = '0.5.5'
+__version__ = '0.6.0'
 
 # vim: ts=4 et list
index f19e08745c033036fb674f99f6b766f0435bef66..b796e271a41f6e0433c4a5353ca1d2b6d6980b21 100644 (file)
@@ -79,6 +79,8 @@ class BaseHookApp(object):
         """
         self._start_verbose = verbose
 
+        self._simulate = False
+
         self.data = None
         self.json_data = None
         self.ref = None
@@ -147,6 +149,16 @@ class BaseHookApp(object):
         else:
             LOG.warn("Wrong verbose level %r, must be >= 0", value)
 
+    # -----------------------------------------------------------
+    @property
+    def simulate(self):
+        """Flag for simulation mode."""
+        return getattr(self, '_simulate', False)
+
+    @simulate.setter
+    def simulate(self, value):
+        self._simulate = to_bool(value)
+
     # -----------------------------------------------------------
     @property
     def log_directory(self):
@@ -194,6 +206,7 @@ class BaseHookApp(object):
         res['__class_name__'] = self.__class__.__name__
         res['appname'] = self.appname
         res['verbose'] = self.verbose
+        res['simulate'] = self.simulate
         res['base_dir'] = self.base_dir
         res['cgi_bin_dir'] = self.cgi_bin_dir
         res['log_directory'] = self.log_directory
@@ -211,36 +224,32 @@ class BaseHookApp(object):
         )
 
         arg_parser.add_argument(
-            "-v", "--verbose",
-            action="count",
-            dest='verbose',
+            "-v", "--verbose", action="count", dest='verbose',
             help='Increase the verbosity level',
         )
 
         arg_parser.add_argument(
-            "-C", '--cgi',
-            action='store_true',
-            dest='cgi',
+            '-s', '--simulate', '--test', action='store_true', dest='simulate',
+            help="Simulation mode, nothing is really done.",
+        )
+
+        arg_parser.add_argument(
+            "-C", '--cgi', action='store_true', dest='cgi',
             help='Enforces behaviour as called as a CGI script.',
         )
 
         arg_parser.add_argument(
-            "-h", "--help",
-            action='help',
-            dest='help',
+            "-h", "--help", action='help', dest='help',
             help='Show this help message and exit'
         )
 
         arg_parser.add_argument(
-            "--usage",
-            action='store_true',
-            dest='usage',
+            "--usage", action='store_true', dest='usage',
             help="Display brief usage message and exit"
         )
 
         arg_parser.add_argument(
-            "-V", '--version',
-            action='version',
+            "-V", '--version', action='version',
             version='Version of %(prog)s: {}'.format(self.version),
             help="Show program's version number and exit"
         )
@@ -261,6 +270,9 @@ class BaseHookApp(object):
             if not os.environ.get('REQUEST_METHOD', None):
                 os.environ['REQUEST_METHOD'] = 'GET'
 
+        if self.cmdline_args.simulate:
+            self.simulate = True
+
     # -------------------------------------------------------------------------
     def get_cmd(self, cmd):
 
@@ -388,6 +400,9 @@ class BaseHookApp(object):
                     v=config['verbose'], f=yaml_file, e=e)
                 LOG.warn(msg)
 
+        if 'simulate' in config:
+            self.simulate = config['simulate']
+
         if 'do_sudo' in config:
             self.do_sudo = to_bool(config['do_sudo'])
 
index d40b6f9238b3f910babde3a9a559515b071c717f..eec299a08e1e67a98a7eee5bc4df060d96183f78 100644 (file)
@@ -46,7 +46,6 @@ class R10kHookApp(BaseHookApp):
             ''').strip()
 
         self.locale = 'de_DE.utf8'
-        self.simulate = False
         self.http_timeout = 30
 
         self.puppetmaster_host = 'puppetmaster01.pixelpark.com'
@@ -126,9 +125,6 @@ class R10kHookApp(BaseHookApp):
 
         super(R10kHookApp, self).evaluate_config(config, yaml_file)
 
-        if 'simulate' in config:
-            self.simulate = to_bool(config['simulate'])
-
         if 'locale' in config and config['locale']:
             self.locale = config['locale']