예제 #1
0
def import_file(req, test_data=None, **kwargs):
    # input_data is passed by test cases only
    input_data = test_data
    text = pkcompat.from_bytes(req.file_stream.read())
    if 'simulationId' in req.req_data:
        input_data = simulation_db.read_simulation_json(
            SIM_TYPE, sid=req.req_data.simulationId)
    if re.search(r'\.ele$', req.filename, re.IGNORECASE):
        data = elegant_command_importer.import_file(text)
    elif re.search(r'\.lte$', req.filename, re.IGNORECASE):
        data = elegant_lattice_importer.import_file(text, input_data)
        if input_data:
            _map_commands_to_lattice(data)
    elif re.search(r'\.madx$', req.filename, re.IGNORECASE):
        from sirepo.template import madx_converter, madx_parser
        data = madx_converter.from_madx(
            SIM_TYPE, madx_parser.parse_file(text, downcase_variables=True))
    else:
        raise IOError('invalid file extension, expecting .ele or .lte')
    data.models.simulation.name = re.sub(r'\.(lte|ele|madx)$',
                                         '',
                                         req.filename,
                                         flags=re.IGNORECASE)
    if input_data and not test_data:
        simulation_db.delete_simulation(
            SIM_TYPE, input_data.models.simulation.simulationId)
    return data
예제 #2
0
파일: elegant.py 프로젝트: njsmith/sirepo
def import_file(request, lib_dir=None, tmp_dir=None, test_data=None):
    # input_data is passed by test cases only
    f = request.files['file']
    filename = werkzeug.secure_filename(f.filename)
    input_data = test_data

    if 'simulationId' in request.form:
        input_data = simulation_db.read_simulation_json(
            elegant_common.SIM_TYPE, sid=request.form['simulationId'])
    if re.search(r'.ele$', filename, re.IGNORECASE):
        data = elegant_command_importer.import_file(f.read())
    elif re.search(r'.lte$', filename, re.IGNORECASE):
        data = elegant_lattice_importer.import_file(f.read(), input_data)
        if input_data:
            _map_commands_to_lattice(data)
    else:
        raise IOError('invalid file extension, expecting .ele or .lte')
    data['models']['simulation']['name'] = re.sub(r'\.(lte|ele)$',
                                                  '',
                                                  filename,
                                                  flags=re.IGNORECASE)
    if input_data and not test_data:
        simulation_db.delete_simulation(
            elegant_common.SIM_TYPE,
            input_data['models']['simulation']['simulationId'])
    return data
예제 #3
0
def import_file(req, test_data=None, **kwargs):
    # input_data is passed by test cases only
    d = test_data
    if 'id' in req:
        d = simulation_db.read_simulation_json(SIM_TYPE, sid=req.id)
    p = pkio.py_path(req.filename)
    res = parse_input_text(
        p,
        pkcompat.from_bytes(req.file_stream.read()),
        d,
    )
    res.models.simulation.name = p.purebasename
    if d and not test_data:
        simulation_db.delete_simulation(
            SIM_TYPE,
            d.models.simulation.simulationId,
        )
    return res
예제 #4
0
파일: elegant.py 프로젝트: e-carlin/sirepo
def import_file(request, lib_dir=None, tmp_dir=None, test_data=None):
    # input_data is passed by test cases only
    f = request.files['file']
    filename = werkzeug.secure_filename(f.filename)
    input_data = test_data

    if 'simulationId' in request.form:
        input_data = simulation_db.read_simulation_json(elegant_common.SIM_TYPE, sid=request.form['simulationId'])
    if re.search(r'.ele$', filename, re.IGNORECASE):
        data = elegant_command_importer.import_file(f.read())
    elif re.search(r'.lte$', filename, re.IGNORECASE):
        data = elegant_lattice_importer.import_file(f.read(), input_data)
        if input_data:
            _map_commands_to_lattice(data)
    else:
        raise IOError('invalid file extension, expecting .ele or .lte')
    data['models']['simulation']['name'] = re.sub(r'\.(lte|ele)$', '', filename, flags=re.IGNORECASE)
    if input_data and not test_data:
        simulation_db.delete_simulation(elegant_common.SIM_TYPE, input_data['models']['simulation']['simulationId'])
    return data
예제 #5
0
파일: elegant.py 프로젝트: mrakitin/sirepo
def import_file(request, lib_dir=None, tmp_dir=None, test_data=None):
    # input_data is passed by test cases only
    f = request.files["file"]
    filename = werkzeug.secure_filename(f.filename)
    input_data = test_data

    if "simulationId" in request.form:
        input_data = simulation_db.read_simulation_json(_SIMULATION_TYPE, sid=request.form["simulationId"])
    try:
        if re.search(r".ele$", filename, re.IGNORECASE):
            data = elegant_command_importer.import_file(f.read())
        elif re.search(r".lte$", filename, re.IGNORECASE):
            data = elegant_lattice_importer.import_file(f.read(), input_data)
            if input_data:
                _map_commands_to_lattice(data)
        else:
            raise IOError("invalid file extension, expecting .ele or .lte")
        data["models"]["simulation"]["name"] = re.sub(r"\.(lte|ele)$", "", filename, re.IGNORECASE)
        if input_data and not test_data:
            simulation_db.delete_simulation(_SIMULATION_TYPE, input_data["models"]["simulation"]["simulationId"])
        return None, data
    except IOError as e:
        return e.message, None
예제 #6
0
def import_file(req, test_data=None, **kwargs):
    # input_data is passed by test cases only
    input_data = test_data

    if 'simulationId' in req:
        input_data = simulation_db.read_simulation_json(
            elegant_common.SIM_TYPE, sid=req.simulationId)
    if re.search(r'.ele$', req.filename, re.IGNORECASE):
        data = elegant_command_importer.import_file(req.file_stream.read())
    elif re.search(r'.lte$', req.filename, re.IGNORECASE):
        data = elegant_lattice_importer.import_file(req.file_stream.read(),
                                                    input_data)
        if input_data:
            _map_commands_to_lattice(data)
    else:
        raise IOError('invalid file extension, expecting .ele or .lte')
    data.models.simulation.name = re.sub(r'\.(lte|ele)$',
                                         '',
                                         req.filename,
                                         flags=re.IGNORECASE)
    if input_data and not test_data:
        simulation_db.delete_simulation(
            elegant_common.SIM_TYPE, input_data.models.simulation.simulationId)
    return data
예제 #7
0
파일: server.py 프로젝트: mrakitin/sirepo
def app_delete_simulation():
    data = _parse_data_input()
    simulation_db.delete_simulation(data['simulationType'], data['simulationId'])
    return _json_response_ok();
예제 #8
0
파일: server.py 프로젝트: yeeon/sirepo
def api_deleteSimulation():
    data = _parse_data_input()
    simulation_db.delete_simulation(data['simulationType'],
                                    data['simulationId'])
    return http_reply.gen_json_ok()
예제 #9
0
파일: server.py 프로젝트: pir8aye/sirepo
def api_deleteSimulation():
    data = _parse_data_input()
    simulation_db.delete_simulation(data['simulationType'],
                                    data['simulationId'])
    return _json_response_ok()
예제 #10
0
def api_deleteSimulation():
    req = http_request.parse_post(id=True)
    simulation_db.delete_simulation(req.type, req.id)
    return http_reply.gen_json_ok()