Example #1
0
def safety_shutter_state_changed(values):
    ho = BeamlineSetupMediator(mxcube.beamline).getObjectByRole("safety_shutter")
    data = ho.dict_repr()
    try:
        socketio.emit("beamline_value_change", data, namespace="/hwr")
    except Exception:
        logging.getLogger("HWR").error('error sending message: %s' + str(data))
Example #2
0
def beamline_abort_action(name):
    """
    Aborts an action in progress.

    :param str name: Owner / Actuator of the process/action to abort

    Replies with status code 200 on success and 520 on exceptions.
    """
    try:
        cmds = mxcube.actions.getCommands()
    except Exception:
        cmds = []
    
    for cmd in cmds:
        if cmd.name() == name:
            try:
                cmd.abort()
            except Exception:
                err = sys.exc_info()[0]
                return make_response(err, 520) 
            else:
                return make_response("", 200)
   
    ho = BeamlineSetupMediator(mxcube.beamline).getObjectByRole(name.lower())

    try:
        ho.stop()
    except Exception:
        err = sys.exc_info()[0]
        return make_response(err, 520)
    else:
        logging.getLogger('user_level_log').error('Aborted by user.')
        return make_response("", 200)
Example #3
0
def beamline_set_attribute(name):
    """
    Tries to set <name> to value, replies with the following json:

        {name: <name>, value: <value>, msg: <msg>, state: <state>

    Where msg is an arbitrary msg to user, state is the internal state
    of the set operation (for the moment, VALID, ABORTED, ERROR).

    Replies with status code 200 on success and 520 on exceptions.
    """
    data = json.loads(request.data)
    ho = BeamlineSetupMediator(mxcube.beamline).getObjectByRole(name.lower())

    try:
        ho.set(data["value"])
        data = ho.dict_repr()
        result, code = json.dumps(data), 200
    except Exception as ex:
        data["value"] = ho.get()
        data["state"] = "UNUSABLE"
        data["msg"] = str(ex)
        result, code = json.dumps(data), 520

    return Response(result, status=code, mimetype='application/json')
Example #4
0
def beamline_get_attribute(name):
    """
    Retrieves value of attribute <name>, replies with the following json:

        {name: <name>, value: <value>, msg: <msg>, state: <state>

    Where msg is an arbitrary msg to user, state is the internal state
    of the get operation (for the moment, VALID, ABORTED, ERROR).

    Replies with status code 200 on success and 520 on exceptions.
    """
    ho = BeamlineSetupMediator(mxcube.beamline).getObjectByRole(name.lower())
    data = {"name": name, "value": ""}

    try:
        data = ho.dict_repr()
        code = 200
    except Exception as ex:
        data["value"] = ""
        data["state"] = "UNUSABLE"
        data["msg"] = str(ex)
        code = 520

    response = jsonify(data)
    response.code = code
    return response
Example #5
0
def beamline_get_attribute(name):
    """
    Retrieves value of attribute <name>, replies with the following json:

        {name: <name>, value: <value>, msg: <msg>, state: <state>

    Where msg is an arbitrary msg to user, state is the internal state
    of the get operation (for the moment, VALID, ABORTED, ERROR).

    Replies with status code 200 on success and 520 on exceptions.
    """
    ho = BeamlineSetupMediator(mxcube.beamline).getObjectByRole(name.lower())
    data = {"name": name, "value": ""}

    try:
        data = ho.dict_repr()
        code = 200
    except Exception as ex:
        data["value"] = ""
        data["state"] = "UNUSABLE"
        data["msg"] = str(ex)
        code = 520
 
    response = jsonify(data)
    response.code = code
    return response
Example #6
0
def safety_shutter_state_changed(values):
    ho = BeamlineSetupMediator(mxcube.beamline).getObjectByRole("safety_shutter")
    data = ho.dict_repr()
    try:
        socketio.emit("beamline_value_change", data, namespace="/hwr")
    except Exception:
        logging.getLogger("HWR").error('error sending message: %s' + str(data))
Example #7
0
def beamline_abort_action(name):
    """
    Aborts an action in progress.

    :param str name: Owner / Actuator of the process/action to abort
    """
    # This could be made to give access to arbitrary method of HO, possible
    # security issues to be discussed.
    ho = BeamlineSetupMediator(mxcube.beamline).getObjectByRole(name.lower())
    ho.stop()

    return Response('', status=200, mimetype='application/json')
Example #8
0
def beamline_abort_action(name):
    """
    Aborts an action in progress.

    :param str name: Owner / Actuator of the process/action to abort
    """
    # This could be made to give access to arbitrary method of HO, possible
    # security issues to be discussed.
    ho = BeamlineSetupMediator(mxcube.beamline).getObjectByRole(name.lower())
    ho.stop()

    return Response('', status=200, mimetype='application/json')
