From 673ec24fa3a302c419262b103286c0df7d8fcfec Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Wed, 19 Mar 2025 15:52:31 +0100 Subject: [PATCH] More work on plugins --- .../settings/templates/settings.html | 27 +++++++++++++++++++ changedetectionio/processors/__init__.py | 6 +++-- .../processors/example_processor_plugin.py | 10 +++++-- changedetectionio/tests/test_plugins.py | 15 +++++++++++ 4 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 changedetectionio/tests/test_plugins.py diff --git a/changedetectionio/blueprint/settings/templates/settings.html b/changedetectionio/blueprint/settings/templates/settings.html index cc79f0fd..cb9e09e3 100644 --- a/changedetectionio/blueprint/settings/templates/settings.html +++ b/changedetectionio/blueprint/settings/templates/settings.html @@ -26,6 +26,7 @@
  • API
  • Time & Date
  • CAPTCHA & Proxies
  • +
  • Plugins
  • @@ -297,6 +298,32 @@ nav {{ render_field(form.requests.form.extra_browsers) }}
    +
    +
    +

    Registered Plugins

    +

    The following plugins are currently registered in the system - Get more plugins here

    + + + + + + + + + + + {% for plugin in plugins_info %} + + + + + + {% endfor %} + +
    NameDescriptionVersion
    {{ plugin.name }}{{ plugin.description }}{{ plugin.version }}
    +
    +
    +
    {{ render_button(form.save_button) }} diff --git a/changedetectionio/processors/__init__.py b/changedetectionio/processors/__init__.py index 299a2ebe..e7413c1b 100644 --- a/changedetectionio/processors/__init__.py +++ b/changedetectionio/processors/__init__.py @@ -330,7 +330,8 @@ class TextJsonDiffPlugin: @hookimpl def get_processor_version(self): - return "1.0.0" + from changedetectionio import __version__ + return __version__ @hookimpl def perform_site_check(self, datastore, watch_uuid): @@ -366,7 +367,8 @@ class RestockDiffPlugin: @hookimpl def get_processor_version(self): - return "1.0.0" + from changedetectionio import __version__ + return __version__ @hookimpl def perform_site_check(self, datastore, watch_uuid): diff --git a/changedetectionio/processors/example_processor_plugin.py b/changedetectionio/processors/example_processor_plugin.py index 058fe9a1..37aab8f3 100644 --- a/changedetectionio/processors/example_processor_plugin.py +++ b/changedetectionio/processors/example_processor_plugin.py @@ -1,14 +1,20 @@ """ Example plugin to demonstrate how to create a new processor plugin """ + from .pluggy_interface import hookimpl -import importlib class ExampleProcessorPlugin: """ Example processor plugin that extends the text_json_diff processor """ - + + def random_string(self, length=50): + import random + import string + + return ''.join(random.choices(string.ascii_letters + string.digits, k=length)) + @hookimpl def get_processor_name(self): return "example_processor" diff --git a/changedetectionio/tests/test_plugins.py b/changedetectionio/tests/test_plugins.py new file mode 100644 index 00000000..34dc70c1 --- /dev/null +++ b/changedetectionio/tests/test_plugins.py @@ -0,0 +1,15 @@ +from flask import url_for + +from changedetectionio.tests.util import live_server_setup + + +def test_checkplugins_registered(live_server, client): + live_server_setup(live_server) + res = client.get( + url_for("settings.settings_page") + ) + assert res.status_code == 200 + # Should be registered in the info table + assert b'Webpage Text/HTML, JSON and PDF changes' in res.data + assert b'text_json_diff' in res.data +