From f1c643ddea69c526a1040c9768a4efd36a86e574 Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Mon, 14 Apr 2014 20:09:19 +0100 Subject: [PATCH] Add default Plugin.setup() method Adding a default setup() method to the base Plugin class allows useful plugins to be written declaratively by setting the 'files' and 'packages' members of the subclass, e.g.: class FooPlugin(Plugin): plugin_name = 'foo' packages = ('foo',) files = ('/etc/foo.conf',) Creates a plugin class named 'foo' that will run whenever the 'foo' package is installed or the '/etc/foo.conf' file exists. The method calls self.add_copy_specs() with the plugin's files list. Signed-off-by: Bryn M. Reeves --- sos/plugins/__init__.py | 7 ++++--- sos/plugins/anacron.py | 3 --- sos/plugins/distupgrade.py | 2 -- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index a599c714b7..6cac31c4e1 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -647,10 +647,11 @@ def default_enabled(self): return True def setup(self): - """This method must be overridden to add the copy_specs, forbidden_paths, - and external programs to be collected at a minimum. + """Collect the list of files declared by the plugin. This method + may be overridden to add further copy_specs, forbidden_paths, and + external programs if required. """ - pass + self.add_copy_specs(list(self.files)) def postproc(self): """ diff --git a/sos/plugins/anacron.py b/sos/plugins/anacron.py index 60efa27b67..a5635355ed 100644 --- a/sos/plugins/anacron.py +++ b/sos/plugins/anacron.py @@ -25,7 +25,4 @@ class Anacron(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin): # just look for the configuration file which is common files = ('/etc/anacrontab',) - def setup(self): - self.add_copy_specs(list(self.files)) - # vim: et ts=4 sw=4 diff --git a/sos/plugins/distupgrade.py b/sos/plugins/distupgrade.py index d618dfc678..8bc44c23c2 100644 --- a/sos/plugins/distupgrade.py +++ b/sos/plugins/distupgrade.py @@ -24,8 +24,6 @@ class DistUpgrade(Plugin): files = None - def setup(self): - self.add_copy_specs(list(self.files)) class RedHatDistUpgrade(DistUpgrade, RedHatPlugin):