Skip to content

Commit

Permalink
Supports debian_version file content for version(best=True) calls (
Browse files Browse the repository at this point in the history
  • Loading branch information
HorlogeSkynet authored and Samuel FORESTIER committed Jun 7, 2022
1 parent ad4177b commit 6c6ff7f
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 7 deletions.
7 changes: 7 additions & 0 deletions distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,13 @@ def version(self, pretty=False, best=False):
).get("version_id", ""),
self.uname_attr("release"),
]
if self.id() == "debian" or "debian" in self.like().split():
# On Debian-like, add debian_version file content to candidates list.
try:
with open(os.path.join(self.etc_dir, "debian_version")) as fp:
versions.append(fp.readline().rstrip())
except FileNotFoundError:
pass
version = ""
if best:
# This algorithm uses the last version in priority order that has
Expand Down
21 changes: 21 additions & 0 deletions tests/resources/distros/debian10/bin/lsb_release
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
#
# lsb_release command for testing the ld module.
# Only the -a option is supported.
#
# This version of the lsb_release command works without a corresponding
# etc/lsb-release file.
#

if [[ "$@" != "-a" ]]; then
echo "Usage: lsb_release -a"
exit 2
fi

echo "No LSB modules are available."
echo "Distributor ID: Debian"
echo "Description: Debian GNU/Linux 10 (buster)"
echo "Release: 10"
echo "Codename: buster"

exit 0
1 change: 1 addition & 0 deletions tests/resources/distros/debian10/etc/debian_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10.11
9 changes: 9 additions & 0 deletions tests/resources/distros/debian10/etc/os-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
39 changes: 32 additions & 7 deletions tests/test_distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,10 @@ def _setup_for_distro(self, distro_root):
class TestOSRelease:
def setup_method(self, test_method):
dist = test_method.__name__.split("_")[1]
os_release = os.path.join(DISTROS_DIR, dist, "etc", "os-release")
self.distro = distro.LinuxDistribution(
include_lsb=False,
os_release_file=os_release,
distro_release_file="path-to-non-existing-file",
root_dir=os.path.join(DISTROS_DIR, dist),
)

def _test_outcome(self, outcome):
Expand Down Expand Up @@ -218,11 +217,23 @@ def test_debian8_os_release(self):
"pretty_name": "Debian GNU/Linux 8 (jessie)",
"version": "8",
"pretty_version": "8 (jessie)",
"best_version": "8",
"best_version": "8.2",
"codename": "jessie",
}
self._test_outcome(desired_outcome)

def test_debian10_os_release(self):
desired_outcome = {
"id": "debian",
"name": "Debian GNU/Linux",
"pretty_name": "Debian GNU/Linux 10 (buster)",
"version": "10",
"pretty_version": "10 (buster)",
"best_version": "10.11",
"codename": "buster",
}
self._test_outcome(desired_outcome)

def test_fedora19_os_release(self):
desired_outcome = {
"id": "fedora",
Expand Down Expand Up @@ -347,7 +358,7 @@ def test_raspbian7_os_release(self):
"pretty_name": "Raspbian GNU/Linux 7 (wheezy)",
"version": "7",
"pretty_version": "7 (wheezy)",
"best_version": "7",
"best_version": "7.1",
"like": "debian",
"codename": "wheezy",
}
Expand All @@ -360,7 +371,7 @@ def test_raspbian8_os_release(self):
"pretty_name": "Raspbian GNU/Linux 8 (jessie)",
"version": "8",
"pretty_version": "8 (jessie)",
"best_version": "8",
"best_version": "8.0",
"like": "debian",
"codename": "jessie",
}
Expand Down Expand Up @@ -1216,6 +1227,20 @@ def test_debian8_release(self):
self._test_outcome(desired_outcome)
self._test_non_existing_release_file()

def test_debian10_release(self):
desired_outcome = {
"id": "debian",
"name": "Debian GNU/Linux",
"pretty_name": "Debian GNU/Linux 10 (buster)",
"version": "10",
"pretty_version": "10 (buster)",
"best_version": "10.11",
"codename": "buster",
"major_version": "10",
}
self._test_outcome(desired_outcome)
self._test_non_existing_release_file()

def test_exherbo_release(self):
desired_outcome = {
"id": "exherbo",
Expand Down Expand Up @@ -1434,7 +1459,7 @@ def test_raspbian7_release(self):
"pretty_name": "Raspbian GNU/Linux 7 (wheezy)",
"version": "7",
"pretty_version": "7 (wheezy)",
"best_version": "7",
"best_version": "7.1",
"like": "debian",
"codename": "wheezy",
"major_version": "7",
Expand All @@ -1449,7 +1474,7 @@ def test_raspbian8_release(self):
"pretty_name": "Raspbian GNU/Linux 8 (jessie)",
"version": "8",
"pretty_version": "8 (jessie)",
"best_version": "8",
"best_version": "8.0",
"like": "debian",
"codename": "jessie",
"major_version": "8",
Expand Down

0 comments on commit 6c6ff7f

Please sign in to comment.