Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore "n/a" from lsb_release output allowing other sources to be honored #374

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ namely from these data sources (from high to low precedence):
* The os-release file `/etc/os-release` if present, with a fall-back on `/usr/lib/os-release` if needed.
* The output of the `lsb_release` command, if available.
* The distro release file (`/etc/*(-|_)(release|version)`), if present.
* The `uname` command for BSD based distrubtions.
* The `uname` command for BSD based distributions.


## Python and Distribution Support
Expand Down
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
Loading