diff options
-rw-r--r-- | bitbake/lib/toaster/toastergui/api.py | 74 | ||||
-rw-r--r-- | bitbake/lib/toaster/toastergui/tables.py | 43 | ||||
-rw-r--r-- | bitbake/lib/toaster/toastergui/urls.py | 5 |
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 | |||
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 | ||
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 @@ | |||
22 | from toastergui.widgets import ToasterTable | 22 | from toastergui.widgets import ToasterTable |
23 | from orm.models import Recipe, ProjectLayer, Layer_Version, Machine, Project | 23 | from orm.models import Recipe, ProjectLayer, Layer_Version, Machine, Project |
24 | from orm.models import CustomImageRecipe, Package, Target, Build, LogMessage, Task | 24 | from orm.models import CustomImageRecipe, Package, Target, Build, LogMessage, Task |
25 | from orm.models import CustomImagePackage, ProjectTarget | 25 | from orm.models import CustomImagePackage |
26 | from django.db.models import Q, Max, Sum, Count, When, Case, Value, IntegerField | 26 | from django.db.models import Q, Max, Sum, Count, When, Case, Value, IntegerField |
27 | from django.conf.urls import url | 27 | from django.conf.urls import url |
28 | from django.core.urlresolvers import reverse, resolve | 28 | from 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 | ||
1445 | class AllBuildsTable(BuildsTable): | 1404 | class 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 | |||
22 | from django.http import HttpResponseBadRequest | 22 | from django.http import HttpResponseBadRequest |
23 | from toastergui import tables | 23 | from toastergui import tables |
24 | from toastergui import typeaheads | 24 | from toastergui import typeaheads |
25 | from toastergui import api | ||
25 | 26 | ||
26 | urlpatterns = patterns('toastergui.views', | 27 | urlpatterns = 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 | ) |