1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639

640

641

642

643

644

645

646

647

648

649

650

651

652

653

654

655

656

657

658

659

660

661

662

663

664

665

666

667

668

669

670

671

672

673

674

675

676

677

678

679

680

681

682

683

684

685

686

687

688

689

690

691

692

693

694

695

696

697

698

699

700

701

702

703

704

705

706

707

708

709

710

711

712

713

714

715

716

717

718

719

720

721

722

723

724

725

726

727

728

729

730

731

732

733

734

735

736

737

738

739

740

741

742

743

744

745

746

747

748

749

750

751

752

753

754

755

756

757

758

759

760

761

762

763

764

765

766

767

768

769

770

771

772

773

774

775

776

777

778

779

780

781

782

783

784

785

786

787

788

789

790

791

792

793

794

795

796

797

798

799

800

801

802

803

804

805

806

807

808

809

810

811

812

813

814

815

816

817

818

819

820

821

822

823

824

825

826

827

828

829

830

831

832

833

834

835

836

837

838

839

840

841

842

843

844

845

846

847

848

849

850

851

852

853

854

855

856

857

858

859

860

861

862

863

864

865

866

867

868

869

870

871

872

873

874

875

876

877

878

879

880

881

882

883

884

885

886

887

888

889

890

891

892

893

894

895

896

897

898

899

900

901

902

903

904

905

906

907

908

909

910

911

912

913

914

915

916

917

918

919

920

921

922

923

924

925

926

927

928

929

930

931

932

933

934

935

936

937

938

939

940

941

942

943

944

945

946

947

948

949

950

951

952

953

954

955

956

957

958

959

960

961

962

963

964

965

966

967

968

969

970

971

972

973

974

975

976

977

978

979

980

981

982

983

984

985

986

987

988

989

990

991

992

993

994

995

996

997

998

999

1000

1001

1002

1003

1004

1005

1006

1007

1008

1009

1010

1011

1012

1013

1014

1015

1016

1017

1018

1019

1020

1021

1022

1023

1024

1025

1026

1027

1028

1029

1030

1031

1032

1033

1034

1035

1036

1037

1038

1039

1040

1041

1042

1043

1044

1045

1046

1047

1048

1049

1050

1051

1052

1053

1054

1055

1056

1057

1058

1059

1060

1061

1062

1063

1064

1065

1066

1067

1068

1069

1070

1071

1072

1073

1074

1075

1076

1077

1078

1079

1080

1081

1082

1083

1084

1085

1086

1087

1088

1089

1090

1091

1092

1093

1094

1095

1096

1097

1098

1099

1100

1101

1102

1103

1104

1105

1106

1107

1108

1109

1110

1111

1112

1113

1114

1115

1116

1117

1118

1119

1120

1121

1122

1123

1124

1125

1126

1127

1128

1129

1130

1131

1132

1133

1134

1135

1136

1137

1138

1139

1140

1141

1142

1143

1144

1145

1146

1147

1148

1149

1150

1151

1152

1153

1154

1155

1156

1157

1158

1159

1160

1161

1162

1163

1164

1165

1166

1167

1168

1169

1170

1171

1172

1173

1174

1175

1176

1177

1178

1179

1180

1181

1182

1183

1184

1185

1186

1187

1188

1189

1190

1191

1192

1193

1194

1195

1196

1197

1198

1199

1200

1201

1202

1203

1204

1205

1206

1207

1208

1209

1210

1211

1212

1213

1214

1215

1216

1217

1218

1219

1220

1221

1222

1223

1224

1225

1226

1227

1228

1229

1230

1231

1232

1233

1234

1235

1236

1237

1238

1239

1240

1241

1242

1243

1244

1245

1246

1247

1248

1249

1250

1251

1252

1253

1254

1255

1256

1257

1258

1259

1260

1261

1262

1263

1264

1265

1266

1267

1268

1269

1270

1271

1272

1273

1274

1275

1276

1277

1278

1279

1280

1281

1282

1283

1284

1285

1286

1287

1288

1289

1290

1291

1292

1293

1294

1295

1296

1297

1298

1299

1300

1301

1302

1303

1304

1305

1306

1307

1308

1309

1310

1311

1312

1313

1314

1315

1316

1317

1318

1319

1320

1321

1322

1323

1324

1325

1326

1327

1328

1329

1330

1331

1332

1333

1334

1335

1336

1337

1338

1339

1340

1341

1342

1343

1344

1345

1346

1347

1348

1349

1350

1351

1352

1353

1354

1355

1356

1357

1358

1359

1360

1361

1362

1363

1364

1365

1366

1367

1368

1369

1370

1371

1372

1373

1374

1375

1376

1377

1378

1379

1380

1381

1382

1383

1384

1385

1386

1387

1388

1389

1390

1391

1392

1393

1394

1395

1396

1397

1398

1399

1400

1401

1402

1403

1404

1405

1406

1407

1408

1409

1410

1411

1412

1413

1414

1415

1416

1417

1418

1419

1420

1421

1422

1423

1424

1425

1426

1427

1428

1429

1430

1431

1432

1433

1434

1435

1436

1437

1438

1439

1440

1441

1442

1443

1444

1445

1446

1447

1448

1449

1450

1451

1452

1453

1454

1455

1456

1457

1458

1459

1460

1461

1462

1463

1464

1465

1466

1467

1468

1469

1470

1471

1472

1473

1474

1475

1476

1477

1478

1479

1480

1481

1482

1483

1484

1485

1486

1487

1488

1489

1490

1491

1492

1493

1494

1495

1496

1497

1498

1499

1500

1501

1502

1503

1504

1505

1506

1507

1508

1509

1510

1511

1512

1513

1514

1515

1516

1517

1518

1519

1520

1521

1522

1523

1524

1525

1526

1527

1528

1529

1530

1531

1532

1533

1534

1535

1536

1537

1538

1539

1540

1541

1542

1543

1544

1545

1546

1547

1548

1549

1550

1551

1552

1553

1554

1555

1556

1557

1558

1559

1560

1561

1562

1563

1564

1565

1566

1567

1568

1569

1570

1571

1572

1573

1574

1575

1576

1577

1578

1579

1580

1581

1582

1583

1584

1585

1586

1587

1588

1589

1590

1591

1592

1593

1594

1595

1596

1597

1598

1599

1600

1601

1602

1603

1604

1605

1606

1607

1608

1609

1610

1611

1612

1613

1614

1615

1616

1617

1618

1619

1620

1621

1622

1623

1624

1625

1626

1627

1628

1629

1630

1631

1632

1633

1634

1635

1636

1637

1638

1639

1640

1641

1642

1643

1644

1645

1646

1647

1648

1649

1650

1651

1652

1653

1654

1655

1656

1657

1658

1659

1660

1661

1662

1663

1664

1665

1666

1667

1668

1669

1670

1671

1672

1673

1674

1675

1676

1677

1678

1679

1680

1681

1682

1683

1684

1685

1686

1687

1688

1689

1690

1691

1692

1693

1694

1695

1696

1697

1698

1699

1700

1701

1702

1703

1704

1705

1706

1707

1708

1709

1710

1711

1712

1713

1714

1715

1716

1717

1718

1719

1720

1721

1722

1723

1724

1725

1726

1727

1728

1729

1730

1731

1732

1733

1734

1735

1736

1737

1738

1739

1740

1741

1742

1743

1744

1745

1746

1747

1748

1749

1750

1751

1752

1753

1754

1755

1756

1757

1758

1759

1760

1761

1762

1763

1764

1765

1766

1767

1768

1769

1770

1771

1772

1773

1774

1775

1776

1777

1778

1779

1780

1781

1782

1783

1784

1785

1786

1787

1788

1789

1790

1791

1792

1793

1794

1795

1796

1797

1798

1799

1800

1801

1802

1803

1804

1805

1806

1807

1808

1809

1810

1811

1812

1813

1814

1815

1816

1817

1818

1819

1820

1821

1822

1823

1824

1825

1826

1827

1828

1829

1830

1831

1832

1833

1834

1835

1836

1837

1838

1839

1840

1841

1842

1843

1844

1845

1846

1847

1848

1849

1850

1851

1852

1853

1854

1855

1856

1857

1858

1859

1860

1861

1862

1863

1864

1865

1866

1867

1868

1869

1870

1871

1872

1873

1874

1875

1876

1877

1878

1879

1880

1881

1882

1883

1884

1885

1886

1887

1888

1889

1890

1891

1892

1893

1894

1895

1896

1897

1898

1899

1900

1901

1902

1903

1904

1905

1906

1907

1908

1909

1910

1911

1912

1913

1914

1915

1916

1917

1918

1919

1920

1921

1922

1923

1924

1925

1926

1927

1928

1929

1930

1931

1932

1933

1934

1935

1936

1937

1938

1939

1940

1941

1942

1943

1944

1945

1946

1947

1948

1949

1950

1951

1952

1953

1954

1955

1956

1957

1958

1959

1960

1961

1962

1963

1964

1965

1966

1967

1968

1969

1970

1971

1972

1973

1974

1975

1976

1977

1978

1979

1980

1981

1982

1983

1984

1985

1986

1987

1988

1989

1990

1991

1992

1993

1994

1995

1996

1997

1998

1999

2000

2001

2002

2003

2004

2005

2006

2007

2008

2009

2010

2011

2012

2013

2014

2015

2016

2017

2018

2019

2020

2021

2022

2023

2024

2025

2026

2027

2028

2029

2030

2031

2032

2033

2034

2035

2036

2037

2038

2039

2040

2041

2042

2043

2044

2045

2046

2047

2048

2049

2050

2051

2052

2053

2054

2055

2056

2057

2058

2059

2060

2061

2062

2063

2064

2065

2066

2067

2068

2069

2070

2071

2072

2073

2074

2075

2076

2077

2078

2079

2080

2081

2082

2083

2084

2085

2086

2087

2088

2089

2090

2091

2092

2093

2094

2095

2096

2097

2098

2099

2100

2101

2102

2103

2104

2105

2106

2107

2108

2109

2110

2111

2112

2113

2114

2115

2116

2117

2118

2119

2120

2121

2122

2123

2124

2125

2126

2127

2128

2129

2130

2131

2132

2133

2134

2135

2136

2137

2138

2139

2140

2141

2142

2143

2144

2145

2146

2147

2148

2149

2150

2151

2152

2153

2154

2155

2156

2157

2158

2159

2160

2161

2162

2163

2164

2165

2166

2167

2168

2169

2170

2171

2172

2173

2174

2175

2176

2177

2178

2179

2180

2181

2182

2183

2184

2185

2186

2187

2188

2189

2190

2191

2192

2193

2194

2195

2196

2197

2198

2199

2200

2201

2202

2203

2204

2205

2206

2207

2208

2209

2210

2211

2212

2213

2214

2215

2216

2217

2218

2219

2220

2221

2222

2223

2224

2225

2226

2227

2228

2229

2230

2231

2232

2233

2234

2235

2236

2237

2238

2239

2240

2241

2242

2243

2244

2245

2246

2247

2248

2249

2250

2251

2252

2253

2254

2255

2256

2257

2258

2259

2260

2261

2262

2263

2264

2265

2266

2267

2268

2269

2270

2271

2272

2273

2274

2275

2276

2277

2278

2279

2280

2281

2282

2283

2284

2285

2286

2287

2288

2289

2290

2291

2292

2293

2294

2295

2296

2297

2298

2299

2300

2301

2302

2303

2304

2305

2306

2307

2308

2309

2310

2311

2312

2313

2314

2315

2316

2317

2318

2319

2320

2321

2322

2323

2324

2325

2326

2327

2328

2329

2330

2331

2332

2333

2334

2335

2336

2337

2338

2339

2340

2341

2342

2343

2344

2345

2346

2347

2348

2349

2350

2351

2352

2353

2354

2355

2356

2357

2358

2359

2360

2361

2362

2363

2364

2365

2366

2367

2368

2369

2370

2371

2372

2373

2374

2375

2376

2377

2378

2379

2380

2381

2382

2383

2384

2385

2386

2387

2388

2389

2390

2391

2392

2393

2394

2395

2396

2397

2398

2399

2400

2401

2402

2403

2404

2405

2406

2407

2408

2409

2410

2411

2412

2413

2414

2415

2416

2417

2418

2419

2420

2421

2422

2423

2424

2425

2426

2427

2428

2429

2430

2431

2432

2433

2434

2435

2436

2437

2438

2439

2440

2441

2442

2443

2444

2445

2446

2447

2448

2449

2450

2451

2452

2453

2454

2455

2456

2457

2458

2459

2460

2461

2462

2463

2464

2465

2466

2467

2468

2469

2470

2471

2472

2473

2474

2475

2476

2477

2478

2479

2480

2481

2482

2483

2484

2485

2486

2487

2488

2489

2490

2491

2492

2493

2494

2495

2496

2497

2498

2499

2500

2501

2502

2503

2504

2505

2506

2507

2508

2509

2510

2511

2512

2513

2514

2515

2516

2517

2518

2519

2520

2521

2522

2523

2524

2525

2526

2527

2528

2529

2530

2531

2532

2533

2534

2535

2536

2537

2538

2539

2540

2541

2542

2543

2544

2545

2546

2547

2548

2549

2550

2551

2552

2553

2554

2555

2556

2557

2558

2559

2560

2561

2562

2563

2564

2565

2566

2567

2568

2569

2570

2571

2572

2573

2574

2575

2576

2577

2578

2579

2580

2581

2582

2583

2584

2585

2586

2587

2588

2589

2590

2591

2592

2593

2594

2595

2596

2597

2598

2599

2600

2601

2602

2603

2604

2605

2606

2607

2608

2609

2610

2611

2612

2613

2614

2615

2616

2617

2618

2619

2620

2621

2622

2623

2624

2625

2626

2627

2628

2629

2630

2631

2632

2633

2634

2635

2636

2637

2638

2639

2640

2641

2642

2643

2644

2645

2646

2647

2648

2649

2650

2651

2652

2653

2654

2655

2656

2657

2658

2659

2660

2661

2662

2663

2664

2665

2666

2667

2668

2669

2670

2671

2672

2673

2674

2675

2676

2677

2678

2679

2680

2681

2682

2683

2684

2685

2686

2687

2688

2689

2690

2691

2692

2693

2694

2695

2696

2697

2698

2699

2700

2701

2702

2703

2704

2705

2706

2707

2708

2709

2710

2711

2712

2713

2714

2715

2716

2717

2718

2719

2720

2721

2722

2723

2724

2725

2726

2727

2728

2729

2730

2731

2732

2733

2734

2735

2736

2737

2738

2739

2740

2741

2742

2743

2744

2745

2746

2747

2748

2749

2750

2751

2752

2753

2754

2755

2756

2757

2758

2759

2760

2761

2762

2763

2764

2765

2766

2767

2768

2769

2770

2771

2772

2773

2774

2775

2776

2777

2778

2779

2780

2781

2782

2783

2784

2785

2786

2787

2788

2789

2790

2791

2792

2793

2794

2795

2796

2797

2798

2799

2800

2801

2802

2803

2804

2805

2806

2807

2808

2809

2810

2811

2812

2813

2814

2815

2816

2817

2818

2819

2820

2821

2822

2823

2824

2825

2826

2827

2828

2829

2830

2831

2832

2833

2834

2835

2836

2837

2838

2839

2840

2841

2842

2843

2844

2845

2846

2847

2848

2849

2850

2851

2852

2853

2854

2855

2856

2857

2858

2859

2860

2861

2862

2863

2864

2865

2866

2867

2868

2869

2870

2871

2872

2873

2874

2875

2876

2877

2878

2879

2880

2881

2882

2883

2884

2885

2886

2887

2888

2889

2890

2891

2892

2893

2894

2895

2896

2897

2898

2899

2900

2901

2902

2903

2904

2905

2906

2907

2908

2909

2910

2911

2912

2913

2914

2915

2916

2917

2918

2919

2920

2921

2922

2923

2924

2925

2926

2927

2928

2929

2930

2931

2932

2933

2934

2935

2936

2937

2938

2939

2940

2941

2942

2943

2944

2945

2946

2947

2948

2949

2950

2951

2952

2953

2954

2955

2956

2957

2958

2959

2960

2961

2962

2963

2964

2965

2966

2967

2968

2969

2970

2971

2972

2973

2974

2975

2976

2977

2978

2979

2980

2981

2982

2983

2984

2985

2986

2987

2988

2989

2990

2991

2992

2993

2994

2995

2996

2997

2998

2999

3000

3001

3002

3003

3004

3005

3006

3007

3008

3009

3010

3011

3012

3013

3014

3015

3016

3017

3018

3019

3020

3021

3022

3023

3024

3025

3026

3027

3028

3029

3030

3031

3032

3033

3034

3035

3036

3037

