[gnome-continuous-yocto/gnomeostree-3.28-rocko: 3649/8267] bitbake: toaster: typeaheads Add a git revisions suggestions
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-continuous-yocto/gnomeostree-3.28-rocko: 3649/8267] bitbake: toaster: typeaheads Add a git revisions suggestions
- Date: Sun, 17 Dec 2017 00:55:48 +0000 (UTC)
commit 97ff2c0091c654bf01bc4b0809a6a664ad6c579c
Author: Michael Wood <michael g wood intel com>
Date: Fri Dec 9 16:52:49 2016 +0000
bitbake: toaster: typeaheads Add a git revisions suggestions
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]
(Bitbake rev: a94ae3ad0cb07a52004143c6f86f371b9e330e9f)
Signed-off-by: Michael Wood <michael g wood intel com>
Signed-off-by: Richard Purdie <richard purdie linuxfoundation org>
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<pid>\d+)$', 'xhr_testreleasechange',
name='xhr_testreleasechange'),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]