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
from .owner_info import ForgeOwnerInfo
-__version__ = '0.2.1'
+__version__ = '0.3.1'
LOG = logging.getLogger(__name__)
self._slug = None
self._superseded_by = None
self._supported = None
+ self._ts_checked = None
self._updated_at = None
self._uri = None
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
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
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)
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)
self._deprecated_for = None
return
v = str(value).strip()
- if value == '':
+ if v == '':
self._deprecated_for = None
return
self._deprecated_for = v
self._endorsement = None
return
v = str(value).strip()
- if value == '':
+ if v == '':
self._endorsement = None
return
self._endorsement = v
self._homepage_url = None
return
v = str(value).strip()
- if value == '':
+ if v == '':
self._homepage_url = None
return
self._homepage_url = v
self._issues_url = None
return
v = str(value).strip()
- if value == '':
+ if v == '':
self._issues_url = None
return
self._issues_url = v
self._module_group = None
return
v = str(value).strip()
- if value == '':
+ if v == '':
self._module_group = None
return
self._module_group = v
self._slug = None
return
v = str(value).strip()
- if value == '':
+ if v == '':
self._slug = None
return
self._slug = v
return
v = str(value).strip()
- if value == '':
+ if v == '':
self._superseded_by = None
return
self._superseded_by = v
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)
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."""
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
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:
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))