Lint: plugin code

This commit is contained in:
mrjk 2022-01-26 16:14:01 -05:00
parent 94662df00a
commit 2fd179a3ff
6 changed files with 69 additions and 46 deletions

View File

@ -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)

View File

@ -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):

View File

@ -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

View File

@ -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

View File

@ -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]

View File

@ -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"]