[gnome-continuous-yocto/gnomeostree-3.28-rocko: 3337/8267] lib/oe/lsb: prefer /etc/os-release for distribution data
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-continuous-yocto/gnomeostree-3.28-rocko: 3337/8267] lib/oe/lsb: prefer /etc/os-release for distribution data
- Date: Sun, 17 Dec 2017 00:29:30 +0000 (UTC)
commit 42441ea4819dfeca7183f6a095c99708124ded5d
Author: Joshua Lock <joshua g lock intel com>
Date: Tue Nov 8 14:49:55 2016 +0000
lib/oe/lsb: prefer /etc/os-release for distribution data
os-release(5) is an increasingly standard source of operating system
identification and more likely to be present on modern OS deployments, i.e.
many container variants of common distros include os-release and not the
lsb_release tool.
Therefore we should favour parsing /etc/os-release in distro_identifier(),
try lsb_release when that fails and finally fall back on various distro
specific sources of OS identification.
(From OE-Core rev: fc4eddecddec68d03a985086fa32db40ad0c7bfc)
Signed-off-by: Joshua Lock <joshua g lock intel com>
Signed-off-by: Ross Burton <ross burton intel com>
Signed-off-by: Richard Purdie <richard purdie linuxfoundation org>
meta/lib/oe/lsb.py | 37 ++++++++++++++++++++++++++++---------
1 files changed, 28 insertions(+), 9 deletions(-)
---
diff --git a/meta/lib/oe/lsb.py b/meta/lib/oe/lsb.py
index 0bb7686..8018c7b 100644
--- a/meta/lib/oe/lsb.py
+++ b/meta/lib/oe/lsb.py
@@ -1,3 +1,25 @@
+def release_dict_osr():
+ """ Populate a dict with pertinent values from /etc/os-release """
+ if not os.path.exists('/etc/os-release'):
+ return None
+
+ data = {}
+ with open('/etc/os-release') as f:
+ for line in f:
+ try:
+ key, val = line.rstrip().split('=', 1)
+ except ValueError:
+ continue
+ if key == 'NAME':
+ data['DISTRIB_ID'] = val.strip('"')
+ if key == 'VERSION_ID':
+ data['DISTRIB_RELEASE'] = val.strip('"')
+
+ if len(data.keys()) != 2:
+ return None
+
+ return data
+
def release_dict_lsb():
""" Return the output of lsb_release -ir as a dictionary """
from subprocess import PIPE
@@ -46,14 +68,6 @@ def release_dict_file():
if match:
data['DISTRIB_ID'] = match.group(1)
data['DISTRIB_RELEASE'] = match.group(2)
- elif os.path.exists('/etc/os-release'):
- data = {}
- with open('/etc/os-release') as f:
- for line in f:
- if line.startswith('NAME='):
- data['DISTRIB_ID'] = line[5:].rstrip().strip('"')
- if line.startswith('VERSION_ID='):
- data['DISTRIB_RELEASE'] = line[11:].rstrip().strip('"')
elif os.path.exists('/etc/SuSE-release'):
data = {}
data['DISTRIB_ID'] = 'SUSE LINUX'
@@ -73,7 +87,12 @@ def distro_identifier(adjust_hook=None):
import re
- distro_data = release_dict_lsb()
+ # Try /etc/os-release first, then the output of `lsb_release -ir` and
+ # finally fall back on parsing various release files in order to determine
+ # host distro name and version.
+ distro_data = release_dict_osr()
+ if not distro_data:
+ distro_data = release_dict_lsb()
if not distro_data:
distro_data = release_dict_file()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]