3038

3039

3040

3041

3042

3043

3044

3045

3046

3047

3048

3049

3050

3051

3052

3053

3054

3055

3056

3057

3058

3059

3060

3061

3062

3063

3064

3065

3066

3067

3068

3069

3070

3071

3072

3073

3074

3075

3076

3077

3078

3079

3080

3081

3082

3083

3084

3085

3086

3087

3088

3089

3090

3091

3092

3093

3094

3095

3096

3097

3098

3099

3100

3101

3102

3103

3104

3105

3106

3107

3108

3109

3110

3111

3112

3113

3114

3115

3116

3117

3118

3119

3120

3121

3122

3123

3124

3125

3126

3127

3128

3129

3130

3131

3132

3133

3134

3135

3136

3137

3138

3139

3140

3141

3142

3143

3144

3145

3146

3147

3148

3149

3150

3151

3152

3153

3154

3155

3156

3157

3158

3159

3160

3161

3162

3163

3164

3165

3166

3167

3168

3169

3170

3171

3172

3173

3174

3175

3176

3177

3178

3179

3180

3181

3182

3183

3184

3185

3186

3187

3188

3189

3190

3191

3192

3193

3194

3195

3196

3197

3198

3199

3200

3201

3202

3203

3204

3205

3206

3207

3208

3209

3210

3211

3212

3213

3214

3215

3216

3217

3218

3219

3220

3221

3222

3223

3224

3225

3226

3227

3228

3229

3230

3231

3232

3233

3234

3235

3236

3237

3238

3239

3240

3241

3242

3243

3244

3245

3246

3247

3248

3249

3250

3251

3252

3253

3254

3255

3256

3257

3258

3259

3260

3261

3262

3263

3264

3265

3266

3267

3268

3269

3270

3271

3272

3273

3274

3275

3276

3277

3278

3279

3280

3281

3282

3283

3284

3285

3286

3287

3288

3289

3290

3291

3292

3293

3294

3295

3296

3297

3298

3299

3300

3301

3302

3303

3304

3305

3306

3307

3308

3309

3310

3311

3312

3313

3314

3315

3316

3317

3318

3319

3320

3321

3322

# Copyright 2013-2019 The Distro Tracker Developers 

# See the COPYRIGHT file at the top-level directory of this distribution and 

# at https://deb.li/DTAuthors 

# 

# This file is part of Distro Tracker. It is subject to the license terms 

# in the LICENSE file found in the top-level directory of this 

# distribution and at https://deb.li/DTLicense. No part of Distro Tracker, 

# including this file, may be copied, modified, propagated, or distributed 

# except according to the terms contained in the LICENSE file. 

 

""" 

Debian-specific tasks. 

""" 

 

import collections 

import itertools 

import json 

import logging 

import os 

import re 

from enum import Enum 

 

from bs4 import BeautifulSoup as soup 

 

from debian import deb822, debian_support 

from debian.debian_support import AptPkgVersion 

 

import debianbts 

 

from django.conf import settings 

from django.core.exceptions import ValidationError 

from django.db import transaction 

from django.db.models import Prefetch 

from django.utils.http import urlencode 

 

import yaml 

 

from distro_tracker.accounts.models import UserEmail 

from distro_tracker.core.models import ( 

ActionItem, 

ActionItemType, 

BinaryPackageBugStats, 

BinaryPackageName, 

BugDisplayManagerMixin, 

PackageBugStats, 

PackageData, 

PackageName, 

Repository, 

SourcePackageDeps, 

SourcePackageName 

) 

from distro_tracker.core.tasks import BaseTask 

from distro_tracker.core.tasks.mixins import PackageTagging 

from distro_tracker.core.tasks.schedulers import IntervalScheduler 

from distro_tracker.core.utils import get_or_none 

from distro_tracker.core.utils.http import get_resource_text 

from distro_tracker.core.utils.misc import get_data_checksum 

from distro_tracker.core.utils.packages import ( 

html_package_list, 

package_url 

) 

from distro_tracker.vendor.debian.models import ( 

BuildLogCheckStats, 

LintianStats, 

PackageExcuses, 

PackageTransition, 

UbuntuPackage 

) 

 

from .models import DebianContributor 

 

logger = logging.getLogger(__name__) 

logger_input = logging.getLogger('distro_tracker.input') 

 

 

class RetrieveDebianMaintainersTask(BaseTask): 

""" 

Retrieves (and updates if necessary) a list of Debian Maintainers. 

""" 

 

class Scheduler(IntervalScheduler): 

interval = 3600 * 24 

 

def execute_main(self): 

url = "https://ftp-master.debian.org/dm.txt" 

content = get_resource_text(url, force_update=self.force_update, 

only_if_updated=True) 

88 ↛ 90line 88 didn't jump to line 90, because the condition on line 88 was never true if content is None: 

# No need to do anything if the cached item was still not updated 

return 

 

maintainers = {} 

lines = content.splitlines() 

for stanza in deb822.Deb822.iter_paragraphs(lines): 

95 ↛ 94line 95 didn't jump to line 94, because the condition on line 95 was never false if 'Uid' in stanza and 'Allow' in stanza: 

# Allow is a comma-separated string of 'package (DD fpr)' items, 

# where DD fpr is the fingerprint of the DD that granted the 

# permission 

name, email = stanza['Uid'].rsplit(' ', 1) 

email = email.strip('<>') 

for pair in stanza['Allow'].split(','): 

pair = pair.strip() 

pkg, dd_fpr = pair.split() 

maintainers.setdefault(email, []) 

maintainers[email].append(pkg) 

 

# Now update the developer information 

with transaction.atomic(): 

# Reset all old maintainers first. 

qs = DebianContributor.objects.filter(is_debian_maintainer=True) 

qs.update(is_debian_maintainer=False) 

 

for email, packages in maintainers.items(): 

try: 

user_email, _ = UserEmail.objects.get_or_create(email=email) 

except ValidationError: 

logger_input.info('%s refers to invalid email "%s".', 

url, email) 

continue 

 

contributor, _ = DebianContributor.objects.get_or_create( 

email=user_email) 

 

contributor.is_debian_maintainer = True 

contributor.allowed_packages = packages 

contributor.save() 

 

 

class RetrieveLowThresholdNmuTask(BaseTask): 

""" 

Updates the list of Debian Maintainers which agree with the lowthreshold 

NMU. 

""" 

 

class Scheduler(IntervalScheduler): 

interval = 3600 * 24 

 

def _retrieve_emails(self): 

""" 

Helper function which obtains the list of emails of maintainers that 

agree with the lowthreshold NMU. 

""" 

url = 'https://wiki.debian.org/LowThresholdNmu?action=raw' 

content = get_resource_text(url, force_update=self.force_update, 

only_if_updated=True) 

146 ↛ 147line 146 didn't jump to line 147, because the condition on line 146 was never true if content is None: 

return 

 

emails = [] 

devel_php_RE = re.compile( 

r'https?://qa\.debian\.org/developer\.php\?login=([^\s&|]+)') 

word_RE = re.compile(r'^\w+$') 

for line in content.splitlines(): 

match = devel_php_RE.search(line) 

while match: # look for several matches on the same line 

email = None 

login = match.group(1) 

if word_RE.match(login): 

email = login + '@debian.org' 

160 ↛ 162line 160 didn't jump to line 162, because the condition on line 160 was never false elif login.find('@') >= 0: 

email = login 

162 ↛ 164line 162 didn't jump to line 164, because the condition on line 162 was never false if email: 

emails.append(email) 

line = line[match.end():] 

match = devel_php_RE.search(line) 

return emails 

 

def execute_main(self): 

emails = self._retrieve_emails() 

with transaction.atomic(): 

# Reset all threshold flags first. 

qs = DebianContributor.objects.filter( 

agree_with_low_threshold_nmu=True) 

qs.update(agree_with_low_threshold_nmu=False) 

 

for email in emails: 

try: 

email, _ = UserEmail.objects.get_or_create(email=email) 

except ValidationError: 

logger_input.info( 

'LowThresholdNmu refers to invalid email "%s".', email) 

continue 

 

contributor, _ = DebianContributor.objects.get_or_create( 

email=email) 

 

contributor.agree_with_low_threshold_nmu = True 

contributor.save() 

 

 

class UpdatePackageBugStats(BaseTask, BugDisplayManagerMixin): 

""" 

Updates the BTS bug stats for all packages (source, binary and pseudo). 

Creates :class:`distro_tracker.core.ActionItem` instances for packages 

which have bugs tagged help or patch. 

""" 

 

class Scheduler(IntervalScheduler): 

interval = 3600 

 

PATCH_BUG_ACTION_ITEM_TYPE_NAME = 'debian-patch-bugs-warning' 

HELP_BUG_ACTION_ITEM_TYPE_NAME = 'debian-help-bugs-warning' 

 

PATCH_ITEM_SHORT_DESCRIPTION = ( 

'<a href="{url}">{count}</a> tagged patch in the ' 

'<abbr title="Bug Tracking System">BTS</abbr>') 

HELP_ITEM_SHORT_DESCRIPTION = ( 

'<a href="{url}">{count}</a> tagged help in the ' 

'<abbr title="Bug Tracking System">BTS</abbr>') 

PATCH_ITEM_FULL_DESCRIPTION_TEMPLATE = 'debian/patch-bugs-action-item.html' 

HELP_ITEM_FULL_DESCRIPTION_TEMPLATE = 'debian/help-bugs-action-item.html' 

 

bug_categories = ( 

'rc', 

'normal', 

'wishlist', 

'fixed', 

'patch', 

) 

 

def initialize(self, *args, **kwargs): 

super(UpdatePackageBugStats, self).initialize(*args, **kwargs) 

# The :class:`distro_tracker.core.models.ActionItemType` instances which 

# this task can create. 

self.patch_item_type = ActionItemType.objects.create_or_update( 

type_name=self.PATCH_BUG_ACTION_ITEM_TYPE_NAME, 

full_description_template=self.PATCH_ITEM_FULL_DESCRIPTION_TEMPLATE) 

self.help_item_type = ActionItemType.objects.create_or_update( 

type_name=self.HELP_BUG_ACTION_ITEM_TYPE_NAME, 

full_description_template=self.HELP_ITEM_FULL_DESCRIPTION_TEMPLATE) 

 

def _get_tagged_bug_stats(self, tag, user=None): 

""" 

Using the BTS interface, retrieves the statistics of bugs with a 

particular tag. 

 

:param tag: The tag for which the statistics are required. 

:type tag: string 

:param user: The email of the user who tagged the bug with the given 

tag. 

:type user: string 

 

:returns: A dict mapping package names to the count of bugs with the 

given tag. 

""" 

debian_ca_bundle = '/etc/ssl/ca-debian/ca-certificates.crt' 

if os.path.exists(debian_ca_bundle): 

os.environ['SSL_CERT_FILE'] = debian_ca_bundle 

if user: 

bug_numbers = debianbts.get_usertag(user, tag).values() 

else: 

bug_numbers = debianbts.get_bugs('tag', tag) 

 

# Match each retrieved bug ID to a package and then find the aggregate 

# count for each package. 

bug_stats = {} 

bugs = debianbts.get_status(*bug_numbers) 

for bug in bugs: 

if bug.done or bug.fixed_versions or bug.pending == 'done': 

continue 

 

bug_stats.setdefault(bug.package, 0) 

bug_stats[bug.package] += 1 

 

return bug_stats 

 

def _extend_bug_stats(self, bug_stats, extra_stats, category_name): 

""" 

Helper method which adds extra bug stats to an already existing list of 

stats. 

 

:param bug_stats: An already existing list of bug stats. Maps package 

names to list of bug category descriptions. 

:type bug_stats: dict 

:param extra_stats: Extra bug stats which should be added to 

``bug_stats``. Maps package names to integers representing bug 

counts. 

:type extra_stats: dict 

:param category_name: The name of the bug category which is being added 

:type category_name: string 

""" 

for package, count in extra_stats.items(): 

bug_stats.setdefault(package, []) 

bug_stats[package].append({ 

'category_name': category_name, 

'bug_count': count, 

}) 

 

def _create_patch_bug_action_item(self, package, bug_stats): 

""" 

Creates a :class:`distro_tracker.core.models.ActionItem` instance for 

the given package if it contains any bugs tagged patch. 

 

:param package: The package for which the action item should be 

updated. 

:type package: :class:`distro_tracker.core.models.PackageName` 

:param bug_stats: A dictionary mapping category names to structures 

describing those categories. Those structures should be 

identical to the ones stored in the :class:`PackageBugStats` 

instance. 

:type bug_stats: dict 

""" 

# Get the old action item, if any 

action_item = package.get_action_item_for_type( 

self.PATCH_BUG_ACTION_ITEM_TYPE_NAME) 

 

if 'patch' not in bug_stats or bug_stats['patch']['bug_count'] == 0: 

# Remove the old action item, since the package does not have any 

# bugs tagged patch anymore. 

if action_item is not None: 

action_item.delete() 

return 

 

# If the package has bugs tagged patch, update the action item 

if action_item is None: 

action_item = ActionItem( 

package=package, 

item_type=self.patch_item_type) 

 

bug_count = bug_stats['patch']['bug_count'] 

# Include the URL in the short description 

url = self.bug_manager.get_bug_tracker_url( 

package.name, 'source', 'patch') 

324 ↛ 325line 324 didn't jump to line 325, because the condition on line 324 was never true if not url: 

url = '' 

# Include the bug count in the short description 

count = '{bug_count} bug'.format(bug_count=bug_count) 

if bug_count > 1: 

count += 's' 

action_item.short_description = \ 

self.PATCH_ITEM_SHORT_DESCRIPTION.format(url=url, count=count) 

# Set additional URLs and merged bug count in the extra data for a full 

# description 

action_item.extra_data = { 

'bug_count': bug_count, 

'merged_count': bug_stats['patch'].get('merged_count', 0), 

'url': url, 

'merged_url': self.bug_manager.get_bug_tracker_url( 

package.name, 'source', 'patch-merged'), 

} 

action_item.save() 

 

def _create_help_bug_action_item(self, package, bug_stats): 

""" 

Creates a :class:`distro_tracker.core.models.ActionItem` instance for 

the given package if it contains any bugs tagged help. 

 

:param package: The package for which the action item should be 

updated. 

:type package: :class:`distro_tracker.core.models.PackageName` 

:param bug_stats: A dictionary mapping category names to structures 

describing those categories. Those structures should be 

identical to the ones stored in the :class:`PackageBugStats` 

instance. 

:type bug_stats: dict 

""" 

# Get the old action item, if any 

action_item = package.get_action_item_for_type( 

self.HELP_BUG_ACTION_ITEM_TYPE_NAME) 

 

if 'help' not in bug_stats or bug_stats['help']['bug_count'] == 0: 

# Remove the old action item, since the package does not have any 

# bugs tagged patch anymore. 

if action_item is not None: 

action_item.delete() 

return 

 

# If the package has bugs tagged patch, update the action item 

if action_item is None: 

action_item = ActionItem( 

package=package, 

item_type=self.help_item_type) 

 

bug_count = bug_stats['help']['bug_count'] 

# Include the URL in the short description 

url = self.bug_manager.get_bug_tracker_url( 

package.name, 'source', 'help') 

378 ↛ 379line 378 didn't jump to line 379, because the condition on line 378 was never true if not url: 

url = '' 

# Include the bug count in the short description 

count = '{bug_count} bug'.format(bug_count=bug_count) 

if bug_count > 1: 

count += 's' 

action_item.short_description = self.HELP_ITEM_SHORT_DESCRIPTION.format( 

url=url, count=count) 

# Set additional URLs and merged bug count in the extra data for a full 

# description 

action_item.extra_data = { 

'bug_count': bug_count, 

'url': url, 

} 

action_item.save() 

 

def _create_action_items(self, package_bug_stats): 

""" 

Method which creates a :class:`distro_tracker.core.models.ActionItem` 

instance for a package based on the given package stats. 

 

For now, an action item is created if the package either has bugs 

tagged as help or patch. 

""" 

# Transform the bug stats to a structure easier to pass to functions 

# for particular bug-category action items. 

bug_stats = { 

category['category_name']: category 

for category in package_bug_stats.stats 

} 

package = package_bug_stats.package 

self._create_patch_bug_action_item(package, bug_stats) 

self._create_help_bug_action_item(package, bug_stats) 

 

def _get_udd_bug_stats(self): 

url = 'https://udd.debian.org/cgi-bin/ddpo-bugs.cgi' 

response_content = get_resource_text(url) 

if not response_content: 

return 

 

# Each line in the response should be bug stats for a single package 

bug_stats = {} 

for line in response_content.splitlines(): 

line = line.strip() 

try: 

package_name, bug_counts = line, '' 

if line.startswith('src:'): 

