diff options
author | Tudor Florea <tudor.florea@enea.com> | 2014-10-16 03:05:19 +0200 |
---|---|---|
committer | Tudor Florea <tudor.florea@enea.com> | 2014-10-16 03:05:19 +0200 |
commit | c527fd1f14c27855a37f2e8ac5346ce8d940ced2 (patch) | |
tree | bb002c1fdf011c41dbd2f0927bed23ecb5f83c97 /meta/lib/oe/lsb.py | |
download | poky-daisy-140929.tar.gz |
initial commit for Enea Linux 4.0-140929daisy-140929
Migrated from the internal git server on the daisy-enea-point-release branch
Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'meta/lib/oe/lsb.py')
-rw-r--r-- | meta/lib/oe/lsb.py | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/meta/lib/oe/lsb.py b/meta/lib/oe/lsb.py new file mode 100644 index 0000000000..b53f361035 --- /dev/null +++ b/meta/lib/oe/lsb.py | |||
@@ -0,0 +1,81 @@ | |||
1 | def release_dict(): | ||
2 | """Return the output of lsb_release -ir as a dictionary""" | ||
3 | from subprocess import PIPE | ||
4 | |||
5 | try: | ||
6 | output, err = bb.process.run(['lsb_release', '-ir'], stderr=PIPE) | ||
7 | except bb.process.CmdError as exc: | ||
8 | return None | ||
9 | |||
10 | data = {} | ||
11 | for line in output.splitlines(): | ||
12 | try: | ||
13 | key, value = line.split(":\t", 1) | ||
14 | except ValueError: | ||
15 | continue | ||
16 | else: | ||
17 | data[key] = value | ||
18 | return data | ||
19 | |||
20 | def 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.strip() | ||
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 | elif os.path.exists('/etc/os-release'): | ||
48 | data = {} | ||
49 | with open('/etc/os-release') as f: | ||
50 | for line in f: | ||
51 | if line.startswith('NAME='): | ||
52 | data['DISTRIB_ID'] = line[5:].rstrip().strip('"') | ||
53 | if line.startswith('VERSION_ID='): | ||
54 | data['DISTRIB_RELEASE'] = line[11:].rstrip().strip('"') | ||
55 | except IOError: | ||
56 | return None | ||
57 | return data | ||
58 | |||
59 | def distro_identifier(adjust_hook=None): | ||
60 | """Return a distro identifier string based upon lsb_release -ri, | ||
61 | with optional adjustment via a hook""" | ||
62 | |||
63 | lsb_data = release_dict() | ||
64 | if lsb_data: | ||
65 | distro_id, release = lsb_data['Distributor ID'], lsb_data['Release'] | ||
66 | else: | ||
67 | lsb_data_file = release_dict_file() | ||
68 | if lsb_data_file: | ||
69 | distro_id, release = lsb_data_file['DISTRIB_ID'], lsb_data_file.get('DISTRIB_RELEASE', None) | ||
70 | else: | ||
71 | distro_id, release = None, None | ||
72 | |||
73 | if adjust_hook: | ||
74 | distro_id, release = adjust_hook(distro_id, release) | ||
75 | if not distro_id: | ||
76 | return "Unknown" | ||
77 | if release: | ||
78 | id_str = '{0}-{1}'.format(distro_id, release) | ||
79 | else: | ||
80 | id_str = distro_id | ||
81 | return id_str.replace(' ','-').replace('/','-') | ||