# # ex:ts=4:sw=4:sts=4:et # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- # # BitBake Toaster Implementation # # Copyright (C) 2016 Intel Corporation # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. from orm.models import Build, Task, Target, Package from django.db.models import Q, Sum import toastergui.tables as tables from toastergui.widgets import ToasterTable from toastergui.tablefilter import TableFilter from toastergui.tablefilter import TableFilterActionToggle class BuildTablesMixin(ToasterTable): def get_context_data(self, **kwargs): # We need to be explicit about which superclass we're calling here # Otherwise the MRO gets in a right mess context = ToasterTable.get_context_data(self, **kwargs) context['build'] = Build.objects.get(pk=kwargs['build_id']) return context class BuiltPackagesTableBase(tables.PackagesTable): """ Table to display all the packages built in a build """ def __init__(self, *args, **kwargs): super(BuiltPackagesTableBase, self).__init__(*args, **kwargs) self.title = "Packages built" self.default_orderby = "name" def setup_queryset(self, *args, **kwargs): build = Build.objects.get(pk=kwargs['build_id']) self.static_context_extra['build'] = build self.static_context_extra['target_name'] = None self.queryset = build.package_set.all().exclude(recipe=None) self.queryset = self.queryset.order_by(self.default_orderby) def setup_columns(self, *args, **kwargs): super(BuiltPackagesTableBase, self).setup_columns(*args, **kwargs) def pkg_link_template(val): """ return the template used for the link with the val as the element value i.e. inside the """ return (''' %s ''' % val) def recipe_link_template(val): return (''' {%% if data.recipe %%} %(value)s {%% else %%} %(value)s {%% endif %%} ''' % {'value': val}) add_pkg_link_to = 'name' add_recipe_link_to = 'recipe__name' # Add the recipe and pkg build links to the required columns for column in self.columns: # Convert to template field style accessors tmplv = column['field_name'].replace('__', '.') tmplv = "{{data.%s}}" % tmplv if column['field_name'] is add_pkg_link_to: # Don't overwrite an existing template if column['static_data_template']: column['static_data_template'] =\ pkg_link_template(column['static_data_template']) else: column['static_data_template'] = pkg_link_template(tmplv) column['static_data_name'] = column['field_name'] elif column['field_name'] is add_recipe_link_to: # Don't overwrite an existing template if column['static_data_template']: column['static_data_template'] =\ recipe_link_template(column['static_data_template']) else: column['static_data_template'] =\ recipe_link_template(tmplv) column['static_data_name'] = column['field_name'] self.add_column(title="Layer", field_name="recipe__layer_version__layer__name", hidden=True, orderable=True) layer_branch_template = ''' {%if not data.recipe.layer_version.layer.local_source_dir %} {{data.recipe.layer_version.branch}} {% else %} Not applicable {% endif %} ''' self.add_column(title="Layer branch", field_name="recipe__layer_version__branch", hidden=True, static_data_name="recipe__layer_version__branch", static_data_template=layer_branch_template, orderable=True) git_rev_template = ''' {% if not data.recipe.layer_version.layer.local_source_dir %} {% with vcs_ref=data.recipe.layer_version.commit %} {% include 'snippets/gitrev_popover.html' %} {% endwith %} {% else %} Not applicable {% endif %} ''' self.add_column(title="Layer commit", static_data_name='vcs_ref', static_data_template=git_rev_template, hidden=True) class BuiltPackagesTable(BuildTablesMixin, BuiltPackagesTableBase): """ Show all the packages built for the selected build """ def __init__(self, *args, **kwargs): super(BuiltPackagesTable, self).__init__(*args, **kwargs) self.title = "Packages built" self.default_orderby = "name" self.empty_state =\ ('No packages were built. How did this happen? ' 'Well, BitBake reuses as much stuff as possible. ' 'If all of the packages needed were already built and available ' 'in your build infrastructure, BitBake ' 'will not rebuild any of them. This might be slightly confusing, ' 'but it does make everything faster.') def setup_columns(self, *args, **kwargs): super(BuiltPackagesTable, self).setup_columns(*args, **kwargs) def remove_dep_cols(columns): for column in columns: # We don't need these fields if column['static_data_name'] in ['reverse_dependencies', 'dependencies']: continue yield column self.columns = list(remove_dep_cols(self.columns)) class InstalledPackagesTable(BuildTablesMixin, BuiltPackagesTableBase): """ Show all packages installed in an image """ def __init__(self, *args, **kwargs): super(InstalledPackagesTable, self).__init__(*args, **kwargs) self.title = "Packages Included" self.default_orderby = "name" def make_package_list(self, target): # The database design means that you get the intermediate objects and # not package objects like you'd really want so we get them here pkgs = target.target_installed_package_set.values_list('package', flat=True) return Package.objects.filter(pk__in=pkgs) def get_context_data(self, **kwargs): context = super(InstalledPackagesTable, self).get_context_data(**kwargs) target = Target.objects.get(pk=kwargs['target_id']) packages = self.make_package_list(target) context['packages_sum'] = packages.aggregate( Sum('installed_size'))['installed_size__sum'] context['target'] = target return context def setup_queryset(self, *args, **kwargs): build = Build.objects.get(pk=kwargs['build_id']) self.static_context_extra['build'] = build target = Target.objects.get(pk=kwargs['target_id']) # We send these separately because in the case of image details table # we don't have a target just the recipe name as the target self.static_context_extra['target_name'] = target.target self.static_context_extra['target_id'] = target.pk self.static_context_extra['add_links'] = True self.queryset = self.make_package_list(target) self.queryset = self.queryset.order_by(self.default_orderby) def setup_columns(self, *args, **kwargs): super(InstalledPackagesTable, self).setup_columns(**kwargs) self.add_column(title="Installed size", static_data_name="installed_size", static_data_template="{% load projecttags %}" "{{data.size|filtered_filesizeformat}}", orderable=True, hidden=True) # Add the template to show installed name for installed packages install_name_tmpl =\ ('{{data.name}}' '{% if data.installed_name and data.installed_name !=' ' data.name %}' ' as {{data.installed_name}}' ' {% endif %} ') for column in self.columns: if column['static_data_name'] == 'name': column['static_data_template'] = install_name_tmpl break class BuiltRecipesTable(BuildTablesMixin): """ Table to show the recipes that have been built in this build """ def __init__(self, *args, **kwargs): super(BuiltRecipesTable, self).__init__(*args, **kwargs) self.title = "Recipes built" self.default_orderby = "name" def setup_queryset(self, *args, **kwargs): build = Build.objects.get(pk=kwargs['build_id']) self.static_context_extra['build'] = build self.queryset = build.get_recipes() self.queryset = self.queryset.order_by(self.default_orderby) def setup_columns(self, *args, **kwargs): recipe_name_tmpl =\ ''\ '{{data.name}}'\ '' recipe_file_tmpl =\ '{{data.file_path}}'\ '{% if data.pathflags %}({{data.pathflags}})'\ '{% endif %}' git_branch_template = ''' {% if data.layer_version.layer.local_source_dir %} Not applicable {% else %} {{data.layer_version.branch}} {% endif %} ''' git_rev_template = ''' {% if data.layer_version.layer.local_source_dir %} Not applicable {% else %} {% with vcs_ref=data.layer_version.commit %} {% include 'snippets/gitrev_popover.html' %} {% endwith %} {% endif %} ''' depends_on_tmpl = ''' {% with deps=data.r_dependencies_recipe.all %} {% with count=deps|length %} {% if count %} {{data.name}} dependencies" data-content="