diff options
Diffstat (limited to 'bitbake/lib/toaster/toastergui/api.py')
-rw-r--r-- | bitbake/lib/toaster/toastergui/api.py | 74 |
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 | |||
22 | from orm.models import Project, ProjectTarget | ||
23 | from bldcontrol.models import BuildRequest | ||
24 | from bldcontrol import bbcontroller | ||
25 | from django.http import HttpResponse, JsonResponse | ||
26 | from django.views.generic import View | ||
27 | |||
28 | |||
29 | class 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 | ||