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
|
#!/usr/bin/python -O
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# Next to do: dep syntax checking in mask files
# Then, check to make sure deps are satisfiable (to avoid "can't find match for" problems)
# that last one is tricky because multiple profiles need to be checked.
from __future__ import print_function, unicode_literals
import codecs
import copy
import errno
import formatter
import io
import logging
import re
import signal
import stat
import subprocess
import sys
import tempfile
import textwrap
import time
import platform
from itertools import chain
from stat import S_ISDIR
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
from os import path as osp
pym_path = osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), "pym")
sys.path.insert(0, pym_path)
import portage
portage._internal_caller = True
portage._disable_legacy_globals()
try:
import xml.etree.ElementTree
from xml.parsers.expat import ExpatError
except (SystemExit, KeyboardInterrupt):
raise
except (ImportError, SystemError, RuntimeError, Exception):
# broken or missing xml support
# http://bugs.python.org/issue14988
msg = ["Please enable python's \"xml\" USE flag in order to use repoman."]
from portage.output import EOutput
out = EOutput()
for line in msg:
out.eerror(line)
sys.exit(1)
from portage import os
from portage import _encodings
from portage import _unicode_encode
import repoman.checks
from repoman.checks import run_checks
from repoman import utilities
from repoman.herdbase import make_herd_base
from _emerge.Package import Package
from _emerge.RootConfig import RootConfig
from _emerge.userquery import userquery
import portage.checksum
import portage.const
import portage.repository.config
from portage import cvstree, normalize_path
from portage import util
from portage.exception import (FileNotFound, InvalidAtom, MissingParameter,
ParseError, PermissionDenied)
from portage.dep import Atom
from portage.process import find_binary, spawn
from portage.output import bold, create_color_func, \
green, nocolor, red
from portage.output import ConsoleStyleFile, StyleWriter
from portage.util import writemsg_level
from portage.util._argparse import ArgumentParser
from portage.package.ebuild.digestgen import digestgen
from portage.eapi import eapi_has_iuse_defaults, eapi_has_required_use
if sys.hexversion >= 0x3000000:
basestring = str
util.initialize_logger()
# 14 is the length of DESCRIPTION=""
max_desc_len = 100
allowed_filename_chars="a-zA-Z0-9._-+:"
pv_toolong_re = re.compile(r'[0-9]{19,}')
GPG_KEY_ID_REGEX = r'(0x)?([0-9a-fA-F]{8}|[0-9a-fA-F]{16}|[0-9a-fA-F]{24}|[0-9a-fA-F]{32}|[0-9a-fA-F]{40})!?'
bad = create_color_func("BAD")
# A sane umask is needed for files that portage creates.
os.umask(0o22)
# Repoman sets it's own ACCEPT_KEYWORDS and we don't want it to
# behave incrementally.
repoman_incrementals = tuple(x for x in \
portage.const.INCREMENTALS if x != 'ACCEPT_KEYWORDS')
config_root = os.environ.get("PORTAGE_CONFIGROOT")
repoman_settings = portage.config(config_root=config_root, local_config=False)
if repoman_settings.get("NOCOLOR", "").lower() in ("yes", "true") or \
repoman_settings.get('TERM') == 'dumb' or \
not sys.stdout.isatty():
nocolor()
def warn(txt):
print("repoman: " + txt)
def err(txt):
warn(txt)
sys.exit(1)
def exithandler(signum=None, _frame=None):
logging.fatal("Interrupted; exiting...")
if signum is None:
sys.exit(1)
else:
sys.exit(128 + signum)
signal.signal(signal.SIGINT, exithandler)
def ParseArgs(argv, qahelp):
"""This function uses a customized optionParser to parse command line arguments for repoman
Args:
argv - a sequence of command line arguments
qahelp - a dict of qa warning to help message
Returns:
(opts, args), just like a call to parser.parse_args()
"""
argv = portage._decode_argv(argv)
modes = {
'commit' : 'Run a scan then commit changes',
'ci' : 'Run a scan then commit changes',
'fix' : 'Fix simple QA issues (stray digests, missing digests)',
'full' : 'Scan directory tree and print all issues (not a summary)',
'help' : 'Show this screen',
'manifest' : 'Generate a Manifest (fetches files if necessary)',
'manifest-check' : 'Check Manifests for missing or incorrect digests',
'scan' : 'Scan directory tree for QA issues'
}
mode_keys = list(modes)
mode_keys.sort()
parser = ArgumentParser(usage="repoman [options] [mode]",
description="Modes: %s" % " | ".join(mode_keys),
epilog="For more help consult the man page.")
parser.add_argument('-a', '--ask', dest='ask', action='store_true', default=False,
help='Request a confirmation before commiting')
parser.add_argument('-m', '--commitmsg', dest='commitmsg',
help='specify a commit message on the command line')
parser.add_argument('-M', '--commitmsgfile', dest='commitmsgfile',
help='specify a path to a file that contains a commit message')
parser.add_argument('--digest',
choices=('y', 'n'), metavar='<y|n>',
help='Automatically update Manifest digests for modified files')
parser.add_argument('-p', '--pretend', dest='pretend', default=False,
action='store_true', help='don\'t commit or fix anything; just show what would be done')
parser.add_argument('-q', '--quiet', dest="quiet", action="count", default=0,
help='do not print unnecessary messages')
parser.add_argument(
'--echangelog', choices=('y', 'n', 'force'), metavar="<y|n|force>",
help='for commit mode, call echangelog if ChangeLog is unmodified (or '
'regardless of modification if \'force\' is specified)')
parser.add_argument('--experimental-inherit', choices=('y', 'n'),
metavar="<y|n>", default='n',
help='Enable experimental inherit.missing checks which may misbehave'
' when the internal eclass database becomes outdated')
parser.add_argument('-f', '--force', dest='force', default=False, action='store_true',
help='Commit with QA violations')
parser.add_argument('--vcs', dest='vcs',
help='Force using specific VCS instead of autodetection')
parser.add_argument('-v', '--verbose', dest="verbosity", action='count',
help='be very verbose in output', default=0)
parser.add_argument('-V', '--version', dest='version', action='store_true',
help='show version info')
parser.add_argument('-x', '--xmlparse', dest='xml_parse', action='store_true',
default=False, help='forces the metadata.xml parse check to be carried out')
parser.add_argument(
'--if-modified', choices=('y', 'n'), default='n',
metavar="<y|n>",
help='only check packages that have uncommitted modifications')
parser.add_argument('-i', '--ignore-arches', dest='ignore_arches', action='store_true',
default=False, help='ignore arch-specific failures (where arch != host)')
parser.add_argument("--ignore-default-opts",
action="store_true",
help="do not use the REPOMAN_DEFAULT_OPTS environment variable")
parser.add_argument('-I', '--ignore-masked', dest='ignore_masked', action='store_true',
default=False, help='ignore masked packages (not allowed with commit mode)')
parser.add_argument('--include-arches', dest='include_arches',
metavar='ARCHES', action='append',
help='A space separated list of arches used to '
'filter the selection of profiles for dependency checks')
parser.add_argument('-d', '--include-dev', dest='include_dev', action='store_true',
default=False, help='include dev profiles in dependency checks')
parser.add_argument('-e', '--include-exp-profiles', choices=('y', 'n'),
default=False, help='include exp profiles in dependency checks',
metavar='<y|n>')
parser.add_argument('--unmatched-removal', dest='unmatched_removal', action='store_true',
default=False, help='enable strict checking of package.mask and package.unmask files for unmatched removal atoms')
parser.add_argument('--without-mask', dest='without_mask', action='store_true',
default=False, help='behave as if no package.mask entries exist (not allowed with commit mode)')
parser.add_argument('--mode', dest='mode', choices=mode_keys,
help='specify which mode repoman will run in (default=full)')
opts, args = parser.parse_known_args(argv[1:])
if not opts.ignore_default_opts:
default_opts = portage.util.shlex_split(
repoman_settings.get("REPOMAN_DEFAULT_OPTS", ""))
if default_opts:
opts, args = parser.parse_known_args(default_opts + sys.argv[1:])
if opts.mode == 'help':
parser.print_help(short=False)
for arg in args:
if arg in modes:
if not opts.mode:
opts.mode = arg
break
else:
parser.error("invalid mode: %s" % arg)
if not opts.mode:
opts.mode = 'full'
if opts.mode == 'ci':
opts.mode = 'commit' # backwards compat shortcut
# Use the verbosity and quiet options to fiddle with the loglevel appropriately
for val in range(opts.verbosity):
logger = logging.getLogger()
logger.setLevel(logger.getEffectiveLevel() - 10)
for val in range(opts.quiet):
logger = logging.getLogger()
logger.setLevel(logger.getEffectiveLevel() + 10)
if opts.mode == 'commit' and not (opts.force or opts.pretend):
if opts.ignore_masked:
opts.ignore_masked = False
logging.warn('Commit mode automatically disables --ignore-masked')
if opts.without_mask:
opts.without_mask = False
logging.warn('Commit mode automatically disables --without-mask')
return (opts, args)
qahelp = {
"CVS/Entries.IO_error": "Attempting to commit, and an IO error was encountered access the Entries file",
"ebuild.invalidname": "Ebuild files with a non-parseable or syntactically incorrect name (or using 2.1 versioning extensions)",
"ebuild.namenomatch": "Ebuild files that do not have the same name as their parent directory",
"changelog.ebuildadded": "An ebuild was added but the ChangeLog was not modified",
"changelog.missing": "Missing ChangeLog files",
"ebuild.notadded": "Ebuilds that exist but have not been added to cvs",
"ebuild.patches": "PATCHES variable should be a bash array to ensure white space safety",
"changelog.notadded": "ChangeLogs that exist but have not been added to cvs",
"dependency.bad": "User-visible ebuilds with unsatisfied dependencies (matched against *visible* ebuilds)",
"dependency.badmasked": "Masked ebuilds with unsatisfied dependencies (matched against *all* ebuilds)",
"dependency.badindev": "User-visible ebuilds with unsatisfied dependencies (matched against *visible* ebuilds) in developing arch",
"dependency.badmaskedindev": "Masked ebuilds with unsatisfied dependencies (matched against *all* ebuilds) in developing arch",
"dependency.badtilde": "Uses the ~ dep operator with a non-zero revision part, which is useless (the revision is ignored)",
"dependency.syntax": "Syntax error in dependency string (usually an extra/missing space/parenthesis)",
"dependency.unknown": "Ebuild has a dependency that refers to an unknown package (which may be valid if it is a blocker for a renamed/removed package, or is an alternative choice provided by an overlay)",
"file.executable": "Ebuilds, digests, metadata.xml, Manifest, and ChangeLog do not need the executable bit",
"file.size": "Files in the files directory must be under 20 KiB",
"file.size.fatal": "Files in the files directory must be under 60 KiB",
"file.name": "File/dir name must be composed of only the following chars: %s " % allowed_filename_chars,
"file.UTF8": "File is not UTF8 compliant",
"inherit.deprecated": "Ebuild inherits a deprecated eclass",
"inherit.missing": "Ebuild uses functions from an eclass but does not inherit it",
"inherit.unused": "Ebuild inherits an eclass but does not use it",
"java.eclassesnotused": "With virtual/jdk in DEPEND you must inherit a java eclass",
"wxwidgets.eclassnotused": "Ebuild DEPENDs on x11-libs/wxGTK without inheriting wxwidgets.eclass",
"KEYWORDS.dropped": "Ebuilds that appear to have dropped KEYWORDS for some arch",
"KEYWORDS.missing": "Ebuilds that have a missing or empty KEYWORDS variable",
"KEYWORDS.stable": "Ebuilds that have been added directly with stable KEYWORDS",
"KEYWORDS.stupid": "Ebuilds that use KEYWORDS=-* instead of package.mask",
"LICENSE.missing": "Ebuilds that have a missing or empty LICENSE variable",
"LICENSE.virtual": "Virtuals that have a non-empty LICENSE variable",
"DESCRIPTION.missing": "Ebuilds that have a missing or empty DESCRIPTION variable",
"DESCRIPTION.toolong": "DESCRIPTION is over %d characters" % max_desc_len,
"EAPI.definition": "EAPI definition does not conform to PMS section 7.3.1 (first non-comment, non-blank line)",
"EAPI.deprecated": "Ebuilds that use features that are deprecated in the current EAPI",
"EAPI.incompatible": "Ebuilds that use features that are only available with a different EAPI",
"EAPI.unsupported": "Ebuilds that have an unsupported EAPI version (you must upgrade portage)",
"SLOT.invalid": "Ebuilds that have a missing or invalid SLOT variable value",
"HOMEPAGE.missing": "Ebuilds that have a missing or empty HOMEPAGE variable",
"HOMEPAGE.virtual": "Virtuals that have a non-empty HOMEPAGE variable",
"PDEPEND.suspect": "PDEPEND contains a package that usually only belongs in DEPEND.",
"LICENSE.syntax": "Syntax error in LICENSE (usually an extra/missing space/parenthesis)",
"PROVIDE.syntax": "Syntax error in PROVIDE (usually an extra/missing space/parenthesis)",
"PROPERTIES.syntax": "Syntax error in PROPERTIES (usually an extra/missing space/parenthesis)",
"RESTRICT.syntax": "Syntax error in RESTRICT (usually an extra/missing space/parenthesis)",
"REQUIRED_USE.syntax": "Syntax error in REQUIRED_USE (usually an extra/missing space/parenthesis)",
"SRC_URI.syntax": "Syntax error in SRC_URI (usually an extra/missing space/parenthesis)",
"SRC_URI.mirror": "A uri listed in profiles/thirdpartymirrors is found in SRC_URI",
"ebuild.syntax": "Error generating cache entry for ebuild; typically caused by ebuild syntax error or digest verification failure",
"ebuild.output": "A simple sourcing of the ebuild produces output; this breaks ebuild policy.",
"ebuild.nesteddie": "Placing 'die' inside ( ) prints an error, but doesn't stop the ebuild.",
"variable.invalidchar": "A variable contains an invalid character that is not part of the ASCII character set",
"variable.readonly": "Assigning a readonly variable",
"variable.usedwithhelpers": "Ebuild uses D, ROOT, ED, EROOT or EPREFIX with helpers",
"LIVEVCS.stable": "This ebuild is a live checkout from a VCS but has stable keywords.",
"LIVEVCS.unmasked": "This ebuild is a live checkout from a VCS but has keywords and is not masked in the global package.mask.",
"IUSE.invalid": "This ebuild has a variable in IUSE that is not in the use.desc or its metadata.xml file",
"IUSE.missing": "This ebuild has a USE conditional which references a flag that is not listed in IUSE",
"IUSE.rubydeprecated": "The ebuild has set a ruby interpreter in USE_RUBY, that is not available as a ruby target anymore",
"LICENSE.invalid": "This ebuild is listing a license that doesnt exist in portages license/ dir.",
"LICENSE.deprecated": "This ebuild is listing a deprecated license.",
"KEYWORDS.invalid": "This ebuild contains KEYWORDS that are not listed in profiles/arch.list or for which no valid profile was found",
"RDEPEND.implicit": "RDEPEND is unset in the ebuild which triggers implicit RDEPEND=$DEPEND assignment (prior to EAPI 4)",
"RDEPEND.suspect": "RDEPEND contains a package that usually only belongs in DEPEND.",
"RESTRICT.invalid": "This ebuild contains invalid RESTRICT values.",
"digest.assumed": "Existing digest must be assumed correct (Package level only)",
"digest.missing": "Some files listed in SRC_URI aren't referenced in the Manifest",
"digest.unused": "Some files listed in the Manifest aren't referenced in SRC_URI",
"ebuild.majorsyn": "This ebuild has a major syntax error that may cause the ebuild to fail partially or fully",
"ebuild.minorsyn": "This ebuild has a minor syntax error that contravenes gentoo coding style",
"ebuild.badheader": "This ebuild has a malformed header",
"manifest.bad": "Manifest has missing or incorrect digests",
"metadata.missing": "Missing metadata.xml files",
"metadata.bad": "Bad metadata.xml files",
"metadata.warning": "Warnings in metadata.xml files",
"portage.internal": "The ebuild uses an internal Portage function or variable",
"repo.eapi.banned": "The ebuild uses an EAPI which is banned by the repository's metadata/layout.conf settings",
"repo.eapi.deprecated": "The ebuild uses an EAPI which is deprecated by the repository's metadata/layout.conf settings",
"virtual.oldstyle": "The ebuild PROVIDEs an old-style virtual (see GLEP 37)",
"virtual.suspect": "Ebuild contains a package that usually should be pulled via virtual/, not directly.",
"usage.obsolete": "The ebuild makes use of an obsolete construct",
"upstream.workaround": "The ebuild works around an upstream bug, an upstream bug should be filed and tracked in bugs.gentoo.org"
}
qacats = list(qahelp)
qacats.sort()
qawarnings = set((
"changelog.missing",
"changelog.notadded",
"dependency.unknown",
"digest.assumed",
"digest.unused",
"ebuild.notadded",
"ebuild.nesteddie",
"dependency.badmasked",
"dependency.badindev",
"dependency.badmaskedindev",
"dependency.badtilde",
"DESCRIPTION.toolong",
"EAPI.deprecated",
"HOMEPAGE.virtual",
"LICENSE.deprecated",
"LICENSE.virtual",
"KEYWORDS.dropped",
"KEYWORDS.stupid",
"KEYWORDS.missing",
"PDEPEND.suspect",
"RDEPEND.implicit",
"RDEPEND.suspect",
"virtual.suspect",
"RESTRICT.invalid",
"ebuild.minorsyn",
"ebuild.badheader",
"ebuild.patches",
"file.size",
"inherit.unused",
"inherit.deprecated",
"java.eclassesnotused",
"wxwidgets.eclassnotused",
"metadata.warning",
"portage.internal",
"repo.eapi.deprecated",
"usage.obsolete",
"upstream.workaround",
"LIVEVCS.stable",
"LIVEVCS.unmasked",
"IUSE.rubydeprecated",
))
non_ascii_re = re.compile(r'[^\x00-\x7f]')
missingvars = ["KEYWORDS", "LICENSE", "DESCRIPTION", "HOMEPAGE"]
allvars = set(x for x in portage.auxdbkeys if not x.startswith("UNUSED_"))
allvars.update(Package.metadata_keys)
allvars = sorted(allvars)
commitmessage = None
for x in missingvars:
x += ".missing"
if x not in qacats:
logging.warn('* missingvars values need to be added to qahelp ("%s")' % x)
qacats.append(x)
qawarnings.add(x)
valid_restrict = frozenset(["binchecks", "bindist",
"fetch", "installsources", "mirror", "preserve-libs",
"primaryuri", "splitdebug", "strip", "test", "userpriv"])
live_eclasses = portage.const.LIVE_ECLASSES
suspect_rdepend = frozenset([
"app-arch/cabextract",
"app-arch/rpm2targz",
"app-doc/doxygen",
"dev-lang/nasm",
"dev-lang/swig",
"dev-lang/yasm",
"dev-perl/extutils-pkgconfig",
"dev-util/byacc",
"dev-util/cmake",
"dev-util/ftjam",
"dev-util/gperf",
"dev-util/gtk-doc",
"dev-util/gtk-doc-am",
"dev-util/intltool",
"dev-util/jam",
"dev-util/pkg-config-lite",
"dev-util/pkgconf",
"dev-util/pkgconfig",
"dev-util/pkgconfig-openbsd",
"dev-util/scons",
"dev-util/unifdef",
"dev-util/yacc",
"media-gfx/ebdftopcf",
"sys-apps/help2man",
"sys-devel/autoconf",
"sys-devel/automake",
"sys-devel/bin86",
"sys-devel/bison",
"sys-devel/dev86",
"sys-devel/flex",
"sys-devel/m4",
"sys-devel/pmake",
"virtual/linux-sources",
"virtual/pkgconfig",
"x11-misc/bdftopcf",
"x11-misc/imake",
])
suspect_virtual = {
"dev-util/pkg-config-lite":"virtual/pkgconfig",
"dev-util/pkgconf":"virtual/pkgconfig",
"dev-util/pkgconfig":"virtual/pkgconfig",
"dev-util/pkgconfig-openbsd":"virtual/pkgconfig",
"dev-libs/libusb":"virtual/libusb",
"dev-libs/libusbx":"virtual/libusb",
"dev-libs/libusb-compat":"virtual/libusb",
}
ruby_deprecated = frozenset([
"ruby_targets_ree18",
])
metadata_xml_encoding = 'UTF-8'
metadata_xml_declaration = '<?xml version="1.0" encoding="%s"?>' % \
(metadata_xml_encoding,)
metadata_doctype_name = 'pkgmetadata'
metadata_dtd_uri = 'http://www.gentoo.org/dtd/metadata.dtd'
# force refetch if the local copy creation time is older than this
metadata_dtd_ctime_interval = 60 * 60 * 24 * 7 # 7 days
# file.executable
no_exec = frozenset(["Manifest", "ChangeLog", "metadata.xml"])
options, arguments = ParseArgs(sys.argv, qahelp)
if options.version:
print("Portage", portage.VERSION)
sys.exit(0)
if options.experimental_inherit == 'y':
# This is experimental, so it's non-fatal.
qawarnings.add("inherit.missing")
repoman.checks._init(experimental_inherit=True)
# Set this to False when an extraordinary issue (generally
# something other than a QA issue) makes it impossible to
# commit (like if Manifest generation fails).
can_force = True
portdir, portdir_overlay, mydir = utilities.FindPortdir(repoman_settings)
if portdir is None:
sys.exit(1)
myreporoot = os.path.basename(portdir_overlay)
myreporoot += mydir[len(portdir_overlay):]
if options.vcs:
if options.vcs in ('cvs', 'svn', 'git', 'bzr', 'hg'):
vcs = options.vcs
else:
vcs = None
else:
vcses = utilities.FindVCS()
if len(vcses) > 1:
print(red('*** Ambiguous workdir -- more than one VCS found at the same depth: %s.' % ', '.join(vcses)))
print(red('*** Please either clean up your workdir or specify --vcs option.'))
sys.exit(1)
elif vcses:
vcs = vcses[0]
else:
vcs = None
if options.if_modified == "y" and vcs is None:
logging.info("Not in a version controlled repository; "
"disabling --if-modified.")
options.if_modified = "n"
# Disable copyright/mtime check if vcs does not preserve mtime (bug #324075).
vcs_preserves_mtime = vcs in ('cvs',)
vcs_local_opts = repoman_settings.get("REPOMAN_VCS_LOCAL_OPTS", "").split()
vcs_global_opts = repoman_settings.get("REPOMAN_VCS_GLOBAL_OPTS")
if vcs_global_opts is None:
if vcs in ('cvs', 'svn'):
vcs_global_opts = "-q"
else:
vcs_global_opts = ""
vcs_global_opts = vcs_global_opts.split()
if options.mode == 'commit' and not options.pretend and not vcs:
logging.info("Not in a version controlled repository; enabling pretend mode.")
options.pretend = True
# Ensure that current repository is in the list of enabled repositories.
repodir = os.path.realpath(portdir_overlay)
try:
repoman_settings.repositories.get_repo_for_location(repodir)
except KeyError:
repo_name = portage.repository.config.RepoConfig._read_valid_repo_name(portdir_overlay)[0]
layout_conf_data = portage.repository.config.parse_layout_conf(portdir_overlay)[0]
if layout_conf_data['repo-name']:
repo_name = layout_conf_data['repo-name']
tmp_conf_file = io.StringIO(textwrap.dedent("""
[%s]
location = %s
""") % (repo_name, portdir_overlay))
# Ensure that the repository corresponding to $PWD overrides a
# repository of the same name referenced by the existing PORTDIR
# or PORTDIR_OVERLAY settings.
repoman_settings['PORTDIR_OVERLAY'] = "%s %s" % \
(repoman_settings.get('PORTDIR_OVERLAY', ''),
portage._shell_quote(portdir_overlay))
repositories = portage.repository.config.load_repository_config(repoman_settings, extra_files=[tmp_conf_file])
# We have to call the config constructor again so that attributes
# dependent on config.repositories are initialized correctly.
repoman_settings = portage.config(config_root=config_root, local_config=False, repositories=repositories)
root = repoman_settings['EROOT']
trees = {
root : {'porttree' : portage.portagetree(settings=repoman_settings)}
}
portdb = trees[root]['porttree'].dbapi
# Constrain dependency resolution to the master(s)
# that are specified in layout.conf.
repo_config = repoman_settings.repositories.get_repo_for_location(repodir)
portdb.porttrees = list(repo_config.eclass_db.porttrees)
portdir = portdb.porttrees[0]
commit_env = os.environ.copy()
# list() is for iteration on a copy.
for repo in list(repoman_settings.repositories):
# all paths are canonical
if repo.location not in repo_config.eclass_db.porttrees:
del repoman_settings.repositories[repo.name]
if repo_config.allow_provide_virtual:
qawarnings.add("virtual.oldstyle")
if repo_config.sign_commit:
if vcs == 'git':
# NOTE: It's possible to use --gpg-sign=key_id to specify the key in
# the commit arguments. If key_id is unspecified, then it must be
# configured by `git config user.signingkey key_id`.
vcs_local_opts.append("--gpg-sign")
if repoman_settings.get("PORTAGE_GPG_DIR"):
# Pass GNUPGHOME to git for bug #462362.
commit_env["GNUPGHOME"] = repoman_settings["PORTAGE_GPG_DIR"]
# Pass GPG_TTY to git for bug #477728.
try:
commit_env["GPG_TTY"] = os.ttyname(sys.stdin.fileno())
except OSError:
pass
# In order to disable manifest signatures, repos may set
# "sign-manifests = false" in metadata/layout.conf. This
# can be used to prevent merge conflicts like those that
# thin-manifests is designed to prevent.
sign_manifests = "sign" in repoman_settings.features and \
repo_config.sign_manifest
if repo_config.sign_manifest and repo_config.name == "gentoo" and \
options.mode in ("commit",) and not sign_manifests:
msg = ("The '%s' repository has manifest signatures enabled, "
"but FEATURES=sign is currently disabled. In order to avoid this "
"warning, enable FEATURES=sign in make.conf. Alternatively, "
"repositories can disable manifest signatures by setting "
"'sign-manifests = false' in metadata/layout.conf.") % \
(repo_config.name,)
for line in textwrap.wrap(msg, 60):
logging.warn(line)
if sign_manifests and options.mode in ("commit",) and \
repoman_settings.get("PORTAGE_GPG_KEY") and \
re.match(r'^%s$' % GPG_KEY_ID_REGEX,
repoman_settings["PORTAGE_GPG_KEY"]) is None:
logging.error("PORTAGE_GPG_KEY value is invalid: %s" %
repoman_settings["PORTAGE_GPG_KEY"])
sys.exit(1)
manifest_hashes = repo_config.manifest_hashes
if manifest_hashes is None:
manifest_hashes = portage.const.MANIFEST2_HASH_DEFAULTS
if options.mode in ("commit", "fix", "manifest"):
if portage.const.MANIFEST2_REQUIRED_HASH not in manifest_hashes:
msg = ("The 'manifest-hashes' setting in the '%s' repository's "
"metadata/layout.conf does not contain the '%s' hash which "
"is required by this portage version. You will have to "
"upgrade portage if you want to generate valid manifests for "
"this repository.") % \
(repo_config.name, portage.const.MANIFEST2_REQUIRED_HASH)
for line in textwrap.wrap(msg, 70):
logging.error(line)
sys.exit(1)
unsupported_hashes = manifest_hashes.difference(
portage.const.MANIFEST2_HASH_FUNCTIONS)
if unsupported_hashes:
msg = ("The 'manifest-hashes' setting in the '%s' repository's "
"metadata/layout.conf contains one or more hash types '%s' "
"which are not supported by this portage version. You will "
"have to upgrade portage if you want to generate valid "
"manifests for this repository.") % \
(repo_config.name, " ".join(sorted(unsupported_hashes)))
for line in textwrap.wrap(msg, 70):
logging.error(line)
sys.exit(1)
if options.echangelog is None and repo_config.update_changelog:
options.echangelog = 'y'
if vcs is None:
options.echangelog = 'n'
# The --echangelog option causes automatic ChangeLog generation,
# which invalidates changelog.ebuildadded and changelog.missing
# checks.
# Note: Some don't use ChangeLogs in distributed SCMs.
# It will be generated on server side from scm log,
# before package moves to the rsync server.
# This is needed because they try to avoid merge collisions.
# Gentoo's Council decided to always use the ChangeLog file.
# TODO: shouldn't this just be switched on the repo, iso the VCS?
check_changelog = options.echangelog not in ('y', 'force') and vcs in ('cvs', 'svn')
if 'digest' in repoman_settings.features and options.digest != 'n':
options.digest = 'y'
logging.debug("vcs: %s" % (vcs,))
logging.debug("repo config: %s" % (repo_config,))
logging.debug("options: %s" % (options,))
# It's confusing if these warnings are displayed without the user
# being told which profile they come from, so disable them.
env = os.environ.copy()
env['FEATURES'] = env.get('FEATURES', '') + ' -unknown-features-warn'
categories = []
for path in repo_config.eclass_db.porttrees:
categories.extend(portage.util.grabfile(
os.path.join(path, 'profiles', 'categories')))
repoman_settings.categories = frozenset(
portage.util.stack_lists([categories], incremental=1))
categories = repoman_settings.categories
portdb.settings = repoman_settings
root_config = RootConfig(repoman_settings, trees[root], None)
# We really only need to cache the metadata that's necessary for visibility
# filtering. Anything else can be discarded to reduce memory consumption.
portdb._aux_cache_keys.clear()
portdb._aux_cache_keys.update(["EAPI", "IUSE", "KEYWORDS", "repository", "SLOT"])
reposplit = myreporoot.split(os.path.sep)
repolevel = len(reposplit)
# check if it's in $PORTDIR/$CATEGORY/$PN , otherwise bail if commiting.
# Reason for this is if they're trying to commit in just $FILESDIR/*, the Manifest needs updating.
# this check ensures that repoman knows where it is, and the manifest recommit is at least possible.
if options.mode == 'commit' and repolevel not in [1, 2, 3]:
print(red("***")+" Commit attempts *must* be from within a vcs co, category, or package directory.")
print(red("***")+" Attempting to commit from a packages files directory will be blocked for instance.")
print(red("***")+" This is intended behaviour, to ensure the manifest is recommitted for a package.")
print(red("***"))
err("Unable to identify level we're commiting from for %s" % '/'.join(reposplit))
# Make startdir relative to the canonical repodir, so that we can pass
# it to digestgen and it won't have to be canonicalized again.
if repolevel == 1:
startdir = repodir
else:
startdir = normalize_path(mydir)
startdir = os.path.join(repodir, *startdir.split(os.sep)[-2 - repolevel + 3:])
def caterror(mycat):
err(mycat + " is not an official category. Skipping QA checks in this directory.\nPlease ensure that you add " + catdir + " to " + repodir + "/profiles/categories\nif it is a new category.")
def repoman_getstatusoutput(cmd):
"""
Implements an interface similar to getstatusoutput(), but with
customized unicode handling (see bug #310789) and without the shell.
"""
args = portage.util.shlex_split(cmd)
if sys.hexversion < 0x3020000 and sys.hexversion >= 0x3000000 and \
not os.path.isabs(args[0]):
# Python 3.1 _execvp throws TypeError for non-absolute executable
# path passed as bytes (see http://bugs.python.org/issue8513).
fullname = find_binary(args[0])
if fullname is None:
raise portage.exception.CommandNotFound(args[0])
args[0] = fullname
encoding = _encodings['fs']
args = [_unicode_encode(x,
encoding=encoding, errors='strict') for x in args]
proc = subprocess.Popen(args, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
output = portage._unicode_decode(proc.communicate()[0],
encoding=encoding, errors='strict')
if output and output[-1] == "\n":
# getstatusoutput strips one newline
output = output[:-1]
return (proc.wait(), output)
class repoman_popen(portage.proxy.objectproxy.ObjectProxy):
"""
Implements an interface similar to os.popen(), but with customized
unicode handling (see bug #310789) and without the shell.
"""
__slots__ = ('_proc', '_stdout')
def __init__(self, cmd):
args = portage.util.shlex_split(cmd)
if sys.hexversion < 0x3020000 and sys.hexversion >= 0x3000000 and \
not os.path.isabs(args[0]):
# Python 3.1 _execvp throws TypeError for non-absolute executable
# path passed as bytes (see http://bugs.python.org/issue8513).
fullname = find_binary(args[0])
if fullname is None:
raise portage.exception.CommandNotFound(args[0])
args[0] = fullname
encoding = _encodings['fs']
args = [_unicode_encode(x,
encoding=encoding, errors='strict') for x in args]
proc = subprocess.Popen(args, stdout=subprocess.PIPE)
object.__setattr__(self, '_proc', proc)
object.__setattr__(self, '_stdout',
codecs.getreader(encoding)(proc.stdout, 'strict'))
def _get_target(self):
return object.__getattribute__(self, '_stdout')
__enter__ = _get_target
def __exit__(self, exc_type, exc_value, traceback):
proc = object.__getattribute__(self, '_proc')
proc.wait()
proc.stdout.close()
class ProfileDesc(object):
__slots__ = ('abs_path', 'arch', 'status', 'sub_path', 'tree_path',)
def __init__(self, arch, status, sub_path, tree_path):
self.arch = arch
self.status = status
if sub_path:
sub_path = normalize_path(sub_path.lstrip(os.sep))
self.sub_path = sub_path
self.tree_path = tree_path
if tree_path:
self.abs_path = os.path.join(tree_path, 'profiles', self.sub_path)
else:
self.abs_path = tree_path
def __str__(self):
if self.sub_path:
return self.sub_path
return 'empty profile'
profile_list = []
valid_profile_types = frozenset(['dev', 'exp', 'stable'])
# get lists of valid keywords, licenses, and use
kwlist = set()
liclist = set()
uselist = set()
global_pmasklines = []
for path in portdb.porttrees:
try:
liclist.update(os.listdir(os.path.join(path, "licenses")))
except OSError:
pass
kwlist.update(portage.grabfile(os.path.join(path,
"profiles", "arch.list")))
use_desc = portage.grabfile(os.path.join(path, 'profiles', 'use.desc'))
for x in use_desc:
x = x.split()
if x:
uselist.add(x[0])
expand_desc_dir = os.path.join(path, 'profiles', 'desc')
try:
expand_list = os.listdir(expand_desc_dir)
except OSError:
pass
else:
for fn in expand_list:
if not fn[-5:] == '.desc':
continue
use_prefix = fn[:-5].lower() + '_'
for x in portage.grabfile(os.path.join(expand_desc_dir, fn)):
x = x.split()
if x:
uselist.add(use_prefix + x[0])
global_pmasklines.append(portage.util.grabfile_package(
os.path.join(path, 'profiles', 'package.mask'), recursive=1, verify_eapi=True))
desc_path = os.path.join(path, 'profiles', 'profiles.desc')
try:
desc_file = io.open(_unicode_encode(desc_path,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'], errors='replace')
except EnvironmentError:
pass
else:
for i, x in enumerate(desc_file):
if x[0] == "#":
continue
arch = x.split()
if len(arch) == 0:
continue
if len(arch) != 3:
err("wrong format: \"" + bad(x.strip()) + "\" in " + \
desc_path + " line %d" % (i + 1, ))
elif arch[0] not in kwlist:
err("invalid arch: \"" + bad(arch[0]) + "\" in " + \
desc_path + " line %d" % (i + 1, ))
elif arch[2] not in valid_profile_types:
err("invalid profile type: \"" + bad(arch[2]) + "\" in " + \
desc_path + " line %d" % (i + 1, ))
profile_desc = ProfileDesc(arch[0], arch[2], arch[1], path)
if not os.path.isdir(profile_desc.abs_path):
logging.error(
"Invalid %s profile (%s) for arch %s in %s line %d",
arch[2], arch[1], arch[0], desc_path, i + 1)
continue
if os.path.exists(
os.path.join(profile_desc.abs_path, 'deprecated')):
continue
profile_list.append(profile_desc)
desc_file.close()
repoman_settings['PORTAGE_ARCHLIST'] = ' '.join(sorted(kwlist))
repoman_settings.backup_changes('PORTAGE_ARCHLIST')
global_pmasklines = portage.util.stack_lists(global_pmasklines, incremental=1)
global_pmaskdict = {}
for x in global_pmasklines:
global_pmaskdict.setdefault(x.cp, []).append(x)
del global_pmasklines
def has_global_mask(pkg):
mask_atoms = global_pmaskdict.get(pkg.cp)
if mask_atoms:
pkg_list = [pkg]
for x in mask_atoms:
if portage.dep.match_from_list(x, pkg_list):
return x
return None
# Ensure that profile sub_path attributes are unique. Process in reverse order
# so that profiles with duplicate sub_path from overlays will override
# profiles with the same sub_path from parent repos.
profiles = {}
profile_list.reverse()
profile_sub_paths = set()
for prof in profile_list:
if prof.sub_path in profile_sub_paths:
continue
profile_sub_paths.add(prof.sub_path)
profiles.setdefault(prof.arch, []).append(prof)
# Use an empty profile for checking dependencies of
# packages that have empty KEYWORDS.
prof = ProfileDesc('**', 'stable', '', '')
profiles.setdefault(prof.arch, []).append(prof)
for x in repoman_settings.archlist():
if x[0] == "~":
continue
if x not in profiles:
print(red("\"" + x + "\" doesn't have a valid profile listed in profiles.desc."))
print(red("You need to either \"cvs update\" your profiles dir or follow this"))
print(red("up with the " + x + " team."))
print()
liclist_deprecated = set()
if "DEPRECATED" in repoman_settings._license_manager._license_groups:
liclist_deprecated.update(
repoman_settings._license_manager.expandLicenseTokens(["@DEPRECATED"]))
if not liclist:
logging.fatal("Couldn't find licenses?")
sys.exit(1)
if not kwlist:
logging.fatal("Couldn't read KEYWORDS from arch.list")
sys.exit(1)
if not uselist:
logging.fatal("Couldn't find use.desc?")
sys.exit(1)
scanlist = []
if repolevel == 2:
# we are inside a category directory
catdir = reposplit[-1]
if catdir not in categories:
caterror(catdir)
mydirlist = os.listdir(startdir)
for x in mydirlist:
if x == "CVS" or x.startswith("."):
continue
if os.path.isdir(startdir + "/" + x):
scanlist.append(catdir + "/" + x)
repo_subdir = catdir + os.sep
elif repolevel == 1:
for x in categories:
if not os.path.isdir(startdir + "/" + x):
continue
for y in os.listdir(startdir + "/" + x):
if y == "CVS" or y.startswith("."):
continue
if os.path.isdir(startdir + "/" + x + "/" + y):
scanlist.append(x + "/" + y)
repo_subdir = ""
elif repolevel == 3:
catdir = reposplit[-2]
if catdir not in categories:
caterror(catdir)
scanlist.append(catdir + "/" + reposplit[-1])
repo_subdir = scanlist[-1] + os.sep
else:
msg = 'Repoman is unable to determine PORTDIR or PORTDIR_OVERLAY' + \
' from the current working directory'
logging.critical(msg)
sys.exit(1)
repo_subdir_len = len(repo_subdir)
scanlist.sort()
logging.debug("Found the following packages to scan:\n%s" % '\n'.join(scanlist))
def vcs_files_to_cps(vcs_file_iter):
"""
Iterate over the given modified file paths returned from the vcs,
and return a frozenset containing category/pn strings for each
modified package.
"""
modified_cps = []
if repolevel == 3:
if reposplit[-2] in categories and \
next(vcs_file_iter, None) is not None:
modified_cps.append("/".join(reposplit[-2:]))
elif repolevel == 2:
category = reposplit[-1]
if category in categories:
for filename in vcs_file_iter:
f_split = filename.split(os.sep)
# ['.', pn, ...]
if len(f_split) > 2:
modified_cps.append(category + "/" + f_split[1])
else:
# repolevel == 1
for filename in vcs_file_iter:
f_split = filename.split(os.sep)
# ['.', category, pn, ...]
if len(f_split) > 3 and f_split[1] in categories:
modified_cps.append("/".join(f_split[1:3]))
return frozenset(modified_cps)
def git_supports_gpg_sign():
status, cmd_output = \
repoman_getstatusoutput("git --version")
cmd_output = cmd_output.split()
if cmd_output:
version = re.match(r'^(\d+)\.(\d+)\.(\d+)', cmd_output[-1])
if version is not None:
version = [int(x) for x in version.groups()]
if version[0] > 1 or \
(version[0] == 1 and version[1] > 7) or \
(version[0] == 1 and version[1] == 7 and version[2] >= 9):
return True
return False
def dev_keywords(profiles):
"""
Create a set of KEYWORDS values that exist in 'dev'
profiles. These are used
to trigger a message notifying the user when they might
want to add the --include-dev option.
"""
type_arch_map = {}
for arch, arch_profiles in profiles.items():
for prof in arch_profiles:
arch_set = type_arch_map.get(prof.status)
if arch_set is None:
arch_set = set()
type_arch_map[prof.status] = arch_set
arch_set.add(arch)
dev_keywords = type_arch_map.get('dev', set())
dev_keywords.update(['~' + arch for arch in dev_keywords])
return frozenset(dev_keywords)
dev_keywords = dev_keywords(profiles)
stats = {}
fails = {}
for x in qacats:
stats[x] = 0
fails[x] = []
xmllint_capable = False
metadata_dtd = os.path.join(repoman_settings["DISTDIR"], 'metadata.dtd')
def fetch_metadata_dtd():
"""
Fetch metadata.dtd if it doesn't exist or the ctime is older than
metadata_dtd_ctime_interval.
@rtype: bool
@return: True if successful, otherwise False
"""
must_fetch = True
metadata_dtd_st = None
current_time = int(time.time())
try:
metadata_dtd_st = os.stat(metadata_dtd)
except EnvironmentError as e:
if e.errno not in (errno.ENOENT, errno.ESTALE):
raise
del e
else:
# Trigger fetch if metadata.dtd mtime is old or clock is wrong.
if abs(current_time - metadata_dtd_st.st_ctime) \
< metadata_dtd_ctime_interval:
must_fetch = False
if must_fetch:
print()
print(green("***") + " the local copy of metadata.dtd " + \
"needs to be refetched, doing that now")
print()
parsed_url = urlparse(metadata_dtd_uri)
setting = 'FETCHCOMMAND_' + parsed_url.scheme.upper()
fcmd = repoman_settings.get(setting)
if not fcmd:
fcmd = repoman_settings.get('FETCHCOMMAND')
if not fcmd:
logging.error("FETCHCOMMAND is unset")
return False
destdir = repoman_settings["DISTDIR"]
fd, metadata_dtd_tmp = tempfile.mkstemp(
prefix='metadata.dtd.', dir=destdir)
os.close(fd)
try:
if not portage.getbinpkg.file_get(metadata_dtd_uri,
destdir, fcmd=fcmd,
filename=os.path.basename(metadata_dtd_tmp)):
logging.error("failed to fetch metadata.dtd from '%s'" %
metadata_dtd_uri)
return False
try:
portage.util.apply_secpass_permissions(metadata_dtd_tmp,
gid=portage.data.portage_gid, mode=0o664, mask=0o2)
except portage.exception.PortageException:
pass
os.rename(metadata_dtd_tmp, metadata_dtd)
finally:
try:
os.unlink(metadata_dtd_tmp)
except OSError:
pass
return True
if options.mode == "manifest":
pass
elif not find_binary('xmllint'):
print(red("!!! xmllint not found. Can't check metadata.xml.\n"))
if options.xml_parse or repolevel == 3:
print(red("!!!")+" sorry, xmllint is needed. failing\n")
sys.exit(1)
else:
if not fetch_metadata_dtd():
sys.exit(1)
# this can be problematic if xmllint changes their output
xmllint_capable = True
if options.mode == 'commit' and vcs:
utilities.detect_vcs_conflicts(options, vcs)
if options.mode == "manifest":
pass
elif options.pretend:
print(green("\nRepoMan does a once-over of the neighborhood..."))
else:
print(green("\nRepoMan scours the neighborhood..."))
new_ebuilds = set()
modified_ebuilds = set()
modified_changelogs = set()
mychanged = []
mynew = []
myremoved = []
if vcs == "cvs":
mycvstree = cvstree.getentries("./", recursive=1)
mychanged = cvstree.findchanged(mycvstree, recursive=1, basedir="./")
mynew = cvstree.findnew(mycvstree, recursive=1, basedir="./")
if options.if_modified == "y":
myremoved = cvstree.findremoved(mycvstree, recursive=1, basedir="./")
elif vcs == "svn":
with repoman_popen("svn status") as f:
svnstatus = f.readlines()
mychanged = ["./" + elem.split()[-1:][0] for elem in svnstatus if elem and elem[:1] in "MR"]
mynew = ["./" + elem.split()[-1:][0] for elem in svnstatus if elem.startswith("A")]
if options.if_modified == "y":
myremoved = ["./" + elem.split()[-1:][0] for elem in svnstatus if elem.startswith("D")]
elif vcs == "git":
with repoman_popen("git diff-index --name-only "
"--relative --diff-filter=M HEAD") as f:
mychanged = f.readlines()
mychanged = ["./" + elem[:-1] for elem in mychanged]
with repoman_popen("git diff-index --name-only "
"--relative --diff-filter=A HEAD") as f:
mynew = f.readlines()
mynew = ["./" + elem[:-1] for elem in mynew]
if options.if_modified == "y":
with repoman_popen("git diff-index --name-only "
"--relative --diff-filter=D HEAD") as f:
myremoved = f.readlines()
myremoved = ["./" + elem[:-1] for elem in myremoved]
elif vcs == "bzr":
with repoman_popen("bzr status -S .") as f:
bzrstatus = f.readlines()
mychanged = ["./" + elem.split()[-1:][0].split('/')[-1:][0] for elem in bzrstatus if elem and elem[1:2] == "M"]
mynew = ["./" + elem.split()[-1:][0].split('/')[-1:][0] for elem in bzrstatus if elem and (elem[1:2] == "NK" or elem[0:1] == "R")]
if options.if_modified == "y":
myremoved = ["./" + elem.split()[-3:-2][0].split('/')[-1:][0] for elem in bzrstatus if elem and (elem[1:2] == "K" or elem[0:1] == "R")]
elif vcs == "hg":
with repoman_popen("hg status --no-status --modified .") as f:
mychanged = f.readlines()
mychanged = ["./" + elem.rstrip() for elem in mychanged]
with repoman_popen("hg status --no-status --added .") as f:
mynew = f.readlines()
mynew = ["./" + elem.rstrip() for elem in mynew]
if options.if_modified == "y":
with repoman_popen("hg status --no-status --removed .") as f:
myremoved = f.readlines()
myremoved = ["./" + elem.rstrip() for elem in myremoved]
if vcs:
new_ebuilds.update(x for x in mynew if x.endswith(".ebuild"))
modified_ebuilds.update(x for x in mychanged if x.endswith(".ebuild"))
modified_changelogs.update(x for x in chain(mychanged, mynew) \
if os.path.basename(x) == "ChangeLog")
def vcs_new_changed(relative_path):
for x in chain(mychanged, mynew):
if x == relative_path:
return True
return False
have_pmasked = False
have_dev_keywords = False
dofail = 0
# NOTE: match-all caches are not shared due to potential
# differences between profiles in _get_implicit_iuse.
arch_caches = {}
arch_xmatch_caches = {}
shared_xmatch_caches = {"cp-list":{}}
include_arches = None
if options.include_arches:
include_arches = set()
include_arches.update(*[x.split() for x in options.include_arches])
# Disable the "ebuild.notadded" check when not in commit mode and
# running `svn status` in every package dir will be too expensive.
check_ebuild_notadded = not \
(vcs == "svn" and repolevel < 3 and options.mode != "commit")
# Build a regex from thirdpartymirrors for the SRC_URI.mirror check.
thirdpartymirrors = {}
for k, v in repoman_settings.thirdpartymirrors().items():
for v in v:
if not v.endswith("/"):
v += "/"
thirdpartymirrors[v] = k
class _XMLParser(xml.etree.ElementTree.XMLParser):
def __init__(self, data, **kwargs):
xml.etree.ElementTree.XMLParser.__init__(self, **kwargs)
self._portage_data = data
if hasattr(self, 'parser'):
self._base_XmlDeclHandler = self.parser.XmlDeclHandler
self.parser.XmlDeclHandler = self._portage_XmlDeclHandler
self._base_StartDoctypeDeclHandler = \
self.parser.StartDoctypeDeclHandler
self.parser.StartDoctypeDeclHandler = \
self._portage_StartDoctypeDeclHandler
def _portage_XmlDeclHandler(self, version, encoding, standalone):
if self._base_XmlDeclHandler is not None:
self._base_XmlDeclHandler(version, encoding, standalone)
self._portage_data["XML_DECLARATION"] = (version, encoding, standalone)
def _portage_StartDoctypeDeclHandler(self, doctypeName, systemId, publicId,
has_internal_subset):
if self._base_StartDoctypeDeclHandler is not None:
self._base_StartDoctypeDeclHandler(doctypeName, systemId, publicId,
has_internal_subset)
self._portage_data["DOCTYPE"] = (doctypeName, systemId, publicId)
class _MetadataTreeBuilder(xml.etree.ElementTree.TreeBuilder):
"""
Implements doctype() as required to avoid deprecation warnings with
>=python-2.7.
"""
def doctype(self, name, pubid, system):
pass
try:
herd_base = make_herd_base(os.path.join(repoman_settings["PORTDIR"], "metadata/herds.xml"))
except (EnvironmentError, ParseError, PermissionDenied) as e:
err(str(e))
except FileNotFound:
# TODO: Download as we do for metadata.dtd, but add a way to
# disable for non-gentoo repoman users who may not have herds.
herd_base = None
effective_scanlist = scanlist
if options.if_modified == "y":
effective_scanlist = sorted(vcs_files_to_cps(
chain(mychanged, mynew, myremoved)))
for x in effective_scanlist:
# ebuilds and digests added to cvs respectively.
logging.info("checking package %s" % x)
# save memory by discarding xmatch caches from previous package(s)
arch_xmatch_caches.clear()
eadded = []
catdir, pkgdir = x.split("/")
checkdir = repodir + "/" + x
checkdir_relative = ""
if repolevel < 3:
checkdir_relative = os.path.join(pkgdir, checkdir_relative)
if repolevel < 2:
checkdir_relative = os.path.join(catdir, checkdir_relative)
checkdir_relative = os.path.join(".", checkdir_relative)
generated_manifest = False
if options.mode == "manifest" or \
(options.mode != 'manifest-check' and options.digest == 'y') or \
options.mode in ('commit', 'fix') and not options.pretend:
auto_assumed = set()
fetchlist_dict = portage.FetchlistDict(checkdir,
repoman_settings, portdb)
if options.mode == 'manifest' and options.force:
portage._doebuild_manifest_exempt_depend += 1
try:
distdir = repoman_settings['DISTDIR']
mf = repoman_settings.repositories.get_repo_for_location(
os.path.dirname(os.path.dirname(checkdir)))
mf = mf.load_manifest(checkdir, distdir,
fetchlist_dict=fetchlist_dict)
mf.create(requiredDistfiles=None,
assumeDistHashesAlways=True)
for distfiles in fetchlist_dict.values():
for distfile in distfiles:
if os.path.isfile(os.path.join(distdir, distfile)):
mf.fhashdict['DIST'].pop(distfile, None)
else:
auto_assumed.add(distfile)
mf.write()
finally:
portage._doebuild_manifest_exempt_depend -= 1
repoman_settings["O"] = checkdir
try:
generated_manifest = digestgen(
mysettings=repoman_settings, myportdb=portdb)
except portage.exception.PermissionDenied as e:
generated_manifest = False
writemsg_level("!!! Permission denied: '%s'\n" % (e,),
level=logging.ERROR, noiselevel=-1)
if not generated_manifest:
print("Unable to generate manifest.")
dofail = 1
if options.mode == "manifest":
if not dofail and options.force and auto_assumed and \
'assume-digests' in repoman_settings.features:
# Show which digests were assumed despite the --force option
# being given. This output will already have been shown by
# digestgen() if assume-digests is not enabled, so only show
# it here if assume-digests is enabled.
pkgs = list(fetchlist_dict)
pkgs.sort()
portage.writemsg_stdout(" digest.assumed" + \
portage.output.colorize("WARN",
str(len(auto_assumed)).rjust(18)) + "\n")
for cpv in pkgs:
fetchmap = fetchlist_dict[cpv]
pf = portage.catsplit(cpv)[1]
for distfile in sorted(fetchmap):
if distfile in auto_assumed:
portage.writemsg_stdout(
" %s::%s\n" % (pf, distfile))
continue
elif dofail:
sys.exit(1)
if not generated_manifest:
repoman_settings['O'] = checkdir
repoman_settings['PORTAGE_QUIET'] = '1'
if not portage.digestcheck([], repoman_settings, strict=1):
stats["manifest.bad"] += 1
fails["manifest.bad"].append(os.path.join(x, 'Manifest'))
repoman_settings.pop('PORTAGE_QUIET', None)
if options.mode == 'manifest-check':
continue
checkdirlist = os.listdir(checkdir)
ebuildlist = []
pkgs = {}
allvalid = True
for y in checkdirlist:
if (y in no_exec or y.endswith(".ebuild")) and \
stat.S_IMODE(os.stat(os.path.join(checkdir, y)).st_mode) & 0o111:
stats["file.executable"] += 1
fails["file.executable"].append(os.path.join(checkdir, y))
if y.endswith(".ebuild"):
pf = y[:-7]
ebuildlist.append(pf)
cpv = "%s/%s" % (catdir, pf)
try:
myaux = dict(zip(allvars, portdb.aux_get(cpv, allvars)))
except KeyError:
allvalid = False
stats["ebuild.syntax"] += 1
fails["ebuild.syntax"].append(os.path.join(x, y))
continue
except IOError:
allvalid = False
stats["ebuild.output"] += 1
fails["ebuild.output"].append(os.path.join(x, y))
continue
if not portage.eapi_is_supported(myaux["EAPI"]):
allvalid = False
stats["EAPI.unsupported"] += 1
fails["EAPI.unsupported"].append(os.path.join(x, y))
continue
pkgs[pf] = Package(cpv=cpv, metadata=myaux,
root_config=root_config, type_name="ebuild")
slot_keywords = {}
if len(pkgs) != len(ebuildlist):
# If we can't access all the metadata then it's totally unsafe to
# commit since there's no way to generate a correct Manifest.
# Do not try to do any more QA checks on this package since missing
# metadata leads to false positives for several checks, and false
# positives confuse users.
can_force = False
continue
# Sort ebuilds in ascending order for the KEYWORDS.dropped check.
ebuildlist = sorted(pkgs.values())
ebuildlist = [pkg.pf for pkg in ebuildlist]
for y in checkdirlist:
index = repo_config.find_invalid_path_char(y)
if index != -1:
y_relative = os.path.join(checkdir_relative, y)
if vcs is not None and not vcs_new_changed(y_relative):
# If the file isn't in the VCS new or changed set, then
# assume that it's an irrelevant temporary file (Manifest
# entries are not generated for file names containing
# prohibited characters). See bug #406877.
index = -1
if index != -1:
stats["file.name"] += 1
fails["file.name"].append("%s/%s: char '%s'" % \
(checkdir, y, y[index]))
if not (y in ("ChangeLog", "metadata.xml") or y.endswith(".ebuild")):
continue
f = None
try:
line = 1
f = io.open(_unicode_encode(os.path.join(checkdir, y),
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'])
for l in f:
line += 1
except UnicodeDecodeError as ue:
stats["file.UTF8"] += 1
s = ue.object[:ue.start]
l2 = s.count("\n")
line += l2
if l2 != 0:
s = s[s.rfind("\n") + 1:]
fails["file.UTF8"].append("%s/%s: line %i, just after: '%s'" % (checkdir, y, line, s))
finally:
if f is not None:
f.close()
if vcs in ("git", "hg") and check_ebuild_notadded:
if vcs == "git":
myf = repoman_popen("git ls-files --others %s" % \
(portage._shell_quote(checkdir_relative),))
if vcs == "hg":
myf = repoman_popen("hg status --no-status --unknown %s" % \
(portage._shell_quote(checkdir_relative),))
for l in myf:
if l[:-1][-7:] == ".ebuild":
stats["ebuild.notadded"] += 1
fails["ebuild.notadded"].append(
os.path.join(x, os.path.basename(l[:-1])))
myf.close()
if vcs in ("cvs", "svn", "bzr") and check_ebuild_notadded:
try:
if vcs == "cvs":
myf = open(checkdir + "/CVS/Entries", "r")
if vcs == "svn":
myf = repoman_popen("svn status --depth=files --verbose " +
portage._shell_quote(checkdir))
if vcs == "bzr":
myf = repoman_popen("bzr ls -v --kind=file " +
portage._shell_quote(checkdir))
myl = myf.readlines()
myf.close()
for l in myl:
if vcs == "cvs":
if l[0] != "/":
continue
splitl = l[1:].split("/")
if not len(splitl):
continue
if splitl[0][-7:] == ".ebuild":
eadded.append(splitl[0][:-7])
if vcs == "svn":
if l[:1] == "?":
continue
if l[:7] == ' >':
# tree conflict, new in subversion 1.6
continue
l = l.split()[-1]
if l[-7:] == ".ebuild":
eadded.append(os.path.basename(l[:-7]))
if vcs == "bzr":
if l[1:2] == "?":
continue
l = l.split()[-1]
if l[-7:] == ".ebuild":
eadded.append(os.path.basename(l[:-7]))
if vcs == "svn":
myf = repoman_popen("svn status " +
portage._shell_quote(checkdir))
myl = myf.readlines()
myf.close()
for l in myl:
if l[0] == "A":
l = l.rstrip().split(' ')[-1]
if l[-7:] == ".ebuild":
eadded.append(os.path.basename(l[:-7]))
except IOError:
if vcs == "cvs":
stats["CVS/Entries.IO_error"] += 1
fails["CVS/Entries.IO_error"].append(checkdir + "/CVS/Entries")
else:
raise
continue
mf = repoman_settings.repositories.get_repo_for_location(
os.path.dirname(os.path.dirname(checkdir)))
mf = mf.load_manifest(checkdir, repoman_settings["DISTDIR"])
mydigests = mf.getTypeDigests("DIST")
fetchlist_dict = portage.FetchlistDict(checkdir, repoman_settings, portdb)
myfiles_all = []
src_uri_error = False
for mykey in fetchlist_dict:
try:
myfiles_all.extend(fetchlist_dict[mykey])
except portage.exception.InvalidDependString as e:
src_uri_error = True
try:
portdb.aux_get(mykey, ["SRC_URI"])
except KeyError:
# This will be reported as an "ebuild.syntax" error.
pass
else:
stats["SRC_URI.syntax"] += 1
fails["SRC_URI.syntax"].append(
"%s.ebuild SRC_URI: %s" % (mykey, e))
del fetchlist_dict
if not src_uri_error:
# This test can produce false positives if SRC_URI could not
# be parsed for one or more ebuilds. There's no point in
# producing a false error here since the root cause will
# produce a valid error elsewhere, such as "SRC_URI.syntax"
# or "ebuild.sytax".
myfiles_all = set(myfiles_all)
for entry in mydigests:
if entry not in myfiles_all:
stats["digest.unused"] += 1
fails["digest.unused"].append(checkdir + "::" + entry)
for entry in myfiles_all:
if entry not in mydigests:
stats["digest.missing"] += 1
fails["digest.missing"].append(checkdir + "::" + entry)
del myfiles_all
if os.path.exists(checkdir + "/files"):
filesdirlist = os.listdir(checkdir + "/files")
# recurse through files directory
# use filesdirlist as a stack, appending directories as needed so people can't hide > 20k files in a subdirectory.
while filesdirlist:
y = filesdirlist.pop(0)
relative_path = os.path.join(x, "files", y)
full_path = os.path.join(repodir, relative_path)
try:
mystat = os.stat(full_path)
except OSError as oe:
if oe.errno == 2:
# don't worry about it. it likely was removed via fix above.
continue
else:
raise oe
if S_ISDIR(mystat.st_mode):
# !!! VCS "portability" alert! Need some function isVcsDir() or alike !!!
if y == "CVS" or y == ".svn":
continue
for z in os.listdir(checkdir + "/files/" + y):
if z == "CVS" or z == ".svn":
continue
filesdirlist.append(y + "/" + z)
# Current policy is no files over 20 KiB, these are the checks. File size between
# 20 KiB and 60 KiB causes a warning, while file size over 60 KiB causes an error.
elif mystat.st_size > 61440:
stats["file.size.fatal"] += 1
fails["file.size.fatal"].append("(" + str(mystat.st_size//1024) + " KiB) " + x + "/files/" + y)
elif mystat.st_size > 20480:
stats["file.size"] += 1
fails["file.size"].append("(" + str(mystat.st_size//1024) + " KiB) " + x + "/files/" + y)
index = repo_config.find_invalid_path_char(y)
if index != -1:
y_relative = os.path.join(checkdir_relative, "files", y)
if vcs is not None and not vcs_new_changed(y_relative):
# If the file isn't in the VCS new or changed set, then
# assume that it's an irrelevant temporary file (Manifest
# entries are not generated for file names containing
# prohibited characters). See bug #406877.
index = -1
if index != -1:
stats["file.name"] += 1
fails["file.name"].append("%s/files/%s: char '%s'" % \
(checkdir, y, y[index]))
del mydigests
if check_changelog and "ChangeLog" not in checkdirlist:
stats["changelog.missing"] += 1
fails["changelog.missing"].append(x + "/ChangeLog")
musedict = {}
# metadata.xml file check
if "metadata.xml" not in checkdirlist:
stats["metadata.missing"] += 1
fails["metadata.missing"].append(x + "/metadata.xml")
# metadata.xml parse check
else:
metadata_bad = False
xml_info = {}
xml_parser = _XMLParser(xml_info, target=_MetadataTreeBuilder())
# read metadata.xml into memory
try:
_metadata_xml = xml.etree.ElementTree.parse(
_unicode_encode(os.path.join(checkdir, "metadata.xml"),
encoding=_encodings['fs'], errors='strict'),
parser=xml_parser)
except (ExpatError, SyntaxError, EnvironmentError) as e:
metadata_bad = True
stats["metadata.bad"] += 1
fails["metadata.bad"].append("%s/metadata.xml: %s" % (x, e))
del e
else:
if not hasattr(xml_parser, 'parser') or \
sys.hexversion < 0x2070000 or \
(sys.hexversion > 0x3000000 and sys.hexversion < 0x3020000):
# doctype is not parsed with python 2.6 or 3.1
pass
else:
if "XML_DECLARATION" not in xml_info:
stats["metadata.bad"] += 1
fails["metadata.bad"].append("%s/metadata.xml: "
"xml declaration is missing on first line, "
"should be '%s'" % (x, metadata_xml_declaration))
else:
xml_version, xml_encoding, xml_standalone = \
xml_info["XML_DECLARATION"]
if xml_encoding is None or \
xml_encoding.upper() != metadata_xml_encoding:
stats["metadata.bad"] += 1
if xml_encoding is None:
encoding_problem = "but it is undefined"
else:
encoding_problem = "not '%s'" % xml_encoding
fails["metadata.bad"].append("%s/metadata.xml: "
"xml declaration encoding should be '%s', %s" %
(x, metadata_xml_encoding, encoding_problem))
if "DOCTYPE" not in xml_info:
metadata_bad = True
stats["metadata.bad"] += 1
fails["metadata.bad"].append("%s/metadata.xml: %s" % (x,
"DOCTYPE is missing"))
else:
doctype_name, doctype_system, doctype_pubid = \
xml_info["DOCTYPE"]
if doctype_system != metadata_dtd_uri:
stats["metadata.bad"] += 1
if doctype_system is None:
system_problem = "but it is undefined"
else:
system_problem = "not '%s'" % doctype_system
fails["metadata.bad"].append("%s/metadata.xml: "
"DOCTYPE: SYSTEM should refer to '%s', %s" %
(x, metadata_dtd_uri, system_problem))
if doctype_name != metadata_doctype_name:
stats["metadata.bad"] += 1
fails["metadata.bad"].append("%s/metadata.xml: "
"DOCTYPE: name should be '%s', not '%s'" %
(x, metadata_doctype_name, doctype_name))
# load USE flags from metadata.xml
try:
musedict = utilities.parse_metadata_use(_metadata_xml)
except portage.exception.ParseError as e:
metadata_bad = True
stats["metadata.bad"] += 1
fails["metadata.bad"].append("%s/metadata.xml: %s" % (x, e))
else:
for atom in chain(*musedict.values()):
if atom is None:
continue
try:
atom = Atom(atom)
except InvalidAtom as e:
stats["metadata.bad"] += 1
fails["metadata.bad"].append(
"%s/metadata.xml: Invalid atom: %s" % (x, e))
else:
if atom.cp != x:
stats["metadata.bad"] += 1
fails["metadata.bad"].append(
("%s/metadata.xml: Atom contains "
"unexpected cat/pn: %s") % (x, atom))
# Run other metadata.xml checkers
try:
utilities.check_metadata(_metadata_xml, herd_base)
except (utilities.UnknownHerdsError, ) as e:
metadata_bad = True
stats["metadata.bad"] += 1
fails["metadata.bad"].append("%s/metadata.xml: %s" % (x, e))
del e
# Only carry out if in package directory or check forced
if xmllint_capable and not metadata_bad:
# xmlint can produce garbage output even on success, so only dump
# the ouput when it fails.
st, out = repoman_getstatusoutput(
"xmllint --nonet --noout --dtdvalid %s %s" % \
(portage._shell_quote(metadata_dtd),
portage._shell_quote(os.path.join(checkdir, "metadata.xml"))))
if st != os.EX_OK:
print(red("!!!") + " metadata.xml is invalid:")
for z in out.splitlines():
print(red("!!! ") + z)
stats["metadata.bad"] += 1
fails["metadata.bad"].append(x + "/metadata.xml")
del metadata_bad
muselist = frozenset(musedict)
changelog_path = os.path.join(checkdir_relative, "ChangeLog")
changelog_modified = changelog_path in modified_changelogs
# detect unused local USE-descriptions
used_useflags = set()
for y in ebuildlist:
relative_path = os.path.join(x, y + ".ebuild")
full_path = os.path.join(repodir, relative_path)
ebuild_path = y + ".ebuild"
if repolevel < 3:
ebuild_path = os.path.join(pkgdir, ebuild_path)
if repolevel < 2:
ebuild_path = os.path.join(catdir, ebuild_path)
ebuild_path = os.path.join(".", ebuild_path)
if check_changelog and not changelog_modified \
and ebuild_path in new_ebuilds:
stats['changelog.ebuildadded'] += 1
fails['changelog.ebuildadded'].append(relative_path)
if vcs in ("cvs", "svn", "bzr") and check_ebuild_notadded and y not in eadded:
# ebuild not added to vcs
stats["ebuild.notadded"] += 1
fails["ebuild.notadded"].append(x + "/" + y + ".ebuild")
myesplit = portage.pkgsplit(y)
if myesplit is None or myesplit[0] != x.split("/")[-1] \
or pv_toolong_re.search(myesplit[1]) \
or pv_toolong_re.search(myesplit[2]):
stats["ebuild.invalidname"] += 1
fails["ebuild.invalidname"].append(x + "/" + y + ".ebuild")
continue
elif myesplit[0] != pkgdir:
print(pkgdir, myesplit[0])
stats["ebuild.namenomatch"] += 1
fails["ebuild.namenomatch"].append(x + "/" + y + ".ebuild")
continue
pkg = pkgs[y]
if pkg.invalid:
allvalid = False
for k, msgs in pkg.invalid.items():
for msg in msgs:
stats[k] += 1
fails[k].append("%s: %s" % (relative_path, msg))
continue
myaux = pkg._metadata
eapi = myaux["EAPI"]
inherited = pkg.inherited
live_ebuild = live_eclasses.intersection(inherited)
if repo_config.eapi_is_banned(eapi):
stats["repo.eapi.banned"] += 1
fails["repo.eapi.banned"].append(
"%s: %s" % (relative_path, eapi))
elif repo_config.eapi_is_deprecated(eapi):
stats["repo.eapi.deprecated"] += 1
fails["repo.eapi.deprecated"].append(
"%s: %s" % (relative_path, eapi))
for k, v in myaux.items():
if not isinstance(v, basestring):
continue
m = non_ascii_re.search(v)
if m is not None:
stats["variable.invalidchar"] += 1
fails["variable.invalidchar"].append(
("%s: %s variable contains non-ASCII " + \
"character at position %s") % \
(relative_path, k, m.start() + 1))
if not src_uri_error:
# Check that URIs don't reference a server from thirdpartymirrors.
for uri in portage.dep.use_reduce( \
myaux["SRC_URI"], matchall=True, is_src_uri=True, eapi=eapi, flat=True):
contains_mirror = False
for mirror, mirror_alias in thirdpartymirrors.items():
if uri.startswith(mirror):
contains_mirror = True
break
if not contains_mirror:
continue
new_uri = "mirror://%s/%s" % (mirror_alias, uri[len(mirror):])
stats["SRC_URI.mirror"] += 1
fails["SRC_URI.mirror"].append(
"%s: '%s' found in thirdpartymirrors, use '%s'" % \
(relative_path, mirror, new_uri))
if myaux.get("PROVIDE"):
stats["virtual.oldstyle"] += 1
fails["virtual.oldstyle"].append(relative_path)
for pos, missing_var in enumerate(missingvars):
if not myaux.get(missing_var):
if catdir == "virtual" and \
missing_var in ("HOMEPAGE", "LICENSE"):
continue
if live_ebuild and missing_var == "KEYWORDS":
continue
myqakey = missingvars[pos] + ".missing"
stats[myqakey] += 1
fails[myqakey].append(x + "/" + y + ".ebuild")
if catdir == "virtual":
for var in ("HOMEPAGE", "LICENSE"):
if myaux.get(var):
myqakey = var + ".virtual"
stats[myqakey] += 1
fails[myqakey].append(relative_path)
# 14 is the length of DESCRIPTION=""
if len(myaux['DESCRIPTION']) > max_desc_len:
stats['DESCRIPTION.toolong'] += 1
fails['DESCRIPTION.toolong'].append(
"%s: DESCRIPTION is %d characters (max %d)" % \
(relative_path, len(myaux['DESCRIPTION']), max_desc_len))
keywords = myaux["KEYWORDS"].split()
stable_keywords = []
for keyword in keywords:
if not keyword.startswith("~") and \
not keyword.startswith("-"):
stable_keywords.append(keyword)
if stable_keywords:
if ebuild_path in new_ebuilds and catdir != "virtual":
stable_keywords.sort()
stats["KEYWORDS.stable"] += 1
fails["KEYWORDS.stable"].append(
x + "/" + y + ".ebuild added with stable keywords: %s" % \
" ".join(stable_keywords))
ebuild_archs = set(kw.lstrip("~") for kw in keywords \
if not kw.startswith("-"))
previous_keywords = slot_keywords.get(pkg.slot)
if previous_keywords is None:
slot_keywords[pkg.slot] = set()
elif ebuild_archs and "*" not in ebuild_archs and not live_ebuild:
dropped_keywords = previous_keywords.difference(ebuild_archs)
if dropped_keywords:
stats["KEYWORDS.dropped"] += 1
fails["KEYWORDS.dropped"].append(
relative_path + ": %s" % \
" ".join(sorted(dropped_keywords)))
slot_keywords[pkg.slot].update(ebuild_archs)
# KEYWORDS="-*" is a stupid replacement for package.mask and screws general KEYWORDS semantics
if "-*" in keywords:
haskeyword = False
for kw in keywords:
if kw[0] == "~":
kw = kw[1:]
if kw in kwlist:
haskeyword = True
if not haskeyword:
stats["KEYWORDS.stupid"] += 1
fails["KEYWORDS.stupid"].append(x + "/" + y + ".ebuild")
"""
Ebuilds that inherit a "Live" eclass (darcs,subversion,git,cvs,etc..) should
not be allowed to be marked stable
"""
if live_ebuild and repo_config.name == "gentoo":
bad_stable_keywords = []
for keyword in keywords:
if not keyword.startswith("~") and \
not keyword.startswith("-"):
bad_stable_keywords.append(keyword)
del keyword
if bad_stable_keywords:
stats["LIVEVCS.stable"] += 1
fails["LIVEVCS.stable"].append(
x + "/" + y + ".ebuild with stable keywords:%s " % \
bad_stable_keywords)
del bad_stable_keywords
if keywords and not has_global_mask(pkg):
stats["LIVEVCS.unmasked"] += 1
fails["LIVEVCS.unmasked"].append(relative_path)
if options.ignore_arches:
arches = [[repoman_settings["ARCH"], repoman_settings["ARCH"],
repoman_settings["ACCEPT_KEYWORDS"].split()]]
else:
arches = set()
for keyword in keywords:
if keyword[0] == "-":
continue
elif keyword[0] == "~":
arch = keyword[1:]
if arch == "*":
for expanded_arch in profiles:
if expanded_arch == "**":
continue
arches.add((keyword, expanded_arch,
(expanded_arch, "~" + expanded_arch)))
else:
arches.add((keyword, arch, (arch, keyword)))
else:
if keyword == "*":
for expanded_arch in profiles:
if expanded_arch == "**":
continue
arches.add((keyword, expanded_arch,
(expanded_arch,)))
else:
arches.add((keyword, keyword, (keyword,)))
if not arches:
# Use an empty profile for checking dependencies of
# packages that have empty KEYWORDS.
arches.add(('**', '**', ('**',)))
unknown_pkgs = set()
baddepsyntax = False
badlicsyntax = False
badprovsyntax = False
catpkg = catdir + "/" + y
inherited_java_eclass = "java-pkg-2" in inherited or \
"java-pkg-opt-2" in inherited
inherited_wxwidgets_eclass = "wxwidgets" in inherited
operator_tokens = set(["||", "(", ")"])
type_list, badsyntax = [], []
for mytype in Package._dep_keys + ("LICENSE", "PROPERTIES", "PROVIDE"):
mydepstr = myaux[mytype]
buildtime = mytype in Package._buildtime_keys
runtime = mytype in Package._runtime_keys
token_class = None
if mytype.endswith("DEPEND"):
token_class = portage.dep.Atom
try:
atoms = portage.dep.use_reduce(mydepstr, matchall=1, flat=True, \
is_valid_flag=pkg.iuse.is_valid_flag, token_class=token_class)
except portage.exception.InvalidDependString as e:
atoms = None
badsyntax.append(str(e))
if atoms and mytype.endswith("DEPEND"):
if runtime and \
"test?" in mydepstr.split():
stats[mytype + '.suspect'] += 1
fails[mytype + '.suspect'].append(relative_path + \
": 'test?' USE conditional in %s" % mytype)
for atom in atoms:
if atom == "||":
continue
# Skip dependency.unknown for blockers, so that we
# don't encourage people to remove necessary blockers,
# as discussed in bug #382407.
if atom.blocker is None and \
not portdb.xmatch("match-all", atom) and \
not atom.cp.startswith("virtual/"):
unknown_pkgs.add((mytype, atom.unevaluated_atom))
is_blocker = atom.blocker
if catdir != "virtual":
if not is_blocker and \
atom.cp in suspect_virtual:
stats['virtual.suspect'] += 1
fails['virtual.suspect'].append(
relative_path +
": %s: consider using '%s' instead of '%s'" %
(mytype, suspect_virtual[atom.cp], atom))
if buildtime and \
not is_blocker and \
not inherited_java_eclass and \
atom.cp == "virtual/jdk":
stats['java.eclassesnotused'] += 1
fails['java.eclassesnotused'].append(relative_path)
elif buildtime and \
not is_blocker and \
not inherited_wxwidgets_eclass and \
atom.cp == "x11-libs/wxGTK":
stats['wxwidgets.eclassnotused'] += 1
fails['wxwidgets.eclassnotused'].append(
(relative_path + ": %ss on x11-libs/wxGTK"
" without inheriting wxwidgets.eclass") % mytype)
elif runtime:
if not is_blocker and \
atom.cp in suspect_rdepend:
stats[mytype + '.suspect'] += 1
fails[mytype + '.suspect'].append(
relative_path + ": '%s'" % atom)
if atom.operator == "~" and \
portage.versions.catpkgsplit(atom.cpv)[3] != "r0":
qacat = 'dependency.badtilde'
stats[qacat] += 1
fails[qacat].append(
(relative_path + ": %s uses the ~ operator"
" with a non-zero revision:" + \
" '%s'") % (mytype, atom))
type_list.extend([mytype] * (len(badsyntax) - len(type_list)))
for m, b in zip(type_list, badsyntax):
if m.endswith("DEPEND"):
qacat = "dependency.syntax"
else:
qacat = m + ".syntax"
stats[qacat] += 1
fails[qacat].append("%s: %s: %s" % (relative_path, m, b))
badlicsyntax = len([z for z in type_list if z == "LICENSE"])
badprovsyntax = len([z for z in type_list if z == "PROVIDE"])
baddepsyntax = len(type_list) != badlicsyntax + badprovsyntax
badlicsyntax = badlicsyntax > 0
badprovsyntax = badprovsyntax > 0
# uselist checks - global
myuse = []
default_use = []
for myflag in myaux["IUSE"].split():
flag_name = myflag.lstrip("+-")
used_useflags.add(flag_name)
if myflag != flag_name:
default_use.append(myflag)
if flag_name not in uselist:
myuse.append(flag_name)
# uselist checks - metadata
for mypos in range(len(myuse)-1, -1, -1):
if myuse[mypos] and (myuse[mypos] in muselist):
del myuse[mypos]
if default_use and not eapi_has_iuse_defaults(eapi):
for myflag in default_use:
stats['EAPI.incompatible'] += 1
fails['EAPI.incompatible'].append(
(relative_path + ": IUSE defaults" + \
" not supported with EAPI='%s':" + \
" '%s'") % (eapi, myflag))
for mypos in range(len(myuse)):
stats["IUSE.invalid"] += 1
fails["IUSE.invalid"].append(x + "/" + y + ".ebuild: %s" % myuse[mypos])
# Check for outdated RUBY targets
if "ruby-ng" in inherited or "ruby-fakegem" in inherited or "ruby" in inherited:
ruby_intersection = pkg.iuse.all.intersection(ruby_deprecated)
if ruby_intersection:
for myruby in ruby_intersection:
stats["IUSE.rubydeprecated"] += 1
fails["IUSE.rubydeprecated"].append(
(relative_path + ": Deprecated ruby target: %s") % myruby)
# license checks
if not badlicsyntax:
# Parse the LICENSE variable, remove USE conditions and
# flatten it.
licenses = portage.dep.use_reduce(myaux["LICENSE"], matchall=1, flat=True)
# Check each entry to ensure that it exists in PORTDIR's
# license directory.
for lic in licenses:
# Need to check for "||" manually as no portage
# function will remove it without removing values.
if lic not in liclist and lic != "||":
stats["LICENSE.invalid"] += 1
fails["LICENSE.invalid"].append(x + "/" + y + ".ebuild: %s" % lic)
elif lic in liclist_deprecated:
stats["LICENSE.deprecated"] += 1
fails["LICENSE.deprecated"].append("%s: %s" % (relative_path, lic))
# keyword checks
myuse = myaux["KEYWORDS"].split()
for mykey in myuse:
if mykey not in ("-*", "*", "~*"):
myskey = mykey
if myskey[:1] == "-":
myskey = myskey[1:]
if myskey[:1] == "~":
myskey = myskey[1:]
if myskey not in kwlist:
stats["KEYWORDS.invalid"] += 1
fails["KEYWORDS.invalid"].append(x + "/" + y + ".ebuild: %s" % mykey)
elif myskey not in profiles:
stats["KEYWORDS.invalid"] += 1
fails["KEYWORDS.invalid"].append(x + "/" + y + ".ebuild: %s (profile invalid)" % mykey)
# restrict checks
myrestrict = None
try:
myrestrict = portage.dep.use_reduce(myaux["RESTRICT"], matchall=1, flat=True)
except portage.exception.InvalidDependString as e:
stats["RESTRICT.syntax"] += 1
fails["RESTRICT.syntax"].append(
"%s: RESTRICT: %s" % (relative_path, e))
del e
if myrestrict:
myrestrict = set(myrestrict)
mybadrestrict = myrestrict.difference(valid_restrict)
if mybadrestrict:
stats["RESTRICT.invalid"] += len(mybadrestrict)
for mybad in mybadrestrict:
fails["RESTRICT.invalid"].append(x + "/" + y + ".ebuild: %s" % mybad)
# REQUIRED_USE check
required_use = myaux["REQUIRED_USE"]
if required_use:
if not eapi_has_required_use(eapi):
stats['EAPI.incompatible'] += 1
fails['EAPI.incompatible'].append(
relative_path + ": REQUIRED_USE" + \
" not supported with EAPI='%s'" % (eapi,))
try:
portage.dep.check_required_use(required_use, (),
pkg.iuse.is_valid_flag, eapi=eapi)
except portage.exception.InvalidDependString as e:
stats["REQUIRED_USE.syntax"] += 1
fails["REQUIRED_USE.syntax"].append(
"%s: REQUIRED_USE: %s" % (relative_path, e))
del e
# Syntax Checks
relative_path = os.path.join(x, y + ".ebuild")
full_path = os.path.join(repodir, relative_path)
if not vcs_preserves_mtime:
if ebuild_path not in new_ebuilds and \
ebuild_path not in modified_ebuilds:
pkg.mtime = None
try:
# All ebuilds should have utf_8 encoding.
f = io.open(_unicode_encode(full_path,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'])
try:
for check_name, e in run_checks(f, pkg):
stats[check_name] += 1
fails[check_name].append(relative_path + ': %s' % e)
finally:
f.close()
except UnicodeDecodeError:
# A file.UTF8 failure will have already been recorded above.
pass
if options.force:
# The dep_check() calls are the most expensive QA test. If --force
# is enabled, there's no point in wasting time on these since the
# user is intent on forcing the commit anyway.
continue
relevant_profiles = []
for keyword, arch, groups in arches:
if arch not in profiles:
# A missing profile will create an error further down
# during the KEYWORDS verification.
continue
if include_arches is not None:
if arch not in include_arches:
continue
relevant_profiles.extend((keyword, groups, prof)
for prof in profiles[arch])
def sort_key(item):
return item[2].sub_path
relevant_profiles.sort(key=sort_key)
for keyword, groups, prof in relevant_profiles:
if not (prof.status == "stable" or \
(prof.status == "dev" and options.include_dev) or \
(prof.status == "exp" and options.include_exp_profiles == 'y')):
continue
dep_settings = arch_caches.get(prof.sub_path)
if dep_settings is None:
dep_settings = portage.config(
config_profile_path=prof.abs_path,
config_incrementals=repoman_incrementals,
config_root=config_root,
local_config=False,
_unmatched_removal=options.unmatched_removal,
env=env, repositories=repoman_settings.repositories)
dep_settings.categories = repoman_settings.categories
if options.without_mask:
dep_settings._mask_manager_obj = \
copy.deepcopy(dep_settings._mask_manager)
dep_settings._mask_manager._pmaskdict.clear()
arch_caches[prof.sub_path] = dep_settings
xmatch_cache_key = (prof.sub_path, tuple(groups))
xcache = arch_xmatch_caches.get(xmatch_cache_key)
if xcache is None:
portdb.melt()
portdb.freeze()
xcache = portdb.xcache
xcache.update(shared_xmatch_caches)
arch_xmatch_caches[xmatch_cache_key] = xcache
trees[root]["porttree"].settings = dep_settings
portdb.settings = dep_settings
portdb.xcache = xcache
dep_settings["ACCEPT_KEYWORDS"] = " ".join(groups)
# just in case, prevent config.reset() from nuking these.
dep_settings.backup_changes("ACCEPT_KEYWORDS")
# This attribute is used in dbapi._match_use() to apply
# use.stable.{mask,force} settings based on the stable
# status of the parent package. This is required in order
# for USE deps of unstable packages to be resolved correctly,
# since otherwise use.stable.{mask,force} settings of
# dependencies may conflict (see bug #456342).
dep_settings._parent_stable = dep_settings._isStable(pkg)
# Handle package.use*.{force,mask) calculation, for use
# in dep_check.
dep_settings.useforce = dep_settings._use_manager.getUseForce(
pkg, stable=dep_settings._parent_stable)
dep_settings.usemask = dep_settings._use_manager.getUseMask(
pkg, stable=dep_settings._parent_stable)
if not baddepsyntax:
ismasked = not ebuild_archs or \
pkg.cpv not in portdb.xmatch("match-visible", pkg.cp)
if ismasked:
if not have_pmasked:
have_pmasked = bool(dep_settings._getMaskAtom(
pkg.cpv, pkg._metadata))
if options.ignore_masked:
continue
# we are testing deps for a masked package; give it some lee-way
suffix = "masked"
matchmode = "minimum-all"
else:
suffix = ""
matchmode = "minimum-visible"
if not have_dev_keywords:
have_dev_keywords = \
bool(dev_keywords.intersection(keywords))
if prof.status == "dev":
suffix = suffix + "indev"
for mytype in Package._dep_keys:
mykey = "dependency.bad" + suffix
myvalue = myaux[mytype]
if not myvalue:
continue
success, atoms = portage.dep_check(myvalue, portdb,
dep_settings, use="all", mode=matchmode,
trees=trees)
if success:
if atoms:
# Don't bother with dependency.unknown for
# cases in which *DEPEND.bad is triggered.
for atom in atoms:
# dep_check returns all blockers and they
# aren't counted for *DEPEND.bad, so we
# ignore them here.
if not atom.blocker:
unknown_pkgs.discard(
(mytype, atom.unevaluated_atom))
if not prof.sub_path:
# old-style virtuals currently aren't
# resolvable with empty profile, since
# 'virtuals' mappings are unavailable
# (it would be expensive to search
# for PROVIDE in all ebuilds)
atoms = [atom for atom in atoms if not \
(atom.cp.startswith('virtual/') and \
not portdb.cp_list(atom.cp))]
# we have some unsolvable deps
# remove ! deps, which always show up as unsatisfiable
atoms = [str(atom.unevaluated_atom) \
for atom in atoms if not atom.blocker]
# if we emptied out our list, continue:
if not atoms:
continue
stats[mykey] += 1
fails[mykey].append("%s: %s: %s(%s) %s" % \
(relative_path, mytype, keyword,
prof, repr(atoms)))
else:
stats[mykey] += 1
fails[mykey].append("%s: %s: %s(%s) %s" % \
(relative_path, mytype, keyword,
prof, repr(atoms)))
if not baddepsyntax and unknown_pkgs:
type_map = {}
for mytype, atom in unknown_pkgs:
type_map.setdefault(mytype, set()).add(atom)
for mytype, atoms in type_map.items():
stats["dependency.unknown"] += 1
fails["dependency.unknown"].append("%s: %s: %s" %
(relative_path, mytype, ", ".join(sorted(atoms))))
# check if there are unused local USE-descriptions in metadata.xml
# (unless there are any invalids, to avoid noise)
if allvalid:
for myflag in muselist.difference(used_useflags):
stats["metadata.warning"] += 1
fails["metadata.warning"].append(
"%s/metadata.xml: unused local USE-description: '%s'" % \
(x, myflag))
if options.if_modified == "y" and len(effective_scanlist) < 1:
logging.warn("--if-modified is enabled, but no modified packages were found!")
if options.mode == "manifest":
sys.exit(dofail)
# dofail will be set to 1 if we have failed in at least one non-warning category
dofail = 0
# dowarn will be set to 1 if we tripped any warnings
dowarn = 0
# dofull will be set if we should print a "repoman full" informational message
dofull = options.mode != 'full'
for x in qacats:
if not stats[x]:
continue
dowarn = 1
if x not in qawarnings:
dofail = 1
if dofail or \
(dowarn and not (options.quiet or options.mode == "scan")):
dofull = 0
# Save QA output so that it can be conveniently displayed
# in $EDITOR while the user creates a commit message.
# Otherwise, the user would not be able to see this output
# once the editor has taken over the screen.
qa_output = io.StringIO()
style_file = ConsoleStyleFile(sys.stdout)
if options.mode == 'commit' and \
(not commitmessage or not commitmessage.strip()):
style_file.write_listener = qa_output
console_writer = StyleWriter(file=style_file, maxcol=9999)
console_writer.style_listener = style_file.new_styles
f = formatter.AbstractFormatter(console_writer)
utilities.format_qa_output(f, stats, fails, dofull, dofail, options, qawarnings)
style_file.flush()
del console_writer, f, style_file
qa_output = qa_output.getvalue()
qa_output = qa_output.splitlines(True)
suggest_ignore_masked = False
suggest_include_dev = False
if have_pmasked and not (options.without_mask or options.ignore_masked):
suggest_ignore_masked = True
if have_dev_keywords and not options.include_dev:
suggest_include_dev = True
if suggest_ignore_masked or suggest_include_dev:
print()
if suggest_ignore_masked:
print(bold("Note: use --without-mask to check " + \
"KEYWORDS on dependencies of masked packages"))
if suggest_include_dev:
print(bold("Note: use --include-dev (-d) to check " + \
"dependencies for 'dev' profiles"))
print()
if options.mode != 'commit':
if dofull:
print(bold("Note: type \"repoman full\" for a complete listing."))
if dowarn and not dofail:
print(green("RepoMan sez:"),"\"You're only giving me a partial QA payment?\n I'll take it this time, but I'm not happy.\"")
elif not dofail:
print(green("RepoMan sez:"),"\"If everyone were like you, I'd be out of business!\"")
elif dofail:
print(bad("Please fix these important QA issues first."))
print(green("RepoMan sez:"),"\"Make your QA payment on time and you'll never see the likes of me.\"\n")
sys.exit(1)
else:
if dofail and can_force and options.force and not options.pretend:
print(green("RepoMan sez:") + \
" \"You want to commit even with these QA issues?\n" + \
" I'll take it this time, but I'm not happy.\"\n")
elif dofail:
if options.force and not can_force:
print(bad("The --force option has been disabled due to extraordinary issues."))
print(bad("Please fix these important QA issues first."))
print(green("RepoMan sez:"),"\"Make your QA payment on time and you'll never see the likes of me.\"\n")
sys.exit(1)
if options.pretend:
print(green("RepoMan sez:"), "\"So, you want to play it safe. Good call.\"\n")
myunadded = []
if vcs == "cvs":
try:
myvcstree = portage.cvstree.getentries("./", recursive=1)
myunadded = portage.cvstree.findunadded(myvcstree, recursive=1, basedir="./")
except SystemExit as e:
raise # TODO propagate this
except:
err("Error retrieving CVS tree; exiting.")
if vcs == "svn":
try:
with repoman_popen("svn status --no-ignore") as f:
svnstatus = f.readlines()
myunadded = ["./" + elem.rstrip().split()[1] for elem in svnstatus if elem.startswith("?") or elem.startswith("I")]
except SystemExit as e:
raise # TODO propagate this
except:
err("Error retrieving SVN info; exiting.")
if vcs == "git":
# get list of files not under version control or missing
myf = repoman_popen("git ls-files --others")
myunadded = ["./" + elem[:-1] for elem in myf]
myf.close()
if vcs == "bzr":
try:
with repoman_popen("bzr status -S .") as f:
bzrstatus = f.readlines()
myunadded = ["./" + elem.rstrip().split()[1].split('/')[-1:][0] for elem in bzrstatus if elem.startswith("?") or elem[0:2] == " D"]
except SystemExit as e:
raise # TODO propagate this
except:
err("Error retrieving bzr info; exiting.")
if vcs == "hg":
with repoman_popen("hg status --no-status --unknown .") as f:
myunadded = f.readlines()
myunadded = ["./" + elem.rstrip() for elem in myunadded]
# Mercurial doesn't handle manually deleted files as removed from
# the repository, so the user need to remove them before commit,
# using "hg remove [FILES]"
with repoman_popen("hg status --no-status --deleted .") as f:
mydeleted = f.readlines()
mydeleted = ["./" + elem.rstrip() for elem in mydeleted]
myautoadd = []
if myunadded:
for x in range(len(myunadded)-1, -1, -1):
xs = myunadded[x].split("/")
if xs[-1] == "files":
print("!!! files dir is not added! Please correct this.")
sys.exit(-1)
elif xs[-1] == "Manifest":
# It's a manifest... auto add
myautoadd += [myunadded[x]]
del myunadded[x]
if myunadded:
print(red("!!! The following files are in your local tree but are not added to the master"))
print(red("!!! tree. Please remove them from the local tree or add them to the master tree."))
for x in myunadded:
print(" ", x)
print()
print()
sys.exit(1)
if vcs == "hg" and mydeleted:
print(red("!!! The following files are removed manually from your local tree but are not"))
print(red("!!! removed from the repository. Please remove them, using \"hg remove [FILES]\"."))
for x in mydeleted:
print(" ", x)
print()
print()
sys.exit(1)
if vcs == "cvs":
mycvstree = cvstree.getentries("./", recursive=1)
mychanged = cvstree.findchanged(mycvstree, recursive=1, basedir="./")
mynew = cvstree.findnew(mycvstree, recursive=1, basedir="./")
myremoved = portage.cvstree.findremoved(mycvstree, recursive=1, basedir="./")
bin_blob_pattern = re.compile("^-kb$")
no_expansion = set(portage.cvstree.findoption(mycvstree, bin_blob_pattern,
recursive=1, basedir="./"))
if vcs == "svn":
with repoman_popen("svn status") as f:
svnstatus = f.readlines()
mychanged = ["./" + elem.split()[-1:][0] for elem in svnstatus if (elem[:1] in "MR" or elem[1:2] in "M")]
mynew = ["./" + elem.split()[-1:][0] for elem in svnstatus if elem.startswith("A")]
myremoved = ["./" + elem.split()[-1:][0] for elem in svnstatus if elem.startswith("D")]
# Subversion expands keywords specified in svn:keywords properties.
with repoman_popen("svn propget -R svn:keywords") as f:
props = f.readlines()
expansion = dict(("./" + prop.split(" - ")[0], prop.split(" - ")[1].split()) \
for prop in props if " - " in prop)
elif vcs == "git":
with repoman_popen("git diff-index --name-only "
"--relative --diff-filter=M HEAD") as f:
mychanged = f.readlines()
mychanged = ["./" + elem[:-1] for elem in mychanged]
with repoman_popen("git diff-index --name-only "
"--relative --diff-filter=A HEAD") as f:
mynew = f.readlines()
mynew = ["./" + elem[:-1] for elem in mynew]
with repoman_popen("git diff-index --name-only "
"--relative --diff-filter=D HEAD") as f:
myremoved = f.readlines()
myremoved = ["./" + elem[:-1] for elem in myremoved]
if vcs == "bzr":
with repoman_popen("bzr status -S .") as f:
bzrstatus = f.readlines()
mychanged = ["./" + elem.split()[-1:][0].split('/')[-1:][0] for elem in bzrstatus if elem and elem[1:2] == "M"]
mynew = ["./" + elem.split()[-1:][0].split('/')[-1:][0] for elem in bzrstatus if elem and (elem[1:2] in "NK" or elem[0:1] == "R")]
myremoved = ["./" + elem.split()[-1:][0].split('/')[-1:][0] for elem in bzrstatus if elem.startswith("-")]
myremoved = ["./" + elem.split()[-3:-2][0].split('/')[-1:][0] for elem in bzrstatus if elem and (elem[1:2] == "K" or elem[0:1] == "R")]
# Bazaar expands nothing.
if vcs == "hg":
with repoman_popen("hg status --no-status --modified .") as f:
mychanged = f.readlines()
mychanged = ["./" + elem.rstrip() for elem in mychanged]
with repoman_popen("hg status --no-status --added .") as f:
mynew = f.readlines()
mynew = ["./" + elem.rstrip() for elem in mynew]
with repoman_popen("hg status --no-status --removed .") as f:
myremoved = f.readlines()
myremoved = ["./" + elem.rstrip() for elem in myremoved]
if vcs:
if not (mychanged or mynew or myremoved or (vcs == "hg" and mydeleted)):
print(green("RepoMan sez:"), "\"Doing nothing is not always good for QA.\"")
print()
print("(Didn't find any changed files...)")
print()
sys.exit(1)
# Manifests need to be regenerated after all other commits, so don't commit
# them now even if they have changed.
mymanifests = set()
myupdates = set()
for f in mychanged + mynew:
if "Manifest" == os.path.basename(f):
mymanifests.add(f)
else:
myupdates.add(f)
myupdates.difference_update(myremoved)
myupdates = list(myupdates)
mymanifests = list(mymanifests)
myheaders = []
mydirty = []
commitmessage = options.commitmsg
if options.commitmsgfile:
try:
f = io.open(_unicode_encode(options.commitmsgfile,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['content'], errors='replace')
commitmessage = f.read()
f.close()
del f
except (IOError, OSError) as e:
if e.errno == errno.ENOENT:
portage.writemsg("!!! File Not Found: --commitmsgfile='%s'\n" % options.commitmsgfile)
else:
raise
# We've read the content so the file is no longer needed.
commitmessagefile = None
if not commitmessage or not commitmessage.strip():
try:
editor = os.environ.get("EDITOR")
if editor and utilities.editor_is_executable(editor):
commitmessage = utilities.get_commit_message_with_editor(
editor, message=qa_output)
else:
commitmessage = utilities.get_commit_message_with_stdin()
except KeyboardInterrupt:
exithandler()
if not commitmessage or not commitmessage.strip():
print("* no commit message? aborting commit.")
sys.exit(1)
commitmessage = commitmessage.rstrip()
changelog_msg = commitmessage
portage_version = getattr(portage, "VERSION", None)
gpg_key = repoman_settings.get("PORTAGE_GPG_KEY", "")
dco_sob = repoman_settings.get("DCO_SIGNED_OFF_BY", "")
if portage_version is None:
sys.stderr.write("Failed to insert portage version in message!\n")
sys.stderr.flush()
portage_version = "Unknown"
report_options = []
if options.force:
report_options.append("--force")
if options.ignore_arches:
report_options.append("--ignore-arches")
if include_arches is not None:
report_options.append("--include-arches=\"%s\"" %
" ".join(sorted(include_arches)))
if vcs == "git":
# Use new footer only for git (see bug #438364).
commit_footer = "\n\nPackage-Manager: portage-%s" % portage_version
if report_options:
commit_footer += "\nRepoMan-Options: " + " ".join(report_options)
if sign_manifests:
commit_footer += "\nManifest-Sign-Key: %s" % (gpg_key, )
if dco_sob:
commit_footer += "\nSigned-off-by: %s" % (dco_sob, )
else:
unameout = platform.system() + " "
if platform.system() in ["Darwin", "SunOS"]:
unameout += platform.processor()
else:
unameout += platform.machine()
commit_footer = "\n\n"
if dco_sob:
commit_footer += "Signed-off-by: %s\n" % (dco_sob, )
commit_footer += "(Portage version: %s/%s/%s" % \
(portage_version, vcs, unameout)
if report_options:
commit_footer += ", RepoMan options: " + " ".join(report_options)
if sign_manifests:
commit_footer += ", signed Manifest commit with key %s" % \
(gpg_key, )
else:
commit_footer += ", unsigned Manifest commit"
commit_footer += ")"
commitmessage += commit_footer
broken_changelog_manifests = []
if options.echangelog in ('y', 'force'):
logging.info("checking for unmodified ChangeLog files")
committer_name = utilities.get_committer_name(env=repoman_settings)
for x in sorted(vcs_files_to_cps(
chain(myupdates, mymanifests, myremoved))):
catdir, pkgdir = x.split("/")
checkdir = repodir + "/" + x
checkdir_relative = ""
if repolevel < 3:
checkdir_relative = os.path.join(pkgdir, checkdir_relative)
if repolevel < 2:
checkdir_relative = os.path.join(catdir, checkdir_relative)
checkdir_relative = os.path.join(".", checkdir_relative)
changelog_path = os.path.join(checkdir_relative, "ChangeLog")
changelog_modified = changelog_path in modified_changelogs
if changelog_modified and options.echangelog != 'force':
continue
# get changes for this package
cdrlen = len(checkdir_relative)
clnew = [elem[cdrlen:] for elem in mynew if elem.startswith(checkdir_relative)]
clremoved = [elem[cdrlen:] for elem in myremoved if elem.startswith(checkdir_relative)]
clchanged = [elem[cdrlen:] for elem in mychanged if elem.startswith(checkdir_relative)]
# Skip ChangeLog generation if only the Manifest was modified,
# as discussed in bug #398009.
nontrivial_cl_files = set()
nontrivial_cl_files.update(clnew, clremoved, clchanged)
nontrivial_cl_files.difference_update(['Manifest'])
if not nontrivial_cl_files and options.echangelog != 'force':
continue
new_changelog = utilities.UpdateChangeLog(checkdir_relative,
committer_name, changelog_msg,
os.path.join(repodir, 'skel.ChangeLog'),
catdir, pkgdir,
new=clnew, removed=clremoved, changed=clchanged,
pretend=options.pretend)
if new_changelog is None:
writemsg_level("!!! Updating the ChangeLog failed\n", \
level=logging.ERROR, noiselevel=-1)
sys.exit(1)
# if the ChangeLog was just created, add it to vcs
if new_changelog:
myautoadd.append(changelog_path)
# myautoadd is appended to myupdates below
else:
myupdates.append(changelog_path)
if options.ask and not options.pretend:
# regenerate Manifest for modified ChangeLog (bug #420735)
repoman_settings["O"] = checkdir
digestgen(mysettings=repoman_settings, myportdb=portdb)
else:
broken_changelog_manifests.append(x)
if myautoadd:
print(">>> Auto-Adding missing Manifest/ChangeLog file(s)...")
add_cmd = [vcs, "add"]
add_cmd += myautoadd
if options.pretend:
portage.writemsg_stdout("(%s)\n" % " ".join(add_cmd),
noiselevel=-1)
else:
if sys.hexversion < 0x3020000 and sys.hexversion >= 0x3000000 and \
not os.path.isabs(add_cmd[0]):
# Python 3.1 _execvp throws TypeError for non-absolute executable
# path passed as bytes (see http://bugs.python.org/issue8513).
fullname = find_binary(add_cmd[0])
if fullname is None:
raise portage.exception.CommandNotFound(add_cmd[0])
add_cmd[0] = fullname
add_cmd = [_unicode_encode(arg) for arg in add_cmd]
retcode = subprocess.call(add_cmd)
if retcode != os.EX_OK:
logging.error(
"Exiting on %s error code: %s\n" % (vcs, retcode))
sys.exit(retcode)
myupdates += myautoadd
print("* %s files being committed..." % green(str(len(myupdates))), end=' ')
if vcs not in ('cvs', 'svn'):
# With git, bzr and hg, there's never any keyword expansion, so
# there's no need to regenerate manifests and all files will be
# committed in one big commit at the end.
print()
elif not repo_config.thin_manifest:
if vcs == 'cvs':
headerstring = "'\$(Header|Id).*\$'"
elif vcs == "svn":
svn_keywords = dict((k.lower(), k) for k in [
"Rev",
"Revision",
"LastChangedRevision",
"Date",
"LastChangedDate",
"Author",
"LastChangedBy",
"URL",
"HeadURL",
"Id",
"Header",
])
for myfile in myupdates:
# for CVS, no_expansion contains files that are excluded from expansion
if vcs == "cvs":
if myfile in no_expansion:
continue
# for SVN, expansion contains files that are included in expansion
elif vcs == "svn":
if myfile not in expansion:
continue
# Subversion keywords are case-insensitive in svn:keywords properties, but case-sensitive in contents of files.
enabled_keywords = []
for k in expansion[myfile]:
keyword = svn_keywords.get(k.lower())
if keyword is not None:
enabled_keywords.append(keyword)
headerstring = "'\$(%s).*\$'" % "|".join(enabled_keywords)
myout = repoman_getstatusoutput("egrep -q " + headerstring + " " +
portage._shell_quote(myfile))
if myout[0] == 0:
myheaders.append(myfile)
print("%s have headers that will change." % green(str(len(myheaders))))
print("* Files with headers will cause the manifests to be changed and committed separately.")
logging.info("myupdates: %s", myupdates)
logging.info("myheaders: %s", myheaders)
if options.ask and userquery('Commit changes?', True) != 'Yes':
print("* aborting commit.")
sys.exit(128 + signal.SIGINT)
# Handle the case where committed files have keywords which
# will change and need a priming commit before the Manifest
# can be committed.
if (myupdates or myremoved) and myheaders:
myfiles = myupdates + myremoved
fd, commitmessagefile = tempfile.mkstemp(".repoman.msg")
mymsg = os.fdopen(fd, "wb")
mymsg.write(_unicode_encode(commitmessage))
mymsg.close()
print()
print(green("Using commit message:"))
print(green("------------------------------------------------------------------------------"))
print(commitmessage)
print(green("------------------------------------------------------------------------------"))
print()
# Having a leading ./ prefix on file paths can trigger a bug in
# the cvs server when committing files to multiple directories,
# so strip the prefix.
myfiles = [f.lstrip("./") for f in myfiles]
commit_cmd = [vcs]
commit_cmd.extend(vcs_global_opts)
commit_cmd.append("commit")
commit_cmd.extend(vcs_local_opts)
commit_cmd.extend(["-F", commitmessagefile])
commit_cmd.extend(myfiles)
try:
if options.pretend:
print("(%s)" % (" ".join(commit_cmd),))
else:
retval = spawn(commit_cmd, env=commit_env)
if retval != os.EX_OK:
writemsg_level(("!!! Exiting on %s (shell) " + \
"error code: %s\n") % (vcs, retval),
level=logging.ERROR, noiselevel=-1)
sys.exit(retval)
finally:
try:
os.unlink(commitmessagefile)
except OSError:
pass
# Setup the GPG commands
def gpgsign(filename):
gpgcmd = repoman_settings.get("PORTAGE_GPG_SIGNING_COMMAND")
if gpgcmd is None:
raise MissingParameter("PORTAGE_GPG_SIGNING_COMMAND is unset!" + \
" Is make.globals missing?")
if "${PORTAGE_GPG_KEY}" in gpgcmd and \
"PORTAGE_GPG_KEY" not in repoman_settings:
raise MissingParameter("PORTAGE_GPG_KEY is unset!")
if "${PORTAGE_GPG_DIR}" in gpgcmd:
if "PORTAGE_GPG_DIR" not in repoman_settings:
repoman_settings["PORTAGE_GPG_DIR"] = \
os.path.expanduser("~/.gnupg")
logging.info("Automatically setting PORTAGE_GPG_DIR to '%s'" \
% repoman_settings["PORTAGE_GPG_DIR"])
else:
repoman_settings["PORTAGE_GPG_DIR"] = \
os.path.expanduser(repoman_settings["PORTAGE_GPG_DIR"])
if not os.access(repoman_settings["PORTAGE_GPG_DIR"], os.X_OK):
raise portage.exception.InvalidLocation(
"Unable to access directory: PORTAGE_GPG_DIR='%s'" % \
repoman_settings["PORTAGE_GPG_DIR"])
gpgvars = {"FILE": filename}
for k in ("PORTAGE_GPG_DIR", "PORTAGE_GPG_KEY"):
v = repoman_settings.get(k)
if v is not None:
gpgvars[k] = v
gpgcmd = portage.util.varexpand(gpgcmd, mydict=gpgvars)
if options.pretend:
print("(" + gpgcmd + ")")
else:
# Encode unicode manually for bug #310789.
gpgcmd = portage.util.shlex_split(gpgcmd)
if sys.hexversion < 0x3020000 and sys.hexversion >= 0x3000000 and \
not os.path.isabs(gpgcmd[0]):
# Python 3.1 _execvp throws TypeError for non-absolute executable
# path passed as bytes (see http://bugs.python.org/issue8513).
fullname = find_binary(gpgcmd[0])
if fullname is None:
raise portage.exception.CommandNotFound(gpgcmd[0])
gpgcmd[0] = fullname
gpgcmd = [_unicode_encode(arg,
encoding=_encodings['fs'], errors='strict') for arg in gpgcmd]
rValue = subprocess.call(gpgcmd)
if rValue == os.EX_OK:
os.rename(filename + ".asc", filename)
else:
raise portage.exception.PortageException("!!! gpg exited with '" + str(rValue) + "' status")
def need_signature(filename):
try:
with open(_unicode_encode(filename,
encoding=_encodings['fs'], errors='strict'), 'rb') as f:
return b"BEGIN PGP SIGNED MESSAGE" not in f.readline()
except IOError as e:
if e.errno in (errno.ENOENT, errno.ESTALE):
return False
raise
# When files are removed and re-added, the cvs server will put /Attic/
# inside the $Header path. This code detects the problem and corrects it
# so that the Manifest will generate correctly. See bug #169500.
# Use binary mode in order to avoid potential character encoding issues.
cvs_header_re = re.compile(br'^#\s*\$Header.*\$$')
attic_str = b'/Attic/'
attic_replace = b'/'
for x in myheaders:
f = open(_unicode_encode(x,
encoding=_encodings['fs'], errors='strict'),
mode='rb')
mylines = f.readlines()
f.close()
modified = False
for i, line in enumerate(mylines):
if cvs_header_re.match(line) is not None and \
attic_str in line:
mylines[i] = line.replace(attic_str, attic_replace)
modified = True
if modified:
portage.util.write_atomic(x, b''.join(mylines),
mode='wb')
if repolevel == 1:
print(green("RepoMan sez:"), "\"You're rather crazy... "
"doing the entire repository.\"\n")
if vcs in ('cvs', 'svn') and (myupdates or myremoved):
for x in sorted(vcs_files_to_cps(
chain(myupdates, myremoved, mymanifests))):
repoman_settings["O"] = os.path.join(repodir, x)
digestgen(mysettings=repoman_settings, myportdb=portdb)
elif broken_changelog_manifests:
for x in broken_changelog_manifests:
repoman_settings["O"] = os.path.join(repodir, x)
digestgen(mysettings=repoman_settings, myportdb=portdb)
signed = False
if sign_manifests:
signed = True
try:
for x in sorted(vcs_files_to_cps(
chain(myupdates, myremoved, mymanifests))):
repoman_settings["O"] = os.path.join(repodir, x)
manifest_path = os.path.join(repoman_settings["O"], "Manifest")
if not need_signature(manifest_path):
continue
gpgsign(manifest_path)
except portage.exception.PortageException as e:
portage.writemsg("!!! %s\n" % str(e))
portage.writemsg("!!! Disabled FEATURES='sign'\n")
signed = False
if vcs == 'git':
# It's not safe to use the git commit -a option since there might
# be some modified files elsewhere in the working tree that the
# user doesn't want to commit. Therefore, call git update-index
# in order to ensure that the index is updated with the latest
# versions of all new and modified files in the relevant portion
# of the working tree.
myfiles = mymanifests + myupdates
myfiles.sort()
update_index_cmd = ["git", "update-index"]
update_index_cmd.extend(f.lstrip("./") for f in myfiles)
if options.pretend:
print("(%s)" % (" ".join(update_index_cmd),))
else:
retval = spawn(update_index_cmd, env=os.environ)
if retval != os.EX_OK:
writemsg_level(("!!! Exiting on %s (shell) " + \
"error code: %s\n") % (vcs, retval),
level=logging.ERROR, noiselevel=-1)
sys.exit(retval)
if True:
myfiles = mymanifests[:]
# If there are no header (SVN/CVS keywords) changes in
# the files, this Manifest commit must include the
# other (yet uncommitted) files.
if not myheaders:
myfiles += myupdates
myfiles += myremoved
myfiles.sort()
fd, commitmessagefile = tempfile.mkstemp(".repoman.msg")
mymsg = os.fdopen(fd, "wb")
mymsg.write(_unicode_encode(commitmessage))
mymsg.close()
commit_cmd = []
if options.pretend and vcs is None:
# substitute a bogus value for pretend output
commit_cmd.append("cvs")
else:
commit_cmd.append(vcs)
commit_cmd.extend(vcs_global_opts)
commit_cmd.append("commit")
commit_cmd.extend(vcs_local_opts)
if vcs == "hg":
commit_cmd.extend(["--logfile", commitmessagefile])
commit_cmd.extend(myfiles)
else:
commit_cmd.extend(["-F", commitmessagefile])
commit_cmd.extend(f.lstrip("./") for f in myfiles)
try:
if options.pretend:
print("(%s)" % (" ".join(commit_cmd),))
else:
retval = spawn(commit_cmd, env=commit_env)
if retval != os.EX_OK:
if repo_config.sign_commit and vcs == 'git' and \
not git_supports_gpg_sign():
# Inform user that newer git is needed (bug #403323).
logging.error(
"Git >=1.7.9 is required for signed commits!")
writemsg_level(("!!! Exiting on %s (shell) " + \
"error code: %s\n") % (vcs, retval),
level=logging.ERROR, noiselevel=-1)
sys.exit(retval)
finally:
try:
os.unlink(commitmessagefile)
except OSError:
pass
print()
if vcs:
print("Commit complete.")
else:
print("repoman was too scared by not seeing any familiar version control file that he forgot to commit anything")
print(green("RepoMan sez:"), "\"If everyone were like you, I'd be out of business!\"\n")
sys.exit(0)
|