Lint: plugin code
This commit is contained in:
parent
94662df00a
commit
2fd179a3ff
@ -1,14 +1,16 @@
|
|||||||
|
"""Hierarchy backend plugin"""
|
||||||
|
|
||||||
|
import copy
|
||||||
|
import logging
|
||||||
|
|
||||||
from kheops.plugin.common import PluginBackendClass
|
from kheops.plugin.common import PluginBackendClass
|
||||||
from kheops.utils import path_assemble_hier
|
from kheops.utils import path_assemble_hier
|
||||||
from pprint import pprint
|
|
||||||
import logging
|
|
||||||
import copy
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Plugin(PluginBackendClass):
|
class Plugin(PluginBackendClass):
|
||||||
|
"""Hierarchy plugin"""
|
||||||
|
|
||||||
_plugin_name = "hier"
|
_plugin_name = "hier"
|
||||||
_schema_props_new = {
|
_schema_props_new = {
|
||||||
@ -55,6 +57,7 @@ class Plugin(PluginBackendClass):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def process(self, backends: list, ctx: dict) -> (list, dict):
|
def process(self, backends: list, ctx: dict) -> (list, dict):
|
||||||
|
"""Return results"""
|
||||||
|
|
||||||
new_backends = []
|
new_backends = []
|
||||||
|
|
||||||
@ -80,12 +83,16 @@ class Plugin(PluginBackendClass):
|
|||||||
hier_data = path_assemble_hier(hier_data, hier_sep)
|
hier_data = path_assemble_hier(hier_data, hier_sep)
|
||||||
|
|
||||||
if not isinstance(hier_data, list):
|
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
|
continue
|
||||||
|
|
||||||
# Build result list
|
# Build result list
|
||||||
ret1 = hier_data
|
ret1 = hier_data
|
||||||
log.debug (f"Hier plugin will loop over: {ret1}")
|
log.debug("Hier plugin will loop over: %s", ret1)
|
||||||
ret2 = []
|
ret2 = []
|
||||||
for index, item in enumerate(ret1):
|
for index, item in enumerate(ret1):
|
||||||
_cand = copy.deepcopy(cand)
|
_cand = copy.deepcopy(cand)
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
from kheops.plugin.common import PluginBackendClass
|
"""Init backend plugin"""
|
||||||
from pprint import pprint
|
|
||||||
|
import copy
|
||||||
import logging
|
import logging
|
||||||
|
from kheops.plugin.common import PluginBackendClass
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
import copy
|
|
||||||
|
|
||||||
|
|
||||||
class Plugin(PluginBackendClass):
|
class Plugin(PluginBackendClass):
|
||||||
|
"""Init backend plugin"""
|
||||||
|
|
||||||
_plugin_name = "init"
|
_plugin_name = "init"
|
||||||
_schema_props_new = None
|
_schema_props_new = None
|
||||||
@ -15,6 +16,7 @@ class Plugin(PluginBackendClass):
|
|||||||
default_engine = "jerakia"
|
default_engine = "jerakia"
|
||||||
|
|
||||||
def process(self, backends: list, ctx: dict) -> (list, dict):
|
def process(self, backends: list, ctx: dict) -> (list, dict):
|
||||||
|
"""Return the new backend list"""
|
||||||
|
|
||||||
new_backends = []
|
new_backends = []
|
||||||
for index, item in enumerate(backends):
|
for index, item in enumerate(backends):
|
||||||
|
|||||||
@ -1,16 +1,14 @@
|
|||||||
import copy
|
"""Loop backend plugin"""
|
||||||
from pathlib import Path
|
|
||||||
from kheops.utils import render_template
|
|
||||||
from kheops.plugin.common import PluginBackendClass
|
|
||||||
from pprint import pprint
|
|
||||||
|
|
||||||
|
import copy
|
||||||
import logging
|
import logging
|
||||||
import anyconfig
|
|
||||||
import textwrap
|
from kheops.plugin.common import PluginBackendClass
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
class Plugin(PluginBackendClass):
|
class Plugin(PluginBackendClass):
|
||||||
|
"""Loop backend plugin"""
|
||||||
|
|
||||||
_plugin_name = "loop"
|
_plugin_name = "loop"
|
||||||
_plugin_help = (
|
_plugin_help = (
|
||||||
@ -118,6 +116,7 @@ class Plugin(PluginBackendClass):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def process(self, backends: list, ctx: dict) -> (list, dict):
|
def process(self, backends: list, ctx: dict) -> (list, dict):
|
||||||
|
"""Return results"""
|
||||||
|
|
||||||
new_backends = []
|
new_backends = []
|
||||||
for cand in backends:
|
for cand in backends:
|
||||||
@ -135,7 +134,11 @@ class Plugin(PluginBackendClass):
|
|||||||
if isinstance(loop_data, str):
|
if isinstance(loop_data, str):
|
||||||
loop_data = cand["_run"]["scope"].get(loop_data, None)
|
loop_data = cand["_run"]["scope"].get(loop_data, None)
|
||||||
if not isinstance(loop_data, list):
|
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
|
continue
|
||||||
|
|
||||||
# Build a new list
|
# Build a new list
|
||||||
|
|||||||
@ -1,11 +1,14 @@
|
|||||||
from pathlib import Path
|
"""Jerakia Engine Code"""
|
||||||
from kheops.utils import render_template, glob_files
|
|
||||||
from kheops.plugin.common import PluginEngineClass, PluginFileGlob #, Candidate
|
|
||||||
from pprint import pprint
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import anyconfig
|
import anyconfig
|
||||||
|
|
||||||
|
from kheops.utils import render_template, glob_files
|
||||||
|
from kheops.plugin.common import PluginEngineClass, PluginFileGlob # , Candidate
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -56,8 +59,8 @@ class Plugin(PluginEngineClass, PluginFileGlob):
|
|||||||
# "type": "string",
|
# "type": "string",
|
||||||
# },
|
# },
|
||||||
# },
|
# },
|
||||||
]
|
],
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
def _init(self):
|
def _init(self):
|
||||||
@ -97,18 +100,19 @@ class Plugin(PluginEngineClass, PluginFileGlob):
|
|||||||
|
|
||||||
# Look for files (NOT BE HERE !!!)
|
# Look for files (NOT BE HERE !!!)
|
||||||
ret3 = []
|
ret3 = []
|
||||||
for p in parsed:
|
for item in parsed:
|
||||||
globbed = glob_files(path_top / p, 'ansible.yaml')
|
globbed = glob_files(path_top / item, "ansible.yaml")
|
||||||
ret3.extend(globbed)
|
ret3.extend(globbed)
|
||||||
log.debug(f"Matched globs: %s", ret3)
|
log.debug("Matched globs: %s", ret3)
|
||||||
|
|
||||||
return ret3
|
return ret3
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
|
"""return results"""
|
||||||
|
|
||||||
# Detect path root and path prefix
|
# Detect path root and path prefix
|
||||||
path_root = self.app.run['path_root']
|
path_root = self.app.run["path_root"]
|
||||||
path_prefix = self.app.conf2['config']['tree']['prefix']
|
path_prefix = self.app.conf2["config"]["tree"]["prefix"]
|
||||||
|
|
||||||
if path_prefix:
|
if path_prefix:
|
||||||
path_prefix = Path(path_prefix)
|
path_prefix = Path(path_prefix)
|
||||||
@ -119,9 +123,7 @@ class Plugin(PluginEngineClass, PluginFileGlob):
|
|||||||
else:
|
else:
|
||||||
path_top = path_root
|
path_top = path_root
|
||||||
|
|
||||||
path_top = path_top
|
log.debug("Path Top: %s", path_top)
|
||||||
log.debug (f"Path Top: {path_top}")
|
|
||||||
|
|
||||||
|
|
||||||
scope = self.config["_run"]["scope"]
|
scope = self.config["_run"]["scope"]
|
||||||
key = self.config["_run"]["key"]
|
key = self.config["_run"]["key"]
|
||||||
@ -132,7 +134,7 @@ class Plugin(PluginEngineClass, PluginFileGlob):
|
|||||||
|
|
||||||
ret = []
|
ret = []
|
||||||
for index, path in enumerate(self._show_paths(path_top, scope)):
|
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
|
# Fetch data
|
||||||
found = False
|
found = False
|
||||||
raw_data = anyconfig.load(path, ac_parser="yaml")
|
raw_data = anyconfig.load(path, ac_parser="yaml")
|
||||||
@ -156,6 +158,7 @@ class Plugin(PluginEngineClass, PluginFileGlob):
|
|||||||
# Build result object
|
# Build result object
|
||||||
result = {}
|
result = {}
|
||||||
result["run"] = {
|
result["run"] = {
|
||||||
|
"index": index,
|
||||||
"path": path,
|
"path": path,
|
||||||
"rel_path": str(rel_path),
|
"rel_path": str(rel_path),
|
||||||
}
|
}
|
||||||
@ -166,4 +169,3 @@ class Plugin(PluginEngineClass, PluginFileGlob):
|
|||||||
ret.append(result)
|
ret.append(result)
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|||||||
@ -1,14 +1,17 @@
|
|||||||
|
"""Simple last strategy"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from kheops.plugin.common import PluginStrategyClass
|
from kheops.plugin.common import PluginStrategyClass
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Plugin(PluginStrategyClass):
|
class Plugin(PluginStrategyClass):
|
||||||
|
"""Last strategy plugin"""
|
||||||
|
|
||||||
_plugin_name = "last"
|
_plugin_name = "last"
|
||||||
_schema_props_new = None
|
_schema_props_new = None
|
||||||
|
|
||||||
def process(self, candidates: list, rule=None) -> (list, dict):
|
def process(self, candidates: list, rule=None) -> (list, dict):
|
||||||
|
"""Return results"""
|
||||||
|
|
||||||
return candidates[-1]
|
return candidates[-1]
|
||||||
|
|||||||
@ -1,16 +1,21 @@
|
|||||||
import logging
|
"""Schema strategy"""
|
||||||
from kheops.plugin.common import PluginStrategyClass
|
|
||||||
from kheops.utils import schema_validate, str_ellipsis
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
||||||
from jsonmerge import Merger
|
from jsonmerge import Merger
|
||||||
from prettytable import PrettyTable
|
from prettytable import PrettyTable
|
||||||
|
|
||||||
|
from kheops.plugin.common import PluginStrategyClass
|
||||||
|
from kheops.utils import str_ellipsis
|
||||||
|
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Plugin(PluginStrategyClass):
|
class Plugin(PluginStrategyClass):
|
||||||
|
"""Schema strategy plugin"""
|
||||||
|
|
||||||
_plugin_name = "schema"
|
_plugin_name = "schema"
|
||||||
_schema_props_new = {
|
_schema_props_new = {
|
||||||
@ -88,6 +93,7 @@ class Plugin(PluginStrategyClass):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def process(self, candidates: list, rule=None) -> (list, dict):
|
def process(self, candidates: list, rule=None) -> (list, dict):
|
||||||
|
"""Return results"""
|
||||||
|
|
||||||
trace = rule["trace"]
|
trace = rule["trace"]
|
||||||
explain = rule["explain"]
|
explain = rule["explain"]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user