from .module_meta_info import ModuleMetadata
-__version__ = '0.6.2'
+__version__ = '0.6.3'
LOG = logging.getLogger(__name__)
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):
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
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
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:
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])
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