diff options
author | Joshua Lock <joshua.g.lock@intel.com> | 2016-11-08 14:49:55 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-11-15 15:19:54 +0000 |
commit | 42441ea4819dfeca7183f6a095c99708124ded5d (patch) | |
tree | 021edfc9ebc0ce416109ad57a3715db2142329bc /meta/lib/oe | |
parent | 545f5f96d9b7447583d865de7b35e444a9785426 (diff) | |
download | poky-42441ea4819dfeca7183f6a095c99708124ded5d.tar.gz |
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>
Diffstat (limited to 'meta/lib/oe')
-rw-r--r-- | 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 0bb76864a0..8018c7b076 100644 --- a/meta/lib/oe/lsb.py +++ b/meta/lib/oe/lsb.py | |||
@@ -1,3 +1,25 @@ | |||
1 | def release_dict_osr(): | ||
2 | """ Populate a dict with pertinent values from /etc/os-release """ | ||
3 | if not os.path.exists('/etc/os-release'): | ||
4 | return None | ||
5 | |||
6 | data = {} | ||
7 | with open('/etc/os-release') as f: | ||
8 | for line in f: | ||
9 | try: | ||
10 | key, val = line.rstrip().split('=', 1) | ||
11 | except ValueError: | ||
12 | continue | ||
13 | if key == 'NAME': | ||
14 | data['DISTRIB_ID'] = val.strip('"') | ||
15 | if key == 'VERSION_ID': | ||
16 | data['DISTRIB_RELEASE'] = val.strip('"') | ||
17 | |||
18 | if len(data.keys()) != 2: | ||
19 | return None | ||
20 | |||
21 | return data | ||
22 | |||
1 | def release_dict_lsb(): | 23 | def release_dict_lsb(): |
2 | """ Return the output of lsb_release -ir as a dictionary """ | 24 | """ Return the output of lsb_release -ir as a dictionary """ |
3 | from subprocess import PIPE | 25 | from subprocess import PIPE |
@@ -46,14 +68,6 @@ def release_dict_file(): | |||
46 | if match: | 68 | if match: |
47 | data['DISTRIB_ID'] = match.group(1) | 69 | data['DISTRIB_ID'] = match.group(1) |
48 | data['DISTRIB_RELEASE'] = match.group(2) | 70 | data['DISTRIB_RELEASE'] = match.group(2) |
49 | elif os.path.exists('/etc/os-release'): | ||
50 | data = {} | ||
51 | with open('/etc/os-release') as f: | ||
52 | for line in f: | ||
53 | if line.startswith('NAME='): | ||
54 | data['DISTRIB_ID'] = line[5:].rstrip().strip('"') | ||
55 | if line.startswith('VERSION_ID='): | ||
56 | data['DISTRIB_RELEASE'] = line[11:].rstrip().strip('"') | ||
57 | elif os.path.exists('/etc/SuSE-release'): | 71 | elif os.path.exists('/etc/SuSE-release'): |
58 | data = {} | 72 | data = {} |
59 | data['DISTRIB_ID'] = 'SUSE LINUX' | 73 | data['DISTRIB_ID'] = 'SUSE LINUX' |
@@ -73,7 +87,12 @@ def distro_identifier(adjust_hook=None): | |||
73 | 87 | ||
74 | import re | 88 | import re |
75 | 89 | ||
76 | distro_data = release_dict_lsb() | 90 | # Try /etc/os-release first, then the output of `lsb_release -ir` and |
91 | # finally fall back on parsing various release files in order to determine | ||
92 | # host distro name and version. | ||
93 | distro_data = release_dict_osr() | ||
94 | if not distro_data: | ||
95 | distro_data = release_dict_lsb() | ||
77 | if not distro_data: | 96 | if not distro_data: |
78 | distro_data = release_dict_file() | 97 | distro_data = release_dict_file() |
79 | 98 | ||