summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib')
-rw-r--r--meta/lib/oe/lsb.py39
1 files changed, 37 insertions, 2 deletions
diff --git a/meta/lib/oe/lsb.py b/meta/lib/oe/lsb.py
index 9133356afb..f4a5ba1c17 100644
--- a/meta/lib/oe/lsb.py
+++ b/meta/lib/oe/lsb.py
@@ -17,6 +17,37 @@ def release_dict():
17 data[key] = value 17 data[key] = value
18 return data 18 return data
19 19
20def release_dict_file():
21 """ Try to gather LSB release information manually when lsb_release tool is unavailable """
22 data = None
23 try:
24 if os.path.exists('/etc/lsb-release'):
25 data = {}
26 with open('/etc/lsb-release') as f:
27 for line in f:
28 key, value = line.split("=", 1)
29 data[key] = value
30 elif os.path.exists('/etc/redhat-release'):
31 data = {}
32 with open('/etc/redhat-release') as f:
33 distro = f.readline().strip()
34 import re
35 match = re.match(r'(.*) release (.*) \((.*)\)', distro)
36 if match:
37 data['DISTRIB_ID'] = match.group(1)
38 data['DISTRIB_RELEASE'] = match.group(2)
39 elif os.path.exists('/etc/SuSE-release'):
40 data = {}
41 data['DISTRIB_ID'] = 'SUSE LINUX'
42 with open('/etc/SuSE-release') as f:
43 for line in f:
44 if line.startswith('VERSION = '):
45 data['DISTRIB_RELEASE'] = line[10:].rstrip()
46 break
47 except IOError:
48 return None
49 return data
50
20def distro_identifier(adjust_hook=None): 51def distro_identifier(adjust_hook=None):
21 """Return a distro identifier string based upon lsb_release -ri, 52 """Return a distro identifier string based upon lsb_release -ri,
22 with optional adjustment via a hook""" 53 with optional adjustment via a hook"""
@@ -25,8 +56,12 @@ def distro_identifier(adjust_hook=None):
25 if lsb_data: 56 if lsb_data:
26 distro_id, release = lsb_data['Distributor ID'], lsb_data['Release'] 57 distro_id, release = lsb_data['Distributor ID'], lsb_data['Release']
27 else: 58 else:
28 distro_id, release = None, None 59 lsb_data_file = release_dict_file()
29 60 if lsb_data_file:
61 distro_id, release = lsb_data_file['DISTRIB_ID'], lsb_data_file['DISTRIB_RELEASE']
62 else:
63 distro_id, release = None, None
64
30 if adjust_hook: 65 if adjust_hook:
31 distro_id, release = adjust_hook(distro_id, release) 66 distro_id, release = adjust_hook(distro_id, release)
32 if not distro_id: 67 if not distro_id: