Skip to content

Commit

Permalink
avocado/utils/archive.py: make probe function for zstd public
Browse files Browse the repository at this point in the history
There's value in making the zstd probe function public (which was
previously not perceived).  This function can be used to skip/cancel
tests when a suitable zstd is not found.

Signed-off-by: Cleber Rosa <[email protected]>
  • Loading branch information
clebergnu committed Aug 5, 2024
1 parent 6c02201 commit f19efec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions avocado/utils/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,13 @@ def is_zstd_file(path):
return zstd_file.read(len(ZSTD_MAGIC)) == ZSTD_MAGIC


def _probe_zstd_cmd():
def probe_zstd_cmd():
"""
Attempts to find a suitable zstd tool that behaves as expected
:rtype: str or None
:returns: path to a suitable zstd executable or None if not found
"""
zstd_cmd = shutil.which("zstd")
if zstd_cmd is not None:
proc = subprocess.run(
Expand All @@ -136,7 +142,7 @@ def zstd_uncompress(path, output_path=None, force=False):
"""
Extracts a zstd compressed file.
"""
zstd_cmd = _probe_zstd_cmd()
zstd_cmd = probe_zstd_cmd()
if not zstd_cmd:
raise ArchiveException("Unable to find a suitable zstd compression tool")
output_path = _decide_on_path(path, ".zst", output_path)
Expand Down
2 changes: 1 addition & 1 deletion selftests/unit/utils/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from avocado.utils import archive, crypto, data_factory
from selftests.utils import BASEDIR, temp_dir_prefix

ZSTD_AVAILABLE = archive._probe_zstd_cmd() is not None
ZSTD_AVAILABLE = archive.probe_zstd_cmd() is not None


class ArchiveTest(unittest.TestCase):
Expand Down

0 comments on commit f19efec

Please sign in to comment.