tests/functional: add common zip_extract helper
authorDaniel P. Berrangé <berrange@redhat.com>
Tue, 17 Dec 2024 15:59:39 +0000 (15:59 +0000)
committerThomas Huth <thuth@redhat.com>
Tue, 17 Dec 2024 18:39:53 +0000 (19:39 +0100)
This mirrors the existing archive_extract and cpio_extract helpers

Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Message-ID: <20241217155953.3950506-19-berrange@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
tests/functional/qemu_test/archive.py

index 9872f08d238b0c4341a9b280b9c3bc2a7e856ab0..06b66701c061645ded1cc5f90acf2ac98867a814 100644 (file)
@@ -10,6 +10,7 @@
 import os
 import subprocess
 import tarfile
+import zipfile
 
 
 def tar_extract(archive, dest_dir, member=None):
@@ -29,3 +30,10 @@ def cpio_extract(cpio_handle, output_path):
                    input=cpio_handle.read(),
                    stderr=subprocess.DEVNULL)
     os.chdir(cwd)
+
+def zip_extract(archive, dest_dir, member=None):
+    with zipfile.ZipFile(archive, 'r') as zf:
+        if member:
+            zf.extract(member=member, path=dest_dir)
+        else:
+            zf.extractall(path=dest_dir)