Skip to content

Commit

Permalink
[#44] compute aggregation path for updated aggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
pkdash committed Apr 21, 2023
1 parent 6f2747c commit 5efe36c
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion hsclient/hydroshare.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,16 @@ def _validate_aggregation_for_update(self, resource: 'Resource', agg_type: Aggre
if aggr is None:
raise Exception("This aggregation is not part of the specified resource.")

def _compute_updated_aggregation_path(self, temp_folder, *files) -> str:
file_path = os.path.join(temp_folder, os.path.basename(self.main_file_path))
return file_path

def _update_aggregation(self, resource, *files):
temp_folder = uuid4().hex
resource.folder_create(temp_folder)
resource.file_upload(*files, destination_path=temp_folder)
# check aggregation got created in the temp folder
file_path = os.path.join(temp_folder, os.path.basename(self.main_file_path))
file_path = self._compute_updated_aggregation_path(temp_folder, *files)
original_aggr_dir_path = dirname(self.main_file_path)
aggr = resource.aggregation(file__path=file_path)
if aggr is not None:
Expand Down Expand Up @@ -706,6 +710,19 @@ class GeoRasterAggregation(DataObjectSupportingAggregation):
def create(cls, base_aggr):
return super().create(aggr_cls=cls, base_aggr=base_aggr)

def _compute_updated_aggregation_path(self, temp_folder, *files) -> str:
file_path = ""
for _file in files:
filename = os.path.basename(_file)
if filename.endswith(".vrt"):
file_path = os.path.join(temp_folder, filename)
break
else:
filename = pathlib.Path(filename).stem + ".vrt"
file_path = os.path.join(temp_folder, filename)
break
return file_path

def _validate_aggregation_path(self, agg_path: str, for_save_data: bool = False) -> str:
if for_save_data:
tif_file_count = 0
Expand Down

0 comments on commit 5efe36c

Please sign in to comment.