Skip to content

Commit

Permalink
Use distro.id() instead of platform.linux_distribution()
Browse files Browse the repository at this point in the history
Fix #175

We also needed to rename all variables named `distro` to not shadow
the imported module name.
  • Loading branch information
FrostyX committed Aug 23, 2021
1 parent 30bee79 commit db04215
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ sphinx_rtd_theme
Pygments
dbus-python
future
distro
1 change: 0 additions & 1 deletion tests/__meta__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
os.sys.path.insert(0, parentdir)

import sys
import platform
import unittest
from tracer.resources.system import System

Expand Down
4 changes: 4 additions & 0 deletions tracer.spec
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ BuildRequires: python2-pytest
BuildRequires: python2-psutil
BuildRequires: python2-six
BuildRequires: dbus-python
BuildRequires: python2-distro
Requires: dbus-python
Requires: python2-psutil
Requires: python2-setuptools
Requires: python2-future
Requires: python2-six
Requires: python2-distro
Requires: %{name}-common = %{version}-%{release}
%if %{with suggest}
Suggests: python-argcomplete
Expand All @@ -99,11 +101,13 @@ BuildRequires: python3-psutil
BuildRequires: python3-six
BuildRequires: python3-dbus
BuildRequires: python3-rpm
BuildRequires: python3-distro
Requires: python3-rpm
Requires: python3-psutil
Requires: python3-setuptools
Requires: python3-dbus
Requires: python3-six
Requires: python3-distro
Requires: %{name}-common = %{version}-%{release}
%if %{with suggest}
Suggests: python3-argcomplete
Expand Down
18 changes: 9 additions & 9 deletions tracer/resources/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import os
import pwd
import importlib
import platform
import distro
import psutil
from sys import version_info
from tracer.resources.PackageManager import PackageManager
Expand All @@ -37,7 +37,7 @@ def distribution():
"""
Checks if /etc/os-release exists, and if it does, uses it to divine the name of the distribution or
distribution like. e.g It will return 'debian' on Ubuntu systems.
Otherwise, revert to using platform.linux_distribution()
Otherwise, revert to using distro.id()
"""
if os.path.isfile("/etc/os-release"):
with open("/etc/os-release") as os_release_file:
Expand All @@ -56,11 +56,11 @@ def distribution():
return os_release_data["ID"]
else:
if "ID_LIKE" in os_release_data:
for distro in os_release_data["ID_LIKE"].split():
if distro in distros:
return distro
for distribution in os_release_data["ID_LIKE"].split():
if distribution in distros:
return distribution
else:
return platform.linux_distribution(full_distribution_name=False)[0]
return distro.id()

@staticmethod
def package_manager(**kwargs):
Expand Down Expand Up @@ -95,11 +95,11 @@ def get_instance(pair):
"suse": [("tracer.packageManagers.dnf", "Dnf")],
}

distro = System.distribution()
if distro not in managers:
distribution = System.distribution()
if distribution not in managers:
return None

return PackageManager(*list(map(get_instance, managers[distro])))
return PackageManager(*list(map(get_instance, managers[distribution])))

@staticmethod
def init_system():
Expand Down

0 comments on commit db04215

Please sign in to comment.