Esempio n. 1
0
def api_exportRSOptConfig(simulation_type, simulation_id, filename):
    t = sirepo.template.import_module(simulation_type)
    assert hasattr(t, 'export_rsopt_config'), 'Export rsopt unavailable'
    d = simulation_db.read_simulation_json(simulation_type, sid=simulation_id)
    return http_reply.gen_file_as_attachment(t.export_rsopt_config(
        d, filename),
                                             filename,
                                             content_type='application/zip')
Esempio n. 2
0
def api_exportJupyterNotebook(simulation_type,
                              simulation_id,
                              model=None,
                              title=None):
    t = sirepo.template.import_module(simulation_type)
    assert hasattr(t, 'export_jupyter_notebook'), 'Jupyter export unavailable'
    d = simulation_db.read_simulation_json(simulation_type, sid=simulation_id)
    return http_reply.gen_file_as_attachment(
        t.export_jupyter_notebook(d),
        f"{d.models.simulation.name}{'-' + srschema.parse_name(title) if title else ''}.ipynb",
        content_type='application/json')
Esempio n. 3
0
def api_downloadFile(simulation_type, simulation_id, filename):
    #TODO(pjm): simulation_id is an unused argument
    req = http_request.parse_params(type=simulation_type, filename=filename)
    n = req.sim_data.lib_file_name_without_type(req.filename)
    p = req.sim_data.lib_file_abspath(req.filename)
    try:
        return http_reply.gen_file_as_attachment(p, filename=n)
    except Exception as e:
        if pkio.exception_is_not_found(e):
            sirepo.util.raise_not_found('lib_file={} not found', p)
        raise
Esempio n. 4
0
def api_pythonSource(simulation_type, simulation_id, model=None, title=None):
    req = http_request.parse_params(type=simulation_type,
                                    id=simulation_id,
                                    template=True)
    m = model and req.sim_data.parse_model(model)
    d = simulation_db.read_simulation_json(req.type, sid=req.id)
    return http_reply.gen_file_as_attachment(
        req.template.python_source_for_model(d, m),
        '{}.{}'.format(
            d.models.simulation.name + ('-' + title if title else ''),
            'madx' if m == 'madx' else 'py',
        ),
    )
Esempio n. 5
0
def api_getApplicationData(filename=None):
    """Get some data from the template

    Args:
        filename (str): if supplied, result is file attachment

    Returns:
        response: may be a file or JSON
    """
    req = http_request.parse_post(template=True, filename=filename or None)
    with simulation_db.tmp_dir() as d:
        res = req.template.get_application_data(req.req_data, tmp_dir=d)
        if 'filename' in req:
            assert isinstance(res, pkconst.PY_PATH_LOCAL_TYPE), \
                '{}: template did not return a file'.format(res)
            return http_reply.gen_file_as_attachment(res,
                                                     filename=req.filename)
        return http_reply.gen_json(res)
Esempio n. 6
0
def api_downloadDataFile(simulation_type,
                         simulation_id,
                         model,
                         frame,
                         suffix=None):
    #TODO(robnagler) validate suffix and frame
    req = http_request.parse_params(
        id=simulation_id,
        model=model,
        type=simulation_type,
        check_sim_exists=True,
    )
    f, c, t = sirepo.template.import_module(req.type).get_data_file(
        simulation_db.simulation_run_dir(req.req_data),
        req.model,
        int(frame),
        options=req.req_data.copy().update(suffix=suffix),
    )
    return http_reply.gen_file_as_attachment(c, f, t)
Esempio n. 7
0
def api_getApplicationData(filename=None):
    """Get some data from the template

    Args:
        filename (str): if supplied, result is file attachment

    Returns:
        response: may be a file or JSON
    """
    req = http_request.parse_post(template=True, filename=filename or None)
    with simulation_db.tmp_dir() as d:
        assert 'method' in req.req_data
        res = req.template.get_application_data(req.req_data, tmp_dir=d)
        assert res != None, f'unhandled application data method: {req.req_data.method}'
        if 'filename' in req and isinstance(res, pkconst.PY_PATH_LOCAL_TYPE):
            return http_reply.gen_file_as_attachment(
                res,
                filename=req.filename,
                content_type=req.req_data.get('contentType', None))
        return http_reply.gen_json(res)