1
# Copyright (C) 2008-2012 Canonical, Ltd.
3
# This program is free software: you can redistribute it and/or modify it
4
# under the terms of the GNU General Public License as published by the Free
5
# Software Foundation, version 3 of the License.
7
# This program is distributed in the hope that it will be useful, but WITHOUT
8
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
# You should have received a copy of the GNU General Public License along with
13
# this program. If not, see <http://www.gnu.org/licenses/>.
16
from __future__ import absolute_import, print_function, unicode_literals
24
from janitor.plugincore.exceptions import UnimplementedMethod
28
"""Base class for plugins.
30
These plugins only do one thing: identify cruft. See the 'get_cruft'
34
# XXX BAW 2012-06-08: For historical reasons, we do not set
35
# self._condition or self.app in a constructor. This needs to be fixed.
39
return (self._condition if hasattr(self, '_condition') else [])
42
def condition(self, condition):
43
self._condition = condition
45
def set_application(self, app):
46
"""Set the Application instance this plugin belongs to."""
49
def do_cleanup_cruft(self):
50
"""Find cruft and clean it up.
52
This is a helper method.
54
for cruft in self.get_cruft():
59
"""Find some cruft in the system.
61
This method MUST return an iterator (see 'yield' statement).
62
This interface design allows cruft to be collected piecemeal,
63
which makes it easier to show progress in the user interface.
65
The base class default implementation of this raises an
66
exception. Subclasses MUST override this method.
68
raise UnimplementedMethod(self.get_cruft)
72
for cruft in self.get_cruft():
75
def post_cleanup(self):
76
"""Do plugin-wide cleanup after the individual cleanup was performed.
78
This is useful for stuff that needs to be processed in batches
79
(e.g. for performance reasons) like package removal.