Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id ECC98E00CFA; Thu, 25 Feb 2016 10:21:34 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on yocto-www.yoctoproject.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature * 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily * valid Received: from mail-wm0-f50.google.com (mail-wm0-f50.google.com [74.125.82.50]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id A2AF9E00CFE for ; Thu, 25 Feb 2016 10:21:32 -0800 (PST) Received: by mail-wm0-f50.google.com with SMTP id g62so43393567wme.0 for ; Thu, 25 Feb 2016 10:21:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MGTNsX+ULPDcuiStTsDSs8GAm7p7On1SBAZonfRw49E=; b=jY9+TPgn+tYAXPaIzvgewYXzG5MYuaFxNamKynIPqCIaWo4Ji8smBVcuGFrjHtBJai 6nylFkB6wr5xRCChbrUKVB930IJfMS41io0+/fQjjYFX/8GMSOl2EFn7YULzzp5qrIV5 YufVwOKf1AvWtgmXveB2HbRIsRLigtsE/beBuZ1EiwdJk78BgPUiZYXjFvnmHYtqe+tl 4xK1Mw9P5IU8AvRqfSexFzpbiYz8WFlzjawIEZ4wM+gA9IueMwbPgbZzRKbaQ/oD34ud //KgCAbgSZ2Md9jl6a5m9FeBYlsRvi2wecTWrmU51u0VqVqCV8EImFERZJEeT6mWsZNO +fqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MGTNsX+ULPDcuiStTsDSs8GAm7p7On1SBAZonfRw49E=; b=Lqmx3Kkpx9a1My/c8GK827bvglE4u+RpbY0vheEu23L9ENFPay2Pp0bTD8/A7KnzUs KE9medO5yi4zrLR5z44yrspW9kCrBbSZiUYx8d0N/xYijV3N3549orApOIYANpwlN4OY Vr+HHexN9B+jnjAFedAwn4PTNc5PZfS259ZVeSV/gLQCo4YA6OWBsJnvFmfSGZIHJWl5 7j3AU2F3c9ZPVvp9YWRxxfJL6aPyzPzvkUoM25wT93RC9gFmh753GKCVxZlsMHWr9v8z SyMod3WCFx5E61qDk+ZEVw9H5AWWi9CYk73HqKY3qzLgQle8ERrVJsOPp8aVQ1kqI4RK Et6Q== X-Gm-Message-State: AG10YOQwn2CW3Bp43sGJ5jNwOzooOaN9VSnYTlV//3fULj+TlytPaGjrS/dZ9+hHJNOOVI/F X-Received: by 10.194.77.193 with SMTP id u1mr45877338wjw.73.1456424491481; Thu, 25 Feb 2016 10:21:31 -0800 (PST) Received: from draco.icx.intel.com ([83.217.123.106]) by smtp.gmail.com with ESMTPSA id az8sm3084010wjc.17.2016.02.25.10.21.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 Feb 2016 10:21:30 -0800 (PST) From: Michael Wood To: toaster@yoctoproject.org Date: Thu, 25 Feb 2016 18:21:16 +0000 Message-Id: <1456424485-6566-3-git-send-email-michael.g.wood@intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1456424485-6566-1-git-send-email-michael.g.wood@intel.com> References: <1456424485-6566-1-git-send-email-michael.g.wood@intel.com> Subject: [PATCH 02/11] toaster: Move xhr calls for starting and stopping builds X-BeenThere: toaster@yoctoproject.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Web based interface for BitBake List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Feb 2016 18:21:35 -0000 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. Signed-off-by: Michael Wood --- bitbake/lib/toaster/toastergui/api.py | 74 ++++++++++++++++++++++++++++++++ bitbake/lib/toaster/toastergui/tables.py | 43 +------------------ bitbake/lib/toaster/toastergui/urls.py | 5 +++ 3 files changed, 80 insertions(+), 42 deletions(-) create mode 100644 bitbake/lib/toaster/toastergui/api.py diff --git a/bitbake/lib/toaster/toastergui/api.py b/bitbake/lib/toaster/toastergui/api.py new file mode 100644 index 0000000..1b1f598 --- /dev/null +++ b/bitbake/lib/toaster/toastergui/api.py @@ -0,0 +1,74 @@ +# +# BitBake Toaster Implementation +# +# Copyright (C) 2016 Intel Corporation +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + +# Temporary home for the UI's misc API + +from orm.models import Project, ProjectTarget +from bldcontrol.models import BuildRequest +from bldcontrol import bbcontroller +from django.http import HttpResponse, JsonResponse +from django.views.generic import View + + +class XhrBuildRequest(View): + + def get(self, request, *args, **kwargs): + return HttpResponse() + + def post(self, request, *args, **kwargs): + """ Process HTTP POSTs which make build requests """ + + project = Project.objects.get(pk=kwargs['pid']) + + if 'buildCancel' in request.POST: + for i in request.POST['buildCancel'].strip().split(" "): + try: + br = BuildRequest.objects.select_for_update().get(project = project, pk = i, state__lte = BuildRequest.REQ_QUEUED) + br.state = BuildRequest.REQ_DELETED + br.save() + except BuildRequest.DoesNotExist: + pass + + if 'buildDelete' in request.POST: + for i in request.POST['buildDelete'].strip().split(" "): + try: + BuildRequest.objects.select_for_update().get(project = project, pk = i, state__lte = BuildRequest.REQ_DELETED).delete() + except BuildRequest.DoesNotExist: + pass + + if 'targets' in request.POST: + ProjectTarget.objects.filter(project = project).delete() + s = str(request.POST['targets']) + for t in s.translate(None, ";%|\"").split(" "): + if ":" in t: + target, task = t.split(":") + else: + target = t + task = "" + ProjectTarget.objects.create(project = project, + target = target, + task = task) + project.schedule_build() + + # redirect back to builds page so any new builds in progress etc. + # are visible + response = HttpResponse() + response.status_code = 302 + response['Location'] = request.build_absolute_uri() + return response diff --git a/bitbake/lib/toaster/toastergui/tables.py b/bitbake/lib/toaster/toastergui/tables.py index 71892e2..0cda459 100644 --- a/bitbake/lib/toaster/toastergui/tables.py +++ b/bitbake/lib/toaster/toastergui/tables.py @@ -22,7 +22,7 @@ from toastergui.widgets import ToasterTable from orm.models import Recipe, ProjectLayer, Layer_Version, Machine, Project from orm.models import CustomImageRecipe, Package, Target, Build, LogMessage, Task -from orm.models import CustomImagePackage, ProjectTarget +from orm.models import CustomImagePackage from django.db.models import Q, Max, Sum, Count, When, Case, Value, IntegerField from django.conf.urls import url from django.core.urlresolvers import reverse, resolve @@ -1400,47 +1400,6 @@ class BuildsTable(ToasterTable): failed_tasks_filter.add_action(without_failed_tasks_action) self.add_filter(failed_tasks_filter) - def post(self, request, *args, **kwargs): - """ Process HTTP POSTs which make build requests """ - - project = Project.objects.get(pk=kwargs['pid']) - - if 'buildCancel' in request.POST: - for i in request.POST['buildCancel'].strip().split(" "): - try: - br = BuildRequest.objects.select_for_update().get(project = project, pk = i, state__lte = BuildRequest.REQ_QUEUED) - br.state = BuildRequest.REQ_DELETED - br.save() - except BuildRequest.DoesNotExist: - pass - - if 'buildDelete' in request.POST: - for i in request.POST['buildDelete'].strip().split(" "): - try: - BuildRequest.objects.select_for_update().get(project = project, pk = i, state__lte = BuildRequest.REQ_DELETED).delete() - except BuildRequest.DoesNotExist: - pass - - if 'targets' in request.POST: - ProjectTarget.objects.filter(project = project).delete() - s = str(request.POST['targets']) - for t in s.translate(None, ";%|\"").split(" "): - if ":" in t: - target, task = t.split(":") - else: - target = t - task = "" - ProjectTarget.objects.create(project = project, - target = target, - task = task) - project.schedule_build() - - # redirect back to builds page so any new builds in progress etc. - # are visible - response = HttpResponse() - response.status_code = 302 - response['Location'] = request.build_absolute_uri() - return response class AllBuildsTable(BuildsTable): """ Builds page for all builds """ diff --git a/bitbake/lib/toaster/toastergui/urls.py b/bitbake/lib/toaster/toastergui/urls.py index 4aa6488..78cc3bd 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 from django.http import HttpResponseBadRequest from toastergui import tables from toastergui import typeaheads +from toastergui import api urlpatterns = patterns('toastergui.views', # landing page @@ -180,6 +181,10 @@ urlpatterns = patterns('toastergui.views', url(r'^xhr_customrecipe/', 'xhr_customrecipe', name='xhr_customrecipe'), + url(r'^xhr_buildrequest/project/(?P\d+)$', + api.XhrBuildRequest.as_view(), + name='xhr_buildrequest'), + # default redirection url(r'^$', RedirectView.as_view(url='landing', permanent=True)), ) -- 2.1.4