Anmol
September 13, 2017, 12:09pm
1
I have installed snap on ubuntu and trying to get the linux distribution through platform.
>>import platform
>>plaform.linux_distribution()[0]
'debian'
my ‘/etc/os-release’ file content:
NAME="Ubuntu Core"
VERSION="16"
ID=ubuntu-core
PRETTY_NAME="Ubuntu Core 16"
VERSION_ID="16"
HOME_URL="http://www.snapcraft.io/"
BUG_REPORT_URL="http://bugs.launchpad.net/snappy/"
‘/etc/lsb-release’ file content:
DISTRIB_ID="Ubuntu Core"
DISTRIB_RELEASE=16
DISTRIB_DESCRIPTION="Ubuntu Core 16"
“debian_version” file content:
stretch/sid
‘uname -a output’:
>>uname -a
Linux CH2QB02 4.4.0-89-generic #112-Ubuntu SMP Mon Jul 31 19:38:41 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
I expect it to return “Ubuntu”.
Any suggestions on the issue?
ogra
September 13, 2017, 12:42pm
2
not sure the platform module is the right thing to use … (it doesnt even list Ubuntu by default, but dead things like yellowdog or UnitedLinux)
r'(?: release )?' r'([\d.]+)' r'[^(]*(?:\((.+)\))?', re.ASCII) # See also http://www.novell.com/coolsolutions/feature/11251.html # and http://linuxmafia.com/faq/Admin/release-files.html # and http://data.linux-ntfs.org/rpm/whichrpm # and http://www.die.net/doc/linux/man/man1/lsb_release.1.html _supported_dists = ( 'SuSE', 'debian', 'fedora', 'redhat', 'centos', 'mandrake', 'mandriva', 'rocks', 'slackware', 'yellowdog', 'gentoo', 'UnitedLinux', 'turbolinux', 'arch', 'mageia') def _parse_release_file(firstline): # Default to empty 'version' and 'id' strings. Both defaults are used # when 'firstline' is empty. 'id' defaults to empty when an id can not # be deduced. version = '' id = ''
i think @sergiusens did hit the same with snapcraft and found a better solution than the platform module.
We parse /etc/os-release
but we are a classic snap so we get the file from the host.
Anmol
September 13, 2017, 1:08pm
4
@ogra It (platform.linux_distribution()[0], i didn’t get into much details of the implementation) returns “Ubuntu” for any machine running Ubuntu though.
@sergiusens So do you suggest to parse either “/etc/os-release” or “/etc/lsb-release” for this purpose? any other solutions?
DO NOT parse /etc/lsb-release
(it has no definition and doesn’t exist in most distributions). Only parse /etc/os-release
, as that file is stable and is used everywhere.
platform.linux_distribution()
is being removed in Python 3.7.
1 Like