diff --git a/kheops/plugin/backend/hier.py b/kheops/plugin/backend/hier.py index c4103a4..89827c0 100644 --- a/kheops/plugin/backend/hier.py +++ b/kheops/plugin/backend/hier.py @@ -1,14 +1,16 @@ +"""Hierarchy backend plugin""" + +import copy +import logging from kheops.plugin.common import PluginBackendClass from kheops.utils import path_assemble_hier -from pprint import pprint -import logging -import copy log = logging.getLogger(__name__) class Plugin(PluginBackendClass): + """Hierarchy plugin""" _plugin_name = "hier" _schema_props_new = { @@ -55,6 +57,7 @@ class Plugin(PluginBackendClass): } def process(self, backends: list, ctx: dict) -> (list, dict): + """Return results""" new_backends = [] @@ -80,12 +83,16 @@ class Plugin(PluginBackendClass): hier_data = path_assemble_hier(hier_data, hier_sep) if not isinstance(hier_data, list): - log.debug(f"Hier module can't loop over non list data, got: {hier_data} for {cand}") + log.debug( + "Hier module can't loop over non list data, got: %s for %s", + hier_data, + cand, + ) continue # Build result list ret1 = hier_data - log.debug (f"Hier plugin will loop over: {ret1}") + log.debug("Hier plugin will loop over: %s", ret1) ret2 = [] for index, item in enumerate(ret1): _cand = copy.deepcopy(cand) diff --git a/kheops/plugin/backend/init.py b/kheops/plugin/backend/init.py index eab2ee0..35e1048 100644 --- a/kheops/plugin/backend/init.py +++ b/kheops/plugin/backend/init.py @@ -1,13 +1,14 @@ -from kheops.plugin.common import PluginBackendClass -from pprint import pprint +"""Init backend plugin""" + +import copy import logging +from kheops.plugin.common import PluginBackendClass log = logging.getLogger(__name__) -import copy - class Plugin(PluginBackendClass): + """Init backend plugin""" _plugin_name = "init" _schema_props_new = None @@ -15,6 +16,7 @@ class Plugin(PluginBackendClass): default_engine = "jerakia" def process(self, backends: list, ctx: dict) -> (list, dict): + """Return the new backend list""" new_backends = [] for index, item in enumerate(backends): diff --git a/kheops/plugin/backend/loop.py b/kheops/plugin/backend/loop.py index fa87975..b5518c6 100644 --- a/kheops/plugin/backend/loop.py +++ b/kheops/plugin/backend/loop.py @@ -1,16 +1,14 @@ -import copy -from pathlib import Path -from kheops.utils import render_template -from kheops.plugin.common import PluginBackendClass -from pprint import pprint +"""Loop backend plugin""" +import copy import logging -import anyconfig -import textwrap + +from kheops.plugin.common import PluginBackendClass log = logging.getLogger(__name__) class Plugin(PluginBackendClass): + """Loop backend plugin""" _plugin_name = "loop" _plugin_help = ( @@ -118,6 +116,7 @@ class Plugin(PluginBackendClass): } def process(self, backends: list, ctx: dict) -> (list, dict): + """Return results""" new_backends = [] for cand in backends: @@ -135,7 +134,11 @@ class Plugin(PluginBackendClass): if isinstance(loop_data, str): loop_data = cand["_run"]["scope"].get(loop_data, None) if not isinstance(loop_data, list): - log.debug("Got an empty list for loop for var %s, skipping this entry: %s", cand, loop_data) + log.debug( + "Got an empty list for loop for var %s, skipping this entry: %s", + cand, + loop_data, + ) continue # Build a new list diff --git a/kheops/plugin/engine/jerakia.py b/kheops/plugin/engine/jerakia.py index 08bf1c9..e6a52cb 100644 --- a/kheops/plugin/engine/jerakia.py +++ b/kheops/plugin/engine/jerakia.py @@ -1,15 +1,18 @@ -from pathlib import Path -from kheops.utils import render_template, glob_files -from kheops.plugin.common import PluginEngineClass, PluginFileGlob #, Candidate -from pprint import pprint +"""Jerakia Engine Code""" import logging +from pathlib import Path + import anyconfig +from kheops.utils import render_template, glob_files +from kheops.plugin.common import PluginEngineClass, PluginFileGlob # , Candidate + + log = logging.getLogger(__name__) -#class FileCandidate(Candidate): +# class FileCandidate(Candidate): # path = None # # def _report_data(self): @@ -50,14 +53,14 @@ class Plugin(PluginEngineClass, PluginFileGlob): { "type": "string", }, -# { -# "type": "array", -# "items": { -# "type": "string", -# }, -# }, - ] - } + # { + # "type": "array", + # "items": { + # "type": "string", + # }, + # }, + ], + }, } def _init(self): @@ -97,18 +100,19 @@ class Plugin(PluginEngineClass, PluginFileGlob): # Look for files (NOT BE HERE !!!) ret3 = [] - for p in parsed: - globbed = glob_files(path_top / p, 'ansible.yaml') + for item in parsed: + globbed = glob_files(path_top / item, "ansible.yaml") ret3.extend(globbed) - log.debug(f"Matched globs: %s", ret3) + log.debug("Matched globs: %s", ret3) return ret3 def process(self): + """return results""" # Detect path root and path prefix - path_root = self.app.run['path_root'] - path_prefix = self.app.conf2['config']['tree']['prefix'] + path_root = self.app.run["path_root"] + path_prefix = self.app.conf2["config"]["tree"]["prefix"] if path_prefix: path_prefix = Path(path_prefix) @@ -119,9 +123,7 @@ class Plugin(PluginEngineClass, PluginFileGlob): else: path_top = path_root - path_top = path_top - log.debug (f"Path Top: {path_top}") - + log.debug("Path Top: %s", path_top) scope = self.config["_run"]["scope"] key = self.config["_run"]["key"] @@ -132,7 +134,7 @@ class Plugin(PluginEngineClass, PluginFileGlob): ret = [] for index, path in enumerate(self._show_paths(path_top, scope)): - log.debug(f"Reading file: {path}") + log.debug("Reading file: %s", path) # Fetch data found = False raw_data = anyconfig.load(path, ac_parser="yaml") @@ -156,6 +158,7 @@ class Plugin(PluginEngineClass, PluginFileGlob): # Build result object result = {} result["run"] = { + "index": index, "path": path, "rel_path": str(rel_path), } @@ -166,4 +169,3 @@ class Plugin(PluginEngineClass, PluginFileGlob): ret.append(result) return ret - diff --git a/kheops/plugin/strategy/last.py b/kheops/plugin/strategy/last.py index 49c6e74..6e3c3c4 100644 --- a/kheops/plugin/strategy/last.py +++ b/kheops/plugin/strategy/last.py @@ -1,14 +1,17 @@ +"""Simple last strategy""" + import logging from kheops.plugin.common import PluginStrategyClass log = logging.getLogger(__name__) - class Plugin(PluginStrategyClass): + """Last strategy plugin""" _plugin_name = "last" _schema_props_new = None def process(self, candidates: list, rule=None) -> (list, dict): + """Return results""" return candidates[-1] diff --git a/kheops/plugin/strategy/schema.py b/kheops/plugin/strategy/schema.py index 4c96175..3de24b0 100644 --- a/kheops/plugin/strategy/schema.py +++ b/kheops/plugin/strategy/schema.py @@ -1,16 +1,21 @@ -import logging -from kheops.plugin.common import PluginStrategyClass -from kheops.utils import schema_validate, str_ellipsis - -log = logging.getLogger(__name__) +"""Schema strategy""" import json +import logging from pprint import pprint + from jsonmerge import Merger from prettytable import PrettyTable +from kheops.plugin.common import PluginStrategyClass +from kheops.utils import str_ellipsis + + +log = logging.getLogger(__name__) + class Plugin(PluginStrategyClass): + """Schema strategy plugin""" _plugin_name = "schema" _schema_props_new = { @@ -88,6 +93,7 @@ class Plugin(PluginStrategyClass): } def process(self, candidates: list, rule=None) -> (list, dict): + """Return results""" trace = rule["trace"] explain = rule["explain"]