added naming to monitors, handlers and conductors so runners can identify them, in prep for in-workflow modification of patterns and recipes'
This commit is contained in:
@ -12,12 +12,18 @@ from typing import Union, Dict
|
||||
from meow_base.core.base_pattern import BasePattern
|
||||
from meow_base.core.base_recipe import BaseRecipe
|
||||
from meow_base.core.base_rule import BaseRule
|
||||
from meow_base.core.correctness.vars import VALID_CHANNELS, get_drt_imp_msg
|
||||
from meow_base.core.correctness.validation import check_implementation
|
||||
from meow_base.core.correctness.vars import VALID_CHANNELS, \
|
||||
VALID_MONITOR_NAME_CHARS, get_drt_imp_msg
|
||||
from meow_base.core.correctness.validation import check_implementation, \
|
||||
valid_string
|
||||
from meow_base.functionality.meow import create_rules
|
||||
from meow_base.functionality.naming import generate_monitor_id
|
||||
|
||||
|
||||
class BaseMonitor:
|
||||
# An identifier for a monitor within the runner. Can be manually set in
|
||||
# the constructor, or autogenerated if no name provided.
|
||||
name:str
|
||||
# A collection of patterns
|
||||
_patterns: Dict[str, BasePattern]
|
||||
# A collection of recipes
|
||||
@ -29,7 +35,7 @@ class BaseMonitor:
|
||||
# monitor is passed to it.
|
||||
to_runner: VALID_CHANNELS
|
||||
def __init__(self, patterns:Dict[str,BasePattern],
|
||||
recipes:Dict[str,BaseRecipe])->None:
|
||||
recipes:Dict[str,BaseRecipe], name:str="")->None:
|
||||
"""BaseMonitor Constructor. This will check that any class inheriting
|
||||
from it implements its validation functions. It will then call these on
|
||||
the input parameters."""
|
||||
@ -53,6 +59,10 @@ class BaseMonitor:
|
||||
self._patterns = deepcopy(patterns)
|
||||
self._recipes = deepcopy(recipes)
|
||||
self._rules = create_rules(patterns, recipes)
|
||||
if not name:
|
||||
name = generate_monitor_id()
|
||||
self._is_valid_name(name)
|
||||
self.name = name
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
"""A check that this base class is not instantiated itself, only
|
||||
@ -62,6 +72,12 @@ class BaseMonitor:
|
||||
raise TypeError(msg)
|
||||
return object.__new__(cls)
|
||||
|
||||
def _is_valid_name(self, name:str)->None:
|
||||
"""Validation check for 'name' variable from main constructor. Is
|
||||
automatically called during initialisation. This does not need to be
|
||||
overridden by child classes."""
|
||||
valid_string(name, VALID_MONITOR_NAME_CHARS)
|
||||
|
||||
def _is_valid_patterns(self, patterns:Dict[str,BasePattern])->None:
|
||||
"""Validation check for 'patterns' variable from main constructor. Must
|
||||
be implemented by any child class."""
|
||||
|
Reference in New Issue
Block a user