From 4f2baebf362d71351db044c0646f9bc6e8a39c49 Mon Sep 17 00:00:00 2001 From: David Reyna Date: Tue, 27 Jun 2017 13:44:30 -0700 Subject: bitbake: toaster: Add distro selection support Add the ability to select a distro in the project page, based on values from the Layer Index. Add a distro selection page with the add layer feature, based on the add machine page. [YOCTO #10632] (Bitbake rev: a156a4eff67cdc3943494f5be72b96e3db656250) Signed-off-by: David Reyna Signed-off-by: Richard Purdie --- .../toaster/orm/management/commands/lsupdates.py | 19 +++++ .../toaster/orm/migrations/0017_distro_clone.py | 25 ++++++ bitbake/lib/toaster/orm/models.py | 31 ++++++++ bitbake/lib/toaster/toastergui/api.py | 13 +++- .../toaster/toastergui/static/js/projectpage.js | 73 +++++++++++++++++ bitbake/lib/toaster/toastergui/tables.py | 91 ++++++++++++++++++++++ bitbake/lib/toaster/toastergui/templates/base.html | 1 + .../toastergui/templates/baseprojectpage.html | 1 + .../toaster/toastergui/templates/distro_btn.html | 20 +++++ .../lib/toaster/toastergui/templates/project.html | 16 ++++ bitbake/lib/toaster/toastergui/typeaheads.py | 30 +++++++ bitbake/lib/toaster/toastergui/urls.py | 8 ++ 12 files changed, 325 insertions(+), 3 deletions(-) create mode 100644 bitbake/lib/toaster/orm/migrations/0017_distro_clone.py create mode 100644 bitbake/lib/toaster/toastergui/templates/distro_btn.html (limited to 'bitbake') diff --git a/bitbake/lib/toaster/orm/management/commands/lsupdates.py b/bitbake/lib/toaster/orm/management/commands/lsupdates.py index 90f07c9dc5..0b0d4ff8f9 100644 --- a/bitbake/lib/toaster/orm/management/commands/lsupdates.py +++ b/bitbake/lib/toaster/orm/management/commands/lsupdates.py @@ -23,6 +23,7 @@ from django.core.management.base import BaseCommand from orm.models import LayerSource, Layer, Release, Layer_Version from orm.models import LayerVersionDependency, Machine, Recipe +from orm.models import Distro import os import sys @@ -249,6 +250,24 @@ class Command(BaseCommand): depends_on=lvd) self.mini_progress("Layer version dependencies", i, total) + # update Distros + logger.info("Fetching distro information") + distros_info = _get_json_response( + apilinks['distros'] + "?filter=layerbranch__branch__name:%s" % + "OR".join(whitelist_branch_names)) + + total = len(distros_info) + for i, di in enumerate(distros_info): + distro, created = Distro.objects.get_or_create( + name=di['name'], + layer_version=Layer_Version.objects.get( + pk=li_layer_branch_id_to_toaster_lv_id[di['layerbranch']])) + distro.up_date = di['updated'] + distro.name = di['name'] + distro.description = di['description'] + distro.save() + self.mini_progress("distros", i, total) + # update machines logger.info("Fetching machine information") machines_info = _get_json_response( diff --git a/bitbake/lib/toaster/orm/migrations/0017_distro_clone.py b/bitbake/lib/toaster/orm/migrations/0017_distro_clone.py new file mode 100644 index 0000000000..d3c5901275 --- /dev/null +++ b/bitbake/lib/toaster/orm/migrations/0017_distro_clone.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + +class Migration(migrations.Migration): + + dependencies = [ + ('orm', '0016_clone_progress'), + ] + + operations = [ + migrations.CreateModel( + name='Distro', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('up_id', models.IntegerField(default=None, null=True)), + ('up_date', models.DateTimeField(default=None, null=True)), + ('name', models.CharField(max_length=255)), + ('description', models.CharField(max_length=255)), + ('layer_version', models.ForeignKey(to='orm.Layer_Version')), + ], + ), + ] + diff --git a/bitbake/lib/toaster/orm/models.py b/bitbake/lib/toaster/orm/models.py index 13bd11704a..5c14727a70 100644 --- a/bitbake/lib/toaster/orm/models.py +++ b/bitbake/lib/toaster/orm/models.py @@ -321,6 +321,22 @@ class Project(models.Model): return queryset + def get_available_distros(self): + """ Returns QuerySet of all Distros which are provided by the + Layers currently added to the Project """ + queryset = Distro.objects.filter( + layer_version__in=self.get_project_layer_versions()) + + return queryset + + def get_all_compatible_distros(self): + """ Returns QuerySet of all the compatible Wind River distros available to the + project including ones from Layers not currently added """ + queryset = Distro.objects.filter( + layer_version__in=self.get_all_compatible_layer_versions()) + + return queryset + def get_available_recipes(self): """ Returns QuerySet of all the recipes that are provided by layers added to this project """ @@ -1795,6 +1811,21 @@ def signal_runbuilds(): except FileNotFoundError: logger.info("Stopping existing runbuilds: no current process found") +class Distro(models.Model): + search_allowed_fields = ["name", "description", "layer_version__layer__name"] + up_date = models.DateTimeField(null = True, default = None) + + layer_version = models.ForeignKey('Layer_Version') + name = models.CharField(max_length=255) + description = models.CharField(max_length=255) + + def get_vcs_distro_file_link_url(self): + path = self.name+'.conf' + return self.layer_version.get_vcs_file_link_url(path) + + def __unicode__(self): + return "Distro " + self.name + "(" + self.description + ")" + django.db.models.signals.post_save.connect(invalidate_cache) django.db.models.signals.post_delete.connect(invalidate_cache) django.db.models.signals.m2m_changed.connect(invalidate_cache) diff --git a/bitbake/lib/toaster/toastergui/api.py b/bitbake/lib/toaster/toastergui/api.py index 5b035505c2..88d6aa7f68 100644 --- a/bitbake/lib/toaster/toastergui/api.py +++ b/bitbake/lib/toaster/toastergui/api.py @@ -874,6 +874,12 @@ class XhrProject(View): machinevar.value = request.POST['machineName'] machinevar.save() + # Distro name change + if 'distroName' in request.POST: + distrovar = prj.projectvariable_set.get(name="DISTRO") + distrovar.value = request.POST['distroName'] + distrovar.save() + return JsonResponse({"error": "ok"}) def get(self, request, *args, **kwargs): @@ -960,10 +966,11 @@ class XhrProject(View): except ProjectVariable.DoesNotExist: data["machine"] = None try: - data["distro"] = project.projectvariable_set.get( - name="DISTRO").value + data["distro"] = {"name": + project.projectvariable_set.get( + name="DISTRO").value} except ProjectVariable.DoesNotExist: - data["distro"] = "-- not set yet" + data["distro"] = None data['error'] = "ok" diff --git a/bitbake/lib/toaster/toastergui/static/js/projectpage.js b/bitbake/lib/toaster/toastergui/static/js/projectpage.js index 21adf816c6..506471e091 100644 --- a/bitbake/lib/toaster/toastergui/static/js/projectpage.js +++ b/bitbake/lib/toaster/toastergui/static/js/projectpage.js @@ -15,6 +15,13 @@ function projectPageInit(ctx) { var machineInputForm = $("#machine-input-form"); var invalidMachineNameHelp = $("#invalid-machine-name-help"); + var distroChangeInput = $("#distro-change-input"); + var distroChangeBtn = $("#distro-change-btn"); + var distroForm = $("#select-distro-form"); + var distroChangeFormToggle = $("#change-distro-toggle"); + var distroNameTitle = $("#project-distro-name"); + var distroChangeCancel = $("#cancel-distro-change"); + var freqBuildBtn = $("#freq-build-btn"); var freqBuildList = $("#freq-build-list"); @@ -26,6 +33,7 @@ function projectPageInit(ctx) { var currentLayerAddSelection; var currentMachineAddSelection = ""; + var currentDistroAddSelection = ""; var urlParams = libtoaster.parseUrlParams(); @@ -45,6 +53,17 @@ function projectPageInit(ctx) { updateMachineName(prjInfo.machine.name); } + /* If we're receiving a distro set from the url and it's different from + * our current distro then activate set machine sequence. + */ + if (urlParams.hasOwnProperty('setDistro') && + urlParams.setDistro !== prjInfo.distro.name){ + distroChangeInput.val(urlParams.setDistro); + distroChangeBtn.click(); + } else { + updateDistroName(prjInfo.distro.name); + } + /* Now we're really ready show the page */ $("#project-page").show(); @@ -278,6 +297,60 @@ function projectPageInit(ctx) { }); + /* Change distro functionality */ + + distroChangeFormToggle.click(function(){ + distroForm.slideDown(); + distroNameTitle.hide(); + $(this).hide(); + }); + + distroChangeCancel.click(function(){ + distroForm.slideUp(function(){ + distroNameTitle.show(); + distroChangeFormToggle.show(); + }); + }); + + function updateDistroName(distroName){ + distroChangeInput.val(distroName); + distroNameTitle.text(distroName); + } + + libtoaster.makeTypeahead(distroChangeInput, + libtoaster.ctx.distrosTypeAheadUrl, + { }, function(item){ + currentDistroAddSelection = item.name; + distroChangeBtn.removeAttr("disabled"); + }); + + distroChangeBtn.click(function(e){ + e.preventDefault(); + /* We accept any value regardless of typeahead selection or not */ + if (distroChangeInput.val().length === 0) + return; + + currentDistroAddSelection = distroChangeInput.val(); + + libtoaster.editCurrentProject( + { distroName : currentDistroAddSelection }, + function(){ + /* Success machine changed */ + updateDistroName(currentDistroAddSelection); + distroChangeCancel.click(); + + /* Show the alert message */ + var message = $('You have changed the distro to: '); + message.find("#notify-machine-name").text(currentDistroAddSelection); + libtoaster.showChangeNotification(message); + }, + function(){ + /* Failed machine changed */ + console.warn("Failed to change distro"); + }); + }); + + /* Change release functionality */ function updateProjectRelease(release){ releaseTitle.text(release.description); diff --git a/bitbake/lib/toaster/toastergui/tables.py b/bitbake/lib/toaster/toastergui/tables.py index e2d23c1e81..dca2fa2913 100644 --- a/bitbake/lib/toaster/toastergui/tables.py +++ b/bitbake/lib/toaster/toastergui/tables.py @@ -23,6 +23,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, Package_DependencyManager +from orm.models import Distro 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 @@ -1536,3 +1537,93 @@ class ProjectBuildsTable(BuildsTable): context['build_in_progress_none_completed'] = False return context + + +class DistrosTable(ToasterTable): + """Table of Distros in Toaster""" + + def __init__(self, *args, **kwargs): + super(DistrosTable, self).__init__(*args, **kwargs) + self.empty_state = "Toaster has no distro information for this project. Sadly, distro information cannot be obtained from builds, so this page will remain empty." + self.title = "Compatible Distros" + self.default_orderby = "name" + + def get_context_data(self, **kwargs): + context = super(DistrosTable, self).get_context_data(**kwargs) + context['project'] = Project.objects.get(pk=kwargs['pid']) + return context + + def setup_filters(self, *args, **kwargs): + project = Project.objects.get(pk=kwargs['pid']) + + in_current_project_filter = TableFilter( + "in_current_project", + "Filter by project Distros" + ) + + in_project_action = TableFilterActionToggle( + "in_project", + "Distro provided by layers added to this project", + ProjectFilters.in_project(self.project_layers) + ) + + not_in_project_action = TableFilterActionToggle( + "not_in_project", + "Distros provided by layers not added to this project", + ProjectFilters.not_in_project(self.project_layers) + ) + + in_current_project_filter.add_action(in_project_action) + in_current_project_filter.add_action(not_in_project_action) + self.add_filter(in_current_project_filter) + + def setup_queryset(self, *args, **kwargs): + prj = Project.objects.get(pk = kwargs['pid']) + self.queryset = prj.get_all_compatible_distros() + self.queryset = self.queryset.order_by(self.default_orderby) + + self.static_context_extra['current_layers'] = \ + self.project_layers = \ + prj.get_project_layer_versions(pk=True) + + def setup_columns(self, *args, **kwargs): + + self.add_column(title="Distro", + hideable=False, + orderable=True, + field_name="name") + + self.add_column(title="Description", + field_name="description") + + layer_link_template = ''' + + {{data.layer_version.layer.name}} + ''' + + self.add_column(title="Layer", + static_data_name="layer_version__layer__name", + static_data_template=layer_link_template, + orderable=True) + + self.add_column(title="Git revision", + help_text="The Git branch, tag or commit. For the layers from the OpenEmbedded layer source, the revision is always the branch compatible with the Yocto Project version you selected for this project", + hidden=True, + field_name="layer_version__get_vcs_reference") + + wrtemplate_file_template = '''conf/machine/{{data.name}}.conf + ''' + + self.add_column(title="Distro file", + hidden=True, + static_data_name="templatefile", + static_data_template=wrtemplate_file_template) + + + self.add_column(title="Select", + help_text="Sets the selected distro to the project", + hideable=False, + filter_name="in_current_project", + static_data_name="add-del-layers", + static_data_template='{% include "distro_btn.html" %}') + diff --git a/bitbake/lib/toaster/toastergui/templates/base.html b/bitbake/lib/toaster/toastergui/templates/base.html index 11c6f91260..0fbe17b5d8 100644 --- a/bitbake/lib/toaster/toastergui/templates/base.html +++ b/bitbake/lib/toaster/toastergui/templates/base.html @@ -49,6 +49,7 @@ recipesTypeAheadUrl: {% url 'xhr_recipestypeahead' project.id as paturl%}{{paturl|json}}, layersTypeAheadUrl: {% url 'xhr_layerstypeahead' project.id as paturl%}{{paturl|json}}, machinesTypeAheadUrl: {% url 'xhr_machinestypeahead' project.id as paturl%}{{paturl|json}}, + distrosTypeAheadUrl: {% url 'xhr_distrostypeahead' project.id as paturl%}{{paturl|json}}, projectBuildsUrl: {% url 'projectbuilds' project.id as pburl %}{{pburl|json}}, xhrCustomRecipeUrl : "{% url 'xhr_customrecipe' %}", projectId : {{project.id}}, diff --git a/bitbake/lib/toaster/toastergui/templates/baseprojectpage.html b/bitbake/lib/toaster/toastergui/templates/baseprojectpage.html index 8427d25210..f2bb2ebf63 100644 --- a/bitbake/lib/toaster/toastergui/templates/baseprojectpage.html +++ b/bitbake/lib/toaster/toastergui/templates/baseprojectpage.html @@ -32,6 +32,7 @@ $(document).ready(function(){
  • Software recipes
  • Machines
  • Layers
  • +
  • Distros
  • BitBake variables
  • diff --git a/bitbake/lib/toaster/toastergui/templates/distro_btn.html b/bitbake/lib/toaster/toastergui/templates/distro_btn.html new file mode 100644 index 0000000000..fac79472cc --- /dev/null +++ b/bitbake/lib/toaster/toastergui/templates/distro_btn.html @@ -0,0 +1,20 @@ + + + diff --git a/bitbake/lib/toaster/toastergui/templates/project.html b/bitbake/lib/toaster/toastergui/templates/project.html index ab7e665b64..11603d1e12 100644 --- a/bitbake/lib/toaster/toastergui/templates/project.html +++ b/bitbake/lib/toaster/toastergui/templates/project.html @@ -77,6 +77,22 @@ +
    +

    Distro

    + +

    + + +
    +

    Most built recipes

    diff --git a/bitbake/lib/toaster/toastergui/typeaheads.py b/bitbake/lib/toaster/toastergui/typeaheads.py index 58c650f8fc..5aa0f8d889 100644 --- a/bitbake/lib/toaster/toastergui/typeaheads.py +++ b/bitbake/lib/toaster/toastergui/typeaheads.py @@ -100,6 +100,36 @@ class MachinesTypeAhead(ToasterTypeAhead): return results +class DistrosTypeAhead(ToasterTypeAhead): + """ Typeahead for all the distros available in the current project's + configuration """ + def __init__(self): + super(DistrosTypeAhead, self).__init__() + + def apply_search(self, search_term, prj, request): + distros = prj.get_available_distros() + distros = distros.order_by("name") + + primary_results = distros.filter(name__istartswith=search_term) + secondary_results = distros.filter(name__icontains=search_term).exclude(pk__in=primary_results) + tertiary_results = distros.filter(layer_version__layer__name__icontains=search_term).exclude(pk__in=primary_results).exclude(pk__in=secondary_results) + + results = [] + + for distro in list(primary_results) + list(secondary_results) + list(tertiary_results): + + detail = "[ %s ]" % (distro.layer_version.layer.name) + needed_fields = { + 'id' : distro.pk, + 'name' : distro.name, + 'detail' : detail, + } + + results.append(needed_fields) + + return results + + class RecipesTypeAhead(ToasterTypeAhead): """ Typeahead for all the recipes available in the current project's configuration """ diff --git a/bitbake/lib/toaster/toastergui/urls.py b/bitbake/lib/toaster/toastergui/urls.py index 1ad79a4dd3..6aebc3f833 100644 --- a/bitbake/lib/toaster/toastergui/urls.py +++ b/bitbake/lib/toaster/toastergui/urls.py @@ -158,6 +158,11 @@ urlpatterns = [ name=tables.LayerMachinesTable.__name__.lower()), + url(r'^project/(?P\d+)/distros/$', + tables.DistrosTable.as_view(template_name="generic-toastertable-page.html"), + name="projectdistros"), + + url(r'^project/(?P\d+)/customrecipe/(?P\d+)/selectpackages/$', tables.SelectPackagesTable.as_view(), name="recipeselectpackages"), @@ -187,6 +192,9 @@ urlpatterns = [ typeaheads.GitRevisionTypeAhead.as_view(), name='xhr_gitrevtypeahead'), + url(r'^xhr_typeahead/(?P\d+)/distros$', + typeaheads.DistrosTypeAhead.as_view(), name='xhr_distrostypeahead'), + url(r'^xhr_testreleasechange/(?P\d+)$', views.xhr_testreleasechange, name='xhr_testreleasechange'), url(r'^xhr_configvaredit/(?P\d+)$', views.xhr_configvaredit, -- cgit v1.2.3-54-g00ecf