コード例 #1
0
ファイル: upload.py プロジェクト: coycooper/Projects_Coy
def _check_arguments():
    """
    _check_arguments()
    Retrieves the arguments which describe the file being sent.
    These areguments are the file_sent, the file-info, the sessionid, and optionally

    @return file_info, file_sent, reservation_id, is_async
    """
    file_info = get_argument(FILE_INFO)
    if file_info is None:
        raise FileUploadError(WEBLAB_GENERAL_EXCEPTION_CODE,
                              "%s argument not provided!" % FILE_INFO)
    file_sent = request.files.get(FILE_SENT)
    if file_sent is None:
        file_sent = get_argument(FILE_SENT)
        if file_sent is None:
            raise FileUploadError(WEBLAB_GENERAL_EXCEPTION_CODE,
                                  "%s argument not provided!" % FILE_SENT)
    else:
        sio = StringIO.StringIO()
        file_sent.save(sio)
        file_sent = sio.getvalue()

    reservation_id = get_argument(RESERVATION_ID)
    if reservation_id is None:
        reservation_id = get_argument(SESSION_ID)
        if reservation_id is None:
            raise FileUploadError(
                WEBLAB_GENERAL_EXCEPTION_CODE,
                "%s argument not provided!" % ' or '.join(
                    (SESSION_ID, RESERVATION_ID)))

    # Read the IS_ASYNC parameter, which will indicate us whether we should execute the send_file asynchronously
    # or synchronously.
    is_async_str = get_argument(IS_ASYNC)
    if is_async_str is None:
        is_async = False
    else:
        is_async_str = is_async_str.lower()
        if is_async_str in ("true", "yes", "1"):
            is_async = True
        elif is_async_str in ("false", "no", "0"):
            is_async = False
        else:
            raise FileUploadError(
                WEBLAB_GENERAL_EXCEPTION_CODE,
                "%s argument is present but not valid (should be a boolean)!" %
                IS_ASYNC)
    return file_info, file_sent, reservation_id, is_async
コード例 #2
0
ファイル: visir.py プロジェクト: coycooper/Projects_Coy
def intercept_save():
    save = get_argument("save", "")
    response = make_response(save)
    response.content_type = 'application/download'
    response.headers[
        'Content-Disposition'] = 'attachment; filename=circuit.cir'
    return response
コード例 #3
0
def direct2experiment():
    experiment_id_str = get_argument(EXPERIMENT_ID)
    if experiment_id_str is None:
        return "%s argument is missing" % EXPERIMENT_ID
    session_id_str = get_argument(SESSION_ID)
    if session_id_str is None:
        return "%s argument is missing" % EXPERIMENT_ID

    experiment_id = ExperimentId.parse(experiment_id_str)
    weblab_api.context.session_id = session_id_str

    try:
        reservation_id = weblab_api.api.reserve_experiment(experiment_id, "{}", "{}")
    except Exception:
        traceback.print_exc()
        return HTML_ERROR_TEMPLATE

    new_location = "../../client/federated.html#reservation_id=%s" % reservation_id.reservation_id.id
    return redirect(new_location)
コード例 #4
0
def direct2experiment():
    experiment_id_str = get_argument(EXPERIMENT_ID)
    if experiment_id_str is None:
        return "%s argument is missing" % EXPERIMENT_ID
    session_id_str = get_argument(SESSION_ID)
    if session_id_str is None:
        return "%s argument is missing" % EXPERIMENT_ID

    experiment_id = ExperimentId.parse(experiment_id_str)
    weblab_api.context.session_id = session_id_str

    try:
        reservation_id = weblab_api.api.reserve_experiment(
            experiment_id, "{}", "{}")
    except Exception:
        traceback.print_exc()
        return HTML_ERROR_TEMPLATE

    new_location = "../../client/federated.html#reservation_id=%s" % reservation_id.reservation_id.id
    return redirect(new_location)