src, package_name, bug_counts = line.split(':', 2) 

else: 

package_name, bug_counts = line.split(':', 1) 

# Merged counts are in parentheses so remove those before 

# splitting the numbers 

bug_counts = re.sub(r'[()]', ' ', bug_counts).split() 

bug_counts = [int(count) for count in bug_counts] 

except ValueError: 

logger.warning( 

'Failed to parse bug information for %s: %s', 

package_name, bug_counts, exc_info=1) 

continue 

 

# Match the extracted counts with category names 

bug_stats[package_name] = [ 

{ 

'category_name': category_name, 

'bug_count': bug_count, 

'merged_count': merged_count, 

} 

for category_name, (bug_count, merged_count) in zip( 

self.bug_categories, zip(bug_counts[::2], bug_counts[1::2])) 

] 

 

return bug_stats 

 

def _remove_obsolete_action_items(self, package_names): 

""" 

Removes action items for packages which no longer have any bug stats. 

""" 

ActionItem.objects.delete_obsolete_items( 

item_types=[self.patch_item_type, self.help_item_type], 

non_obsolete_packages=package_names) 

 

def update_source_and_pseudo_bugs(self): 

""" 

Performs the update of bug statistics for source and pseudo packages. 

""" 

# First get the bug stats exposed by the UDD. 

bug_stats = self._get_udd_bug_stats() 

if not bug_stats: 

bug_stats = {} 

 

# Add in help bugs from the BTS interface 

try: 

help_bugs = self._get_tagged_bug_stats('help') 

self._extend_bug_stats(bug_stats, help_bugs, 'help') 

except RuntimeError: 

logger.exception("Could not get bugs tagged help") 

 

# Add in newcomer bugs from the BTS interface 

try: 

newcomer_bugs = self._get_tagged_bug_stats('newcomer') 

self._extend_bug_stats(bug_stats, newcomer_bugs, 'newcomer') 

except RuntimeError: 

logger.exception("Could not get bugs tagged newcomer") 

 

with transaction.atomic(): 

# Clear previous stats 

PackageBugStats.objects.all().delete() 

self._remove_obsolete_action_items(bug_stats.keys()) 

# Get all packages which have updated stats, along with their 

# action items in 2 DB queries. 

packages = PackageName.objects.filter(name__in=bug_stats.keys()) 

packages.prefetch_related('action_items') 

 

# Update stats and action items. 

stats = [] 

for package in packages: 

# Save the raw package bug stats 

package_bug_stats = PackageBugStats( 

package=package, stats=bug_stats[package.name]) 

stats.append(package_bug_stats) 

 

# Add action items for the package. 

self._create_action_items(package_bug_stats) 

 

PackageBugStats.objects.bulk_create(stats) 

 

def update_binary_bugs(self): 

""" 

Performs the update of bug statistics for binary packages. 

""" 

url = 'https://udd.debian.org/cgi-bin/bugs-binpkgs-pts.cgi' 

response_content = get_resource_text(url) 

if not response_content: 

return 

 

# Extract known binary package bug stats: each line is a separate pkg 

bug_stats = {} 

for line in response_content.splitlines(): 

package_name, bug_counts = line.split(None, 1) 

bug_counts = bug_counts.split() 

try: 

bug_counts = [int(count) for count in bug_counts] 

except ValueError: 

logger.exception( 

'Failed to parse bug information for %s: %s', 

package_name, bug_counts) 

continue 

 

bug_stats[package_name] = [ 

{ 

'category_name': category_name, 

'bug_count': bug_count, 

} 

for category_name, bug_count in zip( 

self.bug_categories, bug_counts) 

] 

 

with transaction.atomic(): 

# Clear previous stats 

BinaryPackageBugStats.objects.all().delete() 

packages = \ 

BinaryPackageName.objects.filter(name__in=bug_stats.keys()) 

# Create new stats in a single query 

stats = [ 

BinaryPackageBugStats(package=package, 

stats=bug_stats[package.name]) 

for package in packages 

] 

BinaryPackageBugStats.objects.bulk_create(stats) 

 

def execute_main(self): 

# Stats for source and pseudo packages is retrieved from a different 

# resource (with a different structure) than stats for binary packages. 

self.update_source_and_pseudo_bugs() 

self.update_binary_bugs() 

 

 

class UpdateLintianStatsTask(BaseTask): 

""" 

Updates packages' lintian stats. 

""" 

 

class Scheduler(IntervalScheduler): 

interval = 3600 * 4 

 

ACTION_ITEM_TYPE_NAME = 'lintian-warnings-and-errors' 

ITEM_DESCRIPTION = 'lintian reports <a href="{url}">{report}</a>' 

ITEM_FULL_DESCRIPTION_TEMPLATE = 'debian/lintian-action-item.html' 

 

def initialize(self, *args, **kwargs): 

super(UpdateLintianStatsTask, self).initialize(*args, **kwargs) 

self.lintian_action_item_type = ActionItemType.objects.create_or_update( 

type_name=self.ACTION_ITEM_TYPE_NAME, 

full_description_template=self.ITEM_FULL_DESCRIPTION_TEMPLATE) 

 

def get_lintian_stats(self): 

url = 'https://lintian.debian.org/qa-list.txt' 

content = get_resource_text(url, force_update=self.force_update, 

only_if_updated=True) 

if content is None: 

return 

 

all_stats = {} 

categories = ( 

'errors', 

'warnings', 

'pedantics', 

'experimentals', 

'overriddens', 

) 

for line in content.splitlines(): 

package, stats = line.split(None, 1) 

stats = stats.split() 

try: 

all_stats[package] = { 

category: int(count) 

for count, category in zip(stats, categories) 

} 

except ValueError: 

logger.exception( 

'Failed to parse lintian information for %s: %s', 

package, line) 

continue 

 

return all_stats 

 

def update_action_item(self, package, lintian_stats): 

""" 

Updates the :class:`ActionItem` for the given package based on the 

:class:`LintianStats <distro_tracker.vendor.debian.models.LintianStats` 

given in ``package_stats``. If the package has errors or warnings an 

:class:`ActionItem` is created. 

""" 

package_stats = lintian_stats.stats 

warnings, errors = ( 

package_stats.get('warnings'), package_stats.get('errors', 0)) 

# Get the old action item for this warning, if it exists. 

lintian_action_item = package.get_action_item_for_type( 

self.lintian_action_item_type.type_name) 

if not warnings and not errors: 

if lintian_action_item: 

# If the item previously existed, delete it now since there 

# are no longer any warnings/errors. 

lintian_action_item.delete() 

return 

 

# The item didn't previously have an action item: create it now 

if lintian_action_item is None: 

lintian_action_item = ActionItem( 

package=package, 

item_type=self.lintian_action_item_type) 

 

lintian_url = lintian_stats.get_lintian_url() 

new_extra_data = { 

'warnings': warnings, 

'errors': errors, 

'lintian_url': lintian_url, 

} 

if lintian_action_item.extra_data: 

old_extra_data = lintian_action_item.extra_data 

if (old_extra_data['warnings'] == warnings and 

old_extra_data['errors'] == errors): 

# No need to update 

return 

 

lintian_action_item.extra_data = new_extra_data 

 

if errors and warnings: 

report = '{} error{} and {} warning{}'.format( 

errors, 

's' if errors > 1 else '', 

warnings, 

's' if warnings > 1 else '') 

elif errors: 

report = '{} error{}'.format( 

errors, 

's' if errors > 1 else '') 

655 ↛ 660line 655 didn't jump to line 660, because the condition on line 655 was never false elif warnings: 

report = '{} warning{}'.format( 

warnings, 

's' if warnings > 1 else '') 

 

lintian_action_item.short_description = self.ITEM_DESCRIPTION.format( 

url=lintian_url, 

report=report) 

 

# If there are errors make the item a high severity issue 

if errors: 

lintian_action_item.severity = ActionItem.SEVERITY_HIGH 

 

lintian_action_item.save() 

 

def execute_main(self): 

all_lintian_stats = self.get_lintian_stats() 

if not all_lintian_stats: 

return 

 

# Discard all old stats 

LintianStats.objects.all().delete() 

 

packages = PackageName.objects.filter(name__in=all_lintian_stats.keys()) 

packages.prefetch_related('action_items') 

# Remove action items for packages which no longer have associated 

# lintian data. 

ActionItem.objects.delete_obsolete_items( 

[self.lintian_action_item_type], all_lintian_stats.keys()) 

 

stats = [] 

for package in packages: 

package_stats = all_lintian_stats[package.name] 

# Save the raw lintian stats. 

lintian_stats = LintianStats(package=package, stats=package_stats) 

stats.append(lintian_stats) 

# Create an ActionItem if there are errors or warnings 

self.update_action_item(package, lintian_stats) 

 

LintianStats.objects.bulk_create(stats) 

 

 

class UpdateAppStreamStatsTask(BaseTask): 

""" 

Updates packages' AppStream issue hints data. 

""" 

 

class Scheduler(IntervalScheduler): 

interval = 3600 * 6 

 

ACTION_ITEM_TYPE_NAME = 'appstream-issue-hints' 

ITEM_DESCRIPTION = 'AppStream hints: {report}' 

ITEM_FULL_DESCRIPTION_TEMPLATE = 'debian/appstream-action-item.html' 

 

def initialize(self, *args, **kwargs): 

super(UpdateAppStreamStatsTask, self).initialize(*args, **kwargs) 

self.appstream_action_item_type = \ 

ActionItemType.objects.create_or_update( 

type_name=self.ACTION_ITEM_TYPE_NAME, 

full_description_template=self.ITEM_FULL_DESCRIPTION_TEMPLATE) 

self._tag_severities = {} 

 

def _load_tag_severities(self): 

url = 'https://appstream.debian.org/hints/sid/hint-definitions.json' 

json_data = get_resource_text(url, force_update=True) 

 

data = json.loads(json_data) 

for tag, info in data.items(): 

self._tag_severities[tag] = info['severity'] 

 

def _load_appstream_hint_stats(self, section, arch, all_stats={}): 

url = 'https://appstream.debian.org/hints/sid/{}/Hints-{}.json.gz' \ 

.format(section, arch) 

hints_json = get_resource_text(url, force_update=self.force_update) 

 

hints = json.loads(hints_json) 

for hint in hints: 

pkid = hint['package'] 

parts = pkid.split('/') 

package_name = parts[0] 

 

# get the source package for this binary package name 

src_pkgname = None 

if SourcePackageName.objects.exists_with_name(package_name): 

package = SourcePackageName.objects.get(name=package_name) 

src_pkgname = package.name 

elif BinaryPackageName.objects.exists_with_name(package_name): 

bin_package = BinaryPackageName.objects.get(name=package_name) 

package = bin_package.main_source_package_name 

src_pkgname = package.name 

else: 

src_pkgname = package_name 

 

if src_pkgname not in all_stats: 

all_stats[src_pkgname] = {} 

750 ↛ 753line 750 didn't jump to line 753, because the condition on line 750 was never false if package_name not in all_stats[src_pkgname]: 

all_stats[src_pkgname][package_name] = {} 

 

for cid, h in hint['hints'].items(): 

for e in h: 

severity = self._tag_severities[e['tag']] 

if severity == "error": 

sevkey = "errors" 

elif severity == "warning": 

sevkey = "warnings" 

760 ↛ 763line 760 didn't jump to line 763, because the condition on line 760 was never false elif severity == "info": 

sevkey = "infos" 

else: 

continue 

if sevkey not in all_stats[src_pkgname][package_name]: 

all_stats[src_pkgname][package_name][sevkey] = 1 

else: 

all_stats[src_pkgname][package_name][sevkey] += 1 

 

return all_stats 

 

def _get_appstream_url(self, package, bin_pkgname): 

""" 

Returns the AppStream URL for the given PackageName in :package. 

""" 

 

src_package = get_or_none(SourcePackageName, pk=package.pk) 

777 ↛ 778line 777 didn't jump to line 778, because the condition on line 777 was never true if not src_package: 

return '#' 

 

if not src_package.main_version: 

return '#' 

 

component = 'main' 

main_entry = src_package.main_entry 

785 ↛ 786line 785 didn't jump to line 786, because the condition on line 785 was never true if main_entry: 

component = main_entry.component 

if not component: 

component = 'main' 

 

return ( 

'https://appstream.debian.org/sid/{}/issues/{}.html' 

.format(component, bin_pkgname) 

) 

 

def _create_final_stats_report(self, package, package_stats): 

""" 

Returns a transformed statistics report to be stored in the database. 

""" 

 

as_report = package_stats.copy() 

for bin_package in list(as_report.keys()): 

# we currently don't want to display info-type hints 

as_report[bin_package].pop('infos', None) 

804 ↛ 808line 804 didn't jump to line 808, because the condition on line 804 was never false if as_report[bin_package]: 

as_report[bin_package]['url'] = \ 

self._get_appstream_url(package, bin_package) 

else: 

as_report.pop(bin_package) 

return as_report 

 

def update_action_item(self, package, package_stats): 

""" 

Updates the :class:`ActionItem` for the given package based on the 

AppStream hint statistics given in ``package_stats``. 

If the package has errors or warnings an 

:class:`ActionItem` is created. 

""" 

 

total_warnings = 0 

total_errors = 0 

for bin_pkgname, info in package_stats.items(): 

total_warnings += info.get('warnings', 0) 

total_errors += info.get('errors', 0) 

 

# Get the old action item for this warning, if it exists. 

appstream_action_item = package.get_action_item_for_type( 

self.appstream_action_item_type.type_name) 

if not total_warnings and not total_errors: 

if appstream_action_item: 

# If the item previously existed, delete it now since there 

# are no longer any warnings/errors. 

appstream_action_item.delete() 

return 

 

# The item didn't previously have an action item: create it now 

if appstream_action_item is None: 

appstream_action_item = ActionItem( 

package=package, 

item_type=self.appstream_action_item_type) 

 

as_report = self._create_final_stats_report(package, package_stats) 

 

if appstream_action_item.extra_data: 

old_extra_data = appstream_action_item.extra_data 

if old_extra_data == as_report: 

# No need to update 

return 

 

appstream_action_item.extra_data = as_report 

 

if total_errors and total_warnings: 

short_report = '{} error{} and {} warning{}'.format( 

total_errors, 

's' if total_errors > 1 else '', 

total_warnings, 

's' if total_warnings > 1 else '') 

elif total_errors: 

short_report = '{} error{}'.format( 

total_errors, 

's' if total_errors > 1 else '') 

861 ↛ 866line 861 didn't jump to line 866 elif total_warnings: 

short_report = '{} warning{}'.format( 

total_warnings, 

's' if total_warnings > 1 else '') 

 

appstream_action_item.short_description = \ 

self.ITEM_DESCRIPTION.format(report=short_report) 

 

# If there are errors make the item a high severity issue; 

# otherwise, make sure to set the severity as normal in case the item 

# existed already 

if total_errors: 

appstream_action_item.severity = ActionItem.SEVERITY_HIGH 

else: 

appstream_action_item.severity = ActionItem.SEVERITY_NORMAL 

 

appstream_action_item.save() 

 

def execute_main(self): 

self._load_tag_severities() 

all_stats = {} 

repository = Repository.objects.get(default=True) 

arch = "amd64" 

for component in repository.components: 

self._load_appstream_hint_stats(component, arch, all_stats) 

886 ↛ 887line 886 didn't jump to line 887, because the condition on line 886 was never true if not all_stats: 

return 

 

with transaction.atomic(): 

# Delete obsolete data 

PackageData.objects.filter(key='appstream').delete() 

 

packages = PackageName.objects.filter(name__in=all_stats.keys()) 

packages.prefetch_related('action_items') 

 

stats = [] 

for package in packages: 

package_stats = all_stats[package.name] 

stats.append( 

PackageData( 

package=package, 

key='appstream', 

value=package_stats 

) 

) 

 

# Create an ActionItem if there are errors or warnings 

self.update_action_item(package, package_stats) 

 

PackageData.objects.bulk_create(stats) 

# Remove action items for packages which no longer have associated 

# AppStream hints. 

ActionItem.objects.delete_obsolete_items( 

[self.appstream_action_item_type], all_stats.keys()) 

 

 

class UpdateTransitionsTask(BaseTask): 

 

class Scheduler(IntervalScheduler): 

interval = 3600 

 

REJECT_LIST_URL = 'https://ftp-master.debian.org/transitions.yaml' 

PACKAGE_TRANSITION_LIST_URL = ( 

'https://release.debian.org/transitions/export/packages.yaml') 

 

def _get_yaml_resource(self, url, **kwargs): 

""" 

Gets the YAML resource at the given URL and returns it as a Python 

object. 

""" 

content = get_resource_text(url, **kwargs) 

if content: 

return yaml.safe_load(content) 

 

