]> Frank Brehm's Git Trees - pixelpark/puppet-tools.git/commitdiff
Evaluating existing Puppet environments.
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 15 Feb 2023 10:19:45 +0000 (11:19 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 15 Feb 2023 10:19:45 +0000 (11:19 +0100)
lib/dpx_puppettools/app/__init__.py
lib/dpx_puppettools/app/get_forge_module.py

index ecc413f129a3e853a676c2fa01b787ce4fd76622..91d633b07a9829dc9347005e1ab1cfa030a53e6d 100644 (file)
@@ -48,7 +48,7 @@ LOG = logging.getLogger(__name__)
 _ = XLATOR.gettext
 ngettext = XLATOR.ngettext
 
-__version__ = '0.4.1'
+__version__ = '0.4.2'
 
 
 # =============================================================================
@@ -86,7 +86,7 @@ class BaseDPXPuppetApplication(FbConfigApplication):
 
         self._env_root_dir = DpxPuppetConfig.default_env_root_dir
         self._var_dir = DpxPuppetConfig.default_var_dir
-        self.environments = []
+        self.environments = None
 
         super(BaseDPXPuppetApplication, self).__init__(
             appname=appname, verbose=verbose, version=version, base_dir=base_dir,
@@ -152,7 +152,6 @@ class BaseDPXPuppetApplication(FbConfigApplication):
 
         res = super(BaseDPXPuppetApplication, self).as_dict(short=short)
 
-        res['default_env_root_dir'] = self.default_env_root_dir
         res['env_root_dir'] = self.env_root_dir
         res['var_dir'] = self.env_root_dir
 
@@ -454,6 +453,54 @@ class BaseDPXPuppetApplication(FbConfigApplication):
         p = Popen(cmd, stdin=PIPE, universal_newlines=True)
         p.communicate(mail.as_string())
 
+    # -------------------------------------------------------------------------
+    def eval_puppet_envs(self):
+        """Evaluate all existing checked out puppet environments."""
+
+        LOG.debug(_(
+            "Evaluate all existing checked out puppet environments below {!r} ...").format(
+            str(self.env_root_dir)))
+
+        envs_dir_ok = True
+        if not self.env_root_dir.exists():
+            envs_dir_ok = False
+        if not self.env_root_dir.is_dir():
+            envs_dir_ok = False
+
+        if not envs_dir_ok:
+            LOG.warn(_("Dit not found environments root directory {!r}.").format(
+                str(self.env_root_dir)))
+            self.environments = []
+            return
+
+        for path in self.env_root_dir.glob('*'):
+            if self.verbose > 2:
+                LOG.debug("Checking possible env dir {!r} ...".format(str(path)))
+
+            if not path.is_dir():
+                continue
+
+            pfile = path / 'Puppetfile'
+            if not pfile.is_file():
+                continue
+
+            mdir = path / 'modules'
+            if not mdir.is_dir():
+                continue
+
+            env = path.name
+            if self.environments is None:
+                self.environments = []
+            if env not in self.environments:
+                self.environments.append(env)
+
+        if self.environments:
+            env_list = format_list(self.environments, do_repr=True)
+            msg = _("Found environments:") + ' ' + env_list
+        else:
+            msg = _("Did not found checked out Puppet environments.")
+        LOG.debug(msg)
+
     # -------------------------------------------------------------------------
     def print(self, msg, color=None, end='\n', file=None, flush=False):
 
index 3f776d4e3563fe88b8ecbf8dcdc4d583bdcf7a09..5a7bb573cdd922c4cac632fff4032d64e634590a 100644 (file)
@@ -31,7 +31,7 @@ LOG = logging.getLogger(__name__)
 _ = XLATOR.gettext
 ngettext = XLATOR.ngettext
 
-__version__ = '0.6.4'
+__version__ = '0.6.5'
 
 
 # =============================================================================
@@ -160,6 +160,8 @@ class GetForgeModuleApplication(BaseDPXPuppetApplication):
 
         LOG.debug(_("Finished creating a {} object.").format('ForgeModuleInfo'))
 
+        self.eval_puppet_envs()
+
         self.initialized = True
 
     # -------------------------------------------------------------------------