Skip to content

Commit

Permalink
Add version_id to distro release info for Armbian
Browse files Browse the repository at this point in the history
  • Loading branch information
HorlogeSkynet committed Mar 16, 2024
1 parent 6f17ee3 commit 0d8db44
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/distro/distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,9 @@ def version(self, pretty: bool = False, best: bool = False) -> str:
elif self.id() == "debian" or "debian" in self.like().split():
# On Debian-like, add debian_version file content to candidates list.
versions.append(self._debian_version)
if self._distro_release_info.get("id") == "armbian":
# On Armbian, add version from armbian-release file to candidates list.
versions.append(self._armbian_version)
version = ""
if best:
# This algorithm uses the last version in priority order that has
Expand Down Expand Up @@ -1226,6 +1229,16 @@ def _debian_version(self) -> str:
except FileNotFoundError:
return ""

@cached_property
def _armbian_version(self) -> str:
try:
with open(
os.path.join(self.etc_dir, "armbian-release"), encoding="ascii"
) as fp:
return self._parse_os_release_content(fp).get("version", "")
except FileNotFoundError:
return ""

@staticmethod
def _parse_uname_content(lines: Sequence[str]) -> Dict[str, str]:
if not lines:
Expand Down Expand Up @@ -1309,6 +1322,7 @@ def _distro_release_info(self) -> Dict[str, str]:
"name", ""
).startswith("#"):
distro_info["name"] = "Armbian"
distro_info["version_id"] = self._armbian_version

# CloudLinux < 7: manually enrich info with proper id.
if "cloudlinux" in distro_info.get("name", "").lower():
Expand Down
11 changes: 9 additions & 2 deletions tests/test_distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -1928,7 +1928,7 @@ def test_armbian_release(self) -> None:
"like": "",
"version": "10",
"pretty_version": "10 (buster)",
"best_version": "10",
"best_version": "23.02.2",
"major_version": "10",
"minor_version": "",
}
Expand All @@ -1937,6 +1937,7 @@ def test_armbian_release(self) -> None:
desired_info = {
"id": "armbian",
"name": "Armbian",
"version_id": "23.02.2",
}
self._test_release_file_info("armbian-release", desired_info)

Expand Down Expand Up @@ -2383,6 +2384,12 @@ def test_repr(self) -> None:
repr_str = repr(distro._distro)
assert "LinuxDistribution" in repr_str
for attr in MODULE_DISTRO.__dict__.keys():
if attr in ("root_dir", "etc_dir", "usr_lib_dir", "_debian_version"):
if attr in (
"root_dir",
"etc_dir",
"usr_lib_dir",
"_debian_version",
"_armbian_version",
):
continue
assert f"{attr}=" in repr_str

0 comments on commit 0d8db44

Please sign in to comment.