from ..forge.mod_info import RetrieveForgeDataError
from ..forge.mod_info import ReadForgeModuleInfoError, WriteForgeModuleInfoError
+from ..puppetfile import Puppetfile
+
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
ngettext = XLATOR.ngettext
-__version__ = '0.6.5'
+__version__ = '0.7.0'
# =============================================================================
self.var_dir = None
self.details = False
+ self.mod_env_info = {}
+
self._force_desc_msg = _(
"Write the cache file also, if the data was successful read from chache file.")
LOG.error(str(e))
self.exit(5)
+ self.eval_all_env_infos()
+
self.show_modinfo()
do_write_cache = self.write_cache
except WriteForgeModuleInfoError as e:
LOG.warn(_("Could not write cache: {}").format(e))
+ # -------------------------------------------------------------------------
+ def eval_all_env_infos(self):
+ """Evaluating entries about this module in Puppetfiles of all environments."""
+
+ if not self.environments:
+ return
+
+ for env in self.environments:
+ self.eval_env_info(env)
+
+ # -------------------------------------------------------------------------
+ def eval_env_info(self, env):
+ """Evaluating entry bout this module in Puppetfile of the given environment."""
+
+ if self.verbose > 1:
+ msg = _(
+ "Get entry about this module in Puppetfile of environment "
+ "{!r} ...").format(env)
+ LOG.debug(msg)
+
+ pfile = Puppetfile(
+ env_root_dir=self.env_root_dir, environment=env, appname=self.appname,
+ verbose=self.verbose, base_dir=self.base_dir, initialized=True)
+
+ pfile.read()
+ if self.verbose > 3:
+ LOG.debug(_("Read Puppetfile:") + '\n' + pp(pfile.as_dict()))
+
+ if self.module_name not in pfile:
+ if self.verbose > 1:
+ msg = _("Module {m!r} not found in Puppetfile of environment {e!r}.").format(
+ m=self.module_name, e=env)
+ LOG.debug(msg)
+ return
+
+ module_entry = pfile.modules[self.module_name]
+ if self.verbose > 0:
+ msg = _(
+ "Puppetfile entry of module {m!r} not found in Puppetfile of environment "
+ "{e!r}:").format(m=self.module_name, e=env)
+ msg += '\n' + pp(module_entry.as_dict())
+ LOG.debug(msg)
+
+ self.mod_env_info[env] = module_entry.short_info()
+ if self.verbose > 2:
+ msg = "Module information: " + pp(self.mod_env_info)
+ LOG.debug(msg)
+
# -------------------------------------------------------------------------
def show_modinfo(self):
print(_('Last checked for Puppet forge:') + ' ' + self.module_info.date_checked)
self.empty_line()
+ msg = _("Usage in Puppet environments:")
+ print(msg)
+ self.line(width=len(msg), linechar='-')
+ self.empty_line()
+
+ if not self.mod_env_info.keys():
+ msg = _("This module seems not to be used in Puppet environments.")
+ print(msg)
+ else:
+ max_len_env = 1
+ for env in self.mod_env_info.keys():
+ if len(env) > max_len_env:
+ max_len_env = len(env)
+ for env in self.mod_env_info.keys():
+ msg = ' * {env:<{width}} {info}'.format(
+ width=(max_len_env + 1), env=(self.colored(env, 'CYAN') + ':'),
+ info=self.mod_env_info[env])
+ print(msg)
+ self.empty_line()
+
+
# =============================================================================
from .errors import BaseModuleInfoError
from .base_moduleinfo import BaseModuleInfo
-__version__ = '0.3.1'
+__version__ = '0.4.0'
LOG = logging.getLogger(__name__)
return module_info
+ # -------------------------------------------------------------------------
+ def short_info(self):
+ """Generates a oneliner with all information about this module entry."""
+
+ ret = '{tl}: {t}'.format(tl=_("Type"), t=self.repo_type)
+ if self.repo_type == 'forge':
+ if self.forge_version:
+ ret += ', {vl}: {vv}'.format(vl=_("version"), vv=self.forge_version)
+ return ret
+
+ if self.repo:
+ ret += ', {vl}: {vv}'.format(vl='repo', vv=self.repo)
+
+ if self.repo_type == 'git':
+ if self.ref:
+ if self.ref_type == 'ref':
+ ret += ', {vl}: {vv}'.format(vl='ref', vv=self.ref)
+ elif self.ref_type == 'tag':
+ ret += ', {vl}: {vv}'.format(vl='tag', vv=self.ref)
+ elif self.ref_type == 'branch':
+ ret += ', {vl}: {vv}'.format(vl='branch', vv=self.ref)
+ elif self.ref_type == 'commit-id':
+ ret += ', {vl}: {vv}'.format(vl='commit-id', vv=self.ref[0:8])
+ else:
+ ret += ', {}'.format(self.ref)
+ if self.default_branch:
+ ret += ', {vl}: {vv}'.format(vl='default-branch', vv=self.default_branch)
+ return ret
+
+ if self.repo_type == 'svn':
+ if self.ref:
+ ret += ', {vl}: {vv}'.format(vl='ref', vv=self.ref)
+ return ret
+
+ return ret
# =============================================================================
if __name__ == "__main__":