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