1## base_action.py -*- mode: Py -*-
2# Imports:
3from __future__ import annotations
4
5# ##-- stdlib imports
6import datetime
7import enum
8import functools as ftz
9import itertools as itz
10import logging as logmod
11import pathlib as pl
12import re
13import time
14import types
15from typing import (TYPE_CHECKING, Any, Callable, ClassVar, Final, Generator,
16 Generic, Iterable, Iterator, Mapping, Match,
17 MutableMapping, Protocol, Sequence, Tuple, TypeAlias,
18 TypeGuard, TypeVar, cast, final, overload,
19 runtime_checkable)
20from uuid import UUID, uuid1
21
22# ##-- end stdlib imports
23
24# ##-- 3rd party imports
25from jgdv import Maybe, Proto
26
27# ##-- end 3rd party imports
28
29# ##-- 1st party imports
30import doot
31from .._interface import Action_p, ActionResponse_e
32from doot.errors import TaskError, TaskFailed
33
34# ##-- end 1st party imports
35
36from typing import override
37
38if TYPE_CHECKING:
39 from ..structs.action_spec import ActionSpec
40
41logging = logmod.getLogger(__name__)
42
[docs]
43@Proto(Action_p)
44class DootBaseAction:
45 """
46 The basic action, which just prints that the action was called
47 Subclass this and override __call__ for your own actions.
48 The arguments of the action are held in the passed in spec
49 __call__ is passed a *copy* of the task's state dictionary
50 """
51 ActRE = ActionResponse_e
52
53 @override
54 def __str__(self):
55 return "Base Action"
56
57 def __call__(self, spec:ActionSpec, state:dict) -> Maybe[dict|bool]:
58 logging.debug("Base Action Called: %s", state.get("count", 0))
59 doot.report.gen.detail("Base Action Called: %s", state.get("count", 0))
60 if spec.args:
61 doot.report.gen.user(" ".join(spec.args))
62 return { "count" : state.get("count", 0) + 1 }