Exemple #1
0
def api_copyNonSessionSimulation():
    req = http_request.parse_json()
    sim_type = req['simulationType']
    src = py.path.local(
        simulation_db.find_global_simulation(
            sim_type,
            req['simulationId'],
            checked=True,
        ))
    data = simulation_db.open_json_file(
        sim_type,
        src.join(simulation_db.SIMULATION_DATA_FILE),
    )
    if 'report' in data:
        del data['report']
    data['models']['simulation']['isExample'] = False
    data['models']['simulation']['outOfSessionSimulationId'] = req[
        'simulationId']
    res = _save_new_and_reply(data)
    target = simulation_db.simulation_dir(sim_type,
                                          simulation_db.parse_sid(data))
    template_common.copy_lib_files(
        data,
        simulation_db.lib_dir_from_sim_dir(src),
        simulation_db.lib_dir_from_sim_dir(target),
    )
    template = sirepo.template.import_module(data)
    if hasattr(template, 'copy_related_files'):
        template.copy_related_files(data, str(src), str(target))
    return res
Exemple #2
0
def api_copyNonSessionSimulation():
    req = _json_input()
    sim_type = req['simulationType']
    global_path = simulation_db.find_global_simulation(sim_type,
                                                       req['simulationId'])
    if global_path:
        data = simulation_db.open_json_file(
            sim_type,
            os.path.join(global_path, simulation_db.SIMULATION_DATA_FILE),
        )
        data['models']['simulation']['isExample'] = False
        data['models']['simulation']['outOfSessionSimulationId'] = req[
            'simulationId']
        res = _save_new_and_reply(data)
        target = simulation_db.simulation_dir(sim_type,
                                              simulation_db.parse_sid(data))
        template_common.copy_lib_files(
            data,
            py.path.local(os.path.dirname(global_path)).join('lib'),
            target.join('../lib'),
        )
        template = sirepo.template.import_module(data)
        if hasattr(template, 'copy_related_files'):
            template.copy_related_files(data, global_path, str(target))
        return res
    werkzeug.exceptions.abort(404)
Exemple #3
0
def api_copyNonSessionSimulation():
    req = http_request.parse_post(id=True, template=True)
    simulation_db.verify_app_directory(req.type)
    src = pkio.py_path(
        simulation_db.find_global_simulation(
            req.type,
            req.id,
            checked=True,
        ), )
    data = simulation_db.open_json_file(
        req.type,
        src.join(simulation_db.SIMULATION_DATA_FILE),
    )
    data.pkdel('report')
    data.models.simulation.isExample = False
    data.models.simulation.outOfSessionSimulationId = req.id
    res = _save_new_and_reply(data)
    sirepo.sim_data.get_class(req.type).lib_files_from_other_user(
        data,
        simulation_db.lib_dir_from_sim_dir(src),
    )
    target = simulation_db.simulation_dir(req.type,
                                          data.models.simulation.simulationId)
    #TODO(robnagler) does not work, supervisor needs to be notified to
    # copy the simulation state.
    # if hasattr(req.template, 'copy_related_files'):
    #     req.template.copy_related_files(data, str(src), str(target))
    return res
Exemple #4
0
def app_copy_nonsession_simulation():
    req = _json_input()
    sim_type = req['simulationType']
    global_path = simulation_db.find_global_simulation(sim_type, req['simulationId'])
    if global_path:
        data = simulation_db.open_json_file(sim_type, os.path.join(global_path, simulation_db.SIMULATION_DATA_FILE))
        data['models']['simulation']['isExample'] = False
        data['models']['simulation']['outOfSessionSimulationId'] = req['simulationId']
        res = _save_new_and_reply(sim_type, data)
        sirepo.template.import_module(data).copy_related_files(data, global_path, str(simulation_db.simulation_dir(sim_type, simulation_db.parse_sid(data))))
        return res
    werkzeug.exceptions.abort(404)
