Skip to content

Commit

Permalink
[Fixes #12124] Fix data retriever to handle not default destination f…
Browse files Browse the repository at this point in the history
…olders
  • Loading branch information
mattiagiupponi committed May 23, 2024
1 parent 1247254 commit cfbbf0a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 8 additions & 4 deletions geonode/storage/data_retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,12 @@ def __init__(self, files, tranfer_at_creation=False):
if tranfer_at_creation:
self.transfer_remote_files()

def transfer_remote_files(self):
def transfer_remote_files(self, cloning_directory=None, prefix=None, create_tempdir=True):
from geonode.utils import mkdtemp

self.temporary_folder = mkdtemp()
self.temporary_folder = cloning_directory or settings.MEDIA_ROOT
if create_tempdir:
self.temporary_folder = mkdtemp(cloning_directory or settings.MEDIA_ROOT, prefix=prefix)
for name, data_item_retriever in self.data_items.items():
file_path = data_item_retriever.transfer_remote_file(self.temporary_folder)
self.file_paths[name] = Path(file_path)
Expand All @@ -172,10 +174,12 @@ def transfer_remote_files(self):
os.chmod(self.temporary_folder, settings.FILE_UPLOAD_DIRECTORY_PERMISSIONS)
return self.file_paths

def get_paths(self, allow_transfer=False):
def get_paths(self, allow_transfer=False, cloning_directory=None, prefix=None, create_tempdir=True):
if not self.file_paths:
if allow_transfer:
self.transfer_remote_files()
self.transfer_remote_files(
cloning_directory=cloning_directory, prefix=prefix, create_tempdir=create_tempdir
)
else:
raise DataRetrieverExcepion(detail="You can't retrieve paths without clone file first!")
return self.file_paths.copy()
Expand Down
6 changes: 4 additions & 2 deletions geonode/storage/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,13 @@ def replace_single_file(self, old_file: str, new_file: BinaryIO, prefix: str = N
def generate_filename(self, filename):
return self._concrete_storage_manager.generate_filename(filename)

def clone_remote_files(self) -> Mapping:
def clone_remote_files(self, cloning_directory=None, prefix=None, create_tempdir=True) -> Mapping:
"""
Using the data retriever object clone the remote path into a local temporary storage
"""
return self.data_retriever.get_paths(allow_transfer=True)
return self.data_retriever.get_paths(
allow_transfer=True, cloning_directory=cloning_directory, prefix=prefix, create_tempdir=create_tempdir
)

def get_retrieved_paths(self) -> Mapping:
"""
Expand Down

0 comments on commit cfbbf0a

Please sign in to comment.