Skip to content

Commit 5690899

Browse files
committed
adding a new method
files.get_summary gets the equivalent of the file info in v2
1 parent 4cb4058 commit 5690899

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

pyclowder/api/v2/files.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,22 @@ def download_info(connector, client, fileid):
9696

9797
return result
9898

99+
def download_summary(connector, client, fileid):
100+
"""Download file summary from Clowder.
101+
102+
Keyword arguments:
103+
connector -- connector information, used to get missing parameters and send status updates
104+
client -- ClowderClient containing authentication credentials
105+
fileid -- the file to fetch metadata of
106+
"""
107+
108+
url = '%s/api/v2/files/%s/summary' % (client.host, fileid)
109+
headers = {"Authorization": "Bearer " + client.key}
110+
# fetch data
111+
result = connector.get(url, stream=True, verify=connector.ssl_verify if connector else True, headers=headers)
112+
113+
return result
114+
99115

100116
def download_metadata(connector,client, fileid, extractor=None):
101117
"""Download file JSON-LD metadata from Clowder.

pyclowder/files.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ def download_info(connector, host, key, fileid):
7171
result = v1files.download_info(connector, client, fileid)
7272
return result.json()
7373

74+
def download_summary(connector, host, key, fileid):
75+
"""Download file summary from Clowder.
76+
77+
Keyword arguments:
78+
connector -- connector information, used to get missing parameters and send status updates
79+
host -- the clowder host, including http and port, should end with a /
80+
key -- the secret key to login to clowder
81+
fileid -- the file to fetch metadata of
82+
"""
83+
client = ClowderClient(host=host, key=key)
84+
if clowder_version == 2:
85+
result = v2files.download_summary(connector, client, fileid)
86+
else:
87+
result = v1files.download_info(connector, client, fileid)
88+
return result.json()
7489

7590
def download_metadata(connector, host, key, fileid, extractor=None):
7691
"""Download file JSON-LD metadata from Clowder.

0 commit comments

Comments
 (0)