Exemple #1
0
def update_session_timeout():
    """Updates timeout for valid sessions and updates last modification
    time for existing files related to the session"""
    pm = ProcessManager.get_instance()
    if 'id' in session:
        lock = pm.get_lock(session['id'])
        if lock:
            with lock:
                return update()
    return update()
Exemple #2
0
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
Exemple #3
0
def check_session():
    """Check if the current session is still valid by verifying if the
    timeout value is still bigger than the current time."""
    pm = ProcessManager.get_instance()
    if 'id' in session:
        lock = pm.get_lock(session['id'])
        if lock:
            with lock:
                return ('timeout' in session and session['timeout'] is not None
                        and session['timeout'] > time.time())
    else:
        return ('timeout' in session and session['timeout'] is not None
                and session['timeout'] > time.time())
Exemple #4
0
def close_session():
    """Closes a session by deleting all of its related files and by freeing
    the related session dictionary."""
    pm = ProcessManager.get_instance()
    session.pop('timeout', None)
    session.pop('position', None)
    if 'id' in session and session['id']:
        pm.end_process(session['id'])
        pm.delete_lock(session['id'])
    delete_output_file(True)
    session.pop('id', None)
    session.pop('output', None)
    session.pop('ambiguities', None)
    session.pop('graph', None)
    session.pop('counter_graph', None)
    session.pop('model', None)
Exemple #5
0
def run_vmc():
    pm = ProcessManager.get_instance()
    if not session['ambiguities']:
        queue = pm.get_queue(session['id'])
        if not queue:
            raise VmcException(
                "No ambiguities data available execute a full analysis first")
        else:
            session['ambiguities'] = queue.get()
    if (len(session['ambiguities']['hidden']) != 0):
        raise VmcException(
            "Hidden deadlocks detected. It is necessary to remove them before checking the property"
        )

    folder = session['output'].split('-output')[0]
    model = os.path.join(folder, 'model.txt')
    properties = os.path.join(folder, 'properties.txt')

    try:
        if sys.platform.startswith('linux'):
            vmc = VmcController(app.config['VMC_LINUX'])
        elif sys.platform.startswith('win'):
            vmc = VmcController(app.config['VMC_WINDOWS'])
        elif sys.platform.startswith('cygwin'):
            vmc = VmcController(app.config['VMC_WINDOWS'])
        elif sys.platform.startswith('darwin'):
            vmc = VmcController(app.config['VMC_MAC'])
        else:
            raise VmcException(
                "VMC is not compatible with your operating system")
        vmc.run_vmc(model, properties)
    except ValueError as ve:
        err = str(ve).strip()
        if os.path.isdir(folder):
            shutil.rmtree(folder)
        if err == 'Invalid vmc_path':
            raise VmcException("Unable to locate VMC executable")
        if err == 'Invalid model file':
            raise VmcException('Invalid model file')
        if err == 'Invalid properties file':
            raise VmcException('Invalid properties file')
    except:
        shutil.rmtree(folder)
        raise VmcException('An error occured')
    shutil.rmtree(folder)
    return vmc
Exemple #6
0
def translate_model():
    pm = ProcessManager.get_instance()
    if not session['ambiguities']:
        queue = pm.get_queue(session['id'])
        if not queue:
            raise VmcException(
                "No ambiguities data available execute a full analysis first")
        else:
            session['ambiguities'] = queue.get()
    if (len(session['ambiguities']['hidden']) != 0):
        raise VmcException(
            "Hidden deadlocks detected. It is necessary to remove them before checking the property"
        )

    fpath = session['model']
    actl_property = request.form['property']
    if (len(actl_property) == 0):
        raise VmcException('Missing property to be verified')

    if os.path.isfile(fpath):
        translator = Translator()
        translator.load_model(fpath)
        translator.translate()
        folder = session['output'].split('-output')[0]
        try:
            os.mkdir(folder)
        except FileExistsError:
            #if the directory is already present continue
            pass

        model = os.path.join(folder, 'model.txt')
        properties = os.path.join(folder, 'properties.txt')
        with open(model, "w") as mts:
            mts.write(translator.get_output())
            mts.flush()
        with open(properties, "w") as prop_file:
            prop_file.write(actl_property)
            prop_file.flush()
    else:
        raise VmcException('Unable to translate, FTS model not found.')