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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
|
#
# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
#
# BitBake Toaster Implementation
#
# Copyright (C) 2013 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.
import operator,re
from django.db.models import Q, Sum
from django.shortcuts import render, redirect
from orm.models import Build, Target, Task, Layer, Layer_Version, Recipe, LogMessage, Variable
from orm.models import Task_Dependency, Recipe_Dependency, Package, Package_File, Package_Dependency
from orm.models import Target_Installed_Package, Target_File, Target_Image_File
from django.views.decorators.cache import cache_control
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.http import HttpResponseBadRequest
from django.utils import timezone
from datetime import timedelta
from django.utils import formats
import json
def _build_page_range(paginator, index = 1):
try:
page = paginator.page(index)
except PageNotAnInteger:
page = paginator.page(1)
except EmptyPage:
page = paginator.page(paginator.num_pages)
page.page_range = [page.number]
crt_range = 0
for i in range(1,5):
if (page.number + i) <= paginator.num_pages:
page.page_range = page.page_range + [ page.number + i]
crt_range +=1
if (page.number - i) > 0:
page.page_range = [page.number -i] + page.page_range
crt_range +=1
if crt_range == 4:
break
return page
def _verify_parameters(g, mandatory_parameters):
miss = []
for mp in mandatory_parameters:
if not mp in g:
miss.append(mp)
if len(miss):
return miss
return None
def _redirect_parameters(view, g, mandatory_parameters, *args, **kwargs):
import urllib
from django.core.urlresolvers import reverse
url = reverse(view, kwargs=kwargs)
params = {}
for i in g:
params[i] = g[i]
for i in mandatory_parameters:
if not i in params:
params[i] = mandatory_parameters[i]
return redirect(url + "?%s" % urllib.urlencode(params), *args, **kwargs)
FIELD_SEPARATOR = ":"
VALUE_SEPARATOR = ";"
DESCENDING = "-"
def __get_q_for_val(name, value):
if "OR" in value:
return reduce(operator.or_, map(lambda x: __get_q_for_val(name, x), [ x for x in value.split("OR") ]))
if "AND" in value:
return reduce(operator.and_, map(lambda x: __get_q_for_val(name, x), [ x for x in value.split("AND") ]))
if value.startswith("NOT"):
kwargs = { name : value.strip("NOT") }
return ~Q(**kwargs)
else:
kwargs = { name : value }
return Q(**kwargs)
def _get_filtering_query(filter_string):
search_terms = filter_string.split(FIELD_SEPARATOR)
keys = search_terms[0].split(VALUE_SEPARATOR)
values = search_terms[1].split(VALUE_SEPARATOR)
querydict = dict(zip(keys, values))
return reduce(lambda x, y: x & y, map(lambda x: __get_q_for_val(k, querydict[k]),[k for k in querydict]))
def _get_toggle_order(request, orderkey, reverse = False):
if reverse:
return "%s:+" % orderkey if request.GET.get('orderby', "") == "%s:-" % orderkey else "%s:-" % orderkey
else:
return "%s:-" % orderkey if request.GET.get('orderby', "") == "%s:+" % orderkey else "%s:+" % orderkey
def _get_toggle_order_icon(request, orderkey):
if request.GET.get('orderby', "") == "%s:+"%orderkey:
return "down"
elif request.GET.get('orderby', "") == "%s:-"%orderkey:
return "up"
else:
return None
# we check that the input comes in a valid form that we can recognize
def _validate_input(input, model):
invalid = None
if input:
input_list = input.split(FIELD_SEPARATOR)
# Check we have only one colon
if len(input_list) != 2:
invalid = "We have an invalid number of separators"
return None, invalid
# Check we have an equal number of terms both sides of the colon
if len(input_list[0].split(VALUE_SEPARATOR)) != len(input_list[1].split(VALUE_SEPARATOR)):
invalid = "Not all arg names got values"
return None, invalid + str(input_list)
# Check we are looking for a valid field
valid_fields = model._meta.get_all_field_names()
for field in input_list[0].split(VALUE_SEPARATOR):
if not reduce(lambda x, y: x or y, map(lambda x: field.startswith(x), [ x for x in valid_fields ])):
return None, (field, [ x for x in valid_fields ])
return input, invalid
# uses search_allowed_fields in orm/models.py to create a search query
# for these fields with the supplied input text
def _get_search_results(search_term, queryset, model):
search_objects = []
for st in search_term.split(" "):
q_map = map(lambda x: Q(**{x+'__icontains': st}),
model.search_allowed_fields)
search_objects.append(reduce(operator.or_, q_map))
search_object = reduce(operator.and_, search_objects)
queryset = queryset.filter(search_object)
return queryset
# function to extract the search/filter/ordering parameters from the request
# it uses the request and the model to validate input for the filter and orderby values
def _search_tuple(request, model):
ordering_string, invalid = _validate_input(request.GET.get('orderby', ''), model)
if invalid:
raise BaseException("Invalid ordering model:" + str(model) + str(invalid))
filter_string, invalid = _validate_input(request.GET.get('filter', ''), model)
if invalid:
raise BaseException("Invalid filter " + str(invalid))
search_term = request.GET.get('search', '')
return (filter_string, search_term, ordering_string)
# returns a lazy-evaluated queryset for a filter/search/order combination
def _get_queryset(model, queryset, filter_string, search_term, ordering_string):
if filter_string:
filter_query = _get_filtering_query(filter_string)
queryset = queryset.filter(filter_query)
else:
queryset = queryset.all()
if search_term:
queryset = _get_search_results(search_term, queryset, model)
if ordering_string and queryset:
column, order = ordering_string.split(':')
if order.lower() == DESCENDING:
queryset = queryset.order_by('-' + column)
else:
queryset = queryset.order_by(column)
# insure only distinct records (e.g. from multiple search hits) are returned
return queryset.distinct()
# shows the "all builds" page
def builds(request):
template = 'build.html'
# define here what parameters the view needs in the GET portion in order to
# be able to display something. 'count' and 'page' are mandatory for all views
# that use paginators.
mandatory_parameters = { 'count': 10, 'page' : 1, 'orderby' : 'completed_on:-' };
retval = _verify_parameters( request.GET, mandatory_parameters )
if retval:
return _redirect_parameters( 'all-builds', request.GET, mandatory_parameters)
# boilerplate code that takes a request for an object type and returns a queryset
# for that object type. copypasta for all needed table searches
(filter_string, search_term, ordering_string) = _search_tuple(request, Build)
queryset_all = Build.objects.exclude(outcome = Build.IN_PROGRESS)
queryset_with_search = _get_queryset(Build, queryset_all, None, search_term, ordering_string)
queryset = _get_queryset(Build, queryset_all, filter_string, search_term, ordering_string)
# retrieve the objects that will be displayed in the table; builds a paginator and gets a page range to display
build_info = _build_page_range(Paginator(queryset, request.GET.get('count', 10)),request.GET.get('page', 1))
# build view-specific information; this is rendered specifically in the builds page, at the top of the page (i.e. Recent builds)
build_mru = Build.objects.filter(completed_on__gte=(timezone.now()-timedelta(hours=24))).order_by("-started_on")[:3]
for b in [ x for x in build_mru if x.outcome == Build.IN_PROGRESS ]:
tf = Task.objects.filter(build = b)
tfc = tf.count()
if tfc > 0:
b.completeper = tf.exclude(order__isnull=True).count()*100/tf.count()
else:
b.completeper = 0
b.eta = timezone.now()
if b.completeper > 0:
b.eta += ((timezone.now() - b.started_on)*100/b.completeper)
else:
b.eta = 0
# set up list of fstypes for each build
fstypes_map = {};
for build in build_info:
targets = Target.objects.filter( build_id = build.id )
comma = "";
extensions = "";
for t in targets:
if ( not t.is_image ):
continue
tif = Target_Image_File.objects.filter( target_id = t.id )
for i in tif:
s=re.sub('.*tar.bz2', 'tar.bz2', i.file_name)
if s == i.file_name:
s=re.sub('.*\.', '', i.file_name)
if None == re.search(s,extensions):
extensions += comma + s
comma = ", "
fstypes_map[build.id]=extensions
# send the data to the template
context = {
# specific info for
'mru' : build_mru,
# TODO: common objects for all table views, adapt as needed
'objects' : build_info,
'objectname' : "builds",
'fstypes' : fstypes_map,
'search_term' : search_term,
'total_count' : queryset_with_search.count(),
# Specifies the display of columns for the table, appearance in "Edit columns" box, toggling default show/hide, and specifying filters for columns
'tablecols' : [
{'name': 'Outcome', # column with a single filter
'qhelp' : "The outcome tells you if a build completed successfully or failed", # the help button content
'dclass' : "span2", # indication about column width; comes from the design
'orderfield': _get_toggle_order(request, "outcome"), # adds ordering by the field value; default ascending unless clicked from ascending into descending
'ordericon':_get_toggle_order_icon(request, "outcome"),
# filter field will set a filter on that column with the specs in the filter description
# the class field in the filter has no relation with clclass; the control different aspects of the UI
# still, it is recommended for the values to be identical for easy tracking in the generated HTML
'filter' : {'class' : 'outcome',
'label': 'Show:',
'options' : [
('Successful builds', 'outcome:' + str(Build.SUCCEEDED), queryset_with_search.filter(outcome=str(Build.SUCCEEDED)).count()), # this is the field search expression
('Failed builds', 'outcome:'+ str(Build.FAILED), queryset_with_search.filter(outcome=str(Build.FAILED)).count()),
]
}
},
{'name': 'Target', # default column, disabled box, with just the name in the list
'qhelp': "This is the build target(s): one or more recipes or image recipes",
'orderfield': _get_toggle_order(request, "target__target"),
'ordericon':_get_toggle_order_icon(request, "target__target"),
},
{'name': 'Machine',
'qhelp': "The machine is the hardware for which you are building",
'orderfield': _get_toggle_order(request, "machine"),
'ordericon':_get_toggle_order_icon(request, "machine"),
'dclass': 'span3'
}, # a slightly wider column
{'name': 'Started on', 'clclass': 'started_on', 'hidden' : 1, # this is an unchecked box, which hides the column
'qhelp': "The date and time you started the build",
'orderfield': _get_toggle_order(request, "started_on", True),
'ordericon':_get_toggle_order_icon(request, "started_on"),
'filter' : {'class' : 'started_on',
'label': 'Show:',
'options' : [
("Today's builds" , 'started_on__gte:'+timezone.now().strftime("%Y-%m-%d"), queryset_with_search.filter(started_on__gte=timezone.now().strftime("%Y-%m-%d")).count()),
("Yesterday's builds", 'started_on__gte:'+(timezone.now()-timedelta(hours=24)).strftime("%Y-%m-%d"), queryset_with_search.filter(started_on__gte=(timezone.now()-timedelta(hours=24)).strftime("%Y-%m-%d")).count()),
("This week's builds", 'started_on__gte:'+(timezone.now()-timedelta(days=7)).strftime("%Y-%m-%d"), queryset_with_search.filter(started_on__gte=(timezone.now()-timedelta(days=7)).strftime("%Y-%m-%d")).count()),
]
}
},
{'name': 'Completed on',
'qhelp': "The date and time the build finished",
'orderfield': _get_toggle_order(request, "completed_on", True),
'ordericon':_get_toggle_order_icon(request, "completed_on"),
'filter' : {'class' : 'completed_on',
'label': 'Show:',
'options' : [
("Today's builds", 'completed_on__gte:'+timezone.now().strftime("%Y-%m-%d"), queryset_with_search.filter(completed_on__gte=timezone.now().strftime("%Y-%m-%d")).count()),
("Yesterday's builds", 'completed_on__gte:'+(timezone.now()-timedelta(hours=24)).strftime("%Y-%m-%d"), queryset_with_search.filter(completed_on__gte=(timezone.now()-timedelta(hours=24)).strftime("%Y-%m-%d")).count()),
("This week's builds", 'completed_on__gte:'+(timezone.now()-timedelta(days=7)).strftime("%Y-%m-%d"), queryset_with_search.filter(completed_on__gte=(timezone.now()-timedelta(days=7)).strftime("%Y-%m-%d")).count()),
]
}
},
{'name': 'Failed tasks', 'clclass': 'failed_tasks', # specifing a clclass will enable the checkbox
'qhelp': "How many tasks failed during the build",
'filter' : {'class' : 'failed_tasks',
'label': 'Show:',
'options' : [
('Builds with failed tasks', 'task_build__outcome:4', queryset_with_search.filter(task_build__outcome=4).count()),
('Builds without failed tasks', 'task_build__outcome:NOT4', queryset_with_search.filter(~Q(task_build__outcome=4)).count()),
]
}
},
{'name': 'Errors', 'clclass': 'errors_no',
'qhelp': "How many errors were encountered during the build (if any)",
'orderfield': _get_toggle_order(request, "errors_no", True),
'ordericon':_get_toggle_order_icon(request, "errors_no"),
'filter' : {'class' : 'errors_no',
'label': 'Show:',
'options' : [
('Builds with errors', 'errors_no__gte:1', queryset_with_search.filter(errors_no__gte=1).count()),
('Builds without errors', 'errors_no:0', queryset_with_search.filter(errors_no=0).count()),
]
}
},
{'name': 'Warnings', 'clclass': 'warnings_no',
'qhelp': "How many warnings were encountered during the build (if any)",
'orderfield': _get_toggle_order(request, "warnings_no", True),
'ordericon':_get_toggle_order_icon(request, "warnings_no"),
'filter' : {'class' : 'warnings_no',
'label': 'Show:',
'options' : [
('Builds with warnings','warnings_no__gte:1', queryset_with_search.filter(warnings_no__gte=1).count()),
('Builds without warnings','warnings_no:0', queryset_with_search.filter(warnings_no=0).count()),
]
}
},
{'name': 'Time', 'clclass': 'time', 'hidden' : 1,
'qhelp': "How long it took the build to finish",
'orderfield': _get_toggle_order(request, "timespent", True),
'ordericon':_get_toggle_order_icon(request, "timespent"),
},
{'name': 'Log',
'dclass': "span4",
'qhelp': "The location in disk of the build main log file",
'clclass': 'log', 'hidden': 1,
'orderfield': _get_toggle_order(request, "cooker_log_path"),
'ordericon':_get_toggle_order_icon(request, "cooker_log_path"),
},
{'name': 'Output', 'clclass': 'output',
'qhelp': "The root file system types produced by the build. You can find them in your <code>/build/tmp/deploy/images/</code> directory",
# TODO: compute image fstypes from Target_Image_File
},
]
}
return render(request, template, context)
##
# build dashboard for a single build, coming in as argument
# Each build may contain multiple targets and each target
# may generate multiple image files. display them all.
#
def builddashboard(request, build_id):
template = "builddashboard.html"
if Build.objects.filter(pk=build_id).count() == 0 :
return redirect(builds)
build = Build.objects.filter(pk = build_id)[0];
layerVersionId = Layer_Version.objects.filter( build = build_id );
recipeCount = Recipe.objects.filter( layer_version__id__in = layerVersionId ).count( );
tgts = Target.objects.filter( build_id = build_id ).order_by( 'target' );
# set up custom target list with computed package and image data
targets = [ ];
ntargets = 0;
hasImages = False;
for t in tgts:
elem = { };
elem[ 'target' ] = t;
if ( t.is_image ):
hasImages = True;
npkg = 0;
pkgsz = 0;
pid= 0;
tp = Target_Installed_Package.objects.filter( target_id = t.id );
package = None;
for p in tp:
pid = p.package_id;
package = Package.objects.get( pk = p.package_id )
pkgsz = pkgsz + package.size;
npkg = npkg + 1;
elem[ 'npkg' ] = npkg;
elem[ 'pkgsz' ] = pkgsz;
ti = Target_Image_File.objects.filter( target_id = t.id );
imageFiles = [ ];
for i in ti:
imageFiles.append({ 'path': i.file_name, 'size' : i.file_size });
elem[ 'imageFiles' ] = imageFiles;
targets.append( elem );
context = {
'build' : build,
'hasImages' : hasImages,
'ntargets' : ntargets,
'targets' : targets,
'recipecount' : recipeCount,
'logmessages' : LogMessage.objects.filter(build=build_id),
}
return render(request, template, context)
def task(request, build_id, task_id):
template = "task.html"
if Task.objects.filter(pk=task_id).count() == 0 :
return redirect(builds)
task = Task.objects.filter(pk=task_id)[0]
dependencies = sorted(_find_task_dep(task), key=lambda t:'%s_%s %s'%(t.recipe.name, t.recipe.version, t.task_name))
reverse_dependencies = sorted(_find_task_revdep(task), key=lambda t:'%s_%s %s'%(t.recipe.name, t.recipe.version, t.task_name))
log_head = ''
log_body = ''
if task.outcome == task.OUTCOME_FAILED:
pass
# FIXME: the log should be read from the orm_logmessage table.
# This will be fixed when the backend is done.
context = {
'build' : Build.objects.filter(pk=build_id)[0],
'object': task,
'task':task,
'deps': dependencies,
'rdeps': reverse_dependencies,
'log_head':log_head,
'log_body':log_body,
'showing_matches':False,
}
if request.GET.get('show_matches', ""):
context['showing_matches'] = True
context['matching_tasks'] = Task.objects.filter(sstate_checksum=task.sstate_checksum).filter(build__completed_on__lt=task.build.completed_on).order_by('-build__completed_on')
return render(request, template, context)
def recipe(request, build_id, recipe_id):
template = "recipe.html"
if Recipe.objects.filter(pk=recipe_id).count() == 0 :
return redirect(builds)
object = Recipe.objects.filter(pk=recipe_id)[0]
layer_version = Layer_Version.objects.filter(pk=object.layer_version_id)[0]
layer = Layer.objects.filter(pk=layer_version.layer_id)[0]
tasks = Task.objects.filter(recipe_id = recipe_id).filter(build_id = build_id).exclude(task_name__endswith='_setscene')
packages = Package.objects.filter(recipe_id = recipe_id).filter(build_id = build_id).filter(size__gte=0)
context = {
'build' : Build.objects.filter(pk=build_id)[0],
'object' : object,
'layer_version' : layer_version,
'layer' : layer,
'tasks' : tasks,
'packages': packages,
}
return render(request, template, context)
def target(request, build_id, target_id):
template = "target.html"
mandatory_parameters = { 'count': 25, 'page' : 1, 'orderby':'name:+'};
retval = _verify_parameters( request.GET, mandatory_parameters )
if retval:
return _redirect_parameters( 'target', request.GET, mandatory_parameters, build_id = build_id, target_id = target_id)
(filter_string, search_term, ordering_string) = _search_tuple(request, Package)
# FUTURE: get rid of nested sub-queries replacing with ManyToMany field
queryset = Package.objects.filter(size__gte=0, id__in=Target_Installed_Package.objects.filter(target_id=target_id).values('package_id'))
packages_sum = queryset.aggregate(Sum('installed_size'))
queryset = _get_queryset(Package, queryset, filter_string, search_term, ordering_string)
packages = _build_page_range(Paginator(queryset, request.GET.get('count', 25)),request.GET.get('page', 1))
# bring in package dependencies
for p in packages.object_list:
p.runtime_dependencies = p.package_dependencies_source.filter(target_id = target_id, dep_type=Package_Dependency.TYPE_TRDEPENDS)
p.reverse_runtime_dependencies = p.package_dependencies_target.filter(target_id = target_id, dep_type=Package_Dependency.TYPE_TRDEPENDS)
context = { 'build': Build.objects.filter(pk=build_id)[0],
'target': Target.objects.filter(pk=target_id)[0],
'objects': packages,
'packages_sum' : packages_sum['installed_size__sum'],
'object_search_display': "packages included",
'tablecols':[
{
'name':'Package',
'qhelp':'Packaged output resulting from building a recipe and included in this image',
'orderfield': _get_toggle_order(request, "name"),
'ordericon':_get_toggle_order_icon(request, "name"),
},
{
'name':'Package version',
'qhelp':'The package version and revision',
},
{
'name':'Size',
'qhelp':'The size of the package',
'orderfield': _get_toggle_order(request, "size", True),
'ordericon':_get_toggle_order_icon(request, "size"),
'clclass': 'package_size',
'hidden' : 0,
},
{
'name':'Size over total (%)',
'qhelp':'Proportion of the overall included package size represented by this package',
'orderfield': _get_toggle_order(request, "size"),
'ordericon':_get_toggle_order_icon(request, "size"),
'clclass': 'size_over_total',
'hidden' : 1,
},
{
'name':'License',
'qhelp':'The license under which the package is distributed. Separate license names using | (pipe) means there is a choice between licenses. Separate license names using & (ampersand) means multiple licenses exist that cover different parts of the source',
'orderfield': _get_toggle_order(request, "license"),
'ordericon':_get_toggle_order_icon(request, "license"),
'clclass': 'license',
'hidden' : 1,
},
{
'name':'Dependencies',
'qhelp':"Package runtime dependencies (other packages)",
'clclass': 'depends',
'hidden' : 0,
},
{
'name':'Reverse dependencies',
'qhelp':'Package run-time reverse dependencies (i.e. which other packages depend on this package',
'clclass': 'brought_in_by',
'hidden' : 0,
},
{
'name':'Recipe',
'qhelp':'The name of the recipe building the package',
'orderfield': _get_toggle_order(request, "recipe__name"),
'ordericon':_get_toggle_order_icon(request, "recipe__name"),
'clclass': 'recipe_name',
'hidden' : 0,
},
{
'name':'Recipe version',
'qhelp':'Version and revision of the recipe building the package',
'clclass': 'recipe_version',
'hidden' : 1,
},
{
'name':'Layer',
'qhelp':'The name of the layer providing the recipe that builds the package',
'orderfield': _get_toggle_order(request, "recipe__layer_version__layer__name"),
'ordericon':_get_toggle_order_icon(request, "recipe__layer_version__layer__name"),
'clclass': 'layer_name',
'hidden' : 1,
},
{
'name':'Layer branch',
'qhelp':'The Git branch of the layer providing the recipe that builds the package',
'orderfield': _get_toggle_order(request, "recipe__layer_version__branch"),
'ordericon':_get_toggle_order_icon(request, "recipe__layer_version__branch"),
'clclass': 'layer_branch',
'hidden' : 1,
},
{
'name':'Layer commit',
'qhelp':'The Git commit of the layer providing the recipe that builds the package',
'clclass': 'layer_commit',
'hidden' : 1,
},
{
'name':'Layer directory',
'qhelp':'Location in disk of the layer providing the recipe that builds the package',
'orderfield': _get_toggle_order(request, "recipe__layer_version__layer__local_path"),
'ordericon':_get_toggle_order_icon(request, "recipe__layer_version__layer__local_path"),
'clclass': 'layer_directory',
'hidden' : 1,
},
]
}
return render(request, template, context)
from django.core.serializers.json import DjangoJSONEncoder
from django.http import HttpResponse
def dirinfo_ajax(request, build_id, target_id):
top = request.GET.get('start', '/')
return HttpResponse(_get_dir_entries(build_id, target_id, top))
from django.utils.functional import Promise
from django.utils.encoding import force_text
class LazyEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, Promise):
return force_text(obj)
return super(LazyEncoder, self).default(obj)
from toastergui.templatetags.projecttags import filtered_filesizeformat
from django import template
import os
def _get_dir_entries(build_id, target_id, start):
node_str = {
Target_File.ITYPE_REGULAR : '-',
Target_File.ITYPE_DIRECTORY : 'd',
Target_File.ITYPE_SYMLINK : 'l',
Target_File.ITYPE_SOCKET : 's',
Target_File.ITYPE_FIFO : 'p',
Target_File.ITYPE_CHARACTER : 'c',
Target_File.ITYPE_BLOCK : 'b',
}
response = []
objects = Target_File.objects.filter(target__exact=target_id, directory__path=start)
target_packages = Target_Installed_Package.objects.filter(target__exact=target_id).values_list('package_id', flat=True)
for o in objects:
# exclude root inode '/'
if o.path == '/':
continue
try:
entry = {}
entry['parent'] = start
entry['name'] = os.path.basename(o.path)
entry['fullpath'] = o.path
# set defaults, not all dentries have packages
entry['installed_package'] = None
entry['package_id'] = None
entry['package'] = None
entry['link_to'] = None
if o.inodetype == Target_File.ITYPE_DIRECTORY:
entry['isdir'] = 1
# is there content in directory
entry['childcount'] = Target_File.objects.filter(target__exact=target_id, directory__path=o.path).all().count()
else:
entry['isdir'] = 0
# resolve the file to get the package from the resolved file
resolved_id = o.sym_target_id
resolved_path = o.path
if target_packages.count():
while resolved_id != "" and resolved_id != None:
tf = Target_File.objects.get(pk=resolved_id)
resolved_path = tf.path
resolved_id = tf.sym_target_id
thisfile=Package_File.objects.all().filter(path__exact=resolved_path, package_id__in=target_packages)
if thisfile.count():
p = Package.objects.get(pk=thisfile[0].package_id)
entry['installed_package'] = p.installed_name
entry['package_id'] = str(p.id)
entry['package'] = p.name
# don't use resolved path from above, show immediate link-to
if o.sym_target_id != "" and o.sym_target_id != None:
entry['link_to'] = Target_File.objects.get(pk=o.sym_target_id).path
t = template.Template('{% load projecttags %} {{ size|filtered_filesizeformat }}')
c = template.Context({'size': o.size})
entry['size'] = str(t.render(c))
if entry['link_to'] != None:
entry['permission'] = node_str[o.inodetype] + o.permission
else:
entry['permission'] = node_str[o.inodetype] + o.permission
entry['owner'] = o.owner
entry['group'] = o.group
response.append(entry)
except:
pass
# sort by directories first, then by name
rsorted = sorted(response, key=lambda entry : entry['name'])
rsorted = sorted(rsorted, key=lambda entry : entry['isdir'], reverse=True)
return json.dumps(rsorted, cls=LazyEncoder)
def dirinfo(request, build_id, target_id, file_path=None):
template = "dirinfo.html"
objects = _get_dir_entries(build_id, target_id, '/')
packages_sum = Package.objects.filter(id__in=Target_Installed_Package.objects.filter(target_id=target_id).values('package_id')).aggregate(Sum('installed_size'))
dir_list = None
if file_path != None:
"""
Link from the included package detail file list page and is
requesting opening the dir info to a specific file path.
Provide the list of directories to expand and the full path to
highlight in the page.
"""
# Aassume target's path separator matches host's, that is, os.sep
sep = os.sep
dir_list = []
head = file_path
while head != sep:
(head,tail) = os.path.split(head)
if head != sep:
dir_list.insert(0, head)
context = { 'build': Build.objects.filter(pk=build_id)[0],
'target': Target.objects.filter(pk=target_id)[0],
'packages_sum': packages_sum['installed_size__sum'],
'objects': objects,
'dir_list': dir_list,
'file_path': file_path,
}
return render(request, template, context)
def _find_task_dep(task):
tp = []
for p in Task_Dependency.objects.filter(task=task):
tp.append(p.depends_on);
return tp
def _find_task_revdep(task):
tp = []
for p in Task_Dependency.objects.filter(depends_on=task):
tp.append(p.task);
return tp
def _find_task_provider(task):
task_revdeps = _find_task_revdep(task)
for tr in task_revdeps:
if tr.outcome != Task.OUTCOME_COVERED:
return tr
for tr in task_revdeps:
trc = _find_task_provider(tr)
if trc is not None:
return trc
return None
def tasks_common(request, build_id, variant):
# This class is shared between these pages
#
# Column tasks buildtime diskio cpuusage
# --------- ------ ---------- ------- ---------
# Cache def
# CPU min -
# Disk min -
# Executed def def def def
# Log
# Order def +
# Outcome def def def def
# Recipe min min min min
# Version
# Task min min min min
# Time min -
#
# 'min':on always, 'def':on by default, else hidden
# '+' default column sort up, '-' default column sort down
# default ordering depends on variant
if 'buildtime' == variant:
title_variant='Time'
object_search_display="time data"
filter_search_display="tasks"
mandatory_parameters = { 'count': 25, 'page' : 1, 'orderby':'elapsed_time:-'};
elif 'diskio' == variant:
title_variant='Disk I/O'
object_search_display="disk I/O data"
filter_search_display="tasks"
mandatory_parameters = { 'count': 25, 'page' : 1, 'orderby':'disk_io:-'};
elif 'cpuusage' == variant:
title_variant='CPU usage'
object_search_display="CPU usage data"
filter_search_display="tasks"
mandatory_parameters = { 'count': 25, 'page' : 1, 'orderby':'cpu_usage:-'};
else :
title_variant='Tasks'
object_search_display="tasks"
filter_search_display="tasks"
mandatory_parameters = { 'count': 25, 'page' : 1, 'orderby':'order:+'};
template = 'tasks.html'
retval = _verify_parameters( request.GET, mandatory_parameters )
if retval:
return _redirect_parameters( variant, request.GET, mandatory_parameters, build_id = build_id)
(filter_string, search_term, ordering_string) = _search_tuple(request, Task)
queryset_all = Task.objects.filter(build=build_id, order__gt=0)
queryset_with_search = _get_queryset(Task, queryset_all, None , search_term, ordering_string)
queryset = _get_queryset(Task, queryset_all, filter_string, search_term, ordering_string)
tasks = _build_page_range(Paginator(queryset, request.GET.get('count', 100)),request.GET.get('page', 1))
# define (and modify by variants) the 'tablecols' members
tc_order={
'name':'Order',
'qhelp':'The running sequence of each task in the build',
'clclass': 'order', 'hidden' : 1,
'orderfield':_get_toggle_order(request, "order"),
'ordericon':_get_toggle_order_icon(request, "order")}
if 'tasks' == variant: tc_order['hidden']='0'; del tc_order['clclass']
tc_recipe={
'name':'Recipe',
'qhelp':'The name of the recipe to which each task applies',
'orderfield': _get_toggle_order(request, "recipe__name"),
'ordericon':_get_toggle_order_icon(request, "recipe__name"),
}
tc_recipe_version={
'name':'Recipe version',
'qhelp':'The version of the recipe to which each task applies',
'clclass': 'recipe_version', 'hidden' : 1,
}
tc_task={
'name':'Task',
'qhelp':'The name of the task',
'orderfield': _get_toggle_order(request, "task_name"),
'ordericon':_get_toggle_order_icon(request, "task_name"),
}
tc_executed={
'name':'Executed',
'qhelp':"This value tells you if a task had to run in order to generate the task output (executed), or if the output was provided by another task and therefore the task didn't need to run (not executed)",
'clclass': 'executed', 'hidden' : 0,
'orderfield': _get_toggle_order(request, "task_executed"),
'ordericon':_get_toggle_order_icon(request, "task_executed"),
'filter' : {
'class' : 'executed',
'label': 'Show:',
'options' : [
('Executed Tasks', 'task_executed:1', queryset_with_search.filter(task_executed=1).count()),
('Not Executed Tasks', 'task_executed:0', queryset_with_search.filter(task_executed=0).count()),
]
}
}
tc_outcome={
'name':'Outcome',
'qhelp':'This column tells you if executed tasks succeeded, failed or restored output from the <code>sstate-cache</code> directory or mirrors. It also tells you why not executed tasks did not need to run',
'clclass': 'outcome', 'hidden' : 0,
'orderfield': _get_toggle_order(request, "outcome"),
'ordericon':_get_toggle_order_icon(request, "outcome"),
'filter' : {
'class' : 'outcome',
'label': 'Show:',
'options' : [
('Succeeded Tasks', 'outcome:%d'%Task.OUTCOME_SUCCESS, queryset_with_search.filter(outcome=Task.OUTCOME_SUCCESS).count(), 'Succeeded tasks are those that ran and completed during the build' ),
('Failed Tasks', 'outcome:%d'%Task.OUTCOME_FAILED, queryset_with_search.filter(outcome=Task.OUTCOME_FAILED).count(), 'Failed tasks are those that ran but did not complete during the build'),
('Cached Tasks', 'outcome:%d'%Task.OUTCOME_CACHED, queryset_with_search.filter(outcome=Task.OUTCOME_CACHED).count(), 'Cached tasks restored output from the <code>sstate-cache</code> directory or mirrors'),
('Prebuilt Tasks', 'outcome:%d'%Task.OUTCOME_PREBUILT, queryset_with_search.filter(outcome=Task.OUTCOME_PREBUILT).count(),'Prebuilt tasks didn\'t need to run because their output was reused from a previous build'),
('Covered Tasks', 'outcome:%d'%Task.OUTCOME_COVERED, queryset_with_search.filter(outcome=Task.OUTCOME_COVERED).count(), 'Covered tasks didn\'t need to run because their output is provided by another task in this build'),
('Empty Tasks', 'outcome:%d'%Task.OUTCOME_EMPTY, queryset_with_search.filter(outcome=Task.OUTCOME_NA).count(), 'Empty tasks have no executable content'),
]
}
}
tc_log={
'name':'Log',
'qhelp':'The location in disk of the task log file',
'orderfield': _get_toggle_order(request, "logfile"),
'ordericon':_get_toggle_order_icon(request, "logfile"),
'clclass': 'task_log', 'hidden' : 1,
}
tc_cache={
'name':'Cache attempt',
'qhelp':'This column tells you if a task tried to restore output from the <code>sstate-cache</code> directory or mirrors, and what was the result: Succeeded, Failed or File not in cache',
'clclass': 'cache_attempt', 'hidden' : 0,
'orderfield': _get_toggle_order(request, "sstate_result"),
'ordericon':_get_toggle_order_icon(request, "sstate_result"),
'filter' : {
'class' : 'cache_attempt',
'label': 'Show:',
'options' : [
('Tasks with cache attempts', 'sstate_result:%d'%Task.SSTATE_NA, queryset_with_search.filter(sstate_result=Task.SSTATE_NA).count(), 'Show all tasks that tried to restore ouput from the <code>sstate-cache</code> directory or mirrors'),
("Tasks with 'File not in cache' attempts", 'sstate_result:%d'%Task.SSTATE_MISS, queryset_with_search.filter(sstate_result=Task.SSTATE_MISS).count(), 'Show tasks that tried to restore output, but did not find it in the <code>sstate-cache</code> directory or mirrors'),
("Tasks with 'Failed' cache attempts", 'sstate_result:%d'%Task.SSTATE_FAILED, queryset_with_search.filter(sstate_result=Task.SSTATE_FAILED).count(), 'Show tasks that found the required output in the <code>sstate-cache</code> directory or mirrors, but could not restore it'),
("Tasks with 'Succeeded' cache attempts", 'sstate_result:%d'%Task.SSTATE_RESTORED, queryset_with_search.filter(sstate_result=Task.SSTATE_RESTORED).count(), 'Show tasks that successfully restored the required output from the <code>sstate-cache</code> directory or mirrors'),
]
}
}
#if 'tasks' == variant: tc_cache['hidden']='0';
tc_time={
'name':'Time (secs)',
'qhelp':'How long it took the task to finish, expressed in seconds',
'orderfield': _get_toggle_order(request, "elapsed_time", True),
'ordericon':_get_toggle_order_icon(request, "elapsed_time"),
'clclass': 'time_taken', 'hidden' : 1,
}
if 'buildtime' == variant: tc_time['hidden']='0'; del tc_time['clclass']; tc_cache['hidden']='1';
tc_cpu={
'name':'CPU usage',
'qhelp':'Task CPU utilisation, expressed as a percentage',
'orderfield': _get_toggle_order(request, "cpu_usage", True),
'ordericon':_get_toggle_order_icon(request, "cpu_usage"),
'clclass': 'cpu_used', 'hidden' : 1,
}
if 'cpuusage' == variant: tc_cpu['hidden']='0'; del tc_cpu['clclass']; tc_cache['hidden']='1';
tc_diskio={
'name':'Disk I/O (ms)',
'qhelp':'Number of miliseconds the task spent doing disk input and output',
'orderfield': _get_toggle_order(request, "disk_io", True),
'ordericon':_get_toggle_order_icon(request, "disk_io"),
'clclass': 'disk_io', 'hidden' : 1,
}
if 'diskio' == variant: tc_diskio['hidden']='0'; del tc_diskio['clclass']; tc_cache['hidden']='1';
context = { 'objectname': variant,
'object_search_display': object_search_display,
'filter_search_display': filter_search_display,
'title': title_variant,
'build': Build.objects.filter(pk=build_id)[0],
'objects': tasks,
'search_term': search_term,
'total_count': queryset_with_search.count(),
'tablecols':[
tc_order,
tc_recipe,
tc_recipe_version,
tc_task,
tc_executed,
tc_outcome,
tc_cache,
tc_time,
tc_cpu,
tc_diskio,
tc_log,
]}
return render(request, template, context)
def tasks(request, build_id):
return tasks_common(request, build_id, 'tasks')
def buildtime(request, build_id):
return tasks_common(request, build_id, 'buildtime')
def diskio(request, build_id):
return tasks_common(request, build_id, 'diskio')
def cpuusage(request, build_id):
return tasks_common(request, build_id, 'cpuusage')
def recipes(request, build_id):
template = 'recipes.html'
mandatory_parameters = { 'count': 100, 'page' : 1, 'orderby':'name:+'};
retval = _verify_parameters( request.GET, mandatory_parameters )
if retval:
return _redirect_parameters( 'recipes', request.GET, mandatory_parameters, build_id = build_id)
(filter_string, search_term, ordering_string) = _search_tuple(request, Recipe)
queryset = Recipe.objects.filter(layer_version__id__in=Layer_Version.objects.filter(build=build_id))
queryset = _get_queryset(Recipe, queryset, filter_string, search_term, ordering_string)
recipes = _build_page_range(Paginator(queryset, request.GET.get('count', 100)),request.GET.get('page', 1))
context = {
'objectname': 'recipes',
'build': Build.objects.filter(pk=build_id)[0],
'objects': recipes,
'tablecols':[
{
'name':'Recipe',
'qhelp':'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',
'orderfield': _get_toggle_order(request, "name"),
'ordericon':_get_toggle_order_icon(request, "name"),
},
{
'name':'Recipe version',
'qhelp':'The recipe version and revision',
},
{
'name':'Dependencies',
'qhelp':'Recipe build-time dependencies (other recipes)',
'clclass': 'depends_on', 'hidden': 1,
},
{
'name':'Reverse dependencies',
'qhelp':'Recipe build-time reverse dependencies (i.e. which other recipes depend on this recipe)',
'clclass': 'depends_by', 'hidden': 1,
},
{
'name':'Recipe file',
'qhelp':'Location in disk of the recipe .bb file',
'orderfield': _get_toggle_order(request, "file_path"),
'ordericon':_get_toggle_order_icon(request, "file_path"),
'clclass': 'recipe_file', 'hidden': 0,
},
{
'name':'Section',
'qhelp':'The section in which recipes should be categorised',
'orderfield': _get_toggle_order(request, "section"),
'ordericon':_get_toggle_order_icon(request, "section"),
'clclass': 'recipe_section', 'hidden': 0,
},
{
'name':'License',
'qhelp':'The list of source licenses for the recipe. Separate license names using | (pipe) means there is a choice between licenses. Separate license names using & (ampersand) means multiple licenses exist that cover different parts of the source',
'orderfield': _get_toggle_order(request, "license"),
'ordericon':_get_toggle_order_icon(request, "license"),
'clclass': 'recipe_license', 'hidden': 0,
},
{
'name':'Layer',
'qhelp':'The name of the layer providing the recipe',
'orderfield': _get_toggle_order(request, "layer_version__layer__name"),
'ordericon':_get_toggle_order_icon(request, "layer_version__layer__name"),
'clclass': 'layer_version__layer__name', 'hidden': 0,
},
{
'name':'Layer branch',
'qhelp':'The Git branch of the layer providing the recipe',
'orderfield': _get_toggle_order(request, "layer_version__branch"),
'ordericon':_get_toggle_order_icon(request, "layer_version__branch"),
'clclass': 'layer_version__branch', 'hidden': 1,
},
{
'name':'Layer commit',
'qhelp':'The Git commit of the layer providing the recipe',
'clclass': 'layer_version__layer__commit', 'hidden': 1,
},
{
'name':'Layer directory',
'qhelp':'Location in disk of the layer providing the recipe',
'orderfield': _get_toggle_order(request, "layer_version__layer__local_path"),
'ordericon':_get_toggle_order_icon(request, "layer_version__layer__local_path"),
'clclass': 'layer_version__layer__local_path', 'hidden': 1,
},
]
}
return render(request, template, context)
def configuration(request, build_id):
template = 'configuration.html'
variables = Variable.objects.filter(build=build_id)
BB_VERSION=variables.filter(variable_name='BB_VERSION')[0].variable_value
BUILD_SYS=variables.filter(variable_name='BUILD_SYS')[0].variable_value
NATIVELSBSTRING=variables.filter(variable_name='NATIVELSBSTRING')[0].variable_value
TARGET_SYS=variables.filter(variable_name='TARGET_SYS')[0].variable_value
MACHINE=variables.filter(variable_name='MACHINE')[0].variable_value
DISTRO=variables.filter(variable_name='DISTRO')[0].variable_value
DISTRO_VERSION=variables.filter(variable_name='DISTRO_VERSION')[0].variable_value
TUNE_FEATURES=variables.filter(variable_name='TUNE_FEATURES')[0].variable_value
TARGET_FPU=variables.filter(variable_name='TARGET_FPU')[0].variable_value
targets = Target.objects.filter(build=build_id)
context = {
'objectname': 'configuration',
'object_search_display':'variables',
'filter_search_display':'variables',
'build': Build.objects.filter(pk=build_id)[0],
'BB_VERSION':BB_VERSION,
'BUILD_SYS':BUILD_SYS,
'NATIVELSBSTRING':NATIVELSBSTRING,
'TARGET_SYS':TARGET_SYS,
'MACHINE':MACHINE,
'DISTRO':DISTRO,
'DISTRO_VERSION':DISTRO_VERSION,
'TUNE_FEATURES':TUNE_FEATURES,
'TARGET_FPU':TARGET_FPU,
'targets':targets,
}
return render(request, template, context)
def configvars(request, build_id):
template = 'configvars.html'
mandatory_parameters = { 'count': 100, 'page' : 1, 'orderby':'variable_name:+', 'filter':'description__regex:.+'};
retval = _verify_parameters( request.GET, mandatory_parameters )
(filter_string, search_term, ordering_string) = _search_tuple(request, Variable)
if retval:
# if new search, clear the default filter
if search_term and len(search_term):
mandatory_parameters['filter']=''
return _redirect_parameters( 'configvars', request.GET, mandatory_parameters, build_id = build_id)
queryset = Variable.objects.filter(build=build_id).exclude(variable_name__istartswith='B_').exclude(variable_name__istartswith='do_')
queryset_with_search = _get_queryset(Variable, queryset, None, search_term, ordering_string).exclude(variable_value='',vhistory__file_name__isnull=True)
queryset = _get_queryset(Variable, queryset, filter_string, search_term, ordering_string)
# remove records where the value is empty AND there are no history files
queryset = queryset.exclude(variable_value='',vhistory__file_name__isnull=True)
variables = _build_page_range(Paginator(queryset, request.GET.get('count', 50)), request.GET.get('page', 1))
file_filter= search_term + ":"
if filter_string.find('conf/local.conf') > 0:
file_filter += 'conf/local.conf'
if filter_string.find('conf/bblayers.conf') > 0:
file_filter += 'conf/bblayers.conf'
if filter_string.find('conf/machine/') > 0:
file_filter += 'conf/machine/'
if filter_string.find('conf/distro/') > 0:
file_filter += 'conf/distro/'
if filter_string.find('/bitbake.conf') > 0:
file_filter += '/bitbake.conf'
context = {
'objectname': 'configvars',
'object_search_display':'BitBake variables',
'filter_search_display':'variables',
'file_filter': file_filter,
'build': Build.objects.filter(pk=build_id)[0],
'objects' : variables,
'total_count':queryset_with_search.count(),
'search_term':search_term,
# Specifies the display of columns for the table, appearance in "Edit columns" box, toggling default show/hide, and specifying filters for columns
'tablecols' : [
{'name': 'Variable ',
'qhelp': "BitBake is a generic task executor that considers a list of tasks with dependencies and handles metadata that consists of variables in a certain format that get passed to the tasks",
'dclass' : "span3",
'orderfield': _get_toggle_order(request, "variable_name"),
'ordericon':_get_toggle_order_icon(request, "variable_name"),
},
{'name': 'Value ',
'qhelp': "The value assigned to the variable",
'dclass': "span4",
'orderfield': _get_toggle_order(request, "variable_value"),
'ordericon':_get_toggle_order_icon(request, "variable_value"),
},
{'name': 'Set in file',
'qhelp': "The last configuration file that touched the variable value",
'clclass': 'file', 'hidden' : 0,
'dclass': "span6",
'orderfield': _get_toggle_order(request, "vhistory__file_name"),
'ordericon':_get_toggle_order_icon(request, "vhistory__file_name"),
'filter' : {
'class' : 'vhistory__file_name',
'label': 'Show:',
'options' : [
('Local configuration variables', 'vhistory__file_name__regex:conf/(local|bblayers).conf', queryset_with_search.filter(vhistory__file_name__regex='conf/(local|bblayers).conf').count(), 'Select this filter to see variables set by the <code>local.conf</code> and <code>bblayers.conf</code> configuration files inside the <code>/build/conf/</code> directory'),
('Machine configuration variables', 'vhistory__file_name__contains:conf/machine/',queryset_with_search.filter(vhistory__file_name__contains='conf/machine').count(), 'Select this filter to see variables set by the configuration file(s) inside your layers <code>/conf/machine/</code> directory'),
('Distro configuration variables', 'vhistory__file_name__contains:conf/distro/',queryset_with_search.filter(vhistory__file_name__contains='conf/distro').count(), 'Select this filter to see variables set by the configuration file(s) inside your layers <code>/conf/distro/</code> directory'),
('Layer configuration variables', 'vhistory__file_name__contains:conf/layer.conf',queryset_with_search.filter(vhistory__file_name__contains='conf/layer.conf').count(), 'Select this filter to see variables set by the <code>layer.conf</code> configuration file inside your layers'),
('bitbake.conf variables', 'vhistory__file_name__contains:/bitbake.conf',queryset_with_search.filter(vhistory__file_name__contains='/bitbake.conf').count(), 'Select this filter to see variables set by the <code>bitbake.conf</code> configuration file'),
]
},
},
{'name': 'Description ',
'qhelp': "A brief explanation of the variable",
'clclass': 'description', 'hidden' : 0,
'dclass': "span5",
'filter' : {
'class' : 'description',
'label': 'Show:',
'options' : [
('Variables with description', 'description__regex:.+', queryset_with_search.filter(description__regex='.+').count(), 'We provide descriptions for the most common BiBake variables, so this filter effectively shows you a curated list of variables put together by the Yocto Project maintainers. The curated list lives in <code>/meta/conf/documentation.conf</code> inside your <code>poky</code> directory'),
]
},
},
],
}
return render(request, template, context)
def bpackage(request, build_id):
template = 'bpackage.html'
mandatory_parameters = { 'count': 100, 'page' : 1, 'orderby':'name:+'};
retval = _verify_parameters( request.GET, mandatory_parameters )
if retval:
return _redirect_parameters( 'packages', request.GET, mandatory_parameters, build_id = build_id)
(filter_string, search_term, ordering_string) = _search_tuple(request, Package)
queryset = Package.objects.filter(build = build_id).filter(size__gte=0)
queryset = _get_queryset(Package, queryset, filter_string, search_term, ordering_string)
packages = _build_page_range(Paginator(queryset, request.GET.get('count', 100)),request.GET.get('page', 1))
context = {
'objectname': 'packages built',
'build': Build.objects.filter(pk=build_id)[0],
'objects' : packages,
'tablecols':[
{
'name':'Package',
'qhelp':'Packaged output resulting from building a recipe',
'orderfield': _get_toggle_order(request, "name"),
'ordericon':_get_toggle_order_icon(request, "name"),
},
{
'name':'Package version',
'qhelp':'The package version and revision',
},
{
'name':'Size',
'qhelp':'The size of the package',
'orderfield': _get_toggle_order(request, "size", True),
'ordericon':_get_toggle_order_icon(request, "size"),
'clclass': 'size', 'hidden': 0,
},
{
'name':'License',
'qhelp':'The license under which the package is distributed. Separate license names using | (pipe) means there is a choice between licenses. Separate license names using & (ampersand) means multiple licenses exist that cover different parts of the source',
'orderfield': _get_toggle_order(request, "license"),
'ordericon':_get_toggle_order_icon(request, "license"),
'clclass': 'license', 'hidden': 1,
},
{
'name':'Recipe',
'qhelp':'The name of the recipe building the package',
'orderfield': _get_toggle_order(request, "recipe__name"),
'ordericon':_get_toggle_order_icon(request, "recipe__name"),
'clclass': 'recipe__name', 'hidden': 0,
},
{
'name':'Recipe version',
'qhelp':'Version and revision of the recipe building the package',
'clclass': 'recipe__version', 'hidden': 1,
},
{
'name':'Layer',
'qhelp':'The name of the layer providing the recipe that builds the package',
'orderfield': _get_toggle_order(request, "recipe__layer_version__layer__name"),
'ordericon':_get_toggle_order_icon(request, "recipe__layer_version__layer__name"),
'clclass': 'recipe__layer_version__layer__name', 'hidden': 1,
},
{
'name':'Layer branch',
'qhelp':'The Git branch of the layer providing the recipe that builds the package',
'orderfield': _get_toggle_order(request, "recipe__layer_version__branch"),
'ordericon':_get_toggle_order_icon(request, "recipe__layer_version__branch"),
'clclass': 'recipe__layer_version__branch', 'hidden': 1,
},
{
'name':'Layer commit',
'qhelp':'The Git commit of the layer providing the recipe that builds the package',
'clclass': 'recipe__layer_version__layer__commit', 'hidden': 1,
},
{
'name':'Layer directory',
'qhelp':'Location in disk of the layer providing the recipe that builds the package',
'orderfield': _get_toggle_order(request, "recipe__layer_version__layer__local_path"),
'ordericon':_get_toggle_order_icon(request, "recipe__layer_version__layer__local_path"),
'clclass': 'recipe__layer_version__layer__local_path', 'hidden': 1,
},
]
}
return render(request, template, context)
def bfile(request, build_id, package_id):
template = 'bfile.html'
files = Package_File.objects.filter(package = package_id)
context = {'build': Build.objects.filter(pk=build_id)[0], 'objects' : files}
return render(request, template, context)
def tpackage(request, build_id, target_id):
template = 'package.html'
packages = map(lambda x: x.package, list(Target_Installed_Package.objects.filter(target=target_id)))
context = {'build': Build.objects.filter(pk=build_id)[0], 'objects' : packages}
return render(request, template, context)
def layer(request):
template = 'layer.html'
layer_info = Layer.objects.all()
for li in layer_info:
li.versions = Layer_Version.objects.filter(layer = li)
for liv in li.versions:
liv.count = Recipe.objects.filter(layer_version__id = liv.id).count()
context = {'objects': layer_info}
return render(request, template, context)
def layer_versions_recipes(request, layerversion_id):
template = 'recipe.html'
recipes = Recipe.objects.filter(layer_version__id = layerversion_id)
context = {'objects': recipes,
'layer_version' : Layer_Version.objects.filter( id = layerversion_id )[0]
}
return render(request, template, context)
# A set of dependency types valid for both included and built package views
OTHER_DEPENDS_BASE = [
Package_Dependency.TYPE_RSUGGESTS,
Package_Dependency.TYPE_RPROVIDES,
Package_Dependency.TYPE_RREPLACES,
Package_Dependency.TYPE_RCONFLICTS,
]
# value for invalid row id
INVALID_KEY = -1
"""
Given a package id, target_id retrieves two sets of this image and package's
dependencies. The return value is a dictionary consisting of two other
lists: a list of 'runtime' dependencies, that is, having RDEPENDS
values in source package's recipe, and a list of other dependencies, that is
the list of possible recipe variables as found in OTHER_DEPENDS_BASE plus
the RRECOMENDS or TRECOMENDS value.
The lists are built in the sort order specified for the package runtime
dependency views.
"""
def _get_package_dependencies(package_id, target_id = INVALID_KEY):
runtime_deps = []
other_deps = []
other_depends_types = OTHER_DEPENDS_BASE
if target_id != INVALID_KEY :
rdepends_type = Package_Dependency.TYPE_TRDEPENDS
other_depends_types += [Package_Dependency.TYPE_TRECOMMENDS]
else :
rdepends_type = Package_Dependency.TYPE_RDEPENDS
other_depends_types += [Package_Dependency.TYPE_RRECOMMENDS]
package = Package.objects.get(pk=package_id)
if target_id != INVALID_KEY :
alldeps = package.package_dependencies_source.filter(target_id__exact = target_id)
else :
alldeps = package.package_dependencies_source.all()
for idep in alldeps:
dep_package = Package.objects.get(pk=idep.depends_on_id)
dep_entry = Package_Dependency.DEPENDS_DICT[idep.dep_type]
if dep_package.version == '' :
version = ''
else :
version = dep_package.version + "-" + dep_package.revision
installed = False
if target_id != INVALID_KEY :
if Target_Installed_Package.objects.filter(target_id__exact = target_id, package_id__exact = dep_package.id).count() > 0:
installed = True
dep = {
'name' : dep_package.name,
'version' : version,
'size' : dep_package.size,
'dep_type' : idep.dep_type,
'dep_type_display' : dep_entry[0].capitalize(),
'dep_type_help' : dep_entry[1] % (dep_package.name, package.name),
'depends_on_id' : dep_package.id,
'installed' : installed,
}
if target_id != INVALID_KEY:
dep['alias'] = _get_package_alias(dep_package)
if idep.dep_type == rdepends_type :
runtime_deps.append(dep)
elif idep.dep_type in other_depends_types :
other_deps.append(dep)
rdep_sorted = sorted(runtime_deps, key=lambda k: k['name'])
odep_sorted = sorted(
sorted(other_deps, key=lambda k: k['name']),
key=lambda k: k['dep_type'])
retvalues = {'runtime_deps' : rdep_sorted, 'other_deps' : odep_sorted}
return retvalues
# Return the count of packages dependent on package for this target_id image
def _get_package_reverse_dep_count(package, target_id):
return package.package_dependencies_target.filter(target_id__exact=target_id, dep_type__exact = Package_Dependency.TYPE_TRDEPENDS).count()
# Return the count of the packages that this package_id is dependent on.
# Use one of the two RDEPENDS types, either TRDEPENDS if the package was
# installed, or else RDEPENDS if only built.
def _get_package_dependency_count(package, target_id, is_installed):
if is_installed :
return package.package_dependencies_source.filter(target_id__exact = target_id,
dep_type__exact = Package_Dependency.TYPE_TRDEPENDS).count()
else :
return package.package_dependencies_source.filter(dep_type__exact = Package_Dependency.TYPE_RDEPENDS).count()
def _get_package_alias(package):
alias = package.installed_name
if alias != None and alias != '' and alias != package.name:
return alias
else:
return ''
def _get_fullpackagespec(package):
r = package.name
version_good = package.version != None and package.version != ''
revision_good = package.revision != None and package.revision != ''
if version_good or revision_good:
r += '_'
if version_good:
r += package.version
if revision_good:
r += '-'
if revision_good:
r += package.revision
return r
def package_built_detail(request, build_id, package_id):
template = "package_built_detail.html"
if Build.objects.filter(pk=build_id).count() == 0 :
return redirect(builds)
package = Package.objects.filter(pk=package_id)[0]
package.fullpackagespec = _get_fullpackagespec(package)
context = {
'build' : Build.objects.filter(pk=build_id)[0],
'package' : package,
'dependency_count' : _get_package_dependency_count(package, -1, False),
}
return render(request, template, context)
def package_built_dependencies(request, build_id, package_id):
template = "package_built_dependencies.html"
if Build.objects.filter(pk=build_id).count() == 0 :
return redirect(builds)
package = Package.objects.filter(pk=package_id)[0]
package.fullpackagespec = _get_fullpackagespec(package)
dependencies = _get_package_dependencies(package_id)
context = {
'build' : Build.objects.filter(pk=build_id)[0],
'package' : package,
'runtime_deps' : dependencies['runtime_deps'],
'other_deps' : dependencies['other_deps'],
'dependency_count' : _get_package_dependency_count(package, -1, False)
}
return render(request, template, context)
def package_included_detail(request, build_id, target_id, package_id):
template = "package_included_detail.html"
if Build.objects.filter(pk=build_id).count() == 0 :
return redirect(builds)
package = Package.objects.filter(pk=package_id)[0]
package.fullpackagespec = _get_fullpackagespec(package)
package.alias = _get_package_alias(package)
target = Target.objects.filter(pk=target_id)[0]
context = {
'build' : Build.objects.filter(pk=build_id)[0],
'target' : target,
'package' : package,
'reverse_count' : _get_package_reverse_dep_count(package, target_id),
'dependency_count' : _get_package_dependency_count(package, target_id, True)
}
return render(request, template, context)
def package_included_dependencies(request, build_id, target_id, package_id):
template = "package_included_dependencies.html"
if Build.objects.filter(pk=build_id).count() == 0 :
return redirect(builds)
package = Package.objects.filter(pk=package_id)[0]
package.fullpackagespec = _get_fullpackagespec(package)
package.alias = _get_package_alias(package)
target = Target.objects.filter(pk=target_id)[0]
dependencies = _get_package_dependencies(package_id, target_id)
context = {
'build' : Build.objects.filter(pk=build_id)[0],
'package' : package,
'target' : target,
'runtime_deps' : dependencies['runtime_deps'],
'other_deps' : dependencies['other_deps'],
'reverse_count' : _get_package_reverse_dep_count(package, target_id),
'dependency_count' : _get_package_dependency_count(package, target_id, True)
}
return render(request, template, context)
def package_included_reverse_dependencies(request, build_id, target_id, package_id):
template = "package_included_reverse_dependencies.html"
if Build.objects.filter(pk=build_id).count() == 0 :
return redirect(builds)
package = Package.objects.filter(pk=package_id)[0]
package.fullpackagespec = _get_fullpackagespec(package)
package.alias = _get_package_alias(package)
target = Target.objects.filter(pk=target_id)[0]
reverse_deps = []
alldeps = package.package_dependencies_target.filter(target_id__exact=target_id)
for idep in alldeps:
dep_package = Package.objects.get(pk=idep.package_id)
version = dep_package.version
if version != '' :
version += '-' + dep_package.revision
dep = {
'name' : dep_package.name,
'alias' : _get_package_alias(dep_package),
'dependent_id' : dep_package.id,
'version' : version,
'size' : dep_package.size
}
if idep.dep_type == Package_Dependency.TYPE_TRDEPENDS :
reverse_deps.append(dep)
context = {
'build' : Build.objects.filter(pk=build_id)[0],
'package' : package,
'target' : target,
'reverse_deps' : reverse_deps,
'reverse_count' : _get_package_reverse_dep_count(package, target_id),
'dependency_count' : _get_package_dependency_count(package, target_id, True)
}
return render(request, template, context)
def image_information_dir(request, build_id, target_id, packagefile_id):
# stubbed for now
return redirect(builds)
|