Skip to content

Commit

Permalink
Add support for AIX (closes #241)
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel FORESTIER committed Dec 14, 2021
1 parent 8032f16 commit 407db52
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
21 changes: 20 additions & 1 deletion distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def id() -> str:
"freebsd" FreeBSD
"midnightbsd" MidnightBSD
"rocky" Rocky Linux
"aix" AIX
============== =========================================
If you have a need to get distros for reliable IDs added into this set,
Expand Down Expand Up @@ -752,7 +753,8 @@ def __repr__(self) -> str:
"_os_release_info={self._os_release_info!r}, "
"_lsb_release_info={self._lsb_release_info!r}, "
"_distro_release_info={self._distro_release_info!r}, "
"_uname_info={self._uname_info!r})".format(self=self)
"_uname_info={self._uname_info!r}, "
"_oslevel_info={self._oslevel_info!r})".format(self=self)
)

def linux_distribution(
Expand Down Expand Up @@ -840,6 +842,9 @@ def version(self, pretty: bool = False, best: bool = False) -> str:
).get("version_id", ""),
self.uname_attr("release"),
]
if self.uname_attr("id").startswith("aix"):
# On AIX platforms, prefer oslevel command output.
versions.insert(0, self.oslevel_info())
version = ""
if best:
# This algorithm uses the last version in priority order that has
Expand Down Expand Up @@ -980,6 +985,12 @@ def uname_info(self) -> Dict[str, str]:
"""
return self._uname_info

def oslevel_info(self) -> str:
"""
Return AIX' oslevel command output.
"""
return self._oslevel_info

def os_release_attr(self, attribute: str) -> str:
"""
Return a single named information item from the os-release file data
Expand Down Expand Up @@ -1139,6 +1150,14 @@ def _uname_info(self) -> Dict[str, str]:
content = self._to_str(stdout).splitlines()
return self._parse_uname_content(content)

@cached_property
def _oslevel_info(self) -> str:
try:
stdout = subprocess.check_output("oslevel", stderr=subprocess.DEVNULL)
except (OSError, subprocess.CalledProcessError):
return ""
return self._to_str(stdout).strip()

@staticmethod
def _parse_uname_content(lines: Sequence[str]) -> Dict[str, str]:
if not lines:
Expand Down
3 changes: 3 additions & 0 deletions tests/resources/distros/aix72/bin/oslevel
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

echo "7.2.0.0"
3 changes: 3 additions & 0 deletions tests/resources/distros/aix72/bin/uname
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

echo "AIX 2"
14 changes: 14 additions & 0 deletions tests/test_distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,20 @@ def test_arch_release(self) -> None:
# considered a valid distro release file:
self._test_non_existing_release_file()

def test_aix72_release(self) -> None:
desired_outcome = {
"id": "aix",
"name": "AIX",
"pretty_name": "AIX 7.2.0.0",
"version": "7.2.0.0",
"pretty_version": "7.2.0.0",
"best_version": "7.2.0.0",
"major_version": "7",
"minor_version": "2",
"build_number": "0",
}
self._test_outcome(desired_outcome)

def test_centos5_release(self) -> None:
desired_outcome = {
"id": "centos",
Expand Down

0 comments on commit 407db52

Please sign in to comment.