From 35d3ebeba5d6e56b6d9fc40cdfe244bb0606a918 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Fri, 21 Mar 2025 10:42:25 +0100 Subject: [PATCH] Adding organisational UI tags --- changedetectionio/processors/__init__.py | 10 ++++++++++ changedetectionio/processors/pluggy_interface.py | 16 ++++++++++++++++ .../processors/restock_diff/processor.py | 1 + .../processors/text_json_diff/processor.py | 1 + 4 files changed, 28 insertions(+) diff --git a/changedetectionio/processors/__init__.py b/changedetectionio/processors/__init__.py index f5cb215b0..e05fd221f 100644 --- a/changedetectionio/processors/__init__.py +++ b/changedetectionio/processors/__init__.py @@ -300,6 +300,11 @@ class TextJsonDiffPlugin: def get_processor_version(self): from changedetectionio import __version__ return __version__ + + @hookimpl + def get_processor_ui_tag(self): + from .text_json_diff.processor import UI_tag + return UI_tag @hookimpl def perform_site_check(self, datastore, watch_uuid): @@ -337,6 +342,11 @@ class RestockDiffPlugin: def get_processor_version(self): from changedetectionio import __version__ return __version__ + + @hookimpl + def get_processor_ui_tag(self): + from .restock_diff.processor import UI_tag + return UI_tag @hookimpl def perform_site_check(self, datastore, watch_uuid): diff --git a/changedetectionio/processors/pluggy_interface.py b/changedetectionio/processors/pluggy_interface.py index 350821d36..b757769ae 100644 --- a/changedetectionio/processors/pluggy_interface.py +++ b/changedetectionio/processors/pluggy_interface.py @@ -7,6 +7,7 @@ PLUGIN_NAMESPACE = "changedetectionio_processors" hookspec = pluggy.HookspecMarker(PLUGIN_NAMESPACE) hookimpl = pluggy.HookimplMarker(PLUGIN_NAMESPACE) +UI_tags = {} class ProcessorSpec: """Hook specifications for difference detection processors.""" @@ -26,6 +27,11 @@ class ProcessorSpec: """Return the processor plugin version.""" pass + @hookspec + def get_processor_ui_tag(): + """Return the UI tag for the processor (used for categorization in UI).""" + pass + @hookspec def perform_site_check(datastore, watch_uuid): """Return the processor handler class or None if not applicable. @@ -61,9 +67,19 @@ plugin_manager = pluggy.PluginManager(PLUGIN_NAMESPACE) # Register hookspecs plugin_manager.add_hookspecs(ProcessorSpec) +# Initialize by loading plugins and building UI_tags dictionary try: # Discover installed plugins from external packages (if any) plugin_manager.load_setuptools_entrypoints(PLUGIN_NAMESPACE) logger.info(f"Loaded plugins: {plugin_manager.get_plugins()}") + + # Build UI_tags dictionary from all plugins + for plugin in plugin_manager.get_plugins(): + if hasattr(plugin, "get_processor_name") and hasattr(plugin, "get_processor_ui_tag"): + plugin_name = plugin.get_processor_name() + ui_tag = plugin.get_processor_ui_tag() + if plugin_name and ui_tag: + UI_tags[plugin_name] = ui_tag + logger.info(f"Found UI tag for plugin {plugin_name}: {ui_tag}") except Exception as e: logger.critical(f"Error loading plugins: {str(e)}") \ No newline at end of file diff --git a/changedetectionio/processors/restock_diff/processor.py b/changedetectionio/processors/restock_diff/processor.py index 8242f4e8a..b098a6ef0 100644 --- a/changedetectionio/processors/restock_diff/processor.py +++ b/changedetectionio/processors/restock_diff/processor.py @@ -9,6 +9,7 @@ import time urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) name = 'Re-stock & Price detection for single product pages' description = 'Detects if the product goes back to in-stock' +UI_tag = "Restock" class UnableToExtractRestockData(Exception): def __init__(self, status_code): diff --git a/changedetectionio/processors/text_json_diff/processor.py b/changedetectionio/processors/text_json_diff/processor.py index 5ccc8ce5f..985a7b05b 100644 --- a/changedetectionio/processors/text_json_diff/processor.py +++ b/changedetectionio/processors/text_json_diff/processor.py @@ -17,6 +17,7 @@ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) name = 'Webpage Text/HTML, JSON and PDF changes' description = 'Detects all text changes where possible' +UI_tag = "Text Diff" json_filter_prefixes = ['json:', 'jq:', 'jqraw:']