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
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
|
#
# 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
import HTMLParser
from django.db.models import Q, Sum
from django.db import IntegrityError
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, BuildArtifact
from django.views.decorators.cache import cache_control
from django.core.urlresolvers import reverse
from django.core.exceptions import MultipleObjectsReturned
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.http import HttpResponseBadRequest, HttpResponseNotFound
from django.utils import timezone
from django.utils.html import escape
from datetime import timedelta
from django.utils import formats
from toastergui.templatetags.projecttags import json as jsonfilter
import json
# all new sessions should come through the landing page;
# determine in which mode we are running in, and redirect appropriately
def landing(request):
if toastermain.settings.MANAGED and Build.objects.count() == 0 and Project.objects.count() > 0:
return redirect(reverse('all-projects'), permanent = False)
if Build.objects.all().count() > 0:
return redirect(reverse('all-builds'), permanent = False)
return render(request, 'landing.html')
# returns a list for most recent builds; for use in the Project page, xhr_ updates, and other places, as needed
def _project_recent_build_list(prj):
return map(lambda x: {
"id": x.pk,
"targets" : map(lambda y: {"target": y.target, "task": y.task }, x.brtarget_set.all()),
"status": x.get_state_display(),
"errors": map(lambda y: {"type": y.errtype, "msg": y.errmsg, "tb": y.traceback}, x.brerror_set.exclude(errmsg__contains="Command Failed")),
"build" : map( lambda y: {"id": y.pk,
"status": y.get_outcome_display(),
"completed_on" : y.completed_on.strftime('%s')+"000",
"build_time" : (y.completed_on - y.started_on).total_seconds(),
"build_page_url" : reverse('builddashboard', args=(y.pk,)),
'build_time_page_url': reverse('buildtime', args=(y.pk,)),
"errors": y.errors_no,
"warnings": y.warnings_no,
"completeper": y.completeper(),
"eta": y.eta().strftime('%s')+"000"}, Build.objects.filter(buildrequest = x)),
}, list(prj.buildrequest_set.filter(Q(state__lt=BuildRequest.REQ_COMPLETED) or Q(state=BuildRequest.REQ_DELETED)).order_by("-pk")) +
list(prj.buildrequest_set.filter(state__in=[BuildRequest.REQ_COMPLETED, BuildRequest.REQ_FAILED]).order_by("-pk")[:3]))
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
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] = urllib.unquote(str(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(operator.and_, map(lambda x: __get_q_for_val(x, querydict[x]), [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: " + input + " -> " + str(input_list)
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)
print "search objects", search_object
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, ordering_secondary=''):
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 column == re.sub('-','',ordering_secondary):
ordering_secondary=''
if order.lower() == DESCENDING:
column = '-' + column
if ordering_secondary:
queryset = queryset.order_by(column, ordering_secondary)
else:
queryset = queryset.order_by(column)
# insure only distinct records (e.g. from multiple search hits) are returned
return queryset.distinct()
# returns the value of entries per page and the name of the applied sorting field.
# if the value is given explicitly as a GET parameter it will be the first selected,
# otherwise the cookie value will be used.
def _get_parameters_values(request, default_count, default_order):
pagesize = request.GET.get('count', request.COOKIES.get('count', default_count))
orderby = request.GET.get('orderby', request.COOKIES.get('orderby', default_order))
return (pagesize, orderby)
# set cookies for parameters. this is usefull in case parameters are set
# manually from the GET values of the link
def _save_parameters_cookies(response, pagesize, orderby, request):
html_parser = HTMLParser.HTMLParser()
response.set_cookie(key='count', value=pagesize, path=request.path)
response.set_cookie(key='orderby', value=html_parser.unescape(orderby), path=request.path)
return response
##
# 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.get( pk = build_id );
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
targetHasNoImages = False
for t in tgts:
elem = { }
elem[ 'target' ] = t
if ( t.is_image ):
hasImages = True
npkg = 0
pkgsz = 0
package = None
for package in Package.objects.filter(id__in = [x.package_id for x in t.target_installed_package_set.all()]):
pkgsz = pkgsz + package.size
if ( package.installed_name ):
npkg = npkg + 1
elem[ 'npkg' ] = npkg
elem[ 'pkgsz' ] = pkgsz
ti = Target_Image_File.objects.filter( target_id = t.id )
imageFiles = [ ]
for i in ti:
ndx = i.file_name.rfind( '/' )
if ( ndx < 0 ):
ndx = 0;
f = i.file_name[ ndx + 1: ]
imageFiles.append({ 'id': i.id, 'path': f, 'size' : i.file_size })
if ( t.is_image and
(( len( imageFiles ) <= 0 ) or ( len( t.license_manifest_path ) <= 0 ))):
targetHasNoImages = True
elem[ 'imageFiles' ] = imageFiles
elem[ 'targetHasNoImages' ] = targetHasNoImages
targets.append( elem )
##
# how many packages in this build - ignore anonymous ones
#
packageCount = 0
packages = Package.objects.filter( build_id = build_id )
for p in packages:
if ( p.installed_name ):
packageCount = packageCount + 1
logmessages = list(LogMessage.objects.filter( build = build_id ))
context = {
'build' : build,
'hasImages' : hasImages,
'ntargets' : ntargets,
'targets' : targets,
'recipecount' : recipeCount,
'packagecount' : packageCount,
'logmessages' : logmessages,
}
return render( request, template, context )
def generateCoveredList( task ):
revList = _find_task_revdep( task );
list = { };
for t in revList:
if ( t.outcome == Task.OUTCOME_COVERED ):
list.update( generateCoveredList( t ));
else:
list[ t.task_name ] = t;
return( list );
def task( request, build_id, task_id ):
template = "task.html"
tasks = Task.objects.filter( pk=task_id )
if tasks.count( ) == 0:
return redirect( builds )
task = tasks[ 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 ))
coveredBy = '';
if ( task.outcome == Task.OUTCOME_COVERED ):
dict = generateCoveredList( task )
coveredBy = [ ]
for name, t in dict.items( ):
coveredBy.append( t )
log_head = ''
log_body = ''
if task.outcome == task.OUTCOME_FAILED:
pass
uri_list= [ ]
variables = Variable.objects.filter(build=build_id)
v=variables.filter(variable_name='SSTATE_DIR')
if v.count > 0:
uri_list.append(v[0].variable_value)
v=variables.filter(variable_name='SSTATE_MIRRORS')
if (v.count > 0):
for mirror in v[0].variable_value.split('\\n'):
s=re.sub('.* ','',mirror.strip(' \t\n\r'))
if len(s): uri_list.append(s)
context = {
'build' : Build.objects.filter( pk = build_id )[ 0 ],
'object' : task,
'task' : task,
'covered_by' : coveredBy,
'deps' : dependencies,
'rdeps' : reverse_dependencies,
'log_head' : log_head,
'log_body' : log_body,
'showing_matches' : False,
'uri_list' : uri_list,
}
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).exclude(
order__isnull=True).exclude(outcome=Task.OUTCOME_NA).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.get(pk=recipe_id)
layer_version = Layer_Version.objects.get(pk=object.layer_version_id)
layer = Layer.objects.get(pk=layer_version.layer_id)
tasks = Task.objects.filter(recipe_id = recipe_id, build_id = build_id).exclude(order__isnull=True).exclude(task_name__endswith='_setscene').exclude(outcome=Task.OUTCOME_NA)
packages = Package.objects.filter(recipe_id = recipe_id).filter(build_id = build_id).filter(size__gte=0)
context = {
'build' : Build.objects.get(pk=build_id),
'object' : object,
'layer_version' : layer_version,
'layer' : layer,
'tasks' : tasks,
'packages': packages,
}
return render(request, template, context)
def target_common( request, build_id, target_id, variant ):
template = "target.html"
(pagesize, orderby) = _get_parameters_values(request, 25, 'name:+')
mandatory_parameters = { 'count': pagesize, 'page' : 1, 'orderby': orderby }
retval = _verify_parameters( request.GET, mandatory_parameters )
if retval:
return _redirect_parameters(
variant, 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, 'name' )
packages = _build_page_range( Paginator(queryset, pagesize), request.GET.get( 'page', 1 ))
build = Build.objects.get( pk = build_id )
# 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 )
tc_package = {
'name' : 'Package',
'qhelp' : 'Packaged output resulting from building a recipe included in this image',
'orderfield' : _get_toggle_order( request, "name" ),
'ordericon' : _get_toggle_order_icon( request, "name" ),
}
tc_packageVersion = {
'name' : 'Package version',
'qhelp' : 'The package version and revision',
}
tc_size = {
'name' : 'Size',
'qhelp' : 'The size of the package',
'orderfield' : _get_toggle_order( request, "size", True ),
'ordericon' : _get_toggle_order_icon( request, "size" ),
'orderkey' : 'size',
'clclass' : 'size',
'dclass' : 'span2',
}
if ( variant == 'target' ):
tc_size[ "hidden" ] = 0
else:
tc_size[ "hidden" ] = 1
tc_sizePercentage = {
'name' : 'Size over total (%)',
'qhelp' : 'Proportion of the overall size represented by this package',
'clclass' : 'size_over_total',
'hidden' : 1,
}
tc_license = {
'name' : 'License',
'qhelp' : 'The license under which the package is distributed. Separate license names u\
sing | (pipe) means there is a choice between licenses. Separate license names using & (ampersand) m\
eans multiple licenses exist that cover different parts of the source',
'orderfield' : _get_toggle_order( request, "license" ),
'ordericon' : _get_toggle_order_icon( request, "license" ),
'orderkey' : 'license',
'clclass' : 'license',
}
if ( variant == 'target' ):
tc_license[ "hidden" ] = 1
else:
tc_license[ "hidden" ] = 0
tc_dependencies = {
'name' : 'Dependencies',
'qhelp' : "Package runtime dependencies (other packages)",
'clclass' : 'depends',
}
if ( variant == 'target' ):
tc_dependencies[ "hidden" ] = 0
else:
tc_dependencies[ "hidden" ] = 1
tc_rdependencies = {
'name' : 'Reverse dependencies',
'qhelp' : 'Package run-time reverse dependencies (i.e. which other packages depend on this package',
'clclass' : 'brought_in_by',
}
if ( variant == 'target' ):
tc_rdependencies[ "hidden" ] = 0
else:
tc_rdependencies[ "hidden" ] = 1
tc_recipe = {
'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,
}
tc_recipeVersion = {
'name' : 'Recipe version',
'qhelp' : 'Version and revision of the recipe building the package',
'clclass' : 'recipe_version',
'hidden' : 1,
}
tc_layer = {
'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,
}
tc_layerBranch = {
'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,
}
tc_layerCommit = {
'name' : 'Layer commit',
'qhelp' : 'The Git commit of the layer providing the recipe that builds the package',
'clclass' : 'layer_commit',
'hidden' : 1,
}
context = {
'objectname': variant,
'build' : build,
'target' : Target.objects.filter( pk = target_id )[ 0 ],
'objects' : packages,
'packages_sum' : packages_sum[ 'installed_size__sum' ],
'object_search_display': "packages included",
'default_orderby' : orderby,
'tablecols' : [
tc_package,
tc_packageVersion,
tc_license,
tc_size,
tc_sizePercentage,
tc_dependencies,
tc_rdependencies,
tc_recipe,
tc_recipeVersion,
tc_layer,
tc_layerBranch,
tc_layerCommit,
]
}
if not toastermain.settings.MANAGED or build.project is None:
tc_layerDir = {
'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,
}
context['tablecols'].append(tc_layerDir)
response = render(request, template, context)
_save_parameters_cookies(response, pagesize, orderby, request)
return response
def target( request, build_id, target_id ):
return( target_common( request, build_id, target_id, "target" ))
def targetpkg( request, build_id, target_id ):
return( target_common( request, build_id, target_id, "targetpkg" ))
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
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
entry['size'] = filtered_filesizeformat(o.size)
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 Exception as e:
print "Exception ", e
import traceback
traceback.print_exc(e)
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).replace('</', '<\\/')
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.get(pk=build_id),
'target': Target.objects.get(pk=target_id),
'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):
if (p.depends_on.order > 0) and (p.depends_on.outcome != Task.OUTCOME_NA):
tp.append(p.depends_on);
return tp
def _find_task_revdep(task):
tp = []
for p in Task_Dependency.objects.filter(depends_on=task):
if (p.task.order > 0) and (p.task.outcome != Task.OUTCOME_NA):
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, task_anchor):
# 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
anchor = request.GET.get('anchor', '')
if not anchor:
anchor=task_anchor
# default ordering depends on variant
if 'buildtime' == variant:
title_variant='Time'
object_search_display="time data"
filter_search_display="tasks"
(pagesize, orderby) = _get_parameters_values(request, 25, 'elapsed_time:-')
elif 'diskio' == variant:
title_variant='Disk I/O'
object_search_display="disk I/O data"
filter_search_display="tasks"
(pagesize, orderby) = _get_parameters_values(request, 25, 'disk_io:-')
elif 'cpuusage' == variant:
title_variant='CPU usage'
object_search_display="CPU usage data"
filter_search_display="tasks"
(pagesize, orderby) = _get_parameters_values(request, 25, 'cpu_usage:-')
else :
title_variant='Tasks'
object_search_display="tasks"
filter_search_display="tasks"
(pagesize, orderby) = _get_parameters_values(request, 25, 'order:+')
mandatory_parameters = { 'count': pagesize, 'page' : 1, 'orderby': orderby }
template = 'tasks.html'
retval = _verify_parameters( request.GET, mandatory_parameters )
if retval:
if task_anchor:
mandatory_parameters['anchor']=task_anchor
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).exclude(order__isnull=True).exclude(outcome=Task.OUTCOME_NA)
queryset_with_search = _get_queryset(Task, queryset_all, None , search_term, ordering_string, 'order')
if ordering_string.startswith('outcome'):
queryset = _get_queryset(Task, queryset_all, filter_string, search_term, 'order:+', 'order')
queryset = sorted(queryset, key=lambda ur: (ur.outcome_text), reverse=ordering_string.endswith('-'))
elif ordering_string.startswith('sstate_result'):
queryset = _get_queryset(Task, queryset_all, filter_string, search_term, 'order:+', 'order')
queryset = sorted(queryset, key=lambda ur: (ur.sstate_text), reverse=ordering_string.endswith('-'))
else:
queryset = _get_queryset(Task, queryset_all, filter_string, search_term, ordering_string, 'order')
# compute the anchor's page
if anchor:
request.GET = request.GET.copy()
del request.GET['anchor']
i=0
a=int(anchor)
count_per_page=int(pagesize)
for task in queryset.iterator():
if a == task.order:
new_page= (i / count_per_page ) + 1
request.GET.__setitem__('page', new_page)
mandatory_parameters['page']=new_page
return _redirect_parameters( variant, request.GET, mandatory_parameters, build_id = build_id)
i += 1
tasks = _build_page_range(Paginator(queryset, pagesize),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,
'orderkey' : 'order',
'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',
'orderkey' : 'recipe__name',
'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"),
'orderkey' : 'task_name',
}
tc_executed={
'name':'Executed',
'qhelp':"This value tells you if a task had to run (executed) in order to generate the task output, 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"),
'orderkey' : '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 or failed. The column 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"),
'orderkey' : '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 restore 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_EMPTY).count(), 'Empty tasks have no executable content'),
]
}
}
tc_log={
'name':'Log',
'qhelp':'Path to the task log file',
'orderfield': _get_toggle_order(request, "logfile"),
'ordericon':_get_toggle_order_icon(request, "logfile"),
'orderkey' : '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 reports 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"),
'orderkey' : 'sstate_result',
'filter' : {
'class' : 'cache_attempt',
'label': 'Show:',
'options' : [
('Tasks with cache attempts', 'sstate_result__gt:%d'%Task.SSTATE_NA, queryset_with_search.filter(sstate_result__gt=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 in seconds',
'orderfield': _get_toggle_order(request, "elapsed_time", True),
'ordericon':_get_toggle_order_icon(request, "elapsed_time"),
'orderkey' : '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':'The percentage of task CPU utilization',
'orderfield': _get_toggle_order(request, "cpu_usage", True),
'ordericon':_get_toggle_order_icon(request, "cpu_usage"),
'orderkey' : '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"),
'orderkey' : 'disk_io',
'clclass': 'disk_io', 'hidden' : 1,
}
if 'diskio' == variant: tc_diskio['hidden']='0'; del tc_diskio['clclass']; tc_cache['hidden']='1';
build = Build.objects.get(pk=build_id)
context = { 'objectname': variant,
'object_search_display': object_search_display,
'filter_search_display': filter_search_display,
'title': title_variant,
'build': build,
'objects': tasks,
'default_orderby' : orderby,
'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,
]}
if not toastermain.settings.MANAGED or build.project is None:
context['tablecols'].append(tc_log)
response = render(request, template, context)
_save_parameters_cookies(response, pagesize, orderby, request)
return response
def tasks(request, build_id):
return tasks_common(request, build_id, 'tasks', '')
def tasks_task(request, build_id, task_id):
return tasks_common(request, build_id, 'tasks', task_id)
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'
(pagesize, orderby) = _get_parameters_values(request, 100, 'name:+')
mandatory_parameters = { 'count': pagesize, 'page' : 1, 'orderby' : orderby }
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, 'name')
recipes = _build_page_range(Paginator(queryset, pagesize),request.GET.get('page', 1))
# prefetch the forward and reverse recipe dependencies
deps = { }; revs = { }
queryset_dependency=Recipe_Dependency.objects.filter(recipe__layer_version__build_id = build_id)
for recipe in recipes:
deplist = [ ]
for recipe_dep in [x for x in queryset_dependency if x.recipe_id == recipe.id]:
deplist.append(recipe_dep)
deps[recipe.id] = deplist
revlist = [ ]
for recipe_dep in [x for x in queryset_dependency if x.depends_on_id == recipe.id]:
revlist.append(recipe_dep)
revs[recipe.id] = revlist
build = Build.objects.get(pk=build_id)
context = {
'objectname': 'recipes',
'build': build,
'objects': recipes,
'default_orderby' : 'name:+',
'recipe_deps' : deps,
'recipe_revs' : revs,
'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 (i.e. other recipes)',
'clclass': 'depends_on', 'hidden': 1,
},
{
'name':'Reverse dependencies',
'qhelp':'Recipe build-time reverse dependencies (i.e. the recipes that depend on this recipe)',
'clclass': 'depends_by', 'hidden': 1,
},
{
'name':'Recipe file',
'qhelp':'Path to the recipe .bb file',
'orderfield': _get_toggle_order(request, "file_path"),
'ordericon':_get_toggle_order_icon(request, "file_path"),
'orderkey' : 'file_path',
'clclass': 'recipe_file', 'hidden': 0,
},
{
'name':'Section',
'qhelp':'The section in which recipes should be categorized',
'orderfield': _get_toggle_order(request, "section"),
'ordericon':_get_toggle_order_icon(request, "section"),
'orderkey' : 'section',
'clclass': 'recipe_section', 'hidden': 0,
},
{
'name':'License',
'qhelp':'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',
'orderfield': _get_toggle_order(request, "license"),
'ordericon':_get_toggle_order_icon(request, "license"),
'orderkey' : '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"),
'orderkey' : '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"),
'orderkey' : '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,
},
]
}
if not toastermain.settings.MANAGED or build.project is None:
context['tablecols'].append(
{
'name':'Layer directory',
'qhelp':'Path to the layer prodiving the recipe',
'orderfield': _get_toggle_order(request, "layer_version__layer__local_path"),
'ordericon':_get_toggle_order_icon(request, "layer_version__layer__local_path"),
'orderkey' : 'layer_version__layer__local_path',
'clclass': 'layer_version__layer__local_path', 'hidden': 1,
})
response = render(request, template, context)
_save_parameters_cookies(response, pagesize, orderby, request)
return response
def configuration(request, build_id):
template = 'configuration.html'
variables = Variable.objects.filter(build=build_id)
def _get_variable_or_empty(variable_name):
from django.core.exceptions import ObjectDoesNotExist
try:
return variables.get(variable_name=variable_name).variable_value
except ObjectDoesNotExist:
return ''
BB_VERSION=_get_variable_or_empty(variable_name='BB_VERSION')
BUILD_SYS=_get_variable_or_empty(variable_name='BUILD_SYS')
NATIVELSBSTRING=_get_variable_or_empty(variable_name='NATIVELSBSTRING')
TARGET_SYS=_get_variable_or_empty(variable_name='TARGET_SYS')
MACHINE=_get_variable_or_empty(variable_name='MACHINE')
DISTRO=_get_variable_or_empty(variable_name='DISTRO')
DISTRO_VERSION=_get_variable_or_empty(variable_name='DISTRO_VERSION')
TUNE_FEATURES=_get_variable_or_empty(variable_name='TUNE_FEATURES')
TARGET_FPU=_get_variable_or_empty(variable_name='TARGET_FPU')
targets = Target.objects.filter(build=build_id)
context = {
'objectname': 'configuration',
'object_search_display':'variables',
'filter_search_display':'variables',
'build': Build.objects.get(pk=build_id),
'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'
(pagesize, orderby) = _get_parameters_values(request, 100, 'variable_name:+')
mandatory_parameters = { 'count': pagesize, 'page' : 1, 'orderby' : orderby, '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, 'variable_name').exclude(variable_value='',vhistory__file_name__isnull=True)
queryset = _get_queryset(Variable, queryset, filter_string, search_term, ordering_string, 'variable_name')
# 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, pagesize), request.GET.get('page', 1))
# show all matching files (not just the last one)
file_filter= search_term + ":"
if filter_string.find('/conf/') > 0:
file_filter += 'conf/(local|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'
build_dir=re.sub("/tmp/log/.*","",Build.objects.get(pk=build_id).cooker_log_path)
context = {
'objectname': 'configvars',
'object_search_display':'BitBake variables',
'filter_search_display':'variables',
'file_filter': file_filter,
'build': Build.objects.get(pk=build_id),
'objects' : variables,
'total_count':queryset_with_search.count(),
'default_orderby' : 'variable_name:+',
'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",
'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",
},
{'name': 'Set in file',
'qhelp': "The last configuration file that touched the variable value",
'clclass': 'file', 'hidden' : 0,
'orderkey' : 'vhistory__file_name',
'filter' : {
'class' : 'vhistory__file_name',
'label': 'Show:',
'options' : [
('Local configuration variables', 'vhistory__file_name__contains:'+build_dir+'/conf/',queryset_with_search.filter(vhistory__file_name__contains=build_dir+'/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': "span4",
'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 BitBake variables. The list of descriptions lives in <code>meta/conf/documentation.conf</code>'),
]
},
},
],
}
response = render(request, template, context)
_save_parameters_cookies(response, pagesize, orderby, request)
return response
def bpackage(request, build_id):
template = 'bpackage.html'
(pagesize, orderby) = _get_parameters_values(request, 100, 'name:+')
mandatory_parameters = { 'count' : pagesize, 'page' : 1, 'orderby' : orderby }
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, 'name')
packages = _build_page_range(Paginator(queryset, pagesize),request.GET.get('page', 1))
context = {
'objectname': 'packages built',
'build': Build.objects.get(pk=build_id),
'objects' : packages,
'default_orderby' : 'name:+',
'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"),
'orderkey' : 'size',
'clclass': 'size', 'hidden': 0,
'dclass' : 'span2',
},
{
'name':'License',
'qhelp':'The license under which the package is distributed. 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',
'orderfield': _get_toggle_order(request, "license"),
'ordericon':_get_toggle_order_icon(request, "license"),
'orderkey' : '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"),
'orderkey' : '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"),
'orderkey' : '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"),
'orderkey' : 'recipe__layer_version__layer__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':'Path to 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"),
'orderkey' : 'recipe__layer_version__layer__local_path',
'clclass': 'recipe__layer_version__layer__local_path', 'hidden': 1,
},
]
}
response = render(request, template, context)
_save_parameters_cookies(response, pagesize, orderby, request)
return response
def bfile(request, build_id, package_id):
template = 'bfile.html'
files = Package_File.objects.filter(package = package_id)
context = {'build': Build.objects.get(pk=build_id), '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.get(pk=build_id), '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.get( id = layerversion_id )
}
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)
# follow convention for pagination w/ search although not used for this view
queryset = Package_File.objects.filter(package_id__exact=package_id)
(pagesize, orderby) = _get_parameters_values(request, 25, 'path:+')
mandatory_parameters = { 'count': pagesize, 'page' : 1, 'orderby' : orderby }
retval = _verify_parameters( request.GET, mandatory_parameters )
if retval:
return _redirect_parameters( 'package_built_detail', request.GET, mandatory_parameters, build_id = build_id, package_id = package_id)
(filter_string, search_term, ordering_string) = _search_tuple(request, Package_File)
paths = _get_queryset(Package_File, queryset, filter_string, search_term, ordering_string, 'path')
package = Package.objects.get(pk=package_id)
package.fullpackagespec = _get_fullpackagespec(package)
context = {
'build' : Build.objects.get(pk=build_id),
'package' : package,
'dependency_count' : _get_package_dependency_count(package, -1, False),
'objects' : paths,
'tablecols':[
{
'name':'File',
'orderfield': _get_toggle_order(request, "path"),
'ordericon':_get_toggle_order_icon(request, "path"),
},
{
'name':'Size',
'orderfield': _get_toggle_order(request, "size", True),
'ordericon':_get_toggle_order_icon(request, "size"),
'dclass': 'sizecol span2',
},
]
}
if paths.all().count() < 2:
context['disable_sort'] = True;
response = render(request, template, context)
_save_parameters_cookies(response, pagesize, orderby, request)
return response
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.get(pk=package_id)
package.fullpackagespec = _get_fullpackagespec(package)
dependencies = _get_package_dependencies(package_id)
context = {
'build' : Build.objects.get(pk=build_id),
'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)
# follow convention for pagination w/ search although not used for this view
(pagesize, orderby) = _get_parameters_values(request, 25, 'path:+')
mandatory_parameters = { 'count': pagesize, 'page' : 1, 'orderby' : orderby }
retval = _verify_parameters( request.GET, mandatory_parameters )
if retval:
return _redirect_parameters( 'package_included_detail', request.GET, mandatory_parameters, build_id = build_id, target_id = target_id, package_id = package_id)
(filter_string, search_term, ordering_string) = _search_tuple(request, Package_File)
queryset = Package_File.objects.filter(package_id__exact=package_id)
paths = _get_queryset(Package_File, queryset, filter_string, search_term, ordering_string, 'path')
package = Package.objects.get(pk=package_id)
package.fullpackagespec = _get_fullpackagespec(package)
package.alias = _get_package_alias(package)
target = Target.objects.get(pk=target_id)
context = {
'build' : Build.objects.get(pk=build_id),
'target' : target,
'package' : package,
'reverse_count' : _get_package_reverse_dep_count(package, target_id),
'dependency_count' : _get_package_dependency_count(package, target_id, True),
'objects': paths,
'tablecols':[
{
'name':'File',
'orderfield': _get_toggle_order(request, "path"),
'ordericon':_get_toggle_order_icon(request, "path"),
},
{
'name':'Size',
'orderfield': _get_toggle_order(request, "size", True),
'ordericon':_get_toggle_order_icon(request, "size"),
'dclass': 'sizecol span2',
},
]
}
if paths.all().count() < 2:
context['disable_sort'] = True
response = render(request, template, context)
_save_parameters_cookies(response, pagesize, orderby, request)
return response
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.get(pk=package_id)
package.fullpackagespec = _get_fullpackagespec(package)
package.alias = _get_package_alias(package)
target = Target.objects.get(pk=target_id)
dependencies = _get_package_dependencies(package_id, target_id)
context = {
'build' : Build.objects.get(pk=build_id),
'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)
(pagesize, orderby) = _get_parameters_values(request, 25, 'package__name:+')
mandatory_parameters = { 'count': pagesize, 'page' : 1, 'orderby': orderby }
retval = _verify_parameters( request.GET, mandatory_parameters )
if retval:
return _redirect_parameters( 'package_included_reverse_dependencies', request.GET, mandatory_parameters, build_id = build_id, target_id = target_id, package_id = package_id)
(filter_string, search_term, ordering_string) = _search_tuple(request, Package_File)
queryset = Package_Dependency.objects.select_related('depends_on__name', 'depends_on__size').filter(depends_on=package_id, target_id=target_id, dep_type=Package_Dependency.TYPE_TRDEPENDS)
objects = _get_queryset(Package_Dependency, queryset, filter_string, search_term, ordering_string, 'package__name')
package = Package.objects.get(pk=package_id)
package.fullpackagespec = _get_fullpackagespec(package)
package.alias = _get_package_alias(package)
target = Target.objects.get(pk=target_id)
for o in objects:
if o.package.version != '':
o.package.version += '-' + o.package.revision
o.alias = _get_package_alias(o.package)
context = {
'build' : Build.objects.get(pk=build_id),
'package' : package,
'target' : target,
'objects' : objects,
'reverse_count' : _get_package_reverse_dep_count(package, target_id),
'dependency_count' : _get_package_dependency_count(package, target_id, True),
'tablecols':[
{
'name':'Package',
'orderfield': _get_toggle_order(request, "package__name"),
'ordericon': _get_toggle_order_icon(request, "package__name"),
},
{
'name':'Version',
},
{
'name':'Size',
'orderfield': _get_toggle_order(request, "package__size", True),
'ordericon': _get_toggle_order_icon(request, "package__size"),
'dclass': 'sizecol span2',
},
]
}
if objects.all().count() < 2:
context['disable_sort'] = True
response = render(request, template, context)
_save_parameters_cookies(response, pagesize, orderby, request)
return response
def image_information_dir(request, build_id, target_id, packagefile_id):
# stubbed for now
return redirect(builds)
import toastermain.settings
# we have a set of functions if we're in managed mode, or
# a default "page not available" simple functions for interactive mode
if toastermain.settings.MANAGED:
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, login
from django.contrib.auth.decorators import login_required
from orm.models import Project, ProjectLayer, ProjectTarget, ProjectVariable
from orm.models import Branch, LayerSource, ToasterSetting, Release, Machine, LayerVersionDependency
from bldcontrol.models import BuildRequest
import traceback
class BadParameterException(Exception): pass # error thrown on invalid POST requests
# the context processor that supplies data used across all the pages
def managedcontextprocessor(request):
ret = {
"projects": Project.objects.all(),
"MANAGED" : toastermain.settings.MANAGED,
"DEBUG" : toastermain.settings.DEBUG
}
if 'project_id' in request.session:
try:
ret['project'] = Project.objects.get(pk = request.session['project_id'])
except Project.DoesNotExist:
del request.session['project_id']
return ret
class InvalidRequestException(Exception):
def __init__(self, response):
self.response = response
# shows the "all builds" page for managed mode; it displays build requests (at least started!) instead of actual builds
def builds(request):
template = 'managed_builds.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.
buildrequests = BuildRequest.objects.exclude(state__lte = BuildRequest.REQ_INPROGRESS).exclude(state=BuildRequest.REQ_DELETED)
try:
context, pagesize, orderby = _build_list_helper(request, buildrequests)
except InvalidRequestException as e:
return _redirect_parameters( builds, request.GET, e.response)
context['tablecols'].append(
{'name': 'Project', 'clclass': 'project',
'filter': {'class': 'project',
'label': 'Project:',
'options': map(lambda x: (x.name,'',x.build_set.filter(outcome__lt=BuildRequest.REQ_INPROGRESS).count()), Project.objects.all()),
}
}
)
response = render(request, template, context)
_save_parameters_cookies(response, pagesize, orderby, request)
return response
# helper function, to be used on "all builds" and "project builds" pages
def _build_list_helper(request, buildrequests):
# ATTN: we use here the ordering parameters for interactive mode; the translation for BuildRequest fields will happen below
(pagesize, orderby) = _get_parameters_values(request, 10, 'completed_on:-')
mandatory_parameters = { 'count': pagesize, 'page' : 1, 'orderby' : orderby }
retval = _verify_parameters( request.GET, mandatory_parameters )
if retval:
raise InvalidRequestException(mandatory_parameters)
orig_orderby = orderby
# translate interactive mode ordering to managed mode ordering
ordering_params = orderby.split(":")
if ordering_params[0] == "completed_on":
ordering_params[0] = "updated"
if ordering_params[0] == "started_on":
ordering_params[0] = "created"
if ordering_params[0] == "errors_no":
ordering_params[0] = "build__errors_no"
if ordering_params[0] == "warnings_no":
ordering_params[0] = "build__warnings_no"
if ordering_params[0] == "machine":
ordering_params[0] = "build__machine"
if ordering_params[0] == "target__target":
ordering_params[0] = "brtarget__target"
request.GET = request.GET.copy() # get a mutable copy of the GET QueryDict
request.GET['orderby'] = ":".join(ordering_params)
# 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, BuildRequest)
# we don't display in-progress or deleted builds
queryset_all = buildrequests
queryset_with_search = _get_queryset(BuildRequest, queryset_all, None, search_term, ordering_string, '-updated')
queryset = _get_queryset(BuildRequest, queryset_all, filter_string, search_term, ordering_string, '-updated')
# 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, pagesize), 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)
# most recent build is like projects' most recent builds, but across all projects
build_mru = BuildRequest.objects.all()
build_mru = list(build_mru.filter(Q(state__lt=BuildRequest.REQ_COMPLETED) or Q(state=BuildRequest.REQ_DELETED)).order_by("-pk")) + list(build_mru.filter(state__in=[BuildRequest.REQ_COMPLETED, BuildRequest.REQ_FAILED]).order_by("-pk")[:3])
fstypes_map = {};
for build_request in build_info:
# set display variables for build request
build_request.machine = build_request.brvariable_set.get(name="MACHINE").value
build_request.timespent = build_request.updated - build_request.created
# set up list of fstypes for each build
if build_request.build is None:
continue
targets = Target.objects.filter( build_id = build_request.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_request.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",
'default_orderby' : 'updated:-',
'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 successfully completed or failed", # the help button content
'dclass' : "span2", # indication about column width; comes from the design
'orderfield': _get_toggle_order(request, "state"), # adds ordering by the field value; default ascending unless clicked from ascending into descending
'ordericon':_get_toggle_order_icon(request, "state"),
# 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', 'state:' + str(BuildRequest.REQ_COMPLETED), queryset_with_search.filter(state=str(BuildRequest.REQ_COMPLETED)).count()), # this is the field search expression
('Failed builds', 'state:'+ str(BuildRequest.REQ_FAILED), queryset_with_search.filter(state=str(BuildRequest.REQ_FAILED)).count()),
]
}
},
{'name': 'Target', # default column, disabled box, with just the name in the list
'qhelp': "This is the build target or build targets (i.e. one or more recipes or image recipes)",
'orderfield': _get_toggle_order(request, "brtarget__target"),
'ordericon':_get_toggle_order_icon(request, "brtarget__target"),
},
{'name': 'Machine',
'qhelp': "The machine is the hardware for which you are building a recipe or image recipe",
'orderfield': _get_toggle_order(request, "build__machine"),
'ordericon':_get_toggle_order_icon(request, "build__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, "created", True),
'ordericon':_get_toggle_order_icon(request, "created"),
'filter' : {'class' : 'created',
'label': 'Show:',
'options' : [
("Today's builds" , 'created__gte:'+timezone.now().strftime("%Y-%m-%d"), queryset_with_search.filter(created__gte=timezone.now()).count()),
("Yesterday's builds", 'created__gte:'+(timezone.now()-timedelta(hours=24)).strftime("%Y-%m-%d"), queryset_with_search.filter(created__gte=(timezone.now()-timedelta(hours=24))).count()),
("This week's builds", 'created__gte:'+(timezone.now()-timedelta(days=7)).strftime("%Y-%m-%d"), queryset_with_search.filter(created__gte=(timezone.now()-timedelta(days=7))).count()),
]
}
},
{'name': 'Completed on',
'qhelp': "The date and time the build finished",
'orderfield': _get_toggle_order(request, "updated", True),
'ordericon':_get_toggle_order_icon(request, "updated"),
'orderkey' : 'updated',
'filter' : {'class' : 'updated',
'label': 'Show:',
'options' : [
("Today's builds", 'updated__gte:'+timezone.now().strftime("%Y-%m-%d"), queryset_with_search.filter(updated__gte=timezone.now()).count()),
("Yesterday's builds", 'updated__gte:'+(timezone.now()-timedelta(hours=24)).strftime("%Y-%m-%d"), queryset_with_search.filter(updated__gte=(timezone.now()-timedelta(hours=24))).count()),
("This week's builds", 'updated__gte:'+(timezone.now()-timedelta(days=7)).strftime("%Y-%m-%d"), queryset_with_search.filter(updated__gte=(timezone.now()-timedelta(days=7))).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' : [
('Build with failed tasks', 'build__task_build__outcome:4', queryset_with_search.filter(build__task_build__outcome=4).count()),
('Build without failed tasks', 'build__task_build__outcome:NOT4', queryset_with_search.filter(~Q(build__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, "build__errors_no", True),
'ordericon':_get_toggle_order_icon(request, "build__errors_no"),
'orderkey' : 'errors_no',
'filter' : {'class' : 'errors_no',
'label': 'Show:',
'options' : [
('Build with errors', 'build__errors_no__gte:1', queryset_with_search.filter(build__errors_no__gte=1).count()),
('Build without errors', 'build__errors_no:0', queryset_with_search.filter(build__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, "build__warnings_no", True),
'ordericon':_get_toggle_order_icon(request, "build__warnings_no"),
'orderkey' : 'build__warnings_no',
'filter' : {'class' : 'build__warnings_no',
'label': 'Show:',
'options' : [
('Build with warnings','build__warnings_no__gte:1', queryset_with_search.filter(build__warnings_no__gte=1).count()),
('Build without warnings','build__warnings_no:0', queryset_with_search.filter(build__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"),
'orderkey' : 'timespent',
},
{'name': 'Image files', '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 context, pagesize, orderby
# new project
def newproject(request):
template = "newproject.html"
context = {
'email': request.user.email if request.user.is_authenticated() else '',
'username': request.user.username if request.user.is_authenticated() else '',
'releases': Release.objects.order_by("description"),
}
try:
context['defaultbranch'] = ToasterSetting.objects.get(name = "DEFAULT_RELEASE").value
except ToasterSetting.DoesNotExist:
pass
if request.method == "GET":
# render new project page
return render(request, template, context)
elif request.method == "POST":
mandatory_fields = ['projectname', 'projectversion']
try:
# make sure we have values for all mandatory_fields
if reduce( lambda x, y: x or y, map(lambda x: len(request.POST.get(x, '')) == 0, mandatory_fields)):
# set alert for missing fields
raise BadParameterException("Fields missing: " +
", ".join([x for x in mandatory_fields if len(request.POST.get(x, '')) == 0 ]))
if not request.user.is_authenticated():
user = authenticate(username = request.POST.get('username', '_anonuser'), password = 'nopass')
if user is None:
user = User.objects.create_user(username = request.POST.get('username', '_anonuser'), email = request.POST.get('email', ''), password = "nopass")
user = authenticate(username = user.username, password = 'nopass')
login(request, user)
# save the project
prj = Project.objects.create_project(name = request.POST['projectname'], release = Release.objects.get(pk = request.POST['projectversion']))
prj.user_id = request.user.pk
prj.save()
return redirect(reverse(project, args=(prj.pk,)) + "#/newproject")
except (IntegrityError, BadParameterException) as e:
# fill in page with previously submitted values
map(lambda x: context.__setitem__(x, request.POST.get(x, "-- missing")), mandatory_fields)
if isinstance(e, IntegrityError) and "username" in str(e):
context['alert'] = "Your chosen username is already used"
else:
context['alert'] = str(e)
return render(request, template, context)
raise Exception("Invalid HTTP method for this page")
# Shows the edit project page
def project(request, pid):
template = "project.html"
try:
prj = Project.objects.get(id = pid)
except Project.DoesNotExist:
return HttpResponseNotFound("<h1>Project id " + pid + " is unavailable</h1>")
try:
puser = User.objects.get(id = prj.user_id)
except User.DoesNotExist:
puser = None
# we use implicit knowledge of the current user's project to filter layer information, e.g.
request.session['project_id'] = prj.id
from collections import Counter
freqtargets = []
try:
freqtargets += map(lambda x: x.target, reduce(lambda x, y: x + y, map(lambda x: list(x.target_set.all()), Build.objects.filter(project = prj, outcome__lt = Build.IN_PROGRESS))))
freqtargets += map(lambda x: x.target, reduce(lambda x, y: x + y, map(lambda x: list(x.brtarget_set.all()), BuildRequest.objects.filter(project = prj, state__lte = BuildRequest.REQ_QUEUED))))
except TypeError:
pass
freqtargets = Counter(freqtargets)
freqtargets = sorted(freqtargets, key = lambda x: freqtargets[x])
context = {
"project" : prj,
"completedbuilds": Build.objects.filter(project = prj).exclude(outcome = Build.IN_PROGRESS),
"prj" : {"name": prj.name, "release": { "id": prj.release.pk, "name": prj.release.name, "desc": prj.release.description}},
#"buildrequests" : prj.buildrequest_set.filter(state=BuildRequest.REQ_QUEUED),
"builds" : _project_recent_build_list(prj),
"layers" : map(lambda x: {
"id": x.layercommit.pk,
"orderid": x.pk,
"name" : x.layercommit.layer.name,
"giturl": x.layercommit.layer.vcs_url,
"url": x.layercommit.layer.layer_index_url,
"layerdetailurl": reverse("layerdetails", args=(x.layercommit.pk,)),
# This branch name is actually the release
"branch" : { "name" : x.layercommit.commit, "layersource" : x.layercommit.up_branch.layer_source.name}},
prj.projectlayer_set.all().order_by("id")),
"targets" : map(lambda x: {"target" : x.target, "task" : x.task, "pk": x.pk}, prj.projecttarget_set.all()),
"freqtargets": freqtargets,
"releases": map(lambda x: {"id": x.pk, "name": x.name, "description":x.description}, Release.objects.all()),
}
try:
context["machine"] = {"name": prj.projectvariable_set.get(name="MACHINE").value}
except ProjectVariable.DoesNotExist:
context["machine"] = None
try:
context["distro"] = prj.projectvariable_set.get(name="DISTRO").value
except ProjectVariable.DoesNotExist:
context["distro"] = "-- not set yet"
response = render(request, template, context)
response['Cache-Control'] = "no-cache, must-revalidate, no-store"
response['Pragma'] = "no-cache"
return response
# This is a wrapper for xhr_projectbuild which allows for a project id
# which only becomes known client side.
def xhr_build(request):
if request.POST.has_key("project_id"):
pid = request.POST['project_id']
return xhr_projectbuild(request, pid)
else:
raise BadParameterException("invalid project id")
def xhr_projectbuild(request, pid):
try:
if request.method != "POST":
raise BadParameterException("invalid method")
request.session['project_id'] = pid
prj = Project.objects.get(id = pid)
if 'buildCancel' in request.POST:
for i in request.POST['buildCancel'].strip().split(" "):
try:
br = BuildRequest.objects.select_for_update().get(project = prj, pk = i, state__lte = BuildRequest.REQ_QUEUED)
br.state = BuildRequest.REQ_DELETED
br.save()
except BuildRequest.DoesNotExist:
pass
if 'buildDelete' in request.POST:
for i in request.POST['buildDelete'].strip().split(" "):
try:
br = BuildRequest.objects.select_for_update().get(project = prj, pk = i, state__lte = BuildRequest.REQ_DELETED).delete()
except BuildRequest.DoesNotExist:
pass
if 'targets' in request.POST:
ProjectTarget.objects.filter(project = prj).delete()
s = str(request.POST['targets'])
for t in s.translate(None, ";%|\"").split(" "):
if ":" in t:
target, task = t.split(":")
else:
target = t
task = ""
ProjectTarget.objects.create(project = prj, target = target, task = task)
br = prj.schedule_build()
return HttpResponse(jsonfilter({"error":"ok",
"builds" : _project_recent_build_list(prj),
}), content_type = "application/json")
except Exception as e:
return HttpResponse(jsonfilter({"error":str(e) + "\n" + traceback.format_exc()}), content_type = "application/json")
# This is a wraper for xhr_projectedit which allows for a project id
# which only becomes known client side
def xhr_projectinfo(request):
if request.POST.has_key("project_id") == False:
raise BadParameterException("invalid project id")
return xhr_projectedit(request, request.POST['project_id'])
def xhr_projectedit(request, pid):
try:
prj = Project.objects.get(id = pid)
# add layers
if 'layerAdd' in request.POST:
for lc in Layer_Version.objects.filter(pk__in=request.POST['layerAdd'].split(",")):
ProjectLayer.objects.get_or_create(project = prj, layercommit = lc)
# remove layers
if 'layerDel' in request.POST:
for t in request.POST['layerDel'].strip().split(" "):
pt = ProjectLayer.objects.filter(project = prj, layercommit_id = int(t)).delete()
if 'projectName' in request.POST:
prj.name = request.POST['projectName']
prj.save();
if 'projectVersion' in request.POST:
prj.release = Release.objects.get(pk = request.POST['projectVersion'])
# we need to change the bitbake version
prj.bitbake_version = prj.release.bitbake_version
prj.save()
# we need to change the layers
for i in prj.projectlayer_set.all():
# find and add a similarly-named layer on the new branch
try:
lv = prj.compatible_layerversions(layer_name = i.layercommit.layer.name)[0]
ProjectLayer.objects.get_or_create(project = prj, layercommit = lv)
except IndexError:
pass
finally:
# get rid of the old entry
i.delete()
if 'machineName' in request.POST:
machinevar = prj.projectvariable_set.get(name="MACHINE")
machinevar.value=request.POST['machineName']
machinevar.save()
# return all project settings
return HttpResponse(jsonfilter( {
"error": "ok",
"layers" : map(lambda x: {"id": x.layercommit.pk, "orderid" : x.pk, "name" : x.layercommit.layer.name, "giturl" : x.layercommit.layer.vcs_url, "url": x.layercommit.layer.layer_index_url, "layerdetailurl": reverse("layerdetails", args=(x.layercommit.layer.pk,)), "branch" : { "name" : x.layercommit.up_branch.name, "layersource" : x.layercommit.up_branch.layer_source.name}}, prj.projectlayer_set.all().order_by("id")),
"builds" : _project_recent_build_list(prj),
"variables": map(lambda x: (x.name, x.value), prj.projectvariable_set.all()),
"machine": {"name": prj.projectvariable_set.get(name="MACHINE").value},
"prj": {"name": prj.name, "release": { "id": prj.release.pk, "name": prj.release.name, "desc": prj.release.description}},
}), content_type = "application/json")
except Exception as e:
return HttpResponse(jsonfilter({"error":str(e) + "\n" + traceback.format_exc()}), content_type = "application/json")
from django.views.decorators.csrf import csrf_exempt
@csrf_exempt
def xhr_datatypeahead(request):
try:
prj = None
if request.GET.has_key('project_id'):
prj = Project.objects.get(pk = request.GET['project_id'])
elif 'project_id' in request.session:
prj = Project.objects.get(pk = request.session['project_id'])
else:
raise Exception("No valid project selected")
def _lv_to_dict(x):
return {"id": x.pk, "name": x.layer.name, "tooltip": x.layer.vcs_url+" | "+x.commit,
"detail": "(" + x.layer.vcs_url + (")" if x.up_branch == None else " | "+x.up_branch.name+")"),
"giturl": x.layer.vcs_url, "layerdetailurl" : reverse('layerdetails', args=(x.pk,))}
# returns layers for current project release that are not in the project set, matching the name
if request.GET['type'] == "layers":
# all layers for the current project
queryset_all = prj.compatible_layerversions().filter(layer__name__icontains=request.GET.get('value',''))
# but not layers with equivalent layers already in project
if not request.GET.has_key('include_added'):
queryset_all = queryset_all.exclude(pk__in = [x.id for x in prj.projectlayer_equivalent_set()])[:8]
# and show only the selected layers for this project
final_list = set([x.get_equivalents_wpriority(prj)[0] for x in queryset_all])
return HttpResponse(jsonfilter( { "error":"ok", "list" : map( _lv_to_dict, final_list) }), content_type = "application/json")
# returns layer dependencies for a layer, excluding current project layers
if request.GET['type'] == "layerdeps":
queryset = prj.compatible_layerversions().exclude(pk__in = [x.id for x in prj.projectlayer_equivalent_set()]).filter(
layer__name__in = [ x.depends_on.layer.name for x in LayerVersionDependency.objects.filter(layer_version_id = request.GET['value'])])
final_list = set([x.get_equivalents_wpriority(prj)[0] for x in queryset])
return HttpResponse(jsonfilter( { "error":"ok", "list" : map( _lv_to_dict, final_list) }), content_type = "application/json")
# returns layer versions that would be deleted on the new release__pk
if request.GET['type'] == "versionlayers":
if not 'project_id' in request.session:
raise Exception("This call cannot makes no sense outside a project context")
retval = []
for i in prj.projectlayer_set.all():
lv = prj.compatible_layerversions(release = Release.objects.get(pk=request.GET['value'])).filter(layer__name = i.layercommit.layer.name)
# there is no layer_version with the new release id, and the same name
if lv.count() < 1:
retval.append(i)
return HttpResponse(jsonfilter( {"error":"ok",
"list" : map( _lv_to_dict, map(lambda x: x.layercommit, retval ))
}), content_type = "application/json")
# returns layer versions that provide the named targets
if request.GET['type'] == "layers4target":
# we returnd ata only if the recipe can't be provided by the current project layer set
if reduce(lambda x, y: x + y, [x.recipe_layer_version.filter(name="anki").count() for x in prj.projectlayer_equivalent_set()], 0):
final_list = []
else:
queryset_all = prj.compatible_layerversions().filter(recipe_layer_version__name = request.GET.get('value', '__none__'))
# exclude layers in the project
queryset_all = queryset_all.exclude(pk__in = [x.id for x in prj.projectlayer_equivalent_set()])
# and show only the selected layers for this project
final_list = set([x.get_equivalents_wpriority(prj)[0] for x in queryset_all])
return HttpResponse(jsonfilter( { "error":"ok", "list" : map( _lv_to_dict, final_list) }), content_type = "application/json")
# returns targets provided by current project layers
if request.GET['type'] == "targets":
queryset_all = Recipe.objects.all()
layer_equivalent_set = []
for i in prj.projectlayer_set.all():
layer_equivalent_set += i.layercommit.get_equivalents_wpriority(prj)
queryset_all = queryset_all.filter(layer_version__in = layer_equivalent_set)
return HttpResponse(jsonfilter({ "error":"ok",
"list" : map ( lambda x: {"id": x.pk, "name": x.name, "detail":"[" + x.layer_version.layer.name+ (" | " + x.layer_version.up_branch.name + "]" if x.layer_version.up_branch is not None else "]")},
queryset_all.filter(name__icontains=request.GET.get('value',''))[:8]),
}), content_type = "application/json")
# returns machines provided by the current project layers
if request.GET['type'] == "machines":
queryset_all = Machine.objects.all()
if 'project_id' in request.session:
queryset_all = queryset_all.filter(layer_version__in = prj.projectlayer_equivalent_set())
return HttpResponse(jsonfilter({ "error":"ok",
"list" : map ( lambda x: {"id": x.pk, "name": x.name, "detail":"[" + x.layer_version.layer.name+ (" | " + x.layer_version.up_branch.name + "]" if x.layer_version.up_branch is not None else "]")},
queryset_all.filter(name__icontains=request.GET.get('value',''))[:8]),
}), content_type = "application/json")
# returns all projects
if request.GET['type'] == "projects":
queryset_all = Project.objects.all()
ret = { "error": "ok",
"list": map (lambda x: {"id":x.pk, "name": x.name},
queryset_all.filter(name__icontains=request.GET.get('value',''))[:8])}
return HttpResponse(jsonfilter(ret), content_type = "application/json")
raise Exception("Unknown request! " + request.GET.get('type', "No parameter supplied"))
except Exception as e:
return HttpResponse(jsonfilter({"error":str(e) + "\n" + traceback.format_exc()}), content_type = "application/json")
def xhr_configvaredit(request, pid):
try:
prj = Project.objects.get(id = pid)
# add conf variables
if 'configvarAdd' in request.POST:
t=request.POST['configvarAdd'].strip()
if ":" in t:
variable, value = t.split(":")
else:
variable = t
value = ""
pt, created = ProjectVariable.objects.get_or_create(project = prj, name = variable, value = value)
# change conf variables
if 'configvarChange' in request.POST:
t=request.POST['configvarChange'].strip()
if ":" in t:
variable, value = t.split(":")
else:
variable = t
value = ""
try:
pt = ProjectVariable.objects.get(project = prj, name = variable)
pt.value=value
pt.save()
except ObjectDoesNotExist:
print("the entry doesn't exist.")
# remove conf variables
if 'configvarDel' in request.POST:
t=request.POST['configvarDel'].strip()
pt = ProjectVariable.objects.get(pk = int(t)).delete()
# return all project settings
vars_managed,vars_fstypes,vars_blacklist = get_project_configvars_context()
return HttpResponse(json.dumps( {
"error": "ok",
'configvars' : map(lambda x: (x.name, x.value, x.pk), ProjectVariable.objects.filter(project_id = pid).all()),
'distro' : ProjectVariable.objects.get(project = prj, name = "DISTRO").value,
'fstypes' : ProjectVariable.objects.get(project = prj, name = "IMAGE_FSTYPES").value,
'image_install_append': ProjectVariable.objects.get(project = prj, name = "IMAGE_INSTALL_append").value,
'package_classes': ProjectVariable.objects.get(project = prj, name = "PACKAGE_CLASSES").value,
'sdk_machine' : ProjectVariable.objects.get(project = prj, name = "SDKMACHINE").value,
}), content_type = "application/json")
except Exception as e:
return HttpResponse(json.dumps({"error":str(e) + "\n" + traceback.format_exc()}), content_type = "application/json")
def xhr_importlayer(request):
if (not request.POST.has_key('vcs_url') or
not request.POST.has_key('name') or
not request.POST.has_key('git_ref') or
not request.POST.has_key('project_id')):
return HttpResponse(jsonfilter({"error": "Missing parameters; requires vcs_url, name, git_ref and project_id"}), content_type = "application/json")
layers_added = [];
# Rudimentary check for any possible html tags
if "<" in request.POST:
return HttpResponse(jsonfilter({"error": "Invalid character <"}), content_type = "application/json")
prj = Project.objects.get(pk=request.POST['project_id'])
# Strip trailing/leading whitespace from all values
# put into a new dict because POST one is immutable
post_data = dict()
for key,val in request.POST.iteritems():
post_data[key] = val.strip()
# We need to know what release the current project is so that we
# can set the imported layer's up_branch_id
prj_branch_name = Release.objects.get(pk=prj.release_id).branch_name
up_branch, branch_created = Branch.objects.get_or_create(name=prj_branch_name, layer_source_id=LayerSource.TYPE_IMPORTED)
layer_source = LayerSource.objects.get(sourcetype=LayerSource.TYPE_IMPORTED)
try:
layer, layer_created = Layer.objects.get_or_create(name=post_data['name'])
except MultipleObjectsReturned:
return HttpResponse(jsonfilter({"error": "hint-layer-exists"}), content_type = "application/json")
if layer:
if layer_created:
layer.layer_source = layer_source
layer.vcs_url = post_data['vcs_url']
if post_data.has_key('summary'):
layer.summary = layer.description = post_data['summary']
layer.up_date = timezone.now()
layer.save()
else:
# We have an existing layer by this name, let's see if the git
# url is the same, if it is then we can just create a new layer
# version for this layer. Otherwise we need to bail out.
if layer.vcs_url != post_data['vcs_url']:
return HttpResponse(jsonfilter({"error": "hint-layer-exists-with-different-url" , "current_url" : layer.vcs_url, "current_id": layer.id }), content_type = "application/json")
layer_version, version_created = Layer_Version.objects.get_or_create(layer_source=layer_source, layer=layer, project=prj, up_branch_id=up_branch.id,branch=post_data['git_ref'], commit=post_data['git_ref'], dirpath=post_data['dir_path'])
if layer_version:
if not version_created:
return HttpResponse(jsonfilter({"error": "hint-layer-version-exists", "existing_layer_version": layer_version.id }), content_type = "application/json")
layer_version.up_date = timezone.now()
layer_version.save()
# Add the dependencies specified for this new layer
if (post_data.has_key("layer_deps") and
version_created and
len(post_data["layer_deps"]) > 0):
for layer_dep_id in post_data["layer_deps"].split(","):
layer_dep_obj = Layer_Version.objects.get(pk=layer_dep_id)
LayerVersionDependency.objects.get_or_create(layer_version=layer_version, depends_on=layer_dep_obj)
# Now add them to the project, we could get an execption
# if the project now contains the exact
# dependency already (like modified on another page)
try:
prj_layer, prj_layer_created = ProjectLayer.objects.get_or_create(layercommit=layer_dep_obj, project=prj)
except:
continue
if prj_layer_created:
layers_added.append({'id': layer_dep_obj.id, 'name': Layer.objects.get(id=layer_dep_obj.layer_id).name})
# If an old layer version exists in our project then remove it
for prj_layers in ProjectLayer.objects.filter(project=prj):
dup_layer_v = Layer_Version.objects.filter(id=prj_layers.layercommit_id, layer_id=layer.id)
if len(dup_layer_v) >0 :
prj_layers.delete()
# finally add the imported layer (version id) to the project
ProjectLayer.objects.create(layercommit=layer_version, project=prj,optional=1)
else:
# We didn't create a layer version so back out now and clean up.
if layer_created:
layer.delete()
return HttpResponse(jsonfilter({"error": "Uncaught error: Could not create layer version"}), content_type = "application/json")
return HttpResponse(jsonfilter({"error": "ok", "imported_layer" : { "name" : layer.name, "id": layer_version.id }, "deps_added": layers_added }), content_type = "application/json")
def xhr_updatelayer(request):
def error_response(error):
return HttpResponse(jsonfilter({"error": error}), content_type = "application/json")
if not request.POST.has_key("layer_version_id"):
return error_response("Please specify a layer version id")
try:
layer_version_id = request.POST["layer_version_id"]
layer_version = Layer_Version.objects.get(id=layer_version_id)
except:
return error_response("Cannot find layer to update")
if request.POST.has_key("vcs_url"):
layer_version.layer.vcs_url = request.POST["vcs_url"]
if request.POST.has_key("dirpath"):
layer_version.dirpath = request.POST["dirpath"]
if request.POST.has_key("commit"):
layer_version.commit = request.POST["commit"]
if request.POST.has_key("up_branch"):
layer_version.up_branch_id = int(request.POST["up_branch"])
if request.POST.has_key("add_dep"):
lvd = LayerVersionDependency(layer_version=layer_version, depends_on_id=request.POST["add_dep"])
lvd.save()
if request.POST.has_key("rm_dep"):
rm_dep = LayerVersionDependency.objects.get(layer_version=layer_version, depends_on_id=request.POST["rm_dep"])
rm_dep.delete()
if request.POST.has_key("summary"):
layer_version.layer.summary = request.POST["summary"]
if request.POST.has_key("description"):
layer_version.layer.description = request.POST["description"]
try:
layer_version.layer.save()
layer_version.save()
except:
return error_response("Could not update layer version entry")
return HttpResponse(jsonfilter({"error": "ok",}), content_type = "application/json")
def importlayer(request):
template = "importlayer.html"
context = {
}
return render(request, template, context)
def layers(request):
if not 'project_id' in request.session:
raise Exception("invalid page: cannot show page without a project")
template = "layers.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.
(pagesize, orderby) = _get_parameters_values(request, 100, 'layer__name:+')
mandatory_parameters = { 'count': pagesize, 'page' : 1, 'orderby' : orderby };
retval = _verify_parameters( request.GET, mandatory_parameters )
if retval:
return _redirect_parameters( 'layers', 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, Layer_Version)
prj = Project.objects.get(pk = request.session['project_id'])
queryset_all = prj.compatible_layerversions()
queryset_all = _get_queryset(Layer_Version, queryset_all, filter_string, search_term, ordering_string, '-layer__name')
# retrieve the objects that will be displayed in the table; layers a paginator and gets a page range to display
layer_info = _build_page_range(Paginator(queryset_all, request.GET.get('count', 10)),request.GET.get('page', 1))
context = {
'projectlayerset' : jsonfilter(map(lambda x: x.layercommit.id, prj.projectlayer_set.all())),
'objects' : layer_info,
'objectname' : "layers",
'default_orderby' : 'layer__name:+',
'total_count': queryset_all.count(),
'tablecols' : [
{ 'name': 'Layer',
'orderfield': _get_toggle_order(request, "layer__name"),
'ordericon' : _get_toggle_order_icon(request, "layer__name"),
},
{ 'name': 'Description',
'dclass': 'span4',
'clclass': 'description',
},
{ 'name': 'Layer source',
'clclass': 'source',
'qhelp': "Where the layer is coming from, for example, if it's part of the OpenEmbedded collection of layers or if it's a layer you have imported",
'orderfield': _get_toggle_order(request, "layer_source__name"),
'ordericon': _get_toggle_order_icon(request, "layer_source__name"),
'filter': {
'class': 'layer',
'label': 'Show:',
'options': map(lambda x: (x.name + " layers", 'layer_source__pk:' + str(x.id), queryset_all.filter(layer_source__pk = x.id).count() ), LayerSource.objects.all()),
}
},
{ 'name': 'Git repository URL',
'dclass': 'span6',
'clclass': 'git-repo', 'hidden': 1,
'qhelp': "The Git repository for the layer source code",
},
{ 'name': 'Subdirectory',
'clclass': 'git-subdir',
'hidden': 1,
'qhelp': "The layer directory within the Git repository",
},
{ 'name': 'Branch, tag o commit',
'clclass': 'branch',
'qhelp': "The Git branch of the layer. For the layers from the OpenEmbedded source, the branch matches the Yocto Project version you selected for this project",
},
{ 'name': 'Dependencies',
'clclass': 'dependencies',
'qhelp': "Other layers a layer depends upon",
},
{ 'name': 'Add | Delete',
'dclass': 'span2',
'qhelp': "Add or delete layers to / from your project ",
'filter': {
'class': 'add-del-layers',
'label': 'Show:',
'options': [
('Layers added to this project', "projectlayer__project:" + str(prj.id), queryset_all.filter(projectlayer__project = prj.id).count()),
('Layers not added to this project', "projectlayer__project:NOT" + str(prj.id), queryset_all.exclude(projectlayer__project = prj.id).count()),
]
}
},
]
}
return render(request, template, context)
def layerdetails(request, layerid):
template = "layerdetails.html"
limit = 10
if request.GET.has_key("limit"):
request.session['limit'] = request.GET['limit']
if request.session.has_key('limit'):
limit = request.session['limit']
layer_version = Layer_Version.objects.get(pk = layerid)
# Targets tab query functionality
if request.GET.has_key('targets_search'):
targets = Paginator(Recipe.objects.filter(layer_version=layer_version,name__icontains=request.GET['targets_search']).order_by("name"), limit)
else:
targets = Paginator(Recipe.objects.filter(layer_version=layer_version).order_by("name"), limit)
if request.GET.has_key("tpage"):
try:
targets = targets.page(request.GET['tpage'])
except EmptyPage:
targets = targets.page(targets.num_pages)
else:
targets = targets.page(1)
# Machines tab query functionality
if request.GET.has_key('machines_search'):
machines = Paginator(Machine.objects.filter(layer_version=layer_version,name__icontains=request.GET['machines_search']).order_by("name"), limit)
else:
machines = Paginator(Machine.objects.filter(layer_version=layer_version).order_by("name"), limit)
if request.GET.has_key("mpage"):
try:
machines = machines.page(request.GET['mpage'])
except EmptyPage:
machines = machines.page(machines.num_pages)
else:
machines = machines.page(1)
context = {
'layerversion': layer_version,
'layer_in_project' : ProjectLayer.objects.filter(project_id=request.session['project_id'],layercommit=layerid).count(),
'machines': machines,
'targets': targets,
'total_targets': Recipe.objects.filter(layer_version=layer_version).count(),
'total_machines': Machine.objects.filter(layer_version=layer_version).count(),
}
return render(request, template, context)
def targets(request):
if not 'project_id' in request.session:
raise Exception("invalid page: cannot show page without a project")
template = 'targets.html'
(pagesize, orderby) = _get_parameters_values(request, 100, 'name:+')
mandatory_parameters = { 'count': pagesize, 'page' : 1, 'orderby' : orderby }
retval = _verify_parameters( request.GET, mandatory_parameters )
if retval:
return _redirect_parameters( 'targets', request.GET, mandatory_parameters)
(filter_string, search_term, ordering_string) = _search_tuple(request, Recipe)
prj = Project.objects.get(pk = request.session['project_id'])
queryset_all = Recipe.objects.filter(Q(layer_version__up_branch__name= prj.release.name) | Q(layer_version__build__in = prj.build_set.all()))
queryset_with_search = _get_queryset(Recipe, queryset_all, None, search_term, ordering_string, '-name')
queryset_with_search.prefetch_related("layer_source")
# retrieve the objects that will be displayed in the table; targets a paginator and gets a page range to display
target_info = _build_page_range(Paginator(queryset_with_search, request.GET.get('count', 10)),request.GET.get('page', 1))
context = {
'projectlayerset' : jsonfilter(map(lambda x: x.layercommit.id, prj.projectlayer_set.all())),
'objects' : target_info,
'objectname' : "targets",
'default_orderby' : 'name:+',
'total_count': queryset_with_search.count(),
'tablecols' : [
{ 'name': 'Target',
'orderfield': _get_toggle_order(request, "name"),
'ordericon' : _get_toggle_order_icon(request, "name"),
},
{ 'name': 'Target version',
'dclass': 'span2',
},
{ 'name': 'Description',
'dclass': 'span5',
'clclass': 'description',
},
{ 'name': 'Recipe file',
'clclass': 'recipe-file',
'hidden': 1,
'dclass': 'span5',
},
{ 'name': 'Section',
'clclass': 'target-section',
'hidden': 1,
'orderfield': _get_toggle_order(request, "section"),
'ordericon': _get_toggle_order_icon(request, "section"),
},
{ 'name': 'License',
'clclass': 'license',
'hidden': 1,
'orderfield': _get_toggle_order(request, "license"),
'ordericon': _get_toggle_order_icon(request, "license"),
},
{ 'name': 'Layer',
'clclass': 'layer',
'orderfield': _get_toggle_order(request, "layer_version__layer__name"),
'ordericon': _get_toggle_order_icon(request, "layer_version__layer__name"),
},
{ 'name': 'Layer source',
'clclass': 'source',
'qhelp': "Where the target is coming from, for example, if it's part of the OpenEmbedded collection of targets or if it's a target you have imported",
'orderfield': _get_toggle_order(request, "layer_source__name"),
'ordericon': _get_toggle_order_icon(request, "layer_source__name"),
'filter': {
'class': 'target',
'label': 'Show:',
'options': map(lambda x: ("Targets provided by " + x.name + " layers", 'layer_source__pk:' + str(x.id), queryset_with_search.filter(layer_source__pk = x.id).count() ), LayerSource.objects.all()),
}
},
{ 'name': 'Branch, tag or commit',
'clclass': 'branch',
'hidden': 1,
},
]
}
if 'project_id' in request.session:
context['tablecols'] += [
{ 'name': 'Build',
'dclass': 'span2',
'qhelp': "Add or delete targets to / from your project ",
'filter': {
'class': 'add-layer',
'label': 'Show:',
'options': [
('Targets provided by layers added to this project', "layer_version__projectlayer__project:" + str(prj.id), queryset_with_search.filter(layer_version__projectlayer__project = prj.id).count()),
('Targets provided by layers not added to this project', "layer_version__projectlayer__project:NOT" + str(prj.id), queryset_with_search.exclude(layer_version__projectlayer__project = prj.id).count()),
]
}
}, ]
return render(request, template, context)
def machines(request):
template = "machines.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' : 'name:+' };
retval = _verify_parameters( request.GET, mandatory_parameters )
if retval:
return _redirect_parameters( 'machines', 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, Machine)
queryset_all = Machine.objects.all()
# if 'project_id' in request.session:
# queryset_all = queryset_all.filter(Q(layer_version__up_branch__name = Project.objects.get(request.session['project_id']).release.branch_name) | Q(layer_version__build__in = Project.objects.get(request.session['project_id']).build_set.all()))
queryset_with_search = _get_queryset(Machine, queryset_all, None, search_term, ordering_string, '-name')
queryset = _get_queryset(Machine, queryset_all, filter_string, search_term, ordering_string, '-name')
# retrieve the objects that will be displayed in the table; machines a paginator and gets a page range to display
machine_info = _build_page_range(Paginator(queryset, request.GET.get('count', 10)),request.GET.get('page', 1))
context = {
'objects' : machine_info,
'objectname' : "machines",
'default_orderby' : 'name:+',
'total_count': queryset_with_search.count(),
'tablecols' : [
{ 'name': 'Machine',
'orderfield': _get_toggle_order(request, "name"),
'ordericon' : _get_toggle_order_icon(request, "name"),
},
{ 'name': 'Description',
'dclass': 'span5',
'clclass': 'description',
},
{ 'name': 'Machine file',
'clclass': 'machine-file',
'hidden': 1,
},
{ 'name': 'Layer',
'clclass': 'layer',
},
{ 'name': 'Layer source',
'clclass': 'source',
'qhelp': "Where the machine is coming from, for example, if it's part of the OpenEmbedded collection of machines or if it's a machine you have imported",
'orderfield': _get_toggle_order(request, "layer_source__name"),
'ordericon': _get_toggle_order_icon(request, "layer_source__name"),
'filter': {
'class': 'machine',
'label': 'Show:',
'options': map(lambda x: (x.name, 'layer_source__pk:' + str(x.id), queryset_with_search.filter(layer_source__pk = x.id).count() ), LayerSource.objects.all()),
}
},
{ 'name': 'Branch, tag or commit',
'clclass': 'branch',
'hidden': 1,
},
{ 'name': 'Select',
'dclass': 'span2',
'qhelp': "Add or delete machines to / from your project ",
},
]
}
return render(request, template, context)
def get_project_configvars_context():
# Vars managed outside of this view
vars_managed = {
'MACHINE'
}
vars_blacklist = {
'DL_DR','PARALLEL_MAKE','BB_NUMBER_THREADS','SSTATE_DIR',
'BB_DISKMON_DIRS','BB_NUMBER_THREADS','CVS_PROXY_HOST','CVS_PROXY_PORT',
'DL_DIR','PARALLEL_MAKE','SSTATE_DIR','SSTATE_DIR','SSTATE_MIRRORS','TMPDIR',
'all_proxy','ftp_proxy','http_proxy ','https_proxy'
}
vars_fstypes = {
'btrfs','cpio','cpio.gz','cpio.lz4','cpio.lzma','cpio.xz','cramfs',
'elf','ext2','ext2.bz2','ext2.gz','ext2.lzma' 'ext3','ext3.gz','hddimg',
'iso','jffs2','jffs2.sum','squashfs','squashfs-lzo','squashfs-xz','tar.bz2',
'tar.lz4','tar.xz','tartar.gz','ubi','ubifs','vmdk'
}
return(vars_managed,sorted(vars_fstypes),vars_blacklist)
def projectconf(request, pid):
template = "projectconf.html"
try:
prj = Project.objects.get(id = pid)
except Project.DoesNotExist:
return HttpResponseNotFound("<h1>Project id " + pid + " is unavailable</h1>")
vars_managed,vars_fstypes,vars_blacklist = get_project_configvars_context()
context = {
'configvars': ProjectVariable.objects.filter(project_id = pid).all(),
'vars_managed': vars_managed,
'vars_fstypes': vars_fstypes,
'vars_blacklist': vars_blacklist,
}
try:
context['distro'] = ProjectVariable.objects.get(project = prj, name = "DISTRO").value
except ProjectVariable.DoesNotExist:
pass
try:
context['fstypes'] = ProjectVariable.objects.get(project = prj, name = "IMAGE_FSTYPES").value
except ProjectVariable.DoesNotExist:
pass
try:
context['image_install_append'] = ProjectVariable.objects.get(project = prj, name = "IMAGE_INSTALL_append").value
except ProjectVariable.DoesNotExist:
pass
try:
context['package_classes'] = ProjectVariable.objects.get(project = prj, name = "PACKAGE_CLASSES").value
except ProjectVariable.DoesNotExist:
pass
try:
context['sdk_machine'] = ProjectVariable.objects.get(project = prj, name = "SDKMACHINE").value
except ProjectVariable.DoesNotExist:
pass
return render(request, template, context)
def projectbuilds(request, pid):
template = 'projectbuilds.html'
buildrequests = BuildRequest.objects.exclude(project_id = pid, state__lte = BuildRequest.REQ_INPROGRESS).exclude(state=BuildRequest.REQ_DELETED)
try:
context, pagesize, orderby = _build_list_helper(request, buildrequests)
except InvalidRequestException as e:
return _redirect_parameters(projectbuilds, request.GET, e.response, pid = pid)
response = render(request, template, context)
_save_parameters_cookies(response, pagesize, orderby, request)
return response
def _file_name_for_artifact(b, artifact_type, artifact_id):
file_name = None
# Target_Image_File file_name
if artifact_type == "imagefile":
file_name = Target_Image_File.objects.get(target__build = b, pk = artifact_id).file_name
elif artifact_type == "cookerlog":
file_name = b.cooker_log_path
elif artifact_type == "buildartifact":
file_name = BuildArtifact.objects.get(build = b, pk = artifact_id).file_name
elif artifact_type == "licensemanifest":
file_name = Target.objects.get(build = b, pk = artifact_id).license_manifest_path
elif artifact_type == "tasklogfile":
file_name = Task.objects.get(build = b, pk = artifact_id).logfile
elif artifact_type == "logmessagefile":
file_name = LogMessage.objects.get(build = b, pk = artifact_id).pathname
else:
raise Exception("FIXME: artifact type %s not implemented" % (artifact_type))
return file_name
def build_artifact(request, build_id, artifact_type, artifact_id):
b = Build.objects.get(pk=build_id)
if b.buildrequest is None or b.buildrequest.environment is None:
raise Exception("Artifact not available for download (missing build request or build environment)")
file_name = _file_name_for_artifact(b, artifact_type, artifact_id)
fsock = None
content_type='application/force-download'
if file_name is None:
raise Exception("Could not handle artifact %s id %s" % (artifact_type, artifact_id))
else:
content_type = b.buildrequest.environment.get_artifact_type(file_name)
fsock = b.buildrequest.environment.get_artifact(file_name)
file_name = os.path.basename(file_name) # we assume that the build environment system has the same path conventions as host
response = HttpResponse(fsock, content_type = content_type)
# returns a file from the environment
response['Content-Disposition'] = 'attachment; filename=' + file_name
return response
def projects(request):
template="projects.html"
(pagesize, orderby) = _get_parameters_values(request, 10, 'updated:+')
mandatory_parameters = { 'count': pagesize, 'page' : 1, 'orderby' : orderby }
retval = _verify_parameters( request.GET, mandatory_parameters )
if retval:
return _redirect_parameters( 'all-projects', request.GET, mandatory_parameters)
queryset_all = Project.objects.all()
# 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, Project)
queryset_with_search = _get_queryset(Project, queryset_all, None, search_term, ordering_string, '-updated')
queryset = _get_queryset(Project, queryset_all, filter_string, search_term, ordering_string, '-updated')
# retrieve the objects that will be displayed in the table; projects a paginator and gets a page range to display
project_info = _build_page_range(Paginator(queryset, pagesize), 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.order_by("-started_on")[:3]
context = {
'mru' : build_mru,
'objects' : project_info,
'objectname' : "projects",
'default_orderby' : 'id:-',
'search_term' : search_term,
'total_count' : queryset_with_search.count(),
'tablecols': [
{'name': 'Project',
'orderfield': _get_toggle_order(request, "name"),
'ordericon':_get_toggle_order_icon(request, "name"),
'orderkey' : 'name',
},
{'name': 'Release',
'qhelp' : "The version of the build system used by the project",
'orderfield': _get_toggle_order(request, "release__name"),
'ordericon':_get_toggle_order_icon(request, "release__name"),
'orderkey' : 'release__name',
},
{'name': 'Machine',
'qhelp': "The hardware currently selected for the project",
},
{'name': 'Number of builds',
'qhelp': "How many builds have been run for the project",
},
{'name': 'Last outcome', 'clclass': 'loutcome',
'qhelp': "Tells you if the last project build completed successfully or failed",
},
{'name': 'Last target', 'clclass': 'ltarget',
'qhelp': "The last project build target(s): one or more recipes or image recipes",
},
{'name': 'Last errors', 'clclass': 'lerrors',
'qhelp': "How many errors were encountered during the last project build (if any)",
},
{'name': 'Last warnings', 'clclass': 'lwarnings',
'qhelp': "How many warnigns were encountered during the last project build (if any)",
},
{'name': 'Last image files', 'clclass': 'limagefiles', 'hidden': 1,
'qhelp': "The root file system types produced by the last project build",
},
{'name': 'Last updated', 'clclass': 'updated',
'orderfield': _get_toggle_order(request, "updated"),
'ordericon':_get_toggle_order_icon(request, "updated"),
'orderkey' : 'updated',
}
]
}
return render(request, template, context)
else:
# these are pages that are NOT available in interactive mode
def managedcontextprocessor(request):
return {
"projects": [],
"MANAGED" : toastermain.settings.MANAGED,
"DEBUG" : toastermain.settings.DEBUG
}
# shows the "all builds" page for interactive mode; this is the old code, simply moved
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.
(pagesize, orderby) = _get_parameters_values(request, 10, 'completed_on:-')
mandatory_parameters = { 'count': pagesize, 'page' : 1, 'orderby' : orderby }
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, '-completed_on')
queryset = _get_queryset(Build, queryset_all, filter_string, search_term, ordering_string, '-completed_on')
# 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, pagesize), 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.order_by("-started_on")[:3]
# 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",
'default_orderby' : 'completed_on:-',
'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 successfully completed 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 or build targets (i.e. 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 a recipe or image recipe",
'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()).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))).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))).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"),
'orderkey' : '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()).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))).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))).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"),
'orderkey' : '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"),
'orderkey' : '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"),
'orderkey' : 'timespent',
},
{'name': 'Image files', '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
},
]
}
if not toastermain.settings.MANAGED:
context['tablecols'].insert(-2,
{'name': 'Log1',
'dclass': "span4",
'qhelp': "Path to 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"),
'orderkey' : 'cooker_log_path',
}
)
if toastermain.settings.MANAGED:
context['tablecols'].append(
{'name': 'Project', 'clclass': 'project',
'filter': {'class': 'project',
'label': 'Project:',
'options': map(lambda x: (x.name,'',x.build_set.filter(outcome__lt=Build.IN_PROGRESS).count()), Project.objects.all()),
}
}
)
response = render(request, template, context)
_save_parameters_cookies(response, pagesize, orderby, request)
return response
def newproject(request):
raise Exception("page not available in interactive mode")
def project(request, pid):
raise Exception("page not available in interactive mode")
def xhr_projectbuild(request, pid):
raise Exception("page not available in interactive mode")
def xhr_build(request, pid):
raise Exception("page not available in interactive mode")
def xhr_projectinfo(request, pid):
raise Exception("page not available in interactive mode")
def xhr_projectedit(request, pid):
raise Exception("page not available in interactive mode")
def xhr_datatypeahead(request):
raise Exception("page not available in interactive mode")
def importlayer(request):
raise Exception("page not available in interactive mode")
def layers(request):
raise Exception("page not available in interactive mode")
def layerdetails(request):
raise Exception("page not available in interactive mode")
def targets(request):
raise Exception("page not available in interactive mode")
def targetdetails(request):
raise Exception("page not available in interactive mode")
def machines(request):
raise Exception("page not available in interactive mode")
def projectconf(request):
raise Exception("page not available in interactive mode")
def projectbuilds(request):
raise Exception("page not available in interactive mode")
def build_artifact(request, build_id, artifact_type, artifact_id):
raise Exception("page not available in interactive mode")
def projects(request):
raise Exception("page not available in interactive mode")
def xhr_importlayer(request):
raise Exception("page not available in interactive mode")
def xhr_updatelayer(request):
raise Exception("page not available in interactive mode")
|