from .xlate import XLATOR
-__version__ = '0.2.2'
+__version__ = '0.3.1'
LOG = logging.getLogger(__name__)
pass
+# =============================================================================
+class ModuleDependency(object):
+ """Class for encapsulating a dependency to another Puppet module."""
+
+ # -------------------------------------------------------------------------
+ def __init__(self, name, requirement):
+
+ self.name = str(name).strip().lower()
+ self.requirement = str(requirement).strip()
+
+ # -------------------------------------------------------------------------
+ @classmethod
+ def from_data(cls, data):
+
+ for prop in ('name', 'version_requirement'):
+ if prop not in data:
+ msg = _("{} not included in JSON data.").format(prop)
+ raise MetadataInitError(msg)
+
+ dep = cls(name=data['name'], requirement=data['version_requirement'])
+ return dep
+
+ # -------------------------------------------------------------------------
+ def as_dict(self):
+
+ ret = {
+ 'name': self.name,
+ 'requirement': self.requirement,
+ }
+ return ret
+
+ # -------------------------------------------------------------------------
+ def to_data(self):
+
+ ret = {
+ 'name': self.name,
+ 'version_requirement': self.requirement,
+ }
+ return ret
+
+ # -------------------------------------------------------------------------
+ def __copy__(self):
+
+ new = cls(name=self.name, requirement=self.requirement)
+ return new
+
+
# =============================================================================
class ModuleMetadata(FbBaseObject):
"""Class for encapsulating information about a Puppet module."""
self._license = None
self._summary = None
self._source = None
+ self.dependencies = []
super(ModuleMetadata, self).__init__(
appname=appname, verbose=verbose, version=version,
res['license'] = self.license
res['summary'] = self.summary
res['source'] = self.source
+ res['dependencies'] = []
+ for dep in self.dependencies:
+ res['dependencies'].append(dep.as_dict())
return res
'license': 'License',
'summary': 'Summary',
'source': 'Source',
+ 'dependencies': 'Dependencies',
}
for prop in required_props.keys():
msg = _("{} not included in JSON data.").format(desc)
raise MetadataInitError(msg)
+ if not is_sequence(json_data['dependencies']):
+ msg = _("Invalid dependencies - not a list.")
+ raise MetadataInitError(msg)
+
metadata = cls(appname=appname, verbose=verbose, base_dir=base_dir)
metadata.name = json_data['name']
metadata.license = json_data['license']
metadata.summary = json_data['summary']
metadata.source = json_data['source']
+ for item in json_data['dependencies']:
+ dep = ModuleDependency.from_data(item)
+ metadata.dependencies.append(dep)
metadata.initialized = True
if verbose > 3:
new.license = self.license
new.summary = self.summary
new.source = self.source
+ for dep in self.dependencies:
+ new.dependencies.append(copy.copy(dep))
new.initialized = True
data['license'] = self.license
data['summary'] = self.summary
data['source'] = self.source
+ data['dependencies'] = []
+ for dep in self.dependencies:
+ data['dependencies'].append(dep.to_data())
if self.verbose > 4:
LOG.debug("ModuleMetadata:\n{}".format(pp(data)))