This modifies `lsb-release -r` to be a single-digit alternative (10 instead of 10.5).
Closes: #914287
# LSB release detection module for Debian
# (C) 2005-10 Chris Lawrence <lawrencc@debian.org>
+# (C) 2018 Didier Raboud <odyx@debian.org>
# This package is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
return distinfo
-# Whatever is guessed above can be overridden in /etc/lsb-release
-def get_lsb_information():
+# Whatever is guessed above can be overridden in /usr/lib/os-release by derivatives
+def get_os_release():
distinfo = {}
- etc_lsb_release = os.environ.get('LSB_ETC_LSB_RELEASE','/etc/lsb-release')
- if os.path.exists(etc_lsb_release):
+ os_release = os.environ.get('LSB_OS_RELEASE', '/usr/lib/os-release')
+ if os.path.exists(os_release):
try:
- with open(etc_lsb_release) as lsb_release_file:
- for line in lsb_release_file:
+ with open(os_release) as os_release_file:
+ for line in os_release_file:
line = line.strip()
if not line:
continue
if not '=' in line:
continue
var, arg = line.split('=', 1)
- if var.startswith('DISTRIB_'):
- var = var[8:]
- if arg.startswith('"') and arg.endswith('"'):
- arg = arg[1:-1]
- if arg: # Ignore empty arguments
- distinfo[var] = arg.strip()
+ if arg.startswith('"') and arg.endswith('"'):
+ arg = arg[1:-1]
+ if arg: # Ignore empty arguments
+ # Concert os-release to lsb-release-style
+ if var == 'VERSION_ID':
+ # It'll ignore point-releases
+ distinfo['RELEASE'] = arg.strip()
+ elif var == 'VERSION_CODENAME':
+ distinfo['CODENAME'] = arg.strip()
+ elif var == 'ID':
+ # ID=debian
+ distinfo['ID'] = arg.strip().title()
+ elif var == 'PRETTY_NAME':
+ distinfo['DESCRIPTION'] = arg.strip()
except IOError as msg:
- print('Unable to open ' + etc_lsb_release + ':', str(msg), file=sys.stderr)
-
+ print('Unable to open ' + os_release + ':', str(msg), file=sys.stderr)
+
return distinfo
def get_distro_information():
- lsbinfo = get_lsb_information()
+ lsbinfo = get_os_release()
# OS is only used inside guess_debian_release anyway
for key in ('ID', 'RELEASE', 'CODENAME', 'DESCRIPTION',):
if key not in lsbinfo:
+++ /dev/null
-DISTRIB_ID=(Distributor ID)
-DISTRIB_DESCRIPTION=(A human-readable description of the release)
-DISTRIB_RELEASE=(The release number)
-DISTRIB_CODENAME=(The codename for the release)
-OTHER_VARIABLE=Not supposed to exist
--- /dev/null
+PRETTY_NAME="(A human-readable description of the release)"
+NAME="(The standard name of the distribution)"
+VERSION_ID="(The release number)"
+VERSION="(The release number + codename)"
+ID="(distributor id)"
--- /dev/null
+PRETTY_NAME="(A human-readable description of the release)"
+NAME="(The standard name of the distribution)"
+ID="(distributor id)"
os.environ.pop('LSB_ETC_DEBIAN_VERSION')
os.environ.pop('TEST_APT_CACHE_UNSTABLE')
- def test_get_lsb_information(self):
- # Test that an inexistant /etc/lsb-release leads to empty output
+ def test_get_os_release(self):
+ # Test that an inexistant /usr/lib/os-release leads to empty output
supposed_output = {}
- os.environ['LSB_ETC_LSB_RELEASE'] = 'test/inexistant_file_' + rnd_string(2,5)
- self.assertEqual(lr.get_lsb_information(),supposed_output)
- # Test that a fake /etc/lsb-release leads to output with only the content we want
+ os.environ['LSB_OS_RELEASE'] = 'test/inexistant_file_' + rnd_string(2,5)
+ self.assertEqual(lr.get_os_release(),supposed_output)
+ # Test that a fake full /usr/lib/os-release leads to output with only the content we want
supposed_output = {'RELEASE': '(The release number)',
- 'CODENAME': '(The codename for the release)',
- 'ID': '(Distributor ID)',
+ 'ID': '(Distributor Id)',
'DESCRIPTION': '(A human-readable description of the release)'}
- os.environ['LSB_ETC_LSB_RELEASE'] = 'test/lsb-release'
- self.assertEqual(lr.get_lsb_information(),supposed_output)
- os.environ.pop('LSB_ETC_LSB_RELEASE')
+ os.environ['LSB_OS_RELEASE'] = 'test/os-release'
+ self.assertEqual(lr.get_os_release(),supposed_output)
+ # Test that a fake minimal /usr/lib/os-release leads to output with only the content we want
+ supposed_output = {'ID': '(Distributor Id)',
+ 'DESCRIPTION': '(A human-readable description of the release)'}
+ os.environ['LSB_OS_RELEASE'] = 'test/os-release-minimal'
+ self.assertEqual(lr.get_os_release(),supposed_output)
+ os.environ.pop('LSB_OS_RELEASE')
def test_get_distro_information_no_distinfo_file(self):
# Test that a missing /usr/share/distro-info/{distro}.csv indeed falls
self.assertEqual(debian_info, other_distro_info)
def test_get_distro_information(self):
- # Test that an inexistant /etc/lsb-release leads to empty output
+ # Test that an inexistant /usr/lib/os-release leads to empty output
supposed_output = get_arch_distinfo()
supposed_output['RELEASE'] = 'testing/unstable';
supposed_output['DESCRIPTION'] = '%(ID)s %(OS)s %(RELEASE)s' % supposed_output
- os.environ['LSB_ETC_LSB_RELEASE'] = 'test/inexistant_file_' + rnd_string(2,5)
+ os.environ['LSB_OS_RELEASE'] = 'test/inexistant_file_' + rnd_string(2,5)
fn = 'test/debian_version_' + rnd_string(5,12)
f = open(fn,'w')
f.write('testing/sid')