~dylanmccall/update-manager/dialogs-refactor

« back to all changes in this revision

Viewing changes to janitor/plugincore/core/file_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
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation, version 3 of the License.
 
6
#
 
7
# This program is distributed in the hope that it will be useful,
 
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
# GNU General Public License for more details.
 
11
#
 
12
# You should have received a copy of the GNU General Public License
 
13
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
14
 
 
15
 
 
16
import os
 
17
 
 
18
from janitor.plugincore.cruft import Cruft
 
19
from janitor.plugincore.i18n import setup_gettext
 
20
_ = setup_gettext()
 
21
 
 
22
 
 
23
class FileCruft(Cruft):
 
24
    """Cruft that is individual files.
 
25
 
 
26
    This type of cruft consists of individual files that should be removed.
 
27
    Various plugins may decide that various files are cruft; they can all use
 
28
    objects of FileCruft type to mark such files, regardless of the reason the
 
29
    files are considered cruft.
 
30
    """
 
31
 
 
32
    def __init__(self, pathname, description):
 
33
        self.pathname = pathname
 
34
        self._disk_usage = os.stat(pathname).st_blocks * 512
 
35
        self._description = description
 
36
 
 
37
    def get_prefix(self):
 
38
        return 'file'
 
39
 
 
40
    def get_prefix_description(self):
 
41
        return _('A file on disk')
 
42
 
 
43
    def get_shortname(self):
 
44
        return self.pathname
 
45
 
 
46
    def get_description(self):
 
47
        return '{}\n'.format(self._description)
 
48
 
 
49
    def get_disk_usage(self):
 
50
        return self._disk_usage
 
51
 
 
52
    def cleanup(self):
 
53
        os.remove(self.pathname)