From 94b204aa5396b138e7f17b342ffe83dda04a49b0 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 13 Feb 2019 18:13:58 +0100 Subject: [PATCH] Adding more properties to class ForgeModuleInfo --- lib/webhooks/forge_module_info.py | 133 ++++++++++++++++++++++++++++-- 1 file changed, 128 insertions(+), 5 deletions(-) diff --git a/lib/webhooks/forge_module_info.py b/lib/webhooks/forge_module_info.py index f606024..c8aa593 100644 --- a/lib/webhooks/forge_module_info.py +++ b/lib/webhooks/forge_module_info.py @@ -29,7 +29,7 @@ from .xlate import XLATOR from .base_module_info import BaseModuleInfoError, BaseModuleInfo -__version__ = '0.4.0' +__version__ = '0.5.0' LOG = logging.getLogger(__name__) @@ -527,6 +527,11 @@ class ForgeModuleInfo(BaseModuleInfo): initialized=None, name=None, vendor=None, full_name=None): self.releases = None + self._created_at = None + self._deprecated_at = None + self._deprecated_for = None + self._downloads = None + self._endorsement = None super(ForgeModuleInfo, self).__init__( appname=appname, verbose=verbose, version=version, base_dir=base_dir, @@ -536,14 +541,109 @@ class ForgeModuleInfo(BaseModuleInfo): if initialized is not None: self.initialized = initialized + # ------------------------------------------------------------------------- + @property + def created_at(self): + """Creation date of this forge module.""" + return self._created_at + + @created_at.setter + def created_at(self, value): + if value is None: + self._created_at = None + return + if isinstance(value, datetime.datetime): + self._created_at = value + return + v = str(value).strip() + if value == '': + self._created_at = None + return + self._created_at = parse_forge_date(v) + + # ------------------------------------------------------------------------- + @property + def deprecated_at(self): + """Date of deprecation of this forge module.""" + return self._deprecated_at + + @deprecated_at.setter + def deprecated_at(self, value): + if value is None: + self._deprecated_at = None + return + if isinstance(value, datetime.datetime): + self._deprecated_at = value + return + v = str(value).strip() + if value == '': + self._deprecated_at = None + return + self._deprecated_at = parse_forge_date(v) + + # ------------------------------------------------------------------------- + @property + def deprecated_for(self): + """The reason of deprecation of this forge module..""" + return self._deprecated_for + + @deprecated_for.setter + def deprecated_for(self, value): + if value is None: + self._deprecated_for = None + return + v = str(value).strip() + if value == '': + self._deprecated_for = None + return + self._deprecated_for = v + + # ------------------------------------------------------------------------- + @property + def endorsement(self): + """The endorsement of this forge module..""" + return self._endorsement + + @endorsement.setter + def endorsement(self, value): + if value is None: + self._endorsement = None + return + v = str(value).strip() + if value == '': + self._endorsement = None + return + self._endorsement = v + + # ------------------------------------------------------------------------- + @property + def downloads(self): + """The number of downloads of this module.""" + return self._downloads + + @downloads.setter + def downloads(self, value): + if value is None: + self._downloads = None + return + v = int(value) + if v < 0: + msg = _( + "The number of doenloads must be greater or equal to zero " + "(Given: {}).").format(value) + raise ValueError(msg) + self._downloads = v + # ------------------------------------------------------------------------- def as_dict(self, short=True): res = super(ForgeModuleInfo, self).as_dict(short=short) -# res['releases'] = [] -# for release in self.releases: -# res['releases'].append(release.as_dict(short=short)) + res['created_at'] = self.created_at + res['deprecated_at'] = self.deprecated_at + res['deprecated_for'] = self.deprecated_for + res['downloads'] = self.downloads + res['endorsement'] = self.endorsement return res @@ -553,6 +653,18 @@ class ForgeModuleInfo(BaseModuleInfo): res = {} + res['created_at'] = None + if self.created_at: + res['created_at'] = self.created_at.strftime('%Y-%m-%d %H:%M:%S %z') + + res['deprecated_at'] = None + if self.deprecated_at: + res['deprecated_at'] = self.deprecated_at.strftime('%Y-%m-%d %H:%M:%S %z') + + res['deprecated_for'] = self.deprecated_for + res['downloads'] = self.downloads + res['endorsement'] = self.endorsement + res['releases'] = [] for release in self.releases: res['releases'].append(release.to_data()) @@ -612,6 +724,17 @@ class ForgeModuleInfo(BaseModuleInfo): module_info.releases = ModuleReleaseList( appname=appname, verbose=verbose, base_dir=base_dir) + for prop_name in ( + 'created_at', 'deprecated_at', 'deprecated_for', 'downloads', 'endorsement',): + if prop_name in js_info and js_info[prop_name]: + setattr(module_info, prop_name, js_info[prop_name]) + +# if 'created_at' in js_info and js_info['created_at']: +# module_info.created_at = js_info['created_at'] + +# if 'deprecated_at' in js_info and js_info['deprecated_at']: +# module_info.deprecated_at = js_info['deprecated_at'] + if 'releases' in js_info: for rel in js_info['releases']: release = ModuleReleaseInfo.get_from_forge( @@ -619,7 +742,7 @@ class ForgeModuleInfo(BaseModuleInfo): if release: module_info.releases.append(release) - module_info.releases.imnitialized = True + module_info.releases.initialized = True # if 'current_release' in js_info and js_info['current_release']: # if 'version' in js_info['current_release']: -- 2.39.5