version_infos = self.get_newer_modules(module_infos)
self.generate_version_msgs(version_infos)
+ depr_infos = self.check_deprecations(module_infos)
+ self.generate_deprecation_msgs(depr_infos)
+
self.error_data.append("\n" + _("Checked at: {}").format(self.check_date_str))
# -------------------------------------------------------------------------
env_found = False
- LOG.info(_("Checking verions of modules ..."))
+ LOG.info(_("Checking versions of modules ..."))
version_infos = []
"Didn't found any modules in environment {!r} with a\n"
"newer version on Puppet Forge.").format(self.environment) + "\n\n:-D"
self.error_data.append(msg)
- self.error_data.append("\n" + _("Checked at: {}").format(self.check_date_str))
return
msg = ngettext(
forge_version=str(version_info['forge_version'])
))
+ # -------------------------------------------------------------------------
+ def check_deprecations(self, module_infos):
+
+ env_found = False
+
+ LOG.info(_("Checking for deprecate modules ..."))
+
+ infos = []
+
+ for module_info in module_infos.values():
+
+ if self.verbose > 1:
+ LOG.debug("Checking module {!r} ...".format(module_info.full_name))
+
+ if self.environment not in module_info.local_versions:
+ LOG.debug("Module {m!r} not used in environment {e!r}.".format(
+ m=module_info.full_name, e=self.environment))
+ continue
+ env_found = True
+
+ if not module_info.forge_avail or not module_info.forge_version:
+ LOG.debug("Module {m!r} not available on Puppet forge.".format(
+ m=module_info.full_name))
+ continue
+
+ if not module_info.forge_deprecated_at:
+ continue
+ if self.verbose > 2:
+ LOG.debug("Current module:" + '\n' + pp(module_info.as_dict()))
+ reason = _('unknown')
+ substitute = _('unknown')
+ if module_info.forge_deprecated_for:
+ reason = module_info.forge_deprecated_for
+ if module_info.forge_superseded_by:
+ substitute = module_info.forge_superseded_by
+ local_dt = module_info.forge_deprecated_at.replace(tzinfo=LOCALTZ)
+ local_dt_str = format_datetime(local_dt, 'yyyy-MM-dd HH:mm:ss z', tzinfo=LOCALTZ)
+ LOG.info(_(
+ "Module {m!r} is deprecated since {at} and should be substituted by {s!r}, "
+ "reason: {r}.").format(
+ m=module_info.full_name, at=local_dt_str, s=substitute, r=reason))
+
+ info = {
+ 'module': module_info.full_name,
+ 'since': local_dt_str,
+ 'substitute': substitute,
+ 'reason': reason,
+ }
+ infos.append(info)
+
+ return infos
+
+ # -------------------------------------------------------------------------
+ def generate_deprecation_msgs(self, module_infos):
+
+ msg = _("Results of checking for deprecated modules in environment {!r}:").format(
+ self.environment)
+ self.error_data.append('\n' + msg)
+ if not module_infos:
+ msg = _("Didn't found any deprecated modules in environment {!r}.").format(
+ self.environment) + "\n\n:-D"
+ self.error_data.append(msg)
+ return
+
+ if self.verbose > 2:
+ LOG.debug("Deprecated modules:\n" + pp(module_infos))
+
+ msg = ngettext(
+ "Found one deprecated module in environment {e!r}.",
+ "Found {n} deprecated modules in environment {e!r}.",
+ len(module_infos)).format(n=len(module_infos), e=self.environment) + "\n\n:-(\n"
+ self.error_data.append(msg)
+
+ label = {
+ 'module': _('Module'),
+ 'since': _('Since'),
+ 'substitute': _('Substituted by'),
+ 'reason': _("Reason"),
+ }
+ width = {}
+ for key in label.keys():
+ width[key] = len(label[key])
+
+ for info in module_infos:
+ for key in label.keys():
+ if len(str(info[key])) > width[key]:
+ width[key] = len(str(info[key]))
+
+ len_total = 0
+ first = True
+ for key in width.keys():
+ len_total += width[key]
+ if not first:
+ len_total += 3
+ first = False
+
+ template = "{{module:<{module}}} | "
+ template += "{{since:<{since}}} | "
+ template += "{{substitute:<{substitute}}} | "
+ template += "{{reason:<{reason}}}"
+
+ template = template.format(**width)
+
+ if self.verbose > 2:
+ LOG.debug("Zeilen-Template:\n{}".format(template))
+ LOG.debug("Zeilen-Länge: {}".format(len_total))
+
+ title = template.format(**label)
+ self.error_data.append(title)
+ self.error_data.append('=' * len_total)
+
+ for info in module_infos:
+ self.error_data.append(template.format(**info))
+
# =============================================================================
if __name__ == "__main__":