Esempio n. 1
0
def load_backup_test(msg):
    '''
    Relay test start message to participant view
    '''

    test_name = msg.pop('test_name')
    part_key = msg.pop('part_key')
    thread_type = thread_types[test_name]
    socketio.emit('participant_start_{}'.format(test_name), namespace='/main')
    if part_key != "--":
        participant = participants[part_key]
        folder = participant.data_paths[test_name]
        backupPath = os.path.join(folder, "{}_state.pkl".format(test_name))
    else:
        raise ValueError("Participant must be selected...")

    socketio.emit('participant_start',
                  test_name,
                  namespace='/main',
                  broadcast=True)
    run_test_thread(test_name,
                    thread_type,
                    sessionFilepath=backupPath,
                    participant=participant,
                    **msg)
Esempio n. 2
0
def on_clientmessage(data):
    """ websocket: relay node for clients to send notifications to others """
    room = data['room']
    message = data['message']

    # Just forward all the received message to the specified room
    socketio.emit(message, data, room=room)
Esempio n. 3
0
def checkMatProcessingStatus():
    global thread
    if thread.is_alive():
        socketio.emit('mat-processing-status', {'data': True},
                      namespace='/main')
    else:
        socketio.emit('mat-processing-status', {'data': False},
                      namespace='/main')
Esempio n. 4
0
def openMatDialog():
    # Open a file dialog interface for selecting a directory
    dirs = webview.create_file_dialog(webview.FOLDER_DIALOG)
    if dirs and len(dirs) > 0:
        directory = dirs[0]
        if isinstance(directory, bytes):
            directory = directory.decode("utf-8")
        # TODO: Add filepath checking here...
        # Send message with selected directory to the GUI
        socketio.emit('mat-dialog-resp', {'data': directory},
                      namespace='/main')
Esempio n. 5
0
def openSaveDirDialog():
    # Open a file dialog interface for selecting a directory
    dirs = webview.create_file_dialog(webview.FOLDER_DIALOG)
    if dirs and len(dirs) > 0:
        directory = dirs[0]
        if isinstance(directory, bytes):
            directory = directory.decode("utf-8")
        if not os.path.isdir(directory):
            socketio.emit(
                'main-notification',
                {'data': "\'{}\' is not a valid directory".format(directory)},
                namespace='/main')
            return None
        # Send message with selected directory to the GUI
        socketio.emit('save-file-dialog-resp', {'data': directory},
                      namespace='/main')
Esempio n. 6
0
def start_test(msg):
    test_name = msg.pop('test_name')
    part_key = msg.pop('part_key')
    thread_type = thread_types[test_name]

    if part_key != "--":
        participant = participants[part_key]
    else:
        raise ValueError("Participant must be selected...")

    socketio.emit('participant_start_{}'.format(test_name), namespace='/main')
    socketio.emit('participant_start',
                  test_name,
                  namespace='/main',
                  broadcast=True)
    run_test_thread(test_name, thread_type, participant=participant, **msg)
    def post(self):
        try:
            categorie = request.form.to_dict()
            if 'file' not in request.files:
                imagepath = ''
            elif 'file' in request.files:
                file = request.files['file']
                if file.filename == '':
                    imagepath = ''
                if file:

                    def image():
                        filename = secure_filename(file.filename)
                        file.save(
                            os.path.join(app.config['UPLOAD_FOLDER'],
                                         filename))
                        return url_for("static", filename=filename)

                    imagepath = image()
            name = categorie['categoryEn']
            abc = {key: value for key, value in categorie.items()}
            if imagepath != '':
                abc['imagePath'] = imagepath
            existing_categorie = (Categories.query.filter(
                Categories.categoryEn == name).one_or_none())
            if existing_categorie is None:
                schema = CategoriesSchema()
                new_categorie = schema.load(abc, session=db.session).data
                db.session.add(new_categorie)
                db.session.commit()
                data = schema.dump(new_categorie).data
                logger.info("Data posted successfully to the category")
                loggers.info("Data posted successfully to the category")
                socketio.emit('somecategorie', {'data': data})
                return ({"success": True, "data": data})
            else:
                logger.warning("Category exists already")
                loggers.warning("Category exists already")
                return ({
                    "success": False,
                    "message": "Category exists already"
                })
        except Exception as e:
            logger.warning(str(e))
            return ({"success": False, "message": str(e)})