def _add_reject_transitions(self, packages): 

""" 

Adds the transitions which cause uploads to be rejected to the 

given ``packages`` dict. 

""" 

reject_list = self._get_yaml_resource(self.REJECT_LIST_URL) 

for key, transition in reject_list.items(): 

for package in transition['packages']: 

packages.setdefault(package, {}) 

packages[package].setdefault(key, {}) 

packages[package][key]['reject'] = True 

packages[package][key]['status'] = 'ongoing' 

 

def _add_package_transition_list(self, packages): 

""" 

Adds the ongoing and planned transitions to the given ``packages`` 

dict. 

""" 

package_transition_list = self._get_yaml_resource( 

self.PACKAGE_TRANSITION_LIST_URL) 

 

wanted_transition_statuses = ('ongoing', 'planned') 

for package_info in package_transition_list: 

package_name = package_info['name'] 

for transition_name, status in package_info['list']: 

if status not in wanted_transition_statuses: 

# Skip transitions with an unwanted status 

continue 

 

packages.setdefault(package_name, {}) 

packages[package_name].setdefault(transition_name, {}) 

packages[package_name][transition_name]['status'] = status 

 

def execute_main(self): 

# Update the relevant resources first 

kwargs = { 

'force_update': self.force_update, 

'only_if_updated': True, 

} 

reject_list = self._get_yaml_resource(self.REJECT_LIST_URL, **kwargs) 

package_transition_list = self._get_yaml_resource( 

self.PACKAGE_TRANSITION_LIST_URL, **kwargs) 

 

if reject_list is None and package_transition_list is None: 

# Nothing to do - at least one needs to be updated... 

return 

 

package_transitions = {} 

self._add_reject_transitions(package_transitions) 

self._add_package_transition_list(package_transitions) 

 

PackageTransition.objects.all().delete() 

# Get the packages which have transitions 

packages = PackageName.objects.filter( 

name__in=package_transitions.keys()) 

transitions = [] 

for package in packages: 

for transition_name, data in \ 

package_transitions[package.name].items(): 

transitions.append(PackageTransition( 

package=package, 

transition_name=transition_name, 

status=data.get('status', None), 

reject=data.get('reject', False))) 

 

PackageTransition.objects.bulk_create(transitions) 

 

 

class UpdateExcusesTask(BaseTask): 

 

class Scheduler(IntervalScheduler): 

interval = 3600 

 

ACTION_ITEM_TYPE_NAME = 'debian-testing-migration' 

ITEM_DESCRIPTION = ( 

"The package has not entered testing even though the delay is over") 

ITEM_FULL_DESCRIPTION_TEMPLATE = 'debian/testing-migration-action-item.html' 

 

class AgeVerdict(Enum): 

PKG_OF_AGE = 0 

PKG_TOO_OLD = 1 

PKG_TOO_YOUNG = 2 

PKG_WO_POLICY = 3 

 

def initialize(self, *args, **kwargs): 

super(UpdateExcusesTask, self).initialize(*args, **kwargs) 

self.action_item_type = ActionItemType.objects.create_or_update( 

type_name=self.ACTION_ITEM_TYPE_NAME, 

full_description_template=self.ITEM_FULL_DESCRIPTION_TEMPLATE) 

 

def _adapt_excuse_links(self, excuse): 

""" 

If the excuse contains any anchor links, convert them to links to Distro 

Tracker package pages. Return the original text unmodified, otherwise. 

""" 

re_anchor_href = re.compile(r'^#(.*)$') 

html = soup(excuse, 'html.parser') 

for a_tag in html.findAll('a', {'href': True}): 

href = a_tag['href'] 

match = re_anchor_href.match(href) 

1035 ↛ 1036line 1035 didn't jump to line 1036, because the condition on line 1035 was never true if not match: 

continue 

package = match.group(1).split('/')[0] 

a_tag['href'] = package_url(package) 

 

return str(html) 

 

def _skip_excuses_item(self, item_text): 

if not item_text: 

return True 

# We ignore these excuses 

if "Section" in item_text or "Maintainer" in item_text: 

return True 

return False 

 

def _check_age(self, source): 

"""Checks the age of the package and compares it to the age requirement 

for migration""" 

 

1054 ↛ 1055line 1054 didn't jump to line 1055, because the condition on line 1054 was never true if 'policy_info' not in source or 'age' not in source['policy_info']: 

return (self.AgeVerdict.PKG_WO_POLICY, None, None) 

 

age = source['policy_info']['age']['current-age'] 

limit = source['policy_info']['age']['age-requirement'] 

if age > limit: 

return (self.AgeVerdict.PKG_TOO_OLD, age, limit) 

1061 ↛ 1062line 1061 didn't jump to line 1062, because the condition on line 1061 was never true elif age < limit: 

return (self.AgeVerdict.PKG_TOO_YOUNG, age, limit) 

else: 

return (self.AgeVerdict.PKG_OF_AGE, age, limit) 

 

def _extract_problematic(self, source): 

verdict, age, limit = self._check_age(source) 

 

if verdict == self.AgeVerdict.PKG_TOO_OLD: 

return (source['item-name'], {'age': age, 'limit': limit}) 

 

@staticmethod 

def _make_excuses_check_dependencies(source): 

"""Checks the dependencies of the package (blocked-by and 

migrate-after) and returns a list to display.""" 

 

addendum = [] 

 

if 'dependencies' in source: 

blocked_by = source['dependencies'].get('blocked-by', []) 

after = source['dependencies'].get('migrate-after', []) 

after = [ 

element 

for element in after 

if element not in blocked_by 

] 

1087 ↛ 1088line 1087 didn't jump to line 1088, because the condition on line 1087 was never true if blocked_by: 

addendum.append("Blocked by: %s" % ( 

html_package_list(blocked_by), 

)) 

1091 ↛ 1096line 1091 didn't jump to line 1096, because the condition on line 1091 was never false if after: 

addendum.append("Migrates after: %s" % ( 

html_package_list(after), 

)) 

 

return addendum 

 

@staticmethod 

def _make_excuses_check_verdict(source): 

"""Checks the migration policy verdict of the package and builds an 

excuses message depending on the result.""" 

 

addendum = [] 

 

1105 ↛ 1106line 1105 didn't jump to line 1106, because the condition on line 1105 was never true if 'migration-policy-verdict' in source: 

verdict = source['migration-policy-verdict'] 

if verdict == 'REJECTED_BLOCKED_BY_ANOTHER_ITEM': 

addendum.append("Migration status: Blocked. Can't migrate " 

"due to a non-migratable dependency. Check " 

"status below." 

) 

 

return addendum 

 

def _make_excuses(self, source): 

"""Make the excuses list for a source item using the yaml data it 

contains""" 

 

excuses = [ 

self._adapt_excuse_links(excuse) 

for excuse in source['excuses'] 

] 

 

# This is the place where we compute some additionnal 

# messages that should be added to excuses. 

addendum = [] 

 

addendum.extend(self._make_excuses_check_verdict(source)) 

addendum.extend(self._make_excuses_check_dependencies(source)) 

 

excuses = addendum + excuses 

 

1133 ↛ 1137line 1133 didn't jump to line 1137, because the condition on line 1133 was never false if 'is-candidate' in source: 

1134 ↛ 1137line 1134 didn't jump to line 1137, because the condition on line 1134 was never false if not source['is-candidate']: 

excuses.append("Not considered") 

 

return ( 

source['item-name'], 

excuses, 

) 

 

def _get_excuses_and_problems(self, content): 

""" 

Gets the excuses for each package. 

Also finds a list of packages which have not migrated to testing 

agter the necessary time has passed. 

 

:returns: A two-tuple where the first element is a dict mapping 

package names to a list of excuses. The second element is a dict 

mapping packages names to a problem information. Problem information 

is a dict with the keys ``age`` and ``limit``. 

""" 

1153 ↛ 1154line 1153 didn't jump to line 1154, because the condition on line 1153 was never true if 'sources' not in content: 

logger.warning("Invalid format of excuses file") 

return 

 

sources = content['sources'] 

excuses = [ 

self._make_excuses(source) 

for source in sources 

if '/' not in source['item-name'] 

] 

problems = [ 

self._extract_problematic(source) 

for source in sources 

if '/' not in source['item-name'] 

] 

problematic = [p for p in problems if p] 

return dict(excuses), dict(problematic) 

 

def _create_action_item(self, package, extra_data): 

""" 

Creates a :class:`distro_tracker.core.models.ActionItem` for the given 

package including the given extra data. The item indicates that there is 

a problem with the package migrating to testing. 

""" 

action_item = \ 

package.get_action_item_for_type(self.ACTION_ITEM_TYPE_NAME) 

if action_item is None: 

action_item = ActionItem( 

package=package, 

item_type=self.action_item_type) 

 

action_item.short_description = self.ITEM_DESCRIPTION 

1185 ↛ 1186line 1185 didn't jump to line 1186, because the condition on line 1185 was never true if package.main_entry: 

query_string = urlencode({'package': package.name}) 

extra_data['check_why_url'] = ( 

'https://qa.debian.org/excuses.php' 

'?{query_string}'.format(query_string=query_string)) 

 

action_item.extra_data = extra_data 

action_item.save() 

 

def _remove_obsolete_action_items(self, problematic): 

""" 

Remove action items for packages which are no longer problematic. 

""" 

ActionItem.objects.delete_obsolete_items( 

item_types=[self.action_item_type], 

non_obsolete_packages=problematic.keys()) 

 

def _get_excuses_yaml(self): 

""" 

Function returning the content of excuses from debian-release 

:returns: a dict of excuses or ``None`` if the content in the 

cache is up to date. 

""" 

url = 'https://release.debian.org/britney/excuses.yaml' 

content = get_resource_text(url, force_update=self.force_update, 

only_if_updated=True) 

if content is None: 

return 

 

return yaml.safe_load(content) 

 

def execute_main(self): 

content_lines = self._get_excuses_yaml() 

1218 ↛ 1219line 1218 didn't jump to line 1219, because the condition on line 1218 was never true if not content_lines: 

return 

 

result = self._get_excuses_and_problems(content_lines) 

1222 ↛ 1223line 1222 didn't jump to line 1223, because the condition on line 1222 was never true if not result: 

return 

package_excuses, problematic = result 

 

# Remove stale excuses data and action items which are not still 

# problematic. 

self._remove_obsolete_action_items(problematic) 

PackageExcuses.objects.all().delete() 

 

excuses = [] 

packages = SourcePackageName.objects.filter( 

name__in=package_excuses.keys()) 

packages.prefetch_related('action_items') 

for package in packages: 

excuse = PackageExcuses( 

package=package, 

excuses=package_excuses[package.name]) 

excuses.append(excuse) 

if package.name in problematic: 

self._create_action_item(package, problematic[package.name]) 

 

# Create all excuses in a single query 

PackageExcuses.objects.bulk_create(excuses) 

 

 

class UpdateBuildLogCheckStats(BaseTask): 

 

class Scheduler(IntervalScheduler): 

interval = 3600 * 6 

 

ACTION_ITEM_TYPE_NAME = 'debian-build-logcheck' 

ITEM_DESCRIPTION = 'Build log checks report <a href="{url}">{report}</a>' 

ITEM_FULL_DESCRIPTION_TEMPLATE = 'debian/logcheck-action-item.html' 

 

def initialize(self, *args, **kwargs): 

super(UpdateBuildLogCheckStats, self).initialize(*args, **kwargs) 

self.action_item_type = ActionItemType.objects.create_or_update( 

type_name=self.ACTION_ITEM_TYPE_NAME, 

full_description_template=self.ITEM_FULL_DESCRIPTION_TEMPLATE) 

 

def _get_buildd_content(self): 

url = 'https://qa.debian.org/bls/logcheck.txt' 

return get_resource_text(url) 

 

def get_buildd_stats(self): 

content = self._get_buildd_content() 

stats = {} 

for line in content.splitlines(): 

pkg, errors, warnings = line.split("|")[:3] 

try: 

errors, warnings = int(errors), int(warnings) 

except ValueError: 

continue 

stats[pkg] = { 

'errors': errors, 

'warnings': warnings, 

} 

return stats 

 

def create_action_item(self, package, stats): 

""" 

Creates a :class:`distro_tracker.core.models.ActionItem` instance for 

the given package if the build logcheck stats indicate 

""" 

action_item = \ 

package.get_action_item_for_type(self.ACTION_ITEM_TYPE_NAME) 

 

errors = stats.get('errors', 0) 

warnings = stats.get('warnings', 0) 

 

if not errors and not warnings: 

# Remove the previous action item since the package no longer has 

# errors/warnings. 

if action_item is not None: 

action_item.delete() 

return 

 

if action_item is None: 

action_item = ActionItem( 

package=package, 

item_type=self.action_item_type) 

 

if action_item.extra_data: 

1305 ↛ 1309line 1305 didn't jump to line 1309, because the condition on line 1305 was never false if action_item.extra_data == stats: 

# Nothing has changed -- do not update the item 

return 

 

logcheck_url = "https://qa.debian.org/bls/packages/{hash}/{pkg}.html"\ 

.format(hash=package.name[0], pkg=package.name) 

if errors and warnings: 

report = '{} error{} and {} warning{}'.format( 

errors, 

's' if errors > 1 else '', 

warnings, 

's' if warnings > 1 else '') 

action_item.severity = ActionItem.SEVERITY_HIGH 

elif errors: 

report = '{} error{}'.format( 

errors, 

's' if errors > 1 else '') 

action_item.severity = ActionItem.SEVERITY_HIGH 

1323 ↛ 1329line 1323 didn't jump to line 1329, because the condition on line 1323 was never false elif warnings: 

report = '{} warning{}'.format( 

warnings, 

's' if warnings > 1 else '') 

action_item.severity = ActionItem.SEVERITY_LOW 

 

action_item.short_description = self.ITEM_DESCRIPTION.format( 

url=logcheck_url, 

report=report) 

action_item.extra_data = stats 

action_item.save() 

 

def execute_main(self): 

# Build a dict with stats from both buildd and clang 

stats = self.get_buildd_stats() 

 

BuildLogCheckStats.objects.all().delete() 

ActionItem.objects.delete_obsolete_items( 

[self.action_item_type], stats.keys()) 

 

packages = SourcePackageName.objects.filter(name__in=stats.keys()) 

packages = packages.prefetch_related('action_items') 

 

logcheck_stats = [] 

for package in packages: 

logcheck_stat = BuildLogCheckStats( 

package=package, 

stats=stats[package.name]) 

logcheck_stats.append(logcheck_stat) 

 

self.create_action_item(package, stats[package.name]) 

 

# One SQL query to create all the stats. 

BuildLogCheckStats.objects.bulk_create(logcheck_stats) 

 

 

class DebianWatchFileScannerUpdate(BaseTask): 

 

class Scheduler(IntervalScheduler): 

interval = 3600 * 6 

 

ACTION_ITEM_TYPE_NAMES = ( 

'new-upstream-version', 

'watch-failure', 

) 

ACTION_ITEM_TEMPLATES = { 

'new-upstream-version': "debian/new-upstream-version-action-item.html", 

'watch-failure': "debian/watch-failure-action-item.html", 

} 

ITEM_DESCRIPTIONS = { 

'new-upstream-version': lambda item: ( 

'A new upstream version is available: ' 

'<a href="{url}">{version}</a>'.format( 

url=item.extra_data['upstream_url'], 

version=item.extra_data['upstream_version'])), 

'watch-failure': lambda item: ( 

'Problems while searching for a new upstream version'), 

} 

ITEM_SEVERITIES = { 

'new-upstream-version': ActionItem.SEVERITY_HIGH, 

'watch-failure': ActionItem.SEVERITY_HIGH, 

} 

 

def initialize(self, *args, **kwargs): 

super(DebianWatchFileScannerUpdate, self).initialize(*args, **kwargs) 

self.action_item_types = { 

type_name: ActionItemType.objects.create_or_update( 

type_name=type_name, 

full_description_template=self.ACTION_ITEM_TEMPLATES.get( 

type_name, None)) 

for type_name in self.ACTION_ITEM_TYPE_NAMES 

} 

 

def _get_upstream_status_content(self): 

url = 'https://udd.debian.org/cgi-bin/upstream-status.json.cgi' 

return get_resource_text(url) 

 

def _remove_obsolete_action_items(self, item_type_name, 

non_obsolete_packages): 

""" 

Removes any existing :class:`ActionItem` with the given type name based 

on the list of package names which should still have the items based on 

the processed stats. 

""" 

action_item_type = self.action_item_types[item_type_name] 

ActionItem.objects.delete_obsolete_items( 

item_types=[action_item_type], 

non_obsolete_packages=non_obsolete_packages) 

 

def get_upstream_status_stats(self, stats): 

