Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id 9C57EE0070F; Thu, 1 Dec 2016 08:45:46 -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 * [209.85.210.171 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-wj0-f171.google.com (mail-wj0-f171.google.com [209.85.210.171]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id E1F85E0070F for ; Thu, 1 Dec 2016 08:45:44 -0800 (PST) Received: by mail-wj0-f171.google.com with SMTP id v7so209654005wjy.2 for ; Thu, 01 Dec 2016 08:45:44 -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=dYA1hnnxMqIhk8oOTls/7mrXNq5nJgM19WS9NpFz42fWJ4XEkctHvPpvdndmIIpIAE K3qJavcd41zkW45g1vXCr9vLvCLgnqYcNQPI9MNZYmIQUNQtfdI7QP+adUu7UIulY3e+ sdZgb4bF/mwck7x4AdbDN4FcAoPD9RH+LrsVDhKa6SmK/wg/0IU6E/SsVntugAUGHbOo 9DWyAGUwIaWNlJCECN3SAO6JHbO4Il/nZ+SYzWxlOtpx54/1rUxEorM3078wLccdxtXl O2lmgZYyR7VItLo3CtWGLadpXwD8C+wh49cmenEOTAVHvuU3QoVFyuW33uVv2Lql1CGy WcOA== 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=gbRjJ8UOTgp0OzHlNaEhxHKm+PdvOuXsnpewOQa8mrnNiam1wFSNlz0+X0uMldGQW2 GhQJyrXQ4wBkESDQ1Uu/SpRtUjh/sgqhcdsufPKmCq/ELvIiA6tYHt/ypAj657KTN7nY 1ZoQDX5uvydXZahGqOPgyx7mBaPLXYsHdY9zYsC7yDfAx4hLriDd9623FD2qBXEG2e9p TyHO2QnS43G5wES871bmaIvYedinFKw+DAUzZcRI7MTBLLx9RKdPmvmDpUIUV0Zb+EaG viNFS9uLyUnQ0C5P7J0+pjVKi3hEnOtYNhftCH60IiWkVtc2sF96TzTmTeKaJjmrQ7j9 2nRg== X-Gm-Message-State: AKaTC00vf6mjlmNrDT+dlPjrrAU7U5pI8PHYgX/mNRBjm/4ZoeR6tMFOJQoavfmaX5kPk3Ag X-Received: by 10.194.164.226 with SMTP id yt2mr39420933wjb.201.1480610743334; Thu, 01 Dec 2016 08:45:43 -0800 (PST) Received: from localhost.localdomain ([192.198.151.62]) by smtp.gmail.com with ESMTPSA id 14sm1801422wmk.1.2016.12.01.08.45.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Dec 2016 08:45:42 -0800 (PST) From: Michael Wood To: toaster@yoctoproject.org Date: Thu, 1 Dec 2016 16:45:32 +0000 Message-Id: <1480610733-11839-2-git-send-email-michael.g.wood@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1480610733-11839-1-git-send-email-michael.g.wood@intel.com> References: <1480610733-11839-1-git-send-email-michael.g.wood@intel.com> Subject: [PATCH 2/3] 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: Thu, 01 Dec 2016 16:45:46 -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