summaryrefslogtreecommitdiffstats
path: root/meta/lib/oe
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2017-04-27 11:17:33 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-05-16 14:08:28 +0100
commitef8c15852cecb467cd2ebbec11b4df4bdd21ab68 (patch)
tree00a72f01c7b34cfd1db0957a73f30650fc2d348a /meta/lib/oe
parenta11e87f179409d7f8581db73f636190e428ae849 (diff)
downloadpoky-ef8c15852cecb467cd2ebbec11b4df4bdd21ab68.tar.gz
oe.lsb: add get_os_release()
Move get_os_release() from oeqa.utils.metadata to oe.lsb, merging the code with release_dict_osr() from oe.lsb. This removes some code duplication and makes get_os_release() more robust. (From OE-Core rev: 56b883f7765f6bd72e83dec26a5db8c7108c835d) Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.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.py33
1 files changed, 20 insertions, 13 deletions
diff --git a/meta/lib/oe/lsb.py b/meta/lib/oe/lsb.py
index 3a945e0fce..71c0992c5d 100644
--- a/meta/lib/oe/lsb.py
+++ b/meta/lib/oe/lsb.py
@@ -1,19 +1,26 @@
1def get_os_release():
2 """Get all key-value pairs from /etc/os-release as a dict"""
3 from collections import OrderedDict
4
5 data = OrderedDict()
6 if os.path.exists('/etc/os-release'):
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 data[key.strip()] = val.strip('"')
14 return data
15
1def release_dict_osr(): 16def release_dict_osr():
2 """ Populate a dict with pertinent values from /etc/os-release """ 17 """ 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 = {} 18 data = {}
7 with open('/etc/os-release') as f: 19 os_release = get_os_release()
8 for line in f: 20 if 'ID' in os_release:
9 try: 21 data['DISTRIB_ID'] = os_release['ID']
10 key, val = line.rstrip().split('=', 1) 22 if 'VERSION_ID' in os_release:
11 except ValueError: 23 data['DISTRIB_RELEASE'] = os_release['VERSION_ID']
12 continue
13 if key == 'ID':
14 data['DISTRIB_ID'] = val.strip('"')
15 if key == 'VERSION_ID':
16 data['DISTRIB_RELEASE'] = val.strip('"')
17 24
18 return data 25 return data
19 26