From: Frank Brehm Date: Fri, 20 Oct 2017 13:15:08 +0000 (+0200) Subject: Moving option 'simulate' to lib/webhooks/base_app.py X-Git-Tag: 0.8.4~12 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=68ce92c96b992a814a0355de98390b14b10a126b;p=pixelpark%2Fpuppetmaster-webhooks.git Moving option 'simulate' to lib/webhooks/base_app.py --- diff --git a/lib/webhooks/__init__.py b/lib/webhooks/__init__.py index 77c24cf..dbc1d16 100644 --- a/lib/webhooks/__init__.py +++ b/lib/webhooks/__init__.py @@ -1,6 +1,6 @@ #!/bin/env python3 # -*- coding: utf-8 -*- -__version__ = '0.5.5' +__version__ = '0.6.0' # vim: ts=4 et list diff --git a/lib/webhooks/base_app.py b/lib/webhooks/base_app.py index f19e087..b796e27 100644 --- a/lib/webhooks/base_app.py +++ b/lib/webhooks/base_app.py @@ -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']) diff --git a/lib/webhooks/r10k.py b/lib/webhooks/r10k.py index d40b6f9..eec299a 100644 --- a/lib/webhooks/r10k.py +++ b/lib/webhooks/r10k.py @@ -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']