]> Frank Brehm's Git Trees - pixelpark/puppetmaster-webhooks.git/commitdiff
Adding class ForgeOwnerInfo
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 26 Feb 2019 10:13:46 +0000 (11:13 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 26 Feb 2019 10:13:46 +0000 (11:13 +0100)
lib/webhooks/forge_module_info.py

index 8065e63520c0a5490ce0659521f554f0b0110f1c..fa0f742d8d191088a0a30cd13bb0116bbeebfb27 100644 (file)
@@ -31,7 +31,7 @@ from .base_module_info import BaseModuleInfoError, BaseModuleInfo
 
 from .module_meta_info import ModuleMetadata
 
-__version__ = '0.5.2'
+__version__ = '0.5.3'
 
 LOG = logging.getLogger(__name__)
 
@@ -63,6 +63,180 @@ class ForgeModuleInfoTypeError(ForgeModuleInfoError, TypeError):
     pass
 
 
+# =============================================================================
+class ForgeOwnerInfo(FbBaseObject):
+    """Class for encapsulating information about an module owner in Puppet forge."""
+
+    # -------------------------------------------------------------------------
+    def __init__(
+        self, gravatar_id=None, slug=None, uri=None, username=None,
+            appname=None, verbose=0, version=__version__, base_dir=None, initialized=None):
+
+        self._gravatar_id = None
+        self._slug = None
+        self._uri = None
+        self._username = None
+
+        super(ForgeOwnerInfo, self).__init__(
+            appname=appname, verbose=verbose, version=version, base_dir=base_dir, initialized=False)
+
+        self.gravatar_id = gravatar_id
+        self.slug = slug
+        self.uri = uri
+        self.username = username
+
+        if initialized is not None:
+            self.initialized = initialized
+
+    # -------------------------------------------------------------------------
+    def as_dict(self, short=True):
+        """
+        Transforms the elements of the object into a dict
+
+        @return: structure as dict
+        @rtype:  dict
+        """
+
+        res = super(ForgeOwnerInfo, self).as_dict(short=short)
+
+        res['gravatar_id'] = self.gravatar_id
+        res['slug'] = self.slug
+        res['uri'] = self.uri
+        res['username'] = self.username
+
+        return res
+
+    # -------------------------------------------------------------------------
+    @property
+    def gravatar_id(self):
+        """The Gravatar-Id of this owner."""
+        return self._gravatar_id
+
+    @gravatar_id.setter
+    def gravatar_id(self, value):
+        if value is None:
+            self._gravatar_id = None
+            return
+        v = str(value).strip()
+        if value == '':
+            self._gravatar_id = None
+            return
+        self._gravatar_id = v
+
+    # -------------------------------------------------------------------------
+    @property
+    def slug(self):
+        """The slug of this owner."""
+        return self._slug
+
+    @slug.setter
+    def slug(self, value):
+        if value is None:
+            self._slug = None
+            return
+        v = str(value).strip()
+        if value == '':
+            self._slug = None
+            return
+        self._slug = v
+
+    # -------------------------------------------------------------------------
+    @property
+    def uri(self):
+        """The URI of this owner."""
+        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
+
+    # -------------------------------------------------------------------------
+    @property
+    def username(self):
+        """The username of this owner."""
+        return self._username
+
+    @username.setter
+    def username(self, value):
+        if value is None:
+            self._username = None
+            return
+        v = str(value).strip()
+        if value == '':
+            self._username = None
+            return
+        self._username = v
+
+    # -------------------------------------------------------------------------
+    def to_data(self):
+        """Returning a dict, which can be used to re-instantiate this owner info."""
+
+        res = {
+            'gravatar_id': self.gravatar_id,
+            'slug': self.slug,
+            'uri': self.uri,
+            'username': self.username,
+        }
+
+        return res
+
+    # -------------------------------------------------------------------------
+    def __copy__(self):
+
+        owner = ForgeOwnerInfo(
+            gravatar_id=self.gravatar_id, slug=self.slug, uri=self.uri, username=self.username,
+            appname=self.appname, verbose=self.verbose, base_dir=self.base_dir,
+            initialized=self.initialized)
+        return owner
+
+    # -------------------------------------------------------------------------
+    def __eq__(self, other):
+
+        if self.verbose > 4:
+            LOG.debug(_("Comparing {} objects ...").format(self.__class__.__name__))
+
+        if not isinstance(other, ForgeOwnerInfo):
+            return False
+
+        if self.gravatar_id != other.gravatar_id:
+            return False
+        if self.slug != other.slug:
+            return False
+        if self.uri != other.uri:
+            return False
+        if self.username != other.username:
+            return False
+
+        return True
+
+    # -------------------------------------------------------------------------
+    @classmethod
+    def from_data(cls, data, appname=None, verbose=0, base_dir=None):
+
+        owner = cls(appname=appname, verbose=verbose, base_dir=base_dir)
+
+        if 'gravatar_id' in data:
+            owner.gravatar_id = data['gravatar_id']
+        if 'slug' in data:
+            owner.slug = data['slug']
+        if 'uri' in data:
+            owner.guri = data['uri']
+        if 'username' in data:
+            owner.username = data['username']
+
+        if verbose > 3:
+            LOG.debug(_("Got {}:").format(cls.__name__) + '\n' + pp(owner.as_dict()))
+
+        return owner
+
+
 # =============================================================================
 class ModuleReleaseInfo(FbBaseObject):
     """Class for encapsulating information about a Puppet module release from Puppet Forge."""