Skip to content

Commit 22c9d6e

Browse files
committed
new method for getting download url
used in filedigest
1 parent 7d556a0 commit 22c9d6e

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

pyclowder/api/v1/files.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@
2323
except:
2424
pass
2525

26+
# pylint: disable=too-many-arguments
27+
def get_download_url(connector, client, fileid, intermediatefileid=None, ext=""):
28+
"""Download file to be processed from Clowder.
29+
30+
Keyword arguments:
31+
connector -- connector information, used to get missing parameters and send status updates
32+
client -- ClowderClient containing authentication credentials
33+
fileid -- the file that is currently being processed
34+
intermediatefileid -- either same as fileid, or the intermediate file to be used
35+
ext -- the file extension, the downloaded file will end with this extension
36+
"""
37+
38+
connector.message_process({"type": "file", "id": fileid}, "Get download url for file.")
39+
40+
# TODO: intermediateid doesn't really seem to be used here, can we remove entirely?
41+
if not intermediatefileid:
42+
intermediatefileid = fileid
43+
44+
url = '%s/api/files/%s?key=%s' % (client.host, intermediatefileid, client.key)
45+
return url
2646

2747
# pylint: disable=too-many-arguments
2848
def download(connector, client, fileid, intermediatefileid=None, ext=""):

pyclowder/api/v2/files.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@
2424
pass
2525

2626

27+
def get_download_url(connector, client, fileid, intermediatefileid=None, ext=""):
28+
"""Download file to be processed from Clowder.
29+
30+
Keyword arguments:
31+
connector -- connector information, used to get missing parameters and send status updates
32+
client -- ClowderClient containing authentication credentials
33+
fileid -- the file that is currently being processed
34+
intermediatefileid -- either same as fileid, or the intermediate file to be used
35+
ext -- the file extension, the downloaded file will end with this extension
36+
"""
37+
38+
connector.message_process({"type": "file", "id": fileid}, "Getting download url for file.")
39+
40+
# TODO: intermediateid doesn't really seem to be used here, can we remove entirely?
41+
if not intermediatefileid:
42+
intermediatefileid = fileid
43+
44+
url = '%s/api/v2/files/%s' % (client.host, intermediatefileid)
45+
return url
46+
2747
# pylint: disable=too-many-arguments
2848
def download(connector, client, fileid, intermediatefileid=None, ext=""):
2949
"""Download file to be processed from Clowder.

pyclowder/files.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@
2727
except:
2828
pass
2929

30+
def get_download_url(connector, host, key, fileid, intermediatefileid=None, ext=""):
31+
client = ClowderClient(host=host, key=key)
32+
if clowder_version == 2:
33+
download_url = v2files.get_download_url(connector, client, fileid, intermediatefileid, ext)
34+
else:
35+
download_url = v1files.get_download_url(connector, client, fileid, intermediatefileid, ext)
36+
return download_url
3037

3138
# pylint: disable=too-many-arguments
3239
def download(connector, host, key, fileid, intermediatefileid=None, ext=""):

0 commit comments

Comments
 (0)