mirror of
https://git.yoctoproject.org/poky
synced 2026-01-29 21:08:42 +01:00
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>
This commit is contained in:
committed by
Richard Purdie
parent
a11e87f179
commit
ef8c15852c
@@ -1,19 +1,26 @@
|
||||
def get_os_release():
|
||||
"""Get all key-value pairs from /etc/os-release as a dict"""
|
||||
from collections import OrderedDict
|
||||
|
||||
data = OrderedDict()
|
||||
if os.path.exists('/etc/os-release'):
|
||||
with open('/etc/os-release') as f:
|
||||
for line in f:
|
||||
try:
|
||||
key, val = line.rstrip().split('=', 1)
|
||||
except ValueError:
|
||||
continue
|
||||
data[key.strip()] = val.strip('"')
|
||||
return data
|
||||
|
||||
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 == 'ID':
|
||||
data['DISTRIB_ID'] = val.strip('"')
|
||||
if key == 'VERSION_ID':
|
||||
data['DISTRIB_RELEASE'] = val.strip('"')
|
||||
os_release = get_os_release()
|
||||
if 'ID' in os_release:
|
||||
data['DISTRIB_ID'] = os_release['ID']
|
||||
if 'VERSION_ID' in os_release:
|
||||
data['DISTRIB_RELEASE'] = os_release['VERSION_ID']
|
||||
|
||||
return data
|
||||
|
||||
|
||||
Reference in New Issue
Block a user