1
2
3
4
5 """
6
7 Base plugin class
8 =================
9
10 All plugins should inherit doapfiend.plugins.Plugin
11
12 """
13
14
15 import textwrap
16
18 """Base class for doapfiend plugins. It's not necessary to subclass this
19 class to create a plugin; however, all plugins must implement
20 `add_options(self, parser)` and `configure(self, options,
21 conf)`, and must have the attributes `enabled` and `name`.
22
23 Plugins should not be enabled by default.
24
25 Subclassing Plugin will give your plugin some friendly default
26 behavior:
27
28 - A --with-$name option will be added to the command line
29 interface to enable the plugin. The plugin class's docstring
30 will be used as the help for this option.
31 - The plugin will not be enabled unless this option is selected by
32 the user.
33 """
34 enabled = False
35 enable_opt = None
36 name = None
37
39 self.conf = None
40 if self.name is None:
41 self.name = self.__class__.__name__.lower()
42 if self.enable_opt is None:
43 self.enable_opt = "enable_plugin_%s" % self.name
44
46 """Add command-line options for this plugin.
47
48 The base plugin class adds --with-$name by default, used to enable the
49 plugin.
50 """
51 parser.add_option("--with-%s" % self.name,
52 action="store_true",
53 dest=self.enable_opt,
54 help="Enable plugin %s: %s" %
55 (self.__class__.__name__, self.help())
56 )
57
68
70 """Return help for this plugin. This will be output as the help
71 section of the --with-$name option that enables the plugin.
72 """
73 if self.__class__.__doc__:
74
75 return textwrap.dedent(self.__class__.__doc__)
76 return "(no help available)"
77