|
|
|
@ -8,10 +8,12 @@ import threading
|
|
|
|
|
import platypush.backend
|
|
|
|
|
import platypush.plugins
|
|
|
|
|
import platypush.message.event
|
|
|
|
|
import platypush.message.response
|
|
|
|
|
|
|
|
|
|
from platypush.backend import Backend
|
|
|
|
|
from platypush.plugins import Plugin, action
|
|
|
|
|
from platypush.message.event import Event
|
|
|
|
|
from platypush.message.response import Response
|
|
|
|
|
from platypush.utils import get_decorators
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -74,6 +76,18 @@ class EventModel(Model):
|
|
|
|
|
yield attr, getattr(self, attr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ResponseModel(Model):
|
|
|
|
|
def __init__(self, response, html_doc: bool = False):
|
|
|
|
|
self.package = response.__module__
|
|
|
|
|
self.name = response.__name__
|
|
|
|
|
self.html_doc = html_doc
|
|
|
|
|
self.doc = self.to_html(response.__doc__) if html_doc and response.__doc__ else response.__doc__
|
|
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
|
for attr in ['name', 'doc', 'html_doc']:
|
|
|
|
|
yield attr, getattr(self, attr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ActionModel(Model):
|
|
|
|
|
# noinspection PyShadowingNames
|
|
|
|
|
def __init__(self, action, html_doc: bool = False):
|
|
|
|
@ -148,9 +162,11 @@ class InspectPlugin(Plugin):
|
|
|
|
|
self._plugins = {}
|
|
|
|
|
self._backends = {}
|
|
|
|
|
self._events = {}
|
|
|
|
|
self._responses = {}
|
|
|
|
|
self._plugins_lock = threading.RLock()
|
|
|
|
|
self._backends_lock = threading.RLock()
|
|
|
|
|
self._events_lock = threading.RLock()
|
|
|
|
|
self._responses_lock = threading.RLock()
|
|
|
|
|
self._html_doc = False
|
|
|
|
|
|
|
|
|
|
def _init_plugins(self):
|
|
|
|
@ -215,6 +231,27 @@ class InspectPlugin(Plugin):
|
|
|
|
|
else:
|
|
|
|
|
self._events[event.package][event.name] = event
|
|
|
|
|
|
|
|
|
|
def _init_responses(self):
|
|
|
|
|
package = platypush.message.response
|
|
|
|
|
prefix = package.__name__ + '.'
|
|
|
|
|
|
|
|
|
|
for _, modname, _ in pkgutil.walk_packages(path=package.__path__,
|
|
|
|
|
prefix=prefix,
|
|
|
|
|
onerror=lambda x: None):
|
|
|
|
|
# noinspection PyBroadException
|
|
|
|
|
try:
|
|
|
|
|
module = importlib.import_module(modname)
|
|
|
|
|
except:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
for _, obj in inspect.getmembers(module):
|
|
|
|
|
if inspect.isclass(obj) and issubclass(obj, Response):
|
|
|
|
|
response = ResponseModel(response=obj, html_doc=self._html_doc)
|
|
|
|
|
if response.package not in self._responses:
|
|
|
|
|
self._responses[response.package] = {response.name: response}
|
|
|
|
|
else:
|
|
|
|
|
self._responses[response.package][response.name] = response
|
|
|
|
|
|
|
|
|
|
@action
|
|
|
|
|
def get_all_plugins(self, html_doc: bool = None):
|
|
|
|
|
"""
|
|
|
|
@ -263,5 +300,23 @@ class InspectPlugin(Plugin):
|
|
|
|
|
for package, events in self._events.items()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
@action
|
|
|
|
|
def get_all_responses(self, html_doc: bool = None):
|
|
|
|
|
"""
|
|
|
|
|
:param html_doc: If True then the docstring will be parsed into HTML (default: False)
|
|
|
|
|
"""
|
|
|
|
|
with self._responses_lock:
|
|
|
|
|
if not self._responses or (html_doc is not None and html_doc != self._html_doc):
|
|
|
|
|
self._html_doc = html_doc
|
|
|
|
|
self._init_responses()
|
|
|
|
|
|
|
|
|
|
return json.dumps({
|
|
|
|
|
package: {
|
|
|
|
|
name: dict(event)
|
|
|
|
|
for name, event in self._responses[package].items()
|
|
|
|
|
}
|
|
|
|
|
for package, events in self._responses.items()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# vim:sw=4:ts=4:et:
|
|
|
|
|