--- /dev/null
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+@author: Frank Brehm
+@contact: frank.brehm@pixelpark.com
+@copyright: © 2023 by Frank Brehm, Digitas Pixelpark GmbH, Berlin
+@summary: A module for encapsulating basic information about a Forge module
+"""
+from __future__ import absolute_import
+
+# Standard modules
+import logging
+import copy
+import datetime
+
+# Own modules
+
+from ..xlate import XLATOR
+
+from . import parse_forge_date
+from . import BaseForgeObject
+
+from .owner_info import ForgeOwnerInfo
+
+__version__ = '0.2.0'
+
+LOG = logging.getLogger(__name__)
+
+_ = XLATOR.gettext
+ngettext = XLATOR.ngettext
+
+
+# =============================================================================
+class BaseForgeModuleInfo(BaseForgeObject):
+
+ # -------------------------------------------------------------------------
+ def __init__(
+ self, appname=None, verbose=0, version=__version__, base_dir=None,
+ initialized=None):
+
+ self._deprecated_at = None
+ self._name = None
+ self.owner = 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
+
+ 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 v == '':
+ 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 v == '':
+ self._name = None
+ return
+ self._name = v
+
+ # -------------------------------------------------------------------------
+ def to_data(self):
+ """Returning a dict, which can be used to re-instantiate this module info."""
+
+ res = super(BaseForgeModuleInfo, self).to_data()
+
+ 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
+
+ return res
+
+ # -------------------------------------------------------------------------
+ def apply_to(self, new):
+
+ if not isinstance(new, BaseForgeModuleInfo):
+ msg = _("Parameter {p!r} is not of class {c!r}, but of {e!r} instead.").format(
+ p='new', c='BaseForgeModuleInfo', e=new.__class__.__name__)
+ raise TypeError(msg)
+
+ super(BaseForgeModuleInfo, self).apply_to(new)
+ new.deprecated_at = self.deprecated_at
+ new.name = self.name
+ if self.owner:
+ new.owner = copy.copy(self.owner)
+
+ # -------------------------------------------------------------------------
+ def __eq__(self, other):
+
+ if self.verbose > 4:
+ LOG.debug(_("Comparing {} objects ...").format(self.__class__.__name__))
+
+ if not super(BaseForgeModuleInfo, self).__eq__(other):
+ return False
+
+ 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
+
+ return True
+
+ # -------------------------------------------------------------------------
+ def apply_data(self, data):
+
+ super(BaseForgeModuleInfo, self).apply_data(data)
+
+ if 'deprecated_at' in data:
+ self.deprecated_at = data['deprecated_at']
+ if 'name' in data:
+ self.name = data['name']
+
+ if 'owner' in data and data['owner']:
+ self.owner = ForgeOwnerInfo.from_data(
+ data['owner'], appname=self.appname,
+ verbose=self.verbose, base_dir=self.base_dir)
+
+
+# =============================================================================
+if __name__ == "__main__":
+
+ pass
+
+# =============================================================================
+
+# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 list