Skip to content

Commit

Permalink
Prefer pathlib to os
Browse files Browse the repository at this point in the history
Change-Id: I1d70e1f28d295571c92fb215efc4915b011665da
  • Loading branch information
spt29 committed Aug 26, 2024
1 parent fa13907 commit ac45d0b
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions omd/packages/omd/omdlib/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.

import os
import sys
from collections.abc import Iterable, Mapping, Sequence
from pathlib import Path
Expand Down Expand Up @@ -54,12 +53,12 @@ def main_versions(


def default_version(versions_path: Path) -> str:
return os.path.basename(os.path.realpath(versions_path / "default"))
return (versions_path / "default").resolve().name


def omd_versions(versions_path: Path) -> Iterable[str]:
try:
return sorted([v for v in os.listdir(versions_path) if v != "default"])
return sorted(d.name for d in versions_path.iterdir() if d.name != "default")
except FileNotFoundError:
return []

Expand All @@ -71,8 +70,7 @@ def version_exists(v: str, versions_path: Path) -> bool:
def version_from_site_dir(site_dir: Path) -> str | None:
"""The version of a site is solely determined by the link ~SITE/version
In case the version of a site can not be determined, it reports None."""
version_link = site_dir / "version"
try:
return os.readlink(version_link).split("/")[-1]
return (site_dir / "version").readlink().name
except Exception:
return None

0 comments on commit ac45d0b

Please sign in to comment.