2019-12-30 10:16:55 +01:00
|
|
|
import os
|
|
|
|
|
2021-09-16 17:53:40 +02:00
|
|
|
from platypush.backend import Backend
|
2019-12-30 10:16:55 +01:00
|
|
|
from platypush.context import get_plugin
|
2021-09-16 17:53:40 +02:00
|
|
|
from platypush.plugins import Plugin
|
|
|
|
from platypush.utils.manifest import get_manifests
|
2019-12-30 10:16:55 +01:00
|
|
|
|
|
|
|
|
2022-03-03 15:15:55 +01:00
|
|
|
def _get_inspect_plugin():
|
|
|
|
p = get_plugin('inspect')
|
|
|
|
assert p, 'Could not load the `inspect` plugin'
|
|
|
|
return p
|
|
|
|
|
|
|
|
|
2019-12-30 10:16:55 +01:00
|
|
|
def get_all_plugins():
|
2021-09-16 17:53:40 +02:00
|
|
|
manifests = {mf.component_name for mf in get_manifests(Plugin)}
|
|
|
|
return {
|
|
|
|
plugin_name: plugin_info
|
2022-03-03 15:15:55 +01:00
|
|
|
for plugin_name, plugin_info in _get_inspect_plugin().get_all_plugins().output.items()
|
2021-09-16 17:53:40 +02:00
|
|
|
if plugin_name in manifests
|
|
|
|
}
|
2019-12-30 10:16:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
def get_all_backends():
|
2021-09-16 17:53:40 +02:00
|
|
|
manifests = {mf.component_name for mf in get_manifests(Backend)}
|
|
|
|
return {
|
|
|
|
backend_name: backend_info
|
2022-03-03 15:15:55 +01:00
|
|
|
for backend_name, backend_info in _get_inspect_plugin().get_all_backends().output.items()
|
2021-09-16 17:53:40 +02:00
|
|
|
if backend_name in manifests
|
|
|
|
}
|
2019-12-30 10:16:55 +01:00
|
|
|
|
|
|
|
|
2019-12-30 18:50:01 +01:00
|
|
|
def get_all_events():
|
2022-03-03 15:15:55 +01:00
|
|
|
return _get_inspect_plugin().get_all_events().output
|
2019-12-30 18:50:01 +01:00
|
|
|
|
|
|
|
|
2020-03-05 17:39:50 +01:00
|
|
|
def get_all_responses():
|
2022-03-03 15:15:55 +01:00
|
|
|
return _get_inspect_plugin().get_all_responses().output
|
2020-03-05 17:39:50 +01:00
|
|
|
|
|
|
|
|
2019-12-30 10:16:55 +01:00
|
|
|
# noinspection DuplicatedCode
|
|
|
|
def generate_plugins_doc():
|
|
|
|
plugins_index = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'docs', 'source', 'plugins.rst')
|
|
|
|
plugins_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'docs', 'source', 'platypush', 'plugins')
|
|
|
|
all_plugins = sorted(plugin for plugin in get_all_plugins().keys())
|
|
|
|
|
|
|
|
for plugin in all_plugins:
|
|
|
|
plugin_file = os.path.join(plugins_dir, plugin + '.rst')
|
|
|
|
if not os.path.exists(plugin_file):
|
|
|
|
plugin = 'platypush.plugins.' + plugin
|
2021-07-17 22:14:15 +02:00
|
|
|
header = '``{}``'.format('.'.join(plugin.split('.')[2:]))
|
2019-12-30 10:16:55 +01:00
|
|
|
divider = '=' * len(header)
|
|
|
|
body = '\n.. automodule:: {}\n :members:\n'.format(plugin)
|
|
|
|
out = '\n'.join([header, divider, body])
|
|
|
|
|
|
|
|
with open(plugin_file, 'w') as f:
|
|
|
|
f.write(out)
|
|
|
|
|
|
|
|
with open(plugins_index, 'w') as f:
|
|
|
|
f.write('''
|
|
|
|
Plugins
|
|
|
|
=======
|
|
|
|
|
|
|
|
.. toctree::
|
|
|
|
:maxdepth: 2
|
|
|
|
:caption: Plugins:
|
|
|
|
|
|
|
|
''')
|
|
|
|
|
|
|
|
for plugin in all_plugins:
|
|
|
|
f.write(' platypush/plugins/' + plugin + '.rst\n')
|
|
|
|
|
|
|
|
|
|
|
|
# noinspection DuplicatedCode
|
|
|
|
def generate_backends_doc():
|
|
|
|
backends_index = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'docs', 'source', 'backends.rst')
|
|
|
|
backends_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'docs', 'source', 'platypush', 'backend')
|
|
|
|
all_backends = sorted(backend for backend in get_all_backends().keys())
|
|
|
|
|
|
|
|
for backend in all_backends:
|
|
|
|
backend_file = os.path.join(backends_dir, backend + '.rst')
|
|
|
|
if not os.path.exists(backend_file):
|
|
|
|
backend = 'platypush.backend.' + backend
|
2021-07-17 22:14:15 +02:00
|
|
|
header = '``{}``'.format('.'.join(backend.split('.')[2:]))
|
2019-12-30 10:16:55 +01:00
|
|
|
divider = '=' * len(header)
|
|
|
|
body = '\n.. automodule:: {}\n :members:\n'.format(backend)
|
|
|
|
out = '\n'.join([header, divider, body])
|
|
|
|
|
|
|
|
with open(backend_file, 'w') as f:
|
|
|
|
f.write(out)
|
|
|
|
|
|
|
|
with open(backends_index, 'w') as f:
|
|
|
|
f.write('''
|
|
|
|
Backends
|
|
|
|
========
|
|
|
|
|
|
|
|
.. toctree::
|
|
|
|
:maxdepth: 2
|
|
|
|
:caption: Backends:
|
|
|
|
|
|
|
|
''')
|
|
|
|
|
|
|
|
for backend in all_backends:
|
2019-12-30 10:22:05 +01:00
|
|
|
f.write(' platypush/backend/' + backend + '.rst\n')
|
2019-12-30 10:16:55 +01:00
|
|
|
|
|
|
|
|
2019-12-30 18:50:01 +01:00
|
|
|
# noinspection DuplicatedCode
|
|
|
|
def generate_events_doc():
|
2022-03-03 15:15:55 +01:00
|
|
|
from platypush.message import event as event_module
|
2019-12-30 18:50:01 +01:00
|
|
|
events_index = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'docs', 'source', 'events.rst')
|
|
|
|
events_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'docs', 'source', 'platypush', 'events')
|
2022-03-03 15:15:55 +01:00
|
|
|
all_events = sorted(event for event in get_all_events().keys() if event)
|
2019-12-30 18:50:01 +01:00
|
|
|
|
|
|
|
for event in all_events:
|
2022-03-03 15:15:55 +01:00
|
|
|
event_file = os.path.join(events_dir, event + '.rst')
|
2019-12-30 18:50:01 +01:00
|
|
|
if not os.path.exists(event_file):
|
|
|
|
header = '``{}``'.format(event)
|
|
|
|
divider = '=' * len(header)
|
2022-03-03 15:15:55 +01:00
|
|
|
body = '\n.. automodule:: {}.{}\n :members:\n'.format(event_module.__name__, event)
|
2019-12-30 18:50:01 +01:00
|
|
|
out = '\n'.join([header, divider, body])
|
|
|
|
|
|
|
|
with open(event_file, 'w') as f:
|
|
|
|
f.write(out)
|
|
|
|
|
|
|
|
with open(events_index, 'w') as f:
|
|
|
|
f.write('''
|
|
|
|
Events
|
|
|
|
======
|
|
|
|
|
|
|
|
.. toctree::
|
|
|
|
:maxdepth: 2
|
|
|
|
:caption: Events:
|
|
|
|
|
|
|
|
''')
|
|
|
|
|
|
|
|
for event in all_events:
|
2022-03-03 15:15:55 +01:00
|
|
|
f.write(' platypush/events/' + event + '.rst\n')
|
2019-12-30 18:50:01 +01:00
|
|
|
|
|
|
|
|
2020-03-05 17:39:50 +01:00
|
|
|
# noinspection DuplicatedCode
|
|
|
|
def generate_responses_doc():
|
2022-03-03 15:15:55 +01:00
|
|
|
from platypush.message import response as response_module
|
2020-03-05 17:39:50 +01:00
|
|
|
responses_index = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'docs', 'source', 'responses.rst')
|
|
|
|
responses_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'docs', 'source', 'platypush', 'responses')
|
2022-03-03 15:15:55 +01:00
|
|
|
all_responses = sorted(response for response in get_all_responses().keys() if response)
|
2020-03-05 17:39:50 +01:00
|
|
|
|
|
|
|
for response in all_responses:
|
2022-03-03 15:15:55 +01:00
|
|
|
response_file = os.path.join(responses_dir, response + '.rst')
|
2020-03-05 17:39:50 +01:00
|
|
|
if not os.path.exists(response_file):
|
|
|
|
header = '``{}``'.format(response)
|
|
|
|
divider = '=' * len(header)
|
2022-03-03 15:15:55 +01:00
|
|
|
body = '\n.. automodule:: {}.{}\n :members:\n'.format(response_module.__name__, response)
|
2020-03-05 17:39:50 +01:00
|
|
|
out = '\n'.join([header, divider, body])
|
|
|
|
|
|
|
|
with open(response_file, 'w') as f:
|
|
|
|
f.write(out)
|
|
|
|
|
|
|
|
with open(responses_index, 'w') as f:
|
|
|
|
f.write('''
|
|
|
|
Responses
|
|
|
|
=========
|
|
|
|
|
|
|
|
.. toctree::
|
|
|
|
:maxdepth: 2
|
|
|
|
:caption: Responses:
|
|
|
|
|
|
|
|
''')
|
|
|
|
|
|
|
|
for response in all_responses:
|
2022-03-03 15:15:55 +01:00
|
|
|
f.write(' platypush/responses/' + response + '.rst\n')
|
2020-03-05 17:39:50 +01:00
|
|
|
|
|
|
|
|
2019-12-30 10:16:55 +01:00
|
|
|
generate_plugins_doc()
|
|
|
|
generate_backends_doc()
|
2019-12-30 18:50:01 +01:00
|
|
|
generate_events_doc()
|
2020-03-05 17:39:50 +01:00
|
|
|
generate_responses_doc()
|
2019-12-30 10:16:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
# vim:sw=4:ts=4:et:
|