~dylanmccall/update-manager/dialogs-refactor

« back to all changes in this revision

Viewing changes to janitor/plugincore/core/package_cruft.py

  • Committer: Barry Warsaw
  • Date: 2012-06-11 15:08:35 UTC
  • mto: (2446.1.6 py3)
  • mto: This revision was merged to the branch mainline in revision 2454.
  • Revision ID: barry@python.org-20120611150835-lbx9cjwzfjy3y7bw
Re-integrate the Python 3 Computer Janitor refactoring branch for now.  The
code itself lives in ~computer-janitor-hackers/computer-janitor/py3refactor
and will eventually be ripped out of here, but for now, this unblocks other
folks.

Still getting test failures in `bzr bd -S` though.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2008-2012  Canonical, Ltd.
 
2
#
 
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.
 
6
#
 
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
 
10
# more details.
 
11
#
 
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/>.
 
14
 
 
15
from __future__ import absolute_import, print_function, unicode_literals
 
16
 
 
17
__metaclass__ = type
 
18
__all__ = [
 
19
    'PackageCruft',
 
20
    ]
 
21
 
 
22
 
 
23
from janitor.plugincore.cruft import Cruft
 
24
from janitor.plugincore.i18n import setup_gettext
 
25
_ = setup_gettext()
 
26
 
 
27
 
 
28
class PackageCruft(Cruft):
 
29
    """Cruft that is .deb packages.
 
30
 
 
31
    This type of cruft consists of .deb packages installed onto the system
 
32
    which can be removed.  Various plugins may decide that various packages
 
33
    are cruft; they can all use objects of PackageCruft type to mark such
 
34
    packages, regardless of the reason the packages are considered cruft.
 
35
 
 
36
    When PackageCruft instantiated, the package is identified by an
 
37
    apt.Package object.  That object is used for all the real operations, so
 
38
    this class is merely a thin wrapper around it.
 
39
    """
 
40
 
 
41
    def __init__(self, pkg, description):
 
42
        self._pkg = pkg
 
43
        self._description = description
 
44
 
 
45
    def get_prefix(self):
 
46
        return 'deb'
 
47
 
 
48
    def get_prefix_description(self):
 
49
        return _('.deb package')
 
50
 
 
51
    def get_shortname(self):
 
52
        return self._pkg.name
 
53
 
 
54
    def get_description(self):
 
55
        return '{}\n\n{}'.format(self._description, self._pkg.summary)
 
56
 
 
57
    def get_disk_usage(self):
 
58
        return self._pkg.installedSize
 
59
 
 
60
    def cleanup(self):
 
61
        self._pkg.markDelete()