コード例 #5
0
ファイル: upload.py プロジェクト: Kiolali/weblabdeusto
def _check_arguments():
    """
    _check_arguments()
    Retrieves the arguments which describe the file being sent.
    These areguments are the file_sent, the file-info, the sessionid, and optionally

    @return file_info, file_sent, reservation_id, is_async
    """
    file_info = get_argument(FILE_INFO)
    if file_info is None:
        raise FileUploadError(WEBLAB_GENERAL_EXCEPTION_CODE, "%s argument not provided!" % FILE_INFO)
    file_sent = request.files.get(FILE_SENT)
    if file_sent is None:
        file_sent = get_argument(FILE_SENT)
        if file_sent is None:
            raise FileUploadError(WEBLAB_GENERAL_EXCEPTION_CODE, "%s argument not provided!" % FILE_SENT)
    else:
        sio = StringIO.StringIO()
        file_sent.save(sio)
        file_sent = sio.getvalue()

    reservation_id = get_argument(RESERVATION_ID)
    if reservation_id is None:
        reservation_id = get_argument(SESSION_ID)
        if reservation_id is None:
            raise FileUploadError(WEBLAB_GENERAL_EXCEPTION_CODE, "%s argument not provided!" % ' or '.join((SESSION_ID, RESERVATION_ID)))

    # Read the IS_ASYNC parameter, which will indicate us whether we should execute the send_file asynchronously
    # or synchronously.
    is_async_str = get_argument(IS_ASYNC)
    if is_async_str is None:
        is_async = False
    else:
        is_async_str = is_async_str.lower()
        if is_async_str in ("true", "yes", "1"):
            is_async = True
        elif is_async_str in ("false", "no", "0"):
            is_async = False
        else:
            raise FileUploadError(WEBLAB_GENERAL_EXCEPTION_CODE, "%s argument is present but not valid (should be a boolean)!" % IS_ASYNC)
    return file_info, file_sent, reservation_id, is_async
コード例 #6
0
ファイル: labview.py プロジェクト: zstars/weblabdeusto
def labview():
    try:
        reservation_id = get_argument(SESSION_ID)
        if reservation_id is None:
            return HTML_TEMPLATE % {
                        'MESSAGE' : "Failed to load LabVIEW experiment. Reason: %s argument not provided!." % SESSION_ID
                    }

        weblab_api.ctx.reservation_id = reservation_id
        result = weblab_api.api.send_command(Command.Command("get_html"))
    except Exception as e:
        message = e.args[0]
        return HTML_TEMPLATE % {
                    'MESSAGE' : "Failed to load LabVIEW experiment. Reason: %s. Call the administrator to fix it." % message
                }
    else:
        resultstr = result.commandstring
        print "[DBG] Returning result from labview: " + resultstr
        return HTML_TEMPLATE % {
                    'MESSAGE' : resultstr
                }
コード例 #7
0
ファイル: labview.py プロジェクト: coycooper/Projects_Coy
def labview():
    try:
        reservation_id = get_argument(SESSION_ID)
        if reservation_id is None:
            return HTML_TEMPLATE % {
                        'MESSAGE' : "Failed to load LabVIEW experiment. Reason: %s argument not provided!." % SESSION_ID
                    }

        weblab_api.ctx.reservation_id = reservation_id
        result = weblab_api.api.send_command(Command.Command("get_html"))
    except Exception as e:
        message = e.args[0]
        return HTML_TEMPLATE % {
                    'MESSAGE' : "Failed to load LabVIEW experiment. Reason: %s. Call the administrator to fix it." % message
                }
    else:
        resultstr = result.commandstring
        print("[DBG] Returning result from labview: " + resultstr)
        return HTML_TEMPLATE % {
                    'MESSAGE' : resultstr
                }
コード例 #8
0
ファイル: visir.py プロジェクト: Kiolali/weblabdeusto
def intercept_save():
    save = get_argument("save", "")
    response = make_response(save)
    response.content_type = 'application/download'
    response.headers['Content-Disposition'] = 'attachment; filename=circuit.cir'
    return response