Exemplo n.º 1
0
def edit_action(action_name):
    if gl.get_value('state') == 'WAITING':
        gl.set_value('state', 'BUSY')
        form = ActionForm().validate_for_api()
        from DRcode.app.libs.robot import Robot
        robot = Robot()
        # 动作不存在
        if action_name not in robot.action_user_list:
            gl.set_value('state', 'WAITING')
            return NotFound()
        # 重命名并修改动作
        else:
            try:
                # 仅修改名称
                if form.body.data == '':
                    new_name = form.name.data
                    Robot.robot_rename_action(action_name, new_name)
                # 仅修改内容
                elif form.name.data == '':
                    Robot.robot_delete_action(action_name)
                    Robot.robot_add_action(action_name, form.body.data)
                # 都修改
                else:
                    Robot.robot_delete_action(action_name)
                    Robot.robot_add_action(form.name.data, form.body.data)
                gl.set_value('state', 'WAITING')
                return Success(msg='rename and edit successfully')
            except Exception as result:
                print('检测出异常{}'.format(result))
                gl.set_value('state', 'WAITING')
                return ServerError(msg='Error{}'.format(result))
    else:
        return InstructBusy()
Exemplo n.º 2
0
def delete_action(action_name):
    if gl.get_value('state') == 'WAITING':
        gl.set_value('state', 'BUSY')
        from DRcode.app.libs.robot import Robot
        robot = Robot()
        if action_name not in robot.action_user_list:
            gl.set_value('state', 'WAITING')
            return NotFound()
        else:
            try:
                Robot.robot_delete_action(action_name)
                gl.set_value('state', 'WAITING')
                return DeleteSuccess()
            except Exception as result:
                print('检测出异常{}'.format(result))
                gl.set_value('state', 'WAITING')
                return ServerError(msg='Error{}'.format(result))
    else:
        return InstructBusy()