Exemple #5
0
def app_copy_nonsession_simulation():
    req = _json_input()
    sim_type = req['simulationType']
    global_path = simulation_db.find_global_simulation(sim_type, req['simulationId'])
    if global_path:
        data = simulation_db.open_json_file(sim_type, os.path.join(global_path, simulation_db.SIMULATION_DATA_FILE))
        data['models']['simulation']['isExample'] = False
        data['models']['simulation']['outOfSessionSimulationId'] = req['simulationId']
        res = _save_new_and_reply(sim_type, data)
        sirepo.template.import_module(data).copy_related_files(data, global_path, str(simulation_db.simulation_dir(sim_type, simulation_db.parse_sid(data))))
        return res
    werkzeug.exceptions.abort(404)
Exemple #6
0
def api_blueskyAuth():
    req = http_request.parse_json()
    auth_hash(req, verify=True)
    sid = req.simulationId
    sim_type = req.simulationType
    path = simulation_db.find_global_simulation(
        sim_type,
        sid,
        checked=True,
    )
    cookie.set_user(simulation_db.uid_from_dir_name(path))
    return http_reply.gen_json_ok(dict(
        data=simulation_db.open_json_file(req.simulationType, sid=req.simulationId),
        schema=simulation_db.get_schema(req.simulationType),
    ))
Exemple #7
0
def auth_login(req):
    from sirepo import server

    if cfg.auth_secret:
        auth_hash(req, verify=True)
    # DEPRECATED
    elif not server.cfg.enable_bluesky:
        util.raise_not_found('bluesky is not enabled')
    sid = req.simulationId
    sim_type = req.simulationType
    path = simulation_db.find_global_simulation(
        sim_type,
        sid,
        checked=True,
    )
    server.session_user(simulation_db.uid_from_dir_name(path))
Exemple #8
0
def api_blueskyAuth():
    req = http_request.parse_json()
    auth_hash(req, verify=True)
    sid = req.simulationId
    sim_type = req.simulationType
    path = simulation_db.find_global_simulation(
        sim_type,
        sid,
        checked=True,
    )
    cookie.set_user(simulation_db.uid_from_dir_name(path))
    return http_reply.gen_json_ok(
        dict(
            data=simulation_db.open_json_file(req.simulationType,
                                              sid=req.simulationId),
            schema=simulation_db.get_schema(req.simulationType),
        ))
Exemple #9
0
def api_authBlueskyLogin():
    req = sirepo.http_request.parse_post(id=True)
    auth_hash(req.req_data, verify=True)
    path = simulation_db.find_global_simulation(
        req.type,
        req.id,
        checked=True,
    )
    sirepo.auth.login(
        this_module,
        uid=simulation_db.uid_from_dir_name(path),
        # do not supply sim_type (see auth.login)
    )
    return sirepo.http_reply.gen_json_ok(
        PKDict(
            data=simulation_db.open_json_file(req.type, sid=req.id),
            schema=simulation_db.get_schema(req.type),
        ), )
Exemple #10
0
def api_authBlueskyLogin():
    req = http_request.parse_json()
    auth_hash(req, verify=True)
    sid = req.simulationId
    sim_type = req.simulationType
    path = simulation_db.find_global_simulation(
        sim_type,
        sid,
        checked=True,
    )
    r = auth.login(
        this_module,
        uid=simulation_db.uid_from_dir_name(path),
    )
    if r:
        return r
    return http_reply.gen_json_ok(dict(
        data=simulation_db.open_json_file(req.simulationType, sid=req.simulationId),
        schema=simulation_db.get_schema(req.simulationType),
    ))
Exemple #11
0
def api_blueskyAuth():
    if not cfg.enable_bluesky:
        return _json_response({
            'status': 'error',
            'error': 'bluesky auth is not enabled',
        })
    req = _json_input()
    sim_id = req.simulationId
    sim_type = req.simulationType
    global_path = simulation_db.find_global_simulation(sim_type, sim_id)
    if global_path:
        m = re.search('/user/(.+)/{}/{}$'.format(sim_type, sim_id),
                      global_path)
        assert m, 'global_path user parse failed: {}'.format(global_path)
        session_user(m.group(1))
        return _json_response({
            'status':
            'OK',
            'data':
            simulation_db.open_json_file(sim_type, sid=sim_id),
        })
    werkzeug.exceptions.abort(404)