_ = XLATOR.gettext
ngettext = XLATOR.ngettext
-__version__ = '0.4.1'
+__version__ = '0.4.2'
# =============================================================================
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,
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
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):