""" 

Gets the stats from the downloaded data and puts them in the given 

``stats`` dictionary. 

The keys of the dict are package names. 

 

:returns: A a two-tuple where the first item is a list of packages 

which have new upstream versions and the second is a list of 

packages which have watch failures. 

""" 

content = self._get_upstream_status_content() 

dehs_data = None 

if content: 

dehs_data = json.loads(content) 

if not dehs_data: 

return [], [] 

 

all_new_versions, all_failures = [], [] 

for entry in dehs_data: 

package_name = entry['package'] 

stats.setdefault(package_name, {}) 

stats[package_name]['upstream_version'] = entry['upstream-version'] 

stats[package_name]['upstream_url'] = entry['upstream-url'] 

if 'status' in entry and ('Newer version' in entry['status'] or 

'newer package' in entry['status']): 

stats[package_name]['new-upstream-version'] = { 

'upstream_version': entry['upstream-version'], 

'upstream_url': entry['upstream-url'], 

} 

all_new_versions.append(package_name) 

if entry.get('warnings') or entry.get('errors'): 

msg = '{}\n{}'.format( 

entry.get('errors') or '', 

entry.get('warnings') or '', 

).strip() 

stats[package_name]['watch-failure'] = { 

'warning': msg, 

} 

all_failures.append(package_name) 

 

return all_new_versions, all_failures 

 

def update_package_info(self, package, stats): 

""" 

Updates upstream information of the given package based on the given 

stats. Upstream data is saved as a :class:`PackageData` within the 

`general` key 

 

:param package: The package to which the upstream info should be 

associated. 

:type package: :class:`distro_tracker.core.models.PackageName` 

:param stats: The stats which are used to create the upstream info. 

:type stats: :class:`dict` 

""" 

try: 

watch_data = package.watch_status[0] 

except IndexError: 

watch_data = PackageData( 

package=package, 

key='upstream-watch-status', 

) 

 

watch_data.value = stats 

watch_data.save() 

 

def update_action_item(self, item_type, package, stats): 

""" 

Updates the action item of the given type for the given package based 

on the given stats. 

 

The severity of the item is defined by the :attr:`ITEM_SEVERITIES` dict. 

 

The short descriptions are created by passing the :class:`ActionItem` 

(with extra data already set) to the callables defined in 

:attr:`ITEM_DESCRIPTIONS`. 

 

:param item_type: The type of the :class:`ActionItem` that should be 

updated. 

:type item_type: string 

:param package: The package to which this action item should be 

associated. 

:type package: :class:`distro_tracker.core.models.PackageName` 

:param stats: The stats which are used to create the action item. 

:type stats: :class:`dict` 

""" 

action_item = package.get_action_item_for_type(item_type) 

if action_item is None: 

# Create an action item... 

action_item = ActionItem( 

package=package, 

item_type=self.action_item_types[item_type]) 

 

1504 ↛ 1506line 1504 didn't jump to line 1506, because the condition on line 1504 was never false if item_type in self.ITEM_SEVERITIES: 

action_item.severity = self.ITEM_SEVERITIES[item_type] 

action_item.extra_data = stats 

action_item.short_description = \ 

self.ITEM_DESCRIPTIONS[item_type](action_item) 

 

action_item.save() 

 

@transaction.atomic 

def execute_main(self): 

stats = {} 

new_upstream_version, failures = self.get_upstream_status_stats(stats) 

updated_packages_per_type = { 

'new-upstream-version': new_upstream_version, 

'watch-failure': failures, 

} 

 

# Remove obsolete action items for each of the categories... 

for item_type, packages in updated_packages_per_type.items(): 

self._remove_obsolete_action_items(item_type, packages) 

 

packages = SourcePackageName.objects.filter( 

name__in=stats.keys()) 

filter_qs = PackageData.objects.filter(key='upstream-watch-status') 

packages = packages.prefetch_related( 

'action_items', 

Prefetch('data', queryset=filter_qs, to_attr='watch_status') 

) 

 

# Update action items for each package 

for package in packages: 

for type_name in self.ACTION_ITEM_TYPE_NAMES: 

if type_name in stats[package.name]: 

# method(package, stats[package.name][type_name]) 

self.update_action_item( 

type_name, package, stats[package.name][type_name]) 

 

self.update_package_info(package, stats[package.name]) 

 

 

class UpdateSecurityIssuesTask(BaseTask): 

 

class Scheduler(IntervalScheduler): 

interval = 3600 * 3 

 

ACTION_ITEM_TYPE_NAME = 'debian-security-issue-in-{}' 

ACTION_ITEM_TEMPLATE = 'debian/security-issue-action-item.html' 

ITEM_DESCRIPTION_TEMPLATE = { 

'open': '<a href="{url}">{count} security {issue}</a> in {release}', 

'nodsa': 

'<a href="{url}">{count} ignored security {issue}</a> in {release}', 

'none': 'No known security issue in {release}', 

} 

 

def initialize(self, *args, **kwargs): 

super(UpdateSecurityIssuesTask, self).initialize(*args, **kwargs) 

self._action_item_type = {} 

self._content = None 

 

def action_item_type(self, release): 

return self._action_item_type.setdefault( 

release, ActionItemType.objects.create_or_update( 

type_name=self.ACTION_ITEM_TYPE_NAME.format(release), 

full_description_template=self.ACTION_ITEM_TEMPLATE)) 

 

def _get_issues_content(self): 

if self._content: 

return self._content 

url = 'https://security-tracker.debian.org/tracker/data/json' 

content = get_resource_text(url) 

if content: 

self._content = json.loads(content) 

return self._content 

 

@staticmethod 

def get_issues_summary(issues): 

result = {} 

for issue_id, issue_data in issues.items(): 

for release, data in issue_data['releases'].items(): 

stats = result.setdefault(release, { 

'open': 0, 

'open_details': {}, 

'nodsa': 0, 

'nodsa_details': {}, 

'unimportant': 0, 

}) 

if (data.get('status', '') == 'resolved' or 

data.get('urgency', '') == 'end-of-life'): 

continue 

elif data.get('urgency', '') == 'unimportant': 

stats['unimportant'] += 1 

elif data.get('nodsa', False): 

stats['nodsa'] += 1 

stats['nodsa_details'][issue_id] = \ 

issue_data.get('description', '') 

else: 

stats['open'] += 1 

stats['open_details'][issue_id] = \ 

issue_data.get('description', '') 

return result 

 

@classmethod 

def get_issues_stats(cls, content): 

""" 

Gets package issue stats from Debian's security tracker. 

""" 

stats = {} 

for pkg, issues in content.items(): 

stats[pkg] = cls.get_issues_summary(issues) 

return stats 

 

def _get_short_description(self, key, action_item): 

count = action_item.extra_data['security_issues_count'] 

url = 'https://security-tracker.debian.org/tracker/source-package/{}' 

return self.ITEM_DESCRIPTION_TEMPLATE[key].format( 

count=count, 

issue='issues' if count > 1 else 'issue', 

release=action_item.extra_data.get('release', 'sid'), 

url=url.format(action_item.package.name), 

) 

 

def update_action_item(self, stats, action_item): 

""" 

Updates the ``debian-security-issue`` action item based on the count of 

security issues. 

""" 

security_issues_count = stats['open'] + stats['nodsa'] 

action_item.extra_data['security_issues_count'] = security_issues_count 

action_item.extra_data['open_details'] = stats['open_details'] 

action_item.extra_data['nodsa_details'] = stats['nodsa_details'] 

if stats['open']: 

action_item.severity = ActionItem.SEVERITY_HIGH 

action_item.short_description = \ 

self._get_short_description('open', action_item) 

1638 ↛ 1643line 1638 didn't jump to line 1643, because the condition on line 1638 was never false elif stats['nodsa']: 

action_item.severity = ActionItem.SEVERITY_LOW 

action_item.short_description = \ 

self._get_short_description('nodsa', action_item) 

else: 

action_item.severity = ActionItem.SEVERITY_WISHLIST 

action_item.short_description = \ 

self._get_short_description('none', action_item) 

 

@classmethod 

def generate_package_data(cls, issues): 

return { 

'details': issues, 

'stats': cls.get_issues_summary(issues), 

'checksum': get_data_checksum(issues) 

} 

 

def process_pkg_action_items(self, pkgdata, existing_action_items): 

release_ai = {} 

to_add = [] 

to_update = [] 

to_drop = [] 

global_stats = pkgdata.value.get('stats', {}) 

for ai in existing_action_items: 

release = ai.extra_data['release'] 

release_ai[release] = ai 

1664 ↛ 1665line 1664 didn't jump to line 1665, because the condition on line 1664 was never true if release not in global_stats: 

to_drop.append(ai) 

for release, stats in global_stats.items(): 

count = stats.get('open', 0) + stats.get('nodsa', 0) 

if release in release_ai: 

ai = release_ai[release] 

if count == 0: 

to_drop.append(ai) 

else: 

self.update_action_item(stats, ai) 

to_update.append(ai) 

elif count > 0: 

new_ai = ActionItem(item_type=self.action_item_type(release), 

package=pkgdata.package, 

extra_data={'release': release}) 

self.update_action_item(stats, new_ai) 

to_add.append(new_ai) 

return to_add, to_update, to_drop 

 

def execute_main(self): 

# Fetch all debian-security PackageData 

all_pkgdata = PackageData.objects.select_related( 

'package').filter(key='debian-security').only( 

'package__name', 'value') 

 

all_data = {} 

packages = {} 

for pkgdata in all_pkgdata: 

all_data[pkgdata.package.name] = pkgdata 

packages[pkgdata.package.name] = pkgdata.package 

# Fetch all debian-security ActionItems 

pkg_action_items = collections.defaultdict(lambda: []) 

all_action_items = ActionItem.objects.select_related( 

'package').filter( 

item_type__type_name__startswith='debian-security-issue-in-') 

for action_item in all_action_items: 

pkg_action_items[action_item.package.name].append(action_item) 

# Scan the security tracker data 

content = self._get_issues_content() 

to_add = [] 

to_update = [] 

for pkgname, issues in content.items(): 

if pkgname in all_data: 

# Check if we need to update the existing data 

checksum = get_data_checksum(issues) 

if all_data[pkgname].value.get('checksum', '') == checksum: 

continue 

# Update the data 

pkgdata = all_data[pkgname] 

pkgdata.value = self.generate_package_data(issues) 

to_update.append(pkgdata) 

else: 

# Add data for a new package 

package, _ = PackageName.objects.get_or_create(name=pkgname) 

to_add.append( 

PackageData( 

package=package, 

key='debian-security', 

value=self.generate_package_data(issues) 

) 

) 

# Process action items 

ai_to_add = [] 

ai_to_update = [] 

ai_to_drop = [] 

for pkgdata in itertools.chain(to_add, to_update): 

add, update, drop = self.process_pkg_action_items( 

pkgdata, pkg_action_items[pkgdata.package.name]) 

ai_to_add.extend(add) 

ai_to_update.extend(update) 

ai_to_drop.extend(drop) 

# Sync in database 

with transaction.atomic(): 

# Delete obsolete data 

PackageData.objects.filter( 

key='debian-security').exclude( 

package__name__in=content.keys()).delete() 

ActionItem.objects.filter( 

item_type__type_name__startswith='debian-security-issue-in-' 

).exclude(package__name__in=content.keys()).delete() 

ActionItem.objects.filter( 

item_type__type_name__startswith='debian-security-issue-in-', 

id__in=[ai.id for ai in ai_to_drop]).delete() 

# Add new entries 

PackageData.objects.bulk_create(to_add) 

ActionItem.objects.bulk_create(ai_to_add) 

# Update existing entries 

for pkgdata in to_update: 

pkgdata.save() 

for ai in ai_to_update: 

ai.save() 

 

 

class UpdatePiuPartsTask(BaseTask): 

""" 

Retrieves the piuparts stats for all the suites defined in the 

:data:`distro_tracker.project.local_settings.DISTRO_TRACKER_DEBIAN_PIUPARTS_SUITES` 

""" 

 

class Scheduler(IntervalScheduler): 

interval = 3600 * 3 

 

ACTION_ITEM_TYPE_NAME = 'debian-piuparts-test-fail' 

ACTION_ITEM_TEMPLATE = 'debian/piuparts-action-item.html' 

ITEM_DESCRIPTION = 'piuparts found (un)installation error(s)' 

 

def initialize(self, *args, **kwargs): 

super(UpdatePiuPartsTask, self).initialize(*args, **kwargs) 

self.action_item_type = ActionItemType.objects.create_or_update( 

type_name=self.ACTION_ITEM_TYPE_NAME, 

full_description_template=self.ACTION_ITEM_TEMPLATE) 

 

def _get_piuparts_content(self, suite): 

""" 

:returns: The content of the piuparts report for the given package 

or ``None`` if there is no data for the particular suite. 

""" 

url = 'https://piuparts.debian.org/{suite}/sources.txt' 

return get_resource_text(url.format(suite=suite)) 

 

def get_piuparts_stats(self): 

suites = getattr(settings, 'DISTRO_TRACKER_DEBIAN_PIUPARTS_SUITES', []) 

failing_packages = {} 

for suite in suites: 

content = self._get_piuparts_content(suite) 

if content is None: 

logger.info("There is no piuparts for suite: %s", suite) 

continue 

 

for line in content.splitlines(): 

package_name, status = line.split(':', 1) 

package_name, status = package_name.strip(), status.strip() 

if status == 'fail': 

failing_packages.setdefault(package_name, []) 

failing_packages[package_name].append(suite) 

 

return failing_packages 

 

def create_action_item(self, package, suites): 

""" 

Creates an :class:`ActionItem <distro_tracker.core.models.ActionItem>` 

instance for the package based on the list of suites in which the 

piuparts installation test failed. 

""" 

action_item = package.get_action_item_for_type(self.action_item_type) 

if action_item is None: 

action_item = ActionItem( 

package=package, 

item_type=self.action_item_type, 

short_description=self.ITEM_DESCRIPTION) 

 

if action_item.extra_data: 

existing_items = action_item.extra_data.get('suites', []) 

if list(sorted(existing_items)) == list(sorted(suites)): 

# No need to update this item 

return 

action_item.extra_data = { 

'suites': suites, 

} 

action_item.save() 

 

def execute_main(self): 

failing_packages = self.get_piuparts_stats() 

 

ActionItem.objects.delete_obsolete_items( 

item_types=[self.action_item_type], 

non_obsolete_packages=failing_packages.keys()) 

 

packages = SourcePackageName.objects.filter( 

name__in=failing_packages.keys()) 

packages = packages.prefetch_related('action_items') 

 

for package in packages: 

self.create_action_item(package, failing_packages[package.name]) 

 

 

class UpdateUbuntuStatsTask(BaseTask): 

""" 

The task updates Ubuntu stats for packages. These stats are displayed in a 

separate panel. 

""" 

 

class Scheduler(IntervalScheduler): 

interval = 3600 * 3 

 

def initialize(self, *args, **kwargs): 

super(UpdateUbuntuStatsTask, self).initialize(*args, **kwargs) 

 

def _get_versions_content(self): 

url = 'https://udd.debian.org/cgi-bin/ubuntupackages.cgi' 

return get_resource_text(url) 

 

def get_ubuntu_versions(self): 

""" 

Retrieves the Ubuntu package versions. 

 

:returns: A dict mapping package names to Ubuntu versions. 

""" 

content = self._get_versions_content() 

 

package_versions = {} 

for line in content.splitlines(): 

package, version = line.split(' ', 1) 

version = version.strip() 

package_versions[package] = version 

 

return package_versions 

 

def _get_bug_stats_content(self): 

url = 'https://udd.debian.org/cgi-bin/ubuntubugs.cgi' 

return get_resource_text(url) 

 

def get_ubuntu_bug_stats(self): 

""" 

Retrieves the Ubuntu bug stats of a package. Bug stats contain the 

count of bugs and the count of patches. 

 

:returns: A dict mapping package names to a dict of package stats. 

""" 

content = self._get_bug_stats_content() 

 

bug_stats = {} 

for line in content.splitlines(): 

package_name, bug_count, patch_count = line.split("|", 2) 

try: 

bug_count, patch_count = int(bug_count), int(patch_count) 

except ValueError: 

continue 

bug_stats[package_name] = { 

'bug_count': bug_count, 

'patch_count': patch_count, 

} 

 

return bug_stats 

 

def _get_ubuntu_patch_diff_content(self): 

url = 'https://patches.ubuntu.com/PATCHES' 

return get_resource_text(url) 

 

def get_ubuntu_patch_diffs(self): 

""" 

Retrieves the Ubuntu patch diff information. The information consists 

of the diff URL and the version of the Ubuntu package to which the 

diff belongs to. 

 

:returns: A dict mapping package names to diff information. 

""" 

