summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta/lib/oe/lsb.py37
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 @@
1def 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
1def release_dict_lsb(): 23def 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