Skip to content

Commit

Permalink
[2024-07-01 12:48] Fix for issue with AROME repository (#130)
Browse files Browse the repository at this point in the history
Created from original fix provided by Rick de Rooij.

Also fixed the folder not always being properly cleaned up under Linux systems due to issues with trailing slashes.
  • Loading branch information
rflinnenbank authored Jul 1, 2024
1 parent 12e9a3d commit 4333c88
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "weather_provider_api"
version = "2.53.0"
version = "2.54.0"
description = "Weather Provider Libraries and API"
authors = ["Verbindingsteam", "Raoul Linnenbank <[email protected]>"]
license = "MPL-2.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# SPDX-FileCopyrightText: 2019-2022 Alliander N.V.
# SPDX-License-Identifier: MPL-2.0
import glob
import os
import re
import sys
import tarfile
Expand Down Expand Up @@ -178,7 +179,8 @@ def _process_downloaded_file(self, download_folder: Path, filename: str, predict
def _clear_temp_folder(download_folder: Path):
"""A function that cleans up the temporary download folder to prevent issues with partially written files."""
logger.debug(f"Emptying the download folder: {download_folder}")
for existing_file in glob.glob(f"{download_folder}*.*"):
file_filter = f"{download_folder}/*.*" if str(download_folder)[-1] != "/" else f"{download_folder}*.*"
for existing_file in glob.glob(file_filter):
try:
# Try to delete:
Path(existing_file).unlink()
Expand All @@ -191,9 +193,13 @@ def _unpack_downloaded_file(download_folder: Path, file_name: str):
"""The function that unpacks downloaded files to prediction files."""
logger.info(f"Unpacking file: {file_name}")
try:
tar_file = tarfile.open(download_folder.joinpath(file_name))
tar_file.extractall(path=download_folder)
tar_file.close()
tar = tarfile.open(download_folder.joinpath(file_name))
for member in tar.getmembers():
if member.isreg(): # Only process files
member.name = os.path.basename(
member.name) # Remove the path to setting it to only the filename.
tar.extract(member, download_folder) # Extract the file to the download folder
tar.close()
except Exception as e:
logger.error(f"The tarfile [{file_name}] could not be unpacked!")
raise e
Expand Down

0 comments on commit 4333c88

Please sign in to comment.