summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/buildtables.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/toaster/toastergui/buildtables.py')
-rw-r--r--bitbake/lib/toaster/toastergui/buildtables.py152
1 files changed, 152 insertions, 0 deletions
diff --git a/bitbake/lib/toaster/toastergui/buildtables.py b/bitbake/lib/toaster/toastergui/buildtables.py
new file mode 100644
index 0000000000..cf07ea8789
--- /dev/null
+++ b/bitbake/lib/toaster/toastergui/buildtables.py
@@ -0,0 +1,152 @@
1#
2# ex:ts=4:sw=4:sts=4:et
3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4#
5# BitBake Toaster Implementation
6#
7# Copyright (C) 2016 Intel Corporation
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License version 2 as
11# published by the Free Software Foundation.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License along
19# with this program; if not, write to the Free Software Foundation, Inc.,
20# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
22from orm.models import Build
23import toastergui.tables as tables
24
25from toastergui.widgets import ToasterTable
26
27
28class BuildTablesMixin(ToasterTable):
29 def get_context_data(self, **kwargs):
30 # We need to be explicit about which superclass we're calling here
31 # Otherwise the MRO gets in a right mess
32 context = ToasterTable.get_context_data(self, **kwargs)
33 context['build'] = Build.objects.get(pk=kwargs['build_id'])
34 return context
35
36
37class BuiltPackagesTableBase(tables.PackagesTable):
38 """ Table to display all the packages built in a build """
39 def __init__(self, *args, **kwargs):
40 super(BuiltPackagesTableBase, self).__init__(*args, **kwargs)
41 self.title = "Packages built"
42 self.default_orderby = "name"
43
44 def setup_queryset(self, *args, **kwargs):
45 build = Build.objects.get(pk=kwargs['build_id'])
46 self.static_context_extra['build'] = build
47 self.queryset = build.package_set.all().exclude(recipe=None)
48 self.queryset = self.queryset.order_by(self.default_orderby)
49
50 def setup_columns(self, *args, **kwargs):
51 super(BuiltPackagesTableBase, self).setup_columns(*args, **kwargs)
52
53 def pkg_link_template(val):
54 """ return the template used for the link with the val as the
55 element value i.e. inside the <a></a>"""
56
57 return ('''
58 <a href="
59 {%% url "package_built_detail" extra.build.pk data.pk %%}
60 ">%s</a>
61 ''' % val)
62
63 def recipe_link_template(val):
64 return ('''
65 {%% if data.recipe %%}
66 <a href="
67 {%% url "recipe" extra.build.pk data.recipe.pk %%}
68 ">%(value)s</a>
69 {%% else %%}
70 %(value)s
71 {%% endif %%}
72 ''' % {'value': val})
73
74 add_pkg_link_to = ['name', 'version', 'size', 'license']
75 add_recipe_link_to = ['recipe__name', 'recipe__version']
76
77 # Add the recipe and pkg build links to the required columns
78 for column in self.columns:
79 # Convert to template field style accessors
80 tmplv = column['field_name'].replace('__', '.')
81 tmplv = "{{data.%s}}" % tmplv
82
83 if column['field_name'] in add_pkg_link_to:
84 # Don't overwrite an existing template
85 if column['static_data_template']:
86 column['static_data_template'] =\
87 pkg_link_template(column['static_data_template'])
88 else:
89 column['static_data_template'] = pkg_link_template(tmplv)
90
91 column['static_data_name'] = column['field_name']
92
93 elif column['field_name'] in add_recipe_link_to:
94 # Don't overwrite an existing template
95 if column['static_data_template']:
96 column['static_data_template'] =\
97 recipe_link_template(column['static_data_template'])
98 else:
99 column['static_data_template'] =\
100 recipe_link_template(tmplv)
101 column['static_data_name'] = column['field_name']
102
103 self.add_column(title="Layer",
104 field_name="recipe__layer_version__layer__name",
105 hidden=True,
106 orderable=True)
107
108 self.add_column(title="Layer branch",
109 field_name="recipe__layer_version__branch",
110 hidden=True,
111 orderable=True)
112
113 git_rev_template = '''
114 {% with vcs_ref=data.recipe.layer_version.commit %}
115 {% include 'snippets/gitrev_popover.html' %}
116 {% endwith %}
117 '''
118
119 self.add_column(title="Layer commit",
120 static_data_name='vcs_ref',
121 static_data_template=git_rev_template,
122 hidden=True)
123
124
125class BuiltPackagesTable(BuildTablesMixin, BuiltPackagesTableBase):
126 """ Show all the packages built for the selected build """
127 def __init__(self, *args, **kwargs):
128 super(BuiltPackagesTable, self).__init__(*args, **kwargs)
129 self.title = "Packages built"
130 self.default_orderby = "name"
131
132 self.empty_state =\
133 ('<strong>No packages were built.</strong> How did this happen?'
134 'Well, BitBake reuses as much stuff as possible.'
135 'If all of the packages needed were already built and available'
136 'in your build infrastructure, BitBake'
137 'will not rebuild any of them. This might be slightly confusing,'
138 'but it does make everything faster.')
139
140 def setup_columns(self, *args, **kwargs):
141 super(BuiltPackagesTable, self).setup_columns(*args, **kwargs)
142
143 def remove_dep_cols(columns):
144 for column in columns:
145 # We don't need these fields
146 if column['static_data_name'] in ['reverse_dependencies',
147 'dependencies']:
148 continue
149
150 yield column
151
152 self.columns = list(remove_dep_cols(self.columns))