Unverified Commit c4ae3d15 authored by Guillaume Binet's avatar Guillaume Binet Committed by GitHub

Added a !plugin info admin command. (#1226)

* Added a !plugin info admin command.

The command allows you to get the all the states, namespaces, log etc...
from a plugin.

* flipped a line...
parent 25769b25
......@@ -2,6 +2,7 @@ from ast import literal_eval
from pprint import pformat
import os
import shutil
import logging
from errbot import BotPlugin, botcmd
from errbot.plugin_manager import PluginConfigurationException, PluginActivationException
......@@ -303,3 +304,14 @@ class Plugins(BotPlugin):
return f'Error activating plugin: {pae}'
return self._bot.plugin_manager.unblacklist_plugin(args)
@botcmd(admin_only=True, template='plugin_info')
def plugin_info(self, _, args):
"""Gives you a more technical information about a specific plugin."""
pm = self._bot.plugin_manager
if args not in pm.get_all_plugin_names():
return (f"{args} isn't a valid plugin name. The current plugins are:\n"
f"{self.formatted_plugin_list(active_only=False)}")
return {'plugin_info': pm.plugin_infos[args],
'plugin': pm.plugins[args],
'logging': logging}
#### Plugin info from {{ plugin_info.location }}
name: {{ plugin_info.name }}
module: {{ plugin_info.module }}
full_module_path: {{ plugin_info.location.parent / (plugin_info.module + '.py') }}
core: {{ plugin_info.core }}
{% if plugin_info.dependencies %}
dependencies: {{ ', '.join(plugin_info.dependencies) }}
{% endif %}
class: {{ plugin.__module__ + "." + plugin.__class__.__name__ }}
storage namespace: {{ plugin.namespace }}
log destination: {{ plugin.log.name }}
log level: {{ logging.getLevelName(plugin.log.level) }}
{% if plugin.keys %}
**storage content**
Key | Value
-------------------- | -----------------------
{% for key, value in plugin.items() %}{{ key.ljust(20) }} | `{{ value }}`
{% endfor %}
{% endif %}
{% if plugin.config %}
**config content**
Key | Value
-------------------- | -----------------------
{% for key, value in plugin.config.items() %}{{ key.ljust(20) }} | `{{ value }}`
{% endfor %}
{% endif %}
......@@ -376,3 +376,11 @@ def test_multiline_command(testbot):
'!bar title\nfirst line of body\nsecond line of body',
dedent=True
)
def test_plugin_info_command(testbot):
output = testbot.exec_command('!plugin info Help')
assert 'name: Help' in output
assert 'module: help' in output
assert 'help.py' in output
assert 'log level: NOTSET' in output
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment