Skip to content

Commit

Permalink
Make sure to keep all unzipped files as file_paths
Browse files Browse the repository at this point in the history
CSV and JSON are both valid `base_file`s. However, the content of a
ZIP file containing a JSON file along with one or multiple CSV files
will not be stored as `data_retriever` will override all allowed
`base_file`s until just one file remain.
  • Loading branch information
ridoo committed Mar 23, 2023
2 parents d79159b + dd8df18 commit 28ab262
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions geonode/storage/data_retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,23 @@ def _unzip(self, zip_name: str) -> Mapping:
not_main_files = ["xml", "sld", "zip", "kmz"]
base_file_choices = [x for x in available_choices if x not in not_main_files]
for _file in Path(self.temporary_folder).iterdir():
if any([_file.name.endswith(_ext) for _ext in base_file_choices]):
self.file_paths["base_file"] = Path(str(_file))
elif not zipfile.is_zipfile(str(_file)):
if not zipfile.is_zipfile(str(_file)):
if any([_file.name.endswith(_ext) for _ext in base_file_choices]):
self.file_paths['base_file'] = Path(str(_file))
ext = _file.name.split(".")[-1]
self.file_paths[f"{ext}_file"] = Path(str(_file))
if f"{ext}_file" in self.file_paths:
existing = self.file_paths[f"{ext}_file"]
self.file_paths[f"{ext}_file"] = [ Path(str(_file)), *(existing if type(existing) == list else [existing]) ]
else:
self.file_paths[f"{ext}_file"] = Path(str(_file))

tmp = self.file_paths.copy()
for key, value in self.file_paths.items():
if type(value) == list:
for index, file_path in enumerate(value):
n = f"{key}_{index}" if index > 0 else key
tmp[n] = file_path
self.file_paths = tmp

# remiving the zip file
os.remove(zip_name)
Expand Down

0 comments on commit 28ab262

Please sign in to comment.