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

index 59ecc9e7463f94f48897725db5552772afc8f5f1..7b9914793da7e07bcc225006d29116f3b77ca269 100644 (file)
@@ -31,7 +31,7 @@ from .base_module_info import BaseModuleInfoError, BaseModuleInfo
 
 from .module_meta_info import ModuleMetadata
 
-__version__ = '0.5.4'
+__version__ = '0.5.5'
 
 LOG = logging.getLogger(__name__)
 
@@ -837,6 +837,92 @@ class CurrentModuleReleaseInfo(ModuleReleaseInfo):
             return
         self._license = v
 
+    # -------------------------------------------------------------------------
+    @property
+    def pdk(self):
+        """The pdk of this release."""
+        return self._pdk
+
+    @pdk.setter
+    def pdk(self, value):
+        if value is None:
+            self._pdk = None
+            return
+        self._pdk = to_bool(value)
+
+    # -------------------------------------------------------------------------
+    @property
+    def readme(self):
+        """The readme of module release."""
+        return self._readme
+
+    @readme.setter
+    def readme(self, value):
+        if value is None:
+            self._readme = None
+            return
+        v = str(value).strip()
+        if v == '':
+            self._readme = None
+            return
+        self._readme = v
+
+    # -------------------------------------------------------------------------
+    @property
+    def reference(self):
+        """The reference of module release."""
+        return self._reference
+
+    @reference.setter
+    def reference(self, value):
+        if value is None:
+            self._reference = None
+            return
+        v = str(value).strip()
+        if v == '':
+            self._reference = None
+            return
+        self._reference = v
+
+    # -------------------------------------------------------------------------
+    @property
+    def updated_at(self):
+        """Update date of this release."""
+        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 validation_score(self):
+        "The validation score of this module release."""
+        return self._validation_score
+
+    @validation_score.setter
+    def validation_score(self, value):
+        if value is None:
+            self._validation_score = None
+            return
+        try:
+            v = int(value)
+            self._validation_score = v
+            return
+        except Exception as e:
+            LOG.error(_("Got a {c} setting {w}: {e}").format(
+                c=e.__class__.__name__, w='validation_score', e=e))
+
     # -------------------------------------------------------------------------
     def as_dict(self, short=True):
         """
@@ -853,6 +939,11 @@ class CurrentModuleReleaseInfo(ModuleReleaseInfo):
         res['downloads'] = self.downloads
         res['file_md5'] = self.file_md5
         res['license'] = self.license
+        res['pdk'] = self.pdk
+        res['readme'] = self.readme
+        res['reference'] = self.reference
+        res['updated_at'] = self.updated_at
+        res['validation_score'] = self.validation_score
 
         return res
 
@@ -882,6 +973,110 @@ class CurrentModuleReleaseInfo(ModuleReleaseInfo):
                 data['module'], appname=self.appname,
                 verbose=self.verbose, base_dir=self.base_dir)
 
+        if 'pdk' in data:
+            self.pdk = data['pdk']
+        if 'readme' in data:
+            self.readme = data['readme']
+        if 'reference' in data:
+            self.reference = data['reference']
+        if 'updated_at' in data:
+            self.reference = data['updated_at']
+        if 'validation_score' in data:
+            self.validation_score = data['validation_score']
+
+        self.tags = []
+        if 'tags' in data and data['tags']:
+            if self.verbose > 2:
+                LOG.debug(
+                    "Tags in current release of {!r}:".format(self.slug) + '\n' + pp(data['tags']))
+            for tag in data['tags']:
+                self.tags.append(tag)
+
+        self.tasks = []
+        if 'tasks' in data and data['tasks']:
+            if self.verbose > 3:
+                LOG.debug(
+                    "Tasks in current release of {!r}:".format(self.slug) +
+                    '\n' + pp(data['tasks']))
+            for task in data['tasks']:
+                self.tasks.append(copy.copy(task))
+
+    # -------------------------------------------------------------------------
+    def to_data(self):
+        """Returning a dict, which can be used to re-instantiate this module info."""
+
+        res = super(CurrentModuleReleaseInfo, self).to_data()
+
+        res['changelog'] = self.changelog
+        res['deleted_for'] = self.deleted_for
+        res['downloads'] = self.downloads
+        res['file_md5'] = self.file_md5
+        res['license'] = self.license
+        res['pdk'] = self.pdk
+        res['readme'] = self.readme
+        res['reference'] = self.reference
+        res['validation_score'] = self.validation_score
+
+        res['metadata'] = None
+        if self.metadata:
+            res['metadata'] = self.metadata.to_data()
+
+        res['module'] = None
+        if self.module:
+            res['module'] = self.module.to_data()
+
+        res['updated_at'] = None
+        if self.updated_at:
+            res['updated_at'] = self.updated_at.strftime('%Y-%m-%d %H:%M:%S %z')
+
+        res['tags'] = []
+        for tag in self.tags:
+            res['tags'].append(tag)
+
+        res['tasks'] = []
+        for task in self.tasks:
+            res['tasks'].append(copy.copy(task))
+
+        return res
+
+    # -------------------------------------------------------------------------
+    def __copy__(self):
+
+        release = super(CurrentModuleReleaseInfo, self).__copy__()
+        release.initialized = False
+
+        release.changelog = self.changelog
+        release.deleted_for = self.deleted_for
+        release.downloads = self.downloads
+        release.file_md5 = self.file_md5
+        release.license = self.license
+        release.pdk = self.pdk
+        release.readme = self.readme
+        release.reference = self.reference
+        release.updated_at = self.updated_at
+        release.validation_score = self.validation_score
+
+        release.metadata = None
+        if self.metadata:
+            release.metadata = copy.copy(self.metadata)
+
+        release.module = None
+        if self.module:
+            release.module = copy.copy(self.module)
+
+        release.tags = []
+        if self.tags:
+            for tag in self.tags:
+                release.tags.append(tag)
+
+        release.tasks = []
+        if self.tasks:
+            for task in self.tasks:
+                release.tasks.append(copy.copy(task))
+
+        release.initialized = self.initialized
+        return release
+
 # =============================================================================
 class ModuleReleaseList(collections.MutableSequence, FbBaseObject):