feat: add presets
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
from collections import defaultdict
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from ..entry import Entry, EntryDetector
|
||||
from .util import PresetUtil
|
||||
|
||||
__all__ = ("PresetEntryDetector",)
|
||||
|
||||
|
||||
class PresetEntryDetector(EntryDetector):
|
||||
def __init__(self, filename: Path):
|
||||
self._preset = PresetUtil.resolve_preset(filename)
|
||||
|
||||
def detect_entry(self, basepath: Path) -> Optional["Entry"]:
|
||||
tasks = defaultdict(list)
|
||||
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)
|
||||
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 tasks:
|
||||
return Entry(tasks, basepath)
|
||||
Reference in New Issue
Block a user