1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
|
#
# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
#
# BitBake Toaster Implementation
#
# Copyright (C) 2015 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 toastergui.widgets import ToasterTable
from orm.models import Recipe, ProjectLayer, Layer_Version, Machine, Project
from django.db.models import Q, Max
from django.conf.urls import url
from django.views.generic import TemplateView
class LayersTable(ToasterTable):
"""Table of layers in Toaster"""
def __init__(self, *args, **kwargs):
super(LayersTable, self).__init__(*args, **kwargs)
self.default_orderby = "layer__name"
def get_context_data(self, **kwargs):
context = super(LayersTable, self).get_context_data(**kwargs)
context['project'] = Project.objects.get(pk=kwargs['pid'])
context['projectlayers'] = map(lambda prjlayer: prjlayer.layercommit.id, ProjectLayer.objects.filter(project=context['project']))
return context
def setup_queryset(self, *args, **kwargs):
prj = Project.objects.get(pk = kwargs['pid'])
compatible_layers = prj.compatible_layerversions()
self.queryset = compatible_layers.order_by(self.default_orderby)
def setup_columns(self, *args, **kwargs):
layer_link_template = '''
<a href="{% url 'layerdetails' extra.pid data.id %}">
{{data.layer.name}}
</a>
'''
self.add_column(title="Layer",
hideable=False,
orderable=True,
static_data_name="layer__name",
static_data_template=layer_link_template)
self.add_column(title="Summary",
field_name="layer__summary")
git_url_template = '''
<a href="{% url 'layerdetails' extra.pid data.id %}">
<code>{{data.layer.vcs_url}}</code>
</a>
{% if data.get_vcs_link_url %}
<a target="_blank" href="{{ data.get_vcs_link_url }}">
<i class="icon-share get-info"></i>
</a>
{% endif %}
'''
self.add_column(title="Git repository URL",
help_text="The Git repository for the layer source code",
hidden=True,
static_data_name="layer__vcs_url",
static_data_template=git_url_template)
git_dir_template = '''
<a href="{% url 'layerdetails' extra.pid data.id %}">
<code>{{data.dirpath}}</code>
</a>
{% if data.dirpath and data.get_vcs_dirpath_link_url %}
<a target="_blank" href="{{ data.get_vcs_dirpath_link_url }}">
<i class="icon-share get-info"></i>
</a>
{% endif %}'''
self.add_column(title="Subdirectory",
help_text="The layer directory within the Git repository",
hidden=True,
static_data_name="git_subdir",
static_data_template=git_dir_template)
revision_template = '''
{% load projecttags %}
{% with vcs_ref=data.get_vcs_reference %}
{% if vcs_ref|is_shaid %}
<a class="btn" data-content="<ul class='unstyled'> <li>{{vcs_ref}}</li> </ul>">
{{vcs_ref|truncatechars:10}}
</a>
{% else %}
{{vcs_ref}}
{% endif %}
{% endwith %}
'''
self.add_column(title="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",
static_data_name="revision",
static_data_template=revision_template)
deps_template = '''
{% with ods=data.dependencies.all%}
{% if ods.count %}
<a class="btn" title="<a href='{% url "layerdetails" extra.pid data.id %}'>{{data.layer.name}}</a> dependencies"
data-content="<ul class='unstyled'>
{% for i in ods%}
<li><a href='{% url "layerdetails" extra.pid i.depends_on.pk %}'>{{i.depends_on.layer.name}}</a></li>
{% endfor %}
</ul>">
{{ods.count}}
</a>
{% endif %}
{% endwith %}
'''
self.add_column(title="Dependencies",
help_text="Other layers a layer depends upon",
static_data_name="dependencies",
static_data_template=deps_template)
self.add_column(title="Add | Delete",
help_text="Add or delete layers to / from your project",
hideable=False,
static_data_name="add-del-layers",
static_data_template='{% include "layer_btn.html" %}')
class LayerDetails(TemplateView):
def get_context_data(self, **kwargs):
context = super(LayerDetails, self).get_context_data(**kwargs)
context['project'] = Project.objects.get(pk=kwargs['pid'])
context['layerversion'] = Layer_Version.objects.get(pk=kwargs['layerid'])
context['projectlayers'] = map(lambda prjlayer: prjlayer.layercommit.id, ProjectLayer.objects.filter(project=context['project']))
return context
class MachinesTable(ToasterTable):
"""Table of Machines in Toaster"""
def __init__(self, *args, **kwargs):
super(MachinesTable, self).__init__(*args, **kwargs)
self.empty_state = "No machines maybe you need to do a build?"
self.default_orderby = "name"
def get_context_data(self, **kwargs):
context = super(MachinesTable, self).get_context_data(**kwargs)
context['project'] = Project.objects.get(pk=kwargs['pid'])
context['projectlayers'] = map(lambda prjlayer: prjlayer.layercommit.id, ProjectLayer.objects.filter(project=context['project']))
return context
def setup_queryset(self, *args, **kwargs):
prj = Project.objects.get(pk = kwargs['pid'])
compatible_layers = prj.compatible_layerversions()
self.queryset = Machine.objects.filter(layer_version__in=compatible_layers).order_by(self.default_orderby)
def setup_columns(self, *args, **kwargs):
self.add_column(title="Machine",
hideable=False,
orderable=True,
field_name="name")
self.add_column(title="Description",
field_name="description")
layer_link_template = '''
<a href="{% url 'layerdetails' extra.pid data.layer_version.id %}">
{{data.layer_version.layer.name}}</a>
'''
self.add_column(title="Layer",
static_data_name="layer_version__layer__name",
static_data_template=layer_link_template,
orderable=True)
self.add_column(title="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")
machine_file_template = '''<code>conf/machine/{{data.name}}.conf</code>
<a href="{{data.get_vcs_machine_file_link_url}}" target="_blank"><i class="icon-share get-info"></i></a>'''
self.add_column(title="Machine file",
hidden=True,
static_data_name="machinefile",
static_data_template=machine_file_template)
self.add_column(title="Select",
help_text="Sets the selected machine as the project machine. You can only have one machine per project",
hideable=False,
static_data_name="add-del-layers",
static_data_template='{% include "machine_btn.html" %}',
field_name="layer_version__id")
class LayerMachinesTable(MachinesTable):
""" Smaller version of the Machines table for use in layer details """
def __init__(self, *args, **kwargs):
super(LayerMachinesTable, self).__init__(*args, **kwargs)
def get_context_data(self, **kwargs):
context = super(LayerMachinesTable, self).get_context_data(**kwargs)
context['layerversion'] = Layer_Version.objects.get(pk=kwargs['layerid'])
return context
def setup_queryset(self, *args, **kwargs):
MachinesTable.setup_queryset(self, *args, **kwargs)
self.queryset = self.queryset.filter(layer_version__pk=int(kwargs['layerid']))
self.static_context_extra['in_prj'] = ProjectLayer.objects.filter(Q(project=kwargs['pid']) and Q(layercommit=kwargs['layerid'])).count()
def setup_columns(self, *args, **kwargs):
self.add_column(title="Machine",
hideable=False,
orderable=True,
field_name="name")
self.add_column(title="Description",
field_name="description")
select_btn_template = '<a href="{% url "project" extra.pid %}#/machineselect={{data.name}}" class="btn btn-block select-machine-btn" {% if extra.in_prj == 0%}disabled="disabled"{%endif%}>Select machine</a>'
self.add_column(title="Select machine",
static_data_name="add-del-layers",
static_data_template=select_btn_template)
class RecipesTable(ToasterTable):
"""Table of Recipes in Toaster"""
def __init__(self, *args, **kwargs):
super(RecipesTable, self).__init__(*args, **kwargs)
self.empty_state = "Toaster has no recipe information. To generate recipe information you can configure a layer source then run a build."
self.default_orderby = "name"
def get_context_data(self, **kwargs):
context = super(RecipesTable, self).get_context_data(**kwargs)
context['project'] = Project.objects.get(pk=kwargs['pid'])
context['projectlayers'] = map(lambda prjlayer: prjlayer.layercommit.id, ProjectLayer.objects.filter(project=context['project']))
return context
def setup_queryset(self, *args, **kwargs):
prj = Project.objects.get(pk = kwargs['pid'])
self.queryset = Recipe.objects.filter(Q(layer_version__up_branch__name= prj.release.name) | Q(layer_version__build__in = prj.build_set.all())).filter(name__regex=r'.{1,}.*')
search_maxids = map(lambda i: i[0], list(self.queryset.values('name').distinct().annotate(max_id=Max('id')).values_list('max_id')))
self.queryset = self.queryset.filter(id__in=search_maxids).select_related('layer_version', 'layer_version__layer', 'layer_version__up_branch', 'layer_source')
self.queryset = self.queryset.order_by(self.default_orderby)
def setup_columns(self, *args, **kwargs):
self.add_column(title="Recipe",
help_text="Information about a single piece of software, including where to download the source, configuration options, how to compile the source files and how to package the compiled output",
hideable=False,
orderable=True,
field_name="name")
self.add_column(title="Recipe Version",
hidden=True,
field_name="version")
self.add_column(title="Description",
field_name="get_description_or_summary")
recipe_file_template = '''
<code>{{data.file_path}}</code>
<a href="{{data.get_vcs_recipe_file_link_url}}" target="_blank">
<i class="icon-share get-info"></i>
</a>
'''
self.add_column(title="Recipe file",
help_text="Path to the recipe .bb file",
static_data_name="recipe-file",
static_data_template=recipe_file_template)
self.add_column(title="Section",
help_text="The section in which recipes should be categorized",
orderable=True,
field_name="section")
layer_link_template = '''
<a href="{% url 'layerdetails' extra.pid data.layer_version.id %}">
{{data.layer_version.layer.name}}</a>
'''
self.add_column(title="Layer",
help_text="The name of the layer providing the recipe",
orderable=True,
static_data_name="layer_version__layer__name",
static_data_template=layer_link_template)
self.add_column(title="License",
help_text="The list of source licenses for the recipe. Multiple license names separated by the pipe character indicates a choice between licenses. Multiple license names separated by the ampersand character indicates multiple licenses exist that cover different parts of the source",
orderable=True,
field_name="license")
self.add_column(title="Revision",
field_name="layer_version__get_vcs_reference")
self.add_column(title="Build",
help_text="Add or delete recipes to and from your project",
hideable=False,
static_data_name="add-del-layers",
static_data_template='{% include "recipe_btn.html" %}')
self.add_column(title="Project compatible Layer ID",
displayable = False,
field_name = "projectcompatible_layer",
computation = lambda x: (x.layer_version.get_equivalents_wpriority(Project.objects.get(pk=kwargs['pid']))[0]))
class LayerRecipesTable(RecipesTable):
""" Smaller version of the Recipes table for use in layer details """
def __init__(self, *args, **kwargs):
super(LayerRecipesTable, self).__init__(*args, **kwargs)
def get_context_data(self, **kwargs):
context = super(LayerRecipesTable, self).get_context_data(**kwargs)
context['layerversion'] = Layer_Version.objects.get(pk=kwargs['layerid'])
return context
def setup_queryset(self, *args, **kwargs):
RecipesTable.setup_queryset(self, *args, **kwargs)
self.queryset = self.queryset.filter(layer_version__pk=int(kwargs['layerid']))
self.static_context_extra['in_prj'] = ProjectLayer.objects.filter(Q(project=kwargs['pid']) and Q(layercommit=kwargs['layerid'])).count()
def setup_columns(self, *args, **kwargs):
self.add_column(title="Recipe",
help_text="Information about a single piece of software, including where to download the source, configuration options, how to compile the source files and how to package the compiled output",
hideable=False,
orderable=True,
field_name="name")
self.add_column(title="Description",
field_name="get_description_or_summary")
build_recipe_template ='<button class="btn btn-block build-target-btn" data-target-name="{{data.name}}" {%if extra.in_prj == 0 %}disabled="disabled"{%endif%}>Build recipe</button>'
self.add_column(title="Build recipe",
static_data_name="add-del-layers",
static_data_template=build_recipe_template)
|