-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathworkflowUploaderCwl.py
executable file
·135 lines (117 loc) · 4.4 KB
/
workflowUploaderCwl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/python3
####################################################################################
#
# Copyright (c) 2018 Thanasis Vergoulis & Konstantinos Zagganas & Loukas Kavouras
# for the Information Management Systems Institute, "Athena" Research Center.
#
# This file is part of SCHeMa.
#
# SCHeMa is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# SCHeMa is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Foobar. If not, see <https://www.gnu.org/licenses/>.
#
####################################################################################
import workflowUploadFunctions as wuf
import sys
import subprocess
import re
import os.path
import json
import os
import yaml
workName=sys.argv[1]
workVersion=sys.argv[2]
workflowPath=sys.argv[3]
workflowExtension=sys.argv[4]
user=sys.argv[5]
visibility=sys.argv[6]
description=sys.argv[7]
biotools=sys.argv[8]
doiFile=sys.argv[9]
covid19=sys.argv[10]
github_link=sys.argv[11]
instructions=sys.argv[12]
def quoteEnclose(string):
return "'" + string + "'"
# Read configuration
configFileName=os.path.dirname(os.path.abspath(__file__)) + '/configuration.json'
configFile=open(configFileName,'r')
config=json.load(configFile)
configFile.close()
# containerMount=config['workflowContainerMount']
workAllowedExt=set(['yaml','cwl'])
# Get the folder where the file was uploaded
tokens=workflowPath.split('/')
filename=tokens[-1]
folderTokens=tokens[0:-1]
folder='/'.join(folderTokens)
# If the whole workflow is not uploaded as a single cwl or yaml file,
# or if it is compressed, then uncompress, and find the main workflow file.
if workflowExtension not in workAllowedExt:
if workflowExtension=='zip':
subprocess.call(['unzip','-o',workflowPath, '-d', folder])
elif workflowExtension=='gz':
filenameTokens=filename.split('.')
#Check if the file is .tar.gz or simple .gz and uncompress
if (len(filenameTokens)>1):
secondExtension=filenameTokens[1]
if secondExtension=='tar':
subprocess.call(['tar','xzf',workflowPath, '-C', folder])
else:
subprocess.call(['gzip','-d','-k','-f', workflowPath])
else:
subprocess.call(['gzip','-d','-k','-f', workflowPath])
elif workflowExtension=='tar':
subprocess.call(['tar','xvf',workflowPath, '-C', folder])
# print(folder)
workFile,retCode,content=wuf.getMainWorkflowFileCwl(folder,workAllowedExt)
if retCode!=0:
print("getMainWorkflowFile method failed with code %d" % retCode)
exit(retCode)
else: # If 'workflowExtension' is in 'workAllowedExt', so either 'yaml' or 'cwl'
f=open(workflowPath, encoding='utf8', mode='r')
try:
content=yaml.load(f,Loader=yaml.FullLoader)
except Exception as e:
print("File: %s " % workflowPath)
print("ERROR: %s" % e)
exit(11)
finally:
f.close()
workFile=workflowPath
print('Workfile: ' + workFile)
# workFile=workFile.replace(containerMount['local'],containerMount['wesContainer'])
try:
content
except NameError:
print("No content found in workflow");
exit(3)
if 'inputs' not in content:
print("Inputs key not in content dictionary")
exit(2)
wuf.workflowStoreCwl(workName,workVersion,workFile,user,visibility,
description,biotools,doiFile,github_link,covid19,workflowPath,instructions)
inputs=content['inputs']
# print(content)
if isinstance(inputs,dict):
exit_value=wuf.inputStoreDictCwl(workName,workVersion,content['inputs'])
elif isinstance(inputs,list):
exit_value=wuf.inputStoreListCwl(workName,workVersion,content['inputs'])
else:
exit_value=50
exit(exit_value)
# uf.imageStoreAndClassify(softName,softVersion, imageNew,script,user,visibility,
# workingDir,imountPoint,omountPoint,description,cwlPath,biotools,doiFile,mpi,original,dockerHub,covid19)
# if 'inputs' not in cwlContent:
# cwlContent['inputs']=[];
# exit_value=uf.inputStore(softName,softVersion, cwlContent['inputs'])
# exit(exit_value)