1# SPDX-License-Identifier: GPL-2.0-or-later 2# 3# Utilities for python-based QEMU tests 4# 5# Copyright 2024 Red Hat, Inc. 6# 7# Authors: 8# Thomas Huth <thuth@redhat.com> 9 10import gzip 11import lzma 12import os 13import shutil 14 15 16def gzip_uncompress(gz_path, output_path): 17 if os.path.exists(output_path): 18 return 19 with gzip.open(gz_path, 'rb') as gz_in: 20 try: 21 with open(output_path, 'wb') as raw_out: 22 shutil.copyfileobj(gz_in, raw_out) 23 except: 24 os.remove(output_path) 25 raise 26 27def lzma_uncompress(xz_path, output_path): 28 if os.path.exists(output_path): 29 return 30 with lzma.open(xz_path, 'rb') as lzma_in: 31 try: 32 with open(output_path, 'wb') as raw_out: 33 shutil.copyfileobj(lzma_in, raw_out) 34 except: 35 os.remove(output_path) 36 raise 37