summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Client/Tools/APK.py
blob: 7313f6fcc726765e32719fb4a0cf22d1d6b0bf9f (plain)
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
54
"""This provides Bcfg2 support for Alpine Linux APK packages."""

import Bcfg2.Client.Tools


class APK(Bcfg2.Client.Tools.PkgTool):
    """Support for Apk packages."""
    name = 'APK'
    __execs__ = ["/sbin/apk"]
    __handles__ = [('Package', 'apk')]
    __req__ = {'Package': ['name', 'version']}
    pkgtype = 'apk'
    pkgtool = ("/sbin/apk add %s", ("%s", ["name"]))

    def RefreshPackages(self):
        """Refresh memory hashes of packages."""
        names = self.cmd.run("/sbin/apk info").stdout.splitlines()
        nameversions = self.cmd.run("/sbin/apk info -v").stdout.splitlines()
        for pkg in zip(names, nameversions):
            pkgname = pkg[0]
            version = pkg[1][len(pkgname) + 1:]
            self.logger.debug(" pkgname: %s" % pkgname)
            self.logger.debug(" version: %s" % version)
            self.installed[pkgname] = version

    def VerifyPackage(self, entry, _):
        """Verify Package status for entry."""
        if 'version' not in entry.attrib:
            self.logger.info("Cannot verify unversioned package %s" %
                             entry.attrib['name'])
            return False

        if entry.attrib['name'] in self.installed:
            if entry.attrib['version'] in \
                    ['auto', self.installed[entry.attrib['name']]]:
                # FIXME: Does APK have any sort of verification mechanism?
                return True
            else:
                self.logger.info(" pkg %s at version %s, not %s" %
                                 (entry.attrib['name'],
                                  self.installed[entry.attrib['name']],
                                  entry.attrib['version']))
                entry.set('current_version', self.installed[entry.get('name')])
                return False
        entry.set('current_exists', 'false')
        return False

    def Remove(self, packages):
        """Remove extra packages."""
        names = [pkg.get('name') for pkg in packages]
        self.logger.info("Removing packages: %s" % " ".join(names))
        self.cmd.run("/sbin/apk del %s" % " ".join(names))
        self.RefreshPackages()
        self.extra = self.FindExtra()