Example #9
0
def beamline_set_attribute(name):
    """
    Tries to set <name> to value, replies with the following json:

        {name: <name>, value: <value>, msg: <msg>, state: <state>

    Where msg is an arbitrary msg to user, state is the internal state
    of the set operation (for the moment, VALID, ABORTED, ERROR).

    Replies with status code 200 on success and 520 on exceptions.
    """
    data = json.loads(request.data)

    if name.lower() == "detdist":
        ho = BeamlineSetupMediator(mxcube.beamline).getObjectByRole("dtox")
    else:
        ho = BeamlineSetupMediator(mxcube.beamline).getObjectByRole(name.lower())

    try:
        ho.set(data["value"])
        logging.getLogger('HWR').info("Setting bl attribute %s to %s" %(name, data["value"]))
        res = ho.dict_repr()
        code = 200
    except Exception as ex:
        res = ho.dict_repr()
        res["value"] = ho.get()
        res["state"] = "UNUSABLE"
        res["msg"] = "submitted value out of limits"
        code = 520
        logging.getLogger('HWR').error("Error setting bl attribute: " + str(ex))

    response = jsonify(res)
    response.code = code
    return response
Example #10
0
def beamline_get_all_attributes():
    ho = BeamlineSetupMediator(mxcube.beamline)
    data = ho.dict_repr()
    actions = list()
    try:
        cmds = mxcube.actions.getCommands()
    except Exception:
        cmds = []
    for cmd in cmds:
        args = []
        for arg in cmd.getArguments():
          argname = arg[0]; argtype = arg[1]
          args.append({ "name": argname, "type": argtype })
          if argtype == 'combo':
            args[-1]["items"] = cmd.getComboArgumentItems(argname)
         
        actions.append({ "name": cmd.name(), "username": cmd.userName(), "state": READY, "arguments": args, "messages": [] })
    
    data.update({'path': mxcube.session.get_base_image_directory(), 'actionsList': actions })
    
    return jsonify(data)
Example #11
0
def beamline_set_attribute(name):
    """
    Tries to set <name> to value, replies with the following json:

        {name: <name>, value: <value>, msg: <msg>, state: <state>

    Where msg is an arbitrary msg to user, state is the internal state
    of the set operation (for the moment, VALID, ABORTED, ERROR).

    Replies with status code 200 on success and 520 on exceptions.
    """
    data = json.loads(request.data)
    ho = BeamlineSetupMediator(mxcube.beamline).getObjectByRole(name.lower())

    try:
        ho.set(data["value"])
        data = ho.dict_repr()
        result, code = json.dumps(data), 200
    except Exception as ex:
        data["value"] = ho.get()
        data["state"] = "UNUSABLE"
        data["msg"] = str(ex)
        result, code = json.dumps(data), 520

    return Response(result, status=code, mimetype='application/json')
Example #12
0
def beamline_get_all_attributes():
    ho = BeamlineSetupMediator(mxcube.beamline)
    data = ho.dict_repr()
    actions = list()
    try:
        cmds = mxcube.actions.getCommands()
    except Exception:
        cmds = []
    for cmd in cmds:
        args = []
        for arg in cmd.getArguments():
          argname = arg[0]; argtype = arg[1]
          args.append({ "name": argname, "type": argtype })
          if argtype == 'combo':
            args[-1]["items"] = cmd.getComboArgumentItems(argname)

        actions.append({ "name": cmd.name(), "username": cmd.userName(), "state": READY, "arguments": args, "messages": [] })

    data.update({'availableMethods': ho.get_available_methods()})
    data.update({'path': mxcube.session.get_base_image_directory(), 'actionsList': actions })
    data.update({'energyScanElements': ho.get_available_elements().get("elements", [])})

    return jsonify(data)
Example #13
0
def beamline_abort_action(name):
    """
    Aborts an action in progress.

    :param str name: Owner / Actuator of the process/action to abort

    Replies with status code 200 on success and 520 on exceptions.
    """
    try:
        cmds = mxcube.actions.getCommands()
    except Exception:
        cmds = []

    for cmd in cmds:
        if cmd.name() == name:
            try:
                cmd.abort()
            except Exception:
                err = str(sys.exc_info()[1])
                return make_response(err, 520)
            else:
                return make_response("", 200)

    # This could be made to give access to arbitrary method of HO, possible
    # security issues to be discussed.
    if name.lower() == "detdist":
        ho = BeamlineSetupMediator(mxcube.beamline).getObjectByRole("dtox")
    else:
        ho = BeamlineSetupMediator(mxcube.beamline).getObjectByRole(name.lower())
    ho.stop()

    try:
        ho.stop()
    except Exception:
        err = str(sys.exc_info()[1])
        return make_response(err, 520)
    else:
        logging.getLogger('user_level_log').error('Aborting set on %s.' % name)
        return make_response("", 200)
Example #14
0
def beamline_get_all_attributes():
    ho = BeamlineSetupMediator(mxcube.beamline)
    data = ho.dict_repr()
    return Response(json.dumps(data), status=200, mimetype='application/json')
Example #15
0
def beamline_get_all_attributes():
    ho = BeamlineSetupMediator(mxcube.beamline)
    data = ho.dict_repr()
    data.update({'path': mxcube.session.get_base_image_directory()})
    return Response(json.dumps(data), status=200, mimetype='application/json')
Example #16
0
def beamline_get_all_attributes():
    ho = BeamlineSetupMediator(mxcube.beamline)
    data = ho.dict_repr()
    data.update({'path': mxcube.session.get_base_image_directory()})
    return Response(json.dumps(data), status=200, mimetype='application/json')