Skip to content

Commit 20a9559

Browse files
author
Peter Amstutz
committed
Support subdirs in attachments.
Wes-client uses relpath() relative to the main workflow.
1 parent 18ca9cd commit 20a9559

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

wes_client/util.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,12 @@ def build_wes_request(workflow_file, json_path, attachments=None):
129129
if attachment.startswith("file://"):
130130
attachment = attachment[7:]
131131
attach_f = open(attachment, "rb")
132+
relpath = os.path.relpath(attachment, os.path.dirname(workflow_file[7:]))
132133
elif attachment.startswith("http"):
133134
attach_f = urlopen(attachment)
135+
relpath = os.path.basename(attach_f)
134136

135-
parts.append(("workflow_attachment", (os.path.basename(attachment), attach_f)))
137+
parts.append(("workflow_attachment", (relpath, attach_f)))
136138

137139
return parts
138140

wes_client/wes_client_main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def main(argv=sys.argv[1:]):
6666

6767
if args.log:
6868
response = client.get_run_log(run_id=args.log)
69-
sys.stdout.write(response["workflow_log"]["stderr"])
69+
sys.stdout.write(requests.get(response["run_log"]["stderr"], headers=auth).text)
7070
return 0
7171

7272
if args.get:

wes_service/arvados_wes.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ def invoke_cwl_runner(self, cr_uuid, workflow_url, workflow_params,
165165

166166
self.log_for_run(cr_uuid, stderrdata, env['ARVADOS_API_TOKEN'])
167167

168-
if tempdir:
169-
shutil.rmtree(tempdir)
168+
if tempdir:
169+
shutil.rmtree(tempdir)
170170

171171
except subprocess.CalledProcessError as e:
172172
api.container_requests().update(uuid=cr_uuid, body={"priority": 0,
@@ -272,11 +272,10 @@ def log_object(cr):
272272
"exit_code": containerlog["exit_code"] or 0
273273
}
274274
if containerlog["log"]:
275-
r["stdout"] = "%sc=%s/_/%s" % (api._resourceDesc["keepWebServiceUrl"], containerlog["log"], "stdout.txt") # NOQA
276-
r["stderr"] = "%sc=%s/_/%s" % (api._resourceDesc["keepWebServiceUrl"], containerlog["log"], "stderr.txt") # NOQA
277-
else:
278-
r["stdout"] = "%s/x-dynamic-logs/stdout" % (connexion.request.url)
279-
r["stderr"] = "%s/x-dynamic-logs/stderr" % (connexion.request.url)
275+
r["stdout_keep"] = "%sc=%s/_/%s" % (api._resourceDesc["keepWebServiceUrl"], containerlog["log"], "stdout.txt") # NOQA
276+
r["stderr_keep"] = "%sc=%s/_/%s" % (api._resourceDesc["keepWebServiceUrl"], containerlog["log"], "stderr.txt") # NOQA
277+
r["stdout"] = "%s/x-dynamic-logs/stdout" % (connexion.request.url)
278+
r["stderr"] = "%s/x-dynamic-logs/stderr" % (connexion.request.url)
280279

281280
return r
282281

wes_service/util.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,14 @@ def collect_attachments(self, run_id=None):
5252
for k, ls in iterlists(connexion.request.files):
5353
for v in ls:
5454
if k == "workflow_attachment":
55-
filename = secure_filename(v.filename)
56-
dest = os.path.join(tempdir, filename)
55+
sp = v.filename.split("/")
56+
fn = []
57+
for p in sp:
58+
if p not in ("", ".", ".."):
59+
fn.append(secure_filename(p))
60+
dest = os.path.join(tempdir, *fn)
61+
if not os.path.isdir(os.path.dirname(dest)):
62+
os.makedirs(os.path.dirname(dest))
5763
self.log_for_run(run_id, "Staging attachment '%s' to '%s'" % (v.filename, dest))
5864
v.save(dest)
5965
body[k] = "file://%s" % tempdir # Reference to temp working dir.

0 commit comments

Comments
 (0)