Skip to content

Commit 1edecd5

Browse files
committed
Tried working with connectors for datasets but just modified download for files
1 parent df8ff14 commit 1edecd5

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

pyclowder/connectors.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ def _download_file_metadata(self, host, secret_key, fileid, filepath):
309309
(fd, md_file) = tempfile.mkstemp(suffix=md_name, dir=md_dir)
310310

311311
with os.fdopen(fd, "wb") as tmp_file:
312+
print("Writing metadata to %s" % md_file)
313+
print(file_md)
312314
tmp_file.write(json.dumps(file_md))
313315

314316
return (md_dir, md_file)
@@ -327,12 +329,21 @@ def _prepare_dataset(self, host, secret_key, resource):
327329
tmp_dirs_created.append(temp_link_dir)
328330

329331
# Check if miniomounted path is set and if the file is in the minio mounted path
330-
if self.minio_mounted_path:
331-
for file in resource['files']:
332-
file_path = self._check_for_local_file(file, file['id'])
333-
if file_path:
334-
# print("Found file locally: %s" % file_path)
335-
located_files.append(file_path)
332+
# if self.minio_mounted_path:
333+
# for file in resource['files']:
334+
# file_path = self._check_for_local_file(file, file['id'])
335+
# if not file_path:
336+
# missing_files.append(file)
337+
# else:
338+
# md_file_path = file['name'].split('.')[0] + "_metadata.json"
339+
# (file_md_dir, file_md_tmp) = self._download_file_metadata(host, secret_key, file['id'], md_file_path)
340+
# located_files.append(file_path)
341+
# located_files.append(file_md_tmp)
342+
# tmp_files_created.append(file_md_tmp)
343+
# tmp_dirs_created.append(file_md_dir)
344+
345+
# else:
346+
336347
#check if any files in dataset accessible locally
337348
ds_file_list = pyclowder.datasets.get_file_list(self, host, secret_key, resource["id"])
338349
for ds_file in ds_file_list:
@@ -349,7 +360,7 @@ def _prepare_dataset(self, host, secret_key, resource):
349360

350361
# Also get file metadata in format expected by extrator
351362
(file_md_dir, file_md_tmp) = self._download_file_metadata(host, secret_key, ds_file['id'],
352-
ds_file['filepath'])
363+
ds_file['filepath'])
353364
located_files.append(file_path)
354365
located_files.append(file_md_tmp)
355366
tmp_files_created.append(file_md_tmp)
@@ -393,6 +404,7 @@ def _prepare_dataset(self, host, secret_key, resource):
393404
except Exception as e:
394405
logger.exception("No files found and download failed")
395406

407+
print("File paths: %s" % file_paths)
396408
return (file_paths, tmp_files_created, tmp_dirs_created)
397409

398410
# pylint: disable=too-many-branches,too-many-statements

pyclowder/files.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ def download(connector, host, key, fileid, intermediatefileid=None, ext="", trac
5151
tracking -- should the download action be tracked
5252
"""
5353
client = ClowderClient(host=host, key=key)
54+
# Check if minio mounted path is set
55+
minio_mounted_path = os.getenv("MINIO_MOUNTED_PATH", "")
56+
if minio_mounted_path:
57+
# Check if the file is stored in Minio mount path
58+
minio_file_path = minio_mounted_path + "/" + fileid
59+
if os.path.isfile(minio_file_path):
60+
return minio_file_path
61+
# Else download the file from Clowder
5462
inputfilename = files.download(connector, client, fileid, intermediatefileid, ext)
5563
return inputfilename
5664

0 commit comments

Comments
 (0)