116 lines
3.3 KiB
Python
116 lines
3.3 KiB
Python
|
|
|
|
import copy
|
|
# from pathlib import Path
|
|
# from albero.utils import render_template
|
|
# from albero.plugin.common import PluginBackendClass
|
|
# from pprint import pprint
|
|
#
|
|
# import logging
|
|
# import anyconfig
|
|
# import textwrap
|
|
|
|
from albero.plugin.common import PluginBackendClass
|
|
from pprint import pprint
|
|
import logging
|
|
log = logging.getLogger(__name__)
|
|
|
|
class Plugin(PluginBackendClass):
|
|
|
|
_plugin_name = "hier"
|
|
_schema_props_files = {
|
|
"path": {
|
|
"anyOf": [
|
|
{
|
|
"type": "string",
|
|
},
|
|
{
|
|
"type": "array",
|
|
"items": {
|
|
"type": "string",
|
|
}
|
|
},
|
|
]
|
|
}
|
|
}
|
|
|
|
sssss_schema_props_default = {
|
|
"$schema": 'http://json-schema.org/draft-04/schema#',
|
|
"default": "",
|
|
"oneOf": [
|
|
{
|
|
"type": "string",
|
|
"default": "BLAAAAHHH"
|
|
},
|
|
{
|
|
"type": "object",
|
|
"additionalProperties": True,
|
|
"default": {},
|
|
"properties": {
|
|
"engine": {
|
|
"type": "string",
|
|
"default": "jerakia",
|
|
"optional": False,
|
|
},
|
|
"value": {
|
|
"default": 'UNSET',
|
|
"optional": False,
|
|
},
|
|
},
|
|
},
|
|
]
|
|
}
|
|
|
|
|
|
def process(self, backends: list, ctx: dict) -> (list, dict):
|
|
|
|
new_backends = []
|
|
for cand in backends:
|
|
|
|
# Init
|
|
plugin_config = cand.get("hier", {})
|
|
hier_data = plugin_config.get("data", None)
|
|
if not hier_data:
|
|
new_backends.append(cand)
|
|
continue
|
|
|
|
# Retrieve config data
|
|
hier_var = plugin_config.get("var", "item")
|
|
hier_sep = plugin_config.get("separator", "/")
|
|
if isinstance(hier_data, str):
|
|
hier_data = cand['_run']['scope'].get(hier_data, None)
|
|
|
|
# Build a new list
|
|
|
|
if isinstance(hier_data, str):
|
|
r = hier_data.split(hier_sep)
|
|
assert (isinstance(r, list)), f"Got: {r}"
|
|
|
|
ret1 = []
|
|
for index, part in enumerate(r):
|
|
|
|
try:
|
|
prefix = ret1[index - 1]
|
|
except IndexError:
|
|
prefix = f'{hier_sep}'
|
|
prefix = ""
|
|
item = f"{prefix}{part}{hier_sep}"
|
|
ret1.append(item)
|
|
|
|
ret2 = []
|
|
for item in ret1:
|
|
_cand = copy.deepcopy(cand)
|
|
run = {
|
|
"index": index,
|
|
"hier_value": item,
|
|
"hier_var": hier_var,
|
|
}
|
|
_cand['_run']['hier'] = run
|
|
_cand['_run']['scope'][hier_var] = item
|
|
ret2.append(_cand)
|
|
|
|
new_backends.extend(ret2)
|
|
return new_backends, ctx
|
|
|
|
|