Skip to content

Commit

Permalink
Rework and polish plugins for release
Browse files Browse the repository at this point in the history
base.py, ob.py, plugins.py, and default.py
  • Loading branch information
jerlendds committed Dec 9, 2023
1 parent b3d395b commit e1511ec
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
5 changes: 1 addition & 4 deletions src/osintbuddy/elements/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,16 @@ class BaseElement(object):
"""
def __init__(self, **kwargs):
self.label: str = ''
self.style: dict = {}
self.placeholder: str = ''

for key, value in kwargs.items():
if key == 'label' or key == 'style' or key == 'placeholder':
if key == 'label' or key == 'placeholder':
setattr(self, key, value)

def _base_blueprint(self):
return {
'type': self.node_type,
'label': self.label,
'placeholder': self.placeholder,
'style': self.style
}


Expand Down
12 changes: 6 additions & 6 deletions src/osintbuddy/ob.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ def start_lsp():


def start():
jedi_language_server = start_lsp()
# jedi_language_server = start_lsp()
_print_server_details()
import signal
# import signal
import uvicorn
uvicorn.run(
"osintbuddy.server:app",
Expand All @@ -79,11 +79,11 @@ def start():
log_level='info'
)

def signal_handler(sig, frame):
jedi_language_server.wait(timeout=1)
# def signal_handler(sig, frame):
# jedi_language_server.wait(timeout=1)

signal.signal(signal.SIGINT, signal_handler)
signal.pause()
# signal.signal(signal.SIGINT, signal_handler)
# signal.pause()


def create_plugin_wizard():
Expand Down
23 changes: 17 additions & 6 deletions src/osintbuddy/plugins.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os, imp, importlib
import os, imp, importlib, inspect
from typing import List, Any, Callable
from collections import defaultdict
from pydantic import BaseModel, ConfigDict
Expand All @@ -13,6 +13,20 @@ class OBNode(BaseModel):
model_config = OBNodeConfig


def plugin_results_middleman(f):
def return_result(r):
return r
def yield_result(r):
for i in r:
yield i
def decorator(*a, **kwa):
if inspect.isgeneratorfunction(f):
return yield_result(f(*a, **kwa))
else:
return return_result(f(*a, **kwa))
return decorator


class OBAuthorUse(BaseModel):
get_driver: Callable[[], None]
get_graph: Callable[[], None]
Expand Down Expand Up @@ -53,7 +67,7 @@ async def get_plugin(cls, plugin_label: str):
:return: The plugin class or None if not found.
"""
for idx, label in enumerate(cls.labels):
if to_snake_case(label) == to_snake_case(plugin_label):
if label == plugin_label or to_snake_case(label) == to_snake_case(plugin_label):
return cls.plugins[idx]
return None

Expand All @@ -71,7 +85,7 @@ def get_plug(cls, plugin_label: str):
return cls.plugins[idx]
return None

def __getitem__(self, i):
def __getitem__(self, i: str):
return self.get_plug[i]

# https://stackoverflow.com/a/7548190
Expand Down Expand Up @@ -168,7 +182,6 @@ class OBPlugin(object, metaclass=OBRegistry):
label: str = ''
icon: str = 'atom-2'
show_label = True
style: dict = {}

author = 'Unknown'
description = 'No description.'
Expand Down Expand Up @@ -212,7 +225,6 @@ def blueprint(cls, **kwargs):
node['label'] = cls.label
node['color'] = cls.color if cls.color else '#145070'
node['icon'] = cls.icon
node['style'] = cls.style
node['elements'] = []
for element in cls.node:
if isinstance(element, list):
Expand Down Expand Up @@ -275,7 +287,6 @@ def _map_element(transform_map: dict, element: dict):
def _map_to_transform_data(cls, node: dict) -> OBNode:
transform_map: dict = {}
data: dict = node.get('data', {})
# model_label: str = data.get('label')
elements: list[dict] = data.get('elements', [])
for element in elements:
if isinstance(element, list):
Expand Down
4 changes: 2 additions & 2 deletions src/osintbuddy/templates/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def plugin_source_template(label: str, description: str, author: str) -> str:
class {class_name}(ob.Plugin):
label = '{label}'
icon = 'atom' # https://tabler-icons.io/
icon = 'atom-2' # https://tabler-icons.io/
color = '#FFD166'
author = '{author}'
Expand All @@ -16,7 +16,7 @@ class {class_name}(ob.Plugin):
TextInput(label='Example', icon='radioactive')
]
@ob.transform(label='To example', icon='atom')
@ob.transform(label='To example', icon='atom-2')
async def transform_example(self, node, use):
WebsitePlugin = await ob.Registry.get_plugin('website')
website_plugin = WebsitePlugin()
Expand Down

0 comments on commit e1511ec

Please sign in to comment.