aboutsummaryrefslogtreecommitdiff
path: root/bh20simplewebuploader/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'bh20simplewebuploader/main.py')
-rw-r--r--bh20simplewebuploader/main.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py
index bfc7762..f5324a5 100644
--- a/bh20simplewebuploader/main.py
+++ b/bh20simplewebuploader/main.py
@@ -3,12 +3,18 @@ import tempfile
import shutil
import subprocess
import os
+import sys
import re
import string
import yaml
import urllib.request
from flask import Flask, request, redirect, send_file, send_from_directory, render_template
+import os.path
+
+if not os.path.isfile('bh20sequploader/mainx.py'):
+ print("WARNING: run FLASK from the root of the source repository!", file=sys.stderr)
+
app = Flask(__name__, static_url_path='/static', static_folder='static')
# Limit file upload size. We shouldn't be working with anything over 1 MB; these are small genomes.
@@ -126,6 +132,7 @@ def generate_form(schema):
return list(walk_fields(root_name))
+
# At startup, we need to load the current metadata schema so we can make a form for it
METADATA_SCHEMA = yaml.safe_load(urllib.request.urlopen('https://raw.githubusercontent.com/arvados/bh20-seq-resource/master/bh20sequploader/bh20seq-schema.yml'))
FORM_ITEMS = generate_form(METADATA_SCHEMA)
@@ -184,15 +191,17 @@ def receive_files():
# We're going to work in one directory per request
dest_dir = tempfile.mkdtemp()
+ # The uploader will happily accept a FASTQ with this name
fasta_dest = os.path.join(dest_dir, 'fasta.fa')
metadata_dest = os.path.join(dest_dir, 'metadata.json')
try:
if 'fasta' not in request.files:
return (render_template('error.html',
- error_message="You did not include a FASTA file."), 403)
+ error_message="You did not include a FASTA or FASTQ file."), 403)
try:
with open(fasta_dest, 'wb') as out_stream:
- copy_with_limit(request.files.get('fasta').stream, out_stream)
+ # Use a plausible file size limit for a little FASTQ
+ copy_with_limit(request.files.get('fasta').stream, out_stream, limit=50*1024*1024)
except FileTooBigError as e:
# Delegate to the 413 error handler
return handle_large_file(e)
@@ -247,12 +256,16 @@ def receive_files():
error_message="You did not include metadata."), 403)
# Try and upload files to Arvados using the sequence uploader CLI
- result = subprocess.run(['bh20-seq-uploader', fasta_dest, metadata_dest],
+
+ cmd = ['python3','bh20sequploader/main.py', fasta_dest, metadata_dest]
+ print(" ".join(cmd),file=sys.stderr)
+ result = subprocess.run(cmd,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode != 0:
# It didn't work. Complain.
- error_message="Upload failed. Uploader returned {} and said:\n{}".format(result.returncode, result.stderr)
+ error_message="Uploader returned value {} and said:".format(result.returncode) + str(result.stderr.decode('utf-8'))
+ print(error_message, file=sys.stderr)
return (render_template('error.html', error_message=error_message), 403)
else:
# It worked. Say so.