Skip to content

Commit c4ae3d1

Browse files
authored
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...
1 parent 25769b2 commit c4ae3d1

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

errbot/core_plugins/plugins.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from pprint import pformat
33
import os
44
import shutil
5+
import logging
56

67
from errbot import BotPlugin, botcmd
78
from errbot.plugin_manager import PluginConfigurationException, PluginActivationException
@@ -303,3 +304,14 @@ def plugin_unblacklist(self, _, args):
303304
return f'Error activating plugin: {pae}'
304305

305306
return self._bot.plugin_manager.unblacklist_plugin(args)
307+
308+
@botcmd(admin_only=True, template='plugin_info')
309+
def plugin_info(self, _, args):
310+
"""Gives you a more technical information about a specific plugin."""
311+
pm = self._bot.plugin_manager
312+
if args not in pm.get_all_plugin_names():
313+
return (f"{args} isn't a valid plugin name. The current plugins are:\n"
314+
f"{self.formatted_plugin_list(active_only=False)}")
315+
return {'plugin_info': pm.plugin_infos[args],
316+
'plugin': pm.plugins[args],
317+
'logging': logging}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#### Plugin info from {{ plugin_info.location }}
2+
name: {{ plugin_info.name }}
3+
4+
module: {{ plugin_info.module }}
5+
6+
full_module_path: {{ plugin_info.location.parent / (plugin_info.module + '.py') }}
7+
8+
core: {{ plugin_info.core }}
9+
10+
{% if plugin_info.dependencies %}
11+
dependencies: {{ ', '.join(plugin_info.dependencies) }}
12+
{% endif %}
13+
14+
class: {{ plugin.__module__ + "." + plugin.__class__.__name__ }}
15+
16+
storage namespace: {{ plugin.namespace }}
17+
18+
log destination: {{ plugin.log.name }}
19+
20+
log level: {{ logging.getLevelName(plugin.log.level) }}
21+
22+
{% if plugin.keys %}
23+
**storage content**
24+
25+
Key | Value
26+
-------------------- | -----------------------
27+
{% for key, value in plugin.items() %}{{ key.ljust(20) }} | `{{ value }}`
28+
{% endfor %}
29+
{% endif %}
30+
31+
{% if plugin.config %}
32+
**config content**
33+
34+
Key | Value
35+
-------------------- | -----------------------
36+
{% for key, value in plugin.config.items() %}{{ key.ljust(20) }} | `{{ value }}`
37+
{% endfor %}
38+
{% endif %}
39+
40+
41+
42+

tests/commands_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,11 @@ def test_multiline_command(testbot):
376376
'!bar title\nfirst line of body\nsecond line of body',
377377
dedent=True
378378
)
379+
380+
381+
def test_plugin_info_command(testbot):
382+
output = testbot.exec_command('!plugin info Help')
383+
assert 'name: Help' in output
384+
assert 'module: help' in output
385+
assert 'help.py' in output
386+
assert 'log level: NOTSET' in output

0 commit comments

Comments
 (0)