Skip to content

Commit 1062e39

Browse files
author
Peter Amstutz
committed
Can get outputs back.
1 parent 5aa41eb commit 1062e39

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

cwl_flask.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def handlecwl(workflow):
3232
with tempfile.NamedTemporaryFile() as f:
3333
f.write(request.stream.read())
3434
f.flush()
35-
outdir = tempfile.mkdtemp()
35+
outdir = tempfile.mkdtemp(dir=os.path.abspath("output"))
3636
proc = subprocess.Popen(["cwl-runner", os.path.abspath(wf), f.name],
3737
stdout=subprocess.PIPE,
3838
stderr=subprocess.PIPE,
@@ -59,7 +59,30 @@ def index():
5959
print e
6060
return str(e), 500, {"Content-Type": "text/plain"}
6161

62+
@app.route("/output")
63+
def outindex():
64+
try:
65+
return json.dumps(["%s/%s" % (r[7:], f2) for r, _, f in os.walk("output") for f2 in f]), 200, {"Content-Type": "application/json"}
66+
except Exception as e:
67+
print e
68+
return str(e), 500, {"Content-Type": "text/plain"}
69+
70+
@app.route("/output/<path:fn>")
71+
def outfile(fn):
72+
if ".." in fn:
73+
return "Path cannot contain ..", 400, {"Content-Type": "text/plain"}
74+
75+
fn = os.path.join("output", fn)
76+
77+
if not os.path.exists(fn):
78+
return "Not found", 404, {"Content-Type": "text/plain"}
79+
80+
with open(fn, "r") as f:
81+
return f.read(), 200
82+
6283
if __name__ == "__main__":
6384
if not os.path.exists("files"):
6485
os.mkdir("files")
86+
if not os.path.exists("output"):
87+
os.mkdir("output")
6588
app.run()

0 commit comments

Comments
 (0)