def show_counter_graph(): if sessions.check_session(): try: vmc, t = get_vmc() if not vmc._is_formula(): return {"text": 'The formula is not valid, no counter example available'}, 200 clean_counter = vmc.clean_counterexample() if not clean_counter: if vmc.get_eval() == 'FALSE': return {"explanation": vmc.get_explanation()} else: return {"text": 'The formula is TRUE, no counter example available'}, 200 t.load_mts(clean_counter) t.mts_to_dot(session['counter_graph']) if(os.path.isfile(os.path.join(app.config['TMP_FOLDER'], os.path.basename(session['counter_graph'])))): return { "text": "Here's an example where the provided property is false:", "graph": os.path.join('static','tmp', os.path.basename(session['counter_graph'])) }, 200 else: return {'text': 'No counter example graph available'}, 404 except VmcException as e: return {"text": str(e)}, 400 except Exception as e: print(str(e)) return {"text": "An error occured"}, 400
def solve_hdd(): pm = ProcessManager.get_instance() if not sessions.check_session(): return {"text": "No ambiguities data available execute a full analysis first"}, 400 if not session['ambiguities']: queue = pm.get_queue(session['id']) if not queue: return {"text": "No ambiguities data available execute a full analysis first"}, 400 else: session['ambiguities'] = queue.get() payload = {} file_path = session['model'] if os.path.isfile(file_path): dis = Disambiguator.from_file(file_path) dis.remove_transitions(session['ambiguities']['dead']) dis.solve_hidden_deadlocks(session['ambiguities']['hidden']) pm.delete_queue(session['id']) graph = graphviz.Graph(dis.get_graph()) payload['mts'] = graph.get_mts() payload['text'] = "Removed hidden deadlocks and dead transitions" payload['graph'] = graph.get_graph() payload['edges'], payload['nodes'] = graph.get_graph_number() graph.draw_graph(session['graph']) return payload, 200 return {"text": 'File not found'}, 400
def translate_to_pml(): if sessions.check_session(): t = Translator() print('mdoasdoiajsodij') print(session['model']) t.load_model(session['model']) return {"text": t.translate_to_pml()}, 200
def get_graph(): message = """No graph data available, the graph may be too big render. You can render it locally by downloading the graph source code and use the following command: dot -Tsvg model.dot -o output.svg""" if 'src' in request.form and request.form['src']: graphviz.Graph(request.form['src']).draw_graph(session['graph']) if sessions.check_session(): if os.path.isfile(session['graph']): return {"source":os.path.join('static', 'tmp', os.path.basename(session['graph']))}, 200 return {"text":message}, 400
def download(): """The function returns the path to the requested file Arguments: request.form['target'] -- Part of the HTTP request is used to choose the right file. request.form['main'] -- Part of the HTTP request is used to populate the content of the temporary file used to serve the download.""" if not sessions.check_session(): return {'text': "Session timed-out"}, 400 if not ('target' in request.form and 'main' in request.form): return {'text': "Invalid request"}, 400 payload = 'empty' mimetype = '' format = '' if (request.form['target'] == 'source'): payload = request.form['main'] mimetype = 'text/plain' format = "model.dot" elif (request.form['target'] == 'summary'): payload = request.form['main'] mimetype = 'text/html' format = "summary.html" elif (request.form['target'] == 'graph'): mime = 'image/svg+xml' format = "graph.svg" path = os.path.join('static', 'tmp', os.path.basename(session['graph'])) if os.path.isfile(os.path.join('src', path)): return {"source": path, 'name': format}, 200 else: return {"text": "File not found"}, 404 elif (request.form['target'] == 'console'): payload = request.form['main'] mimetype = 'text/plain' format = "log.txt" else: return {"text": "Invalid request"}, 400 with open(session['output'] + format, 'w') as tmp: tmp.write(payload) path = os.path.join('static', 'tmp', os.path.basename(session['output'] + format)) if os.path.isfile(os.path.join('src', path)): return {"source": path, "name": format}, 200 else: return {"text": "File not found"}, 404
def get_output(): pm = ProcessManager.get_instance() if not sessions.check_session(): sessions.delete_output_file() return {"text": '\nSession timed-out'}, 404 elif not 'id' in session or not pm.process_exists(session['id']): sessions.delete_output_file() return {"text": ''}, 404 else: if pm.is_alive(session['id']): with open(session['output']) as out: out.seek(session['position']) result = out.read(4096) session['position'] = out.tell() return {"text": result}, 206 else: with open(session['output']) as out: out.seek(session['position']) result = out.read() os.remove(session['output']) queue = pm.get_queue(session['id']) payload = {} payload['text'] = result graph = graphviz.Graph.from_file(session['model']) payload['edges'], payload['nodes'] = graph.get_graph_number() payload['mts'] = graph.get_mts() if (queue): tmp = queue.get()['ambiguities'] session['ambiguities'] = tmp payload['ambiguities'] = tmp ProcessManager.get_instance().delete_queue(session['id']) try: dis = Disambiguator.from_file(session['model']) dis.highlight_ambiguities(tmp['dead'], tmp['false'], tmp['hidden']) payload['graph'] = dis.get_graph() graphviz.Graph(dis.get_graph()).draw_graph( session['graph']) return payload, 200 except: return payload, 200 return payload, 200
def test_check_session(self): with app.test_request_context(): session['timeout'] = time.time() + 600 assert sessions.check_session()
def test_check_session_undefined(self): with app.test_request_context(): assert not sessions.check_session()
def test_check_session_undefined_timeout(self): with app.test_request_context(): session['timeout'] = None assert not sessions.check_session()
def test_check_expired_session(self): with app.test_request_context(): session['timeout'] = time.time() - 1 assert not sessions.check_session()