feat: update presets

This commit is contained in:
2023-03-19 21:21:48 +03:00
parent 8b718fda79
commit 81bf685fec
6 changed files with 150 additions and 59 deletions
+14 -5
View File
@@ -4,6 +4,7 @@ from typing import Optional
from ..entry import Entry, EntryDetector
from .util import PresetUtil
from .value import ValueResolver
__all__ = ("PresetEntryDetector",)
@@ -17,12 +18,20 @@ class PresetEntryDetector(EntryDetector):
for preset_name, preset in self._preset.presets.items():
filename = basepath / preset.filename
if filename.exists():
loader = PresetUtil.resolve_loader(preset.loader)
with open(filename, "rb") as fd:
data = loader(fd)
value_resolver = ValueResolver(basepath)
for task_name, task_pack in preset.tasks.items():
for task_item_name, task in task_pack.items():
if PresetUtil.check_conditions(data, task.conditions):
tasks[task_name] += task.commands
if value_resolver.check_conditions(task.conditions):
variables = (
{
k: value_resolver.resolve_value(v)
for k, v in task.variables.items()
}
if task.variables
else {}
)
tasks[task_name] += [
command.format(**variables) for command in task.commands
]
if tasks:
return Entry(tasks, basepath)