Skip to content

Commit d63603a

Browse files
HorlogeSkynetSamuel FORESTIER
authored andcommitted
Supports debian_version file content for version(best=True) calls (#333)
1 parent ad4177b commit d63603a

File tree

5 files changed

+70
-7
lines changed

5 files changed

+70
-7
lines changed

distro.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,13 @@ def version(self, pretty=False, best=False):
866866
).get("version_id", ""),
867867
self.uname_attr("release"),
868868
]
869+
if self.id() == "debian" or "debian" in self.like().split():
870+
# On Debian-like, add debian_version file content to candidates list.
871+
try:
872+
with open(os.path.join(self.etc_dir, "debian_version")) as fp:
873+
versions.append(fp.readline().rstrip())
874+
except IOError:
875+
pass
869876
version = ""
870877
if best:
871878
# This algorithm uses the last version in priority order that has
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
#
3+
# lsb_release command for testing the ld module.
4+
# Only the -a option is supported.
5+
#
6+
# This version of the lsb_release command works without a corresponding
7+
# etc/lsb-release file.
8+
#
9+
10+
if [[ "$@" != "-a" ]]; then
11+
echo "Usage: lsb_release -a"
12+
exit 2
13+
fi
14+
15+
echo "No LSB modules are available."
16+
echo "Distributor ID: Debian"
17+
echo "Description: Debian GNU/Linux 10 (buster)"
18+
echo "Release: 10"
19+
echo "Codename: buster"
20+
21+
exit 0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
10.11
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
2+
NAME="Debian GNU/Linux"
3+
VERSION_ID="10"
4+
VERSION="10 (buster)"
5+
VERSION_CODENAME=buster
6+
ID=debian
7+
HOME_URL="https://www.debian.org/"
8+
SUPPORT_URL="https://www.debian.org/support"
9+
BUG_REPORT_URL="https://bugs.debian.org/"

tests/test_distro.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,10 @@ def _setup_for_distro(self, distro_root):
139139
class TestOSRelease:
140140
def setup_method(self, test_method):
141141
dist = test_method.__name__.split("_")[1]
142-
os_release = os.path.join(DISTROS_DIR, dist, "etc", "os-release")
143142
self.distro = distro.LinuxDistribution(
144143
include_lsb=False,
145-
os_release_file=os_release,
146144
distro_release_file="path-to-non-existing-file",
145+
root_dir=os.path.join(DISTROS_DIR, dist),
147146
)
148147

149148
def _test_outcome(self, outcome):
@@ -218,11 +217,23 @@ def test_debian8_os_release(self):
218217
"pretty_name": "Debian GNU/Linux 8 (jessie)",
219218
"version": "8",
220219
"pretty_version": "8 (jessie)",
221-
"best_version": "8",
220+
"best_version": "8.2",
222221
"codename": "jessie",
223222
}
224223
self._test_outcome(desired_outcome)
225224

225+
def test_debian10_os_release(self):
226+
desired_outcome = {
227+
"id": "debian",
228+
"name": "Debian GNU/Linux",
229+
"pretty_name": "Debian GNU/Linux 10 (buster)",
230+
"version": "10",
231+
"pretty_version": "10 (buster)",
232+
"best_version": "10.11",
233+
"codename": "buster",
234+
}
235+
self._test_outcome(desired_outcome)
236+
226237
def test_fedora19_os_release(self):
227238
desired_outcome = {
228239
"id": "fedora",
@@ -347,7 +358,7 @@ def test_raspbian7_os_release(self):
347358
"pretty_name": "Raspbian GNU/Linux 7 (wheezy)",
348359
"version": "7",
349360
"pretty_version": "7 (wheezy)",
350-
"best_version": "7",
361+
"best_version": "7.1",
351362
"like": "debian",
352363
"codename": "wheezy",
353364
}
@@ -360,7 +371,7 @@ def test_raspbian8_os_release(self):
360371
"pretty_name": "Raspbian GNU/Linux 8 (jessie)",
361372
"version": "8",
362373
"pretty_version": "8 (jessie)",
363-
"best_version": "8",
374+
"best_version": "8.0",
364375
"like": "debian",
365376
"codename": "jessie",
366377
}
@@ -1216,6 +1227,20 @@ def test_debian8_release(self):
12161227
self._test_outcome(desired_outcome)
12171228
self._test_non_existing_release_file()
12181229

1230+
def test_debian10_release(self):
1231+
desired_outcome = {
1232+
"id": "debian",
1233+
"name": "Debian GNU/Linux",
1234+
"pretty_name": "Debian GNU/Linux 10 (buster)",
1235+
"version": "10",
1236+
"pretty_version": "10 (buster)",
1237+
"best_version": "10.11",
1238+
"codename": "buster",
1239+
"major_version": "10",
1240+
}
1241+
self._test_outcome(desired_outcome)
1242+
self._test_non_existing_release_file()
1243+
12191244
def test_exherbo_release(self):
12201245
desired_outcome = {
12211246
"id": "exherbo",
@@ -1434,7 +1459,7 @@ def test_raspbian7_release(self):
14341459
"pretty_name": "Raspbian GNU/Linux 7 (wheezy)",
14351460
"version": "7",
14361461
"pretty_version": "7 (wheezy)",
1437-
"best_version": "7",
1462+
"best_version": "7.1",
14381463
"like": "debian",
14391464
"codename": "wheezy",
14401465
"major_version": "7",
@@ -1449,7 +1474,7 @@ def test_raspbian8_release(self):
14491474
"pretty_name": "Raspbian GNU/Linux 8 (jessie)",
14501475
"version": "8",
14511476
"pretty_version": "8 (jessie)",
1452-
"best_version": "8",
1477+
"best_version": "8.0",
14531478
"like": "debian",
14541479
"codename": "jessie",
14551480
"major_version": "8",

0 commit comments

Comments
 (0)