summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/api.py
diff options
context:
space:
mode:
authorMichael Wood <michael.g.wood@intel.com>2016-04-06 17:46:30 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-04-06 23:10:29 +0100
commiteead032aca1592de9a764b530f9c436ff57cee21 (patch)
treecc6f60e468aaa758555f203cac598dacc9b271ca /bitbake/lib/toaster/toastergui/api.py
parentf5aa97067f0955b6be5e69b5859d1f3c5624c2da (diff)
downloadpoky-eead032aca1592de9a764b530f9c436ff57cee21.tar.gz
bitbake: toaster: Move xhr calls for starting and stopping builds
Move the backend xhr implementation of the build request changes into it's own file and out of the ToasterTable definition. It used to live in the views.py but in a hope of starting to collate logical groups of views move this to a new file called api. (Bitbake rev: 29572f0e6bd3b5e8315f3b93d55bdb8967b86bc3) Signed-off-by: Michael Wood <michael.g.wood@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/toastergui/api.py')
-rw-r--r--bitbake/lib/toaster/toastergui/api.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/bitbake/lib/toaster/toastergui/api.py b/bitbake/lib/toaster/toastergui/api.py
new file mode 100644
index 0000000000..1b1f59813f
--- /dev/null
+++ b/bitbake/lib/toaster/toastergui/api.py
@@ -0,0 +1,74 @@
1#
2# BitBake Toaster Implementation
3#
4# Copyright (C) 2016 Intel Corporation
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License version 2 as
8# published by the Free Software Foundation.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License along
16# with this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19
20# Temporary home for the UI's misc API
21
22from orm.models import Project, ProjectTarget
23from bldcontrol.models import BuildRequest
24from bldcontrol import bbcontroller
25from django.http import HttpResponse, JsonResponse
26from django.views.generic import View
27
28
29class XhrBuildRequest(View):
30
31 def get(self, request, *args, **kwargs):
32 return HttpResponse()
33
34 def post(self, request, *args, **kwargs):
35 """ Process HTTP POSTs which make build requests """
36
37 project = Project.objects.get(pk=kwargs['pid'])
38
39 if 'buildCancel' in request.POST:
40 for i in request.POST['buildCancel'].strip().split(" "):
41 try:
42 br = BuildRequest.objects.select_for_update().get(project = project, pk = i, state__lte = BuildRequest.REQ_QUEUED)
43 br.state = BuildRequest.REQ_DELETED
44 br.save()
45 except BuildRequest.DoesNotExist:
46 pass
47
48 if 'buildDelete' in request.POST:
49 for i in request.POST['buildDelete'].strip().split(" "):
50 try:
51 BuildRequest.objects.select_for_update().get(project = project, pk = i, state__lte = BuildRequest.REQ_DELETED).delete()
52 except BuildRequest.DoesNotExist:
53 pass
54
55 if 'targets' in request.POST:
56 ProjectTarget.objects.filter(project = project).delete()
57 s = str(request.POST['targets'])
58 for t in s.translate(None, ";%|\"").split(" "):
59 if ":" in t:
60 target, task = t.split(":")
61 else:
62 target = t
63 task = ""
64 ProjectTarget.objects.create(project = project,
65 target = target,
66 task = task)
67 project.schedule_build()
68
69 # redirect back to builds page so any new builds in progress etc.
70 # are visible
71 response = HttpResponse()
72 response.status_code = 302
73 response['Location'] = request.build_absolute_uri()
74 return response