예제 #1
0
파일: meta.py 프로젝트: rabaarabaa/server
def get_command_value(command_ids: list):
    """
    Get the returned command value

    Args:
        command_ids: list of command ids

    Returns:
        ```
        { command_id : value }
        ```

    """

    _command_msg(command_ids)

    values = {}

    for i in command_ids:
        cmd = Service.get_command(i)
        if cmd.state not in (command.CommandState.finished, command.CommandState.stopped):
            if cmd.state == command.CommandState.failed:
                raise exceptions.CommandError(utils.this_function(), "Command with ID '{}' has failed".format(i))
            raise exceptions.CommandError(utils.this_function(),
                                          "Command with ID '{}' has not finished running".format(i))

        if isinstance(cmd.value, message.CoreMessage):
            values[i] = cmd.value.json_friendly(include_key=False)
        else:
            values[i] = cmd.value
        if constants.debug:
            cmd._log_stats(arrow.now())

    return message.Identity('command_value', values)
예제 #2
0
파일: meta.py 프로젝트: rabaarabaa/server
def get_command_state(command_ids: list):
    """
    Get state of command

    Args:
        command_ids: list of command ids

    Returns:
        ```
        { command_id : state }
        ```
    """

    _command_msg(command_ids)

    states = {}

    for i in command_ids:
        states[i] = Service.get_command(i).state.name

    return message.Identity('command_state', states)
예제 #3
0
파일: meta.py 프로젝트: rabaarabaa/server
def start_command(command_ids: list):
    """
    Start running a command

    Args:
        command_ids: list of command ids

    Returns:
        ```
        { command_id : state }
        ```
    """
    _command_msg(command_ids)

    states = {}

    for i in command_ids:
        cmd = Service.get_command(i)
        cmd.start()
        states[i] = cmd.state.name

    return message.Identity('command_state', states)
예제 #4
0
파일: meta.py 프로젝트: rabaarabaa/server
def _command_msg(ids):
    for x in ids:
        if not Service.get_command(x):
            raise exceptions.CommandError(utils.this_function(), "Command with ID '{}' does not exist".format(x))