Skip to content

Commit c7c9e62

Browse files
committed
updates
1 parent 3708d29 commit c7c9e62

File tree

1 file changed

+62
-15
lines changed

1 file changed

+62
-15
lines changed

expansion/expansion.py

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ def get_submission_order(
10171017
)
10181018
return submission_order
10191019

1020-
def delete_project(self, project_id, root_node="project", chunk_size=200):
1020+
def delete_project(self, project_id, root_node="project", chunk_size=200, nuke_project=False):
10211021
prog, proj = project_id.split("-", 1)
10221022
submission_order = self.get_submission_order(root_node=root_node)
10231023
delete_order = sorted(submission_order, key=lambda x: x[1], reverse=True)
@@ -1032,14 +1032,18 @@ def delete_project(self, project_id, root_node="project", chunk_size=200):
10321032
# node=node, project_id=project_id, chunk_size=chunk_size
10331033
# )
10341034
self.sub.delete_node(program=prog,project=proj,node_name=node)
1035-
try:
1036-
data = self.sub.delete_project(program=prog, project=proj)
1037-
except Exception as e:
1038-
print("Couldn't delete project '{}':\n\t{}".format(project_id, e))
1039-
if "Can not delete the project." in data:
1040-
print("{}".format(data))
1035+
if nuke_project is True:
1036+
try:
1037+
data = self.sub.delete_project(program=prog, project=proj)
1038+
except Exception as e:
1039+
print("Couldn't delete project '{}':\n\t{}".format(project_id, e))
1040+
if "Can not delete the project." in data:
1041+
print("{}".format(data))
1042+
else:
1043+
print("Successfully deleted the project '{}'".format(project_id))
10411044
else:
1042-
print("Successfully deleted the project '{}'".format(project_id))
1045+
print("Successfully deleted all nodes in the project '{}'.\nIf you'd like to delete thr project node itself, then add the flag 'nuke_project=True'.".format(project_id))
1046+
10431047

10441048
# Analysis Functions
10451049
def property_counts_table(self, prop, df):
@@ -5067,11 +5071,21 @@ def create_mock_tsv(self,
50675071

50685072
for prop in props:
50695073
if prop == 'md5sum':
5070-
md5 = str(hashlib.md5(b"test").hexdigest())
5071-
data['md5sum'] = [md5] * count
5074+
md5s = []
5075+
for i in range(count):
5076+
md5 = str(hashlib.md5(b"test").hexdigest())
5077+
md5s.append(md5)
5078+
data['md5sum'] = md5s
50725079
elif prop == 'object_id':
5073-
object_id = str(uuid.uuid4())
5074-
data['object_id'] = [object_id] * count
5080+
# add blank column to fill later upon submission (will create indexd records to get object_ids)
5081+
data['object_id'] = [np.nan] * count
5082+
# object_ids = []
5083+
# for i in range(count):
5084+
# irec = index.create_blank(uploader="[email protected]",file_name="thisisatest.filename")
5085+
# object_ids.append(irec['did'])
5086+
# OR
5087+
# object_ids.append(str(uuid.uuid4())) # guids will need to be created in indexd later for sheepdog submission to work
5088+
# data['object_id'] = object_ids
50755089
elif 'type' in dd[node]['properties'][prop]:
50765090
prop_type = dd[node]['properties'][prop]['type'] # expected type
50775091
if prop_type == 'array':
@@ -5134,9 +5148,6 @@ def create_mock_tsv(self,
51345148
self.submit_file(project_id="DEV-test",filename=output)
51355149
return df
51365150

5137-
5138-
5139-
51405151
def create_mock_project(self,
51415152
dd,
51425153
node_counts=None,
@@ -5230,4 +5241,40 @@ def create_mock_project(self,
52305241
outdir=outdir,
52315242
)
52325243
if submit_tsvs:
5244+
if 'object_id' in df and df['object_id'].isnull().values.any():
5245+
object_ids = []
5246+
for i in range(len(df)):
5247+
file_name = list(df['file_name'])[i]
5248+
try:
5249+
irec = self.create_blank_indexd_record(
5250+
uploader="[email protected]",
5251+
file_name=file_name
5252+
)
5253+
if 'did' in irec:
5254+
object_ids.append(irec['did'])
5255+
else:
5256+
print("No object_id in indexd response:\n\t{}".format(irec))
5257+
except:
5258+
print("Couldn't create the indexd record for file:\n\t{}.".format(file_name))
5259+
df['object_id'] = object_ids
52335260
d = self.submit_df(project_id=project_id, df=df, chunk_size=250)
5261+
5262+
def create_blank_indexd_record(self, uploader="[email protected]", file_name=None):
5263+
"""
5264+
Create a blank indexd record}
5265+
"""
5266+
iurl = "{}index/index/blank".format(self._endpoint)
5267+
payload = {"uploader": uploader, "file_name": file_name}
5268+
res = requests.post(
5269+
iurl,
5270+
headers={"content-type": "application/json"},
5271+
auth=self._auth_provider,
5272+
data=json.dumps(payload),
5273+
)
5274+
try:
5275+
irec = res.json()
5276+
object_id = irec['did']
5277+
return object_id
5278+
except:
5279+
print(res)
5280+
return res

0 commit comments

Comments
 (0)