File: compile_plugin_docs.py

package info (click to toggle)
tuned 2.26.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,280 kB
  • sloc: python: 14,045; sh: 836; makefile: 216; ansic: 178
file content (36 lines) | stat: -rw-r--r-- 958 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

import argparse
import os
import inspect
from tuned.utils.class_loader import ClassLoader
from tuned.plugins.base import Plugin


class PluginDocLoader(ClassLoader):
	def __init__(self):
		super(PluginDocLoader, self).__init__()

	def _set_loader_parameters(self):
		self._namespace = "tuned.plugins"
		self._prefix = "plugin_"
		self._interface = Plugin

parser = argparse.ArgumentParser()
parser.add_argument("intro")
parser.add_argument("out")
args = parser.parse_args()

with open(args.intro, "r") as intro_file:
	intro = intro_file.read()

all_plugins = sorted(PluginDocLoader().load_all_classes(), key=lambda x: x.__module__)

with open(args.out, "w") as out_file:
	out_file.write(intro)
	for plugin in all_plugins:
		plugin_file = inspect.getfile(plugin)
		plugin_name = os.path.basename(plugin_file)[7:-3]
		out_file.write("\n")
		out_file.write("== **%s**\n" % plugin_name)
		out_file.write(inspect.cleandoc(plugin.__doc__))
		out_file.write("\n")