content = self._get_ubuntu_patch_diff_content() 

 

patch_diffs = {} 

re_diff_version = re.compile(r'_(\S+)\.patch') 

for line in content.splitlines(): 

package_name, diff_url = line.split(' ', 1) 

# Extract the version of the package from the diff url 

match = re_diff_version.search(diff_url) 

1919 ↛ 1921line 1919 didn't jump to line 1921, because the condition on line 1919 was never true if not match: 

# Invalid URL: no version 

continue 

version = match.group(1) 

patch_diffs[package_name] = { 

'version': version, 

'diff_url': diff_url 

} 

 

return patch_diffs 

 

def execute_main(self): 

package_versions = self.get_ubuntu_versions() 

bug_stats = self.get_ubuntu_bug_stats() 

patch_diffs = self.get_ubuntu_patch_diffs() 

 

obsolete_ubuntu_pkgs = UbuntuPackage.objects.exclude( 

package__name__in=package_versions.keys()) 

obsolete_ubuntu_pkgs.delete() 

 

packages = PackageName.objects.filter(name__in=package_versions.keys()) 

packages = packages.prefetch_related('ubuntu_package') 

 

for package in packages: 

version = package_versions[package.name] 

bugs = bug_stats.get(package.name, None) 

diff = patch_diffs.get(package.name, None) 

 

try: 

ubuntu_package = package.ubuntu_package 

ubuntu_package.version = version 

ubuntu_package.bugs = bugs 

ubuntu_package.patch_diff = diff 

ubuntu_package.save() 

except UbuntuPackage.DoesNotExist: 

ubuntu_package = UbuntuPackage.objects.create( 

package=package, 

version=version, 

bugs=bugs, 

patch_diff=diff) 

 

 

class UpdateWnppStatsTask(BaseTask): 

""" 

The task updates the WNPP bugs for all packages. 

""" 

 

class Scheduler(IntervalScheduler): 

interval = 3600 * 3 

 

ACTION_ITEM_TYPE_NAME = 'debian-wnpp-issue' 

ACTION_ITEM_TEMPLATE = 'debian/wnpp-action-item.html' 

ITEM_DESCRIPTION = '<a href="{url}">{wnpp_type}: {wnpp_msg}</a>' 

 

def initialize(self, *args, **kwargs): 

super(UpdateWnppStatsTask, self).initialize(*args, **kwargs) 

self.action_item_type = ActionItemType.objects.create_or_update( 

type_name=self.ACTION_ITEM_TYPE_NAME, 

full_description_template=self.ACTION_ITEM_TEMPLATE) 

 

def get_wnpp_stats(self): 

""" 

Retrieves and parses the wnpp stats for all packages. WNPP stats 

include the WNPP type and the BTS bug id. 

 

:returns: A dict mapping package names to wnpp stats. 

""" 

url = 'https://qa.debian.org/data/bts/wnpp_rm' 

content = get_resource_text(url, only_if_updated=True) 

1988 ↛ 1989line 1988 didn't jump to line 1989, because the condition on line 1988 was never true if content is None: 

return 

 

wnpp_stats = {} 

for line in content.splitlines(): 

line = line.strip() 

try: 

package_name, wnpp_type, bug_id = line.split('|')[0].split() 

bug_id = int(bug_id) 

except ValueError: 

# Badly formatted bug number 

continue 

# Strip the colon from the end of the package name 

package_name = package_name[:-1] 

 

wnpp_stats[package_name] = { 

'wnpp_type': wnpp_type, 

'bug_id': bug_id, 

} 

 

return wnpp_stats 

 

def update_action_item(self, package, stats): 

""" 

Creates an :class:`ActionItem <distro_tracker.core.models.ActionItem>` 

instance for the given type indicating that the package has a WNPP 

issue. 

""" 

action_item = package.get_action_item_for_type(self.action_item_type) 

if not action_item: 

action_item = ActionItem( 

package=package, 

item_type=self.action_item_type) 

 

# Check if the stats have actually been changed 

if action_item.extra_data: 

if action_item.extra_data.get('wnpp_info', None) == stats: 

# Nothing to do -- stll the same data 

return 

 

# Update the data since something has changed 

try: 

release = package.main_entry.repository.suite or \ 

package.main_entry.repository.codename 

except AttributeError: 

release = None 

 

msgs = { 

'O': "This package has been orphaned and needs a maintainer.", 

'ITA': "Someone intends to adopt this package.", 

'RFA': "The maintainer wants to pass over package maintainance.", 

'RFH': "The maintainer is looking for help with this package.", 

'ITP': "Someone is planning to reintroduce this package.", 

'RFP': "There is a request to reintroduce this package.", 

'RM': "This package has been requested to be removed.", 

'RFS': "A sponsor is needed to update this package.", 

'?': "The WNPP database contains an entry for this package." 

} 

wnpp_type = stats['wnpp_type'] 

try: 

wnpp_msg = msgs[wnpp_type] 

except KeyError: 

wnpp_msg = msgs['?'] 

 

action_item.short_description = self.ITEM_DESCRIPTION.format( 

url='https://bugs.debian.org/{}'.format(stats['bug_id']), 

wnpp_type=wnpp_type, wnpp_msg=wnpp_msg) 

action_item.extra_data = { 

'wnpp_info': stats, 

'release': release, 

} 

action_item.save() 

 

def update_depneedsmaint_action_item(self, package_needs_maintainer, stats): 

short_description_template = \ 

'Depends on packages which need a new maintainer' 

package_needs_maintainer.get_absolute_url() 

action_item_type = ActionItemType.objects.create_or_update( 

type_name='debian-depneedsmaint', 

full_description_template='debian/depneedsmaint-action-item.html') 

dependencies = SourcePackageDeps.objects.filter( 

dependency=package_needs_maintainer) 

2070 ↛ 2071line 2070 didn't jump to line 2071, because the loop on line 2070 never started for dependency in dependencies: 

package = dependency.source 

action_item = package.get_action_item_for_type(action_item_type) 

if not action_item: 

action_item = ActionItem( 

package=package, 

item_type=action_item_type, 

extra_data={}) 

 

pkgdata = { 

'bug': stats['bug_id'], 

'details': dependency.details, 

} 

 

if (action_item.extra_data.get(package_needs_maintainer.name, {}) == 

pkgdata): 

# Nothing has changed 

continue 

 

action_item.short_description = short_description_template 

action_item.extra_data[package_needs_maintainer.name] = pkgdata 

 

action_item.save() 

 

@transaction.atomic 

def execute_main(self): 

wnpp_stats = self.get_wnpp_stats() 

2097 ↛ 2099line 2097 didn't jump to line 2099, because the condition on line 2097 was never true if wnpp_stats is None: 

# Nothing to do: cached content up to date 

return 

 

ActionItem.objects.delete_obsolete_items( 

item_types=[self.action_item_type], 

non_obsolete_packages=wnpp_stats.keys()) 

# Remove obsolete action items for packages whose dependencies need a 

# new maintainer. 

packages_need_maintainer = [] 

for name, stats in wnpp_stats.items(): 

if stats['wnpp_type'] in ('O', 'RFA'): 

packages_need_maintainer.append(name) 

packages_depneeds_maint = [ 

package.name for package in SourcePackageName.objects.filter( 

source_dependencies__dependency__name__in=packages_need_maintainer) # noqa 

] 

ActionItem.objects.delete_obsolete_items( 

item_types=[ 

ActionItemType.objects.get_or_create( 

type_name='debian-depneedsmaint')[0], 

], 

non_obsolete_packages=packages_depneeds_maint) 

 

# Drop all reverse references 

2122 ↛ 2124line 2122 didn't jump to line 2124, because the loop on line 2122 never started for ai in ActionItem.objects.filter( 

item_type__type_name='debian-depneedsmaint'): 

ai.extra_data = {} 

ai.save() 

 

packages = SourcePackageName.objects.filter(name__in=wnpp_stats.keys()) 

packages = packages.prefetch_related('action_items') 

 

for package in packages: 

stats = wnpp_stats[package.name] 

self.update_action_item(package, stats) 

# Update action items for packages which depend on this one to 

# indicate that a dependency needs a new maintainer. 

if package.name in packages_need_maintainer: 

self.update_depneedsmaint_action_item(package, stats) 

 

 

class UpdateNewQueuePackages(BaseTask): 

""" 

Updates the versions of source packages found in the NEW queue. 

""" 

 

class Scheduler(IntervalScheduler): 

interval = 3600 

 

DATA_KEY = 'debian-new-queue-info' 

 

def initialize(self, *args, **kwargs): 

super(UpdateNewQueuePackages, self).initialize(*args, **kwargs) 

 

def extract_package_info(self, content): 

""" 

Extracts the package information from the content of the NEW queue. 

 

:returns: A dict mapping package names to a dict mapping the 

distribution name in which the package is found to the version 

information for the most recent version of the package in the dist. 

""" 

packages = {} 

for stanza in deb822.Deb822.iter_paragraphs(content.splitlines()): 

necessary_fields = ('Source', 'Queue', 'Version', 'Distribution') 

if not all(field in stanza for field in necessary_fields): 

continue 

2165 ↛ 2166line 2165 didn't jump to line 2166, because the condition on line 2165 was never true if stanza['Queue'] != 'new': 

continue 

 

versions = stanza['Version'].split() 

# Save only the most recent version 

version = max(versions, key=lambda x: AptPkgVersion(x)) 

 

package_name = stanza['Source'] 

pkginfo = packages.setdefault(package_name, {}) 

distribution = stanza['Distribution'] 

if distribution in pkginfo: 

current_version = pkginfo[distribution]['version'] 

if debian_support.version_compare(version, current_version) < 0: 

# The already saved version is more recent than this one. 

continue 

 

pkginfo[distribution] = { 

'version': version, 

} 

 

return packages 

 

def _get_new_content(self): 

url = 'https://ftp-master.debian.org/new.822' 

return get_resource_text(url, force_update=self.force_update, 

only_if_updated=True) 

 

def execute_main(self): 

content = self._get_new_content() 

2194 ↛ 2195line 2194 didn't jump to line 2195, because the condition on line 2194 was never true if content is None: 

return 

 

all_package_info = self.extract_package_info(content) 

 

packages = SourcePackageName.objects.filter( 

name__in=all_package_info.keys()) 

 

with transaction.atomic(): 

# Drop old entries 

PackageData.objects.filter(key=self.DATA_KEY).delete() 

# Prepare current entries 

data = [] 

for package in packages: 

new_queue_info = PackageData( 

key=self.DATA_KEY, 

package=package, 

value=all_package_info[package.name]) 

data.append(new_queue_info) 

# Bulk create them 

PackageData.objects.bulk_create(data) 

 

 

class UpdateAutoRemovalsStatsTask(BaseTask): 

""" 

A task for updating autoremovals information on all packages. 

""" 

 

class Scheduler(IntervalScheduler): 

interval = 3600 

 

ACTION_ITEM_TYPE_NAME = 'debian-autoremoval' 

ACTION_ITEM_TEMPLATE = 'debian/autoremoval-action-item.html' 

ITEM_DESCRIPTION = ('Marked for autoremoval on {removal_date}' + 

'{dependencies}: {bugs}') 

 

def initialize(self, *args, **kwargs): 

super(UpdateAutoRemovalsStatsTask, self).initialize(*args, **kwargs) 

self.action_item_type = ActionItemType.objects.create_or_update( 

type_name=self.ACTION_ITEM_TYPE_NAME, 

full_description_template=self.ACTION_ITEM_TEMPLATE) 

 

def get_autoremovals_stats(self): 

""" 

Retrieves and parses the autoremoval stats for all packages. 

Autoremoval stats include the BTS bugs id. 

 

:returns: A dict mapping package names to autoremoval stats. 

""" 

content = get_resource_text( 

'https://udd.debian.org/cgi-bin/autoremovals.yaml.cgi', 

force_update=self.force_update, 

only_if_updated=True 

) 

2248 ↛ exitline 2248 didn't return from function 'get_autoremovals_stats', because the condition on line 2248 was never false if content: 

return yaml.safe_load(content) 

 

def update_action_item(self, package, stats): 

""" 

Creates an :class:`ActionItem <distro_tracker.core.models.ActionItem>` 

instance for the given type indicating that the package has an 

autoremoval issue. 

""" 

action_item = package.get_action_item_for_type(self.action_item_type) 

2258 ↛ 2264line 2258 didn't jump to line 2264, because the condition on line 2258 was never false if not action_item: 

action_item = ActionItem( 

package=package, 

item_type=self.action_item_type, 

severity=ActionItem.SEVERITY_HIGH) 

 

bugs_dependencies = stats.get('bugs_dependencies', []) 

buggy_dependencies = stats.get('buggy_dependencies', []) 

reverse_dependencies = stats.get('rdeps', []) 

all_bugs = stats['bugs'] + bugs_dependencies 

link = '<a href="https://bugs.debian.org/{}">#{}</a>' 

removal_date = stats['removal_date'].strftime('%d %B') 

2270 ↛ 2271line 2270 didn't jump to line 2271, because the condition on line 2270 was never true if isinstance(removal_date, bytes): 

removal_date = removal_date.decode('utf-8', 'ignore') 

 

action_item.short_description = self.ITEM_DESCRIPTION.format( 

removal_date=removal_date, 

dependencies=(' due to ' + html_package_list( 

buggy_dependencies) if buggy_dependencies else ''), 

bugs=', '.join(link.format(bug, bug) for bug in all_bugs)) 

 

# datetime objects are not JSON-serializable, convert them ourselves 

for key in stats.keys(): 

if hasattr(stats[key], 'strftime'): 

stats[key] = stats[key].strftime('%a %d %b %Y') 

 

action_item.extra_data = { 

'stats': stats, 

'removal_date': stats['removal_date'], 

'version': stats.get('version', ''), 

'bugs': ', '.join(link.format(bug, bug) for bug in stats['bugs']), 

'bugs_dependencies': ', '.join( 

link.format(bug, bug) for bug in bugs_dependencies), 

'buggy_dependencies': 

html_package_list(buggy_dependencies), 

'reverse_dependencies': 

html_package_list(reverse_dependencies), 

'number_rdeps': len(reverse_dependencies)} 

action_item.save() 

 

def execute_main(self): 

autoremovals_stats = self.get_autoremovals_stats() 

2300 ↛ 2302line 2300 didn't jump to line 2302, because the condition on line 2300 was never true if autoremovals_stats is None: 

# Nothing to do: cached content up to date 

return 

 

ActionItem.objects.delete_obsolete_items( 

item_types=[self.action_item_type], 

non_obsolete_packages=autoremovals_stats.keys()) 

 

packages = SourcePackageName.objects.filter( 

name__in=autoremovals_stats.keys()) 

packages = packages.prefetch_related('action_items') 

 

for package in packages: 

self.update_action_item(package, autoremovals_stats[package.name]) 

 

 

class UpdatePackageScreenshotsTask(BaseTask): 

""" 

Check if a screenshot exists on screenshots.debian.net, and add a 

key to PackageData if it does. 

""" 

 

class Scheduler(IntervalScheduler): 

interval = 3600 * 24 

 

DATA_KEY = 'screenshots' 

 

def _get_screenshots(self): 

url = 'https://screenshots.debian.net/json/packages' 

content = get_resource_text(url, force_update=self.force_update, 

only_if_updated=True) 

2331 ↛ 2332line 2331 didn't jump to line 2332, because the condition on line 2331 was never true if content is None: 

return 

 

data = json.loads(content) 

return data 

 

def execute_main(self): 

content = self._get_screenshots() 

2339 ↛ 2340line 2339 didn't jump to line 2340, because the condition on line 2339 was never true if content is None: 

return 

 

packages_with_screenshots = [] 

for item in content['packages']: 

try: 

package = SourcePackageName.objects.get(name=item['name']) 

packages_with_screenshots.append(package) 

except SourcePackageName.DoesNotExist: 

pass 

 

with transaction.atomic(): 

PackageData.objects.filter(key='screenshots').delete() 

 

data = [] 

for package in packages_with_screenshots: 

try: 

screenshot_info = package.data.get(key=self.DATA_KEY) 

screenshot_info.value['screenshots'] = 'true' 

except PackageData.DoesNotExist: 

screenshot_info = PackageData( 

key=self.DATA_KEY, 

package=package, 

value={'screenshots': 'true'}) 

 

data.append(screenshot_info) 

 

PackageData.objects.bulk_create(data) 

 

 

class UpdateBuildReproducibilityTask(BaseTask): 

 

class Scheduler(IntervalScheduler): 

interval = 3600 * 6 

 

BASE_URL = 'https://tests.reproducible-builds.org' 

ACTION_ITEM_TYPE_NAME = 'debian-build-reproducibility' 

ACTION_ITEM_TEMPLATE = 'debian/build-reproducibility-action-item.html' 

