from .xlate import XLATOR
-__version__ = '0.1.1'
+__version__ = '0.2.2'
LOG = logging.getLogger(__name__)
class ModuleMetadata(FbBaseObject):
"""Class for encapsulating information about a Puppet module."""
+ re_author_from_name = re.compile(r'^([^-]+)-')
+
# -------------------------------------------------------------------------
def __init__(
self, appname=None, verbose=0, version=__version__, base_dir=None,
initialized=None):
self._name = None
+ self._version = None
+ self._author = None
super(ModuleMetadata, self).__init__(
appname=appname, verbose=verbose, version=version,
return
self._name = to_str(value).strip().lower()
+ # -------------------------------------------------------------------------
+ @property
+ def version(self):
+ """The version of the module."""
+ return self._version
+
+ @version.setter
+ def version(self, value):
+ if value is None:
+ self._version = None
+ return
+ self._version = to_str(value).strip()
+
+ # -------------------------------------------------------------------------
+ @property
+ def author(self):
+ """The author of the module."""
+ if not self._author:
+ match = self.re_author_from_name.match(self.name)
+ if match:
+ return match.group(1)
+ return self._author
+
+ @author.setter
+ def author(self, value):
+ if value is None:
+ self._author = None
+ return
+ self._author = to_str(value).strip()
+
# -------------------------------------------------------------------------
def as_dict(self, short=True):
"""
res = super(ModuleMetadata, self).as_dict(short=short)
res['name'] = self.name
+ res['version'] = self.version
+ res['author'] = self.author
return res
See https://puppet.com/docs/puppet/5.2/modules_metadata.html for syntax.
"""
- if 'name' not in json_data:
- msg = _("Name of the module not included in JSON data.")
- raise MetadataInitError(msg)
+ required_props = {
+ 'name': 'Name',
+ 'version': 'Version',
+ }
+
+ for prop in required_props.keys():
+ desc = required_props[prop]
+ if prop not in json_data:
+ msg = _("{} not included in JSON data.").format(desc)
+ raise MetadataInitError(msg)
metadata = cls(appname=appname, verbose=verbose, base_dir=base_dir)
metadata.name = json_data['name']
+ metadata.version = json_data['version']
+ if 'author' in json_data:
+ metadata.author = json_data['author']
+ else:
+ metadata.author = metadata.author
+
+ metadata.initialized = True
if verbose > 3:
LOG.debug("ModuleMetadata:\n{}".format(pp(metadata.as_dict())))
def __copy__(self):
new = self.__class__(appname=self.appname, verbose=self.verbose, base_dir=self.base_dir)
+
new.name = self.name
+ new.version = self.version
+ new.author = self.author
+
+ new.initialized = True
return new
data = {}
data['name'] = self.name
+ data['version'] = self.version
+ data['author'] = self.author
if self.verbose > 4:
LOG.debug("ModuleMetadata:\n{}".format(pp(data)))