From 49d802e223412ec2f788ed2be7a493773e85f3a6 Mon Sep 17 00:00:00 2001 From: carvilsi Date: Mon, 6 Jul 2026 18:05:44 +0200 Subject: [PATCH 01/10] :art: changing imports wip --- caetra.py | 17 ++++++++++------- src/__init__.py | 0 src/shields/__init__.py | 0 src/shields/deploying.py | 13 +++++++------ src/shields/usb/__init__.py | 0 src/shields/usb/usb.py | 18 ++++++++++-------- src/shields/usb/usb.toml | 2 +- src/utils/__init__.py | 0 src/utils/config_parser.py | 3 ++- src/utils/dict_handler.py | 3 +-- src/utils/logging_handler.py | 2 +- 11 files changed, 32 insertions(+), 26 deletions(-) create mode 100644 src/__init__.py create mode 100644 src/shields/__init__.py create mode 100644 src/shields/usb/__init__.py create mode 100644 src/utils/__init__.py diff --git a/caetra.py b/caetra.py index 2ce3a3b..b008ca5 100755 --- a/caetra.py +++ b/caetra.py @@ -5,16 +5,19 @@ import os import sys -sys.path.append(os.path.join(os.path.dirname(__file__), "./src/utils/")) -sys.path.append(os.path.join(os.path.dirname(__file__), "./src/")) - -from logger_setup import logger -from config_parser import config -import constants +from src.utils.logger_setup import logger +from src.utils.config_parser import config +import src.constants as constants def run_script(script_name): - subprocess.run(["python3", script_name]) + print(script_name[2:-3]) + module = ( + script_name[2:-3].replace(os.sep, ".") + ) + print(module) + + subprocess.run(["python3", "-m", module]) # Threading execute all the shields under shield directory diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/shields/__init__.py b/src/shields/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/shields/deploying.py b/src/shields/deploying.py index 8d21ae4..56bf93a 100644 --- a/src/shields/deploying.py +++ b/src/shields/deploying.py @@ -1,14 +1,15 @@ from bcc import BPF -from logger_setup import logger import tomllib import os import sys -sys.path.append(os.path.join(os.path.dirname(__file__), "../../utils")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../..")) -import constants -from caetra_exceptions import ShieldConfigurationError -from dict_handler import validate_dict_structure +from src.utils.logger_setup import logger + +# sys.path.append(os.path.join(os.path.dirname(__file__), "../../utils")) +# sys.path.append(os.path.join(os.path.dirname(__file__), "../..")) +import src.constants +from src.caetra_exceptions import ShieldConfigurationError +from src.utils.dict_handler import validate_dict_structure # returns a BPF program loaded and attached to kernel diff --git a/src/shields/usb/__init__.py b/src/shields/usb/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/shields/usb/usb.py b/src/shields/usb/usb.py index ed98e5d..23f93b2 100755 --- a/src/shields/usb/usb.py +++ b/src/shields/usb/usb.py @@ -3,14 +3,16 @@ import os # caetra imports -sys.path.append(os.path.join(os.path.dirname(__file__), "../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../utils")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../senders")) -from shields import deploying -from logger_setup import logger_shields -from caetra_exceptions import ShieldConfigurationError, ConfigurationError -from logging_handler import log_shield_exception +# sys.path.append(os.path.join(os.path.dirname(__file__), "../..")) +# sys.path.append(os.path.join(os.path.dirname(__file__), "../../..")) +# sys.path.append(os.path.join(os.path.dirname(__file__), "../../utils")) +# sys.path.append(os.path.join(os.path.dirname(__file__), "../../senders")) + +from src.shields import deploying +# import deploying +from src.utils.logger_setup import logger_shields +from src.caetra_exceptions import ShieldConfigurationError, ConfigurationError +from src.utils.logging_handler import log_shield_exception from senders_handler import send import constants diff --git a/src/shields/usb/usb.toml b/src/shields/usb/usb.toml index 123e9ec..d3e6123 100644 --- a/src/shields/usb/usb.toml +++ b/src/shields/usb/usb.toml @@ -7,7 +7,7 @@ [usb] # if this shield is enable (if false will override the main config) -enable = true +#enable = true # a description that will logged description = "When a USB device is attached will send notification as it's configured on 'senders'. Also possible to de-authorize the attached USB device if 'de_authorize_dev' is set to true" diff --git a/src/utils/__init__.py b/src/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/utils/config_parser.py b/src/utils/config_parser.py index 4d31ef7..2c56d60 100644 --- a/src/utils/config_parser.py +++ b/src/utils/config_parser.py @@ -1,5 +1,6 @@ import tomllib # TODO: Add a config checker for mandatory variables -f = open("./config/develop.toml", "rb") +f = open("./config/local.toml", "rb") +# f = open("./config/develop.toml", "rb") config = tomllib.load(f) diff --git a/src/utils/dict_handler.py b/src/utils/dict_handler.py index 01c7b0b..f014ad3 100644 --- a/src/utils/dict_handler.py +++ b/src/utils/dict_handler.py @@ -2,8 +2,7 @@ import os # caetra imports -sys.path.append(os.path.join(os.path.dirname(__file__), "../..")) -from caetra_exceptions import ConfigurationError +from src.caetra_exceptions import ConfigurationError def validate_dict_structure(expected_structure, data, structure_name): diff --git a/src/utils/logging_handler.py b/src/utils/logging_handler.py index 8d99454..a02c2c0 100644 --- a/src/utils/logging_handler.py +++ b/src/utils/logging_handler.py @@ -1,4 +1,4 @@ -from logger_setup import logger_shields, logger +from src.utils.logger_setup import logger_shields, logger def log_shield_exception(e, shield_name): From 0e12bfbc7fdaa6500d975b7e7261cd5d8e836d28 Mon Sep 17 00:00:00 2001 From: carvilsi Date: Tue, 7 Jul 2026 18:25:14 +0200 Subject: [PATCH 02/10] :art: changing imports wip --- caetra.py | 2 -- src/senders/__init__.py | 0 src/senders/send_canary_dns_token.py | 4 +--- src/senders/send_telegram_message_to_chat.py | 3 +-- src/senders/senders_handler.py | 16 +++++++--------- src/shields/ambient_light/__init__.py | 0 src/shields/blt_connect/__init__.py | 0 src/shields/blt_disconnect/__init__.py | 0 src/shields/cd_dvd_rom/__init__.py | 0 src/shields/deploying.py | 5 +---- src/shields/hibernation/__init__.py | 0 src/shields/hid_add_remove/__init__.py | 0 src/shields/hid_interact/__init__.py | 0 src/shields/inet/__init__.py | 0 src/shields/input_event/__init__.py | 0 src/shields/mmc/__init__.py | 0 src/shields/power/__init__.py | 0 src/shields/status_handler.py | 4 +--- src/shields/usb/usb.py | 10 ++-------- src/shields/usb/usb.toml | 2 +- src/shields/webcam/__init__.py | 0 21 files changed, 14 insertions(+), 32 deletions(-) create mode 100644 src/senders/__init__.py create mode 100644 src/shields/ambient_light/__init__.py create mode 100644 src/shields/blt_connect/__init__.py create mode 100644 src/shields/blt_disconnect/__init__.py create mode 100644 src/shields/cd_dvd_rom/__init__.py create mode 100644 src/shields/hibernation/__init__.py create mode 100644 src/shields/hid_add_remove/__init__.py create mode 100644 src/shields/hid_interact/__init__.py create mode 100644 src/shields/inet/__init__.py create mode 100644 src/shields/input_event/__init__.py create mode 100644 src/shields/mmc/__init__.py create mode 100644 src/shields/power/__init__.py create mode 100644 src/shields/webcam/__init__.py diff --git a/caetra.py b/caetra.py index b008ca5..4b08367 100755 --- a/caetra.py +++ b/caetra.py @@ -11,11 +11,9 @@ def run_script(script_name): - print(script_name[2:-3]) module = ( script_name[2:-3].replace(os.sep, ".") ) - print(module) subprocess.run(["python3", "-m", module]) diff --git a/src/senders/__init__.py b/src/senders/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/senders/send_canary_dns_token.py b/src/senders/send_canary_dns_token.py index 359c6eb..62872dd 100644 --- a/src/senders/send_canary_dns_token.py +++ b/src/senders/send_canary_dns_token.py @@ -4,9 +4,7 @@ import os import sys -sys.path.append(os.path.join(os.path.dirname(__file__), "../../utils/")) - -from logger_setup import logger +from src.utils.logger_setup import logger DOT = "." MAGIC_STRING = "G69" diff --git a/src/senders/send_telegram_message_to_chat.py b/src/senders/send_telegram_message_to_chat.py index d430758..3aee7aa 100644 --- a/src/senders/send_telegram_message_to_chat.py +++ b/src/senders/send_telegram_message_to_chat.py @@ -3,8 +3,7 @@ import sys import os -sys.path.append(os.path.join(os.path.dirname(__file__), "../../utils")) -from logger_setup import logger +from src.utils.logger_setup import logger HEADERS = {"Content-Type": "application/json"} diff --git a/src/senders/senders_handler.py b/src/senders/senders_handler.py index f3eef51..e48db6d 100644 --- a/src/senders/senders_handler.py +++ b/src/senders/senders_handler.py @@ -1,15 +1,13 @@ import sys import os -sys.path.append(os.path.join(os.path.dirname(__file__), "../../utils")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../..")) -import constants -from config_parser import config -from logger_setup import logger -from caetra_exceptions import ConfigurationError -from dict_handler import validate_dict_structure -from send_canary_dns_token import send_canary -from send_telegram_message_to_chat import send_telegram +import src.constants as constants +from src.utils.config_parser import config +from src.utils.logger_setup import logger +from src.caetra_exceptions import ConfigurationError +from src.utils.dict_handler import validate_dict_structure +from src.senders.send_canary_dns_token import send_canary +from src.senders.send_telegram_message_to_chat import send_telegram def check_send_config(senders_config): diff --git a/src/shields/ambient_light/__init__.py b/src/shields/ambient_light/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/shields/blt_connect/__init__.py b/src/shields/blt_connect/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/shields/blt_disconnect/__init__.py b/src/shields/blt_disconnect/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/shields/cd_dvd_rom/__init__.py b/src/shields/cd_dvd_rom/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/shields/deploying.py b/src/shields/deploying.py index 56bf93a..04a5073 100644 --- a/src/shields/deploying.py +++ b/src/shields/deploying.py @@ -4,10 +4,7 @@ import sys from src.utils.logger_setup import logger - -# sys.path.append(os.path.join(os.path.dirname(__file__), "../../utils")) -# sys.path.append(os.path.join(os.path.dirname(__file__), "../..")) -import src.constants +import src.constants as constants from src.caetra_exceptions import ShieldConfigurationError from src.utils.dict_handler import validate_dict_structure diff --git a/src/shields/hibernation/__init__.py b/src/shields/hibernation/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/shields/hid_add_remove/__init__.py b/src/shields/hid_add_remove/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/shields/hid_interact/__init__.py b/src/shields/hid_interact/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/shields/inet/__init__.py b/src/shields/inet/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/shields/input_event/__init__.py b/src/shields/input_event/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/shields/mmc/__init__.py b/src/shields/mmc/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/shields/power/__init__.py b/src/shields/power/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/shields/status_handler.py b/src/shields/status_handler.py index a89f5d0..540801e 100644 --- a/src/shields/status_handler.py +++ b/src/shields/status_handler.py @@ -4,9 +4,7 @@ import requests # caetra imports -sys.path.append(os.path.join(os.path.dirname(__file__), "../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../")) -import constants +import src.constants as constants from caetra_exceptions import MaxActionReached, MaxRetriesReached diff --git a/src/shields/usb/usb.py b/src/shields/usb/usb.py index 23f93b2..84a90f2 100755 --- a/src/shields/usb/usb.py +++ b/src/shields/usb/usb.py @@ -3,18 +3,12 @@ import os # caetra imports -# sys.path.append(os.path.join(os.path.dirname(__file__), "../..")) -# sys.path.append(os.path.join(os.path.dirname(__file__), "../../..")) -# sys.path.append(os.path.join(os.path.dirname(__file__), "../../utils")) -# sys.path.append(os.path.join(os.path.dirname(__file__), "../../senders")) - from src.shields import deploying -# import deploying from src.utils.logger_setup import logger_shields from src.caetra_exceptions import ShieldConfigurationError, ConfigurationError from src.utils.logging_handler import log_shield_exception -from senders_handler import send -import constants +from src.senders.senders_handler import send +import src.constants as constants # shield name # must be same with in toml root config diff --git a/src/shields/usb/usb.toml b/src/shields/usb/usb.toml index d3e6123..123e9ec 100644 --- a/src/shields/usb/usb.toml +++ b/src/shields/usb/usb.toml @@ -7,7 +7,7 @@ [usb] # if this shield is enable (if false will override the main config) -#enable = true +enable = true # a description that will logged description = "When a USB device is attached will send notification as it's configured on 'senders'. Also possible to de-authorize the attached USB device if 'de_authorize_dev' is set to true" diff --git a/src/shields/webcam/__init__.py b/src/shields/webcam/__init__.py new file mode 100644 index 0000000..e69de29 From 9b05b8a09bb3c1ce8f3362dbfea0c63b7978c3f9 Mon Sep 17 00:00:00 2001 From: carvilsi Date: Wed, 8 Jul 2026 17:41:59 +0200 Subject: [PATCH 03/10] :art: module way wip --- src/shields/hid_add_remove/hid_add_remove.py | 25 +++++++------------- src/shields/status_handler.py | 2 +- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/shields/hid_add_remove/hid_add_remove.py b/src/shields/hid_add_remove/hid_add_remove.py index a2498a9..15fc032 100644 --- a/src/shields/hid_add_remove/hid_add_remove.py +++ b/src/shields/hid_add_remove/hid_add_remove.py @@ -3,23 +3,14 @@ import os # caetra imports -sys.path.append(os.path.join(os.path.dirname(__file__), "../")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../utils")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../senders")) -from shields import deploying -from logger_setup import logger_shields -from caetra_exceptions import ( - ShieldConfigurationError, - ConfigurationError, - MaxActionReached, - ShieldKernelSpaceCError, -) -from logging_handler import log_shield_exception, log_shield_exception_warn -from senders_handler import send -import constants -import status_handler +from src.shields import deploying +from src.utils.logger_setup import logger_shields +from src.caetra_exceptions import ShieldConfigurationError, ConfigurationError +from src.utils.logging_handler import log_shield_exception +from src.senders.senders_handler import send +import src.constants as constants +from src.shields import status_handler + # from linux/hid.h HID_TYPE = { diff --git a/src/shields/status_handler.py b/src/shields/status_handler.py index 540801e..298fd38 100644 --- a/src/shields/status_handler.py +++ b/src/shields/status_handler.py @@ -5,7 +5,7 @@ # caetra imports import src.constants as constants -from caetra_exceptions import MaxActionReached, MaxRetriesReached +from src.caetra_exceptions import MaxActionReached, MaxRetriesReached class StatusHandler(object): From a3c13b9969b29925d398147f95cfecca8705dc60 Mon Sep 17 00:00:00 2001 From: carvilsi Date: Wed, 8 Jul 2026 17:52:42 +0200 Subject: [PATCH 04/10] :art: imports from common for shields --- src/shields/shields_common.py | 31 +++++++++++++++++++++++++++++++ src/shields/usb/usb.py | 22 +++++++++++----------- 2 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 src/shields/shields_common.py diff --git a/src/shields/shields_common.py b/src/shields/shields_common.py new file mode 100644 index 0000000..f1d9c51 --- /dev/null +++ b/src/shields/shields_common.py @@ -0,0 +1,31 @@ +""" +Common imports shared by shield scripts. +""" + +# Generic imports +import os +import sys + +# Caetra imports +import src.constants as constants +from src.caetra_exceptions import ( + ConfigurationError, + ShieldConfigurationError, +) +from src.senders.senders_handler import send +from src.shields import deploying, status_handler +from src.utils.logger_setup import logger_shields +from src.utils.logging_handler import log_shield_exception + +__all__ = [ + "os", + "sys", + "constants", + "deploying", + "status_handler", + "logger_shields", + "ShieldConfigurationError", + "ConfigurationError", + "log_shield_exception", + "send", +] diff --git a/src/shields/usb/usb.py b/src/shields/usb/usb.py index 84a90f2..96ed2ea 100755 --- a/src/shields/usb/usb.py +++ b/src/shields/usb/usb.py @@ -1,14 +1,14 @@ -# generic imports -import sys -import os - -# caetra imports -from src.shields import deploying -from src.utils.logger_setup import logger_shields -from src.caetra_exceptions import ShieldConfigurationError, ConfigurationError -from src.utils.logging_handler import log_shield_exception -from src.senders.senders_handler import send -import src.constants as constants +from src.shields.shields_common import ( + constants, + deploying, + logger_shields, + ShieldConfigurationError, + ConfigurationError, + log_shield_exception, + send, + os, + sys, +) # shield name # must be same with in toml root config From c79882becc7565c1713705ce8d7cdfde58422065 Mon Sep 17 00:00:00 2001 From: carvilsi Date: Wed, 8 Jul 2026 19:25:50 +0200 Subject: [PATCH 05/10] :art: added common import module to all shields and updated generation shield tool --- caetra.py | 1 + src/constants.py | 1 + src/shields/ambient_light/ambient_light.py | 22 +--------------- src/shields/blt_connect/blt_connect.py | 17 +------------ src/shields/blt_disconnect/blt_disconnect.py | 17 +------------ src/shields/cd_dvd_rom/cd_dvd_rom.py | 22 +--------------- src/shields/hibernation/hibernation.py | 22 +--------------- src/shields/hibernation/hibernation.toml | 2 +- src/shields/hid_add_remove/hid_add_remove.py | 14 +---------- src/shields/hid_interact/hid_interact.py | 22 +--------------- src/shields/inet/inet.py | 25 +------------------ src/shields/input_event/input_event.py | 22 +--------------- src/shields/mmc/mmc.py | 16 +----------- src/shields/power/power.py | 16 +----------- src/shields/shields_common.py | 16 +++++++++++- src/shields/usb/usb.py | 12 +-------- src/shields/webcam/webcam.py | 18 +------------ .../templates/ctr_bpf_py.jinja | 17 +------------ 18 files changed, 32 insertions(+), 250 deletions(-) diff --git a/caetra.py b/caetra.py index 4b08367..aa2419b 100755 --- a/caetra.py +++ b/caetra.py @@ -28,6 +28,7 @@ def threading_excute_shields(): file.endswith(".py") and file != constants.SHIELD_DEPLOYING_SCRIPT and file != constants.SHIELD_STATUS_HANDLER_SCRIPT + and file != constants.PYTHON_MODULE_INIT ): shieldname = os.path.splitext(file)[0] if config["caetra"].get("shields_enabled") is not None: diff --git a/src/constants.py b/src/constants.py index 98a7dae..3fa2435 100644 --- a/src/constants.py +++ b/src/constants.py @@ -1,6 +1,7 @@ SHIELD_PATH = "./src/shields/" SHIELD_DEPLOYING_SCRIPT = "deploying.py" SHIELD_STATUS_HANDLER_SCRIPT = "status_handler.py" +PYTHON_MODULE_INIT = "__init__.py" SHIELD_CONFIG_EXT = ".toml" CAETRA_SENDER_LABEL = "Shield" diff --git a/src/shields/ambient_light/ambient_light.py b/src/shields/ambient_light/ambient_light.py index d3bc2f9..7ed8347 100644 --- a/src/shields/ambient_light/ambient_light.py +++ b/src/shields/ambient_light/ambient_light.py @@ -1,24 +1,4 @@ -# generic imports -import sys -import os - -# caetra imports -sys.path.append(os.path.join(os.path.dirname(__file__), "../")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../utils")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../senders")) -from shields import deploying -from logger_setup import logger_shields -from caetra_exceptions import ( - ShieldConfigurationError, - ConfigurationError, - MaxActionReached, -) -from logging_handler import log_shield_exception, log_shield_exception_warn -from senders_handler import send -import constants -import status_handler +from src.shields.shields_common import * # shield name # must be same with in toml root config diff --git a/src/shields/blt_connect/blt_connect.py b/src/shields/blt_connect/blt_connect.py index 51be7b4..8e121d0 100644 --- a/src/shields/blt_connect/blt_connect.py +++ b/src/shields/blt_connect/blt_connect.py @@ -1,19 +1,4 @@ -# generic imports -import sys -import os - -# caetra imports -sys.path.append(os.path.join(os.path.dirname(__file__), "../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../utils")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../senders")) -from shields import deploying -from logger_setup import logger_shields -from caetra_exceptions import ShieldConfigurationError, ConfigurationError -from logging_handler import log_shield_exception -from senders_handler import send -from format_utils import mac_address_format -import constants +from src.shields.shields_common import * # shield name # must be same with in toml root config diff --git a/src/shields/blt_disconnect/blt_disconnect.py b/src/shields/blt_disconnect/blt_disconnect.py index ab86427..1e8dbc0 100644 --- a/src/shields/blt_disconnect/blt_disconnect.py +++ b/src/shields/blt_disconnect/blt_disconnect.py @@ -1,19 +1,4 @@ -# generic imports -import sys -import os - -# caetra imports -sys.path.append(os.path.join(os.path.dirname(__file__), "../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../utils")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../senders")) -from shields import deploying -from logger_setup import logger_shields -from caetra_exceptions import ShieldConfigurationError, ConfigurationError -from logging_handler import log_shield_exception -from senders_handler import send -from format_utils import mac_address_format -import constants +from src.shields.shields_common import * # shield name # must be same with in toml root config diff --git a/src/shields/cd_dvd_rom/cd_dvd_rom.py b/src/shields/cd_dvd_rom/cd_dvd_rom.py index 2acfaeb..ff62674 100644 --- a/src/shields/cd_dvd_rom/cd_dvd_rom.py +++ b/src/shields/cd_dvd_rom/cd_dvd_rom.py @@ -1,24 +1,4 @@ -# generic imports -import sys -import os - -# caetra imports -sys.path.append(os.path.join(os.path.dirname(__file__), "../")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../utils")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../senders")) -from shields import deploying -from logger_setup import logger_shields -from caetra_exceptions import ( - ShieldConfigurationError, - ConfigurationError, - MaxActionReached, -) -from logging_handler import log_shield_exception, log_shield_exception_warn -from senders_handler import send -import constants -import status_handler +from src.shields.shields_common import * # shield name # must be same with in toml root config diff --git a/src/shields/hibernation/hibernation.py b/src/shields/hibernation/hibernation.py index 15ef2db..4ebaada 100644 --- a/src/shields/hibernation/hibernation.py +++ b/src/shields/hibernation/hibernation.py @@ -1,24 +1,4 @@ -# generic imports -import sys -import os - -# caetra imports -sys.path.append(os.path.join(os.path.dirname(__file__), "../")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../utils")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../senders")) -from shields import deploying -from logger_setup import logger_shields -from caetra_exceptions import ( - ShieldConfigurationError, - ConfigurationError, - MaxRetriesReached, -) -from logging_handler import log_shield_exception -from senders_handler import send -import constants -import status_handler +from src.shields.shields_common import * # shield name # must be same with in toml root config diff --git a/src/shields/hibernation/hibernation.toml b/src/shields/hibernation/hibernation.toml index 5da888a..4eb9fe9 100644 --- a/src/shields/hibernation/hibernation.toml +++ b/src/shields/hibernation/hibernation.toml @@ -8,7 +8,7 @@ # if this shield is enable # TODO: this is giving false positive -enable = false +enable = true # a description that will logged diff --git a/src/shields/hid_add_remove/hid_add_remove.py b/src/shields/hid_add_remove/hid_add_remove.py index 15fc032..3383114 100644 --- a/src/shields/hid_add_remove/hid_add_remove.py +++ b/src/shields/hid_add_remove/hid_add_remove.py @@ -1,16 +1,4 @@ -# generic imports -import sys -import os - -# caetra imports -from src.shields import deploying -from src.utils.logger_setup import logger_shields -from src.caetra_exceptions import ShieldConfigurationError, ConfigurationError -from src.utils.logging_handler import log_shield_exception -from src.senders.senders_handler import send -import src.constants as constants -from src.shields import status_handler - +from src.shields.shields_common import * # from linux/hid.h HID_TYPE = { diff --git a/src/shields/hid_interact/hid_interact.py b/src/shields/hid_interact/hid_interact.py index ed5dbc7..49cbb93 100644 --- a/src/shields/hid_interact/hid_interact.py +++ b/src/shields/hid_interact/hid_interact.py @@ -1,24 +1,4 @@ -# generic imports -import sys -import os - -# caetra imports -sys.path.append(os.path.join(os.path.dirname(__file__), "../")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../utils")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../senders")) -from shields import deploying -from logger_setup import logger_shields -from caetra_exceptions import ( - ShieldConfigurationError, - ConfigurationError, - MaxActionReached, -) -from logging_handler import log_shield_exception, log_shield_exception_warn -from senders_handler import send -import constants -import status_handler +from src.shields.shields_common import * # from linux/hid.h HID_TYPE = { diff --git a/src/shields/inet/inet.py b/src/shields/inet/inet.py index f88a9ff..7cba34a 100644 --- a/src/shields/inet/inet.py +++ b/src/shields/inet/inet.py @@ -1,27 +1,4 @@ -# generic imports -import sys -import os - -# caetra imports -sys.path.append(os.path.join(os.path.dirname(__file__), "../")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../utils")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../senders")) -from shields import deploying -from logger_setup import logger_shields -from caetra_exceptions import ( - ShieldConfigurationError, - ConfigurationError, - MaxActionReached, - MaxRetriesReached, - NoInternetConnection, -) -from logging_handler import log_shield_exception, log_shield_exception_warn -from senders_handler import send -from format_utils import mac_address_format -import constants -import status_handler +from src.shields.shields_common import * # from linux/netdevice.h # only interesting events diff --git a/src/shields/input_event/input_event.py b/src/shields/input_event/input_event.py index 756c7a8..1f381e7 100644 --- a/src/shields/input_event/input_event.py +++ b/src/shields/input_event/input_event.py @@ -1,24 +1,4 @@ -# generic imports -import sys -import os - -# caetra imports -sys.path.append(os.path.join(os.path.dirname(__file__), "../")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../utils")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../senders")) -from shields import deploying -from logger_setup import logger_shields -from caetra_exceptions import ( - ShieldConfigurationError, - ConfigurationError, - MaxActionReached, -) -from logging_handler import log_shield_exception, log_shield_exception_warn -from senders_handler import send -import constants -import status_handler +from src.shields.shields_common import * # shield name # must be same with in toml root config diff --git a/src/shields/mmc/mmc.py b/src/shields/mmc/mmc.py index a771585..2fa3ded 100755 --- a/src/shields/mmc/mmc.py +++ b/src/shields/mmc/mmc.py @@ -1,18 +1,4 @@ -# generic imports -import sys -import os - -# caetra imports -sys.path.append(os.path.join(os.path.dirname(__file__), "../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../utils")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../senders")) -from shields import deploying -from logger_setup import logger_shields -from caetra_exceptions import ShieldConfigurationError, ConfigurationError -from logging_handler import log_shield_exception -from senders_handler import send -import constants +from src.shields.shields_common import * # from linux/mmc/card.h # definition fo Multi Media Cards diff --git a/src/shields/power/power.py b/src/shields/power/power.py index d66090e..a709230 100644 --- a/src/shields/power/power.py +++ b/src/shields/power/power.py @@ -1,18 +1,4 @@ -# generic imports -import sys -import os - -# caetra imports -sys.path.append(os.path.join(os.path.dirname(__file__), "../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../utils")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../senders")) -from shields import deploying -from logger_setup import logger_shields -from caetra_exceptions import ShieldConfigurationError, ConfigurationError -from logging_handler import log_shield_exception -from senders_handler import send -import constants +from src.shields.shields_common import * # from linux/power_supply.h POWER_SUPPLY_TYPE = { diff --git a/src/shields/shields_common.py b/src/shields/shields_common.py index f1d9c51..c49f0af 100644 --- a/src/shields/shields_common.py +++ b/src/shields/shields_common.py @@ -11,11 +11,19 @@ from src.caetra_exceptions import ( ConfigurationError, ShieldConfigurationError, + MaxActionReached, + MaxRetriesReached, + NoInternetConnection, + ShieldKernelSpaceCError, ) from src.senders.senders_handler import send from src.shields import deploying, status_handler from src.utils.logger_setup import logger_shields -from src.utils.logging_handler import log_shield_exception +from src.utils.logging_handler import ( + log_shield_exception, + log_shield_exception_warn, +) +from src.utils.format_utils import mac_address_format __all__ = [ "os", @@ -28,4 +36,10 @@ "ConfigurationError", "log_shield_exception", "send", + "MaxActionReached", + "MaxRetriesReached", + "log_shield_exception_warn", + "NoInternetConnection", + "ShieldKernelSpaceCError", + "mac_address_format", ] diff --git a/src/shields/usb/usb.py b/src/shields/usb/usb.py index 96ed2ea..7f903f1 100755 --- a/src/shields/usb/usb.py +++ b/src/shields/usb/usb.py @@ -1,14 +1,4 @@ -from src.shields.shields_common import ( - constants, - deploying, - logger_shields, - ShieldConfigurationError, - ConfigurationError, - log_shield_exception, - send, - os, - sys, -) +from src.shields.shields_common import * # shield name # must be same with in toml root config diff --git a/src/shields/webcam/webcam.py b/src/shields/webcam/webcam.py index 5f14e8f..ca4db90 100644 --- a/src/shields/webcam/webcam.py +++ b/src/shields/webcam/webcam.py @@ -1,20 +1,4 @@ -# generic imports -import sys -import os - -# caetra imports -sys.path.append(os.path.join(os.path.dirname(__file__), "../")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../utils")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../senders")) -from shields import deploying -from logger_setup import logger_shields -from caetra_exceptions import ShieldConfigurationError, ConfigurationError, MaxActionReached -from logging_handler import log_shield_exception, log_shield_exception_warn -from senders_handler import send -import constants -import status_handler +from src.shields.shields_common import * # shield name # must be same with in toml root config diff --git a/tools/caetra_shield_generator/templates/ctr_bpf_py.jinja b/tools/caetra_shield_generator/templates/ctr_bpf_py.jinja index 2a52d2d..5c10560 100644 --- a/tools/caetra_shield_generator/templates/ctr_bpf_py.jinja +++ b/tools/caetra_shield_generator/templates/ctr_bpf_py.jinja @@ -1,19 +1,4 @@ -# generic imports -import sys -import os - -# caetra imports -sys.path.append(os.path.join(os.path.dirname(__file__), "../")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../..")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../utils")) -sys.path.append(os.path.join(os.path.dirname(__file__), "../../senders")) -from shields import deploying -from logger_setup import logger_shields -from caetra_exceptions import ShieldConfigurationError, ConfigurationError -from logging_handler import log_shield_exception, log_shield_exception_warn -from senders_handler import send -import constants +from src.shields.shields_common import * # shield name # must be same with in toml root config From e261710c9592b2db81f1ba5b4b59b91b34d50599 Mon Sep 17 00:00:00 2001 From: carvilsi Date: Wed, 8 Jul 2026 19:31:56 +0200 Subject: [PATCH 06/10] :memo: updating CHANGELOG --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1f7efb..888dd92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ - Adds name of HID for hid_interact shield +# [v1.2.1](https://github.com/carvilsi/caetra/releases/tag/v1.2.1) (2026-07-08) + +- Refactor to import as a module + + # [v1.2.0](https://github.com/carvilsi/caetra/releases/tag/v1.2.0) (2026-03-18) - Added WebCam shield From 9be8d5e4f3208c82f0651f8a5a1f0b1083cdbf48 Mon Sep 17 00:00:00 2001 From: carvilsi Date: Wed, 8 Jul 2026 20:08:15 +0200 Subject: [PATCH 07/10] :art: format the code --- caetra.py | 5 +---- src/senders/send_canary_dns_token.py | 2 -- src/senders/send_telegram_message_to_chat.py | 2 -- src/senders/senders_handler.py | 2 -- src/shields/deploying.py | 1 - src/shields/shields_common.py | 6 +++--- src/shields/status_handler.py | 2 -- src/shields/webcam/webcam.py | 19 +++++++++++-------- src/utils/dict_handler.py | 2 -- 9 files changed, 15 insertions(+), 26 deletions(-) diff --git a/caetra.py b/caetra.py index aa2419b..e61bff9 100755 --- a/caetra.py +++ b/caetra.py @@ -3,7 +3,6 @@ import threading import subprocess import os -import sys from src.utils.logger_setup import logger from src.utils.config_parser import config @@ -11,9 +10,7 @@ def run_script(script_name): - module = ( - script_name[2:-3].replace(os.sep, ".") - ) + module = script_name[2:-3].replace(os.sep, ".") subprocess.run(["python3", "-m", module]) diff --git a/src/senders/send_canary_dns_token.py b/src/senders/send_canary_dns_token.py index 62872dd..caa72df 100644 --- a/src/senders/send_canary_dns_token.py +++ b/src/senders/send_canary_dns_token.py @@ -1,8 +1,6 @@ import base64 import socket import re -import os -import sys from src.utils.logger_setup import logger diff --git a/src/senders/send_telegram_message_to_chat.py b/src/senders/send_telegram_message_to_chat.py index 3aee7aa..989254d 100644 --- a/src/senders/send_telegram_message_to_chat.py +++ b/src/senders/send_telegram_message_to_chat.py @@ -1,7 +1,5 @@ import requests -import sys -import os from src.utils.logger_setup import logger diff --git a/src/senders/senders_handler.py b/src/senders/senders_handler.py index e48db6d..8bdac76 100644 --- a/src/senders/senders_handler.py +++ b/src/senders/senders_handler.py @@ -1,5 +1,3 @@ -import sys -import os import src.constants as constants from src.utils.config_parser import config diff --git a/src/shields/deploying.py b/src/shields/deploying.py index 04a5073..2d100ec 100644 --- a/src/shields/deploying.py +++ b/src/shields/deploying.py @@ -1,7 +1,6 @@ from bcc import BPF import tomllib import os -import sys from src.utils.logger_setup import logger import src.constants as constants diff --git a/src/shields/shields_common.py b/src/shields/shields_common.py index c49f0af..572deff 100644 --- a/src/shields/shields_common.py +++ b/src/shields/shields_common.py @@ -12,7 +12,7 @@ ConfigurationError, ShieldConfigurationError, MaxActionReached, - MaxRetriesReached, + MaxRetriesReached, NoInternetConnection, ShieldKernelSpaceCError, ) @@ -20,8 +20,8 @@ from src.shields import deploying, status_handler from src.utils.logger_setup import logger_shields from src.utils.logging_handler import ( - log_shield_exception, - log_shield_exception_warn, + log_shield_exception, + log_shield_exception_warn, ) from src.utils.format_utils import mac_address_format diff --git a/src/shields/status_handler.py b/src/shields/status_handler.py index 298fd38..dccc9b5 100644 --- a/src/shields/status_handler.py +++ b/src/shields/status_handler.py @@ -1,5 +1,3 @@ -import sys -import os import threading import requests diff --git a/src/shields/webcam/webcam.py b/src/shields/webcam/webcam.py index ca4db90..cfb883f 100644 --- a/src/shields/webcam/webcam.py +++ b/src/shields/webcam/webcam.py @@ -15,6 +15,7 @@ status = status_handler.StatusHandler() + def bpf_main(): try: # shield configuration @@ -37,23 +38,25 @@ def shield_logic(cpu, data, size): event = b["events"].event(data) # get here the data for shield impl - webcam_data = ("pid:%d" % (event.pid)) + webcam_data = "pid:%d" % (event.pid) + + message = f"{constants.CAETRA_SENDER_LABEL}_{SHIELD_NAME.upper()} act: '{shield_config.get('action_label')}' limit_sending: {shield_config['features']['limit_sending']} data: {webcam_data}" - message = f"{constants.CAETRA_SENDER_LABEL}_{SHIELD_NAME.upper()} act: '{shield_config.get("action_label")}' limit_sending: {shield_config["features"]["limit_sending"]} data: { webcam_data }" - try: if shield_config["features"]["limit_sending"]: - status.can_be_sent(event.ts, shield_config["features"]["max_actions"], shield_config["features"]["cool_down_time"]) - + status.can_be_sent( + event.ts, + shield_config["features"]["max_actions"], + shield_config["features"]["cool_down_time"], + ) + send(message, shield_config) except ConfigurationError as e: log_shield_exception(e, SHIELD_NAME) except MaxActionReached as e: log_shield_exception_warn(e, SHIELD_NAME) else: - logger_shields.info( - f"{SHIELD_NAME} triggered and sent: {message}" - ) + logger_shields.info(f"{SHIELD_NAME} triggered and sent: {message}") finally: logger_shields.warning(f"{SHIELD_NAME} triggered: {message}") diff --git a/src/utils/dict_handler.py b/src/utils/dict_handler.py index f014ad3..476121b 100644 --- a/src/utils/dict_handler.py +++ b/src/utils/dict_handler.py @@ -1,5 +1,3 @@ -import sys -import os # caetra imports from src.caetra_exceptions import ConfigurationError From adc23c01146025660ec9c96b295a9a02190e9941 Mon Sep 17 00:00:00 2001 From: carvilsi Date: Mon, 13 Jul 2026 18:42:24 +0200 Subject: [PATCH 08/10] :art: proper imports instead * --- src/senders/senders_handler.py | 1 - src/shields/ambient_light/ambient_light.py | 13 ++++++++++++- src/shields/hid_add_remove/hid_add_remove.py | 14 +++++++++++++- src/shields/hid_interact/hid_interact.py | 13 ++++++++++++- src/shields/inet/inet.py | 16 +++++++++++++++- src/shields/input_event/input_event.py | 13 ++++++++++++- src/shields/mmc/mmc.py | 10 +++++++++- src/shields/power/power.py | 10 +++++++++- src/shields/usb/usb.py | 10 +++++++++- src/shields/webcam/webcam.py | 13 ++++++++++++- src/utils/dict_handler.py | 1 - 11 files changed, 103 insertions(+), 11 deletions(-) diff --git a/src/senders/senders_handler.py b/src/senders/senders_handler.py index 8bdac76..9486068 100644 --- a/src/senders/senders_handler.py +++ b/src/senders/senders_handler.py @@ -1,4 +1,3 @@ - import src.constants as constants from src.utils.config_parser import config from src.utils.logger_setup import logger diff --git a/src/shields/ambient_light/ambient_light.py b/src/shields/ambient_light/ambient_light.py index 7ed8347..d2c36ee 100644 --- a/src/shields/ambient_light/ambient_light.py +++ b/src/shields/ambient_light/ambient_light.py @@ -1,4 +1,15 @@ -from src.shields.shields_common import * +from src.shields.shields_common import ( + constants, + deploying, + send, + status_handler, + logger_shields, + log_shield_exception, + log_shield_exception_warn, + ShieldConfigurationError, + ConfigurationError, + MaxActionReached, +) # shield name # must be same with in toml root config diff --git a/src/shields/hid_add_remove/hid_add_remove.py b/src/shields/hid_add_remove/hid_add_remove.py index 3383114..f4c526d 100644 --- a/src/shields/hid_add_remove/hid_add_remove.py +++ b/src/shields/hid_add_remove/hid_add_remove.py @@ -1,4 +1,16 @@ -from src.shields.shields_common import * +from src.shields.shields_common import ( + constants, + deploying, + logger_shields, + log_shield_exception, + log_shield_exception_warn, + send, + status_handler, + ConfigurationError, + MaxActionReached, + ShieldConfigurationError, + ShieldKernelSpaceCError, +) # from linux/hid.h HID_TYPE = { diff --git a/src/shields/hid_interact/hid_interact.py b/src/shields/hid_interact/hid_interact.py index 49cbb93..2d228e0 100644 --- a/src/shields/hid_interact/hid_interact.py +++ b/src/shields/hid_interact/hid_interact.py @@ -1,4 +1,15 @@ -from src.shields.shields_common import * +from src.shields.shields_common import ( + constants, + deploying, + logger_shields, + log_shield_exception, + log_shield_exception_warn, + send, + status_handler, + ConfigurationError, + MaxActionReached, + ShieldConfigurationError, +) # from linux/hid.h HID_TYPE = { diff --git a/src/shields/inet/inet.py b/src/shields/inet/inet.py index 7cba34a..08753c5 100644 --- a/src/shields/inet/inet.py +++ b/src/shields/inet/inet.py @@ -1,4 +1,18 @@ -from src.shields.shields_common import * +from src.shields.shields_common import ( + constants, + deploying, + logger_shields, + log_shield_exception, + log_shield_exception_warn, + mac_address_format, + send, + status_handler, + ConfigurationError, + MaxActionReached, + MaxRetriesReached, + NoInternetConnection, + ShieldConfigurationError, +) # from linux/netdevice.h # only interesting events diff --git a/src/shields/input_event/input_event.py b/src/shields/input_event/input_event.py index 1f381e7..cb1e138 100644 --- a/src/shields/input_event/input_event.py +++ b/src/shields/input_event/input_event.py @@ -1,4 +1,15 @@ -from src.shields.shields_common import * +from src.shields.shields_common import ( + constants, + deploying, + logger_shields, + log_shield_exception, + log_shield_exception_warn, + send, + status_handler, + ConfigurationError, + MaxActionReached, + ShieldConfigurationError, +) # shield name # must be same with in toml root config diff --git a/src/shields/mmc/mmc.py b/src/shields/mmc/mmc.py index 2fa3ded..56e4ed4 100755 --- a/src/shields/mmc/mmc.py +++ b/src/shields/mmc/mmc.py @@ -1,4 +1,12 @@ -from src.shields.shields_common import * +from src.shields.shields_common import ( + constants, + deploying, + logger_shields, + log_shield_exception, + send, + ConfigurationError, + ShieldConfigurationError, +) # from linux/mmc/card.h # definition fo Multi Media Cards diff --git a/src/shields/power/power.py b/src/shields/power/power.py index a709230..207fb8c 100644 --- a/src/shields/power/power.py +++ b/src/shields/power/power.py @@ -1,4 +1,12 @@ -from src.shields.shields_common import * +from src.shields.shields_common import ( + constants, + deploying, + logger_shields, + log_shield_exception, + send, + ConfigurationError, + ShieldConfigurationError, +) # from linux/power_supply.h POWER_SUPPLY_TYPE = { diff --git a/src/shields/usb/usb.py b/src/shields/usb/usb.py index 7f903f1..3efaec5 100755 --- a/src/shields/usb/usb.py +++ b/src/shields/usb/usb.py @@ -1,4 +1,12 @@ -from src.shields.shields_common import * +from src.shields.shields_common import ( + constants, + deploying, + logger_shields, + log_shield_exception, + send, + ConfigurationError, + ShieldConfigurationError, +) # shield name # must be same with in toml root config diff --git a/src/shields/webcam/webcam.py b/src/shields/webcam/webcam.py index cfb883f..aabe2e9 100644 --- a/src/shields/webcam/webcam.py +++ b/src/shields/webcam/webcam.py @@ -1,4 +1,15 @@ -from src.shields.shields_common import * +from src.shields.shields_common import ( + constants, + deploying, + logger_shields, + log_shield_exception, + log_shield_exception_warn, + send, + status_handler, + ConfigurationError, + MaxActionReached, + ShieldConfigurationError, +) # shield name # must be same with in toml root config diff --git a/src/utils/dict_handler.py b/src/utils/dict_handler.py index 476121b..1dd1403 100644 --- a/src/utils/dict_handler.py +++ b/src/utils/dict_handler.py @@ -1,4 +1,3 @@ - # caetra imports from src.caetra_exceptions import ConfigurationError From edbd54676902252d32b8a0237a3df020f90d5f34 Mon Sep 17 00:00:00 2001 From: carvilsi Date: Fri, 17 Jul 2026 17:18:12 +0200 Subject: [PATCH 09/10] :recycle: refactos imports in the good direction --- src/shields/ambient_light/ambient_light.py | 20 +++++++------- src/shields/blt_connect/blt_connect.py | 11 +++++++- src/shields/blt_disconnect/blt_disconnect.py | 11 +++++++- src/shields/cd_dvd_rom/cd_dvd_rom.py | 13 +++++++++- src/shields/hibernation/hibernation.py | 12 ++++++++- src/shields/hid_add_remove/hid_add_remove.py | 22 ++++++++-------- src/shields/hid_interact/hid_interact.py | 20 +++++++------- src/shields/inet/inet.py | 26 +++++++++---------- src/shields/input_event/input_event.py | 20 +++++++------- src/shields/mmc/mmc.py | 14 +++++----- src/shields/power/power.py | 14 +++++----- src/shields/usb/usb.py | 14 +++++----- src/shields/webcam/webcam.py | 20 +++++++------- src/utils/config_parser.py | 4 +-- .../templates/ctr_bpf_py.jinja | 11 +++++++- 15 files changed, 140 insertions(+), 92 deletions(-) diff --git a/src/shields/ambient_light/ambient_light.py b/src/shields/ambient_light/ambient_light.py index d2c36ee..3137489 100644 --- a/src/shields/ambient_light/ambient_light.py +++ b/src/shields/ambient_light/ambient_light.py @@ -1,14 +1,14 @@ from src.shields.shields_common import ( - constants, - deploying, - send, - status_handler, - logger_shields, - log_shield_exception, - log_shield_exception_warn, - ShieldConfigurationError, - ConfigurationError, - MaxActionReached, + constants, + deploying, + send, + status_handler, + logger_shields, + log_shield_exception, + log_shield_exception_warn, + ShieldConfigurationError, + ConfigurationError, + MaxActionReached, ) # shield name diff --git a/src/shields/blt_connect/blt_connect.py b/src/shields/blt_connect/blt_connect.py index 8e121d0..7c01f7b 100644 --- a/src/shields/blt_connect/blt_connect.py +++ b/src/shields/blt_connect/blt_connect.py @@ -1,4 +1,13 @@ -from src.shields.shields_common import * +from src.shields.shields_common import ( + constants, + deploying, + log_shield_exception, + logger_shields, + mac_address_format, + send, + ConfigurationError, + ShieldConfigurationError, +) # shield name # must be same with in toml root config diff --git a/src/shields/blt_disconnect/blt_disconnect.py b/src/shields/blt_disconnect/blt_disconnect.py index 1e8dbc0..bcc4290 100644 --- a/src/shields/blt_disconnect/blt_disconnect.py +++ b/src/shields/blt_disconnect/blt_disconnect.py @@ -1,4 +1,13 @@ -from src.shields.shields_common import * +from src.shields.shields_common import ( + constants, + deploying, + log_shield_exception, + logger_shields, + mac_address_format, + send, + ConfigurationError, + ShieldConfigurationError, +) # shield name # must be same with in toml root config diff --git a/src/shields/cd_dvd_rom/cd_dvd_rom.py b/src/shields/cd_dvd_rom/cd_dvd_rom.py index ff62674..1616f33 100644 --- a/src/shields/cd_dvd_rom/cd_dvd_rom.py +++ b/src/shields/cd_dvd_rom/cd_dvd_rom.py @@ -1,4 +1,15 @@ -from src.shields.shields_common import * +from src.shields.shields_common import ( + constants, + deploying, + log_shield_exception, + log_shield_exception_warn, + logger_shields, + send, + status_handler, + ConfigurationError, + MaxActionReached, + ShieldConfigurationError, +) # shield name # must be same with in toml root config diff --git a/src/shields/hibernation/hibernation.py b/src/shields/hibernation/hibernation.py index 4ebaada..920cfb4 100644 --- a/src/shields/hibernation/hibernation.py +++ b/src/shields/hibernation/hibernation.py @@ -1,4 +1,14 @@ -from src.shields.shields_common import * +from src.shields.shields_common import ( + constants, + deploying, + log_shield_exception, + logger_shields, + send, + status_handler, + ConfigurationError, + MaxRetriesReached, + ShieldConfigurationError, +) # shield name # must be same with in toml root config diff --git a/src/shields/hid_add_remove/hid_add_remove.py b/src/shields/hid_add_remove/hid_add_remove.py index f4c526d..d7f1ba2 100644 --- a/src/shields/hid_add_remove/hid_add_remove.py +++ b/src/shields/hid_add_remove/hid_add_remove.py @@ -1,15 +1,15 @@ from src.shields.shields_common import ( - constants, - deploying, - logger_shields, - log_shield_exception, - log_shield_exception_warn, - send, - status_handler, - ConfigurationError, - MaxActionReached, - ShieldConfigurationError, - ShieldKernelSpaceCError, + constants, + deploying, + logger_shields, + log_shield_exception, + log_shield_exception_warn, + send, + status_handler, + ConfigurationError, + MaxActionReached, + ShieldConfigurationError, + ShieldKernelSpaceCError, ) # from linux/hid.h diff --git a/src/shields/hid_interact/hid_interact.py b/src/shields/hid_interact/hid_interact.py index 2d228e0..01571c1 100644 --- a/src/shields/hid_interact/hid_interact.py +++ b/src/shields/hid_interact/hid_interact.py @@ -1,14 +1,14 @@ from src.shields.shields_common import ( - constants, - deploying, - logger_shields, - log_shield_exception, - log_shield_exception_warn, - send, - status_handler, - ConfigurationError, - MaxActionReached, - ShieldConfigurationError, + constants, + deploying, + logger_shields, + log_shield_exception, + log_shield_exception_warn, + send, + status_handler, + ConfigurationError, + MaxActionReached, + ShieldConfigurationError, ) # from linux/hid.h diff --git a/src/shields/inet/inet.py b/src/shields/inet/inet.py index 08753c5..3b52cf5 100644 --- a/src/shields/inet/inet.py +++ b/src/shields/inet/inet.py @@ -1,17 +1,17 @@ from src.shields.shields_common import ( - constants, - deploying, - logger_shields, - log_shield_exception, - log_shield_exception_warn, - mac_address_format, - send, - status_handler, - ConfigurationError, - MaxActionReached, - MaxRetriesReached, - NoInternetConnection, - ShieldConfigurationError, + constants, + deploying, + logger_shields, + log_shield_exception, + log_shield_exception_warn, + mac_address_format, + send, + status_handler, + ConfigurationError, + MaxActionReached, + MaxRetriesReached, + NoInternetConnection, + ShieldConfigurationError, ) # from linux/netdevice.h diff --git a/src/shields/input_event/input_event.py b/src/shields/input_event/input_event.py index cb1e138..5d5ecd9 100644 --- a/src/shields/input_event/input_event.py +++ b/src/shields/input_event/input_event.py @@ -1,14 +1,14 @@ from src.shields.shields_common import ( - constants, - deploying, - logger_shields, - log_shield_exception, - log_shield_exception_warn, - send, - status_handler, - ConfigurationError, - MaxActionReached, - ShieldConfigurationError, + constants, + deploying, + logger_shields, + log_shield_exception, + log_shield_exception_warn, + send, + status_handler, + ConfigurationError, + MaxActionReached, + ShieldConfigurationError, ) # shield name diff --git a/src/shields/mmc/mmc.py b/src/shields/mmc/mmc.py index 56e4ed4..35445e5 100755 --- a/src/shields/mmc/mmc.py +++ b/src/shields/mmc/mmc.py @@ -1,11 +1,11 @@ from src.shields.shields_common import ( - constants, - deploying, - logger_shields, - log_shield_exception, - send, - ConfigurationError, - ShieldConfigurationError, + constants, + deploying, + logger_shields, + log_shield_exception, + send, + ConfigurationError, + ShieldConfigurationError, ) # from linux/mmc/card.h diff --git a/src/shields/power/power.py b/src/shields/power/power.py index 207fb8c..c2b3e6a 100644 --- a/src/shields/power/power.py +++ b/src/shields/power/power.py @@ -1,11 +1,11 @@ from src.shields.shields_common import ( - constants, - deploying, - logger_shields, - log_shield_exception, - send, - ConfigurationError, - ShieldConfigurationError, + constants, + deploying, + logger_shields, + log_shield_exception, + send, + ConfigurationError, + ShieldConfigurationError, ) # from linux/power_supply.h diff --git a/src/shields/usb/usb.py b/src/shields/usb/usb.py index 3efaec5..1612b51 100755 --- a/src/shields/usb/usb.py +++ b/src/shields/usb/usb.py @@ -1,11 +1,11 @@ from src.shields.shields_common import ( - constants, - deploying, - logger_shields, - log_shield_exception, - send, - ConfigurationError, - ShieldConfigurationError, + constants, + deploying, + logger_shields, + log_shield_exception, + send, + ConfigurationError, + ShieldConfigurationError, ) # shield name diff --git a/src/shields/webcam/webcam.py b/src/shields/webcam/webcam.py index aabe2e9..dbde472 100644 --- a/src/shields/webcam/webcam.py +++ b/src/shields/webcam/webcam.py @@ -1,14 +1,14 @@ from src.shields.shields_common import ( - constants, - deploying, - logger_shields, - log_shield_exception, - log_shield_exception_warn, - send, - status_handler, - ConfigurationError, - MaxActionReached, - ShieldConfigurationError, + constants, + deploying, + logger_shields, + log_shield_exception, + log_shield_exception_warn, + send, + status_handler, + ConfigurationError, + MaxActionReached, + ShieldConfigurationError, ) # shield name diff --git a/src/utils/config_parser.py b/src/utils/config_parser.py index 2c56d60..16606f0 100644 --- a/src/utils/config_parser.py +++ b/src/utils/config_parser.py @@ -1,6 +1,6 @@ import tomllib # TODO: Add a config checker for mandatory variables -f = open("./config/local.toml", "rb") -# f = open("./config/develop.toml", "rb") +# f = open("./config/local.toml", "rb") +f = open("./config/develop.toml", "rb") config = tomllib.load(f) diff --git a/tools/caetra_shield_generator/templates/ctr_bpf_py.jinja b/tools/caetra_shield_generator/templates/ctr_bpf_py.jinja index 5c10560..1990a10 100644 --- a/tools/caetra_shield_generator/templates/ctr_bpf_py.jinja +++ b/tools/caetra_shield_generator/templates/ctr_bpf_py.jinja @@ -1,4 +1,13 @@ -from src.shields.shields_common import * +# minimun required imports +from src.shields.shields_common import ( + constants, + deploying, + log_shield_exception, + logger_shields, + send, + ConfigurationError, + ShieldConfigurationError, +) # shield name # must be same with in toml root config From ef017ba4c4163492eaecd17e5023270d3b74806f Mon Sep 17 00:00:00 2001 From: carvilsi Date: Fri, 17 Jul 2026 17:27:10 +0200 Subject: [PATCH 10/10] :adhesive_bandage: deletes useless line on config_parser --- CHANGELOG.md | 7 ++----- src/utils/config_parser.py | 1 - 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 888dd92..4768ae5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,10 @@ # Changelog -# develop -- Adds name of HID for hid_interact shield - -# [v1.2.1](https://github.com/carvilsi/caetra/releases/tag/v1.2.1) (2026-07-08) +# [v1.2.1](https://github.com/carvilsi/caetra/releases/tag/v1.2.1) (2026-07-17) - Refactor to import as a module - +- Adds name of HID for hid_interact shield # [v1.2.0](https://github.com/carvilsi/caetra/releases/tag/v1.2.0) (2026-03-18) diff --git a/src/utils/config_parser.py b/src/utils/config_parser.py index 16606f0..4d31ef7 100644 --- a/src/utils/config_parser.py +++ b/src/utils/config_parser.py @@ -1,6 +1,5 @@ import tomllib # TODO: Add a config checker for mandatory variables -# f = open("./config/local.toml", "rb") f = open("./config/develop.toml", "rb") config = tomllib.load(f)