Download a .tar.gz file using wget to the destination directory and extract its contents without renaming the downloaded file. :param url: The URL of the .tar.gz file to download. :param destination_directory: The directory where the file should be downloaded and extracted.
(url, destination_directory)
| 33 | |
| 34 | |
| 35 | def download_and_extract(url, destination_directory): |
| 36 | """ |
| 37 | Download a .tar.gz file using wget to the destination directory |
| 38 | and extract its contents without renaming the downloaded file. |
| 39 | |
| 40 | :param url: The URL of the .tar.gz file to download. |
| 41 | :param destination_directory: The directory where the file should be downloaded and extracted. |
| 42 | """ |
| 43 | os.makedirs(destination_directory, exist_ok=True) |
| 44 | |
| 45 | filename = os.path.basename(url) |
| 46 | file_path = os.path.join(destination_directory, filename) |
| 47 | |
| 48 | try: |
| 49 | subprocess.run( |
| 50 | ["wget", "-O", file_path, url], |
| 51 | check=True, |
| 52 | ) |
| 53 | print(f"Downloaded: {file_path}") |
| 54 | |
| 55 | with tarfile.open(file_path, "r:gz") as tar: |
| 56 | tar.extractall(path=destination_directory) |
| 57 | print(f"Extracted: {file_path} to {destination_directory}") |
| 58 | os.remove(file_path) |
| 59 | print(f"Deleted downloaded file: {file_path}") |
| 60 | except subprocess.CalledProcessError as e: |
| 61 | print(f"Error downloading file: {e}") |
| 62 | except Exception as e: |
| 63 | print(f"Error extracting file: {e}") |
| 64 | |
| 65 | |
| 66 | # cc flags |