updated event dict to always include path, should be more future proof
This commit is contained in:
@ -3,7 +3,8 @@ from inspect import signature
|
||||
from os.path import sep, exists, isfile, isdir, dirname
|
||||
from typing import Any, _SpecialForm, Union, Tuple, get_origin, get_args
|
||||
|
||||
from core.correctness.vars import VALID_PATH_CHARS, get_not_imp_msg, EVENT_TYPE
|
||||
from core.correctness.vars import VALID_PATH_CHARS, get_not_imp_msg, \
|
||||
EVENT_TYPE, EVENT_PATH
|
||||
|
||||
def check_type(variable:Any, expected_type:type, alt_types:list[type]=[],
|
||||
or_none:bool=False)->None:
|
||||
@ -183,3 +184,5 @@ def valid_event(event)->None:
|
||||
check_type(event, dict)
|
||||
if not EVENT_TYPE in event.keys():
|
||||
raise KeyError(f"Events require key '{EVENT_TYPE}'")
|
||||
if not EVENT_PATH in event.keys():
|
||||
raise KeyError(f"Events require key '{EVENT_PATH}'")
|
||||
|
@ -189,8 +189,8 @@ APPENDING_NOTEBOOK = {
|
||||
|
||||
# meow events
|
||||
EVENT_TYPE = "meow_event_type"
|
||||
EVENT_PATH = "event_path"
|
||||
WATCHDOG_TYPE = "watchdog"
|
||||
WATCHDOG_SRC = "src_path"
|
||||
WATCHDOG_BASE = "monitor_base"
|
||||
WATCHDOG_RULE = "rule_name"
|
||||
|
||||
|
@ -16,7 +16,7 @@ from core.correctness.validation import check_type, valid_existing_file_path, \
|
||||
valid_path
|
||||
from core.correctness.vars import CHAR_LOWERCASE, CHAR_UPPERCASE, \
|
||||
VALID_CHANNELS, HASH_BUFFER_SIZE, SHA256, DEBUG_WARNING, DEBUG_INFO, \
|
||||
EVENT_TYPE
|
||||
EVENT_TYPE, EVENT_PATH
|
||||
|
||||
def generate_id(prefix:str="", length:int=16, existing_ids:list[str]=[],
|
||||
charset:str=CHAR_UPPERCASE+CHAR_LOWERCASE, attempts:int=24):
|
||||
@ -241,6 +241,6 @@ def print_debug(print_target, debug_level, msg, level)->None:
|
||||
status = "WARNING"
|
||||
print(f"{status}: {msg}", file=print_target)
|
||||
|
||||
def create_event(event_type:str, source:dict[Any,Any]={})->dict[Any,Any]:
|
||||
return {**source, EVENT_TYPE: event_type}
|
||||
def create_event(event_type:str, path:str, source:dict[Any,Any]={})->dict[Any,Any]:
|
||||
return {**source, EVENT_PATH: path, EVENT_TYPE: event_type}
|
||||
|
||||
|
Reference in New Issue
Block a user