summaryrefslogtreecommitdiff
path: root/icklib/step_debian_info.py
blob: 5ed26d447f96059a1a5266204a29787d35637967 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Copyright 2016  Lars Wirzenius
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# =*= License: GPL-3+ =*=


import logging

import icklib


class CollectDebianInfoAboutTargets(icklib.BuildStep):

    def build(self):
        wanted = ['debian_arch', 'debian_codename', 'debian_release']
        if getattr(self.run_state, 'collect_debian_info', False):
            for target in self.targets:
                if not all(getattr(target, x, None) for x in wanted):
                    target.debian_arch = self._get_debian_arch(target)
                    os_release = self._get_os_release(target)
                    self._collect_from_os_release(target, os_release)

    def _get_debian_arch(self, target):
        logging.info('Finding Debian arch for %s', target.name)
        output = target.ssh_runcmd(['dpkg', '--print-architecture'])
        return output.strip()

    def _get_os_release(self, target):
        logging.info('Finding os-release for %s', target.name)
        pbuilder_argv = [
            'sudo',
            'pbuilder',
            '--execute',
            '--basetgz', target.pbuilder_ci_tgz,
            '--',
            '/bin/cat', '/etc/os-release',
        ]
        output = target.ssh_runcmd(pbuilder_argv)
        return icklib.parse_os_release(output)

    def _collect_from_os_release(self, target, os_release):
        if os_release.debian_codename:
            codename = os_release.debian_codename
        elif os_release.pretty_codename:
            codename = os_release.pretty_codename
        else:
            assert False, 'os-release has no useful Debian codename'

        # We treat 'sid' specially.
        if codename == 'sid':
            codename = 'unstable'

        target.debian_codename = codename

        if codename == 'unstable':
            release = 'unstable'
        elif os_release.debian_release:
            release = 'debian' + os_release.debian_release
        else:
            assert False, 'os-release has no useful Debian release'
        target.debian_release = release