Apache/2.4.7 (Ubuntu) Linux sman1baleendah 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) safemode : OFF MySQL: ON | Perl: ON | cURL: OFF | WGet: ON > / usr / lib / python3 / dist-packages / janitor / plugincore / | server ip : 172.67.156.115 your ip : 172.70.126.203 H O M E |
Filename | /usr/lib/python3/dist-packages/janitor/plugincore/plugin.py |
Size | 2.5 kb |
Permission | rw-r--r-- |
Owner | root : root |
Create time | 27-Apr-2025 09:55 |
Last modified | 05-Dec-2012 23:29 |
Last accessed | 07-Jul-2025 00:18 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
# Copyright (C) 2008-2012 Canonical, Ltd.
# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
'Plugin',
]
from janitor.plugincore.exceptions import UnimplementedMethod
class Plugin:
"""Base class for plugins.
These plugins only do one thing: identify cruft. See the 'get_cruft'
method for details.
"""
# XXX BAW 2012-06-08: For historical reasons, we do not set
# self._condition or self.app in a constructor. This needs to be fixed.
@property
def condition(self):
return (self._condition if hasattr(self, '_condition') else [])
@condition.setter
def condition(self, condition):
self._condition = condition
def set_application(self, app):
"""Set the Application instance this plugin belongs to."""
self.app = app
def do_cleanup_cruft(self):
"""Find cruft and clean it up.
This is a helper method.
"""
for cruft in self.get_cruft():
cruft.cleanup()
self.post_cleanup()
def get_cruft(self):
"""Find some cruft in the system.
This method MUST return an iterator (see 'yield' statement).
This interface design allows cruft to be collected piecemeal,
which makes it easier to show progress in the user interface.
The base class default implementation of this raises an
exception. Subclasses MUST override this method.
"""
raise UnimplementedMethod(self.get_cruft)
@property
def cruft(self):
for cruft in self.get_cruft():
yield cruft
def post_cleanup(self):
"""Do plugin-wide cleanup after the individual cleanup was performed.
This is useful for stuff that needs to be processed in batches
(e.g. for performance reasons) like package removal.
"""
pass
# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
'Plugin',
]
from janitor.plugincore.exceptions import UnimplementedMethod
class Plugin:
"""Base class for plugins.
These plugins only do one thing: identify cruft. See the 'get_cruft'
method for details.
"""
# XXX BAW 2012-06-08: For historical reasons, we do not set
# self._condition or self.app in a constructor. This needs to be fixed.
@property
def condition(self):
return (self._condition if hasattr(self, '_condition') else [])
@condition.setter
def condition(self, condition):
self._condition = condition
def set_application(self, app):
"""Set the Application instance this plugin belongs to."""
self.app = app
def do_cleanup_cruft(self):
"""Find cruft and clean it up.
This is a helper method.
"""
for cruft in self.get_cruft():
cruft.cleanup()
self.post_cleanup()
def get_cruft(self):
"""Find some cruft in the system.
This method MUST return an iterator (see 'yield' statement).
This interface design allows cruft to be collected piecemeal,
which makes it easier to show progress in the user interface.
The base class default implementation of this raises an
exception. Subclasses MUST override this method.
"""
raise UnimplementedMethod(self.get_cruft)
@property
def cruft(self):
for cruft in self.get_cruft():
yield cruft
def post_cleanup(self):
"""Do plugin-wide cleanup after the individual cleanup was performed.
This is useful for stuff that needs to be processed in batches
(e.g. for performance reasons) like package removal.
"""
pass