Installed snap on ubuntu but linux distribution returns debian

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?

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)

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.

@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