From: Frank Brehm Date: Tue, 19 Mar 2019 14:30:52 +0000 (+0100) Subject: New properties ts_checked and date_checked, new method set_ts_checked for class Forge... X-Git-Tag: 1.6.4^2~14 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=d8ef1d3c7caafbc8b8a8c6f7c686edcfdf4cb655;p=pixelpark%2Fpuppetmaster-webhooks.git New properties ts_checked and date_checked, new method set_ts_checked for class ForgeModuleInfo --- diff --git a/lib/webhooks/forge/mod_info.py b/lib/webhooks/forge/mod_info.py index c64bcea..ef612e9 100644 --- a/lib/webhooks/forge/mod_info.py +++ b/lib/webhooks/forge/mod_info.py @@ -14,9 +14,11 @@ import copy import warnings import datetime import collections +import time # Third party modules import requests +import pytz # Own modules from fb_tools.common import pp, to_bool @@ -33,7 +35,7 @@ from .cur_mod_release_info import CurrentModuleReleaseInfo from .owner_info import ForgeOwnerInfo -__version__ = '0.2.1' +__version__ = '0.3.1' LOG = logging.getLogger(__name__) @@ -66,6 +68,7 @@ class ForgeModuleInfo(BaseModuleInfo): self._slug = None self._superseded_by = None self._supported = None + self._ts_checked = None self._updated_at = None self._uri = None @@ -83,6 +86,7 @@ class ForgeModuleInfo(BaseModuleInfo): res = super(ForgeModuleInfo, self).as_dict(short=short) res['created_at'] = self.created_at + res['date_checked'] = self.date_checked res['deprecated_at'] = self.deprecated_at res['deprecated_for'] = self.deprecated_for res['downloads'] = self.downloads @@ -95,6 +99,7 @@ class ForgeModuleInfo(BaseModuleInfo): res['superseded_by'] = self.superseded_by res['supported'] = self.supported res['updated_at'] = self.updated_at + res['ts_checked'] = self.ts_checked res['uri'] = self.uri return res @@ -114,7 +119,7 @@ class ForgeModuleInfo(BaseModuleInfo): self._created_at = value return v = str(value).strip() - if value == '': + if v == '': self._created_at = None return self._created_at = parse_forge_date(v) @@ -134,7 +139,7 @@ class ForgeModuleInfo(BaseModuleInfo): self._deprecated_at = value return v = str(value).strip() - if value == '': + if v == '': self._deprecated_at = None return self._deprecated_at = parse_forge_date(v) @@ -151,7 +156,7 @@ class ForgeModuleInfo(BaseModuleInfo): self._deprecated_for = None return v = str(value).strip() - if value == '': + if v == '': self._deprecated_for = None return self._deprecated_for = v @@ -187,7 +192,7 @@ class ForgeModuleInfo(BaseModuleInfo): self._endorsement = None return v = str(value).strip() - if value == '': + if v == '': self._endorsement = None return self._endorsement = v @@ -223,7 +228,7 @@ class ForgeModuleInfo(BaseModuleInfo): self._homepage_url = None return v = str(value).strip() - if value == '': + if v == '': self._homepage_url = None return self._homepage_url = v @@ -240,7 +245,7 @@ class ForgeModuleInfo(BaseModuleInfo): self._issues_url = None return v = str(value).strip() - if value == '': + if v == '': self._issues_url = None return self._issues_url = v @@ -257,7 +262,7 @@ class ForgeModuleInfo(BaseModuleInfo): self._module_group = None return v = str(value).strip() - if value == '': + if v == '': self._module_group = None return self._module_group = v @@ -274,7 +279,7 @@ class ForgeModuleInfo(BaseModuleInfo): self._slug = None return v = str(value).strip() - if value == '': + if v == '': self._slug = None return self._slug = v @@ -295,7 +300,7 @@ class ForgeModuleInfo(BaseModuleInfo): return v = str(value).strip() - if value == '': + if v == '': self._superseded_by = None return self._superseded_by = v @@ -328,7 +333,7 @@ class ForgeModuleInfo(BaseModuleInfo): self._updated_at = value return v = str(value).strip() - if value == '': + if v == '': self._updated_at = None return self._updated_at = parse_forge_date(v) @@ -345,11 +350,37 @@ class ForgeModuleInfo(BaseModuleInfo): self._uri = None return v = str(value).strip() - if value == '': + if v == '': self._uri = None return self._uri = v + # ------------------------------------------------------------------------- + @property + def ts_checked(self): + """The timestamp, when this module was checked on Puppet forge.""" + return self._ts_checked + + @ts_checked.setter + def ts_checked(self, value): + if value is None: + self._ts_checked = None + return + self._ts_checked = float(value) + + # ------------------------------------------------------------------------- + @property + def date_checked(self): + """A string representation of the check timestamp, if such one is given.""" + if self.ts_checked is None: + return None + dt = datetime.datetime.fromtimestamp(self.ts_checked, tz=pytz.utc) + return dt.strftime('%Y-%m-%d %H:%M:%S %Z') + + # ------------------------------------------------------------------------- + def set_ts_checked(self): + self._ts_checked = time.time() + # ------------------------------------------------------------------------- def to_data(self): """Returning a dict, which can be used to re-instantiate this module info.""" @@ -367,6 +398,7 @@ class ForgeModuleInfo(BaseModuleInfo): res['slug'] = self.slug res['superseded_by'] = self.superseded_by res['supported'] = self.supported + res['ts_checked'] = self.ts_checked res['uri'] = self.uri res['created_at'] = None @@ -404,7 +436,7 @@ class ForgeModuleInfo(BaseModuleInfo): for prop_name in ( 'created_at', 'deprecated_at', 'deprecated_for', 'downloads', 'endorsement', 'feedback_score', 'homepage_url', 'issues_url', 'module_group', 'slug', - 'superseded_by', 'updated_at', 'uri'): + 'superseded_by', 'updated_at', 'ts_checked', 'uri'): if prop_name in data and data[prop_name]: setattr(self, prop_name, data[prop_name]) if 'supported' in data: @@ -501,6 +533,7 @@ class ForgeModuleInfo(BaseModuleInfo): LOG.warn("{c}: {e}".format(c=e.__class__.__name__, e=e)) return None + module_info.set_ts_checked() data = response.json() if verbose > 3: LOG.debug("Performing forge data:\n" + pp(data))