]> Frank Brehm's Git Trees - pixelpark/puppetmaster-webhooks.git/commitdiff
Finishing class ForgeModuleInfo
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 26 Feb 2019 16:24:05 +0000 (17:24 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 26 Feb 2019 16:24:05 +0000 (17:24 +0100)
lib/webhooks/forge_module_info.py

index 82e5b601a10215b33a74e2f9a75d363bfcd4cb17..f3c9e6facb316a14e266272208b3514d635eadbd 100644 (file)
@@ -31,7 +31,7 @@ from .base_module_info import BaseModuleInfoError, BaseModuleInfo
 
 from .module_meta_info import ModuleMetadata
 
-__version__ = '0.6.2'
+__version__ = '0.6.3'
 
 LOG = logging.getLogger(__name__)
 
@@ -1466,6 +1466,73 @@ class ForgeModuleInfo(BaseModuleInfo):
             return
         self._slug = v
 
+    # -------------------------------------------------------------------------
+    @property
+    def superseded_by(self):
+        """The name of the superseding module this forge module."""
+        return self._superseded_by
+
+    @superseded_by.setter
+    def superseded_by(self, value):
+        if value is None:
+            self._superseded_by = None
+            return
+        v = str(value).strip()
+        if value == '':
+            self._superseded_by = None
+            return
+        self._superseded_by = v
+
+    # -------------------------------------------------------------------------
+    @property
+    def supported(self):
+        """Is this forge module supported by Puppetlabs?."""
+        return self._supported
+
+    @supported.setter
+    def supported(self, value):
+        if value is None:
+            self._supported = None
+            return
+        self._supported = to_bool(value)
+
+    # -------------------------------------------------------------------------
+    @property
+    def updated_at(self):
+        """Last update date of this forge module."""
+        return self._updated_at
+
+    @updated_at.setter
+    def updated_at(self, value):
+        if value is None:
+            self._updated_at = None
+            return
+        if isinstance(value, datetime.datetime):
+            self._updated_at = value
+            return
+        v = str(value).strip()
+        if value == '':
+            self._updated_at = None
+            return
+        self._updated_at = parse_forge_date(v)
+
+    # -------------------------------------------------------------------------
+    @property
+    def uri(self):
+        """The URI of this forge module."""
+        return self._uri
+
+    @uri.setter
+    def uri(self, value):
+        if value is None:
+            self._uri = None
+            return
+        v = str(value).strip()
+        if value == '':
+            self._uri = None
+            return
+        self._uri = v
+
     # -------------------------------------------------------------------------
     def as_dict(self, short=True):
 
@@ -1481,6 +1548,10 @@ class ForgeModuleInfo(BaseModuleInfo):
         res['issues_url'] = self.issues_url
         res['module_group'] = self.module_group
         res['slug'] = self.slug
+        res['superseded_by'] = self.superseded_by
+        res['supported'] = self.supported
+        res['updated_at'] = self.updated_at
+        res['uri'] = self.uri
 
         return res
 
@@ -1490,14 +1561,6 @@ 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
@@ -1507,6 +1570,21 @@ class ForgeModuleInfo(BaseModuleInfo):
         res['module_group'] = self.module_group
         res['name'] = self.name
         res['slug'] = self.slug
+        res['superseded_by'] = self.superseded_by
+        res['supported'] = self.supported
+        res['uri'] = self.uri
+
+        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['updated_at'] = None
+        if self.updated_at:
+            res['updated_at'] = self.updated_at.strftime('%Y-%m-%d %H:%M:%S %z')
 
         res['releases'] = []
         for release in self.releases:
@@ -1577,7 +1655,8 @@ class ForgeModuleInfo(BaseModuleInfo):
 
         for prop_name in (
                 'created_at', 'deprecated_at', 'deprecated_for', 'downloads', 'endorsement',
-                'feedback_score', 'homepage_url', 'issues_url', 'module_group', 'slug'):
+                'feedback_score', 'homepage_url', 'issues_url', 'module_group', 'slug',
+                'superseded_by', 'supported', 'updated_at', 'uri'):
             if prop_name in js_info and js_info[prop_name]:
                 setattr(module_info, prop_name, js_info[prop_name])
 
@@ -1598,24 +1677,63 @@ class ForgeModuleInfo(BaseModuleInfo):
             module_info.owner = ForgeOwnerInfo.from_data(
                 js_info['owner'], appname=appname, verbose=verbose, base_dir=base_dir)
 
-#        LOG.debug("Current version of module {name} is {version}.".format(
-#            name=full_name, version=version))
+        if module_info.superseded_by:
+            LOG.warning(_(
+                "Module {c!r} is deprecated at Puppet forge and should be substituted "
+                "by module {n!r}.").format(c=module_info.slug, n=module_info.superseded_by))
 
-#        if version:
-#            module_info.forge_version = version
-#        if source:
-#            module_info.forge_source = source
+        return module_info
+
+    # -------------------------------------------------------------------------
+    @classmethod
+    def from_data(cls, data, appname=None, verbose=0, base_dir=None):
+
+        if verbose > 3:
+            LOG.debug(_(
+                "Trying to instantiate a {}-object from:").format(
+                cls.__name__) + '\n' + pp(data))
+
+        if 'slug' not in data:
+            msg = _("Did not found {!r}-definition in data for forge module:").format(
+                'slug') + '\n' + pp(data))
+            LOG.error(msg)
+            return None
 
-#        if 'homepage_url' in js_info and js_info['homepage_url']:
-#            module_info.forge_homepage_url = js_info['homepage_url']
+        full_name = data['slug'].strip()
+        if full_name == '':
+            msg = _("Found empty {!r}-definition in data for forge module:").format(
+                'slug') + '\n' + pp(data))
+            LOG.error(msg)
+            return None
 
-#        module_info.forge_releases = []
-#        if 'releases' in js_info and is_sequence(js_info['releases']):
-#            for release in js_info['releases']:
-#                if 'version' in release and release['version']:
-#                    module_info.forge_releases.append(release['version'].strip())
+        module_info = cls(appname=appname, verbose=verbose, base_dir=base_dir, full_name=full_name)
 
-#        module_info.set_ts_checked()
+        module_info.releases = ModuleReleaseList(
+            appname=appname, verbose=verbose, base_dir=base_dir)
+
+        for prop_name in (
+                'created_at', 'deprecated_at', 'deprecated_for', 'downloads', 'endorsement',
+                'feedback_score', 'homepage_url', 'issues_url', 'module_group', 'slug',
+                'superseded_by', 'supported', 'updated_at', 'uri'):
+            if prop_name in data and data[prop_name]:
+                setattr(module_info, prop_name, data[prop_name])
+
+        if 'current_release' in data and data['current_release']:
+            module_info.current_release = CurrentModuleReleaseInfo.get_from_forge(
+                data['current_release'], appname=appname, verbose=verbose, base_dir=base_dir)
+
+        if 'releases' in data:
+            for rel in data['releases']:
+                release = ModuleReleaseInfo.get_from_forge(
+                    rel, appname=appname, verbose=verbose, base_dir=base_dir)
+                if release:
+                    module_info.releases.append(release)
+
+        module_info.releases.initialized = True
+
+        if 'owner' in data and data['owner']:
+            module_info.owner = ForgeOwnerInfo.from_data(
+                data['owner'], appname=appname, verbose=verbose, base_dir=base_dir)
 
         return module_info