3
from flexget.event import event
4
from flexget.plugin import register_parser_option, plugins
6
log = logging.getLogger('doc')
12
# Convert tabs to spaces (following the normal Python rules)
13
# and split into a list of lines:
14
lines = docstring.expandtabs().splitlines()
15
# Determine minimum indentation (first line doesn't count):
17
for line in lines[1:]:
18
stripped = line.lstrip()
20
indent = min(indent, len(line) - len(stripped))
21
# Remove indentation (first line is special):
22
trimmed = [lines[0].strip()]
23
if indent < sys.maxint:
24
for line in lines[1:]:
25
trimmed.append(line[indent:].rstrip())
26
# Strip off trailing and leading blank lines:
27
while trimmed and not trimmed[-1]:
29
while trimmed and not trimmed[0]:
31
# Return a single string:
32
return '\n'.join(trimmed)
35
@event('manager.startup')
36
def print_doc(manager):
37
if manager.options.doc:
38
manager.disable_feeds()
39
plugin_name = manager.options.doc
40
plugin = plugins.get(plugin_name, None)
42
if not plugin.instance.__doc__:
43
print 'Plugin %s does not have documentation' % plugin_name
46
print trim(plugin.instance.__doc__)
49
print 'Could not find plugin %s' % plugin_name
51
register_parser_option('--doc', action='store', dest='doc', default=False,
52
metavar='PLUGIN', help='Display plugin documentation. See also --plugins.')