summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2016-02-07 18:11:41 +0200
committerLars Wirzenius <liw@liw.fi>2016-02-07 19:33:36 +0200
commit6ed0857719d564e9789fc25af395c59ac22955af (patch)
treea56364a523533bb8c5714744198bde5907ac14c1
parent56993a04d78fc3b875e6321d2acfab94532328e4 (diff)
downloadick-6ed0857719d564e9789fc25af395c59ac22955af.tar.gz
Get target's codename, release from /etc/os-release
-rw-r--r--NEWS8
-rw-r--r--doc/070-pipeline.yarn8
-rw-r--r--icklib/__init__.py1
-rw-r--r--icklib/os_release.py56
-rw-r--r--icklib/os_release_tests.py59
-rw-r--r--icklib/project.py42
6 files changed, 158 insertions, 16 deletions
diff --git a/NEWS b/NEWS
index f92bd7b..c86679f 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,14 @@
NEWS for Ick
============
+Version 0.11, released UNRELEASED
+---------------------------------
+
+* Get a target's Debian code name and release version from the
+ /etc/os-release file in the pbuilder tarball, not the host directly.
+ This should allow one host be used to build for several Debian
+ releases, by virtue of having many pbuilder tarballs.
+
Version 0.10, released 2016-01-08
---------------------------------
diff --git a/doc/070-pipeline.yarn b/doc/070-pipeline.yarn
index a5d29fd..ebfcee1 100644
--- a/doc/070-pipeline.yarn
+++ b/doc/070-pipeline.yarn
@@ -63,8 +63,8 @@ separately.
WHEN user runs ick foo.ick
THEN the APT repository for foo.ick contains foo_3.2-1.dsc
THEN the APT repository for foo.ick contains foo_3.2-1_all.deb
- THEN the APT repository for foo.ick contains foo_3.2-1.debian8.*.dsc
- THEN the APT repository for foo.ick contains foo_3.2-1.debian8.*_all.deb
+ THEN the APT repository for foo.ick contains foo_3.2-1.debian8*.dsc
+ THEN the APT repository for foo.ick contains foo_3.2-1.debian8*_all.deb
## Separate repositories for upstream code and package ("a la Daniel")
@@ -138,5 +138,5 @@ separately.
WHEN user runs ick foo.ick
THEN the APT repository for foo.ick contains foo_3.2-1.dsc
THEN the APT repository for foo.ick contains foo_3.2-1_all.deb
- THEN the APT repository for foo.ick contains foo_3.2-1.debian8.*.dsc
- THEN the APT repository for foo.ick contains foo_3.2-1.debian8.*_all.deb
+ THEN the APT repository for foo.ick contains foo_3.2-1.debian8*.dsc
+ THEN the APT repository for foo.ick contains foo_3.2-1.debian8*_all.deb
diff --git a/icklib/__init__.py b/icklib/__init__.py
index d82fa71..e2c401c 100644
--- a/icklib/__init__.py
+++ b/icklib/__init__.py
@@ -21,6 +21,7 @@ from .target import Target, create_targets_from_ick
from .build_step import BuildStep
from .run_state import RunState
from .pipeline import BuildPipeline
+from .os_release import parse_os_release, OsRelease, NoOsReleaseInformation
from .project import create_projects_from_ick
from .git import GitClone
from .info import InformationStore
diff --git a/icklib/os_release.py b/icklib/os_release.py
new file mode 100644
index 0000000..e4b04fa
--- /dev/null
+++ b/icklib/os_release.py
@@ -0,0 +1,56 @@
+# 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 re
+
+
+patterns = {
+ 'debian_codename': r'^VERSION="\d+ \((.*)\)"$',
+ 'debian_release': r'^VERSION="(\d+) ',
+ 'pretty_codename': r'^PRETTY_NAME="Debian GNU/Linux .*/(sid)"$',
+}
+
+
+def parse_os_release(text):
+ o = OsRelease()
+
+ found_anything = False
+ for line in text.splitlines():
+ for name, pattern in patterns.items():
+ m = re.match(pattern, line)
+ if m:
+ setattr(o, name, m.group(1))
+ found_anything = True
+
+ if found_anything:
+ return o
+ raise NoOsReleaseInformation(text)
+
+
+class OsRelease(object):
+
+ def __init__(self):
+ self.debian_codename = None
+ self.debian_release = None
+
+
+class NoOsReleaseInformation(Exception):
+
+ def __init__(self, text):
+ super(NoOsReleaseInformation, self).__init__(
+ "Can't parse /etc/os-release: %r" % text)
diff --git a/icklib/os_release_tests.py b/icklib/os_release_tests.py
new file mode 100644
index 0000000..b443264
--- /dev/null
+++ b/icklib/os_release_tests.py
@@ -0,0 +1,59 @@
+# 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 unittest
+
+import icklib
+
+
+jessie_output = '''\
+PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
+NAME="Debian GNU/Linux"
+VERSION_ID="8"
+VERSION="8 (jessie)"
+ID=debian
+HOME_URL="http://www.debian.org/"
+SUPPORT_URL="http://www.debian.org/support"
+BUG_REPORT_URL="https://bugs.debian.org/"
+'''
+
+
+unstable_output = '''\
+PRETTY_NAME="Debian GNU/Linux stretch/sid"
+NAME="Debian GNU/Linux"
+ID=debian
+HOME_URL="https://www.debian.org/"
+SUPPORT_URL="https://www.debian.org/support"
+BUG_REPORT_URL="https://bugs.debian.org/"
+'''
+
+class OsReleaseTests(unittest.TestCase):
+
+ def test_raises_error_if_nothing_can_be_parsed(self):
+ with self.assertRaises(icklib.NoOsReleaseInformation):
+ icklib.parse_os_release('')
+
+ def test_parse_jessie_os_release_ok(self):
+ o = icklib.parse_os_release(jessie_output)
+ self.assertEqual(o.debian_codename, 'jessie')
+ self.assertEqual(o.debian_release, '8')
+
+ def test_parse_unstable_os_release_ok(self):
+ o = icklib.parse_os_release(unstable_output)
+ self.assertEqual(o.pretty_codename, 'sid')
+ self.assertEqual(o.debian_release, None)
diff --git a/icklib/project.py b/icklib/project.py
index 335c87e..4452cf9 100644
--- a/icklib/project.py
+++ b/icklib/project.py
@@ -518,28 +518,46 @@ class CollectDebianInfoAboutTargets(icklib.BuildStep):
if getattr(self.run_state, 'collect_debian_info', False):
for target in self.targets:
target.debian_arch = self._get_debian_arch(target)
- target.debian_codename = self._get_debian_codename(target)
- target.debian_release = self._get_debian_release(target)
+ os_release = self._get_os_release(target)
+ self._collect_from_os_release(target, os_release)
def _get_debian_arch(self, target):
output = target.ssh_runcmd(['dpkg', '--print-architecture'])
return output.strip()
- def _get_debian_codename(self, target):
- output = target.ssh_runcmd(['lsb_release', '-cs'])
- codename = output.strip()
+ def _get_os_release(self, target):
+ 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'
- return codename
+
+ target.debian_codename = codename
- def _get_debian_release(self, target):
- output = target.ssh_runcmd(['lsb_release', '-rs'])
- release = output.strip()
- if release == 'unstable':
- return release
+ if codename == 'unstable':
+ release = 'unstable'
+ elif os_release.debian_release:
+ release = 'debian' + os_release.debian_release
else:
- return 'debian' + release
+ assert False, 'os-release has no useful Debian release'
+ target.debian_release = release
class CreateCITarball(icklib.BuildStep):