@copyright: © 2017 by Frank Brehm, Berlin
@summary: The module for the deploy application object.
"""
+from __future__ import absolute_import
# Standard modules
import os
import requests
# Own modules
-import webhooks
+from . import __version__
-from webhooks.common import pp, to_str
+from .common import pp, to_str
-from webhooks.base_app import BaseHookError, BaseHookApp
+from .base_app import BaseHookError, BaseHookApp
-__version__ = webhooks.__version__
+from .module_info import ModuleInfoError, ModuleInfo
+
+#__version__ = webhooks.__version__
LOG = logging.getLogger(__name__)
self.puppet_root_env_dir = self.default_puppet_root_env_dir
self.forge_uri = self.default_forge_uri
self.http_timeout = self.default_http_timeout
+ self.modules = {}
self.description = textwrap.dedent('''\
Collects information about all used Puppet Modules from {url}
self.print_out(msg)
self.check_data_dir()
- self._init_puppet_environments()
+ self.init_puppet_environments()
+ self.collect_local_modules()
+
+ # -------------------------------------------------------------------------
+ def collect_local_modules(self):
+
+ pass
# -------------------------------------------------------------------------
- def _init_puppet_environments(self):
+ def init_puppet_environments(self):
LOG.debug("Collecting all Puppet environments in {!r}.".format(self.puppet_root_env_dir))
pattern = os.path.join(self.puppet_root_env_dir, '*')
--- /dev/null
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+@author: Frank Brehm
+@contact: frank.brehm@pixelpark.com
+@copyright: © 2018 by Frank Brehm, Publicies Pixelpark GmbH, Berlin
+@summary: A module for encapsulating all information about a Puppet module
+"""
+from __future__ import absolute_import
+
+# Standard modules
+import os
+import logging
+import re
+
+# Third party modules
+import six
+
+# Own modules
+from .common import pp, to_str
+
+from .obj import BaseObjectError
+from .obj import BaseObject
+
+__version__ = '0.1.0'
+
+LOG = logging.getLogger(__name__)
+
+
+# =============================================================================
+class ModuleInfoError(BaseObjectError):
+
+ pass
+
+
+# =============================================================================
+class ModuleInfo(BaseObject):
+ """Class for encapsulating information about a Puppet module."""
+
+ re_split_name = re.compile(r'^\s*([a-z0-9]+)[-/_](\S+)\s*$', re.IGNORECASE)
+
+ # -------------------------------------------------------------------------
+ def __init__(
+ self, appname=None, verbose=0, version=__version__, base_dir=None,
+ initialized=None, name=None, vendor=None, full_name=None):
+
+ self._name = None
+ self._vendor = None
+ self._full_name_orig = None
+ self._version_upstream = None
+ self.local_versions = {}
+
+ super(ModuleInfo, self).__init__(
+ appname=appname, verbose=verbose, version=version,
+ base_dir=base_dir, initialized=False,
+ )
+
+ _name = name
+ if name is not None:
+ _name = to_str(name).strip().lower()
+
+ _vendor = vendor
+ if vendor is not None:
+ _vendor = to_str(vendor).strip().lower()
+
+ _full_name = full_name
+ if full_name is not None:
+ _full_name = to_str(full_name).strip().lower()
+
+ if _full_name:
+
+ match = re_split_name.match(_full_name)
+ if not match:
+ raise ModuleInfoError(
+ "Could not analyze given full module name {!r}.".format(
+ full_name))
+
+ self._full_name_orig = _full_name
+
+ if _name:
+ self._name = _name
+ else:
+ self._name = match.group(2).lower()
+
+ if _vendor:
+ self._vendor = _name
+ else:
+ self._vendor = match.group(1).lower()
+
+ else:
+
+ if not _name or not _vendor:
+ msg = (
+ "There must be given a full module name or the base module name "
+ "and the vendor name (user name on Puppet Forge).")
+ raise ModuleInfoError(msg)
+
+ self._name = _name
+ self._vendor = _vendor
+ self._full_name_orig = self.full_name
+
+ # -------------------------------------------------------------------------
+ @property
+ def name(self):
+ """The name of the module without the vendor."""
+ return self._name
+
+ # -------------------------------------------------------------------------
+ @property
+ def vendor(self):
+ """The vendor of the module - the username on Puppet forge."""
+ return self._vendor
+
+ # -------------------------------------------------------------------------
+ @property
+ def full_name(self):
+ """The full name of the module including vandor and name."""
+ if self.name is None:
+ return None
+ if self.vendor is None:
+ return None
+ return "{v}-{n}".format(v=self.vendor, n=self.name)
+
+ # -------------------------------------------------------------------------
+ @property
+ def full_name_orig(self):
+ """The original full name of the module."""
+ if self._full_name_orig:
+ return self._full_name_orig
+ return self.full_name
+
+ @full_name_orig.setter
+ def full_name_orig(self, value):
+ if value is None:
+ self._full_name_orig = None
+ return
+ val = to_str(value).strip().lower()
+ if val:
+ self._full_name_orig = val
+ else:
+ self._full_name_orig = None
+
+
+# =============================================================================
+
+if __name__ == "__main__":
+
+ pass
+
+# =============================================================================
+
+# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 list