toaster: Add distro selection support
PATCH 1/1 toaster: Add distro selection support
From: David Reyna <[email protected]>
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]
Signed-off-by David Reyna <[email protected]>
--- .../toaster/orm/management/commands/lsupdates.py | 19 +++++ .../toaster/orm/migrations/0016_clone_progress.py | 24 ------ .../toaster/orm/migrations/0016_distro_clone.py | 35 +++++++++ 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 ++ 13 files changed, 335 insertions(+), 27 deletions(-) delete mode 100644 bitbake/lib/toaster/orm/migrations/0016_clone_progress.py create mode 100644 bitbake/lib/toaster/orm/migrations/0016_distro_clone.py create mode 100644 bitbake/lib/toaster/toastergui/templates/distro_btn.html
bitbake/lib/toaster/orm/management/commands/lsupdates.py +19 -0
@@ -23,6 +23,7 @@ from django.core.management.base import NoArgsCommand 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(NoArgsCommand): 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(
bitbake/lib/toaster/orm/migrations/0016_clone_progress.py deleted +0 -24
@@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import migrations, models - -class Migration(migrations.Migration): - - dependencies = [ - ('orm', '0015_layer_local_source_dir'), - ] - - operations = [ - migrations.AddField( - model_name='build', - name='repos_cloned', - field=models.IntegerField(default=0), - ), - migrations.AddField( - model_name='build', - name='repos_to_clone', - field=models.IntegerField(default=1), - ), - ] -
bitbake/lib/toaster/orm/migrations/0016_distro_clone.py new file +35 -0
@@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + +class Migration(migrations.Migration): + + dependencies = [ + ('orm', '0015_layer_local_source_dir'), + ] + + 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')), + ], + ), + migrations.AddField( + model_name='build', + name='repos_cloned', + field=models.IntegerField(default=0), + ), + migrations.AddField( + model_name='build', + name='repos_to_clone', + field=models.IntegerField(default=1), + ), + ] +
bitbake/lib/toaster/orm/models.py +31 -0
@@ -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)
bitbake/lib/toaster/toastergui/api.py +10 -3
@@ -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"
bitbake/lib/toaster/toastergui/static/js/projectpage.js +73 -0
97 lines not on this page · raw message
bitbake/lib/toaster/toastergui/tables.py +91 -0
100 lines not on this page · raw message
bitbake/lib/toaster/toastergui/templates/base.html +1 -0
@@ -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}},
bitbake/lib/toaster/toastergui/templates/baseprojectpage.html +1 -0
@@ -32,6 +32,7 @@ $(document).ready(function(){ <li><a href="{% url 'projectsoftwarerecipes' project.id %}">Software recipes</a></li> <li><a href="{% url 'projectmachines' project.id %}">Machines</a></li> <li><a href="{% url 'projectlayers' project.id %}">Layers</a></li> + <li><a href="{% url 'projectdistros' project.id %}">Distros</a></li> <li class="nav-header">Extra configuration</li> <li><a href="{% url 'projectconf' project.id %}">BitBake variables</a></li>
bitbake/lib/toaster/toastergui/templates/distro_btn.html new file +20 -0
@@ -0,0 +1,20 @@ +<a href="{% url 'project' extra.pid %}?setDistro={{data.name}}" class="btn btn-default btn-block layer-exists-{{data.layer_version.id}}" + {% if data.layer_version.pk not in extra.current_layers %} + style="display:none;" + {% endif %}> + Set distro</a> +<a class="btn btn-default btn-block layerbtn layer-add-{{data.layer_version.id}}" data-layer='{ + "id": {{data.layer_version.id}}, + "name": "{{data.layer_version.layer.name}}", + "xhrLayerUrl": "{% url "xhr_layer" extra.pid data.pk %}", + "layerdetailurl": "{%url 'layerdetails' extra.pid data.layer_version.id %}" + }' data-directive="add" + {% if data.layer_version.pk in extra.current_layers %} + style="display:none;" + {% endif %} +> + <span class="glyphicon glyphicon-plus"></span> + Add layer + <span class="glyphicon glyphicon-question-sign get-help" title="To select this distro, you must first add the {{data.layer_version.layer.name}} layer to your project"></i> +</a> +
bitbake/lib/toaster/toastergui/templates/project.html +16 -0
@@ -77,6 +77,22 @@ </form> </div> + <div class="well well-transparent" id="distro-section"> + <h3>Distro</h3> + + <p class="lead"><span id="project-distro-name"></span> <span class="glyphicon glyphicon-edit" id="change-distro-toggle"></span></p> + + <form id="select-distro-form" style="display:none;" class="form-inline"> + <span class="help-block">Distro suggestions come from the Layer Index</a></span> + <div class="form-group"> + <input class="form-control" id="distro-change-input" autocomplete="off" value="" data-provide="typeahead" data-minlength="1" data-autocomplete="off" type="text"> + </div> + <button id="distro-change-btn" class="btn btn-default" type="button">Save</button> + <a href="#" id="cancel-distro-change" class="btn btn-link">Cancel</a> + <p class="form-link"><a href="{% url 'projectdistros' project.id %}">View compatible distros</a></p> + </form> + </div> + <div class="well well-transparent"> <h3>Most built recipes</h3>
bitbake/lib/toaster/toastergui/typeaheads.py +30 -0
@@ -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 """
bitbake/lib/toaster/toastergui/urls.py +8 -0
@@ -157,6 +157,11 @@ urlpatterns = patterns('toastergui.views', name=tables.LayerMachinesTable.__name__.lower()), + url(r'^project/(?P<pid>\d+)/distros/$', + tables.DistrosTable.as_view(template_name="generic-toastertable-page.html"), + name="projectdistros"), + + url(r'^project/(?P<pid>\d+)/customrecipe/(?P<custrecipeid>\d+)/selectpackages/$', tables.SelectPackagesTable.as_view(), name="recipeselectpackages"),
@@ -186,6 +191,9 @@ urlpatterns = patterns('toastergui.views', typeaheads.GitRevisionTypeAhead.as_view(), name='xhr_gitrevtypeahead'), + url(r'^xhr_typeahead/(?P<pid>\d+)/distros$', + typeaheads.DistrosTypeAhead.as_view(), name='xhr_distrostypeahead'), + url(r'^xhr_testreleasechange/(?P<pid>\d+)$', 'xhr_testreleasechange', name='xhr_testreleasechange'), url(r'^xhr_configvaredit/(?P<pid>\d+)$', 'xhr_configvaredit',
Signature · 1 line
1.9.1