diff options
Diffstat (limited to 'bitbake/lib/toaster/toastergui/api.py')
-rw-r--r-- | bitbake/lib/toaster/toastergui/api.py | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/bitbake/lib/toaster/toastergui/api.py b/bitbake/lib/toaster/toastergui/api.py index 3a05d66383..b01d4ba815 100644 --- a/bitbake/lib/toaster/toastergui/api.py +++ b/bitbake/lib/toaster/toastergui/api.py | |||
@@ -49,6 +49,28 @@ class XhrBuildRequest(View): | |||
49 | def get(self, request, *args, **kwargs): | 49 | def get(self, request, *args, **kwargs): |
50 | return HttpResponse() | 50 | return HttpResponse() |
51 | 51 | ||
52 | @staticmethod | ||
53 | def cancel_build(br): | ||
54 | """Cancel a build request""" | ||
55 | try: | ||
56 | bbctrl = bbcontroller.BitbakeController(br.environment) | ||
57 | bbctrl.forceShutDown() | ||
58 | except: | ||
59 | # We catch a bunch of exceptions here because | ||
60 | # this is where the server has not had time to start up | ||
61 | # and the build request or build is in transit between | ||
62 | # processes. | ||
63 | # We can safely just set the build as cancelled | ||
64 | # already as it never got started | ||
65 | build = br.build | ||
66 | build.outcome = Build.CANCELLED | ||
67 | build.save() | ||
68 | |||
69 | # We now hand over to the buildinfohelper to update the | ||
70 | # build state once we've finished cancelling | ||
71 | br.state = BuildRequest.REQ_CANCELLING | ||
72 | br.save() | ||
73 | |||
52 | def post(self, request, *args, **kwargs): | 74 | def post(self, request, *args, **kwargs): |
53 | """ | 75 | """ |
54 | Build control | 76 | Build control |
@@ -74,26 +96,7 @@ class XhrBuildRequest(View): | |||
74 | for i in request.POST['buildCancel'].strip().split(" "): | 96 | for i in request.POST['buildCancel'].strip().split(" "): |
75 | try: | 97 | try: |
76 | br = BuildRequest.objects.get(project=project, pk=i) | 98 | br = BuildRequest.objects.get(project=project, pk=i) |
77 | 99 | self.cancel_build(br) | |
78 | try: | ||
79 | bbctrl = bbcontroller.BitbakeController(br.environment) | ||
80 | bbctrl.forceShutDown() | ||
81 | except: | ||
82 | # We catch a bunch of exceptions here because | ||
83 | # this is where the server has not had time to start up | ||
84 | # and the build request or build is in transit between | ||
85 | # processes. | ||
86 | # We can safely just set the build as cancelled | ||
87 | # already as it never got started | ||
88 | build = br.build | ||
89 | build.outcome = Build.CANCELLED | ||
90 | build.save() | ||
91 | |||
92 | # We now hand over to the buildinfohelper to update the | ||
93 | # build state once we've finished cancelling | ||
94 | br.state = BuildRequest.REQ_CANCELLING | ||
95 | br.save() | ||
96 | |||
97 | except BuildRequest.DoesNotExist: | 100 | except BuildRequest.DoesNotExist: |
98 | return error_response('No such build request id %s' % i) | 101 | return error_response('No such build request id %s' % i) |
99 | 102 | ||
@@ -823,11 +826,21 @@ class XhrProject(View): | |||
823 | return HttpResponse() | 826 | return HttpResponse() |
824 | 827 | ||
825 | def delete(self, request, *args, **kwargs): | 828 | def delete(self, request, *args, **kwargs): |
829 | """Delete a project. Cancels any builds in progress""" | ||
826 | try: | 830 | try: |
827 | Project.objects.get(pk=kwargs['project_id']).delete() | 831 | project = Project.objects.get(pk=kwargs['project_id']) |
832 | # Cancel any builds in progress | ||
833 | for br in BuildRequest.objects.filter( | ||
834 | project=project, | ||
835 | state=BuildRequest.REQ_INPROGRESS): | ||
836 | XhrBuildRequest.cancel_build(br) | ||
837 | |||
838 | project.delete() | ||
839 | |||
828 | except Project.DoesNotExist: | 840 | except Project.DoesNotExist: |
829 | return error_response("Project %s does not exist" % | 841 | return error_response("Project %s does not exist" % |
830 | kwargs['project_id']) | 842 | kwargs['project_id']) |
843 | |||
831 | return JsonResponse({ | 844 | return JsonResponse({ |
832 | "error": "ok", | 845 | "error": "ok", |
833 | "gotoUrl": reverse("all-projects", args=[]) | 846 | "gotoUrl": reverse("all-projects", args=[]) |