summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
authorJoshua Lock <joshua.g.lock@intel.com>2016-11-15 22:08:54 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-11-23 11:10:14 +0000
commit333d300fba023bfd201f044b52f51d4b13fcd182 (patch)
treed11440bfe4a8fd66a01afd913599adf9357cf280 /meta/lib
parent4bc5353c929cb1a5f33a24c5471a5bde1929a043 (diff)
downloadpoky-333d300fba023bfd201f044b52f51d4b13fcd182.tar.gz
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>
Diffstat (limited to 'meta/lib')
-rw-r--r--meta/lib/oe/lsb.py13
1 files changed, 5 insertions, 8 deletions
diff --git a/meta/lib/oe/lsb.py b/meta/lib/oe/lsb.py
index 5a795a12d3..3a945e0fce 100644
--- a/meta/lib/oe/lsb.py
+++ b/meta/lib/oe/lsb.py
@@ -15,9 +15,6 @@ def release_dict_osr():
15 if key == 'VERSION_ID': 15 if key == 'VERSION_ID':
16 data['DISTRIB_RELEASE'] = val.strip('"') 16 data['DISTRIB_RELEASE'] = val.strip('"')
17 17
18 if len(data.keys()) != 2:
19 return None
20
21 return data 18 return data
22 19
23def release_dict_lsb(): 20def release_dict_lsb():
@@ -27,7 +24,7 @@ def release_dict_lsb():
27 try: 24 try:
28 output, err = bb.process.run(['lsb_release', '-ir'], stderr=PIPE) 25 output, err = bb.process.run(['lsb_release', '-ir'], stderr=PIPE)
29 except bb.process.CmdError as exc: 26 except bb.process.CmdError as exc:
30 return None 27 return {}
31 28
32 lsb_map = { 'Distributor ID': 'DISTRIB_ID', 29 lsb_map = { 'Distributor ID': 'DISTRIB_ID',
33 'Release': 'DISTRIB_RELEASE'} 30 'Release': 'DISTRIB_RELEASE'}
@@ -51,7 +48,7 @@ def release_dict_lsb():
51 48
52def release_dict_file(): 49def release_dict_file():
53 """ Try to gather release information manually when other methods fail """ 50 """ Try to gather release information manually when other methods fail """
54 data = None 51 data = {}
55 try: 52 try:
56 if os.path.exists('/etc/lsb-release'): 53 if os.path.exists('/etc/lsb-release'):
57 data = {} 54 data = {}
@@ -78,7 +75,7 @@ def release_dict_file():
78 break 75 break
79 76
80 except IOError: 77 except IOError:
81 return None 78 return {}
82 return data 79 return data
83 80
84def distro_identifier(adjust_hook=None): 81def distro_identifier(adjust_hook=None):
@@ -96,8 +93,8 @@ def distro_identifier(adjust_hook=None):
96 if not distro_data: 93 if not distro_data:
97 distro_data = release_dict_file() 94 distro_data = release_dict_file()
98 95
99 distro_id = distro_data['DISTRIB_ID'] 96 distro_id = distro_data.get('DISTRIB_ID', '')
100 release = distro_data['DISTRIB_RELEASE'] 97 release = distro_data.get('DISTRIB_RELEASE', '')
101 98
102 if adjust_hook: 99 if adjust_hook:
103 distro_id, release = adjust_hook(distro_id, release) 100 distro_id, release = adjust_hook(distro_id, release)