From a4e9115feb774f3f346a2a9d1c630df9c00b8bb3 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Fri, 7 Sep 2018 13:11:05 +0200 Subject: [PATCH] Adding property environment to class GetModuleChangesApp --- lib/webhooks/get_module_changes.py | 49 ++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/lib/webhooks/get_module_changes.py b/lib/webhooks/get_module_changes.py index 3863b48..57d972c 100644 --- a/lib/webhooks/get_module_changes.py +++ b/lib/webhooks/get_module_changes.py @@ -20,6 +20,7 @@ import pwd import grp import errno import sys +import re from operator import itemgetter @@ -59,6 +60,8 @@ class GetModuleChangesApp(BaseHookApp): default_env = 'development' + re_env_name = re.compile(r'^[a-z0-9][a-z0-9_-]*[a-z0-9]$', re.IGNORECASE) + # ------------------------------------------------------------------------- def __init__(self, appname=None, verbose=0, version=__version__): """Constructor.""" @@ -68,9 +71,30 @@ class GetModuleChangesApp(BaseHookApp): in Puppet forge than in a defined environment ''').strip() + self._environment = self.default_env + super(GetModuleChangesApp, self).__init__( appname=appname, verbose=verbose, version=version) + # ----------------------------------------------------------- + @property + def environment(self): + """The environment, which should be compared with Puppet forge.""" + return self._environment + + @environment.setter + def environment(self, value): + if value is None: + raise TypeError("An environment may not be None.") + val = str(value).strip() + if val == '': + raise ValueError("Invalid environment name: {!r}.".format(value)) + + if not self.re_env_name.match(val): + raise ValueError("Invalid environment name: {!r}.".format(value)) + + self._environment = val + # ------------------------------------------------------------------------- def as_dict(self, short=True): """ @@ -83,9 +107,26 @@ class GetModuleChangesApp(BaseHookApp): res = super(GetModuleChangesApp, self).as_dict(short=short) res['default_env'] = self.default_env + res['environment'] = self.environment return res + # ------------------------------------------------------------------------- + def init_arg_parser(self, arg_parser): + + arg_parser.add_argument( + '-E', '--env', '--environment', metavar='ENVIRONMENT', dest='env', + help=( + "The Puppet environmment, which to compare with Puppet forge, " + "default: {!r}.").format(self.default_env), + ) + + # ------------------------------------------------------------------------- + def perform_args(self, arg_parser): + + if self.cmdline_args.env: + self.environment = self.cmdline_args.env + # ------------------------------------------------------------------------- def evaluate_config(self, config, yaml_file): @@ -111,6 +152,14 @@ class GetModuleChangesApp(BaseHookApp): LOG.error(str(e)) self.exit(7) + mod_list = self.get_newer_modules(module_infos) + + # ------------------------------------------------------------------------- + def get_newer_modules(self, module_infos): + + env_found = False + + # ============================================================================= -- 2.39.5