mirror of
git://git.yoctoproject.org/poky.git
synced 2025-07-19 12:59:02 +02: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:
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
|
||||
|
||||
|
|
|
@ -10,19 +10,9 @@ from collections.abc import MutableMapping
|
|||
from xml.dom.minidom import parseString
|
||||
from xml.etree.ElementTree import Element, tostring
|
||||
|
||||
from oe.lsb import get_os_release
|
||||
from oeqa.utils.commands import runCmd, get_bb_vars
|
||||
|
||||
def get_os_release():
|
||||
"""Get info from /etc/os-release as a dict"""
|
||||
data = OrderedDict()
|
||||
os_release_file = '/etc/os-release'
|
||||
if not os.path.exists(os_release_file):
|
||||
return None
|
||||
with open(os_release_file) as fobj:
|
||||
for line in fobj:
|
||||
key, value = line.split('=', 1)
|
||||
data[key.strip().lower()] = value.strip().strip('"')
|
||||
return data
|
||||
|
||||
def metadata_from_bb():
|
||||
""" Returns test's metadata as OrderedDict.
|
||||
|
@ -45,9 +35,9 @@ def metadata_from_bb():
|
|||
os_release = get_os_release()
|
||||
if os_release:
|
||||
info_dict['host_distro'] = OrderedDict()
|
||||
for key in ('id', 'version_id', 'pretty_name'):
|
||||
for key in ('ID', 'VERSION_ID', 'PRETTY_NAME'):
|
||||
if key in os_release:
|
||||
info_dict['host_distro'][key] = os_release[key]
|
||||
info_dict['host_distro'][key.lower()] = os_release[key]
|
||||
|
||||
info_dict['layers'] = get_layers(data_dict['BBLAYERS'])
|
||||
info_dict['bitbake'] = git_rev_info(os.path.dirname(bb.__file__))
|
||||
|
|
Loading…
Reference in New Issue
Block a user