Skip to content

Commit 0d8db44

Browse files
committed
Add version_id to distro release info for Armbian
1 parent 6f17ee3 commit 0d8db44

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/distro/distro.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,9 @@ def version(self, pretty: bool = False, best: bool = False) -> str:
906906
elif self.id() == "debian" or "debian" in self.like().split():
907907
# On Debian-like, add debian_version file content to candidates list.
908908
versions.append(self._debian_version)
909+
if self._distro_release_info.get("id") == "armbian":
910+
# On Armbian, add version from armbian-release file to candidates list.
911+
versions.append(self._armbian_version)
909912
version = ""
910913
if best:
911914
# This algorithm uses the last version in priority order that has
@@ -1226,6 +1229,16 @@ def _debian_version(self) -> str:
12261229
except FileNotFoundError:
12271230
return ""
12281231

1232+
@cached_property
1233+
def _armbian_version(self) -> str:
1234+
try:
1235+
with open(
1236+
os.path.join(self.etc_dir, "armbian-release"), encoding="ascii"
1237+
) as fp:
1238+
return self._parse_os_release_content(fp).get("version", "")
1239+
except FileNotFoundError:
1240+
return ""
1241+
12291242
@staticmethod
12301243
def _parse_uname_content(lines: Sequence[str]) -> Dict[str, str]:
12311244
if not lines:
@@ -1309,6 +1322,7 @@ def _distro_release_info(self) -> Dict[str, str]:
13091322
"name", ""
13101323
).startswith("#"):
13111324
distro_info["name"] = "Armbian"
1325+
distro_info["version_id"] = self._armbian_version
13121326

13131327
# CloudLinux < 7: manually enrich info with proper id.
13141328
if "cloudlinux" in distro_info.get("name", "").lower():

tests/test_distro.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,7 +1928,7 @@ def test_armbian_release(self) -> None:
19281928
"like": "",
19291929
"version": "10",
19301930
"pretty_version": "10 (buster)",
1931-
"best_version": "10",
1931+
"best_version": "23.02.2",
19321932
"major_version": "10",
19331933
"minor_version": "",
19341934
}
@@ -1937,6 +1937,7 @@ def test_armbian_release(self) -> None:
19371937
desired_info = {
19381938
"id": "armbian",
19391939
"name": "Armbian",
1940+
"version_id": "23.02.2",
19401941
}
19411942
self._test_release_file_info("armbian-release", desired_info)
19421943

@@ -2383,6 +2384,12 @@ def test_repr(self) -> None:
23832384
repr_str = repr(distro._distro)
23842385
assert "LinuxDistribution" in repr_str
23852386
for attr in MODULE_DISTRO.__dict__.keys():
2386-
if attr in ("root_dir", "etc_dir", "usr_lib_dir", "_debian_version"):
2387+
if attr in (
2388+
"root_dir",
2389+
"etc_dir",
2390+
"usr_lib_dir",
2391+
"_debian_version",
2392+
"_armbian_version",
2393+
):
23872394
continue
23882395
assert f"{attr}=" in repr_str

0 commit comments

Comments
 (0)