Lint: plugin.common
This commit is contained in:
parent
b01baf44ad
commit
94662df00a
@ -1,49 +1,43 @@
|
|||||||
# from box import Box
|
"""Common libraries for plugins"""
|
||||||
import textwrap
|
|
||||||
from pprint import pprint
|
|
||||||
import glob
|
|
||||||
from pathlib import Path
|
|
||||||
from jinja2 import Template
|
|
||||||
import yaml
|
|
||||||
import json
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from kheops.utils import schema_validate
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
from kheops.utils import schema_validate
|
|
||||||
import copy
|
|
||||||
|
|
||||||
# Candidate Classes
|
# Candidate Classes
|
||||||
# =============================
|
# =============================
|
||||||
class Candidate:
|
# class Candidate:
|
||||||
engine = None
|
# engine = None
|
||||||
found = False
|
# found = False
|
||||||
data = None
|
# data = None
|
||||||
run = None
|
# run = None
|
||||||
scope = None
|
# scope = None
|
||||||
key = None
|
# key = None
|
||||||
|
#
|
||||||
def __init__(self, run):
|
# def __init__(self, run):
|
||||||
self.run = copy.deepcopy(run)
|
# self.run = copy.deepcopy(run)
|
||||||
|
#
|
||||||
def __repr__(self):
|
# def __repr__(self):
|
||||||
return f"{self.__dict__}"
|
# return f"{self.__dict__}"
|
||||||
|
#
|
||||||
def _report_data(self, data=None):
|
# def _report_data(self, data=None):
|
||||||
default_data = {
|
# default_data = {
|
||||||
# "rule": self.config,
|
# # "rule": self.config,
|
||||||
"value": self.engine._plugin_value,
|
# "value": self.engine._plugin_value,
|
||||||
"data": self.data,
|
# "data": self.data,
|
||||||
}
|
# }
|
||||||
data = data or default_data
|
# data = data or default_data
|
||||||
d = json.dumps(data, indent=2) # , sort_keys=True, )
|
# data = json.dumps(data, indent=2) # , sort_keys=True, )
|
||||||
return d
|
# return data
|
||||||
|
|
||||||
|
|
||||||
# Generic Classes
|
# Generic Classes
|
||||||
# =============================
|
# =============================
|
||||||
class PluginClass:
|
class PluginClass:
|
||||||
|
"""Generic plugin class"""
|
||||||
|
|
||||||
_plugin_type = "none"
|
_plugin_type = "none"
|
||||||
_plugin_value = None
|
_plugin_value = None
|
||||||
|
|
||||||
@ -52,7 +46,6 @@ class PluginClass:
|
|||||||
_schema_props_plugin = {
|
_schema_props_plugin = {
|
||||||
"engine": {
|
"engine": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
# TODO: Fix this ug
|
|
||||||
"default": "jerakia",
|
"default": "jerakia",
|
||||||
},
|
},
|
||||||
"value": {},
|
"value": {},
|
||||||
@ -81,6 +74,8 @@ class PluginClass:
|
|||||||
|
|
||||||
|
|
||||||
class PluginBackendClass(PluginClass):
|
class PluginBackendClass(PluginClass):
|
||||||
|
"""Backend plugin class"""
|
||||||
|
|
||||||
_plugin_type = "backend"
|
_plugin_type = "backend"
|
||||||
|
|
||||||
def _init(self):
|
def _init(self):
|
||||||
@ -88,6 +83,8 @@ class PluginBackendClass(PluginClass):
|
|||||||
|
|
||||||
|
|
||||||
class PluginStrategyClass(PluginClass):
|
class PluginStrategyClass(PluginClass):
|
||||||
|
"""Strategy plugin class"""
|
||||||
|
|
||||||
_plugin_type = "strategy"
|
_plugin_type = "strategy"
|
||||||
|
|
||||||
def _init(self):
|
def _init(self):
|
||||||
@ -95,6 +92,8 @@ class PluginStrategyClass(PluginClass):
|
|||||||
|
|
||||||
|
|
||||||
class PluginEngineClass(PluginClass):
|
class PluginEngineClass(PluginClass):
|
||||||
|
"""Engine plugin class"""
|
||||||
|
|
||||||
_plugin_type = "engine"
|
_plugin_type = "engine"
|
||||||
|
|
||||||
_schema_props_default = {
|
_schema_props_default = {
|
||||||
@ -132,20 +131,22 @@ class PluginEngineClass(PluginClass):
|
|||||||
|
|
||||||
# Public Methods
|
# Public Methods
|
||||||
# =====================
|
# =====================
|
||||||
def dump(self):
|
def dump(self) -> dict:
|
||||||
|
"""Dump plugin configuration"""
|
||||||
|
|
||||||
ret = {
|
ret = {
|
||||||
"config": self.config,
|
"config": self.config,
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def lookup_candidates(self, key=None, scope=None):
|
def lookup_candidates(self, key=None, scope=None) -> list:
|
||||||
raise Exception(f"Module does not implement this method :(")
|
"""Placeholder to return candidates"""
|
||||||
|
raise Exception("Module does not implement this method :(")
|
||||||
# It must always return a list of `Candidate` instances
|
# It must always return a list of `Candidate` instances
|
||||||
return []
|
|
||||||
|
|
||||||
def _example(self):
|
# def _example(self):
|
||||||
print(f"Module does not implement this method :(")
|
# print(f"Module does not implement this method :(")
|
||||||
return None
|
# return None
|
||||||
|
|
||||||
|
|
||||||
# File plugins Extensions
|
# File plugins Extensions
|
||||||
@ -153,6 +154,7 @@ class PluginEngineClass(PluginClass):
|
|||||||
|
|
||||||
|
|
||||||
class PluginFileGlob:
|
class PluginFileGlob:
|
||||||
|
"""Provide glob functionnality"""
|
||||||
|
|
||||||
_schema_props_glob = {
|
_schema_props_glob = {
|
||||||
"glob": {
|
"glob": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user