aboutsummaryrefslogtreecommitdiffstats
path: root/sos/policies/debian.py
blob: 0d6bcec95fbb77647b6c481617785eeca86e8d26 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from __future__ import with_statement

from sos.plugins import DebianPlugin
from sos.policies import PackageManager, LinuxPolicy
from sos.utilities import shell_out

import os

class DebianPackageManager(PackageManager):

    def _get_deb_list(self):
        pkg_list = shell_out(["dpkg-query",
            "-W",
            "-f=",
        "'${Package}|${Version}\\n' \*"]).splitlines()
        self._debs = {}
        for pkg in pkg_list:
            name, version = pkg.split("|")
            self._debs[name] = {
                    'name': name,
                    'version': version
                    }

    def allPkgs(self):
        if not self._debs:
            self._debs = self._get_deb_list()
        return self._debs


class DebianPolicy(LinuxPolicy):
    def __init__(self):
        super(DebianPolicy, self).__init__()
        self.reportName = ""
        self.ticketNumber = ""
        self.package_manager = DebianPackageManager()
        self.valid_subclasses = [DebianPlugin]
        self.distro = "Debian"

    @classmethod
    def check(self):
        """This method checks to see if we are running on Debian.
           It returns True or False."""
        return os.path.isfile('/etc/debian_version')

    def debianVersion(self):
        try:
            fp = open("/etc/debian_version").read()
            if "wheezy/sid" in fp:
                return 6
            fp.close()
        except:
            pass
        return False