Package coprs :: Package rest_api :: Package resources :: Module build_task
[hide private]
[frames] | no frames]

Source Code for Module coprs.rest_api.resources.build_task

  1  # coding: utf-8 
  2   
  3  from flask import url_for 
  4  from flask_restful import Resource 
  5   
  6  from copr_common.enums import StatusEnum 
  7  from coprs.rest_api.common import render_build_task 
  8  from ...exceptions import MalformedArgumentException 
  9  from ...logic.builds_logic import BuildChrootsLogic 
 10  from ..exceptions import MalformedRequest 
 11  from ..util import get_one_safe, get_request_parser 
12 13 14 # todo: add redirect from /build_tasks/<int:build_id> -> /build_tasks?build_id=<build_id> 15 # class BuildTaskListRedirectBuildIdR(Resource): 16 # def get(self, build_id): 17 # resp = make_response("", 302) 18 # resp.headers["Location"] == url_for(".buildtasklistr", build_id=build_id) 19 20 21 -class BuildTaskListR(Resource):
22 state_choices = StatusEnum.vals.keys() 23
24 - def get(self):
25 26 parser = get_request_parser() 27 28 parser.add_argument('owner', type=str,) 29 parser.add_argument('project_id', type=int) 30 parser.add_argument('build_id', type=int) 31 parser.add_argument('group', type=str) 32 33 parser.add_argument('limit', type=int) 34 parser.add_argument('offset', type=int) 35 36 parser.add_argument( 37 'state', type=str, choices=self.state_choices, 38 help=u"allowed states: {}".format(" ".join(self.state_choices))) 39 40 req_args = parser.parse_args() 41 42 self_params = dict(req_args) 43 44 query = BuildChrootsLogic.get_multiply() 45 if self_params.get("build_id") is not None: 46 query = BuildChrootsLogic.filter_by_build_id( 47 query, self_params["build_id"]) 48 elif self_params.get("project_id") is not None: 49 query = BuildChrootsLogic.filter_by_project_id( 50 query, self_params["project_id"]) 51 elif self_params.get("owner") is not None: 52 query = BuildChrootsLogic.filter_by_project_user_name( 53 query, self_params["owner"]) 54 elif self_params.get("group") is not None: 55 query = BuildChrootsLogic.filter_by_group_name(query, req_args["group"]) 56 57 state = self_params.get("state") 58 if state: 59 query = BuildChrootsLogic.filter_by_state(query, state) 60 61 if req_args["limit"] is not None: 62 limit = req_args["limit"] 63 if limit <= 0 or limit > 100: 64 limit = 100 65 else: 66 limit = 100 67 self_params["limit"] = limit 68 query = query.limit(limit) 69 70 if "offset" in self_params is not None: 71 query = query.offset(self_params["offset"]) 72 73 build_chroots = query.all() 74 return { 75 "build_tasks": [ 76 render_build_task(chroot) 77 for chroot in build_chroots 78 ], 79 "_links": { 80 "self": {"href": url_for(".buildtasklistr", **self_params)} 81 } 82 }
83
84 85 -class BuildTaskR(Resource):
86 87 @staticmethod
88 - def _get_chroot_safe(build_id, name):
89 try: 90 chroot = get_one_safe( 91 BuildChrootsLogic.get_by_build_id_and_name(build_id, name), 92 "Build task {} for build {} not found" 93 ) 94 except MalformedArgumentException as err: 95 raise MalformedRequest("Bad mock chroot name: {}".format(err)) 96 return chroot
97
98 - def get(self, build_id, name):
101 102 # todo: add put method: allows only to pass status: cancelled to cancel build 103