From f78437742eb53c4889731eaa3fb2ca5eceb1e2bf Mon Sep 17 00:00:00 2001 From: Alexis Jeandet Date: Thu, 6 Apr 2023 12:12:25 +0200 Subject: [PATCH] Fixes windows CDA inventory construction Signed-off-by: Alexis Jeandet --- .../cda/_inventory_builder/__init__.py | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/speasy/webservices/cda/_inventory_builder/__init__.py b/speasy/webservices/cda/_inventory_builder/__init__.py index 743d28d7..a586ba2a 100644 --- a/speasy/webservices/cda/_inventory_builder/__init__.py +++ b/speasy/webservices/cda/_inventory_builder/__init__.py @@ -1,13 +1,14 @@ -from ._xml_catalogs_parser import load_xml_catalog +import os +import tarfile +from glob import glob +from tempfile import TemporaryDirectory + +from speasy.core import http from ._cdf_masters_parser import update_tree +from ._xml_catalogs_parser import load_xml_catalog +from ....config import cdaweb as cda_cfg from ....core.index import index -from speasy.core import http from ....core.inventory.indexes import SpeasyIndex, to_dict, from_dict -from ....config import cdaweb as cda_cfg -from tempfile import NamedTemporaryFile -import tarfile -import os -from glob import glob _MASTERS_CDF_PATH = f"{cda_cfg.inventory_data_path()}/masters_cdf/" _XML_CATALOG_PATH = f"{cda_cfg.inventory_data_path()}/all.xml" @@ -27,11 +28,12 @@ def _clean_master_cdf_folder(): def _download_and_extract_master_cdf(masters_url: str): - with NamedTemporaryFile('wb') as master_archive: - master_archive.write(http.get(masters_url).content) - master_archive.flush() - tar = tarfile.open(master_archive.name) + with TemporaryDirectory() as tmp_path: + with open(f"{tmp_path}/masters.tar", 'wb') as master_archive: + master_archive.write(http.get(masters_url).content) + tar = tarfile.open(f"{tmp_path}/masters.tar") tar.extractall(_MASTERS_CDF_PATH) + tar.close() def update_master_cdf(masters_url: str = "https://spdf.gsfc.nasa.gov/pub/software/cdawlib/0MASTERS/master.tar"):