File size: 93,968 Bytes
859a779 |
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 |
:mod:`apt_pkg` --- The low-level bindings for apt-pkg
=====================================================
.. module:: apt_pkg
The apt_pkg extensions provides a more low-level way to work with apt. It can
do everything apt can, and is written in C++. It has been in python-apt since
the beginning.
Module Initialization
---------------------
Initialization is needed for most functions, but not for all of them. Some can
be called without having run init*(), but will not return the expected value.
.. function:: init_config
Initialize the configuration of apt. This is needed for most operations.
.. function:: init_system
Initialize the system.
.. function:: init
A short cut to calling :func:`init_config` and :func:`init_system`. You
can use this if you do not use the command line parsing facilities provided
by :func:`parse_commandline`, otherwise call :func:`init_config`, parse
the commandline afterwards and finally call :func:`init_system`.
Exceptions
----------
.. autoclass:: Error
.. autoclass:: CacheMismatchError
Working with the cache
----------------------
.. class:: Cache([progress: apt.progress.base.OpProgress])
A Cache object represents the cache used by APT which contains information
about packages. The object itself provides no means to modify the cache or
the installed packages, see the classes :class:`DepCache` and
:class:`PackageManager` for such functionality.
The constructor takes an optional argument which must be a subclass of
:class:`apt.progress.base.OpProgress`. This object will then be used to
display information during the cache opening process (or possible creation
of the cache). It may also be ``None``, in which case no progress will
be emitted. If not given, progress will be printed to standard output.
.. note::
The cache supports colon-separated name:architecture pairs. For
normal architectures, they are equal to a (name, architecture)
tuple. For the "any" architecture behavior is different, as
"name:any" is equivalent to ("name:any", "any"). This is done so
that "name:any" matches all packages with that name which have
Multi-Arch: allowed set.
.. describe:: cache[pkgname]
Return the :class:`Package()` object for the package name given by
*pkgname*. If *pkgname* includes a colon, the part after the colon
is used as the architecture.
.. describe:: cache[name, architecture]
Return the :class:`Package()` object for the package with the given
name and architecture.
.. versionadded: 0.8.0
.. describe:: pkgname in cache
Check whether a package with the name given by *pkgname* exists in
the cache for the native architecture. If *pkgname* includes a
colon, the part after the colon is used as the architecture.
.. describe:: (name, architecture) in cache
Check whether a package with the given name and architecture exists
in the cache.
.. versionadded: 0.8.0
.. method:: update(progress, sources [, pulse_interval]) -> bool
Update the index files used by the cache. A call to this method
does not affect the current Cache object, instead a new one
should be created in order to use the changed index files.
The parameter *progress* takes an
:class:`apt.progress.base.AcquireProgress` object which will display
the progress of fetching the index files. The parameter *sources* takes
a :class:`SourceList` object which lists the sources. The parameter
*progress* takes an integer describing the interval (in microseconds)
in which the pulse() method of the *progress* object will be called.
.. attribute:: depends_count
The total number of dependencies stored in the cache.
.. attribute:: file_list
A list of all :class:`PackageFile` objects stored in the cache.
.. attribute:: group_count
The number of groups in the cache.
.. versionadded: 0.8.0
.. attribute:: groups
A sequence of :class:`Group` objects, implemented as a
:class:`GroupList` object.
.. versionadded: 0.8.0
.. class:: GroupList
A simple sequence-like object which only provides a length and
an implementation of ``__getitem__`` for accessing groups at
a certain index. Apart from being iterable, it can be used in
the following ways:
.. versionadded: 0.8.0
.. describe:: list[index]
Get the :class:`Group` object for the group at the position
given by *index* in the GroupList *list*.
.. describe:: len(list)
Return the length of the GroupList object *list*.
.. attribute:: is_multi_arch
An attribute determining whether the cache supports multi-arch.
.. versionadded: 0.8.0
.. attribute:: package_count
The total number of packages available in the cache. This value is
equal to the length of the list provided by the :attr:`packages`
attribute.
.. attribute:: package_file_count
The total number of Packages files available (the Packages files
listing the packages). This is the same as the length of the list in
the attribute :attr:`file_list`.
.. attribute:: packages
A sequence of :class:`Package` objects, implemented as a
:class:`PackageList` object.
.. class:: PackageList
A simple sequence-like object which only provides a length and
an implementation of ``__getitem__`` for accessing packages at
a certain index. Apart from being iterable, it can be used in
the following ways:
.. describe:: list[index]
Get the :class:`Package` object for the package at the position
given by *index* in the PackageList *list*.
.. describe:: len(list)
Return the length of the PackageList object *list*.
.. attribute:: provides_count
The number of provided packages.
.. attribute:: ver_file_count
The total number of ``(Version, PackageFile)`` relations stored in
the cache.
.. attribute:: version_count
The total number of package versions available in the cache.
Managing the cache with :class:`DepCache`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. class:: DepCache(cache: apt_pkg.Cache)
A DepCache object provides access to more information about the
objects made available by the :class:`Cache` object as well as
means to mark packages for removal and installation, among other
actions.
The constructor takes a single argument which specifies the
:class:`Cache` object the new object shall be related to. While
it is theoretically possible to create multiple DepCache objects
for the same cache, they will not be independent from each other
since they all access the same underlying C++ object.
Objects of this type provide several methods. Most of those methods
are safe to use and should never raise any exception (all those
methods for requesting state information or marking changes). If a
method is expected to raise an exception, it will be stated in the
description.
If an object of a different cache is passed, :class:`CacheMismatchError`
is raised.
.. method:: commit(acquire_progress, install_progress)
Commit all marked changes, while reporting the progress of
fetching packages via the :class:`apt.progress.base.AcquireProgress`
object given by *acquire_progress* and reporting the installation
of the package using the :class:`apt.progress.base.InstallProgress`
object given by *install_progress*.
If this fails, an exception of the type :exc:`SystemError` will
be raised.
.. method:: fix_broken() -> bool
Try to fix all broken packages in the cache and return ``True`` in
case of success. If an error occurred, a :exc:`SystemError`
exception is raised.
.. method:: get_candidate_ver(pkg: Package) -> Version
Return the candidate version for the package given by the parameter
*pkg* as a :class:`Version` object. The default candidate for a
package is the version with the highest pin, although a different
one may be set using :meth:`set_candidate_ver`. If no candidate
can be found, return ``None`` instead.
.. method:: init(progress: apt.progress.base.OpProgress)
Initialize the DepCache. This is done automatically when the
cache is opened, but sometimes it may be useful to reinitialize
the DepCache. Like the constructor of :class:`Cache`, this
function takes a single :class:`apt.progress.base.OpProgress`
object to display progress information.
.. method:: read_pinfile(file: str)
A proxy function which calls the method :meth:`Policy.read_pinfile` of
the :class:`Policy` object used by this object. This method raises
a :exc:`SystemError` exception if the file could not be parsed.
.. method:: set_candidate_ver(pkg: Package, version: Version) -> bool
Set the candidate version of the package given by the :class:`Package`
object *pkg* to the version given by the :class:`Version` object
*version* and return ``True``. If odd things happen, this function
may raise a :exc:`SystemError` exception, but this should not
happen in normal usage. See :meth:`get_candidate_ver` for a way
to retrieve the candidate version of a package.
.. method:: upgrade([dist_upgrade=False]) -> bool
Mark the packages for upgrade under the same conditions
:program:`apt-get` does. If *dist_upgrade* is ``True``, also
allow packages to be upgraded if they require installation/removal
of other packages; just like apt-get dist-upgrade.
Despite returning a boolean value, this raises :exc:`SystemError` and
does not return ``False`` if an error occurred.
The following methods can mark a single package for installation,
removal, etc:
.. method:: mark_auto(pkg: Package)
Mark the :class:`Package` *pkg* as automatically installed.
.. method:: mark_keep(pkg: Package)
Mark the :class:`Package` *pkg* for keep.
.. method:: mark_delete(pkg: Package[, purge])
Mark the :class:`Package` *pkg* for delete. If *purge* is True,
the configuration files will be removed as well.
.. method:: mark_install(pkg: Package[, auto_inst=True[, from_user=True]])
Mark the :class:`Package` *pkg* for install, and, if *auto_inst*
is ``True``, its dependencies as well. If *from_user* is ``True``,
the package will **not** be marked as automatically installed.
.. method:: set_reinstall(pkg: Package)
Set if the :class:`Package` *pkg* should be reinstalled.
The following methods can be used to check the state of a package:
.. method:: is_auto_installed(pkg: Package) -> bool
Return ``True`` if the package is automatically installed, that
is, as a dependency of another package.
.. method:: is_garbage(pkg: Package) -> bool
Return ``True`` if the package is garbage, that is, if it was
automatically installed and no longer referenced by other packages.
.. method:: is_inst_broken(pkg: Package) -> bool
Return ``True`` if the package is broken on the current install. This
takes changes which have not been marked not into account.
.. method:: is_now_broken(pkg: Package) -> bool
Return ``True`` if the package is now broken, that is, if the package
is broken if the marked changes are applied.
.. method:: is_upgradable(pkg: Package) -> bool
Return ``True`` if the package is upgradable, the package can then
be marked for upgrade by calling the method :meth:`mark_install`.
.. method:: marked_delete(pkg: Package) -> bool
Return ``True`` if the package is marked for delete.
.. method:: marked_downgrade(pkg: Package) -> bool
Return ``True`` if the package should be downgraded.
.. method:: marked_install(pkg: Package) -> bool
Return ``True`` if the package is marked for install.
.. method:: marked_keep(pkg: Package) -> bool
Return ``True`` if the package is marked for keep.
.. method:: marked_reinstall(pkg: Package) -> bool
Return ``True`` if the package should be reinstalled.
.. method:: marked_upgrade(pkg: Package) -> bool
Return ``True`` if the package is marked for upgrade.
DepCache objects also provide several attributes containing information
on the marked changes:
.. attribute:: keep_count
Integer, number of packages marked as keep
.. attribute:: inst_count
Integer, number of packages marked for installation.
.. attribute:: del_count
Number of packages which should be removed.
.. attribute:: broken_count
Number of packages which are broken.
.. attribute:: usr_size
The size required for the changes on the filesystem. If you install
packages, this is positive, if you remove them its negative.
.. attribute:: deb_size
The size of the packages which are needed for the changes to be
applied.
.. attribute:: policy
The underlying :class:`Policy` object used by the :class:`DepCache` to
select candidate versions.
Installing with :class:`PackageManager`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. class:: PackageManager(depcache)
Abstraction of a package manager. This object takes care of retrieving
packages, ordering the installation, and calling the package manager to
do the actual installation.
.. method:: get_archives(fetcher, list, records) -> bool
Add all packages marked for installation (or upgrade, anything
which needs a download) to the :class:`Acquire` object referenced
by *fetcher*.
The parameter *list* specifies a :class:`SourceList` object which
is used to retrieve the information about the archive URI for the
packages which will be fetched.
The parameter *records* takes a :class:`PackageRecords` object which
will be used to look up the file name of the package.
.. method:: do_install(status_fd: int) -> int
Install the packages and return one of the class constants
:attr:`RESULT_COMPLETED`, :attr:`RESULT_FAILED`,
:attr:`RESULT_INCOMPLETE`. The argument *status_fd* can be used
to specify a file descriptor that APT will write status information
on (see README.progress-reporting in the apt source code for
information on what will be written there).
.. method:: fix_missing() -> bool
Fix the installation if a package could not be downloaded.
.. attribute:: RESULT_COMPLETED
A constant for checking whether the result of the call to
:meth:`do_install` is 'failed'.
.. attribute:: RESULT_FAILED
A constant for checking whether the result of the call to
:meth:`do_install` is 'failed'.
.. attribute:: RESULT_INCOMPLETE
A constant for checking whether the result of the call to
:meth:`do_install` is 'incomplete'.
All instances of this class also support the following methods:
.. note::
This methods are provided mainly for subclassing purposes
and should not be used in most programs. This class is a
subclass of an internal :class:`_PackageManager` which does
not provide that methods. As the public C++ API creates such
an object without those methods, you should not rely on those
methods to be available unless you used the constructor of
:class:`PackageManager` to create the object.
.. method:: configure(pkg: Package) -> bool
Notify the package manager that the :class:`Package` given
by *pkg* is to be configured. Must return a ``True`` value
or ``None`` to continue, or a value which is ``False`` if
evaluated as boolean to abort.
.. versionadded:: 0.8.0
.. method:: install(pkg: Package, filename: str) -> bool
Notify the package manager that the :class:`Package` given
by *pkg* is to be installed from the .deb located at
*filename*. Must return a ``True`` value or ``None`` to
continue, or a value which is ``False`` if evaluated as
boolean to abort.
.. versionadded:: 0.8.0
.. method:: remove(pkg: Package, purge: bool) -> bool
Notify the package manager that the :class:`Package` given
by *pkg* is to be removed. If *purge* is ``True``, the package
shall be purged. Must return a ``True`` value or ``None`` to
continue, or a value which is ``False`` if evaluated as boolean
to abort.
.. versionadded:: 0.8.0
.. method:: go(status_fd: int) -> bool
Start dpkg, writing status information to the file descriptor
given by *status_fd*. Must return a ``True`` value or ``None`` to
continue, or a value which is ``False`` if evaluated as boolean
to abort.
.. versionadded:: 0.8.0
.. method:: reset()
Reset the package manager for a new round.
.. versionadded:: 0.8.0
Installation ordering with :class:`OrderList`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. class:: OrderList(depcache: DepCache)
Represent a :c:type:`pkgOrderList`, used for installation
ordering. This class provides several methods and attributes,
is complicated and should not be used by normal programs.
.. versionadded:: 0.8.0
This class is a sequence and supports the following operations:
.. describe:: list[index]
Get the package at the given index in the list. Negative
index is supported.
.. describe:: len(list)
The length of the list.
It also supports the append() method from :class:`list`:
.. method:: append(pkg: Package)
Append a new package to the end of the list. Please note that
you may not append a package twice, as only as much packages
as in the cache can be added.
The class also defines several specific attributes and methods,
to be described hereinafter.
.. method:: score(pkg: Package)
Return the score of the package. Packages are basically
ordered by descending score.
This class allows flags to be set on packages. Those flags are:
.. attribute:: FLAG_ADDED
.. attribute:: FLAG_ADD_PENDING
.. attribute:: FLAG_IMMEDIATE
.. attribute:: FLAG_LOOP
.. attribute:: FLAG_UNPACKED
.. attribute:: FLAG_CONFIGURED
.. attribute:: FLAG_REMOVED
.. attribute:: FLAG_STATES_MASK
Same as ``FLAG_UNPACKED | FLAG_CONFIGURED | FLAG_REMOVED``
.. attribute:: FLAG_IN_LIST
.. attribute:: FLAG_AFTER
The methods to work with those flags are:
.. method:: flag(pkg: Package, flag: int[, unset_flags: int])
Flag a package. Sets the flags given in *flag* and unsets
any flags given in *unset_flags*.
.. method:: is_flag(pkg: Package, flag: int)
Check whether the flags in *flag* are set for the package.
.. method:: wipe_flags(flags: int)
Remove the flags in *flags* from all packages.
.. method:: is_missing(pkg: Package)
Check if the package is missing (not really usable right now)
.. method:: is_now(pkg: Package)
Check if the package is flagged for any state but removal.
The following methods for ordering are provided:
.. method:: order_critical()
Order the packages for critical unpacking; that is, only
respect pre-dependencies.
.. method:: order_unpack()
Order the packages for unpacking, repecting Pre-Depends and
Conflicts.
.. method:: order_configure()
Order the packages for configuration, respecting Depends.
Improve performance with :class:`ActionGroup`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. class:: ActionGroup(depcache)
Create a new :class:`ActionGroup()` object for the :class:`DepCache` object
given by the parameter *depcache*.
:class:`ActionGroup()` objects make operations on the cache faster by
delaying certain cleanup operations until the action group is released.
An action group is also a context manager and therefore supports the
:keyword:`with` statement. But because it becomes active as soon as it
is created, you should not create an ActionGroup() object before entering
the with statement. Thus, you should always use the following form::
with apt_pkg.ActionGroup(depcache):
...
For code which has to run on Python versions prior to 2.5, you can also
use the traditional way::
actiongroup = apt_pkg.ActionGroup(depcache)
...
actiongroup.release()
In addition to the methods required to implement the context
manager interface, :class:`ActionGroup` objects provide the
following method:
.. method:: release()
Release the ActionGroup. This will reactive the collection of package
garbage.
Resolving Dependencies with :class:`ProblemResolver`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. class:: ProblemResolver(depcache: DepCache)
ProblemResolver objects take care of resolving problems with
dependencies. They mark packages for installation/removal and
try to satisfy all dependencies. The constructor takes a single
argument of the type :class:`apt_pkg.DepCache` to determine the
cache that shall be manipulated in order to resolve the problems.
.. method:: clear(pkg: Package)
Revert the action of calling :meth:`protect` or :meth:`remove` on
a package, resetting it to the default state.
.. method:: install_protect()
Mark all protected packages for installation.
.. method:: protect(pkg: Package)
Mark the package given by *pkg* as protected; that is, its state
will not be changed.
.. method:: remove(pkg: Package)
Mark the package given by *pkg* for removal in the resolver.
.. method:: resolve([fix_broken: bool = True]) -> bool
Try to intelligently resolve problems by installing and removing
packages. If *fix_broken* is ``True``, apt will try to repair broken
dependencies of installed packages.
.. method:: resolve_by_keep() -> bool
Try to resolve the problems without installing or removing packages.
:class:`Group` of packages with the same name
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. class:: Group(cache: Cache, name: str)
.. versionadded:: 0.8.0
A collection of packages in which all packages have the same name. Groups
are used in multi-arch environments, where two or more packages have the
same name, but different architectures.
Group objects provide the following parts for sequential access:
.. describe:: group[index]
Get the package at the given **index** in the group.
.. note::
Groups are internally implemented using a linked list. The object
keeps a pointer to the current object and the first object, so
access to the first element, or accesses in order have a
complexity of O(1). Random-access complexity is ranges from
O(1) to O(n).
Group objects also provide special methods to find single packages:
.. method:: find_package(architecture: str) -> Package
Find a package with the groups name and the architecture given
in the argument *architecture*. If no such package exists, return
``None``.
.. method:: find_preferred_package(prefer_nonvirtual: bool = True) -> Package
Find the preferred package. This is the package of the native
architecture (specified in ``APT::Architecture``) if available,
or the package from the first foreign architecture. If no package
could be found, return ``None``
If **prefer_nonvirtual** is ``True``, the preferred package
will be a non-virtual package, if one exists.
:class:`Package` information
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. class:: Package
Represent a package. A package is uniquely identified by its name and
architecture and each package can have zero or more versions which can be
accessed via the :attr:`version_list` property. Packages can be
installed and removed by a :class:`DepCache` object.
Attributes:
.. attribute: architecture
The architecture of the package. This is relevant on multi-arch
systems only. Please note that if a package is Architecture: all,
this value is not "all", but the architecture of the package file
it comes from.
.. versionadded:: 0.7.100.3
.. attribute:: current_ver
The version currently installed as a :class:`Version` object, or None
if the package is not installed.
.. method:: get_fullname([pretty: bool = False]) -> str
Get the full name of the package, including the architecture. If
*pretty* is ``True``, the architecture is omitted for native packages,
that is, an amd64 "apt" package on an amd64 system would give "apt".
.. versionadded:: 0.7.100.3
.. attribute:: has_provides
A boolean value determining whether the list available via the
attribute :attr:`provides_list` has at least one element. This
value may be used in combination with :attr:`has_versions` to
check whether a package is virtual; that is, it has no versions
and is provided at least once::
pkg.has_provides and not pkg.has_versions
.. attribute:: has_versions
A boolean value determining whether the list available via the
attribute :attr:`version_list` has at least one element. This
value may be used in combination with :attr:`has_provides` to
check whether a package is virtual; that is, it has no versions
and is provided at least once::
pkg.has_provides and not pkg.has_versions
.. attribute:: id
The ID of the package. This can be used to store information about
the package. The ID is an int value.
.. attribute:: name
This is the name of the package.
.. attribute:: provides_list
A list of all package versions providing this package. Each element
of the list is a triplet, where the first element is the name of the
provided package, the second element the provided version (empty
string), and the third element the version providing this package
as a :class:`Version` object.
.. attribute:: rev_depends_list
An iterator of :class:`Dependency` objects for dependencies on this
package. The returned iterator is implemented by the class
:class:`DependencyList`:
.. class:: DependencyList
A simple list-like type for representing multiple dependency
objects in an efficient manner; without having to generate
all Dependency objects in advance.
.. describe:: list[index]
Return the item at the position *index* in the list.
.. method:: __len__()
The length of the list. This method should not be used
irectly, instead Python's built-in function :func:`len`
should be used.
.. attribute:: section
The section of the package, as specified in the record. The list of
possible sections is defined in the Policy. This is a string.
.. deprecated:: 1.0
A package can have multiple versions with different sections, so
the section information should be accessed from the version class.
.. attribute:: version_list
A list of :class:`Version` objects for all versions of this package
available in the cache.
**States**:
.. attribute:: selected_state
The state we want it to be, ie. if you mark a package for installation,
this is :attr:`apt_pkg.SELSTATE_INSTALL`.
See :ref:`SelStates` for a list of available states.
.. attribute:: inst_state
The state the currently installed version is in. This is normally
:attr:`apt_pkg.INSTSTATE_OK`, unless the installation failed.
See :ref:`InstStates` for a list of available states.
.. attribute:: current_state
The current state of the package (not installed, unpacked, installed,
etc). See :ref:`CurStates` for a list of available states.
**Flags**:
.. attribute:: essential
Whether the package has the 'Essential' flag set; that is,
whether it has a field 'Essential: yes' in its record.
.. attribute:: important
Whether the package has the (obsolete) 'Important' flag set; that is,
whether it has a field 'Important: yes' in its record.
Example:
~~~~~~~~~
.. literalinclude:: ../examples/cache-packages.py
:class:`Version`
^^^^^^^^^^^^^^^^^
.. class:: Version
The version object contains all information related to a specific package
version.
.. attribute:: arch
The architecture of the package, eg. amd64 or all.
.. attribute:: depends_list
This is basically the same as :attr:`depends_list_str`,
but instead of the ('pkgname', 'version', 'relation') tuples,
it returns :class:`Dependency` objects, which can assist you with
useful functions.
.. attribute:: depends_list_str
A dictionary of dependencies. The key specifies the type of the
dependency ('Depends', 'Recommends', etc.).
The value is a list, containing items which refer to the or-groups of
dependencies. Each of these or-groups is itself a list, containing
tuples like ('pkgname', 'version', 'relation') for each or-choice.
An example return value for a package with a 'Depends: python (>= 2.4)'
would be::
{'Depends': [
[
('python', '2.4', '>=')
]
]
}
The same for a dependency on A (>= 1) | B (>= 2)::
{'Depends': [
[
('A', '1', '>='),
('B', '2', '>='),
]
]
}
The comparison operators are not the Debian ones, but the standard
comparison operators as used in languages such as C and Python. This
means that '>' means "larger than" and '<' means "less than".
.. attribute:: downloadable
Whether this package can be downloaded from a remote site.
.. attribute:: file_list
A list of (:class:`PackageFile`, int: index) tuples for all Package
files containing this version of the package.
.. attribute:: hash
An integer hash value used for the internal storage.
.. attribute:: id
A numeric identifier which uniquely identifies this version in all
versions in the cache.
.. attribute:: installed_size
The size of the package (in kilobytes), when unpacked on the disk.
.. attribute:: multi_arch
The multi-arch state of the package. Can be one of the following
attributes.
.. attribute:: MULTI_ARCH_NO
No multi-arch
.. attribute:: MULTI_ARCH_ALL
An ``Architecture: all`` package
.. attribute:: MULTI_ARCH_FOREIGN
Can satisfy dependencies of foreign-architecture
packages
.. attribute:: MULTI_ARCH_ALL_FOREIGN
:attr:`MULTI_ARCH_FOREIGN` for ``Architecture: all``
packages.
.. attribute:: MULTI_ARCH_SAME
Multiple versions from different architectures may be
installed in parallel, but may only satisfy dependencies
of packages from the same architecture
.. attribute:: MULTI_ARCH_ALLOWED
Installation in parallel and satisfying ``pkg:any``
style dependencies is allowed.
.. attribute:: MULTI_ARCH_ALL_ALLOWED
:attr:`MULTI_ARCH_ALLOWED` for ``Architecture: all``
packages.
.. attribute:: parent_pkg
The :class:`Package` object this version belongs to.
.. attribute:: priority
The integer representation of the priority. This can be used to speed
up comparisons a lot, compared to :attr:`priority_str`.
The values are defined in the :mod:`apt_pkg` extension, see
:ref:`Priorities` for more information.
.. attribute:: priority_str
Return the priority of the package version, as a string, eg.
"optional".
.. attribute:: provides_list
This returns a list of all packages provided by this version. Like
:attr:`Package.provides_list`, it returns a list of tuples
of the form ('virtualpkgname', '', :class:`Version`), where as the
last item is the same as the object itself.
.. attribute:: section
The usual sections (eg. admin, net, etc.). Prefixed with the component
name for packages not in main (eg. non-free/admin).
.. attribute:: size
The size of the .deb file, in bytes.
.. attribute:: translated_description
Return a :class:`Description` object for the translated description
of this package version.
.. attribute:: ver_str
The version, as a string.
:class:`Dependency`
^^^^^^^^^^^^^^^^^^^^
.. class:: Dependency
Represent a dependency from one package to another one.
.. method:: all_targets
A list of all possible target :class:`Version` objects which satisfy
this dependency.
.. attribute:: comp_type
The type of comparison (<,<=,=,!=,>=,>,), as string. Note that the
empty string is a valid string as well, if no version is specified.
.. attribute:: dep_type
The type of the dependency, as string, eg. "Depends".
.. attribute:: dep_type_enum
The type of the dependency, as an integer which can be compared to
one of the TYPE_* constants below.
.. attribute:: dep_type_untranslated
The type of the depndency, as an untranslated string.
.. attribute:: id
The ID of the package, as integer.
.. attribute:: parent_pkg
The :class:`Package` object of the package which declares the
dependency. This is the same as using ParentVer.ParentPkg.
.. attribute:: parent_ver
The :class:`Version` object of the parent version, ie. the package
which declares the dependency.
.. attribute:: target_pkg
The :class:`Package` object of the target package.
.. attribute:: target_ver
The target version of the dependency, as string. Empty string if the
dependency is not versioned.
The following constants describe all values the attribute *dep_type_enum*
can take:
.. attribute:: TYPE_CONFLICTS
Constant for checking against dep_type_enum
.. attribute:: TYPE_DEPENDS
Constant for checking against dep_type_enum
.. attribute:: TYPE_DPKG_BREAKS
Constant for checking against dep_type_enum
.. attribute:: TYPE_ENHANCES
Constant for checking against dep_type_enum
.. attribute:: TYPE_OBSOLETES
Constant for checking against dep_type_enum
.. attribute:: TYPE_PREDEPENDS
Constant for checking against dep_type_enum
.. attribute:: TYPE_RECOMMENDS
Constant for checking against dep_type_enum
.. attribute:: TYPE_REPLACES
Constant for checking against dep_type_enum
.. attribute:: TYPE_SUGGESTS
Constant for checking against dep_type_enum
Example: Find all missing dependencies
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
With the help of Dependency.AllTargets(), you can easily find all packages with
broken dependencies:
.. literalinclude:: ../examples/missing-deps.py
:class:`Description`
^^^^^^^^^^^^^^^^^^^^^
.. class:: Description
Represent the description of the package.
.. attribute:: language_code
The language code of the description; or, if the description
is untranslated, an empty string.
.. attribute:: md5
The MD5 checksum of the description.
.. attribute:: file_list
A list of tuples ``(packagefile: PackageFile, index: int)``.
Package Pinning with :class:`Policy`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. class:: Policy(cache: apt_pkg.Cache)
Representation of the policy of the :class:`Cache` object given by
*cache*. This provides a superset of policy-related functionality
compared to the *DepCache* class. The DepCache can be used for most
purposes, but there may be some cases where a special policy class
is needed.
.. method:: create_pin(type: str, pkg: str, data: str, priority: int)
Create a pin for the policy. The parameter *type* refers to one of the
strings 'Version', 'Release', or 'Origin'. The argument *pkg* is the
name of the package. The parameter *data* refers to the value (such
as 'unstable' for type='Release') and the other possible options.
The parameter 'priority' gives the priority of the pin.
.. automethod:: init_defaults
.. method:: get_candidate_ver(package: apt_pkg.Package) -> apt_pkg.Version
Get the best package for the job; that is, the package with the
highest pin priority.
.. method:: get_priority(package: Union[apt_pkg.Version, apt_pkg.PackageFile]) -> int
Get the pin priority of the package, version, or package file
given by *package*.
.. versionchanged:: 1.7
Introduce support for per-version pins. Deprecated support
for :class:`apt_pkg.Package`.
.. method:: read_pindir(dirname: str) -> bool
Read the pin files in the given dir (e.g. '/etc/apt/preferences.d')
and add them to the policy.
.. method:: read_pinfile(filename: str) -> bool
Read the pin file given by *filename* (e.g. '/etc/apt/preferences')
and add it to the policy.
Index Files
-------------
.. class:: MetaIndex
Represent a Release file as stored in the cache.
.. attribute:: uri
The URI the meta index file is located at, as a string.
.. attribute:: dist
The distribution stored in the meta index, as a string.
.. attribute:: is_trusted
A boolean value determining whether the meta index can be trusted. This
is ``True`` for signed Release files.
.. attribute:: index_files
A list of all :class:`IndexFile` objects associated with this meta
index.
.. class:: IndexFile
Represent an index file, that is, package indexes, translation indexes,
and source indexes.
.. method:: archive_uri(path: str) -> str
Return the URI to the given path in the archive.
.. attribute:: label
The label of the index file.
.. attribute:: describe
A string describing this object.
.. attribute:: exists
A boolean value determining whether the index file exists.
.. attribute:: has_packages
A boolean value determining whether the index file has packages.
.. attribute:: size
The size of the file, measured in bytes.
.. attribute:: is_trusted
A boolean value determining whether the file can be trusted; that is,
because it is from a source with a GPG signed Release file.
.. class:: PackageFile
Provide access to an index file stored in the cache, such as
:file:`/var/lib/dpkg/status`.
.. attribute:: architecture
The architecture of the package file. This attribute normally
contains an empty string and is thus not very useful.
.. attribute:: archive
The archive of the package file as set in the Release file via
the "Suite" field. If there is no Release file, this is an empty
string.
.. attribute:: component
The component of the package file, if it is provided by a repository
using the dists/ hierarchy. For other packages files, this property
is an empty string.
.. attribute:: filename
The path to the file on the local filesystem.
.. attribute:: id
The ID of the package. This is an integer which can be used to store
further information about the file [eg. as dictionary key].
.. attribute:: index_type
A string describing the type of index. Known values are
"Debian Package Index", "Debian Translation Index", and
"Debian dpkg status file".
.. attribute:: label
The label of the package file as set in the release file
via the 'Label' field. If there is no Release file, this
attribute is an empty string.
.. attribute:: not_automatic
Whether packages from this list will be updated automatically. The
default for example is False.
.. attribute:: not_source
Whether the file has no source from which it can be updated. In such a
case, the value is ``True``; else ``False``. For example, it is
``False`` for :file:`/var/lib/dpkg/status`.
Example::
for pkgfile in cache.file_list:
if pkgfile.not_source:
print('The file %s has no source.' % pkgfile.filename)
.. attribute:: origin
The Origin, as set in the Release file
.. attribute:: site
The hostname of the site.
.. attribute:: size
The size of the file.
.. attribute:: version
The version, as set in the release file (eg. "4.0" for "Etch")
The following example shows how to use PackageFile:
.. literalinclude:: ../examples/cache-pkgfile.py
Records (Release files, Packages, Sources)
------------------------------------------
.. class:: IndexRecords()
Represent a Release file and provide means to read information from
the file. This class provides several methods:
.. method:: get_dist() -> str
Return the distribution set in the Release file.
.. method:: load(filename: str)
Load the file located at the path given by *filename*.
.. method:: lookup(key: str) -> (HashString, int)
Look up the filename given by *key* and return a tuple (hash, size),
where the first element *hash* is a :class:`HashString` object
and the second element *size* is an int object.
.. class:: PackageRecords(cache: apt_pkg.Cache)
Provide further information about the packages in the :class:`Cache` object
*cache*. This efficiently parses the package files to provide information
not available in the cache, such as maintainer, hash sums, description,
and the file name of the package. It also provides the complete record
of the package.
.. method:: lookup(verfile_iter: (PackageFile, int)) -> bool
Change the actual package to the package given by the verfile_iter.
The parameter *verfile_iter* refers to a tuple consisting
of (:class:`PackageFile()`, int: index), as returned by various
``file_list`` attributes such as :attr:`Version.file_list`.
Example (shortened)::
cand = depcache.get_candidate_ver(cache['python-apt'])
records.lookup(cand.file_list[0])
# Now you can access the record
print(records.source_pkg) # == python-apt
.. describe:: section[key]
Return the value of the field at *key*. If *key* is not available,
raise :exc:`KeyError`.
Raises AttributeError if not yet looked up.
.. versionadded:: 1.7
.. describe:: key in section
Return ``True`` if *section* has a key *key*, else ``False``.
Raises AttributeError if not yet looked up.
.. versionadded:: 1.7
.. attribute:: filename
Return the field 'Filename' of the record. This is the path to the
package, relative to the base path of the archive.
.. attribute:: hashes
A :class:`apt_pkg.HashStringList` of all hashes.
.. versionadded:: 1.1
.. attribute:: md5_hash
Return the MD5 hashsum of the package This refers to the field
'MD5Sum' in the raw record.
.. deprecated:: 1.1
Use :attr:`hashes` instead.
.. attribute:: sha1_hash
Return the SHA1 hashsum of the package. This refers to the field 'SHA1'
in the raw record.
.. deprecated:: 1.1
Use :attr:`hashes` instead.
.. attribute:: sha256_hash
Return the SHA256 hashsum of the package. This refers to the field
'SHA256' in the raw record.
.. versionadded:: 0.7.9
.. deprecated:: 1.1
Use :attr:`hashes` instead.
.. attribute:: source_pkg
The name of the source package, if different from the name of the
binary package. This information is retrieved from the 'Source' field.
.. attribute:: source_ver
The version of the source package, if it differs from the version
of the binary package. Just like 'source_pkg', this information
is retrieved from the 'Source' field.
.. attribute:: maintainer
Return the maintainer of the package.
.. attribute:: short_desc
Return the short description. This is the summary on the first line of
the 'Description' field.
.. attribute:: long_desc
Return the long description. These are lines 2-END from the
'Description' field.
.. attribute:: name
Return the name of the package. This is the 'Package' field.
.. attribute:: homepage
Return the Homepage. This is the 'Homepage' field.
.. attribute:: record
Return the whole record as a string. If you want to access fields of
the record not available as an attribute, you can use
:class:`apt_pkg.TagSection` to parse the record and access the field
name.
.. deprecated:: 1.7
This property can be considered deprecated for simple string
lookups, as keys can now be looked up in the record itself.
Example::
section = apt_pkg.TagSection(records.record)
print(section['SHA256']) # Use records.sha256_hash instead
.. class:: SourceRecords
Provide an easy way to look up the records of source packages and
provide easy attributes for some widely used fields of the record.
.. note::
If the Lookup failed, because no package could be found, no error is
raised. Instead, the attributes listed below are simply not existing
anymore (same applies when no Lookup has been made, or when it has
been restarted).
.. method:: lookup(pkgname: str) -> bool
Look up the source package with the given name. Each call moves
the position of the records parser forward. If there are no
more records, return None. If the lookup failed this way,
access to any of the attributes will result in an
:exc:`AttributeError`.
Imagine a package P with two versions X, Y. The first ``lookup(P)``
would set the record to version X and the second ``lookup(P)`` to
version Y. A third call would return ``None`` and access to any
of the below attributes will result in an :exc:`AttributeError`
.. method:: restart()
Restart the lookup process. This moves the parser to the first
package and lookups can now be made just like on a new object.
Imagine a package P with two versions X, Y. The first ``Lookup(P)``
would set the record to version X and the second ``Lookup(P)`` to
version Y. If you now call ``restart()``, the internal position
will be cleared. Now you can call ``lookup(P)`` again to move to X.
.. attribute:: binaries
Return a list of strings describing the package names of the binaries
created by the source package. This matches the 'Binary' field in the
raw record.
.. attribute:: build_depends
Return a dictionary representing the build-time dependencies of the
package. The format is the same as for :attr:`Version.depends_list_str`
and possible keys being ``"Build-Depends"``, ``"Build-Depends-Indep"``,
``"Build-Conflicts"`` or ``"Build-Conflicts-Indep"``.
.. attribute:: files
The list of files. This returns a list of :class:`SourceRecordsFile`
.. versionchanged:: 1.6
Used to be a list of tuples, see :class:`SourceRecordFile` for the tuple
layout.
.. attribute:: index
A list of :class:`IndexFile` objects associated with this
source package record.
.. attribute:: maintainer
A string describing the name of the maintainer.
.. attribute:: package
The name of the source package.
.. attribute:: record
The whole record, as a string. You can use :func:`apt_pkg.ParseSection`
if you need to parse it. You need to parse the record to access
fields not available via the attributes such as 'Standards-Version'
.. attribute:: section
A string describing the section.
.. attribute:: version
A string describing the version of the source package.
.. class:: SourceRecordsFile
Represents a file in a source record.
.. versionadded:: 1.6
Before 1.6, this was a tuple `(md5, size, path, type)`.
.. attribute:: hashes
A :class:`HashStringList` of the file's hashes.
.. attribute:: path
The path to the file
.. attribute:: size
The size of the file
.. attribute:: type
The type of the file. Can be 'diff' (includes .debian.tar.gz), 'dsc', or 'tar'.
The Acquire interface
----------------------
The Acquire Interface is responsible for all sorts of downloading in apt. All
packages, index files, etc. downloading is done using the Acquire functionality.
The :mod:`apt_pkg` module provides a subset of this functionality which allows
you to implement file downloading in your applications. Together with the
:class:`PackageManager` class you can also fetch all the packages marked for
installation.
.. class:: Acquire([progress: apt.progress.base.AcquireProgress])
Coordinate the retrieval of files via network or local file system
(using ``copy://path/to/file`` style URIs). Items can be added to
an Acquire object using various means such as creating instances
of :class:`AcquireFile` or the methods :meth:`SourceList.get_indexes`
and :meth:`PackageManager.get_archives`.
Acquire objects maintain a list of items which will be fetched or have
been fetched already during the lifetime of this object. To add new items
to this list, you can create new :class:`AcquireFile` objects which allow
you to add single files.
The constructor takes an optional parameter *progress* which takes an
:class:`apt.progress.base.AcquireProgress` object. This object may then
report progress information (see :mod:`apt.progress.text` for reporting
progress to a I/O stream).
Acquire items have two methods to start and stop the fetching:
.. method:: run() -> int
Fetch all the items which have been added by :class:`AcquireFile` and
return one of the constants :attr:`RESULT_CANCELLED`,
:attr:`RESULT_CONTINUE`, :attr:`RESULT_FAILED` to describe the
result of the run.
.. method:: shutdown()
Shut the fetcher down. This removes all items from the queue and
makes all :class:`AcquireItem`, :class:`AcquireWorker`,
:class:`AcquireItemDesc` objects useless. Accessing an object of one
of those types can cause a segfault then.
Removing an item does not mean that the already fetched data will
be removed from the destination. Instead, APT might use the partial
result and continue from thereon.
Furthermore, they provide three attributes which provide information
on how much data is already available and how much data still needs
to be fetched:
.. attribute:: fetch_needed
The amount of data that has to be fetched in order to fetch all
queued items.
.. attribute:: partial_present
The amount of data which is already available.
.. attribute:: total_needed
The total amount of bytes needed (including those of files which are
already present).
They also provide two attributes representing the items being processed
and the workers fetching them:
.. attribute:: items
A list of :class:`AcquireItem` objects which are attached to the
to this Acquire object. This includes all items ever attached to
this object (except if they were removed using, for example,
:meth:`shutdown()` or by deleting an :class:`AcquireFile` object.)
.. attribute:: workers
A list of :class:`AcquireWorker` objects which are currently active
on this instance.
The Acquire class comes with three constants which represents the results
of the :meth:`run` method:
.. attribute:: RESULT_CANCELLED
The fetching has been aborted, e.g. due to a progress class returning
``False`` in its :meth:`pulse()` method.
.. attribute:: RESULT_CONTINUE
All items have been fetched successfully or failed transiently
and the process has not been canceled.
You need to look at the status of each item and check if it has not
failed transiently to discover errors like a Not Found when acquiring
packages.
.. attribute:: RESULT_FAILED
An item failed to fetch due to some reasons.
.. class:: AcquireItem
An AcquireItem object represents a single item of an :class:`Acquire`
object. It is an abstract class to represent various types of items
which are implemented as subclasses. The only exported subclass is
:class:`AcquireFile` which can be used to fetch files.
.. attribute:: complete
A boolean value which is True only if the item has been
fetched successfully.
.. attribute:: desc_uri
An URI describing where the item is located at.
.. attribute:: destfile
The path to the local location where the fetched data will be
stored at.
.. attribute:: error_text
The error message. For example, when a file does not exist on a HTTP
server, this will contain a 404 error message.
.. attribute:: filesize
The size of the file, in bytes. If the size of the to be fetched file
is unknown, this attribute is set to ``0``.
.. attribute:: id
The ID of the item. This attribute is normally set to ``0``, users may
set a custom value here, for instance in an overridden
:meth:`apt.progress.base.AcquireProgress.fetch` method (the progress
class could keep a counter, increase it by one for every :meth:`fetch`
call and assign the current value to this attribute).
.. attribute:: is_trusted
A boolean value determining whether the file is trusted. Only ``True``
if the item represents a package coming from a repository which is
signed by one of the keys in APT's keyring.
.. attribute:: local
A boolean value determining whether this file is locally available
(``True``) or whether it has to be fetched from a remote source
(``False``).
.. attribute:: mode
Old name for active_subprocess
.. deprecated:: 1.0
.. attribute:: active_subprocess
The name of the active subprocess (for instance, 'gzip', 'rred' or 'gpgv').
.. versionadded:: 1.0
**Status**:
The following attribute represents the status of the item. This class
provides several constants for comparing against this value which are
listed here as well.
.. attribute:: status
Integer, representing the status of the item. This attribute can be
compared against the following constants to gain useful information
on the item's status.
.. attribute:: STAT_AUTH_ERROR
An authentication error occurred while trying to fetch the item.
.. attribute:: STAT_DONE
The item is completely fetched and there have been no problems
while fetching the item.
.. attribute:: STAT_ERROR
An error occurred while trying to fetch the item. This error is
normally not related to authentication problems, as thus are
dealt with using :attr:`STAT_AUTH_ERROR`.
.. attribute:: STAT_FETCHING
The item is being fetched currently.
.. attribute:: STAT_IDLE
The item is yet to be fetched.
.. attribute:: STAT_TRANSIENT_NETWORK_ERROR
There was a network error.
.. class:: AcquireFile(owner, uri[, hash, size, descr, short_descr, destdir, destfile])
Create a new :class:`AcquireFile()` object and register it with *acquire*,
so it will be fetched. You must always keep around a reference to the
object, otherwise it will be removed from the Acquire queue again.
The parameter *owner* refers to an :class:`Acquire()` object as returned
by :func:`GetAcquire`. The file will be added to the Acquire queue
automatically.
The parameter *uri* refers to the location of the file, any protocol
of apt is supported.
The parameter *hash* refers to the hash of the file. If this is set
libapt will check the file after downloading. This should be an instance
of :class:`apt_pkg.HashStringList`.
The parameter *size* can be used to specify the size of the package,
which can then be used to calculate the progress and validate the download.
The parameter *descr* is a description of the download. It may be
used to describe the item in the progress class. *short_descr* is the
short form of it.
The parameters *descr* and *short_descr* can be used to specify
descriptions for the item. The string passed to *descr* should
describe the file and its origin (e.g. "http://localhost sid/main
python-apt 0.7.94.2") and the string passed to *short_descr* should
be one word such as the name of a package.
Normally, the file will be stored in the current directory using the
file name given in the URI. This directory can be changed by passing
the name of a directory to the *destdir* parameter. It is also possible
to set a path to a file using the *destfile* parameter, but both can
not be specified together.
In terms of attributes, this class is a subclass of :class:`AcquireItem`
and thus inherits all its attributes.
.. versionchanged:: 1.9.1
The *hash* parameter now accepts an :class:`apt_pkg.HashStringList`,
the old *md5* parameter has been removed.
.. class:: AcquireWorker
An :class:`AcquireWorker` object represents a sub-process responsible for
fetching files from remote locations. There is no possibility to create
instances of this class from within Python, but a list of objects of
currently active workers is provided by :attr:`Acquire.workers`.
Objects of this type provide several attributes which give information
about the worker's current activity.
.. attribute:: current_item
The item which is currently being fetched. This returns an
:class:`AcquireItemDesc` object.
.. attribute:: current_size
How many bytes of the file have been downloaded. Zero if the current
progress of the file cannot be determined.
.. attribute:: resumepoint
The amount of data which was already available when the download was
started.
.. attribute:: status
The most recent (localized) status string received from the
sub-process.
.. attribute:: total_size
The total number of bytes to be downloaded for the item. Zero if the
total size is unknown.
.. class:: AcquireItemDesc
An :class:`AcquireItemDesc` object stores information about the item which
can be used to describe the item. Objects of this class are used in the
progress classes, see the :class:`apt.progress.base.AcquireProgress`
documentation for information how.
.. attribute:: description
The long description given to the item.
.. attribute:: owner
The :class:`AcquireItem` object owning this object.
.. attribute:: shortdesc
A short description which has been given to this item.
.. attribute:: uri
The URI from which this item would be downloaded.
Hashes
------
The apt_pkg module also provides several hash functions. If you develop
applications with python-apt it is often easier to use these functions instead
of the ones provides in Python's :mod:`hashlib` module.
The module provides the two classes :class:`Hashes` and :class:`HashString` for
generic hash support:
.. autoclass:: Hashes
:members:
.. class:: HashString(type: str[, hash: str])
HashString objects store the type of a hash and the corresponding hash.
They are used by e.g :meth:`IndexRecords.lookup`. The first parameter,
*type* refers to one of "MD5Sum", "SHA1" and "SHA256". The second parameter
*hash* is the corresponding hash.
You can also use a combined form by passing a string with type and hash
separated by a colon as the only argument. For example::
HashString("MD5Sum:d41d8cd98f00b204e9800998ecf8427e")
.. describe:: str(hashstring)
Convert the HashString to a string by joining the hash type and the
hash using ':', e.g. ``"MD5Sum:d41d8cd98f00b204e9800998ecf8427e"``.
.. attribute:: hashtype
The type of the hash, as a string. This may be "MD5Sum", "SHA1",
"SHA256" or "SHA512".
.. autoattribute:: hashvalue
.. autoattribute:: usable
.. method:: verify_file(filename: str) -> bool
Verify that the file given by the parameter *filename* matches the
hash stored in this object.
.. autoclass:: HashStringList
:members:
.. describe:: len(list)
Return the length of the list
.. describe:: list[index]
Get the :class:`HashString` object at the specified index.
The :mod:`apt_pkg` module also provides the functions :func:`md5sum`,
:func:`sha1sum` and :func:`sha256sum` for creating a single hash from a
:class:`bytes` or :class:`file` object:
.. function:: md5sum(object)
Return the md5sum of the object. *object* may either be a string, in
which case the md5sum of the string is returned, or a :class:`file()`
object (or a file descriptor), in which case the md5sum of its contents is
returned.
.. versionchanged:: 0.7.100
Added support for using file descriptors.
.. deprecated:: 1.9
Use :class:`apt_pkg.Hashes` instead. This function will be removed
in a later release.
.. function:: sha1sum(object)
Return the sha1sum of the object. *object* may either be a string, in
which case the sha1sum of the string is returned, or a :class:`file()`
object (or a file descriptor), in which case the sha1sum of its contents
is returned.
.. versionchanged:: 0.7.100
Added support for using file descriptors.
.. deprecated:: 1.9
Use :class:`apt_pkg.Hashes` instead. This function will be removed
in a later release.
.. function:: sha256sum(object)
Return the sha256sum of the object. *object* may either be a string, in
which case the sha256sum of the string is returned, or a :class:`file()`
object (or a file descriptor), in which case the sha256sum of its contents
is returned.
.. versionchanged:: 0.7.100
Added support for using file descriptors.
.. deprecated:: 1.9
Use :class:`apt_pkg.Hashes` instead. This function will be removed
in a later release.
Debian control files
--------------------
Debian control files are files containing multiple stanzas of :RFC:`822`-style
header sections. They are widely used in the Debian community, and can represent
many kinds of information. One example for such a file is the
:file:`/var/lib/dpkg/status` file which contains a list of the currently
installed packages.
The :mod:`apt_pkg` module provides two classes to read those files and parts
thereof and provides a function :func:`RewriteSection` which takes a
:class:`TagSection()` object and sorting information and outputs a sorted
section as a string.
.. class:: TagFile(file, bytes: bool = False)
An object which represents a typical debian control file. Can be used for
Packages, Sources, control, Release, etc.
The *file* argument shall be a path name or an open file object. The
argument *bytes* specifies whether the file shall be represented using
bytes (``True``) or unicode (``False``) strings.
It is a context manager that can be used with a with statement or the
:meth:`close` method.
.. describe:: with TagFile(...) as ...:
Use the :class:`TagFile` as a context manager. This will automatically
close the file after the body finished execution.
.. versionadded:: 1.0
.. method:: close()
Close the file. It's recommended to use the context manager
instead (that is, the `with` statement).
.. versionadded:: 1.0
It provides two kinds of API which should not be used together:
The first API implements the iterator protocol and should be used whenever
possible because it has less side effects than the other one. It may be
used e.g. with a for loop::
with apt_pkg.TagFile('/var/lib/dpkg/status') as tagfile:
for section in tagfile:
print(section['Package'])
.. versionchanged:: 0.7.100
Added support for using gzip files, via :class:`gzip.GzipFile` or any
file containing a compressed gzip stream.
.. versionadded:: 0.8.5
Added support for using bytes instead of str in Python 3
.. method:: next()
A TagFile is its own iterator. This method is part of the iterator
protocol and returns a :class:`TagSection` object for the next
section in the file. If there is no further section, this method
raises the :exc:`StopIteration` exception.
From Python 3 on, this method is not available anymore, and the
global function ``next()`` replaces it.
The second API uses a shared :class:`TagSection` object which is exposed
through the :attr:`section` attribute. This object is modified by calls
to :meth:`step` and :meth:`jump`. This API provides more control and may
use less memory, but is not recommended because it works by modifying
one object. It can be used like this::
with apt_pkg.TagFile('/var/lib/dpkg/status') as tagf:
tagf.step()
print tagf.section['Package']
.. method:: step() -> bool
Step forward to the next section. This simply returns ``True`` if OK,
and ``False`` if there is no section.
.. method:: offset() -> int
Return the current offset (in bytes) from the beginning of the file.
.. method:: jump(offset) -> bool
Jump back/forward to *offset*. Use ``jump(0)`` to jump to the
beginning of the file again. Returns ``True`` if a section could
be parsed or ``False`` if not.
.. attribute:: section
This is the current :class:`TagSection()` instance.
.. class:: TagSection(text)
Represent a single section of a debian control file.
.. describe:: section[key]
Return the value of the field at *key*. If *key* is not available,
raise :exc:`KeyError`.
.. describe:: key in section
Return ``True`` if *section* has a key *key*, else ``False``.
.. versionadded:: 0.7.100
.. method:: bytes() -> int
The number of bytes in the section.
.. method:: find(key: str, default: str = '') -> str
Return the value of the field at the key *key* if available,
else return *default*.
.. method:: find_flag(key: str) -> bool
Find a yes/no value for the key *key*. An example for such a
field is 'Essential'.
.. method:: find_raw(key: str, default: str = '') -> str
Similar to :meth:`find`, but instead of returning just the value,
it returns the complete field consisting of 'key: value'.
.. method:: get(key: str, default: str = '')
Return the value of the field at the key *key* if available, else
return *default*.
.. method:: keys()
Return a list of keys in the section.
.. automethod:: write
A function can be rewritten by using tag classes:
.. autoclass:: Tag
:members:
The following static members can be used to determine the meaning of
:attr:`action`:
.. data:: REWRITE
Change the field value to the value of :attr:`data`
.. data:: RENAME
Rename the tag to a new tag stored in :attr:`data`.
.. data:: REMOVE
Remove the tag.
Apart from this, the class provides access to several attributes.
.. autoclass:: TagRewrite
.. autoclass:: TagRemove
.. autoclass:: TagRename
Pre-defined ordering for tag sections are:
.. data:: REWRITE_PACKAGE_ORDER
The order in which the information for binary packages should be rewritten,
i.e. the order in which the fields should appear.
.. data:: REWRITE_SOURCE_ORDER
The order in which the information for source packages should be rewritten,
i.e. the order in which the fields should appear.
Dependencies
------------
.. function:: check_dep(pkgver: str, op: str, depver: str) -> bool
Check that the given requirement is fulfilled; that is, that the version
string given by *pkg_ver* matches the version string *dep_ver* under
the condition specified by the operator 'dep_op' (<,<=,=,>=,>).
Return True if *pkg_ver* matches *dep_ver* under the condition 'dep_op';
for example::
>>> apt_pkg.check_dep("1.0", ">=", "1")
True
The following two functions provide the ability to parse dependencies. They
use the same format as :attr:`Version.depends_list_str`.
.. function:: parse_depends(depends, strip_multiarch=True, architecture)
Parse the string *depends* which contains dependency information as
specified in Debian Policy, Section 7.1.
Returns a list. The members of this list are lists themselves and contain
one or more tuples in the format ``(package,version,operation)`` for every
'or'-option given, e.g.::
>>> apt_pkg.parse_depends("PkgA (>= VerA) | PkgB (>= VerB)")
[[('PkgA', 'VerA', '>='), ('PkgB', 'VerB', '>=')]]
Note that multiarch dependency information is stripped off by default.
You can force the full dependency info (including the multiarch info)
by passing "False" as a additional parameter to this function.
You can specify an optional argument *architecture* that treats the given
architecture as the native architecture for purposes of parsing the
dependency.
.. note::
The behavior of this function is different than the behavior of the
old function :func:`ParseDepends()`, because the third field
``operation`` uses `>` instead of `>>` and `<` instead of `<<` which
is specified in control files.
.. function:: parse_src_depends(depends, strip_multiarch=True, architecture)
Parse the string *depends* which contains dependency information as
specified in Debian Policy, Section 7.1.
Returns a list. The members of this list are lists themselves and contain
one or more tuples in the format ``(package,version,operation)`` for every
'or'-option given, e.g.::
>>> apt_pkg.parse_depends("PkgA (>= VerA) | PkgB (>= VerB)")
[[('PkgA', 'VerA', '>='), ('PkgB', 'VerB', '>=')]]
Furthemore, this function also supports to limit the architectures, as
used in e.g. Build-Depends::
>>> apt_pkg.parse_src_depends("a (>= 01) [i386 amd64]")
[[('a', '01', '>=')]]
Note that multiarch dependency information is stripped off by default.
You can force the full dependency info (including the multiarch info)
by passing "False" as a additional parameter to this function.
You can specify an optional argument *architecture* that treats the given
architecture as the native architecture for purposes of parsing the
dependency.
.. note::
The behavior of this function is different than the behavior of the
old function :func:`ParseDepends()`, because the third field
``operation`` uses `>` instead of `>>` and `<` instead of `<<` which
is specified in control files.
Configuration and Command-line parsing
--------------------------------------
.. class:: Configuration()
Provide access to and manipulation of APT's configuration which is
used by many classes and functions in this module to define their
behavior. There are options to install recommends, change the root
directory and much more. For an (incomplete) list of available options,
see the :manpage:`apt.conf(5)` manual page.
The most important Configuration object is the one available by the
module's :attr:`apt_pkg.config` attribute. It stores the global
configuration which affects the behavior of most functions and is
initialized by a call to the function :func:`init_config`. While
possible, it is generally not needed to create other instances of
this class.
For accessing and manipulating the configuration space, objects
of this type provide an interface which resembles Python mapping
types like :class:`dict`.
.. describe:: key in conf
Return ``True`` if *conf* has a key *key*, else ``False``.
.. describe:: conf[key]
Return the value of the option given key *key*. If it does not
exist, raise :exc:`KeyError`.
.. describe:: conf[key] = value
Set the option at *key* to *value*.
.. describe del conf[key]
Delete the option with the name *key* in the configuration object
*conf*.
.. method:: get(key[, default='']) -> str
Find the value for the given key and return it. If the given key does
not exist, return *default* instead.
In addition, they provide methods to resemble the interface provided
by the C++ class and some more mapping methods which have been enhanced
to support some more advanced configuration features:
.. method:: clear(key: str)
Remove the option at *key* and all of its children.
.. method:: dump() -> str
Return a string containing the values in the configuration object,
in the standard :manpage:`apt.conf(5)` format.
.. versionadded:: 0.7.100
.. method:: exists(key)
Check whether an option named *key* exists in the configuration.
.. method:: find(key[, default='']) -> str
Return the value stored at the option named *key*, or the value
given by the string *default* if the option in question is not
set.
.. method:: find_b(key[, default=False]) -> bool
Return the boolean value stored at *key*, or the value given by
the :class:`bool` object *default* if the requested option is
not set.
.. method:: find_file(key[, default='']) -> str
find_dir(key[, default='/']) -> str
Locate the given key using :meth:`find` and return the path to the
file/directory. This uses a special algorithms which moves upwards
in the configuration space and prepends the values of the options
to the result. These methods are generally used for the options
stored in the 'Dir' section of the configuration.
As an example of how this works, take a look at the following options
and their values:
.. table::
============== ===========================
Option Value
============== ===========================
Dir /
Dir::Etc etc/apt/
Dir::Etc::main apt.conf
============== ===========================
A call to :meth:`find_file` would now return ``/etc/apt/apt.conf``
because it prepends the values of "Dir::Etc" and "Dir" to the value
of "Dir::Etc::main"::
>>> apt_pkg.config.find_file("Dir::Etc::main")
'/etc/apt/apt.conf'
If the special configuration variable "RootDir" is set, this value
would be prepended to every return value, even if the path is already
absolute. If not, the function ends as soon as an absolute path is
created (once an option with a value starting with "/" is read).
The method :meth:`find_dir` does exactly the same thing as
:meth:`find_file`, but adds a trailing forward slash before
returning the value.
.. method:: find_i(key[, default=0]) -> int
Return the integer value stored at *key*, or the value given by
the integer *default* if the requested option is not set.
.. method:: keys([key])
Return a recursive list of all configuration options or, if *key*
is given, a list of all its children. This method is comparable
to the **keys** method of a mapping object, but additionally
provides the parameter *key*.
.. method:: list([key])
Return a non-recursive list of all configuration options. If *key*
is not given, this returns a list of options like "Apt", "Dir", and
similar. If *key* is given, a list of the names of its child options
will be returned instead.
.. method:: my_tag()
Return the tag name of the current tree. Normally (for
:data:`apt_pkg.config`) this is an empty string, but for
sub-trees it is the key of the sub-tree.
.. method:: set(key: str, value: str)
Set the option named *key* to the value given by the argument
*value*. It is possible to store objects of the types :class:`int`
and :class:`bool` by calling :func:`str` on them to convert them
to a string object. They can then be retrieved again by using the
methods :meth:`find_i` or :meth:`find_b`.
.. method:: subtree(key)
Return a new apt_pkg.Configuration object which starts at the
given option. Example::
apttree = config.subtree('APT')
apttree['Install-Suggests'] = config['APT::Install-Suggests']
The configuration space is shared with the main object which means
that all modifications in one object appear in the other one as
well.
.. method:: value_list([key])
This is the opposite of the :meth:`list` method in that it returns the
values instead of the option names.
.. data:: config
This variable contains the global configuration which is used by
all classes and functions in this module. After importing the
module, this object should be initialized by calling the module's
:func:`init_config` function.
.. function:: read_config_file(configuration: Configuration, filename: str)
Read the configuration file *filename* and set the appropriate
options in the configuration object *configuration*.
.. function:: read_config_dir(configuration, dirname)
Read all configuration files in the dir given by 'dirname' in the
correct order.
.. function:: read_config_file_isc(configuration, filename)
Read the configuration file *filename* and set the appropriate
options in the configuration object *configuration*. This function
requires a slightly different format than APT configuration files,
if you are unsure, do not use it.
.. function:: parse_commandline(configuration, options, argv)
Parse the command line in *argv* into the configuration space. The
list *options* contains a list of 3-tuples or 4-tuples in the form::
(short_option: str, long_option: str, variable: str[, type: str])
The element *short_option* is one character, the *long_option* element
is the name of the long option, the element *variable* the name of the
configuration option the result will be stored in and *type* is one of
'HasArg', 'IntLevel', 'Boolean', 'InvBoolean', 'ConfigFile',
'ArbItem'. The default type is 'Boolean'.
.. table:: Overview of all possible types
=========== =====================================================
Type What happens if the option is given
=========== =====================================================
HasArg The argument given to the option is stored in
the target.
IntLevel The integer value in the target is increased by one
Boolean The target variable is set to True.
InvBoolean The target variable is set to False.
ConfigFile The file given as an argument to this option is read
in and all configuration options are added to the
configuration object (APT's '-c' option).
ArbItem The option takes an argument *key*=*value*, and the
configuration option at *key* is set to the value
*value* (APT's '-o' option).
=========== =====================================================
Locking
--------
When working on the global cache, it is important to lock the cache so other
programs do not modify it. This module provides two context managers for
locking the package system or file-based locking.
.. class:: SystemLock
Context manager for locking the package system. The lock is established
as soon as the method __enter__() is called. It is released when
__exit__() is called. If the lock can not be acquired or can not be
released an exception is raised.
This should be used via the 'with' statement. For example::
with apt_pkg.SystemLock():
... # Do your stuff here.
... # Now it's unlocked again
Once the block is left, the lock is released automatically. The object
can be used multiple times::
lock = apt_pkg.SystemLock()
with lock:
...
with lock:
...
.. class:: FileLock(filename: str)
Context manager for locking using a file. The lock is established
as soon as the method __enter__() is called. It is released when
__exit__() is called. If the lock can not be acquired or can not be
released, an exception is raised.
This should be used via the 'with' statement. For example::
with apt_pkg.FileLock(filename):
...
Once the block is left, the lock is released automatically. The object
can be used multiple times::
lock = apt_pkg.FileLock(filename)
with lock:
...
with lock:
...
For Python versions prior to 2.5, similar functionality is provided by the
following three functions:
.. function:: get_lock(filename: str, errors=False) -> int
Create an empty file at the path specified by the parameter *filename* and
lock it. If this fails and *errors* is **True**, the function raises an
error. If *errors* is **False**, the function returns -1.
The lock can be acquired multiple times within the same process, and can be
released by calling :func:`os.close` on the return value which is the file
descriptor of the created file.
.. function:: pkgsystem_lock()
Lock the global pkgsystem. The lock should be released by calling
:func:`pkgsystem_unlock` again. If this function is called n-times, the
:func:`pkgsystem_unlock` function must be called n-times as well to release
all acquired locks.
.. function:: pkgsystem_unlock()
Unlock the global pkgsystem. This reverts the effect of
:func:`pkgsystem_lock`.
Since version 1.7, APT switches to the frontend locking approach where
dpkg has two lock files, :file:`lock-frontend` and :file:`lock`, the
latter being called the inner lock in apt.
When running dpkg, the inner lock must be released before calling dpkg
and reacquired afterwards. When not using APT functions to run dpkg,
the variable `DPKG_FRONTEND_LOCKED` must be set to tell dpkg to not
acquire the :file:`lock-frontend` lock.
These functions usually do not need to be used by external code.
.. function:: pkgsystem_unlock_inner()
Release the :file:`lock` lock file to allow dpkg to be run.
.. versionadded:: 1.7
.. function:: pkgsystem_lock_inner()
Release the :file:`lock` lock file after a dpkg run.
.. versionadded:: 1.7
.. function:: pkgsystem_is_locked()
Returns true if the global lock is hold. Can be used to check whether
:meth:`pkgsystem_unlock_inner` needs to be called.
.. versionadded:: 1.7
Other classes
--------------
.. class:: Cdrom()
A Cdrom object identifies Debian installation media and adds them to
:file:`/etc/apt/sources.list`. The C++ version of this class is used by
the apt-cdrom tool and using this class, you can re-implement apt-cdrom
in Python, see :doc:`../tutorials/apt-cdrom`.
The class :class:`apt.cdrom.Cdrom` is a subclass of this class and
provides some additional functionality for higher level use and some
shortcuts for setting some related configuration options.
This class provides two functions which take an instance of
:class:`apt.progress.base.CdromProgress` as their argument.
.. method:: add(progress: apt.progress.base.CdromProgress) -> bool
Search for a Debian installation media and add it to the list of
sources stored in :file:`/etc/apt/sources.list`. On success, the
boolean value ``True`` is returned. If the process failed or was
canceled by the progress class, :exc:`SystemError` is raised or
``False`` is returned.
.. method:: ident(progress: apt.progress.base.CdromProgress) -> str
Identify the installation media and return a string which describes
its identity. If no media could be identified, :exc:`SystemError` is
raised or ``None`` is returned.
.. class:: SourceList
Represent the list of sources stored in files such as
:file:`/etc/apt/sources.list`.
.. method:: find_index(pkgfile: PackageFile) -> IndexFile
Return the :class:`IndexFile` object for the :class:`PackageFile`
object given by the argument *pkgfile*. If no index could be found,
return ``None``.
.. method:: get_indexes(acquire: Acquire[, all: bool = False]) -> bool
Add all indexes to the :class:`Acquire` object given by the argument
*acquire*. If *all* is ``True``, all indexes will be added, otherwise
only the meta indexes (Release files) will be added and others are
fetched as needed.
.. method:: read_main_list() -> bool
Read the files configured in Dir::Etc::SourceList and
Dir::Etc::sourceparts; that is (on normal system),
:file:`/etc/apt/sources.list` and the files in
:file:`/etc/apt/sources.list.d`.
.. attribute:: list
A list of :class:`MetaIndex` objects.
String functions
----------------
.. function:: base64_encode(value: bytes) -> str
Encode the given bytes string (which may not contain a null byte)
using base64, for example, on Python 3 and newer::
>>> apt_pkg.base64_encode(b"A")
'QQ=='
on Python versions prior to 3, the 'b' before the string has to be
omitted.
.. function:: check_domain_list(host, list)
See if the host name given by *host* is one of the domains given in the
comma-separated list *list* or a subdomain of one of them.
>>> apt_pkg.check_domain_list("alioth.debian.org","debian.net,debian.org")
True
.. function:: dequote_string(string: str)
Dequote the string specified by the parameter *string*, e.g.::
>>> apt_pkg.dequote_string("%61%70%74%20is%20cool")
'apt is cool'
.. function:: quote_string(string, repl)
Escape the string *string*, replacing any character not allowed in a URL
or specified by *repl* with its ASCII value preceded by a percent sign
(so for example ' ' becomes '%20').
>>> apt_pkg.quote_string("apt is cool","apt")
'%61%70%74%20is%20cool'
.. function:: size_to_str(size: int)
Return a string describing the size in a human-readable manner using
SI prefix and base-10 units, e.g. '1k' for 1000, '1M' for 1000000, etc.
Example::
>>> apt_pkg.size_to_str(10000)
'10.0k'
.. function:: string_to_bool(input)
Parse the string *input* and return one of **-1**, **0**, **1**.
.. table:: Return values
===== =============================================
Value Meaning
===== =============================================
-1 The string *input* is not recognized.
0 The string *input* evaluates to **False**.
+1 The string *input* evaluates to **True**.
===== =============================================
Example::
>>> apt_pkg.string_to_bool("yes")
1
>>> apt_pkg.string_to_bool("no")
0
>>> apt_pkg.string_to_bool("not-recognized")
-1
.. function:: str_to_time(rfc_time)
Convert the :rfc:`1123` conforming string *rfc_time* to the unix time, and
return the integer. This is the opposite of :func:`TimeRFC1123`.
Example::
>> apt_pkg.str_to_time('Thu, 01 Jan 1970 00:00:00 GMT')
0
.. function:: time_rfc1123(seconds: int) -> str
Format the unix time specified by the integer *seconds*, according to the
requirements of :rfc:`1123`.
Example::
>>> apt_pkg.time_rfc1123(0)
'Thu, 01 Jan 1970 00:00:00 GMT'
.. function:: time_to_str(seconds: int) -> str
Format a given duration in a human-readable manner. The parameter *seconds*
refers to a number of seconds, given as an integer. The return value is a
string with a unit like 's' for seconds.
Example::
>>> apt_pkg.time_to_str(3601)
'1h0min1s'
.. function:: upstream_version(version: str) -> str
Return the upstream version for the Debian package version given by
*version*.
.. function:: uri_to_filename(uri: str) -> str
Take a string *uri* as parameter and return a filename which can be used to
store the file, based on the URI.
Example::
>>> apt_pkg.uri_to_filename('http://debian.org/index.html')
'debian.org_index.html'
.. function:: version_compare(a: str, b: str) -> int
Compare two versions, *a* and *b*, and return an integer value which has
the same meaning as the built-in :func:`cmp` function's return value has,
see the following table for details.
.. table:: Return values
===== =============================================
Value Meaning
===== =============================================
> 0 The version *a* is greater than version *b*.
= 0 Both versions are equal.
< 0 The version *a* is less than version *b*.
===== =============================================
Module Constants
----------------
.. _CurStates:
Package States
^^^^^^^^^^^^^^^
.. data:: CURSTATE_CONFIG_FILES
Only the configuration files of the package exist on the system.
.. data:: CURSTATE_HALF_CONFIGURED
The package is unpacked and configuration has been started, but not
yet completed.
.. data:: CURSTATE_HALF_INSTALLED
The installation of the package has been started, but not completed.
.. data:: CURSTATE_INSTALLED
The package is unpacked, configured and OK.
.. data:: CURSTATE_NOT_INSTALLED
The package is not installed.
.. data:: CURSTATE_UNPACKED
The package is unpacked, but not configured.
.. _InstStates:
Installed states
^^^^^^^^^^^^^^^^
.. data:: INSTSTATE_HOLD
The package is put on hold.
.. data:: INSTSTATE_HOLD_REINSTREQ
The package is put on hold, but broken and has to be reinstalled.
.. data:: INSTSTATE_OK
The package is OK.
.. data:: INSTSTATE_REINSTREQ
The package is broken and has to be reinstalled.
.. _Priorities:
Priorities
^^^^^^^^^^^
.. data:: PRI_EXTRA
The integer representation of the priority 'extra'.
.. data:: PRI_IMPORTANT
The integer representation of the priority 'important'.
.. data:: PRI_OPTIONAL
The integer representation of the priority 'optional'.
.. data:: PRI_REQUIRED
The integer representation of the priority 'required'.
.. data:: PRI_STANDARD
The integer representation of the priority 'standard'.
.. _SelStates:
Package selection states
^^^^^^^^^^^^^^^^^^^^^^^^
.. data:: SELSTATE_DEINSTALL
The package is selected for deinstallation.
.. data:: SELSTATE_HOLD
The package is marked to be on hold and will not be modified.
.. data:: SELSTATE_INSTALL
The package is selected for installation.
.. data:: SELSTATE_PURGE
The package is selected to be purged.
.. data:: SELSTATE_UNKNOWN
The package is in an unknown state.
Build information
^^^^^^^^^^^^^^^^^
.. data:: DATE
The date on which this extension has been compiled.
.. data:: LIB_VERSION
The version of the apt_pkg library. This is **not** the version of apt,
nor the version of python-apt.
.. data:: TIME
The time this extension has been built.
.. data:: VERSION
The version of apt (not of python-apt).
|