Esempio n. 8
0
def openSaveFileDialog():
    # Open a file dialog interface for selecting a directory
    filepath = webview.create_file_dialog(
        dialog_type=webview.SAVE_DIALOG,
        file_types=("Python Pickle (*.pkl)", ),
        save_filename="test_session.pkl")
    if filepath and len(filepath) > 0:
        filepath = filepath[0]
        if isinstance(filepath, bytes):
            filepath = filepath.decode("utf-8")
        # Make sure file ends with pickle file extension
        head, tail = os.path.splitext(filepath)
        filepath = head + ".pkl"
        # Send message with selected directory to the GUI
        socketio.emit('save_file_dialog_resp', {'data': filepath},
                      namespace='/main',
                      broadcast=True,
                      include_self=True)
Esempio n. 9
0
def openLoadFileDialog():
    # Open a file dialog interface for selecting a directory
    filepath = webview.create_file_dialog(
        dialog_type=webview.OPEN_DIALOG,
        file_types=("Python Pickle (*.pkl)", ))
    if filepath and len(filepath) > 0:
        filepath = filepath[0]
        if isinstance(filepath, bytes):
            filepath = filepath.decode("utf-8")
        if not os.path.isfile(filepath):
            socketio.emit(
                'main-notification',
                {'data': "\'{}\' is not a valid file".format(directory)},
                namespace='/main')
        # Send message with selected directory to the GUI
        socketio.emit('load_file_dialog_resp', {'data': filepath},
                      namespace='/main',
                      broadcast=True,
                      include_self=True)
Esempio n. 10
0
def start_saved_mat_test(msg):
    '''
    Relay test start message to participant view
    '''
    filepath = webview.create_file_dialog(
        dialog_type=webview.OPEN_DIALOG,
        file_types=("Python Pickle (*.pkl)", ))
    if filepath and len(filepath) > 0:
        filepath = filepath[0]
        if isinstance(filepath, bytes):
            filepath = filepath.decode("utf-8")
    else:
        return None

    part_key = msg['part_key']
    if part_key != "--":
        participant = participants[part_key]
    else:
        participant = None
    socketio.emit('participant_start_mat', {'data': ''},
                  namespace='/main',
                  broadcast=True)
    run_matrix_thread(sessionFilepath=filepath, participant=participant)
Esempio n. 11
0
    def get(self):
        try:

            categories = db.session.query(Categories).order_by(
                desc(Categories.createdAt)).all()
            if categories:
                schema = CategoriesGetSchemas(many=True)
                data = schema.dump(categories).data
                logger.info("Data feteched successfully of the category")
                loggers.info("Data feteched successfully of the category")
                socketio.emit('someevent', {'data': data})
                return ({"success": True, "data": data})
            else:
                logger.warning("No data is available for category")
                loggers.warning("No data is available for category")
                socketio.emit('someevent', {'data': "data"})
                return ({
                    "success": False,
                    "message": "No data is available for category"
                })
        except Exception as e:
            logger.warning(str(e))
            loggers.warning(str(e))
            return ({"success": False, "message": str(e)})
Esempio n. 12
0
def notifyPlayers(room, game):
    print("Notifying Players in room {}".format(room))

    # old way, just a poke to inform players to issue a new GET
    socketio.emit('update', {'message': 'update avail'}, room=room)
    # new way, send along the public information while we're a it
    socketio.emit('publicinfo', game.getPublicInformation(), room=room)
    # send each player their own specific data (they'll join a room for this)
    #       would need their websocket sid bound to their playerid somehow...
    #       The ugly part is anyone who knows a players id, can listen... but meh
    np, players = game.players
    for p in players:
        if p == game.currplayer or game._done == True:
            # NOTE: copying logic from the REST interface as they should match (fix this)
            ret = {'game': game.getPublicInformation()}
            ret['game']['you'] = p.serialize(True)
            socketio.emit('yourturn', ret, room="{}.{}".format(room, p.id))
        # TODO: Only do this if the playerinfo has changed
        socketio.emit('privateinfo',
                      p.savePlayerData(),
                      room="{}.{}".format(room, p.id))
Esempio n. 13
0
def ahhh(room, message):
    socketio.emit('update', {'message': message}, room=room)
    return jsonify({'message': message})
Esempio n. 14
0
def get_participant_info(key):
    socketio.emit('part_info', participants[key]['info'], namespace='/main')
Esempio n. 15
0
def notifyPlayers(room):
    print("Notifying Players in room {}".format(room))
    socketio.emit('update', {'message': 'update avail'}, room=room)
Esempio n. 16
0
 def run(self):
     '''
     This function is called when the thread starts
     '''
     self.process_stimulus()
     socketio.emit('processing-complete', {'data': ''}, namespace='/main')