classification
Title: platform.dist(): detect Linux distribution version in a robust, standard way
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.1, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: platform.dist() has unpredictable result under Linux
View: 1322
Superseder:
Assigned To: lemburg Nosy List: draghuram, lemburg, zooko (3)
Priority: normal Keywords patch

Created on 2008-09-22 22:13 by zooko, last changed 2008-09-23 18:10 by lemburg.

Files
File name Uploaded Description Edit Remove
dist.patch.txt zooko, 2008-09-22 22:13 patch to platform.dist() to execute lsb_release
dist.patch.txt zooko, 2008-09-22 22:45
dist.patch.txt zooko, 2008-09-23 17:15
Messages (5)
msg73601 - (view) Author: Zooko O'Whielacronx (zooko) Date: 2008-09-22 22:13
platform.dist() returns ('debian', 'lenny/sid', '') on my Ubuntu 8.04
Hardy system.  Investigating shows that there are a few techniques in
platform.py to parse the version-number-files of different Linux
distributions.  This patch adds a command to try executing "lsb_release"
first of all.  lsb_release is the standard way to do this, originally
published in 2001:

http://refspecs.freestandards.org/LSB_1.0.0/gLSB/lsbrelease.html

and currently standardized here:

http://refspecs.freestandards.org/LSB_3.2.0/LSB-Core-generic/LSB-Core-generic/lsbrelease.html

If invoking "lsb_release" results in exit code 0 and some non-empty,
non-all-whitespace string on stdout, then dist() returns that.  Else,
dist falls back to the old (current) hacks.

There is a drawback to this: invoking three successive subprocesses
takes a bit of time.  Hopefully nobody needs to invoke platform.dist()
in a time-critical moment...

With this patch, platform.dist() return:
('Ubuntu', '8.04', 'hardy')

Oh, this patch also updates the docstring of dist() to explain what is
meant by "distribution", "version", and "id".
msg73604 - (view) Author: Zooko O'Whielacronx (zooko) Date: 2008-09-22 22:45
Here's a new version of this patch which differs only in having slightly
more correct documentation.
msg73641 - (view) Author: Raghuram Devarakonda (draghuram) Date: 2008-09-23 14:12
Please take a look at #1322 for some discussion on this topic.
msg73651 - (view) Author: Zooko O'Whielacronx (zooko) Date: 2008-09-23 17:15
Here is an updated version of my patch which tries parsing
/etc/lsb-release first and only if that fails tries executing
lsb_release.  The reason is that executing lsb_release in a subprocess
takes half-a-second on my high-performance Athlon64 Ubuntu workstation,
and also that some installations have /etc/lsb-release but not
lsb_release.  See the docstring for more details about why to do it this
way and exactly what it does.
msg73653 - (view) Author: Marc-Andre Lemburg (lemburg) Date: 2008-09-23 18:10
As explained in #1322. platform.dist() has been superseded by
platform.linux_distribution().

Please check what platform.linux_distribution() returns on your platform
using Python 2.6rc2.

I'm closing this ticket since it's basically a duplicate of #1322.
History
Date User Action Args
2008-09-23 18:10:25lemburgsetstatus: open -> closed
resolution: duplicate
messages: + msg73653
2008-09-23 17:36:38gregory.p.smithlinkissue1322 dependencies
2008-09-23 17:36:31gregory.p.smithsetkeywords: + patch
dependencies: + platform.dist() has unpredictable result under Linux
2008-09-23 17:15:59zookosetfiles: + dist.patch.txt
messages: + msg73651
2008-09-23 14:12:12draghuramsetnosy: + draghuram
messages: + msg73641
2008-09-22 22:45:48zookosetfiles: + dist.patch.txt
messages: + msg73604
2008-09-22 22:18:59benjamin.petersonsetpriority: normal
assignee: lemburg
nosy: + lemburg
versions: + Python 3.1, Python 2.7, - Python 2.6, Python 2.5, Python 2.4, Python 3.0
2008-09-22 22:13:31zookocreate