~straemer/ubuntu/quantal/update-manager/fix-for-1058070

« back to all changes in this revision

Viewing changes to Janitor/computerjanitor/cruft.py

  • Committer: Package Import Robot
  • Author(s): Colin Watson, Colin Watson, Adam Conrad, Barry Warsaw, Michael Vogt, Stéphane Graber, Steve Langasek
  • Date: 2012-06-14 00:57:42 UTC
  • Revision ID: package-import@ubuntu.com-20120614005742-2tnicupbt5io911y
Tags: 1:0.163
[ Colin Watson ]
* Isolate tests from local configuration in
  /etc/update-manager/release-upgrades.d/.
* Use Python attributes rather than GObject.get_data and GObject.set_data,
  which have been removed upstream (LP: #1009859).
* Switch default view class to Gtk3 and replace python-gobject dependency
  with python-gi.
* Port away from old-style apt.Package candidateFoo and installedFoo
  properties, preferring candidate.foo and installed.foo.  In a number of
  cases we have to check whether candidate/installed is non-None first.
* Use apt_pkg.version_compare rather than apt_pkg.VersionCompare.
* Use apt_pkg.uri_to_filename rather than apt_pkg.URItoFileName.
* Use apt_pkg.TagFile (and related new-style API) rather than
  apt_pkg.ParseTagFile.
* Use apt_pkg.PackageManager rather than apt_pkg.GetPackageManager.
* Use apt_pkg.Acquire rather than apt_pkg.GetAcquire.
* Use mark_foo/marked_foo rather than markFoo/markedFoo.
* Use apt_pkg.ActionGroup rather than apt_pkg.GetPkgActionGroup.
* Use apt_pkg.ProblemResolver rather than apt_pkg.GetPkgProblemResolver.
* Use apt_pkg.read_config_file rather than apt_pkg.ReadConfigFile.
* Use new spelling of apt_pkg.DepCache methods.
* Rename several local cache methods to PEP-8 style to avoid showing up in
  the output of /usr/share/python-apt/migrate-0.8.py.
* Use apt_pkg.size_to_str rather than apt_pkg.SizeToStr.
* Use apt_pkg.PackageManager.get_archives rather than
  apt_pkg.PackageManager.GetArchives.
* Use apt_pkg.Acquire.fetch_needed rather than
  apt_pkg.Acquire.FetchNeeded.
* Use new spelling of apt_pkg.Package/Version/Dependency methods.
* Use apt_pkg.pkgsystem_lock rather than apt_pkg.PkgSystemLock.
* Use new spelling of apt_pkg dependency parsing methods.
* Use new spelling of apt_pkg.SourceList methods.
* Bump python-apt (build-)dependency to >= 0.8.0.
* Add a scheme for excluding false positives from the pyflakes test, and
  enable it by default.
* Rearrange the OptionParser workaround from 1:0.154.5 to work with Python
  3, using gettext or ugettext as appropriate.
* Always pass bytes to hashlib.md5.update.
* Fix DistUpgradeAptCdrom to account for gzip files being opened in binary
  mode.
* Convert the last use of os.popen to subprocess.check_output, which makes
  it easier to read str rather than bytes.  (This requires Python 2.7.)
* Decode bytes read from urlopened file objects.
* UpdateManager/backend/InstallBackendSynaptic.py
  - Keep a reference to the data tuple passed to GObject.child_watch_add
    to avoid attempts to destroy it without a thread context
    (LP: #724687).
  - Open temporary synaptic selections file in text mode.
* Define __bool__ rather than __nonzero__ method in Python 3.
* sort(cmp=) and sorted(cmp=) no longer work in Python 3.  Use appropriate
  key= arguments instead.
* Fix ResourceWarning while reading /proc/mounts.
* Make update-manager-kde depend on psmisc, for killall.
* DistUpgrade/DistUpgradeView.py:
  - Use floor division in FuzzyTimeToStr.
* DistUpgrade/DistUpgradeViewText.py:
  - Flush stdout after printing confirmation message, since it doesn't
    have a trailing newline.
* Use the appropriate Unicode gettext methods in both Python 2 and 3, and
  drop lots of Python-3-unfriendly Unicode mangling as a result.
* DistUpgrade/DistUpgradeViewKDE.py:
  - Open the terminal log in binary mode.
* data/do-release-upgrade.8:
  - Provide a more useful NAME section.
* DistUpgrade/DistUpgradeCache.py:
  - Tolerate SyntaxError from attempting to import NvidiaDetector, until
    such time as a complete ubuntu-drivers-common Python 3 port is in the
    archive.
* Switch #! lines over to python3, apart from dist-upgrader which needs to
  stay as Python 2 for a while longer (and have some special arrangement
  for running with Python 3 for upgrades from >= quantal).
* Run tests under both Python 2 and 3.

[ Adam Conrad ]
* Merge branch from Michael Terry to drop auto-upgrade-tester
  from update-manager and move it into its own source package

[ Barry Warsaw ]
* Begin refactoring of Computer Janitor code by renaming and
  re-situating all of it to janitor/plugincore.  This will eventually be
  removed from here into its own separate branch.
* Merge the temporary Python 3 sprint branch back into trunk, and close
  the py3 sprint branch.
* Moved UpdateManager/backend and UpdateManager/UnitySupport.py to the
  python*-update-manager packages for apturl.

[ Michael Vogt ]
* UpdateManager/GtkProgress.py:
  - fix python-apt 0.8 API crash

[ Stéphane Graber ]
* Drop fdsend as it's not used and doesn't build with python3.
* Make update-manager-core a binary all packages (everything is python).
* Split update-manager-core into python-update-manager,
  python3-update-manager and update-manager-core.
* Build-depend and depend on python-apt >= 0.8.5~ as we need proper
  python3 support.

[ Steve Langasek ]
* tests/test_country_mirror.py: the test suite shouldn't fail if $LANG
  isn't set in the environment.
* update-manager is now using python3 as an interpreter, so fix these up
  to actually be python3 packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# cruft.py - base class for different kinds of cruft
2
 
# Copyright (C) 2008  Canonical, Ltd.
3
 
#
4
 
# This program is free software: you can redistribute it and/or modify
5
 
# it under the terms of the GNU General Public License as published by
6
 
# the Free Software Foundation, version 3 of the License.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
 
16
 
 
17
 
import computerjanitor
18
 
 
19
 
 
20
 
class Cruft(object):
21
 
 
22
 
    """One piece of cruft to be cleaned out.
23
 
 
24
 
    A piece of cruft can be a file, a package, a configuration tweak
25
 
    that is missing, or something else.
26
 
    
27
 
    This is a base class, which does nothing. Subclasses do the
28
 
    actual work.
29
 
    
30
 
    """
31
 
 
32
 
    def get_prefix(self):
33
 
        """Return the unique prefix used to group this type of cruft.
34
 
        
35
 
        For example, the .deb package called 'foo' would have a prefix
36
 
        of 'deb'. This way, the package foo is not confused with the
37
 
        file foo, or the username foo.
38
 
        
39
 
        Subclasses SHOULD define this. The default implementation
40
 
        returns the name of the class, which is rarely useful to
41
 
        the user.
42
 
        
43
 
        """
44
 
        
45
 
        return self.__class__.__name__
46
 
    
47
 
    def get_prefix_description(self):
48
 
        """Return human-readable description of class of cruft."""
49
 
        return self.get_description()
50
 
    
51
 
    def get_shortname(self):
52
 
        """Return the name of this piece of cruft.
53
 
        
54
 
        The name should be something that the user will understand.
55
 
        For example, it might be the name of a package, or the full
56
 
        path to a file.
57
 
        
58
 
        The name should be unique within the unique prefix returned
59
 
        by get_prefix. The prefix MUST NOT be included by this method,
60
 
        the get_name() method does that instead. The intent is that
61
 
        get_shortname() will be used by the user interface in contexts
62
 
        where the prefix is shown separately from the short name,
63
 
        and get_name() when a single string is used.
64
 
        
65
 
        Subclasses MUST define this. The default implementation
66
 
        raises an exception.
67
 
        
68
 
        """
69
 
 
70
 
        raise computerjanitor.UnimplementedMethod(self.get_shortname)
71
 
 
72
 
    def get_name(self):
73
 
        """Return prefix plus name.
74
 
        
75
 
        See get_prefix() and get_shortname() for a discussion of
76
 
        the prefix and the short name. This method will return
77
 
        the prefix, a colon, and the short name.
78
 
 
79
 
        The long name will used to store state/configuration data:
80
 
        _this_ package should not be removed.
81
 
        
82
 
        """
83
 
 
84
 
        return "%s:%s" % (self.get_prefix(), self.get_shortname())
85
 
        
86
 
    def get_description(self):
87
 
        """Return a description of this piece of cruft.
88
 
        
89
 
        This may be arbitrarily long. The user interface will take
90
 
        care of breaking it into lines or otherwise presenting it to
91
 
        the user in a nice manner. The description should be plain
92
 
        text, in UTF-8.
93
 
        
94
 
        The default implementation returns the empty string. Subclasses
95
 
        MAY override this as they wish.
96
 
        
97
 
        """
98
 
        
99
 
        return ""
100
 
    
101
 
    def get_disk_usage(self):
102
 
        """Return amount of disk space reserved by this piece of cruft.
103
 
        
104
 
        The unit is bytes.
105
 
        
106
 
        The disk space in question should be the amount that will be
107
 
        freed if the cruft is cleaned up. The amount may be an estimate
108
 
        (read: guess). It is intended to be shown to the user to help
109
 
        them decide what to remove and what to keep.
110
 
        
111
 
        This will also be used by the user interface to better
112
 
        estimate how much remaining time there is when cleaning
113
 
        up a lot of cruft.
114
 
        
115
 
        For some types of cruft, this is not applicable and they should
116
 
        return None. The base class implementation does that, so
117
 
        subclasses MUST define this method if it is useful for them to
118
 
        return something else.
119
 
        
120
 
        The user interface will distinguish between None (not
121
 
        applicable) and 0 (no disk space being used).
122
 
        
123
 
        """
124
 
        
125
 
        return None
126
 
    
127
 
    def cleanup(self):
128
 
        """Clean up this piece of cruft.
129
 
        
130
 
        Depending on the type of cruft, this may mean removing files,
131
 
        packages, modifying configuration files, or something else.
132
 
        
133
 
        The default implementation raises an exception. Subclasses
134
 
        MUST override this.
135
 
        
136
 
        """
137
 
        
138
 
        raise computerjanitor.UnimplementedMethod(self.cleanup)