Skip to content

Commit

Permalink
Use ID_LIKE in /etc/os-release (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
sean797 committed May 8, 2017
1 parent 121647f commit bb952e0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion tracer/packageManagers/dpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


from tracer.resources.system import System
if System.distribution() in ["debian", "ubuntu"]:
if System.distribution() == "debian":

from .ipackageManager import IPackageManager
from tracer.resources.package import Package
Expand Down
18 changes: 13 additions & 5 deletions tracer/resources/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,28 @@ class System(object):

@staticmethod
def distribution():
# Checks if /etc/os-release exists, and if it does,
# use it to divine the name of the distribution
# Otherwise, revert to using platform.linux_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()
"""
if os.path.isfile("/etc/os-release"):
with open("/etc/os-release") as os_release_file:
os_release_data = {}
distros = ["gentoo", "debian", "rhel", "centos", "ol", "mageia", "arch", "archarm", "fedora"]

# Remove empty lines and trailing spaces
lines = [line.rstrip() for line in os_release_file if line.rstrip()]
for line in lines:
os_release_key, os_release_value = line.split("=")
os_release_data[os_release_key] = os_release_value.strip('"')
return os_release_data["ID"]
if os_release_data["ID"] in distros:
return os_release_data["ID"]
else:
if os_release_data["ID_LIKE"]:
for distro in os_release_data["ID_LIKE"].split():
if distro in distros:
return distro
else:
return platform.linux_distribution(full_distribution_name=False)[0]

Expand All @@ -64,7 +73,6 @@ def get_instance(pair):
managers = {
"gentoo": [("tracer.packageManagers.portage", "Portage")],
"debian": [("tracer.packageManagers.dpkg", "Dpkg")],
"ubuntu": [("tracer.packageManagers.dpkg", "Dpkg")],
"rhel": [("tracer.packageManagers.yum", "Yum")],
"centos": [("tracer.packageManagers.yum", "Yum")],
"ol": [("tracer.packageManagers.yum", "Yum")],
Expand Down

0 comments on commit bb952e0

Please sign in to comment.