]> Frank Brehm's Git Trees - pixelpark/puppetmaster-webhooks.git/commitdiff
Adding property environment to class GetModuleChangesApp
authorFrank Brehm <frank.brehm@pixelpark.com>
Fri, 7 Sep 2018 11:11:05 +0000 (13:11 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Fri, 7 Sep 2018 11:11:05 +0000 (13:11 +0200)
lib/webhooks/get_module_changes.py

index 3863b4863c440aadeddbbfb1cedd2450870c3b0e..57d972cde0a62b507151ef8adbdce774eee5231f 100644 (file)
@@ -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
+
+
 
 # =============================================================================