Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id CE3FEE00D68; Fri, 9 Dec 2016 08:29:59 -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,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no * trust * [74.125.82.43 listed in list.dnswl.org] * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily * valid * -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Received: from mail-wm0-f43.google.com (mail-wm0-f43.google.com [74.125.82.43]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id 2C5F1E00D5A for ; Fri, 9 Dec 2016 08:29:56 -0800 (PST) Received: by mail-wm0-f43.google.com with SMTP id a197so31784326wmd.0 for ; Fri, 09 Dec 2016 08:29:56 -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=Mm3ffwdcMoQuZ4u/1nEMMgOPnvBhPnrOP4QPBOvWo6A=; b=eFgAcyENxeCN/b/wF/RVlkOCZnv/HDRPzYm0dvtIpJ+aZwDX3hxVbQZH9G8aPkkwRa jHEIik72eTB10zEsXS74dHC2Ev35PEg8ZXJNdMd94v7DDn3KkFYsWqwOrZmsjZ+0/g0p Q6YErQx1q6sP0WdRzf50d2y34etiM8czL3Uq8/Xx2OIv616DCHj3ErtFlZJLeqXi8BVw nev6SnzdwmEVbYg9I/6aItRqrJ6YbOocfxVCDjaOrq0lDlQZWdF6UIeLkyHX0LwUmd0n kD1MR2huecUJAQLFHXFELBvylOmO7UF+dgrWYyE4Lvbesvo+IgMaS3vV3B9ScSfEKOy3 3ikQ== 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=Mm3ffwdcMoQuZ4u/1nEMMgOPnvBhPnrOP4QPBOvWo6A=; b=NqmJwtsA6zLg3o5W9Ybk5mbamRl3GLxl1baWR1zs+7Y4PJgBLexwsUdbBGHymSD7rr GkznN7+gC+Stkv6drD5baFwXUhs3oNAdcYr13qSHrbSonnuH7ebuqlCbKCMSVYe0tc4W 4cnXHmdDABF8gl0NurHqdujW/H0T7iZfNMg1LUwqFSe2+gOra/MV8FugmvSiF3Z8iwJZ +qtWOWfZdLLMHzNSe1Uq5HoqvZ3N0C/bB8uGl7KTEkuBxDUaToB7C/VAmaVQwzpYodcF KCC/az/wWnovXa+l9GKh5SdtLuYiUt1DBEzByIjE56SgXY+Bk/YNURilRwmt3o/f7mdb CI+g== X-Gm-Message-State: AKaTC02KlgDeOingv+l8kkWuS0EW9OsvNHRY/D/xOlrXI1glRnlQYU1e6xa/4OdGVtRHJ+jd X-Received: by 10.28.72.198 with SMTP id v189mr7963527wma.13.1481300995594; Fri, 09 Dec 2016 08:29:55 -0800 (PST) Received: from localhost.localdomain ([192.198.151.62]) by smtp.gmail.com with ESMTPSA id x5sm43051348wje.36.2016.12.09.08.29.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Dec 2016 08:29:55 -0800 (PST) From: Michael Wood To: toaster@yoctoproject.org Date: Fri, 9 Dec 2016 16:29:39 +0000 Message-Id: <1481300985-7356-9-git-send-email-michael.g.wood@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1481300985-7356-1-git-send-email-michael.g.wood@intel.com> References: <1481300985-7356-1-git-send-email-michael.g.wood@intel.com> Subject: [PATCH 08/14] toaster: typeaheads Add a git revisions suggestions 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: Fri, 09 Dec 2016 16:29:59 -0000 When we're importing a layer it's useful to suggest available git revisions of the layers. This uses git ls-remote to fetch the revisions and then filter on this. Caching is added for this typeahead to avoid having to fetch this information multiple times in a single session. [YOCTO #8429] Signed-off-by: Michael Wood --- bitbake/lib/toaster/toastergui/typeaheads.py | 29 ++++++++++++++++++++++++++++ bitbake/lib/toaster/toastergui/urls.py | 5 +++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/bitbake/lib/toaster/toastergui/typeaheads.py b/bitbake/lib/toaster/toastergui/typeaheads.py index 2c6c145..5316000 100644 --- a/bitbake/lib/toaster/toastergui/typeaheads.py +++ b/bitbake/lib/toaster/toastergui/typeaheads.py @@ -16,9 +16,12 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +import subprocess + from toastergui.widgets import ToasterTypeAhead from orm.models import Project from django.core.urlresolvers import reverse +from django.core.cache import cache class LayersTypeAhead(ToasterTypeAhead): """ Typeahead for layers available and not added in the current project's @@ -147,3 +150,29 @@ class ProjectsTypeAhead(ToasterTypeAhead): results.append(needed_fields) return results + + +class GitRevisionTypeAhead(ToasterTypeAhead): + def apply_search(self, search_term, prj, request): + results = [] + git_url = request.GET.get('git_url') + ls_remote = cache.get(git_url) + + if ls_remote is None: + ls_remote = subprocess.check_output(['git', 'ls-remote', git_url], + universal_newlines=True) + ls_remote = ls_remote.splitlines() + # Avoid fetching the list of git refs on each new input + cache.set(git_url, ls_remote, 120) + + for rev in ls_remote: + git_rev = str(rev).split("/")[-1:][0] + # "HEAD" has a special meaning in Toaster... YOCTO #9924 + if "HEAD" in git_rev: + continue + + if git_rev.startswith(search_term): + results.append({'name': git_rev, + 'detail': '[ %s ]' % str(rev)}) + + return results diff --git a/bitbake/lib/toaster/toastergui/urls.py b/bitbake/lib/toaster/toastergui/urls.py index 29f0d96..d92f190 100644 --- a/bitbake/lib/toaster/toastergui/urls.py +++ b/bitbake/lib/toaster/toastergui/urls.py @@ -182,8 +182,9 @@ urlpatterns = patterns('toastergui.views', typeaheads.RecipesTypeAhead.as_view(), name='xhr_recipestypeahead'), url(r'^xhr_typeahead/projects$', typeaheads.ProjectsTypeAhead.as_view(), name='xhr_projectstypeahead'), - - + url(r'^xhr_typeahead/gitrev$', + typeaheads.GitRevisionTypeAhead.as_view(), + name='xhr_gitrevtypeahead'), url(r'^xhr_testreleasechange/(?P\d+)$', 'xhr_testreleasechange', name='xhr_testreleasechange'), -- 2.7.4