Commit bc27d632 authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Add inforun functionnality

parent 0d4c0f6a
......@@ -12,6 +12,7 @@ import os
import argparse
import webbrowser
import threading
import json
from glob import glob
import time
from dgenies.config_reader import AppConfigReader
......@@ -91,10 +92,11 @@ def parse_args():
# Run message
inforun = subparsers.add_parser("inforun", help="Set a message at the top of the run page")
inforun.set_defaults(which="inforun")
inforun.add_argument("-m", "--message", type=str, required=False, help="Message to add")
inforun.add_argument("-m", "--message", type=str, help="Message to add")
inforun.add_argument("-t", "--type", type=str, choices=["info", "warn", "critical", "success"],
help="Type of message")
inforun.add_argument("-c", "--clear", help="Remove message", action='store_const',
const=True, default=False)
#inforun.add_argument("")
args = parser.parse_args()
......@@ -107,6 +109,8 @@ def parse_args():
return "clear", args
if args.subparser_name == "gallery":
return "gallery_" + args.which, args
if args.subparser_name == "inforun":
return "inforun", args
else:
parser.print_help()
print("\nYou must specify the command to launch")
......@@ -316,6 +320,21 @@ def del_from_gallery_by_name(name):
return list_pictures
def set_inforun_message(message, type):
inforun_file = os.path.join(config.config_dir, ".inforun")
with open(inforun_file, "w") as info:
info.write(json.dumps({
"message": message,
"type": type
}))
def clear_inforun():
inforun_file = os.path.join(config.config_dir, ".inforun")
if os.path.exists(inforun_file):
os.remove(inforun_file)
if __name__ == "__main__":
command, args = parse_args()
if command == "run":
......@@ -346,3 +365,14 @@ if __name__ == "__main__":
os.remove(os.path.join(config.app_data, "gallery", picture))
except FileNotFoundError:
pass
elif command == "inforun":
if args.clear:
clear_inforun()
else:
if args.message is None:
print("-m/--message option is required if -c/--clear not given")
exit(1)
if args.type is None:
print("-t/--type option is required if -c/--clear not given")
exit(1)
set_inforun_message(args.message, args.type)
......@@ -464,6 +464,33 @@ div.navbar {
/* Run form: */
div.inforun {
padding: 10px;
font-weight: bold;
border: 2px solid;
border-top: 0 !important;
}
div.inforun.info {
background: #51ccff;
border-color: #084863;
}
div.inforun.warn {
background: #ff7d06;
border-color: #7a3502;
}
div.inforun.critical {
background: #ff3e31;
border-color: #80221b;
}
div.inforun.success {
background: #32e04d;
border-color: #13561e;
}
div.submit-form table td {
padding-bottom: 8px;
vertical-align: bottom;
......
This diff is collapsed.
......@@ -26,6 +26,11 @@
display: none;
}
</style>
{% if inforun is not none %}
<div class="inforun {{ inforun.type }}">
{{ inforun.message }}
</div>
{% endif %}
<form id="submit_minimap" method=post action="#">
<h2 class="title-launch">Launch map analysis</h2>
<div class="errors-submit">
......
from dgenies import app, app_title, app_folder, config_reader, mailer, APP_DATA, MODE, DEBUG, VERSION
import os
import sys
import time
import datetime
import shutil
import re
import threading
import traceback
import json
from flask import render_template, request, url_for, jsonify, Response, abort, send_file, Markup
from pathlib import Path
from dgenies.lib.paf import Paf
......@@ -61,6 +63,15 @@ def run():
"""
Run page
"""
inforun = None
inforun_file = os.path.join(config_reader.config_dir, ".inforun")
if os.path.exists(inforun_file):
try:
with open(inforun_file, "r") as info:
inforun = json.loads(info.read())
except json.JSONDecodeError:
print("Unable to parse inforun file. Ignoring it.", file=sys.stderr)
pass
tools = Tools().tools
tools_names = sorted(list(tools.keys()), key=lambda x: (tools[x].order, tools[x].name))
tools_ava = {}
......@@ -89,7 +100,7 @@ def run():
example=config_reader.example_target != "",
target=os.path.basename(config_reader.example_target),
query=os.path.basename(config_reader.example_query), tools_names=tools_names, tools=tools,
tools_ava=tools_ava, version=VERSION)
tools_ava=tools_ava, version=VERSION, inforun=inforun)
@app.route("/run-test", methods=['GET'])
......
Markdown is supported
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