Exemple #1
0
def _do_download_data_file(msg, template):
    try:
        r = template.get_data_file(
            msg.runDir,
            msg.analysisModel,
            msg.frame,
            options=PKDict(suffix=msg.suffix),
        )
        if not isinstance(r, PKDict):
            if isinstance(r, str):
                r = msg.runDir.join(r, abs=1)
            r = PKDict(filename=r)
        u = r.get('uri')
        if u is None:
            u = r.filename.basename
        c = r.get('content')
        if c is None:
            c = pkcompat.to_bytes(pkio.read_text(r.filename)) \
                if u.endswith(('py', 'txt', 'csv')) \
                else r.filename.read_binary()
        requests.put(
            msg.dataFileUri + u,
            data=c,
            verify=job.cfg.verify_tls,
        ).raise_for_status()
        return PKDict()
    except Exception as e:
        return PKDict(state=job.ERROR, error=e, stack=pkdexc())
Exemple #2
0
def app_download_data_file(simulation_type, simulation_id, model, frame):
    data = {
        'simulationType': simulation_type,
        'simulationId': simulation_id,
        'modelName': model,
    }
    frame = int(frame)
    template = sirepo.template.import_module(data)
    if frame >= 0:
        data['report'] = template.get_animation_name(data)
    else:
        data['report'] = model
    run_dir = simulation_db.simulation_run_dir(data)
    filename, content, content_type = template.get_data_file(run_dir, model, frame)
    return _as_attachment(flask.make_response(content), content_type, filename)
Exemple #3
0
def app_download_data_file(simulation_type, simulation_id, model, frame):
    data = {
        'simulationType': simulation_type,
        'simulationId': simulation_id,
        'modelName': model,
    }
    frame = int(frame)
    template = sirepo.template.import_module(data)
    if frame >= 0:
        data['report'] = template.get_animation_name(data)
    else:
        data['report'] = model
    run_dir = simulation_db.simulation_run_dir(data)
    filename, content, content_type = template.get_data_file(run_dir, model, frame)
    return _as_attachment(flask.make_response(content), content_type, filename)
Exemple #4
0
def _do_get_data_file(msg, template):
    try:
        f, c, _ = template.get_data_file(
            msg.runDir,
            msg.analysisModel,
            msg.frame,
            options=PKDict(suffix=msg.suffix),
        )
        requests.put(
            msg.dataFileUri + f,
            data=c,
            verify=job.cfg.verify_tls,
        ).raise_for_status()
        return PKDict()
    except Exception as e:
        return PKDict(error=e, stack=pkdexc())
Exemple #5
0
def api_downloadDataFile(simulation_type, simulation_id, model, frame, suffix=None):
    data = {
        'simulationType': sirepo.template.assert_sim_type(simulation_type),
        'simulationId': simulation_id,
        'modelName': model,
    }
    options = pkcollections.Dict(data)
    options.suffix = suffix
    frame = int(frame)
    template = sirepo.template.import_module(data)
    if frame >= 0:
        data['report'] = template.get_animation_name(data)
    else:
        data['report'] = model
    run_dir = simulation_db.simulation_run_dir(data)
    filename, content, content_type = template.get_data_file(run_dir, model, frame, options=options)
    return _as_attachment(flask.make_response(content), content_type, filename)
Exemple #6
0
def app_download_data_file(simulation_type, simulation_id, model_or_frame):
    data = {
        'simulationType': simulation_type,
        'simulationId': simulation_id,
    }
    frame_index = -1
    if re.match(r'^\d+$', model_or_frame):
        frame_index = int(model_or_frame)
    else:
        data['report'] = model_or_frame
    run_dir = simulation_db.simulation_run_dir(data)
    template = sirepo.template.import_module(simulation_type)
    filename, content, content_type = template.get_data_file(run_dir, frame_index)
    response = flask.make_response(content)
    response.mimetype = content_type
    response.headers['Content-Disposition'] = 'attachment; filename="{}"'.format(filename)
    return response
Exemple #7
0
def app_download_data_file(simulation_type, simulation_id, model_or_frame):
    data = {
        'simulationType': simulation_type,
        'simulationId': simulation_id,
    }
    frame_index = -1
    if re.match(r'^\d+$', model_or_frame):
        frame_index = int(model_or_frame)
    else:
        data['report'] = model_or_frame
    run_dir = simulation_db.simulation_run_dir(data)
    template = sirepo.template.import_module(simulation_type)
    filename, content, content_type = template.get_data_file(
        run_dir, frame_index)
    response = flask.make_response(content)
    response.mimetype = content_type
    response.headers[
        'Content-Disposition'] = 'attachment; filename="{}"'.format(filename)
    return response