ITEM_DESCRIPTION = { 

'blacklisted': '<a href="{url}">Blacklisted</a> from build ' 

'reproducibility testing', 

'FTBFS': '<a href="{url}">Fails to build</a> during reproducibility ' 

'testing', 

'reproducible': None, 

'FTBR': '<a href="{url}">Does not build reproducibly</a> ' 

'during testing', 

'404': None, 

'not for us': None, 

} 

 

def initialize(self, *args, **kwargs): 

super(UpdateBuildReproducibilityTask, self).initialize(*args, **kwargs) 

self.action_item_type = ActionItemType.objects.create_or_update( 

type_name=self.ACTION_ITEM_TYPE_NAME, 

full_description_template=self.ACTION_ITEM_TEMPLATE) 

 

def get_build_reproducibility(self): 

url = '{}/debian/reproducible-tracker.json'.format(self.BASE_URL) 

content = get_resource_text(url, force_update=self.force_update, 

only_if_updated=True) 

2399 ↛ 2400line 2399 didn't jump to line 2400, because the condition on line 2399 was never true if content is None: 

return 

 

reproducibilities = json.loads(content) 

packages = {} 

for item in reproducibilities: 

package = item['package'] 

status = item['status'] 

missing = package not in packages 

important = self.ITEM_DESCRIPTION.get(status) is not None 

2409 ↛ 2404line 2409 didn't jump to line 2404, because the condition on line 2409 was never false if important or missing: 

packages[package] = status 

 

return packages 

 

def update_action_item(self, package, status): 

description = self.ITEM_DESCRIPTION.get(status) 

 

if not description: # Not worth an action item 

return False 

 

action_item = package.get_action_item_for_type( 

self.action_item_type.type_name) 

2422 ↛ 2428line 2422 didn't jump to line 2428, because the condition on line 2422 was never false if action_item is None: 

action_item = ActionItem( 

package=package, 

item_type=self.action_item_type, 

severity=ActionItem.SEVERITY_NORMAL) 

 

url = "{}/debian/rb-pkg/{}.html".format(self.BASE_URL, package.name) 

action_item.short_description = description.format(url=url) 

action_item.save() 

return True 

 

def execute_main(self): 

reproducibilities = self.get_build_reproducibility() 

2435 ↛ 2436line 2435 didn't jump to line 2436, because the condition on line 2435 was never true if reproducibilities is None: 

return 

 

with transaction.atomic(): 

PackageData.objects.filter(key='reproducibility').delete() 

 

packages = [] 

data = [] 

 

for name, status in reproducibilities.items(): 

try: 

package = SourcePackageName.objects.get(name=name) 

if self.update_action_item(package, status): 

packages.append(package) 

except SourcePackageName.DoesNotExist: 

continue 

 

reproducibility_info = PackageData( 

key='reproducibility', 

package=package, 

value={'reproducibility': status}) 

data.append(reproducibility_info) 

 

ActionItem.objects.delete_obsolete_items([self.action_item_type], 

packages) 

PackageData.objects.bulk_create(data) 

 

 

class MultiArchHintsTask(BaseTask): 

 

class Scheduler(IntervalScheduler): 

interval = 3600 * 6 

 

ACTIONS_WEB = 'https://wiki.debian.org/MultiArch/Hints' 

ACTIONS_URL = 'https://dedup.debian.net/static/multiarch-hints.yaml' 

ACTION_ITEM_TYPE_NAME = 'debian-multiarch-hints' 

ACTION_ITEM_TEMPLATE = 'debian/multiarch-hints.html' 

ACTION_ITEM_DESCRIPTION = \ 

'<a href="{link}">Multiarch hinter</a> reports {count} issue(s)' 

 

def initialize(self, *args, **kwargs): 

super(MultiArchHintsTask, self).initialize(*args, **kwargs) 

self.action_item_type = ActionItemType.objects.create_or_update( 

type_name=self.ACTION_ITEM_TYPE_NAME, 

full_description_template=self.ACTION_ITEM_TEMPLATE) 

self.SEVERITIES = {} 

for value, name in ActionItem.SEVERITIES: 

self.SEVERITIES[name] = value 

 

def get_data(self): 

data = get_resource_text(self.ACTIONS_URL) 

if data: 

return yaml.safe_load(data) 

 

def get_packages(self): 

data = self.get_data() 

if data is None: 

return 

if data['format'] != 'multiarch-hints-1.0': 

return None 

data = data['hints'] 

packages = collections.defaultdict(dict) 

for item in data: 

if 'source' not in item: 

continue 

package = item['source'] 

wishlist = ActionItem.SEVERITY_WISHLIST 

severity = self.SEVERITIES.get(item['severity'], wishlist) 

pkg_severity = packages[package].get('severity', wishlist) 

packages[package]['severity'] = max(severity, pkg_severity) 

packages[package].setdefault('hints', []).append( 

(item['description'], item['link'])) 

return packages 

 

def update_action_item(self, package, severity, description, extra_data): 

action_item = package.get_action_item_for_type( 

self.action_item_type.type_name) 

if action_item is None: 

action_item = ActionItem( 

package=package, 

item_type=self.action_item_type) 

action_item.severity = severity 

action_item.short_description = description 

action_item.extra_data = extra_data 

action_item.save() 

 

def execute_main(self): 

packages = self.get_packages() 

if not packages: 

return 

 

with transaction.atomic(): 

for name, data in packages.items(): 

try: 

package = SourcePackageName.objects.get(name=name) 

except SourcePackageName.DoesNotExist: 

continue 

 

description = self.ACTION_ITEM_DESCRIPTION.format( 

count=len(data['hints']), link=self.ACTIONS_WEB) 

self.update_action_item(package, data['severity'], description, 

data['hints']) 

 

ActionItem.objects.delete_obsolete_items([self.action_item_type], 

packages.keys()) 

 

 

class UpdateVcsWatchTask(BaseTask): 

""" 

Updates packages' vcswatch stats. 

""" 

 

class Scheduler(IntervalScheduler): 

interval = 3600 

 

ACTION_ITEM_TYPE_NAME = 'vcswatch-warnings-and-errors' 

ITEM_FULL_DESCRIPTION_TEMPLATE = 'debian/vcswatch-action-item.html' 

VCSWATCH_URL = 'https://qa.debian.org/cgi-bin/vcswatch?package=%(package)s' 

VCSWATCH_DATA_URL = 'https://qa.debian.org/data/vcswatch/vcswatch.json.gz' 

 

VCSWATCH_STATUS_DICT = { 

"NEW": { 

"description": 

'<a href="{vcswatch_url}">version in VCS is newer</a> than in ' 

'repository, is it time to upload?', 

"severity": ActionItem.SEVERITY_NORMAL, 

}, 

"COMMITS": { 

"description": 

'<a href="{vcswatch_url}">{commits} new commit{commits_s}</a> ' 

'since last upload, is it time to release?', 

"severity": ActionItem.SEVERITY_NORMAL, 

}, 

"OLD": { 

'description': 

'The <a href="{vcswatch_url}">VCS repository is not up to ' 

'date</a>, push the missing commits.', 

"severity": ActionItem.SEVERITY_HIGH, 

}, 

"UNREL": { 

"description": 

'The <a href="{vcswatch_url}">VCS repository is not up to ' 

'date</a>, push the missing commits.', 

"severity": ActionItem.SEVERITY_HIGH, 

}, 

"ERROR": { 

"description": 

'<a href="{vcswatch_url}">Failed to analyze the VCS ' 

'repository</a>. Please troubleshoot and fix the issue.', 

"severity": ActionItem.SEVERITY_HIGH, 

}, 

"DEFAULT": { 

"description": 

'<a href="{url}">Unexpected status</a> ({status}) reported by ' 

'VcsWatch.', 

"severity": ActionItem.SEVERITY_HIGH, 

}, 

} 

 

def initialize(self, *args, **kwargs): 

super(UpdateVcsWatchTask, self).initialize(*args, **kwargs) 

self.vcswatch_ai_type = ActionItemType.objects.create_or_update( 

type_name=self.ACTION_ITEM_TYPE_NAME, 

full_description_template=self.ITEM_FULL_DESCRIPTION_TEMPLATE 

) 

 

def get_vcswatch_data(self): 

text = get_resource_text(self.VCSWATCH_DATA_URL) 

 

2604 ↛ 2605line 2604 didn't jump to line 2605, because the condition on line 2604 was never true if text is None: 

return 

 

# There's some text, let's load! 

data = json.loads(text) 

 

out = {} 

# This allows to save a lot of list search later. 

for entry in data: 

out[entry[u'package']] = entry 

 

return out 

 

def clean_package_info(self, package_infos_without_watch, todo): 

"""Takes a list of :class:`PackageData` which do not 

have a watch entry and cleans it. Then schedule in todo what 

to do with them. 

""" 

for package_info in package_infos_without_watch: 

2623 ↛ 2622line 2623 didn't jump to line 2622, because the condition on line 2623 was never false if 'QA' in package_info.value: 

package_info.value.pop('QA') 

if (list(package_info.value.keys()) == ['checksum'] or 

not package_info.value.keys()): 

todo['drop']['package_infos'].append(package_info) 

else: 

package_info.value['checksum'] = get_data_checksum( 

package_info.value 

) 

todo['update']['package_infos'].append(package_info) 

 

def update_action_item(self, package, vcswatch_data, action_item, todo): 

""" 

For a given :class:`ActionItem` and a given vcswatch data, updates 

properly the todo dict if required. 

 

Returns dependingly on what has been done. If something is to 

be updated, returns True, if nothing is to be updated, returns 

False. If the calling loop should `continue`, returns `None`. 

 

:rtype: bool or `None` 

""" 

 

package_status = vcswatch_data['status'] 

 

if package_status == "OK": 

# Everything is fine, let's purge the action item. Not the 

# package extracted info as its QA url is still relevant. 

2651 ↛ 2655line 2651 didn't jump to line 2655, because the condition on line 2651 was never false if action_item: 

todo['drop']['action_items'].append(action_item) 

 

# Nothing more to do! 

return False 

 

# NOT BEFORE "OK" check!! 

2658 ↛ 2659line 2658 didn't jump to line 2659, because the condition on line 2658 was never true if package_status not in self.VCSWATCH_STATUS_DICT: 

package_status = "DEFAULT" 

 

# If we are here, then something is not OK. Let's check if we 

# already had some intel regarding the current package status. 

if action_item is None: 

action_item = ActionItem( 

package=package, 

item_type=self.vcswatch_ai_type) 

todo['add']['action_items'].append(action_item) 

else: 

todo['update']['action_items'].append(action_item) 

 

# Computes the watch URL 

vcswatch_url = self.VCSWATCH_URL % {'package': package.name} 

 

if action_item.extra_data: 

extra_data = action_item.extra_data 

else: 

extra_data = {} 

 

# Fetches the long description and severity from 

# the VCSWATCH_STATUS_DICT dict. 

action_item.severity = \ 

self.VCSWATCH_STATUS_DICT[package_status]['severity'] 

 

nb_commits = int(vcswatch_data["commits"] or 0) 

 

# The new data 

new_extra_data = { 

'vcswatch_url': vcswatch_url, 

} 

new_extra_data.update(vcswatch_data) 

 

extra_data_match = all([ 

new_extra_data[key] == extra_data.get(key, None) 

for key in new_extra_data 

]) 

 

# If everything is fine and we are not forcing the update 

# then we proceed to the next package. 

2699 ↛ 2701line 2699 didn't jump to line 2701, because the condition on line 2699 was never true if extra_data_match and not self.force_update: 

# Remove from the todolist 

todo['update']['action_items'].remove(action_item) 

return False 

else: 

# Report for short description of the :class:`ActionItem` 

desc = self.VCSWATCH_STATUS_DICT[package_status]['description'] 

commits_s = 's' if nb_commits != 1 else '' 

action_item.short_description = \ 

desc.format(commits_s=commits_s, **new_extra_data) 

action_item.extra_data = new_extra_data 

return True 

 

def update_package_info(self, package, vcswatch_data, package_info, key, 

todo): 

# Same thing with PackageData 

if package_info is None: 

package_info = PackageData( 

package=package, 

key=key, 

) 

todo['add']['package_infos'].append(package_info) 

else: 

todo['update']['package_infos'].append(package_info) 

 

# Computes the watch URL 

vcswatch_url = self.VCSWATCH_URL % {'package': package.name} 

 

new_value = dict(package_info.value) 

if key == 'vcs_extra_links': 

new_value['QA'] = vcswatch_url 

2730 ↛ 2740line 2730 didn't jump to line 2740, because the condition on line 2730 was never false elif key == 'vcswatch': 

2731 ↛ 2733line 2731 didn't jump to line 2733, because the condition on line 2731 was never false if 'package_version' in vcswatch_data: 

new_value['package_version'] = vcswatch_data['package_version'] 

2733 ↛ 2736line 2733 didn't jump to line 2736, because the condition on line 2733 was never false if 'changelog_version' in vcswatch_data: 

new_value['changelog_version'] = vcswatch_data[ 

'changelog_version'] 

2736 ↛ 2740line 2736 didn't jump to line 2740, because the condition on line 2736 was never false if 'changelog_distribution' in vcswatch_data: 

new_value['changelog_distribution'] = vcswatch_data[ 

'changelog_distribution'] 

 

new_value['checksum'] = get_data_checksum(new_value) 

 

package_info_match = ( 

new_value['checksum'] == package_info.value.get('checksum', None) 

) 

 

if package_info_match and not self.force_update: 

todo['update']['package_infos'].remove(package_info) 

return False 

else: 

package_info.value = new_value 

return True 

 

def update_packages_item(self, packages, vcswatch_datas): 

"""Generates the lists of :class:`ActionItem` to be added, 

deleted or updated regarding the status of their packages. 

 

Categories of statuses are: 

{u'COMMITS', u'ERROR', u'NEW', u'OK', u'OLD', u'UNREL'} 

 

Basically, it fetches all info from :class:`PackageData` 

with key='vcs', the ones without data matching vcswatch_datas are 

stored in one variable that's iterated through directly, and if 

there was something before, it is purged. Then, all entries in 

that queryset that have no relevant intel anymore are scheduled 

to be deleted. The others are only updated. 

 

All :class:`PackageData` matching vcswatch_datas 

are stored in another variable. The same is done with the list of 

:class:`ActionItem` that match this task type. 

 

Then, it iterates on all vcswatch_datas' packages and it tries to 

determine if there are any news, if so, it updates apopriately the 

prospective :class:`ActionItem` and :class:`PackageData`, 

and schedule them to be updated. If no data was existent, then 

it creates them and schedule them to be added to the database. 

 

At the end, this function returns a dict of all instances of 

:class:`ActionItem` and :class:`PackageData` stored 

in subdicts depending on their class and what is to be done 

with them. 

 

:rtype: dict 

 

""" 

 

todo = { 

'drop': { 

'action_items': [], 

'package_infos': [], 

}, 

'update': { 

'action_items': [], 

'package_infos': [], 

}, 

'add': { 

'action_items': [], 

'package_infos': [], 

}, 

} 

 

package_info_keys = ['vcs_extra_links', 'vcswatch'] 

package_infos = {} 

for key in package_info_keys: 

# Fetches all PackageData with a given key for packages having 

# a vcswatch key. As the pair (package, key) is unique, there is a 

# bijection between these data, and we fetch them classifying them 

# by package name. 

for package_info in PackageData.objects.select_related( 

'package').filter(key=key).only('package__name', 'value'): 

if package_info.package.name not in package_infos: 

package_infos[package_info.package.name] = {} 

package_infos[package_info.package.name][key] = package_info 

 

# As :class:`PackageData` key=vcs_extra_links is shared, we 

# have to clean up those with vcs watch_url that aren't in vcs_data 

package_infos_without_watch = PackageData.objects.filter( 

key='vcs_extra_links').exclude( 

package__name__in=vcswatch_datas.keys()).only('value') 

 

# Do the actual clean. 

self.clean_package_info(package_infos_without_watch, todo) 

 

# Fetches all :class:`ActionItem` for packages concerned by a vcswatch 

# action. 

action_items = { 

action_item.package.name: action_item 

for action_item in ActionItem.objects.select_related( 

'package' 

).filter(item_type=self.vcswatch_ai_type) 

} 

 

for package in packages: 

# Get the vcswatch_data from the whole vcswatch_datas 

vcswatch_data = vcswatch_datas[package.name] 

 

# Get the old action item for this warning, if it exists. 

action_item = action_items.get(package.name, None) 

 

# Updates the :class:`ActionItem`. If _continue is None, 

# then there is nothing more to do with this package. 

# If it is False, then no update is pending for the 

# :class:`ActionItem`, else there is an update 

# to do. 

