from .xlate import XLATOR
-__version__ = '0.4.2'
+__version__ = '0.5.1'
LOG = logging.getLogger(__name__)
return new
+# =============================================================================
+class ModuleOsSupport(object):
+ """Class for encapsulating the support of the module to a particular operating system."""
+
+ # -------------------------------------------------------------------------
+ def __init__(self, name, releases):
+
+ self.name = str(name).strip()
+ self.releases = copy.copy(releases)
+
+ # -------------------------------------------------------------------------
+ @classmethod
+ def from_data(cls, data):
+
+ if 'operatingsystem' not in data:
+ msg = _("{} not included in JSON data.").format('operatingsystem')
+ raise MetadataInitError(msg)
+
+ releases = []
+ if 'operatingsystemrelease' in data:
+ if not is_sequence(data['operatingsystemrelease']):
+ msg = _("Invalid item {} - not a list.").format('operatingsystemrelease')
+ raise MetadataInitError(msg)
+ for item in data['operatingsystemrelease']:
+ releases.append(str(item).strip())
+
+ os_supp = cls(name=data['operatingsystem'], releases=releases)
+ return os_supp
+
+ # -------------------------------------------------------------------------
+ def as_dict(self):
+
+ ret = {
+ 'name': self.name,
+ 'releases': copy.copy(self.releases),
+ }
+ return ret
+
+ # -------------------------------------------------------------------------
+ def to_data(self):
+
+ ret = {'operatingsystem': self.name}
+ if self.releases:
+ ret['operatingsystemrelease'] = copy.copy(self.releases)
+ return ret
+
+ # -------------------------------------------------------------------------
+ def __copy__(self):
+
+ new = cls(name=self.name, releases=copy.copy(self.releases))
+ return new
+
+
# =============================================================================
class ModuleMetadata(FbBaseObject):
"""Class for encapsulating information about a Puppet module."""
self.requirements = []
self._project_page = None
self._issues_url = None
+ self.operatingsystem_support = []
super(ModuleMetadata, self).__init__(
appname=appname, verbose=verbose, version=version,
res['requirements'].append(req.as_dict())
res['project_page'] = self.project_page
res['issues_url'] = self.issues_url
+ res['operatingsystem_support'] = []
+ for supp in self.operatingsystem_support:
+ res['operatingsystem_support'].append(supp.as_dict())
return res
See https://puppet.com/docs/puppet/5.2/modules_metadata.html for syntax.
"""
+ if verbose > 3:
+ LOG.debug("Trying to create a {c} object from:\n{d}".format(
+ c=cls.__name__, d=pp(json_data)))
+
required_props = {
'name': 'Name',
'version': 'Version',
msg = _("Invalid item {} - not a list.").format('requirements')
raise MetadataInitError(msg)
+ if 'operatingsystem_support' in json_data:
+ if not is_sequence(json_data['operatingsystem_support']):
+ msg = _("Invalid item {} - not a list.").format('operatingsystem_support')
+ raise MetadataInitError(msg)
+
metadata = cls(appname=appname, verbose=verbose, base_dir=base_dir)
metadata.name = json_data['name']
metadata.project_page = json_data['project_page']
if 'issues_url' in json_data:
metadata.issues_url = json_data['issues_url']
+ if 'operatingsystem_support' in json_data:
+ for item in json_data['operatingsystem_support']:
+ supp = ModuleOsSupport.from_data(item)
+ metadata.operatingsystem_support.append(supp)
metadata.initialized = True
if verbose > 3:
new.requirements.append(copy.copy(req))
new.project_page = self.project_page
new.issues_url = self.issues_url
+ for supp in self.operatingsystem_support:
+ new.operatingsystem_support.append(copy.copy(supp))
new.initialized = True
data['project_page'] = self.project_page
if self.issues_url:
data['issues_url'] = self.issues_url
+ if self.operatingsystem_support:
+ data['operatingsystem_support'] = []
+ for supp in self.operatingsystem_support:
+ data['operatingsystem_support'].append(supp.to_data())
if self.verbose > 4:
LOG.debug("ModuleMetadata:\n{}".format(pp(data)))