mirror of
https://git.yoctoproject.org/poky
synced 2026-06-01 00:59:48 +00:00
lib/oe/lsb: better handle missing fields
Some rolling release distros, such as Arch Linux, don't include a VERSION_ID field in their os-release file. Change release_dict_osr() to better handle this optional field being absent. Further improve the resilience of the release_dict_*() methods by always returning a dict and using dict.get() in distro_identifier() to supply a default, empty string, value when then key is missing. (From OE-Core rev: e36066dcc3b56cac1c695370ea178b566c0ebfd6) 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>
This commit is contained in:
committed by
Richard Purdie
parent
4bc5353c92
commit
333d300fba
+5
-8
@@ -15,9 +15,6 @@ def release_dict_osr():
|
|||||||
if key == 'VERSION_ID':
|
if key == 'VERSION_ID':
|
||||||
data['DISTRIB_RELEASE'] = val.strip('"')
|
data['DISTRIB_RELEASE'] = val.strip('"')
|
||||||
|
|
||||||
if len(data.keys()) != 2:
|
|
||||||
return None
|
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def release_dict_lsb():
|
def release_dict_lsb():
|
||||||
@@ -27,7 +24,7 @@ def release_dict_lsb():
|
|||||||
try:
|
try:
|
||||||
output, err = bb.process.run(['lsb_release', '-ir'], stderr=PIPE)
|
output, err = bb.process.run(['lsb_release', '-ir'], stderr=PIPE)
|
||||||
except bb.process.CmdError as exc:
|
except bb.process.CmdError as exc:
|
||||||
return None
|
return {}
|
||||||
|
|
||||||
lsb_map = { 'Distributor ID': 'DISTRIB_ID',
|
lsb_map = { 'Distributor ID': 'DISTRIB_ID',
|
||||||
'Release': 'DISTRIB_RELEASE'}
|
'Release': 'DISTRIB_RELEASE'}
|
||||||
@@ -51,7 +48,7 @@ def release_dict_lsb():
|
|||||||
|
|
||||||
def release_dict_file():
|
def release_dict_file():
|
||||||
""" Try to gather release information manually when other methods fail """
|
""" Try to gather release information manually when other methods fail """
|
||||||
data = None
|
data = {}
|
||||||
try:
|
try:
|
||||||
if os.path.exists('/etc/lsb-release'):
|
if os.path.exists('/etc/lsb-release'):
|
||||||
data = {}
|
data = {}
|
||||||
@@ -78,7 +75,7 @@ def release_dict_file():
|
|||||||
break
|
break
|
||||||
|
|
||||||
except IOError:
|
except IOError:
|
||||||
return None
|
return {}
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def distro_identifier(adjust_hook=None):
|
def distro_identifier(adjust_hook=None):
|
||||||
@@ -96,8 +93,8 @@ def distro_identifier(adjust_hook=None):
|
|||||||
if not distro_data:
|
if not distro_data:
|
||||||
distro_data = release_dict_file()
|
distro_data = release_dict_file()
|
||||||
|
|
||||||
distro_id = distro_data['DISTRIB_ID']
|
distro_id = distro_data.get('DISTRIB_ID', '')
|
||||||
release = distro_data['DISTRIB_RELEASE']
|
release = distro_data.get('DISTRIB_RELEASE', '')
|
||||||
|
|
||||||
if adjust_hook:
|
if adjust_hook:
|
||||||
distro_id, release = adjust_hook(distro_id, release)
|
distro_id, release = adjust_hook(distro_id, release)
|
||||||
|
|||||||
Reference in New Issue
Block a user