# 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 . # # =*= 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