_ai_continue = self.update_action_item( 

package, 

vcswatch_data, 

action_item, 

todo) 

 

_pi_continue = False 

for key in package_info_keys: 

try: 

package_info = package_infos[package.name][key] 

except KeyError: 

package_info = None 

 

_pi_continue |= self.update_package_info( 

package, 

vcswatch_data, 

package_info, 

key, 

todo) 

 

if not _ai_continue and not _pi_continue: 

continue 

 

return todo 

 

def execute_main(self): 

# Get the actual vcswatch json file from qa.debian.org 

vcs_data = self.get_vcswatch_data() 

 

# Only fetch the packages that are in the json dict. 

packages = PackageName.objects.filter(name__in=vcs_data.keys()) 

 

# Faster than fetching the action items one by one in a loop 

# when handling each package. 

packages.prefetch_related('action_items') 

 

# Determine wether something is to be kept or dropped. 

todo = self.update_packages_item(packages, vcs_data) 

 

with transaction.atomic(): 

# Delete the :class:`ActionItem` that are osbolete, and also 

# the :class:`PackageData` of the same. 

ActionItem.objects.delete_obsolete_items( 

[self.vcswatch_ai_type], 

vcs_data.keys()) 

PackageData.objects.filter( 

key='vcs_extra_links', 

id__in=[ 

package_info.id 

for package_info in todo['drop']['package_infos'] 

] 

).delete() 

 

# Then delete the :class:`ActionItem` that are to be deleted. 

ActionItem.objects.filter( 

item_type__type_name=self.vcswatch_ai_type.type_name, 

id__in=[ 

action_item.id 

for action_item in todo['drop']['action_items'] 

] 

).delete() 

 

# Then bulk_create the :class:`ActionItem` to add and the 

# :class:`PackageData` 

ActionItem.objects.bulk_create(todo['add']['action_items']) 

PackageData.objects.bulk_create(todo['add']['package_infos']) 

 

# Update existing entries 

for action_item in todo['update']['action_items']: 

action_item.save() 

for package_info in todo['update']['package_infos']: 

package_info.save() 

 

 

class TagPackagesWithRcBugs(BaseTask, PackageTagging): 

""" 

Performs an update of 'rc-bugs' tag for packages. 

""" 

 

class Scheduler(IntervalScheduler): 

interval = 3600 

 

TAG_NAME = 'tag:rc-bugs' 

TAG_DISPLAY_NAME = 'rc bugs' 

TAG_COLOR_TYPE = 'danger' 

TAG_DESCRIPTION = 'The package has Release Critical bugs' 

TAG_TABLE_TITLE = 'Packages with RC bugs' 

 

def packages_to_tag(self): 

all_bug_stats = PackageBugStats.objects.prefetch_related('package') 

packages_list = [] 

for bug_stats in all_bug_stats: 

categories = bug_stats.stats 

found = False 

2938 ↛ 2935line 2938 didn't jump to line 2935, because the loop on line 2938 didn't complete for category in categories: 

if found: 

break 

2941 ↛ 2938line 2941 didn't jump to line 2938, because the condition on line 2941 was never false if category['category_name'] == 'rc': 

found = True 

if category['bug_count'] > 0: 

packages_list.append(bug_stats.package) 

return packages_list 

 

 

class TagPackagesWithNewUpstreamVersion(BaseTask, PackageTagging): 

""" 

Performs an update of 'new-upstream-version' tag for packages. 

""" 

 

class Scheduler(IntervalScheduler): 

interval = 3600 * 3 

 

TAG_NAME = 'tag:new-upstream-version' 

TAG_DISPLAY_NAME = 'new upstream version' 

TAG_COLOR_TYPE = 'warning' 

TAG_DESCRIPTION = 'The upstream has a newer version available' 

TAG_TABLE_TITLE = 'Newer upstream version' 

 

def packages_to_tag(self): 

try: 

action_type = ActionItemType.objects.get( 

type_name='new-upstream-version') 

except ActionItemType.DoesNotExist: 

return [] 

 

packages_list = [] 

items = action_type.action_items.prefetch_related('package') 

for item in items: 

packages_list.append(item.package) 

return packages_list 

 

 

class UpdateDependencySatisfactionTask(BaseTask): 

""" 

Fetches binary package installability results from qa.debian.org/dose 

""" 

 

class Scheduler(IntervalScheduler): 

interval = 3600 * 3 

 

BASE_URL = 'https://qa.debian.org/dose/debcheck/unstable_main/latest' 

ACTION_ITEM_TYPE_NAME = 'debian-dependency-satisfaction' 

ACTION_ITEM_TEMPLATE = 'debian/dependency-satisfaction-action-item.html' 

 

def __init__(self, force_update=False, *args, **kwargs): 

super(UpdateDependencySatisfactionTask, self).__init__(*args, **kwargs) 

self.force_update = force_update 

self.action_item_type = ActionItemType.objects.create_or_update( 

type_name=self.ACTION_ITEM_TYPE_NAME, 

full_description_template=self.ACTION_ITEM_TEMPLATE) 

 

def set_parameters(self, parameters): 

if 'force_update' in parameters: 

self.force_update = parameters['force_update'] 

 

def get_dependency_satisfaction(self): 

url = '{}/each.txt'.format(self.BASE_URL) 

content = get_resource_text(url, force_update=self.force_update, 

only_if_updated=True) 

3003 ↛ 3004line 3003 didn't jump to line 3004, because the condition on line 3003 was never true if content is None: 

return 

 

dep_sats = collections.defaultdict(set) 

for i, line in enumerate(content.splitlines()): 

binpkg_name, ver, isnative, anchor, expl, arches = line.split('#') 

try: 

bin_package = BinaryPackageName.objects.get(name=binpkg_name) 

srcpkg_name = bin_package.main_source_package_name 

except BinaryPackageName.DoesNotExist: 

continue 

arches = set([arch.strip() for arch in arches.split()]) 

# TODO: retrieve this list programmatically, either from 

# https://api.ftp-master.debian.org/suite/testing 

# or from the Architecture field in the Release file 

# for testing (both lists should be equal). 

arches = arches.intersection( 

{'amd64', 'arm64', 'armel', 'armhf', 'i386', 'mips', 

'mips64el', 'mipsel', 'ppc64el', 's390x'}) 

# only report problems for release architectures 

if not arches: 

continue 

# if the package is arch:all, only report problems on amd64 

if isnative != "True": 

arches = arches.intersection({"amd64"}) 

if not arches: 

continue 

dep_sats[srcpkg_name].add( 

(binpkg_name, ver, tuple(arches), expl, anchor)) 

# turn sets into lists 

dep_sats = dict([(k, list(v)) for k, v in dep_sats.items()]) 

return dep_sats 

 

def update_action_item(self, package, unsats): 

action_item = package.get_action_item_for_type( 

self.action_item_type.type_name) 

3039 ↛ 3044line 3039 didn't jump to line 3044 if action_item is None: 

action_item = ActionItem( 

package=package, 

item_type=self.action_item_type, 

severity=ActionItem.SEVERITY_HIGH) 

action_item.short_description = \ 

"{count} binary package{plural} {have} unsatisfiable " \ 

"dependencies".format( 

count=len(unsats), 

plural='' if len(unsats) == 1 else 's', 

have='has' if len(unsats) == 1 else 'have', 

) 

action_item.extra_data = { 

'unsats': unsats, 

'base_url': '{}/packages/'.format(self.BASE_URL), 

} 

action_item.save() 

 

def execute(self): 

dep_sats = self.get_dependency_satisfaction() 

3059 ↛ 3060line 3059 didn't jump to line 3060, because the condition on line 3059 was never true if dep_sats is None: 

return 

 

with transaction.atomic(): 

PackageData.objects.filter(key='dependency_satisfaction').delete() 

 

packages = [] 

pkgdata_list = [] 

 

for name, unsats in dep_sats.items(): 

try: 

package = SourcePackageName.objects.get(name=name) 

packages.append(package) 

self.update_action_item(package, unsats) 

except SourcePackageName.DoesNotExist: 

continue 

 

dep_sat_info = PackageData( 

key='dependency_satisfaction', 

package=package, 

value={'dependency_satisfaction': unsats}) 

pkgdata_list.append(dep_sat_info) 

 

ActionItem.objects.delete_obsolete_items([self.action_item_type], 

packages) 

PackageData.objects.bulk_create(pkgdata_list) 

 

 

class UpdateBuildDependencySatisfactionTask(BaseTask): 

""" 

Fetches source package installability results from qa.debian.org/dose 

""" 

 

class Scheduler(IntervalScheduler): 

interval = 3600 * 3 

 

BASE_URL = 'https://qa.debian.org/dose/debcheck/src_unstable_main/latest' 

ACTION_ITEM_TYPE_NAME = 'debian-builddependency-satisfaction' 

ACTION_ITEM_TEMPLATE = \ 

'debian/builddependency-satisfaction-action-item.html' 

 

def __init__(self, *args, **kwargs): 

super(UpdateBuildDependencySatisfactionTask, self).__init__(*args, 

**kwargs) 

self.action_item_type = ActionItemType.objects.create_or_update( 

type_name=self.ACTION_ITEM_TYPE_NAME, 

full_description_template=self.ACTION_ITEM_TEMPLATE) 

 

def get_dependency_satisfaction(self): 

url = '{}/each.txt'.format(self.BASE_URL) 

content = get_resource_text(url, force_update=self.force_update, 

only_if_updated=True) 

3111 ↛ 3112line 3111 didn't jump to line 3112, because the condition on line 3111 was never true if content is None: 

return 

 

dep_sats = collections.defaultdict(set) 

for i, line in enumerate(content.splitlines()): 

srcpkg_name, ver, isnative, anchor, expl, arches = line.split('#') 

arches = set([arch.strip() for arch in arches.split()]) 

# TODO: retrieve this list programmatically, either from 

# https://api.ftp-master.debian.org/suite/testing 

# or from the Architecture field in the Release file 

# for testing (both lists should be equal). 

arches = arches.intersection( 

{'amd64', 'arm64', 'armel', 'armhf', 'i386', 'mips', 

'mips64el', 'mipsel', 'ppc64el', 's390x'}) 

# only report problems for release architectures 

if not arches: 

continue 

# if the source package only builds arch:all binary packages, only 

# report problems on amd64 

if isnative != "True": 

arches = arches.intersection({"amd64"}) 

if not arches: 

continue 

dep_sats[srcpkg_name].add( 

(srcpkg_name, tuple(arches), expl, anchor)) 

# turn sets into lists 

dep_sats = dict([(k, list(v)) for k, v in dep_sats.items()]) 

return dep_sats 

 

def update_action_item(self, package, unsats): 

action_item = package.get_action_item_for_type( 

self.action_item_type.type_name) 

3143 ↛ 3148line 3143 didn't jump to line 3148 if action_item is None: 

action_item = ActionItem( 

package=package, 

item_type=self.action_item_type, 

severity=ActionItem.SEVERITY_HIGH) 

action_item.short_description = \ 

"source package has {count} unsatisfiable " \ 

"build dependenc{plural}".format( 

count=len(unsats), 

plural='y' if len(unsats) == 1 else 'ies', 

) 

action_item.extra_data = { 

'unsats': unsats, 

'base_url': '{}/packages/'.format(self.BASE_URL), 

} 

action_item.save() 

 

def execute(self): 

dep_sats = self.get_dependency_satisfaction() 

3162 ↛ 3163line 3162 didn't jump to line 3163, because the condition on line 3162 was never true if dep_sats is None: 

return 

 

with transaction.atomic(): 

PackageData.objects.filter( 

key='builddependency_satisfaction').delete() 

 

packages = [] 

pkgdata_list = [] 

 

for name, unsats in dep_sats.items(): 

try: 

package = SourcePackageName.objects.get(name=name) 

packages.append(package) 

self.update_action_item(package, unsats) 

except SourcePackageName.DoesNotExist: 

continue 

 

dep_sat_info = PackageData( 

key='builddependency_satisfaction', 

package=package, 

value={'builddependency_satisfaction': unsats}) 

pkgdata_list.append(dep_sat_info) 

 

ActionItem.objects.delete_obsolete_items([self.action_item_type], 

packages) 

PackageData.objects.bulk_create(pkgdata_list) 

 

 

class UpdateDl10nStatsTask(BaseTask): 

""" 

Updates packages' l10n statistics. 

""" 

 

class Scheduler(IntervalScheduler): 

interval = 3600 * 6 

 

ACTION_ITEM_TYPE_NAME = 'dl10n' 

ITEM_DESCRIPTION = \ 

'<a href="{url}">Issues</a> found with some translations' 

ITEM_FULL_DESCRIPTION_TEMPLATE = 'debian/dl10n-action-item.html' 

 

def initialize(self, *args, **kwargs): 

super(UpdateDl10nStatsTask, self).initialize(*args, **kwargs) 

self.l10n_action_item_type = \ 

ActionItemType.objects.create_or_update( 

type_name=self.ACTION_ITEM_TYPE_NAME, 

full_description_template=self.ITEM_FULL_DESCRIPTION_TEMPLATE) 

 

def _load_l10n_stats(self): 

url = 'https://i18n.debian.org/l10n-pkg-status/pkglist' 

content = get_resource_text(url, force_update=self.force_update, 

only_if_updated=True) 

3215 ↛ 3216line 3215 didn't jump to line 3216, because the condition on line 3215 was never true if content is None: 

return 

 

def parse_score(score): 

if score == '-': 

return None 

return int(score) 

 

all_stats = {} 

 

# The format of the file is (copied from its header): 

# <package> <version> (<comma sperated scores>) <link> <todo> 

line_re = re.compile( 

r'^([^\s]+) ([^\s]+) \(([^)]+)\) ([^\s]+) ([^\s]+)') 

for line in content.splitlines(): 

3230 ↛ 3231line 3230 didn't jump to line 3231, because the condition on line 3230 was never true if not line or line.startswith('#'): 

continue 

match = line_re.search(line) 

3233 ↛ 3234line 3233 didn't jump to line 3234, because the condition on line 3233 was never true if not match: 

logger.warning('Failed to parse l10n pkglist line: %s', line) 

continue 

 

src_pkgname = match.group(1) 

try: 

scores = match.group(3).split(',') 

score_debian = parse_score(scores[0]) 

score_other = parse_score(scores[1]) 

# <todo> is a "0" or "1" string, so convert through int to get 

# a proper bool 

todo = bool(int(match.group(5))) 

except (IndexError, ValueError): 

logger.warning( 

'Failed to parse l10n scores: %s', 

line, exc_info=1) 

continue 

link = match.group(4) 

3251 ↛ 3252line 3251 didn't jump to line 3252, because the condition on line 3251 was never true if not score_debian and not score_other: 

continue 

 

all_stats[src_pkgname] = { 

'score_debian': score_debian, 

'score_other': score_other, 

'link': link, 

'todo': todo, 

} 

 

return all_stats 

 

def update_action_item(self, package, package_stats): 

todo = package_stats['todo'] 

 

# Get the old action item, if it exists. 

l10n_action_item = package.get_action_item_for_type( 

self.l10n_action_item_type.type_name) 

if not todo: 

if l10n_action_item: 

# If the item previously existed, delete it now since there 

# are no longer any warnings/errors. 

l10n_action_item.delete() 

return 

 

# The item didn't previously have an action item: create it now 

if l10n_action_item is None: 

desc = self.ITEM_DESCRIPTION.format(url=package_stats['link']) 

l10n_action_item = ActionItem( 

package=package, 

item_type=self.l10n_action_item_type, 

severity=ActionItem.SEVERITY_LOW, 

short_description=desc) 

 

if l10n_action_item.extra_data: 

old_extra_data = l10n_action_item.extra_data 

3287 ↛ 3289line 3287 didn't jump to line 3289, because the condition on line 3287 was never true if old_extra_data == package_stats: 

# No need to update 

return 

 

l10n_action_item.extra_data = package_stats 

 

l10n_action_item.save() 

 

def execute_main(self): 

stats = self._load_l10n_stats() 

3297 ↛ 3298line 3297 didn't jump to line 3298, because the condition on line 3297 was never true if not stats: 

return 

 

with transaction.atomic(): 

PackageData.objects.filter(key='dl10n').delete() 

 

packages = [] 

pkgdata_list = [] 

 

for name, stat in stats.items(): 

try: 

package = SourcePackageName.objects.get(name=name) 

packages.append(package) 

self.update_action_item(package, stat) 

except SourcePackageName.DoesNotExist: 

continue 

 

dl10n_stat = PackageData( 

key='dl10n', 

package=package, 

value=stat) 

pkgdata_list.append(dl10n_stat) 

 

ActionItem.objects.delete_obsolete_items( 

[self.l10n_action_item_type], packages) 

PackageData.objects.bulk_create(pkgdata_list)