From: Frank Brehm Date: Mon, 25 Feb 2019 18:16:40 +0000 (+0100) Subject: Starting with class CurrentModuleReleaseInfo X-Git-Tag: 1.6.4^2~51 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=0632f2ad6d6d9efeb977203b75c07e3bde0d597c;p=pixelpark%2Fpuppetmaster-webhooks.git Starting with class CurrentModuleReleaseInfo --- diff --git a/lib/webhooks/forge_module_info.py b/lib/webhooks/forge_module_info.py index c8aa593..d24a45a 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.5.0' +__version__ = '0.5.1' LOG = logging.getLogger(__name__) @@ -320,28 +320,146 @@ class ModuleReleaseInfo(FbBaseObject): def get_from_forge(cls, data, appname=None, verbose=0, base_dir=None): release = cls(appname=appname, verbose=verbose, base_dir=base_dir) + release.apply_forge_data(data) + + if verbose > 2: + LOG.debug(_("Got {}:").format(cls.__name__) + '\n' + pp(release.as_dict())) + + return release + + # ------------------------------------------------------------------------- + def apply_forge_data(self, data): if 'created_at' in data and data['created_at']: - release.created_at = data['created_at'] + self.created_at = data['created_at'] if 'deleted_at' in data and data['deleted_at']: - release.deleted_at = data['deleted_at'] + self.deleted_at = data['deleted_at'] if 'file_size' in data and data['file_size']: - release.file_size = data['file_size'] + self.file_size = data['file_size'] if 'file_uri' in data and data['file_uri']: - release.file_uri = data['file_uri'] + self.file_uri = data['file_uri'] if 'slug' in data and data['slug']: - release.slug = data['slug'] + self.slug = data['slug'] if 'supported' in data and data['supported']: - release.supported = data['supported'] + self.supported = data['supported'] if 'uri' in data and data['uri']: - release.uri = data['uri'] + self.uri = data['uri'] if 'version' in data and data['version']: - release.release_version = data['version'] + self.release_version = data['version'] - if verbose > 2: - LOG.debug(_("Got {}:").format(cls.__name__) + '\n' + pp(release.as_dict())) - return release +# ============================================================================= +class CurrentModuleReleaseInfo(ModuleReleaseInfo): + """Class for encapsulating information about the current release of a Puppet module + from Puppet Forge.""" + + # ------------------------------------------------------------------------- + def __init__( + self, appname=None, verbose=0, version=__version__, base_dir=None, + initialized=None): + + self._changelog = None + self._deleted_for = None + self._downloads = None + self._file_md5 = None + self._license = None + self.metadata = None + self._pdk = False + self._readme = None + self._reference = None + self.tags = [] + self.tasks = [] + self._updated_at = None + self._validation_score = None + + super(CurrentModuleReleaseInfo, self).__init__( + appname=appname, verbose=verbose, version=version, base_dir=base_dir, initialized=False) + + if initialized is not None: + self.initialized = initialized + + # ------------------------------------------------------------------------- + @property + def changelog(self): + """The change log of this module release.""" + return self._changelog + + @changelog.setter + def changelog(self, value): + if value is None: + self._changelog = None + return + v = str(value).strip() + if v == '': + self._changelog = None + return + self._changelog = v + + # ------------------------------------------------------------------------- + @property + def deleted_for(self): + """The reason, why this module release was deleted..""" + return self._deleted_for + + @deleted_for.setter + def deleted_for(self, value): + if value is None: + self._deleted_for = None + return + v = str(value).strip() + if v == '': + self._deleted_for = None + return + self._deleted_for = v + + # ------------------------------------------------------------------------- + @property + def downloads(self): + "The number of downloads of this module release.""" + return self._downloads + + @downloads.setter + def downloads(self, value): + if value is None: + self._downloads = None + return + try: + v = int(value) + self._downloads = v + return + except Exception as e: + LOG.error(_("Got a {c} setting {w}: {e}").format( + c=e.__class__.__name__, w='downloads', e=e)) + + + # ------------------------------------------------------------------------- + def as_dict(self, short=True): + """ + Transforms the elements of the object into a dict + + @return: structure as dict + @rtype: dict + """ + + res = super(CurrentModuleReleaseInfo, self).as_dict(short=short) + + res['changelog'] = self.changelog + res['deleted_for'] = self.deleted_for + res['downloads'] = self.downloads + + return res + + # ------------------------------------------------------------------------- + def apply_forge_data(self, data): + + super(CurrentModuleReleaseInfo, self).apply_forge_data(data) + + if 'changelog' in data and data['changelog']: + self.changelog = data['changelog'] + if 'deleted_for' in data and data['deleted_for']: + self.deleted_for = data['deleted_for'] + if 'downloads' in data and data['downloads']: + self.downloads = data['downloads'] # ============================================================================= @@ -533,6 +651,8 @@ class ForgeModuleInfo(BaseModuleInfo): self._downloads = None self._endorsement = None + self.current_release = None + super(ForgeModuleInfo, self).__init__( appname=appname, verbose=verbose, version=version, base_dir=base_dir, initialized=False, name=name, vendor=vendor, full_name=full_name @@ -735,6 +855,10 @@ class ForgeModuleInfo(BaseModuleInfo): # if 'deprecated_at' in js_info and js_info['deprecated_at']: # module_info.deprecated_at = js_info['deprecated_at'] + if 'current_release' in js_info and js_info['current_release']: + module_info.current_release = CurrentModuleReleaseInfo.get_from_forge( + js_info['current_release'], appname=appname, verbose=verbose, base_dir=base_dir) + if 'releases' in js_info: for rel in js_info['releases']: release = ModuleReleaseInfo.get_from_forge(