from distutils.version import LooseVersion
# Third party modules
-from babel.dates import format_datetime, LOCALTZ
+from babel.dates import format_datetime, format_timedelta, LOCALTZ
# Own modules
from fb_tools.common import pp, to_bool
depr_infos = self.check_deprecations(module_infos)
self.generate_deprecation_msgs(depr_infos)
+ update_infos = self.check_updates(module_infos)
+
self.error_data.append("\n" + _("Checked at: {}").format(self.check_date_str))
# -------------------------------------------------------------------------
for info in module_infos:
self.error_data.append(template.format(**info))
+ # -------------------------------------------------------------------------
+ def check_updates(self, module_infos):
+
+ env_found = False
+
+ LOG.info(_("Checking for last updets modules on Puppet forge ..."))
+
+ infos = []
+
+ warn_update_timediff = datetime.timedelta(self.warn_update_days)
+
+ 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_updated_at:
+ LOG.debug("Did not found last update_date of module {m!r}.".format(
+ m=module_info.full_name))
+ continue
+
+ mod_update_timediff = self.check_date - module_info.forge_updated_at
+ tdiff = format_timedelta(
+ mod_update_timediff * -1, granularity='day', add_direction=True,
+ format='long')
+ if self.verbose > 1:
+ LOG.debug("Last update of module {m!r} was {d} days ago ({t}).".format(
+ m=module_info.full_name, d=mod_update_timediff.days, t=tdiff))
+
+ if mod_update_timediff < warn_update_timediff:
+ continue
+
+ local_dt_str = format_datetime(
+ module_info.forge_updated_at, 'yyyy-MM-dd HH:mm:ss z', tzinfo=LOCALTZ)
+ LOG.info(_(
+ "Module {m!r} was last updated at {at}, {d} days ago ({t}).").format(
+ m=module_info.full_name, at=local_dt_str, d=mod_update_timediff.days, t=tdiff))
+
+ info = {
+ 'module': module_info.full_name,
+ 'upd_date': module_info.forge_updated_at,
+ 'upd_date_str': local_dt_str,
+ 'timediff': mod_update_timediff,
+ }
+ infos.append(info)
+
+ if self.verbose > 1:
+ LOG.debug("Modules with an update on Forge long time ago:\n" + pp(infos))
+ return infos
+
# =============================================================================
if __name__ == "__main__":