Commit 0aa19b98 authored by Floréal Cabanettes's avatar Floréal Cabanettes
Browse files

Add support to URL instead of local files + some improvements + some bug fixes, Implements #11

parent a1a6968e
......@@ -503,4 +503,12 @@ div#uploading-loading {
color: blue;
background: url("images/loading-cascade.gif") no-repeat 0 25px;
background-size: 200px 30px;
}
div.progress, input.show-file {
width: 100% !important;
}
div.in-label {
width: 300px;
}
\ No newline at end of file
......@@ -13,10 +13,8 @@ dgenies.run.init = function () {
};
dgenies.run.restore_form = function () {
if ($("select.query").val() === "0")
$("input#query").val("");
if ($("select.target").val() === "0")
$("input#target").val("");
dgenies.run.change_fasta_type("query", $("select.query").find(":selected").text().toLowerCase(), true);
dgenies.run.change_fasta_type("target", $("select.target").find(":selected").text().toLowerCase(), true);
};
dgenies.run.upload_next = function () {
......@@ -80,7 +78,7 @@ dgenies.run.init_fileuploads = function () {
$("button#button-target").click(function() {
$("input.file-target").trigger("click");
})
}
};
dgenies.run.set_events = function() {
$("input.file-query").change(function () {
......@@ -98,6 +96,32 @@ dgenies.run.set_events = function() {
$("button#submit").click(function () {
dgenies.run.submit();
});
$("select.query").change(function() {
dgenies.run.change_fasta_type("query", $("select.query").find(":selected").text().toLowerCase())
});
$("select.target").change(function() {
dgenies.run.change_fasta_type("target", $("select.target").find(":selected").text().toLowerCase())
});
};
dgenies.run.change_fasta_type = function (fasta, type, keep_url=false) {
let button = $("button#button-" + fasta);
let input = $("input#" + fasta);
let container = $("div." + fasta + "-label");
$("input.file-" + fasta).val("");
if (type === "local") {
button.show();
input.prop("readonly", true);
input.val("");
container.width(300);
}
else {
button.hide();
input.prop("readonly", false);
if (!keep_url)
input.val("");
container.width(348);
}
};
dgenies.run.set_filename = function (name, fasta) {
......
......@@ -10,6 +10,9 @@ class Fasta:
def get_path(self):
return self.__path
def set_name(self, name):
self.__name = name
def get_name(self):
return self.__name
......
......@@ -9,6 +9,9 @@ from config_reader import AppConfigReader
from pony.orm import db_session, select
from database import db, Job
from lib.Fasta import Fasta
from lib.functions import allowed_file
import requests
import wget
class JobManager:
......@@ -89,22 +92,56 @@ class JobManager:
finale_path = self._decompress(finale_path)
return finale_path
def __getting_file_from_url(self, fasta: Fasta):
finale_path = wget.download(fasta.get_path(), self.output_dir, None)
if finale_path.endswith(".gz"):
finale_path = self._decompress(finale_path)
return finale_path
@db_session
def __check_url(self, fasta: Fasta):
filename = requests.head(fasta.get_path(), allow_redirects=True).url.split("/")[-1]
allowed = allowed_file(filename)
if not allowed:
job = Job.get(id_job=self.id_job)
job.status = "error"
job.error = "<p>File <b>%s</b> downloaded from <b>%s</b> is not a Fasta file!</p>" \
"<p>If this is unattended, please contact the support.</p>" % (filename, fasta.get_path())
db.commit()
return allowed
@db_session
def getting_files(self):
job = Job.get(id_job=self.id_job)
job.status = "getfiles"
db.commit()
correct = True
if self.query is not None:
if self.query.get_type() == "local":
self.query.set_path(self.__getting_local_file(self.query))
if self.target is not None:
elif self.__check_url(self.query):
finale_path = self.__getting_file_from_url(self.query)
filename = os.path.splitext(os.path.basename(finale_path).replace(".gz", ""))[0]
self.query.set_path(finale_path)
self.query.set_name(filename)
else:
correct = False
if correct and self.target is not None:
if self.target.get_type() == "local":
self.target.set_path(self.__getting_local_file(self.target))
job = Job.get(id_job=self.id_job)
job.status = "waiting"
db.commit()
if self.batch_system_type == "local":
self.__launch_local()
elif self.__check_url(self.target):
finale_path = self.__getting_file_from_url(self.target)
filename = os.path.splitext(os.path.basename(finale_path).replace(".gz", ""))[0]
self.target.set_path(finale_path)
self.target.set_name(filename)
else:
correct = False
if correct:
job = Job.get(id_job=self.id_job)
job.status = "waiting"
db.commit()
if self.batch_system_type == "local":
self.__launch_local()
@db_session
def launch(self):
......@@ -129,6 +166,6 @@ class JobManager:
def status(self):
job = Job.get(id_job=self.id_job)
if job is not None:
return job.status
return job.status, job.error
else:
return "unknown"
return "unknown", ""
......@@ -3,3 +3,5 @@ Jinja2==2.9.*
pony==0.7.*
docopt==0.6.*
numpy
wget==3.2
requests==2.18.*
......@@ -16,6 +16,7 @@ class Job(db.Entity):
batch_type = Required(str)
status = Required(str, default="submitted")
date_created = Required(datetime.datetime)
error = Optional(str)
db.generate_mapping(create_tables=True)
......@@ -97,13 +97,15 @@ def launch_analysis():
os.makedirs(folder_files)
# Save files:
query_name = os.path.splitext(file_query.replace(".gz", ""))[0]
query_path = os.path.join(app.config["UPLOAD_FOLDER"], session["user_tmp_dir"], file_query)
query_name = os.path.splitext(file_query.replace(".gz", ""))[0] if file_query_type == "local" else None
query_path = os.path.join(app.config["UPLOAD_FOLDER"], session["user_tmp_dir"], file_query) \
if file_query_type == "local" else file_query
query = Fasta(name=query_name, path=query_path, type_f=file_query_type)
target = None
if file_target != "":
target_name = os.path.splitext(file_target.replace(".gz", ""))[0]
target_path = os.path.join(app.config["UPLOAD_FOLDER"], session["user_tmp_dir"], file_target)
target_name = os.path.splitext(file_target.replace(".gz", ""))[0] if file_target_type == "local" else None
target_path = os.path.join(app.config["UPLOAD_FOLDER"], session["user_tmp_dir"], file_target) \
if file_target_type == "local" else file_target
target = Fasta(name=target_name, path=target_path, type_f=file_target_type)
# Launch job:
......@@ -118,8 +120,8 @@ def launch_analysis():
@app.route('/status/<id_job>', methods=['GET'])
def status(id_job):
job = JobManager(id_job)
status = job.status()
return render_template("status.html", title=app_title, status=status, id_job=id_job,
j_status, error = job.status()
return render_template("status.html", title=app_title, status=j_status, error=error, id_job=id_job,
menu="results")
......
......@@ -56,7 +56,7 @@
<input id="query" name="query" class="form-control show-file" type="text" value="" readonly/>
</div>
<button class="btn btn-file" type="button" id="button-query">
<button class="btn btn-file" type="button" id="button-query" title="Select a file">
<span class="glyphicon glyphicon-folder-open"></span>&nbsp
</button>
<div class="loading-file query" style="display: none"></div>
......@@ -74,14 +74,14 @@
<option value="1">Url</option>
</select>
<div class="query-label in-label">
<div class="target-label in-label">
<div id="progress-target" class="progress">
<div class="bar" style="width: 0%;"></div>
</div>
<input id="target" name="target" class="form-control show-file" type="text" value="" readonly/>
</div>
<button class="btn btn-file" type="button" id="button-target">
<button class="btn btn-file" type="button" id="button-target" title="Select a file">
<span class="glyphicon glyphicon-folder-open"></span>&nbsp
</button>
<div class="loading-file target" style="display: none"></div>
......
......@@ -21,8 +21,13 @@
<p>Your job has ended successfully.<br/>
Please <a href="/result/{{ id_job }}">click here</a> to show results.</p>
{% elif status == "error" %}
<p>Your job has failed. Please try again.<br/>
If the problem persists, please contact the support.</p>
<p>Your job has failed.
{% if error == "" %}
Please try again.<br/>
If the problem persists, please contact the support.
{% else %}
<br/>{{ error | safe }}
{% endif %}</p>
{% else %}
<p>This job does not exists!</p>
{% endif %}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment