From e99bd7404cea346b9ba20754e8911e0aa95a0d9c Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 15 Aug 2018 14:23:44 +0200 Subject: [PATCH] Verifying dependencies --- pp_lib/check_puppet_env_app.py | 61 +++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/pp_lib/check_puppet_env_app.py b/pp_lib/check_puppet_env_app.py index 05aeab2..43966f8 100644 --- a/pp_lib/check_puppet_env_app.py +++ b/pp_lib/check_puppet_env_app.py @@ -39,7 +39,7 @@ from .merge import merge_structure from .app import PpApplication -__version__ = '0.3.1' +__version__ = '0.4.1' LOG = logging.getLogger(__name__) @@ -83,6 +83,7 @@ class CheckPuppetEnvApp(PpApplication): self.env_dir = None self.modules_root_dir = None self.modules = {} + self.dependencies = [] super(CheckPuppetEnvApp, self).__init__( appname=appname, verbose=verbose, version=version, base_dir=base_dir, @@ -266,6 +267,64 @@ class CheckPuppetEnvApp(PpApplication): self.collect_modules() self.print_modules() + self.verify_dependencies() + + # ------------------------------------------------------------------------- + def verify_dependencies(self): + + LOG.info("Verifying dependencies ...") + + mods = {} + self.dependencies = [] + re_name_split = re.compile(r'([^/_-]+)[/_-](.*)') + connectors = ('-', '_', '/') + + for b_name in self.modules.keys(): + module_info = self.modules[b_name] + base_name = str(b_name) + if module_info['name']: + mod_name = module_info['name'] + mods[module_info['name']] = base_name + else: + LOG.warn("Did not found complete name of module {!r}.".format(base_name)) + + for b_name in self.modules.keys(): + module_info = self.modules[b_name] + base_name = str(b_name) + if not module_info['dependencies']: + continue + if not module_info['name']: + LOG.debug("Did not found complete name of module {!r}.".format(base_name)) + continue + if not module_info['vendor']: + LOG.warn("Did not found vendor of module {!r}.".format(base_name)) + mod_name = module_info['name'] + + for dep_key in module_info['dependencies'].keys(): + dep_mod = str(dep_key) + if dep_mod in mods: + dep = (dep_mod, mod_name) + self.dependencies.append(dep) + continue + match = re_name_split.match(dep_mod) + found = False + if match: + dep_mod_vendor = match.group(1) + dep_mod_base = match.group(2) + for connector in connectors: + dep_mod_name = dep_mod_vendor + connector + dep_mod_base + if dep_mod_name in mods: + dep = (dep_mod_name, mod_name) + self.dependencies.append(dep) + found = True + break + if found: + break + LOG.warn("Did not found dependency to {d!r} of module {m!r}.".format( + d=dep_mod, m=mod_name)) + + if self.verbose > 2: + LOG.debug("Found dependencies:\n{}".format(pp(self.dependencies))) # ------------------------------------------------------------------------- def print_modules(self): -- 2.39.5