diff options
| author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-07-26 14:05:51 +0100 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-07-28 09:20:52 +0100 |
| commit | f295e29b2e4918886642f73db8cb9f0c1df598fd (patch) | |
| tree | b53dee97913f728d4a3521ad1ca0c5ea79be735a /meta/lib/oe/lsb.py | |
| parent | 3f05622bac998f351168eb49a5ca96e7473f51be (diff) | |
| download | poky-f295e29b2e4918886642f73db8cb9f0c1df598fd.tar.gz | |
lib/oe/lsb: Add basic LSB functions
This code was written by Christopher Larson <chris_larson@mentor.com> and
allows generation of the LSB release data based upon the lsb_release
command. It also includes a helper function to generate a string
representing a given distribution.
(From OE-Core rev: 458bdfe1cc4872e901ea3c38f497bfea6cf4c8cb)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Saul Wold <sgw@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oe/lsb.py')
| -rw-r--r-- | meta/lib/oe/lsb.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/meta/lib/oe/lsb.py b/meta/lib/oe/lsb.py new file mode 100644 index 0000000000..36dd12fc80 --- /dev/null +++ b/meta/lib/oe/lsb.py | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | def release_dict(): | ||
| 2 | """Return the output of lsb_release -a as a dictionary""" | ||
| 3 | from subprocess import PIPE | ||
| 4 | |||
| 5 | try: | ||
| 6 | output, err = bb.process.run(['lsb_release', '-a'], stderr=PIPE) | ||
| 7 | except bb.process.CmdError as exc: | ||
| 8 | return | ||
| 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 distro_identifier(adjust_hook=None): | ||
| 21 | """Return a distro identifier string based upon lsb_release -ri, | ||
| 22 | with optional adjustment via a hook""" | ||
| 23 | |||
| 24 | lsb_data = release_dict() | ||
| 25 | distro_id, release = lsb_data['Distributor ID'], lsb_data['Release'] | ||
| 26 | if adjust_hook: | ||
| 27 | distro_id, release = adjust_hook(distro_id, release) | ||
| 28 | return '{0}-{1}'.format(distro_id, release).replace(' ','-') | ||
