Skip to content

Commit

Permalink
Ignore "n/a" from lsb_release output allowing other sources to be hon…
Browse files Browse the repository at this point in the history
…ored

> closes #373
  • Loading branch information
HorlogeSkynet committed Dec 21, 2024
1 parent 02ffe07 commit 2556eca
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/distro/distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,8 +1193,10 @@ def _parse_lsb_release_content(lines: Iterable[str]) -> Dict[str, str]:
if len(kv) != 2:
# Ignore lines without colon.
continue
k, v = kv
props.update({k.replace(" ", "_").lower(): v.strip()})
k, v = kv[0], kv[1].strip()
if v == "n/a":
v = ""
props.update({k.replace(" ", "_").lower(): v})
return props

@cached_property
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
/bin/cat <<'EOT'
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux trixie/sid
Release: n/a
Codename: trixie
EOT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
trixie/sid
23 changes: 21 additions & 2 deletions tests/test_distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,25 @@ def test_ubuntu14normal_lsb_release(self) -> None:
}
self._test_outcome(desired_outcome)

def test_debian13noosrelease_lsb_release(self) -> None:
self._setup_for_distro(os.path.join(TESTDISTROS, "lsb", "debian13_noosrelease"))

self.distro = distro.LinuxDistribution(
os_release_file="path-to-non-existing-file",
distro_release_file="path-to-non-existing-file",
)

desired_outcome = {
"id": "debian",
"name": "Debian",
"pretty_name": "Debian GNU/Linux trixie/sid",
"version": "trixie/sid",
"pretty_version": "trixie/sid (trixie)",
"best_version": "trixie/sid",
"codename": "trixie",
}
self._test_outcome(desired_outcome)

def test_ubuntu14nomodules_lsb_release(self) -> None:
self._setup_for_distro(os.path.join(TESTDISTROS, "lsb", "ubuntu14_nomodules"))

Expand Down Expand Up @@ -1677,9 +1696,9 @@ def test_sles12_release(self) -> None:
"name": "SLES",
"pretty_name": "SUSE Linux Enterprise Server 12 SP1",
"version": "12.1",
"pretty_version": "12.1 (n/a)",
"pretty_version": "12.1 (s390x)",
"best_version": "12.1",
"codename": "n/a",
"codename": "s390x",
"major_version": "12",
"minor_version": "1",
}
Expand Down

0 comments on commit 2556eca

Please sign in to comment.