Exemplo n.º 1
0
def edit_code(code_name):
    if gl.get_value('state') == 'WAITING':
        gl.set_value('state', 'BUSY')
        form = CodeForm().validate_for_api()
        from DRcode.app.libs.robot import Robot
        robot = Robot()
        # 动作不存在
        if code_name not in robot.code_user_list:
            gl.set_value('state', 'WAITING')
            return NotFound()
        # 重命名并修改动作
        else:
            try:
                # 仅修改名称
                if form.body.data == '':
                    new_name = form.name.data
                    Robot.robot_rename_code(code_name, new_name)
                # 仅修改内容
                elif form.name.data == '':
                    Robot.robot_delete_code(code_name)
                    Robot.robot_add_code(code_name, form.body.data)
                # 都修改
                else:
                    Robot.robot_delete_code(code_name)
                    Robot.robot_add_code(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 create_code():
    if gl.get_value('state') == 'WAITING':
        gl.set_value('state', 'BUSY')
        form = CodeForm().validate_for_api()
        try:
            from DRcode.app.libs.robot import Robot
            Robot.robot_add_code(form.name.data, form.body.data)
            gl.set_value('state', 'WAITING')
            return Success()
        except Exception as result:
            print('检测出异常{}'.format(result))
            return ServerError(msg='Error{}'.format(result))
    else:
        return InstructBusy()