Exemplo n.º 1
0
def delete_task(taskname):
    """
    删除任务
    ---
    tags:
      - 任务
    description:

    parameters:
      - name: taskname
        in: path
        type: string
        required: true
        description: 任务名
    responses:
      2xx:
        description: 成功
      4xx:
        description: 参数有误等
    """
    if taskname == '':
        return BadRequestError(f'参数 taskname 不为空')

    del_task(taskname)

    return Reply({'taskname': taskname})
Exemplo n.º 2
0
def delete_account(username):
    """
    删除账号
    ---
    tags:
      - 账号
    description:

    parameters:
      - name: username
        in: path
        type: string
        required: true
        description: 主键
    responses:
      2xx:
        description: 成功
      4xx:
        description: 参数有误等
    """
    if username == '':
        return BadRequestError(f'参数 username 不为空')

    del_account(username)

    return Reply({'username': username})
Exemplo n.º 3
0
def create_account():
    """
    添加账号
    ---
    tags:
      - 账号
    description:

    parameters:
      - name: body
        in: body
        required: true
        schema:
          id:  账号添加
          required:
            - username
            - password
          properties:
            username:
              type: string
              description: 账户
            password:
              type: string
              description: 密码
            taskname:
              type: string
              description: 任务
    responses:
      2xx:
        description: 成功
      4xx:
        description: 参数有误等
    """
    body = request.form or request.get_json()
    if body is None:
        return BadRequestError(f'参数不合法')
    username = body.get('username', '')
    password = body.get('password', '')
    # taskname = body.get('taskname', '')
    # taskname已经被废弃不再需要
    try:
        if username == '':
            return BadRequestError(f'参数 username 不为空')
        if password == '':
            return BadRequestError(f'参数 password 不为空')

        service_create_account(account=username, password=password)

        return Reply({'username': username, 'password': password})
    
    except Exception as e:
        return NotFoundError(f"添加用户 {username} 失败, {e}")
Exemplo n.º 4
0
def update_account(username):
    """
    更新账号
    ---
    tags:
      - 账号
    description:

    parameters:
      - name: username
        in: path
        type: string
        required: true
        description: 主键
      - name: body
        in: body
        required: true
        schema:
          id:  账号更新
          properties:
            password:
              type: string
              description: 密码
            taskname:
              type: string
              description: 任务
    responses:
      2xx:
        description: 成功
      4xx:
        description: 参数有误等
    """
    if username == '':
        return BadRequestError(f'参数 username 不为空')

    body = request.form or request.get_json()
    if body is None:
        return BadRequestError(f'参数不合法')
    password = body.get('password', None)
    taskname = body.get('taskname', None)

    edit_account(account=username, password=password, taskfile=taskname)
    return Reply({'username': username, 'password': password, 'taskname': taskname})
Exemplo n.º 5
0
def update_task(taskname):
    """
    更新任务
    ---
    tags:
      - 任务
    description:

    parameters:
      - name: pk
        in: path
        type: string
        required: true
        description: 主键
      - name: body
        in: body
        required: true
        schema:
          id:  任务添加
          required:
            taskname
          properties:
            taskname:
              type: string
              description: 任务名
            subtasks:
              type: string
              description: 任务名
    responses:
      2xx:
        description: 成功
      4xx:
        description: 参数有误等
    """
    if taskname == '':
        return BadRequestError(f'参数 taskname 不为空')

    body = request.form or request.get_json()
    if body is None:
        return BadRequestError(f'参数不合法')

    return Reply({})
Exemplo n.º 6
0
def retrieve_account(username):
    """
    获取单条账号
    ---
    tags:
      - 账号
    description:

    parameters:
          - name: username
            in: path
            type: string
            required: true
            description: 用户名
    responses:
      2xx:
        description: 成功
      4xx:
        description: 参数有误等
    """
    if username == '':
        return BadRequestError(f'参数不合法, 用户名:{username}')

    data = {
        'username': '',
        'password': '******',
        'taskname': '',
        'tags': '-'
    }

    try:
        user = AutomatorRecorder(username).getuser()
        if user is not None:
            data['username'] = user.get('account')
            data['taskname'] = user.get('taskfile')
        return Reply(data)

    except Exception as e:
        return NotFoundError(f"获取用户 {username} 失败, {e}")
Exemplo n.º 7
0
def retrieve_task(taskname):
    """
    获取单条任务
    ---
    tags:
      - 任务
    description:

    parameters:
          - name: taskname
            in: path
            type: string
            required: true
            description: 任务名
    responses:
      2xx:
        description: 成功
      4xx:
        description: 参数有误等
    """
    if taskname == '':
        return BadRequestError(f'参数不合法, 任务名:{taskname}')

    data = {
        'taskname': '',
        'accounts': '-',
        'subtasks': {},
    }

    try:
        subtasks = AutomatorRecorder(None).gettask(taskname)
        if subtasks is not None:
            data['taskname'] = taskname
            data['subtasks'] = subtasks
        return Reply(data)

    except Exception as e:
        return NotFoundError(f"获取任务 {taskname} 失败, {e}")
Exemplo n.º 8
0
def create_task():
    """
    添加任务
    ---
    tags:
      - 任务
    description:

    parameters:
      - name: body
        in: body
        required: true
        schema:
          id:  任务添加
          required:
            taskname
          properties:
            taskname:
              type: string
              description: 任务名
    responses:
      2xx:
        description: 成功
      4xx:
        description: 参数有误等
    """

    body = request.form or request.get_json()
    if body is None:
        return BadRequestError(f'参数不合法')
    taskname = body.get('taskname', '')
    if taskname == '':
        return BadRequestError(f'参数 taskname 不为空')

    service_create_task(taskname)
    return Reply({'taskname': taskname})
Exemplo n.º 9
0
def retrieve_subtask_schma(abbr):
    subtask_type: dict = VALID_TASK.T

    return Reply(parse_validate_task(abbr, subtask_type.get(abbr)))