Skip to content

Commit

Permalink
Fixed upload when inputs is a list
Browse files Browse the repository at this point in the history
  • Loading branch information
zagganas committed May 3, 2022
1 parent 6f3b55a commit 172d83b
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 3 deletions.
7 changes: 6 additions & 1 deletion models/SoftwareUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function upload()
$command=Software::sudoWrap(Yii::$app->params['scriptsFolder'] . "imageUploader.py ");
$command.= implode(" ", $arguments) . " ";
$command.= "2>&1";

Software::exec_log($command,$out,$ret);

$errors='';
Expand Down Expand Up @@ -325,6 +325,11 @@ public function upload()
$errors.="One of the inputs does has an unknown type.";
$errors.="<br />Please correct the file syntax and try again or contact an administrator.";
break;
case 100:
$errors.="Error: code $ret. ";
$errors.="Your CWL definition has a format not recognized by the system";
$errors.="<br />Please contact an administrator to fix the issue.";
break;
default:
$errors.="Error: code $ret. ";
$errors.="<br />An unexpected error occurred.";
Expand Down
8 changes: 7 additions & 1 deletion scheduler_files/imageUploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ def quoteEnclose(string):
if 'inputs' not in cwlContent:
cwlContent['inputs']=[];

exit_value=uf.inputStore(softName,softVersion, cwlContent['inputs'])
if isinstance(cwlContent['inputs'],dict):
exit_value=uf.inputStoreDict(softName,softVersion, cwlContent['inputs'])
elif isinstance(cwlContent['inputs'],list):
exit_value=uf.inputStoreList(softName,softVersion, cwlContent['inputs'])
else:
exit_value=100

exit(exit_value)

145 changes: 144 additions & 1 deletion scheduler_files/uploadFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def cwlReturnDockerImage(content):
else:
exit(23)

def inputStore(softName,softVersion, inputs):
def inputStoreDict(softName,softVersion, inputs):
types=set(['string', 'int', 'long', 'float', 'double', 'null', 'File', 'Directory', 'Any','boolean'])

#open db connection and get image id
Expand Down Expand Up @@ -278,6 +278,149 @@ def inputStore(softName,softVersion, inputs):

return 0

def inputStoreList(softName,softVersion, inputs):
types=set(['string', 'int', 'long', 'float', 'double', 'null', 'File', 'Directory', 'Any','boolean'])

#open db connection and get image id
conn=psg.connect(host=host, user=dbuser, password=passwd, dbname=dbname)
cur=conn.cursor()

query="SELECT id FROM software WHERE name='" + softName + "' AND version='" + softVersion + "'"
cur.execute(query)
result=cur.fetchall()
softId=str(result[0][0])

#save script in database and get its id
# print(inputs)
if len(inputs)==0:
exit(30)

#create queries for input insertion
query='INSERT INTO software_inputs(name, position, softwareid, field_type, prefix, separate, optional, default_value, is_array, array_separator, nested_array_binding) VALUES '

bindingFlag=False
positionFlag=False
separateInner=False
prefixInner=False


for inpt in inputs:
try:
inpt_name=inpt['id']
except:
deleteSavedSoftware(softName,softVersion)
return 100
is_array='f'
array_separator=''
nested_array_binding='f'
prefix=''
separate='t'
if 'type' not in inpt.keys():
#stop execution and return because this is serious
deleteSavedSoftware(softName,softVersion)
return 34
fieldType=inpt['type']
#field type is array
if isinstance(fieldType,dict):
if fieldType['type']!='array':
deleteSavedSoftware(softName,softVersion)
return 36
is_array='t'
if 'inputBinding' in fieldType:
nested_array_binding='t'
innerBinding=fieldType['inputBinding']
if 'separate' in binding:
separateInner=True
if innerBinding['separate']==False:
separate='f'
if 'prefix' in binding:
prefixInner=True
prefix=innerBinding['prefix']
if 'items' not in fieldType:
deleteSavedSoftware(softName,softVersion)
return 37

fieldType=fieldType['items']

else:
fieldType=inpt['type'].strip()


if 'inputBinding' not in inpt.keys():
bindingFlag=True
continue
#exit(32)


outerBinding=inpt['inputBinding']
# Get position, separate and prefix from inputBinding.
# If it does not exist, ignore input
if 'position' not in outerBinding:
positionFlat=True
continue
position=outerBinding['position']

if ('separate' in outerBinding) and (separateInner==False):
if outerBinding['separate']=='false':
separate='f'
else:
separate='t'

if ('prefix' in outerBinding) and (prefixInner==False):
prefix=outerBinding['prefix']
if ('itemSeparator' in outerBinding):
array_separator=outerBinding['itemSeparator']

# print(separate)

optional='f'
if fieldType[-1]=='?':
optional='t'
fieldType=fieldType[:-1]

if '[]' in fieldType:
is_array='t'
fieldType=fieldType[:-2]

if fieldType not in types:
#stop execution and return because this is serious
deleteSavedSoftware(softName,softVersion)
print("Field type: %s not in Types %s" % (fieldType,types))
return 35


#get default value
defaultValue=''
if (fieldType!='File') and (fieldType!='Directory') and (fieldType!='null'):
if 'default' in inpt.keys():
defaultValue=str(inpt['default'])

name=quoteEnclose(inpt_name)
fieldType=quoteEnclose(fieldType)
prefix=quoteEnclose(prefix)
defaultValue=quoteEnclose(defaultValue)
optional=quoteEnclose(optional)
separate=quoteEnclose(separate)
is_array=quoteEnclose(is_array)
array_separator=quoteEnclose(array_separator)
nested_array_binding=quoteEnclose(nested_array_binding)

query+='(' + name + ',' + str(position) + ',' + str(softId) + ',' + fieldType + ',' + prefix + ',' + separate + ',' + optional + ',' + defaultValue + ',' + is_array+ ',' + array_separator + ',' + nested_array_binding + '),'

query=query[:-1]
# print(query)
cur.execute(query)
conn.commit()

conn.close()

if bindingFlag:
return 32
if positionFlag:
return 33

return 0

def imageStore(name,version,image,script,user,visibility,
workingDir,imountPoint,omountPoint, description,cwlPath,biotools,doiFile,mpi,original,docker_or_local,covid19,instructions,gpu):

Expand Down

0 comments on commit 172d83b

Please sign in to comment.