Skip to content

Commit

Permalink
Merge pull request #736 from leocardao/mr/cardao/add-minor-os-info
Browse files Browse the repository at this point in the history
Add minor OS version to platform object
  • Loading branch information
leocardao authored Jul 2, 2024
2 parents 8f36db9 + 7d4ab68 commit 4487c59
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/e3/collection/dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,9 @@ def shortest_path(
dist: dict[VertexID | None, int] = {k: infinite for k in self.vertex_data}

# Keep track of the minimum distance
prev: dict[VertexID | None, VertexID | None] = {
k: None for k in self.vertex_data
}
prev: dict[VertexID | None, VertexID | None] = dict.fromkeys(
self.vertex_data, None
)

# Set of non visited vertices
unvisited: set[VertexID | None] = set(self.vertex_data)
Expand Down
8 changes: 4 additions & 4 deletions src/e3/electrolyt/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,10 @@ def _add_action(self, name: str, *args: Any, **kwargs: Any) -> None:
# If necessary adjust target machine name
if board is not None:
result.set_target(
result.target.platform,
result.target.os.version,
board,
result.target.os.mode,
name=result.target.platform,
version=result.target.os.version,
machine=board,
mode=result.target.os.mode,
)

# Set action attribute (with action name)
Expand Down
14 changes: 12 additions & 2 deletions src/e3/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,12 @@ def get_platform(
elif split_value[0] == "target":
return saved_target
elif not propagate_build_info:
return Platform.get(*split_value) # type: ignore
return Platform.get(
platform_name=split_value[0],
version=split_value[1],
machine=split_value[2],
mode=split_value[3],
)
else:
# Propagate machine name and OS version if necessary
if split_value[2] is None:
Expand All @@ -279,7 +284,12 @@ def get_platform(
# Linux machine should not change the OS version
if split_value[1] is None:
split_value[1] = saved_build.os.version
return Platform.get(*split_value) # type: ignore
return Platform.get(
platform_name=split_value[0],
version=split_value[1],
machine=split_value[2],
mode=split_value[3],
)

# Retrieve final values for build, host and target
build_opts = get_platform(build, propagate_build_info=True)
Expand Down
31 changes: 25 additions & 6 deletions src/e3/os/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SystemInfo:
_platform: str | None = None

# _os_version is a tuple: os version, kernel version
_os_version: tuple[str, str] | None = None
_os_version: tuple[str, str, str] | None = None

# _hostname is a tuble: hostname, domain. Joining with a dot hostname and domain
# represent the FQDN
Expand Down Expand Up @@ -138,10 +138,11 @@ def platform(cls) -> str:
return cls._platform

@classmethod
def os_version(cls) -> tuple[str, str]:
"""Compute OS version information.
def _get_os_version(cls) -> tuple[str, str, str]:
"""Compute all OS version information.
:return: a tuple containing os version and kernel version
:return: a tuple containing os version (maybe partial), kernel version and
a full os version.
"""
if cls._os_version is not None:
return cls._os_version
Expand All @@ -156,12 +157,14 @@ def os_version(cls) -> tuple[str, str]:
version = UNKNOWN
kernel_version = UNKNOWN
system = cls.uname.system
full_version = None

if system == "Darwin": # darwin-only
version = cls.uname.release
elif system == "FreeBSD": # bsd-only
version = re.sub("-.*", "", cls.uname.release)
elif system == "Linux": # linux-only
full_version_number = cls.ld_info["version"]
kernel_version = cls.uname.release
name = cls.ld_info["name"].lower()
if "redhat" in name or "red hat" in name: # os-specific
Expand All @@ -176,6 +179,7 @@ def os_version(cls) -> tuple[str, str]:
else: # os-specific
version_number = cls.ld_info["version"]
version = name + version_number
full_version = name + full_version_number
elif system == "AIX": # aix-only
version = cls.uname.version + "." + cls.uname.release
elif system == "SunOS": # solaris-only
Expand Down Expand Up @@ -252,10 +256,24 @@ def get_os_version() -> tuple[None, None, None] | tuple[float, int, bool]:
version = "2022"
else:
version = "10"
full_version = "10.0"

if full_version is None:
full_version = version

cls._os_version = (version, kernel_version)
cls._os_version = (version, kernel_version, full_version)
return version, kernel_version, full_version

@classmethod
def os_version(cls) -> tuple[str, str]:
version, kernel_version, _ = cls._get_os_version()
return version, kernel_version

@classmethod
def full_os_version(cls) -> str:
_, _, version = cls._get_os_version()
return version

@classmethod
def hostname(cls) -> tuple[str, str]:
"""Get hostname and associated domain.
Expand Down Expand Up @@ -387,4 +405,5 @@ def get(
kernel_version = UNKNOWN
else:
kernel_version = UNKNOWN
return OS(name, version, kernel_version, exeext, dllext, is_bareboard, mode)

return cls(name, version, kernel_version, exeext, dllext, is_bareboard, mode)
16 changes: 13 additions & 3 deletions src/e3/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ def get(
automatically (native case only). Otherwise should be a valid
version string.
:param machine: name of the machine
:param mode: an os mode (ex: rtp for vxworks)
:param compute_default: if True compute the default Arch for the
current machine (this parameter is for internal purpose only).
:param mode: an os mode (ex: rtp for vxworks)
"""
# normalize arguments
if not version:
version = e3.os.platform.UNKNOWN

if machine is None or machine == e3.os.platform.UNKNOWN:
machine = ""
if not mode:
Expand Down Expand Up @@ -132,15 +133,24 @@ def get(
is_default,
)

def to_dict(self) -> dict[str, Any]:
def to_dict(self, full_os_version: bool = False) -> dict[str, Any]:
"""Export os and cpu variables as os_{var} and cpu_{var}.
:param full_os_version: False by default. If True, use the full os version as
OS version (with major, minor etc...) if available. Otherwize, use a
potential partial OS version.
:return: a dictionary representing the current Arch instance
"""
str_dict = self._asdict()

for key, var in self.os.as_dict().items():
str_dict["os_" + key] = var

if full_os_version:
# Replace the default OS version
str_dict["os_version"] = self.system_info.full_os_version()

for key, var in self.cpu.as_dict().items():
str_dict["cpu_" + key] = var
del str_dict["os"]
Expand All @@ -166,6 +176,6 @@ def __str__(self) -> str:
" name: %(cpu_name)s\n"
" bits: %(cpu_bits)s\n"
" endian: %(cpu_endian)s\n"
" cores: %(cpu_cores)s" % self.to_dict()
" cores: %(cpu_cores)s" % self.to_dict(full_os_version=True)
)
return result

0 comments on commit 4487c59

Please sign in to comment.