Skip to content

Commit dcca107

Browse files
authored
Merge pull request #9 from cgmeyer/develop
Develop
2 parents 89cc55e + f7fa8a1 commit dcca107

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

expansion/expansion.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,7 @@ def submit_file(self, project_id, filename, chunk_size=30, row_offset=0):
13241324

13251325

13261326
# indexd functions:
1327-
def get_urls(self, guids,api):
1327+
def get_urls(self, guids, api):
13281328
# Get URLs for a list of GUIDs
13291329
if isinstance(guids, str):
13301330
guids = [guids]
@@ -1356,6 +1356,30 @@ def get_guids_for_filenames(self, file_names,api):
13561356
guids[file_name] = guid
13571357
return guids
13581358

1359+
def get_record_for_url(self, url, api):
1360+
""" Returns the indexd record for a file's storage location URL ('urls' in indexd)
1361+
Example:
1362+
exp.get_record_for_url(url=https://icgc.bionimbus.org/index/index/?url=s3://pcawg-tcga-sarc-us/2720a2b8-3f4e-5b6e-9f74-1067a068462a, api=api)
1363+
"""
1364+
indexd_endpoint = "{}/index/index/".format(api)
1365+
indexd_query = "{}?url={}".format(indexd_endpoint,url)
1366+
output = requests.get(indexd_query, auth=self._auth_provider).text
1367+
response = json.loads(output)
1368+
index_records = response['records']
1369+
return index_records
1370+
1371+
def get_guid_for_url(self, url, api):
1372+
"""Return the GUID for a file's URL in indexd"""
1373+
index_records = self.get_record_for_url(url=url,api=api)
1374+
if len(index_records) == 1:
1375+
guid = index_records[0]['did']
1376+
return guid
1377+
else:
1378+
guids = []
1379+
for index_record in index_records:
1380+
guids.append(index_record['did'])
1381+
return guids
1382+
13591383
def delete_uploaded_files(self, guids):
13601384
"""
13611385
DELETE http://petstore.swagger.io/?url=https://raw.githubusercontent.com/uc-cdis/fence/master/openapis/swagger.yaml#/data/delete_data__file_id_

0 commit comments

Comments
 (0)