xtts-castellano / test.py
sob111's picture
Create test.py
ecf7ba2 verified
raw
history blame
1.5 kB
import os, subprocess, sys, zipfile
# === 1.B Extraer el dataset
def extract_zip(zip_file_path, destination_path):
"""
Extracts the contents of a ZIP file to a specified directory.
Args:
zip_file_path (str): The full path to the ZIP file.
destination_path (str): The directory where the contents will be extracted.
"""
# Create the destination directory if it doesn't exist
os.makedirs(destination_path, exist_ok=True)
try:
# Open the ZIP file in read mode
with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
# Extract all the contents to the specified directory
zip_ref.extractall(destination_path)
print(f"✅ Extracted '{zip_file_path}' to '{destination_path}' successfully.")
except zipfile.BadZipFile:
print(f"❌ Error: The file '{zip_file_path}' is not a valid ZIP file.")
except FileNotFoundError:
print(f"❌ Error: The file '{zip_file_path}' was not found.")
except Exception as e:
print(f"❌ An unexpected error occurred: {e}")
# Example usage:
zip_file = "/home/user/app/voxpopuli_es_500.zip"
DATASET_PATH = "/tmp/dataset/voxpopuli_es_500"
# To protect against security vulnerabilities, it is important to sanitize the destination path.
# This prevents an attacker from using a malicious ZIP file to write outside the destination folder.
safe_destination = os.path.abspath(DATASET_PATH)
# Call the function
extract_zip(zip_file, safe_destination)