4
4
from bravado .requests_client import RequestsClient
5
5
import json
6
6
import time
7
- import pprint
8
7
import sys
9
8
import os
10
9
import argparse
15
14
import urllib
16
15
import ruamel .yaml as yaml
17
16
18
- def main (argv = sys .argv [1 :]):
19
17
18
+ def main (argv = sys .argv [1 :]):
20
19
parser = argparse .ArgumentParser (description = 'Workflow Execution Service' )
21
- parser .add_argument ("--host" , type = str , default = os .environ .get ("WES_API_HOST" ))
22
- parser .add_argument ("--auth" , type = str , default = os .environ .get ("WES_API_AUTH" ))
23
- parser .add_argument ("--proto" , type = str , default = os .environ .get ("WES_API_PROTO" , "https" ))
20
+ parser .add_argument (
21
+ "--host" , type = str , default = os .environ .get ("WES_API_HOST" ))
22
+ parser .add_argument (
23
+ "--auth" , type = str , default = os .environ .get ("WES_API_AUTH" ))
24
+ parser .add_argument (
25
+ "--proto" , type = str , default = os .environ .get ("WES_API_PROTO" , "https" ))
24
26
parser .add_argument ("--quiet" , action = "store_true" , default = False )
25
27
parser .add_argument ("--outdir" , type = str )
26
28
@@ -32,8 +34,10 @@ def main(argv=sys.argv[1:]):
32
34
exgroup .add_argument ("--version" , action = "store_true" , default = False )
33
35
34
36
exgroup = parser .add_mutually_exclusive_group ()
35
- exgroup .add_argument ("--wait" , action = "store_true" , default = True , dest = "wait" )
36
- exgroup .add_argument ("--no-wait" , action = "store_false" , default = True , dest = "wait" )
37
+ exgroup .add_argument (
38
+ "--wait" , action = "store_true" , default = True , dest = "wait" )
39
+ exgroup .add_argument (
40
+ "--no-wait" , action = "store_false" , default = True , dest = "wait" )
37
41
38
42
parser .add_argument ("workflow_url" , type = str , nargs = "?" , default = None )
39
43
parser .add_argument ("job_order" , type = str , nargs = "?" , default = None )
@@ -50,31 +54,37 @@ def main(argv=sys.argv[1:]):
50
54
http_client .set_api_key (
51
55
split .hostname , args .auth ,
52
56
param_name = 'Authorization' , param_in = 'header' )
53
- client = SwaggerClient .from_url ("%s://%s/ga4gh/wes/v1/swagger.json" % (args .proto , args .host ),
54
- http_client = http_client , config = {'use_models' : False })
57
+ client = SwaggerClient .from_url (
58
+ "%s://%s/ga4gh/wes/v1/swagger.json" % (args .proto , args .host ),
59
+ http_client = http_client , config = {'use_models' : False })
55
60
56
61
if args .list :
57
62
l = client .WorkflowExecutionService .ListWorkflows ()
58
63
json .dump (l .result (), sys .stdout , indent = 4 )
59
64
return 0
60
65
61
66
if args .log :
62
- l = client .WorkflowExecutionService .GetWorkflowLog (workflow_id = args .log )
67
+ l = client .WorkflowExecutionService .GetWorkflowLog (
68
+ workflow_id = args .log )
63
69
sys .stdout .write (l .result ()["workflow_log" ]["stderr" ])
64
70
return 0
65
71
66
72
if args .get :
67
- l = client .WorkflowExecutionService .GetWorkflowLog (workflow_id = args .get )
73
+ l = client .WorkflowExecutionService .GetWorkflowLog (
74
+ workflow_id = args .get )
68
75
json .dump (l .result (), sys .stdout , indent = 4 )
69
76
return 0
70
77
71
78
with open (args .job_order ) as f :
72
79
input = yaml .safe_load (f )
73
80
basedir = os .path .dirname (args .job_order )
81
+
74
82
def fixpaths (d ):
75
83
if isinstance (d , dict ) and "location" in d :
76
- if not ":" in d ["location" ]:
77
- d ["location" ] = urllib .pathname2url (os .path .normpath (os .path .join (os .getcwd (), basedir , d ["location" ])))
84
+ if ":" not in d ["location" ]:
85
+ local_path = os .path .normpath (
86
+ os .path .join (os .getcwd (), basedir , d ["location" ]))
87
+ d ["location" ] = urllib .pathname2url (local_path )
78
88
visit (input , fixpaths )
79
89
80
90
workflow_url = args .workflow_url
@@ -98,14 +108,17 @@ def fixpaths(d):
98
108
sys .stdout .write (r ["workflow_id" ]+ "\n " )
99
109
exit (0 )
100
110
101
- r = client .WorkflowExecutionService .GetWorkflowStatus (workflow_id = r ["workflow_id" ]).result ()
111
+ r = client .WorkflowExecutionService .GetWorkflowStatus (
112
+ workflow_id = r ["workflow_id" ]).result ()
102
113
while r ["state" ] in ("QUEUED" , "INITIALIZING" , "RUNNING" ):
103
114
time .sleep (1 )
104
- r = client .WorkflowExecutionService .GetWorkflowStatus (workflow_id = r ["workflow_id" ]).result ()
115
+ r = client .WorkflowExecutionService .GetWorkflowStatus (
116
+ workflow_id = r ["workflow_id" ]).result ()
105
117
106
118
logging .info ("State is %s" , r ["state" ])
107
119
108
- s = client .WorkflowExecutionService .GetWorkflowLog (workflow_id = r ["workflow_id" ]).result ()
120
+ s = client .WorkflowExecutionService .GetWorkflowLog (
121
+ workflow_id = r ["workflow_id" ]).result ()
109
122
logging .info (s ["workflow_log" ]["stderr" ])
110
123
111
124
if "fields" in s ["outputs" ] and s ["outputs" ]["fields" ] is None :
@@ -117,5 +130,6 @@ def fixpaths(d):
117
130
else :
118
131
return 1
119
132
133
+
120
134
if __name__ == "__main__" :
121
135
sys .exit (main (sys .argv [1 :]))
0 commit comments