1*850a1951SThomas Huth# Utilities for python-based QEMU tests 2*850a1951SThomas Huth# 3*850a1951SThomas Huth# Copyright 2024 Red Hat, Inc. 4*850a1951SThomas Huth# 5*850a1951SThomas Huth# Authors: 6*850a1951SThomas Huth# Thomas Huth <thuth@redhat.com> 7*850a1951SThomas Huth# 8*850a1951SThomas Huth# This work is licensed under the terms of the GNU GPL, version 2 or 9*850a1951SThomas Huth# later. See the COPYING file in the top-level directory. 10*850a1951SThomas Huth 11*850a1951SThomas Huthimport tarfile 12*850a1951SThomas Huth 13*850a1951SThomas Huthdef archive_extract(archive, dest_dir, member=None): 14*850a1951SThomas Huth with tarfile.open(archive) as tf: 15*850a1951SThomas Huth if hasattr(tarfile, 'data_filter'): 16*850a1951SThomas Huth tf.extraction_filter = getattr(tarfile, 'data_filter', 17*850a1951SThomas Huth (lambda member, path: member)) 18*850a1951SThomas Huth if member: 19*850a1951SThomas Huth tf.extract(member=member, path=dest_dir) 20*850a1951SThomas Huth else: 21*850a1951SThomas Huth tf.extractall(path=dest_dir) 22