from .module_meta_info import ModuleMetadata
-__version__ = '0.5.3'
+__version__ = '0.5.4'
LOG = logging.getLogger(__name__)
if 'slug' in data:
owner.slug = data['slug']
if 'uri' in data:
- owner.guri = data['uri']
+ owner.uri = data['uri']
if 'username' in data:
owner.username = data['username']
+ owner.initialized = True
if verbose > 3:
LOG.debug(_("Got {}:").format(cls.__name__) + '\n' + pp(owner.as_dict()))
return owner
+# =============================================================================
+class BaseForgeModuleInfo(FbBaseObject):
+ """Class for encapsulating base information about a Puppet module from Puppet Forge."""
+
+ # -------------------------------------------------------------------------
+ def __init__(
+ self, appname=None, verbose=0, version=__version__, base_dir=None,
+ initialized=None):
+
+ self._deprecated_at = None
+ self._name = None
+ self.owner = None
+ self._slug = None
+ self._uri = None
+
+ super(BaseForgeModuleInfo, self).__init__(
+ appname=appname, verbose=verbose, version=version, base_dir=base_dir, initialized=False)
+
+ 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(BaseForgeModuleInfo, self).as_dict(short=short)
+
+ res['deprecated_at'] = self.deprecated_at
+ res['name'] = self.name
+ res['slug'] = self.slug
+ res['uri'] = self.uri
+
+ return res
+
+ # -------------------------------------------------------------------------
+ @property
+ def deprecated_at(self):
+ """Date of deprecation of this 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 name(self):
+ """The name of this module."""
+ return self._name
+
+ @name.setter
+ def name(self, value):
+ if value is None:
+ self._name = None
+ return
+ v = str(value).strip()
+ if value == '':
+ self._name = None
+ return
+ self._name = v
+
+ # -------------------------------------------------------------------------
+ @property
+ def slug(self):
+ """The slug of this module."""
+ 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 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 to_data(self):
+ """Returning a dict, which can be used to re-instantiate this module info."""
+
+ res = {}
+
+ res['deprecated_at'] = None
+ if self.deprecated_at:
+ res['deprecated_at'] = self.deprecated_at.strftime('%Y-%m-%d %H:%M:%S %z')
+
+ res['owner'] = None
+ if self.owner:
+ res['owner'] = self.owner.to_data()
+
+ res['name'] = self.name
+ res['slug'] = self.slug
+ res['uri'] = self.uri
+
+ return res
+
+ # -------------------------------------------------------------------------
+ def __copy__(self):
+
+ mod = BaseForgeModuleInfo(
+ appname=self.appname, verbose=self.verbose, base_dir=self.base_dir)
+ mod.deprecated_at = self.deprecated_at
+ mod.name = self.name
+ if self.owner:
+ mod.owner = copy.copy(self.owner)
+ mod.slug = self.slug
+ mod.uri = self.uri
+
+ mod.initialized = self.initialized
+ return mod
+
+ # -------------------------------------------------------------------------
+ def __eq__(self, other):
+
+ if self.verbose > 4:
+ LOG.debug(_("Comparing {} objects ...").format(self.__class__.__name__))
+
+ if not isinstance(other, BaseForgeModuleInfo):
+ return False
+
+ if self.deprecated_at != other.deprecated_at:
+ return False
+ if self.name != other.name:
+ return False
+ if self.owner != other.owner:
+ return False
+ if self.slug != other.slug:
+ return False
+ if self.uri != other.uri:
+ return False
+
+ return True
+
+ # -------------------------------------------------------------------------
+ @classmethod
+ def from_data(cls, data, appname=None, verbose=0, base_dir=None):
+
+ mod = cls(appname=appname, verbose=verbose, base_dir=base_dir)
+
+ if 'deprecated_at' in data:
+ mod.deprecated_at = data['deprecated_at']
+ if 'slug' in data:
+ mod.slug = data['slug']
+ if 'uri' in data:
+ mod.uri = data['uri']
+ if 'name' in data:
+ mod.name = data['name']
+
+ if 'owner' in data and data['owner']:
+ mod.owner = ForgeOwnerInfo.from_data(
+ data['owner'], appname=appname, verbose=verbose, base_dir=base_dir)
+
+ mod.initialized = True
+
+ if verbose > 3:
+ LOG.debug(_("Got {}:").format(cls.__name__) + '\n' + pp(mod.as_dict()))
+
+ return mod
+
+
# =============================================================================
class ModuleReleaseInfo(FbBaseObject):
"""Class for encapsulating information about a Puppet module release from Puppet Forge."""
self._file_md5 = None
self._license = None
self.metadata = None
+ self.module = None
self._pdk = False
self._readme = None
self._reference = None
data['metadata'], appname=self.appname,
verbose=self.verbose, base_dir=self.base_dir)
+ if 'module' in data and data['module']:
+ self.module = BaseForgeModuleInfo.from_data(
+ data['module'], appname=self.appname,
+ verbose=self.verbose, base_dir=self.base_dir)
+
# =============================================================================
class ModuleReleaseList(collections.MutableSequence, FbBaseObject):