~ubuntu-branches/ubuntu/karmic/computer-janitor/karmic

1.1.1 by Lars Wirzenius
Import upstream version 1.12
1
# landscape_stub_plugin.py
2
# Copyright (C) 2009  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 os
18
19
import computerjanitor
6 by Lars Wirzenius
* plugins/*.py: Fix to use the computerjanitorapp gettext instance,
20
import computerjanitorapp
21
_ = computerjanitorapp.setup_gettext()
1.1.1 by Lars Wirzenius
Import upstream version 1.12
22
23
24
class LandscapePackageCruft(computerjanitor.PackageCruft):
25
    def __init__(self, app, pkg, description):
26
        computerjanitor.PackageCruft.__init__(self, pkg, description)
27
        self.app = app
28
    
29
    def cleanup(self):
30
        self.app.apt_cache.markRemove(self._pkg.name, 
31
                                  "custom landscape stub removal rule")
32
        if self.app.apt_cache.has_key("landscape-common"):
33
            self.app.apt_cache["landscape-common"].markKeep()
34
            self.app.apt_cache.markInstall("landscape-common", 
35
                                       "custom landscape-common stub install rule (to ensure its nor marked for auto-remove)")
36
37
class LandscapeStubPlugin(computerjanitor.Plugin):
38
39
    """Plugin to remove landscape-client (in desktop mode).
40
       It was a stub anyway and is more useful on the server """
41
42
    description = _("Remove landscape-client stub")
43
44
    def __init__(self):
45
        self.condition = ["from_hardyPostDistUpgradeCache"]
46
47
    def get_cruft(self):
48
        if not hasattr(self.app, "serverMode"): # pragma: no cover
49
            return
50
        name = "landscape-client"
51
        ver = "0.1"
52
        if not self.app.serverMode:
53
            if (self.app.apt_cache.has_key(name) and
54
                self.app.apt_cache[name].installedVersion == ver):
55
                yield LandscapePackageCruft(self.app,
56
                                            self.app.apt_cache[name],
57
                                            self.description)