80 lines
3.0 KiB
Python
80 lines
3.0 KiB
Python
|
from utils.Logger import Log
|
||
|
import inspect
|
||
|
|
||
|
def _get_plugin_name():
|
||
|
try:
|
||
|
# First try to get the caller's plugin name
|
||
|
for frame_record in inspect.stack():
|
||
|
frame = frame_record[0]
|
||
|
if 'self' in frame.f_locals:
|
||
|
instance = frame.f_locals['self']
|
||
|
# Check if this is a plugin instance with a name attribute
|
||
|
if hasattr(instance, 'name') and 'plugins' in frame.f_globals.get('__file__', ''):
|
||
|
return instance.name
|
||
|
|
||
|
# If we couldn't find a plugin name in the call stack, check if we're being called by another plugin
|
||
|
for frame_record in inspect.stack():
|
||
|
module = inspect.getmodule(frame_record[0])
|
||
|
if module and hasattr(module, '__file__') and 'plugins' in module.__file__:
|
||
|
# Extract the plugin name from the filename
|
||
|
return "Called from " + module.__name__.split('.')[-1]
|
||
|
except Exception as e:
|
||
|
return f"Error: {str(e)}"
|
||
|
return "Unknown"
|
||
|
|
||
|
class Plugin:
|
||
|
def __init__(self):
|
||
|
self.version = "1.0.0"
|
||
|
self.name = "Example - Main"
|
||
|
|
||
|
def demo(self, *args, **kwargs):
|
||
|
Log.v(f"This is \"demo\" function. I am called by \"{_get_plugin_name()}\" with the argument received: args={args}, kwargs={kwargs}")
|
||
|
|
||
|
|
||
|
def on_start(self, *args, **kwargs):
|
||
|
Log.v("="*10)
|
||
|
Log.v("")
|
||
|
Log.v("Hello, this is an example plugin!")
|
||
|
Log.v("You can find this plugin, and disable by removing this plugin at plugins/example.py")
|
||
|
Log.v("With plugins, you can implement your own integrations, or features.")
|
||
|
Log.v("For more informations, please check our documentation!")
|
||
|
Log.v("")
|
||
|
Log.v("="*10)
|
||
|
|
||
|
"""
|
||
|
These codeblocks below are available events.
|
||
|
You can implement your own events by using the examples below.
|
||
|
|
||
|
on_created() : Called when a file is created.
|
||
|
on_deleted() : Called when a file is deleted.
|
||
|
on_modified() : Called when a file is modified.
|
||
|
on_moved() : Called when a file is moved.
|
||
|
|
||
|
on_scan() : Called when a scan is started.
|
||
|
on_scan_completed() : Called when a scan is completed.
|
||
|
on_ai_analysis_completed() : Called when an AI analysis is completed.
|
||
|
|
||
|
Good luck, have fun!
|
||
|
"""
|
||
|
|
||
|
|
||
|
# def on_created(self, *args, **kwargs):
|
||
|
# Log.v(f"File created args={args}, kwargs={kwargs}")
|
||
|
|
||
|
# def on_deleted(self, *args, **kwargs):
|
||
|
# Log.v(f"File deleted args={args}, kwargs={kwargs}")
|
||
|
|
||
|
# def on_modified(self, *args, **kwargs):
|
||
|
# Log.v(f"File modified args={args}, kwargs={kwargs}")
|
||
|
|
||
|
# def on_moved(self, *args, **kwargs):
|
||
|
# Log.v(f"File moved args={args}, kwargs={kwargs}")
|
||
|
|
||
|
# def on_scan(self, *args, **kwargs):
|
||
|
# Log.v(f"Scan started args={args}, kwargs={kwargs}")
|
||
|
|
||
|
# def on_scan_completed(self, *args, **kwargs):
|
||
|
# Log.v(f"Scan completed args={args}, kwargs={kwargs}")
|
||
|
|
||
|
# def on_ai_analysis_completed(self, *args, **kwargs):
|
||
|
# Log.v(f"AI analysis completed args={args}, kwargs={kwargs}")
|