summaryrefslogtreecommitdiffstats
path: root/bitbake
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
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')
-rw-r--r--bitbake/lib/toaster/toastergui/api.py74
-rw-r--r--bitbake/lib/toaster/toastergui/tables.py43
-rw-r--r--bitbake/lib/toaster/toastergui/urls.py5
3 files changed, 80 insertions, 42 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
diff --git a/bitbake/lib/toaster/toastergui/tables.py b/bitbake/lib/toaster/toastergui/tables.py
index 67a659222f..822c7e586c 100644
--- a/bitbake/lib/toaster/toastergui/tables.py
+++ b/bitbake/lib/toaster/toastergui/tables.py
@@ -22,7 +22,7 @@
22from toastergui.widgets import ToasterTable 22from toastergui.widgets import ToasterTable
23from orm.models import Recipe, ProjectLayer, Layer_Version, Machine, Project 23from orm.models import Recipe, ProjectLayer, Layer_Version, Machine, Project
24from orm.models import CustomImageRecipe, Package, Target, Build, LogMessage, Task 24from orm.models import CustomImageRecipe, Package, Target, Build, LogMessage, Task
25from orm.models import CustomImagePackage, ProjectTarget 25from orm.models import CustomImagePackage
26from django.db.models import Q, Max, Sum, Count, When, Case, Value, IntegerField 26from django.db.models import Q, Max, Sum, Count, When, Case, Value, IntegerField
27from django.conf.urls import url 27from django.conf.urls import url
28from django.core.urlresolvers import reverse, resolve 28from django.core.urlresolvers import reverse, resolve
@@ -1400,47 +1400,6 @@ class BuildsTable(ToasterTable):
1400 failed_tasks_filter.add_action(without_failed_tasks_action) 1400 failed_tasks_filter.add_action(without_failed_tasks_action)
1401 self.add_filter(failed_tasks_filter) 1401 self.add_filter(failed_tasks_filter)
1402 1402
1403 def post(self, request, *args, **kwargs):
1404 """ Process HTTP POSTs which make build requests """
1405
1406 project = Project.objects.get(pk=kwargs['pid'])
1407
1408 if 'buildCancel' in request.POST:
1409 for i in request.POST['buildCancel'].strip().split(" "):
1410 try:
1411 br = BuildRequest.objects.select_for_update().get(project = project, pk = i, state__lte = BuildRequest.REQ_QUEUED)
1412 br.state = BuildRequest.REQ_DELETED
1413 br.save()
1414 except BuildRequest.DoesNotExist:
1415 pass
1416
1417 if 'buildDelete' in request.POST:
1418 for i in request.POST['buildDelete'].strip().split(" "):
1419 try:
1420 BuildRequest.objects.select_for_update().get(project = project, pk = i, state__lte = BuildRequest.REQ_DELETED).delete()
1421 except BuildRequest.DoesNotExist:
1422 pass
1423
1424 if 'targets' in request.POST:
1425 ProjectTarget.objects.filter(project = project).delete()
1426 s = str(request.POST['targets'])
1427 for t in s.translate(None, ";%|\"").split(" "):
1428 if ":" in t:
1429 target, task = t.split(":")
1430 else:
1431 target = t
1432 task = ""
1433 ProjectTarget.objects.create(project = project,
1434 target = target,
1435 task = task)
1436 project.schedule_build()
1437
1438 # redirect back to builds page so any new builds in progress etc.
1439 # are visible
1440 response = HttpResponse()
1441 response.status_code = 302
1442 response['Location'] = request.build_absolute_uri()
1443 return response
1444 1403
1445class AllBuildsTable(BuildsTable): 1404class AllBuildsTable(BuildsTable):
1446 """ Builds page for all builds """ 1405 """ Builds page for all builds """
diff --git a/bitbake/lib/toaster/toastergui/urls.py b/bitbake/lib/toaster/toastergui/urls.py
index 400580a235..27b0baabfb 100644
--- a/bitbake/lib/toaster/toastergui/urls.py
+++ b/bitbake/lib/toaster/toastergui/urls.py
@@ -22,6 +22,7 @@ from django.views.generic import RedirectView, TemplateView
22from django.http import HttpResponseBadRequest 22from django.http import HttpResponseBadRequest
23from toastergui import tables 23from toastergui import tables
24from toastergui import typeaheads 24from toastergui import typeaheads
25from toastergui import api
25 26
26urlpatterns = patterns('toastergui.views', 27urlpatterns = patterns('toastergui.views',
27 # landing page 28 # landing page
@@ -180,6 +181,10 @@ urlpatterns = patterns('toastergui.views',
180 url(r'^xhr_customrecipe/', 'xhr_customrecipe', 181 url(r'^xhr_customrecipe/', 'xhr_customrecipe',
181 name='xhr_customrecipe'), 182 name='xhr_customrecipe'),
182 183
184 url(r'^xhr_buildrequest/project/(?P<pid>\d+)$',
185 api.XhrBuildRequest.as_view(),
186 name='xhr_buildrequest'),
187
183 # default redirection 188 # default redirection
184 url(r'^$', RedirectView.as_view(url='landing', permanent=True)), 189 url(r'^$', RedirectView.as_view(url='landing', permanent=True)),
185) 190)