/usr/lib/python3/dist-packages/CedarBackup3/config.py is in cedar-backup3 3.1.12-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 | # -*- coding: iso-8859-1 -*-
# vim: set ft=python ts=3 sw=3 expandtab:
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# C E D A R
# S O L U T I O N S "Software done right."
# S O F T W A R E
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# Copyright (c) 2004-2008,2010,2015 Kenneth J. Pronovici.
# All rights reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License,
# Version 2, as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Copies of the GNU General Public License are available from
# the Free Software Foundation website, http://www.gnu.org/.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# Author : Kenneth J. Pronovici <pronovic@ieee.org>
# Language : Python 3 (>= 3.4)
# Project : Cedar Backup, release 3
# Purpose : Provides configuration-related objects.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
########################################################################
# Module documentation
########################################################################
"""
Provides configuration-related objects.
Summary
=======
Cedar Backup stores all of its configuration in an XML document typically
called ``cback3.conf``. The standard location for this document is in
``/etc``, but users can specify a different location if they want to.
The ``Config`` class is a Python object representation of a Cedar Backup XML
configuration file. The representation is two-way: XML data can be used to
create a ``Config`` object, and then changes to the object can be propogated
back to disk. A ``Config`` object can even be used to create a configuration
file from scratch programmatically.
The ``Config`` class is intended to be the only Python-language interface to
Cedar Backup configuration on disk. Cedar Backup will use the class as its
internal representation of configuration, and applications external to Cedar
Backup itself (such as a hypothetical third-party configuration tool written
in Python or a third party extension module) should also use the class when
they need to read and write configuration files.
Backwards Compatibility
=======================
The configuration file format has changed between Cedar Backup 1.x and Cedar
Backup 2.x. Any Cedar Backup 1.x configuration file is also a valid Cedar
Backup 2.x configuration file. However, it doesn't work to go the other
direction, as the 2.x configuration files contains additional configuration
is not accepted by older versions of the software.
XML Configuration Structure
===========================
A ``Config`` object can either be created "empty", or can be created based on
XML input (either in the form of a string or read in from a file on disk).
Generally speaking, the XML input *must* result in a ``Config`` object which
passes the validations laid out below in the *Validation* section.
An XML configuration file is composed of seven sections:
- *reference*: specifies reference information about the file (author, revision, etc)
- *extensions*: specifies mappings to Cedar Backup extensions (external code)
- *options*: specifies global configuration options
- *peers*: specifies the set of peers in a master's backup pool
- *collect*: specifies configuration related to the collect action
- *stage*: specifies configuration related to the stage action
- *store*: specifies configuration related to the store action
- *purge*: specifies configuration related to the purge action
Each section is represented by an class in this module, and then the overall
``Config`` class is a composition of the various other classes.
Any configuration section that is missing in the XML document (or has not
been filled into an "empty" document) will just be set to ``None`` in the
object representation. The same goes for individual fields within each
configuration section. Keep in mind that the document might not be
completely valid if some sections or fields aren't filled in - but that
won't matter until validation takes place (see the *Validation* section
below).
Unicode vs. String Data
=======================
By default, all string data that comes out of XML documents in Python is
unicode data (i.e. ``u"whatever"``). This is fine for many things, but when
it comes to filesystem paths, it can cause us some problems. We really want
strings to be encoded in the filesystem encoding rather than being unicode.
So, most elements in configuration which represent filesystem paths are
coverted to plain strings using :any:`util.encodePath`. The main exception is
the various ``absoluteExcludePath`` and ``relativeExcludePath`` lists. These
are *not* converted, because they are generally only used for filtering,
not for filesystem operations.
Validation
==========
There are two main levels of validation in the ``Config`` class and its
children. The first is field-level validation. Field-level validation
comes into play when a given field in an object is assigned to or updated.
We use Python's ``property`` functionality to enforce specific validations on
field values, and in some places we even use customized list classes to
enforce validations on list members. You should expect to catch a
``ValueError`` exception when making assignments to configuration class
fields.
The second level of validation is post-completion validation. Certain
validations don't make sense until a document is fully "complete". We don't
want these validations to apply all of the time, because it would make
building up a document from scratch a real pain. For instance, we might
have to do things in the right order to keep from throwing exceptions, etc.
All of these post-completion validations are encapsulated in the
:any:`Config.validate` method. This method can be called at any time by a
client, and will always be called immediately after creating a ``Config``
object from XML data and before exporting a ``Config`` object to XML. This
way, we get decent ease-of-use but we also don't accept or emit invalid
configuration files.
The :any:`Config.validate` implementation actually takes two passes to
completely validate a configuration document. The first pass at validation
is to ensure that the proper sections are filled into the document. There
are default requirements, but the caller has the opportunity to override
these defaults.
The second pass at validation ensures that any filled-in section contains
valid data. Any section which is not set to ``None`` is validated according
to the rules for that section (see below).
*Reference Validations*
No validations.
*Extensions Validations*
The list of actions may be either ``None`` or an empty list ``[]`` if desired.
Each extended action must include a name, a module and a function. Then, an
extended action must include either an index or dependency information.
Which one is required depends on which order mode is configured.
*Options Validations*
All fields must be filled in except the rsh command. The rcp and rsh
commands are used as default values for all remote peers. Remote peers can
also rely on the backup user as the default remote user name if they choose.
*Peers Validations*
Local peers must be completely filled in, including both name and collect
directory. Remote peers must also fill in the name and collect directory,
but can leave the remote user and rcp command unset. In this case, the
remote user is assumed to match the backup user from the options section and
rcp command is taken directly from the options section.
*Collect Validations*
The target directory must be filled in. The collect mode, archive mode and
ignore file are all optional. The list of absolute paths to exclude and
patterns to exclude may be either ``None`` or an empty list ``[]`` if desired.
Each collect directory entry must contain an absolute path to collect, and
then must either be able to take collect mode, archive mode and ignore file
configuration from the parent ``CollectConfig`` object, or must set each
value on its own. The list of absolute paths to exclude, relative paths to
exclude and patterns to exclude may be either ``None`` or an empty list ``[]``
if desired. Any list of absolute paths to exclude or patterns to exclude
will be combined with the same list in the ``CollectConfig`` object to make
the complete list for a given directory.
*Stage Validations*
The target directory must be filled in. There must be at least one peer
(remote or local) between the two lists of peers. A list with no entries
can be either ``None`` or an empty list ``[]`` if desired.
If a set of peers is provided, this configuration completely overrides
configuration in the peers configuration section, and the same validations
apply.
*Store Validations*
The device type and drive speed are optional, and all other values are
required (missing booleans will be set to defaults, which is OK).
The image writer functionality in the ``writer`` module is supposed to be
able to handle a device speed of ``None``. Any caller which needs a "real"
(non-``None``) value for the device type can use ``DEFAULT_DEVICE_TYPE``,
which is guaranteed to be sensible.
*Purge Validations*
The list of purge directories may be either ``None`` or an empty list ``[]``
if desired. All purge directories must contain a path and a retain days
value.
Module Attributes
=================
Attributes:
DEFAULT_DEVICE_TYPE: The default device type
DEFAULT_MEDIA_TYPE: The default media type
VALID_DEVICE_TYPES: List of valid device types
VALID_MEDIA_TYPES: List of valid media types
VALID_COLLECT_MODES: List of valid collect modes
VALID_COMPRESS_MODES: List of valid compress modes
VALID_ARCHIVE_MODES: List of valid archive modes
VALID_ORDER_MODES: List of valid extension order modes
:author: Kenneth J. Pronovici <pronovic@ieee.org>
"""
########################################################################
# Imported modules
########################################################################
# System modules
import os
import re
import logging
from functools import total_ordering
# Cedar Backup modules
from CedarBackup3.writers.util import validateScsiId, validateDriveSpeed
from CedarBackup3.util import UnorderedList, AbsolutePathList, ObjectTypeList, parseCommaSeparatedString
from CedarBackup3.util import RegexMatchList, RegexList, encodePath, checkUnique
from CedarBackup3.util import convertSize, displayBytes, UNIT_BYTES, UNIT_KBYTES, UNIT_MBYTES, UNIT_GBYTES
from CedarBackup3.xmlutil import isElement, readChildren, readFirstChild
from CedarBackup3.xmlutil import readStringList, readString, readInteger, readBoolean
from CedarBackup3.xmlutil import addContainerNode, addStringNode, addIntegerNode, addBooleanNode
from CedarBackup3.xmlutil import createInputDom, createOutputDom, serializeDom
########################################################################
# Module-wide constants and variables
########################################################################
logger = logging.getLogger("CedarBackup3.log.config")
DEFAULT_DEVICE_TYPE = "cdwriter"
DEFAULT_MEDIA_TYPE = "cdrw-74"
VALID_DEVICE_TYPES = [ "cdwriter", "dvdwriter", ]
VALID_CD_MEDIA_TYPES = [ "cdr-74", "cdrw-74", "cdr-80", "cdrw-80", ]
VALID_DVD_MEDIA_TYPES = [ "dvd+r", "dvd+rw", ]
VALID_MEDIA_TYPES = VALID_CD_MEDIA_TYPES + VALID_DVD_MEDIA_TYPES
VALID_COLLECT_MODES = [ "daily", "weekly", "incr", ]
VALID_ARCHIVE_MODES = [ "tar", "targz", "tarbz2", ]
VALID_COMPRESS_MODES = [ "none", "gzip", "bzip2", ]
VALID_ORDER_MODES = [ "index", "dependency", ]
VALID_BLANK_MODES = [ "daily", "weekly", ]
VALID_BYTE_UNITS = [ UNIT_BYTES, UNIT_KBYTES, UNIT_MBYTES, UNIT_GBYTES, ]
VALID_FAILURE_MODES = [ "none", "all", "daily", "weekly", ]
REWRITABLE_MEDIA_TYPES = [ "cdrw-74", "cdrw-80", "dvd+rw", ]
ACTION_NAME_REGEX = r"^[a-z0-9]*$"
########################################################################
# ByteQuantity class definition
########################################################################
@total_ordering
class ByteQuantity(object):
"""
Class representing a byte quantity.
A byte quantity has both a quantity and a byte-related unit. Units are
maintained using the constants from util.py. If no units are provided,
``UNIT_BYTES`` is assumed.
The quantity is maintained internally as a string so that issues of
precision can be avoided. It really isn't possible to store a floating
point number here while being able to losslessly translate back and forth
between XML and object representations. (Perhaps the Python 2.4 Decimal
class would have been an option, but I originally wanted to stay compatible
with Python 2.3.)
Even though the quantity is maintained as a string, the string must be in a
valid floating point positive number. Technically, any floating point
string format supported by Python is allowble. However, it does not make
sense to have a negative quantity of bytes in this context.
"""
def __init__(self, quantity=None, units=None):
"""
Constructor for the ``ByteQuantity`` class.
Args:
quantity: Quantity of bytes, something interpretable as a float
units: Unit of bytes, one of VALID_BYTE_UNITS
Raises:
ValueError: If one of the values is invalid
"""
self._quantity = None
self._units = None
self.quantity = quantity
self.units = units
def __repr__(self):
"""
Official string representation for class instance.
"""
return "ByteQuantity(%s, %s)" % (self.quantity, self.units)
def __str__(self):
"""
Informal string representation for class instance.
"""
return "%s" % displayBytes(self.bytes)
def __eq__(self, other):
"""Equals operator, implemented in terms of Python 2-style compare operator."""
return self.__cmp__(other) == 0
def __lt__(self, other):
"""Less-than operator, implemented in terms of Python 2-style compare operator."""
return self.__cmp__(other) < 0
def __gt__(self, other):
"""Greater-than operator, implemented in terms of Python 2-style compare operator."""
return self.__cmp__(other) > 0
def __cmp__(self, other):
"""
Python 2-style comparison operator.
Args:
other: Other object to compare to
Returns:
-1/0/1 depending on whether self is ``<``, ``=`` or ``>`` other
"""
if other is None:
return 1
elif isinstance(other, ByteQuantity):
if self.bytes != other.bytes:
if self.bytes < other.bytes:
return -1
else:
return 1
return 0
else:
return self.__cmp__(ByteQuantity(other, UNIT_BYTES)) # will fail if other can't be coverted to float
def _setQuantity(self, value):
"""
Property target used to set the quantity
The value must be interpretable as a float if it is not None
Raises:
ValueError: If the value is an empty string
ValueError: If the value is not a valid floating point number
ValueError: If the value is less than zero
"""
if value is None:
self._quantity = None
else:
try:
floatValue = float(value) # allow integer, float, string, etc.
except:
raise ValueError("Quantity must be interpretable as a float")
if floatValue < 0.0:
raise ValueError("Quantity cannot be negative.")
self._quantity = str(value) # keep around string
def _getQuantity(self):
"""
Property target used to get the quantity.
"""
return self._quantity
def _setUnits(self, value):
"""
Property target used to set the units value.
If not ``None``, the units value must be one of the values in :any:`VALID_BYTE_UNITS`.
Raises:
ValueError: If the value is not valid
"""
if value is None:
self._units = UNIT_BYTES
else:
if value not in VALID_BYTE_UNITS:
raise ValueError("Units value must be one of %s." % VALID_BYTE_UNITS)
self._units = value
def _getUnits(self):
"""
Property target used to get the units value.
"""
return self._units
def _getBytes(self):
"""
Property target used to return the byte quantity as a floating point number.
If there is no quantity set, then a value of 0.0 is returned.
"""
if self.quantity is not None and self.units is not None:
return convertSize(self.quantity, self.units, UNIT_BYTES)
return 0.0
quantity = property(_getQuantity, _setQuantity, None, doc="Byte quantity, as a string")
units = property(_getUnits, _setUnits, None, doc="Units for byte quantity, for instance UNIT_BYTES")
bytes = property(_getBytes, None, None, doc="Byte quantity, as a floating point number.")
########################################################################
# ActionDependencies class definition
########################################################################
@total_ordering
class ActionDependencies(object):
"""
Class representing dependencies associated with an extended action.
Execution ordering for extended actions is done in one of two ways: either by using
index values (lower index gets run first) or by having the extended action specify
dependencies in terms of other named actions. This class encapsulates the dependency
information for an extended action.
The following restrictions exist on data in this class:
- Any action name must be a non-empty string matching ``ACTION_NAME_REGEX``
"""
def __init__(self, beforeList=None, afterList=None):
"""
Constructor for the ``ActionDependencies`` class.
Args:
beforeList: List of named actions that this action must be run before
afterList: List of named actions that this action must be run after
Raises:
ValueError: If one of the values is invalid
"""
self._beforeList = None
self._afterList = None
self.beforeList = beforeList
self.afterList = afterList
def __repr__(self):
"""
Official string representation for class instance.
"""
return "ActionDependencies(%s, %s)" % (self.beforeList, self.afterList)
def __str__(self):
"""
Informal string representation for class instance.
"""
return self.__repr__()
def __eq__(self, other):
"""Equals operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) == 0
def __lt__(self, other):
"""Less-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) < 0
def __gt__(self, other):
"""Greater-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) > 0
def __cmp__(self, other):
"""
Original Python 2 comparison operator.
Args:
other: Other object to compare to
Returns:
-1/0/1 depending on whether self is ``<``, ``=`` or ``>`` other
"""
if other is None:
return 1
if self.beforeList != other.beforeList:
if self.beforeList < other.beforeList:
return -1
else:
return 1
if self.afterList != other.afterList:
if self.afterList < other.afterList:
return -1
else:
return 1
return 0
def _setBeforeList(self, value):
"""
Property target used to set the "run before" list.
Either the value must be ``None`` or each element must be a string matching ACTION_NAME_REGEX.
Raises:
ValueError: If the value does not match the regular expression
"""
if value is None:
self._beforeList = None
else:
try:
saved = self._beforeList
self._beforeList = RegexMatchList(ACTION_NAME_REGEX, emptyAllowed=False, prefix="Action name")
self._beforeList.extend(value)
except Exception as e:
self._beforeList = saved
raise e
def _getBeforeList(self):
"""
Property target used to get the "run before" list.
"""
return self._beforeList
def _setAfterList(self, value):
"""
Property target used to set the "run after" list.
Either the value must be ``None`` or each element must be a string matching ACTION_NAME_REGEX.
Raises:
ValueError: If the value does not match the regular expression
"""
if value is None:
self._afterList = None
else:
try:
saved = self._afterList
self._afterList = RegexMatchList(ACTION_NAME_REGEX, emptyAllowed=False, prefix="Action name")
self._afterList.extend(value)
except Exception as e:
self._afterList = saved
raise e
def _getAfterList(self):
"""
Property target used to get the "run after" list.
"""
return self._afterList
beforeList = property(_getBeforeList, _setBeforeList, None, "List of named actions that this action must be run before.")
afterList = property(_getAfterList, _setAfterList, None, "List of named actions that this action must be run after.")
########################################################################
# ActionHook class definition
########################################################################
@total_ordering
class ActionHook(object):
"""
Class representing a hook associated with an action.
A hook associated with an action is a shell command to be executed either
before or after a named action is executed.
The following restrictions exist on data in this class:
- The action name must be a non-empty string matching ``ACTION_NAME_REGEX``
- The shell command must be a non-empty string.
The internal ``before`` and ``after`` instance variables are always set to
False in this parent class.
"""
def __init__(self, action=None, command=None):
"""
Constructor for the ``ActionHook`` class.
Args:
action: Action this hook is associated with
command: Shell command to execute
Raises:
ValueError: If one of the values is invalid
"""
self._action = None
self._command = None
self._before = False
self._after = False
self.action = action
self.command = command
def __repr__(self):
"""
Official string representation for class instance.
"""
return "ActionHook(%s, %s, %s, %s)" % (self.action, self.command, self.before, self.after)
def __str__(self):
"""
Informal string representation for class instance.
"""
return self.__repr__()
def __eq__(self, other):
"""Equals operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) == 0
def __lt__(self, other):
"""Less-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) < 0
def __gt__(self, other):
"""Greater-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) > 0
def __cmp__(self, other):
"""
Original Python 2 comparison operator.
Args:
other: Other object to compare to
Returns:
-1/0/1 depending on whether self is ``<``, ``=`` or ``>`` other
"""
if other is None:
return 1
if self.action != other.action:
if str(self.action or "") < str(other.action or ""):
return -1
else:
return 1
if self.command != other.command:
if str(self.command or "") < str(other.command or ""):
return -1
else:
return 1
if self.before != other.before:
if self.before < other.before:
return -1
else:
return 1
if self.after != other.after:
if self.after < other.after:
return -1
else:
return 1
return 0
def _setAction(self, value):
"""
Property target used to set the action name.
The value must be a non-empty string if it is not ``None``.
It must also consist only of lower-case letters and digits.
Raises:
ValueError: If the value is an empty string
"""
pattern = re.compile(ACTION_NAME_REGEX)
if value is not None:
if len(value) < 1:
raise ValueError("The action name must be a non-empty string.")
if not pattern.search(value):
raise ValueError("The action name must consist of only lower-case letters and digits.")
self._action = value
def _getAction(self):
"""
Property target used to get the action name.
"""
return self._action
def _setCommand(self, value):
"""
Property target used to set the command.
The value must be a non-empty string if it is not ``None``.
Raises:
ValueError: If the value is an empty string
"""
if value is not None:
if len(value) < 1:
raise ValueError("The command must be a non-empty string.")
self._command = value
def _getCommand(self):
"""
Property target used to get the command.
"""
return self._command
def _getBefore(self):
"""
Property target used to get the before flag.
"""
return self._before
def _getAfter(self):
"""
Property target used to get the after flag.
"""
return self._after
action = property(_getAction, _setAction, None, "Action this hook is associated with.")
command = property(_getCommand, _setCommand, None, "Shell command to execute.")
before = property(_getBefore, None, None, "Indicates whether command should be executed before action.")
after = property(_getAfter, None, None, "Indicates whether command should be executed after action.")
@total_ordering
class PreActionHook(ActionHook):
"""
Class representing a pre-action hook associated with an action.
A hook associated with an action is a shell command to be executed either
before or after a named action is executed. In this case, a pre-action hook
is executed before the named action.
The following restrictions exist on data in this class:
- The action name must be a non-empty string consisting of lower-case letters and digits.
- The shell command must be a non-empty string.
The internal ``before`` instance variable is always set to True in this
class.
"""
def __init__(self, action=None, command=None):
"""
Constructor for the ``PreActionHook`` class.
Args:
action: Action this hook is associated with
command: Shell command to execute
Raises:
ValueError: If one of the values is invalid
"""
ActionHook.__init__(self, action, command)
self._before = True
def __repr__(self):
"""
Official string representation for class instance.
"""
return "PreActionHook(%s, %s, %s, %s)" % (self.action, self.command, self.before, self.after)
@total_ordering
class PostActionHook(ActionHook):
"""
Class representing a pre-action hook associated with an action.
A hook associated with an action is a shell command to be executed either
before or after a named action is executed. In this case, a post-action hook
is executed after the named action.
The following restrictions exist on data in this class:
- The action name must be a non-empty string consisting of lower-case letters and digits.
- The shell command must be a non-empty string.
The internal ``before`` instance variable is always set to True in this
class.
"""
def __init__(self, action=None, command=None):
"""
Constructor for the ``PostActionHook`` class.
Args:
action: Action this hook is associated with
command: Shell command to execute
Raises:
ValueError: If one of the values is invalid
"""
ActionHook.__init__(self, action, command)
self._after = True
def __repr__(self):
"""
Official string representation for class instance.
"""
return "PostActionHook(%s, %s, %s, %s)" % (self.action, self.command, self.before, self.after)
########################################################################
# BlankBehavior class definition
########################################################################
@total_ordering
class BlankBehavior(object):
"""
Class representing optimized store-action media blanking behavior.
The following restrictions exist on data in this class:
- The blanking mode must be a one of the values in ``VALID_BLANK_MODES``
- The blanking factor must be a positive floating point number
"""
def __init__(self, blankMode=None, blankFactor=None):
"""
Constructor for the ``BlankBehavior`` class.
Args:
blankMode: Blanking mode
blankFactor: Blanking factor
Raises:
ValueError: If one of the values is invalid
"""
self._blankMode = None
self._blankFactor = None
self.blankMode = blankMode
self.blankFactor = blankFactor
def __repr__(self):
"""
Official string representation for class instance.
"""
return "BlankBehavior(%s, %s)" % (self.blankMode, self.blankFactor)
def __str__(self):
"""
Informal string representation for class instance.
"""
return self.__repr__()
def __eq__(self, other):
"""Equals operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) == 0
def __lt__(self, other):
"""Less-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) < 0
def __gt__(self, other):
"""Greater-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) > 0
def __cmp__(self, other):
"""
Original Python 2 comparison operator.
Args:
other: Other object to compare to
Returns:
-1/0/1 depending on whether self is ``<``, ``=`` or ``>`` other
"""
if other is None:
return 1
if self.blankMode != other.blankMode:
if str(self.blankMode or "") < str(other.blankMode or ""):
return -1
else:
return 1
if self.blankFactor != other.blankFactor:
if float(self.blankFactor or 0.0) < float(other.blankFactor or 0.0):
return -1
else:
return 1
return 0
def _setBlankMode(self, value):
"""
Property target used to set the blanking mode.
The value must be one of ``VALID_BLANK_MODES``.
Raises:
ValueError: If the value is not valid
"""
if value is not None:
if value not in VALID_BLANK_MODES:
raise ValueError("Blanking mode must be one of %s." % VALID_BLANK_MODES)
self._blankMode = value
def _getBlankMode(self):
"""
Property target used to get the blanking mode.
"""
return self._blankMode
def _setBlankFactor(self, value):
"""
Property target used to set the blanking factor.
The value must be a non-empty string if it is not ``None``.
Raises:
ValueError: If the value is an empty string
ValueError: If the value is not a valid floating point number
ValueError: If the value is less than zero
"""
if value is not None:
if len(value) < 1:
raise ValueError("Blanking factor must be a non-empty string.")
floatValue = float(value)
if floatValue < 0.0:
raise ValueError("Blanking factor cannot be negative.")
self._blankFactor = value # keep around string
def _getBlankFactor(self):
"""
Property target used to get the blanking factor.
"""
return self._blankFactor
blankMode = property(_getBlankMode, _setBlankMode, None, "Blanking mode")
blankFactor = property(_getBlankFactor, _setBlankFactor, None, "Blanking factor")
########################################################################
# ExtendedAction class definition
########################################################################
@total_ordering
class ExtendedAction(object):
"""
Class representing an extended action.
Essentially, an extended action needs to allow the following to happen::
exec("from %s import %s" % (module, function))
exec("%s(action, configPath")" % function)
The following restrictions exist on data in this class:
- The action name must be a non-empty string consisting of lower-case letters and digits.
- The module must be a non-empty string and a valid Python identifier.
- The function must be an on-empty string and a valid Python identifier.
- If set, the index must be a positive integer.
- If set, the dependencies attribute must be an ``ActionDependencies`` object.
"""
def __init__(self, name=None, module=None, function=None, index=None, dependencies=None):
"""
Constructor for the ``ExtendedAction`` class.
Args:
name: Name of the extended action
module: Name of the module containing the extended action function
function: Name of the extended action function
index: Index of action, used for execution ordering
dependencies: Dependencies for action, used for execution ordering
Raises:
ValueError: If one of the values is invalid
"""
self._name = None
self._module = None
self._function = None
self._index = None
self._dependencies = None
self.name = name
self.module = module
self.function = function
self.index = index
self.dependencies = dependencies
def __repr__(self):
"""
Official string representation for class instance.
"""
return "ExtendedAction(%s, %s, %s, %s, %s)" % (self.name, self.module, self.function, self.index, self.dependencies)
def __str__(self):
"""
Informal string representation for class instance.
"""
return self.__repr__()
def __eq__(self, other):
"""Equals operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) == 0
def __lt__(self, other):
"""Less-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) < 0
def __gt__(self, other):
"""Greater-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) > 0
def __cmp__(self, other):
"""
Original Python 2 comparison operator.
Args:
other: Other object to compare to
Returns:
-1/0/1 depending on whether self is ``<``, ``=`` or ``>`` other
"""
if other is None:
return 1
if self.name != other.name:
if str(self.name or "") < str(other.name or ""):
return -1
else:
return 1
if self.module != other.module:
if str(self.module or "") < str(other.module or ""):
return -1
else:
return 1
if self.function != other.function:
if str(self.function or "") < str(other.function or ""):
return -1
else:
return 1
if self.index != other.index:
if int(self.index or 0) < int(other.index or 0):
return -1
else:
return 1
if self.dependencies != other.dependencies:
if self.dependencies < other.dependencies:
return -1
else:
return 1
return 0
def _setName(self, value):
"""
Property target used to set the action name.
The value must be a non-empty string if it is not ``None``.
It must also consist only of lower-case letters and digits.
Raises:
ValueError: If the value is an empty string
"""
pattern = re.compile(ACTION_NAME_REGEX)
if value is not None:
if len(value) < 1:
raise ValueError("The action name must be a non-empty string.")
if not pattern.search(value):
raise ValueError("The action name must consist of only lower-case letters and digits.")
self._name = value
def _getName(self):
"""
Property target used to get the action name.
"""
return self._name
def _setModule(self, value):
"""
Property target used to set the module name.
The value must be a non-empty string if it is not ``None``.
It must also be a valid Python identifier.
Raises:
ValueError: If the value is an empty string
"""
pattern = re.compile(r"^([A-Za-z_][A-Za-z0-9_]*)(\.[A-Za-z_][A-Za-z0-9_]*)*$")
if value is not None:
if len(value) < 1:
raise ValueError("The module name must be a non-empty string.")
if not pattern.search(value):
raise ValueError("The module name must be a valid Python identifier.")
self._module = value
def _getModule(self):
"""
Property target used to get the module name.
"""
return self._module
def _setFunction(self, value):
"""
Property target used to set the function name.
The value must be a non-empty string if it is not ``None``.
It must also be a valid Python identifier.
Raises:
ValueError: If the value is an empty string
"""
pattern = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*$")
if value is not None:
if len(value) < 1:
raise ValueError("The function name must be a non-empty string.")
if not pattern.search(value):
raise ValueError("The function name must be a valid Python identifier.")
self._function = value
def _getFunction(self):
"""
Property target used to get the function name.
"""
return self._function
def _setIndex(self, value):
"""
Property target used to set the action index.
The value must be an integer >= 0.
Raises:
ValueError: If the value is not valid
"""
if value is None:
self._index = None
else:
try:
value = int(value)
except TypeError:
raise ValueError("Action index value must be an integer >= 0.")
if value < 0:
raise ValueError("Action index value must be an integer >= 0.")
self._index = value
def _getIndex(self):
"""
Property target used to get the action index.
"""
return self._index
def _setDependencies(self, value):
"""
Property target used to set the action dependencies information.
If not ``None``, the value must be a ``ActionDependecies`` object.
Raises:
ValueError: If the value is not a ``ActionDependencies`` object
"""
if value is None:
self._dependencies = None
else:
if not isinstance(value, ActionDependencies):
raise ValueError("Value must be a ``ActionDependencies`` object.")
self._dependencies = value
def _getDependencies(self):
"""
Property target used to get action dependencies information.
"""
return self._dependencies
name = property(_getName, _setName, None, "Name of the extended action.")
module = property(_getModule, _setModule, None, "Name of the module containing the extended action function.")
function = property(_getFunction, _setFunction, None, "Name of the extended action function.")
index = property(_getIndex, _setIndex, None, "Index of action, used for execution ordering.")
dependencies = property(_getDependencies, _setDependencies, None, "Dependencies for action, used for execution ordering.")
########################################################################
# CommandOverride class definition
########################################################################
@total_ordering
class CommandOverride(object):
"""
Class representing a piece of Cedar Backup command override configuration.
The following restrictions exist on data in this class:
- The absolute path must be absolute
*Note:* Lists within this class are "unordered" for equality comparisons.
"""
def __init__(self, command=None, absolutePath=None):
"""
Constructor for the ``CommandOverride`` class.
Args:
command: Name of command to be overridden
absolutePath: Absolute path of the overrridden command
Raises:
ValueError: If one of the values is invalid
"""
self._command = None
self._absolutePath = None
self.command = command
self.absolutePath = absolutePath
def __repr__(self):
"""
Official string representation for class instance.
"""
return "CommandOverride(%s, %s)" % (self.command, self.absolutePath)
def __str__(self):
"""
Informal string representation for class instance.
"""
return self.__repr__()
def __eq__(self, other):
"""Equals operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) == 0
def __lt__(self, other):
"""Less-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) < 0
def __gt__(self, other):
"""Greater-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) > 0
def __cmp__(self, other):
"""
Original Python 2 comparison operator.
Args:
other: Other object to compare to
Returns:
-1/0/1 depending on whether self is ``<``, ``=`` or ``>`` other
"""
if other is None:
return 1
if self.command != other.command:
if str(self.command or "") < str(other.command or ""):
return -1
else:
return 1
if self.absolutePath != other.absolutePath:
if str(self.absolutePath or "") < str(other.absolutePath or ""):
return -1
else:
return 1
return 0
def _setCommand(self, value):
"""
Property target used to set the command.
The value must be a non-empty string if it is not ``None``.
Raises:
ValueError: If the value is an empty string
"""
if value is not None:
if len(value) < 1:
raise ValueError("The command must be a non-empty string.")
self._command = value
def _getCommand(self):
"""
Property target used to get the command.
"""
return self._command
def _setAbsolutePath(self, value):
"""
Property target used to set the absolute path.
The value must be an absolute path if it is not ``None``.
It does not have to exist on disk at the time of assignment.
Raises:
ValueError: If the value is not an absolute path
ValueError: If the value cannot be encoded properly
"""
if value is not None:
if not os.path.isabs(value):
raise ValueError("Not an absolute path: [%s]" % value)
self._absolutePath = encodePath(value)
def _getAbsolutePath(self):
"""
Property target used to get the absolute path.
"""
return self._absolutePath
command = property(_getCommand, _setCommand, None, doc="Name of command to be overridden.")
absolutePath = property(_getAbsolutePath, _setAbsolutePath, None, doc="Absolute path of the overrridden command.")
########################################################################
# CollectFile class definition
########################################################################
@total_ordering
class CollectFile(object):
"""
Class representing a Cedar Backup collect file.
The following restrictions exist on data in this class:
- Absolute paths must be absolute
- The collect mode must be one of the values in :any:`VALID_COLLECT_MODES`.
- The archive mode must be one of the values in :any:`VALID_ARCHIVE_MODES`.
"""
def __init__(self, absolutePath=None, collectMode=None, archiveMode=None):
"""
Constructor for the ``CollectFile`` class.
Args:
absolutePath: Absolute path of the file to collect
collectMode: Overridden collect mode for this file
archiveMode: Overridden archive mode for this file
Raises:
ValueError: If one of the values is invalid
"""
self._absolutePath = None
self._collectMode = None
self._archiveMode = None
self.absolutePath = absolutePath
self.collectMode = collectMode
self.archiveMode = archiveMode
def __repr__(self):
"""
Official string representation for class instance.
"""
return "CollectFile(%s, %s, %s)" % (self.absolutePath, self.collectMode, self.archiveMode)
def __str__(self):
"""
Informal string representation for class instance.
"""
return self.__repr__()
def __eq__(self, other):
"""Equals operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) == 0
def __lt__(self, other):
"""Less-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) < 0
def __gt__(self, other):
"""Greater-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) > 0
def __cmp__(self, other):
"""
Original Python 2 comparison operator.
Args:
other: Other object to compare to
Returns:
-1/0/1 depending on whether self is ``<``, ``=`` or ``>`` other
"""
if other is None:
return 1
if self.absolutePath != other.absolutePath:
if str(self.absolutePath or "") < str(other.absolutePath or ""):
return -1
else:
return 1
if self.collectMode != other.collectMode:
if str(self.collectMode or "") < str(other.collectMode or ""):
return -1
else:
return 1
if self.archiveMode != other.archiveMode:
if str(self.archiveMode or "") < str(other.archiveMode or ""):
return -1
else:
return 1
return 0
def _setAbsolutePath(self, value):
"""
Property target used to set the absolute path.
The value must be an absolute path if it is not ``None``.
It does not have to exist on disk at the time of assignment.
Raises:
ValueError: If the value is not an absolute path
ValueError: If the value cannot be encoded properly
"""
if value is not None:
if not os.path.isabs(value):
raise ValueError("Not an absolute path: [%s]" % value)
self._absolutePath = encodePath(value)
def _getAbsolutePath(self):
"""
Property target used to get the absolute path.
"""
return self._absolutePath
def _setCollectMode(self, value):
"""
Property target used to set the collect mode.
If not ``None``, the mode must be one of the values in :any:`VALID_COLLECT_MODES`.
Raises:
ValueError: If the value is not valid
"""
if value is not None:
if value not in VALID_COLLECT_MODES:
raise ValueError("Collect mode must be one of %s." % VALID_COLLECT_MODES)
self._collectMode = value
def _getCollectMode(self):
"""
Property target used to get the collect mode.
"""
return self._collectMode
def _setArchiveMode(self, value):
"""
Property target used to set the archive mode.
If not ``None``, the mode must be one of the values in :any:`VALID_ARCHIVE_MODES`.
Raises:
ValueError: If the value is not valid
"""
if value is not None:
if value not in VALID_ARCHIVE_MODES:
raise ValueError("Archive mode must be one of %s." % VALID_ARCHIVE_MODES)
self._archiveMode = value
def _getArchiveMode(self):
"""
Property target used to get the archive mode.
"""
return self._archiveMode
absolutePath = property(_getAbsolutePath, _setAbsolutePath, None, doc="Absolute path of the file to collect.")
collectMode = property(_getCollectMode, _setCollectMode, None, doc="Overridden collect mode for this file.")
archiveMode = property(_getArchiveMode, _setArchiveMode, None, doc="Overridden archive mode for this file.")
########################################################################
# CollectDir class definition
########################################################################
@total_ordering
class CollectDir(object):
"""
Class representing a Cedar Backup collect directory.
The following restrictions exist on data in this class:
- Absolute paths must be absolute
- The collect mode must be one of the values in :any:`VALID_COLLECT_MODES`.
- The archive mode must be one of the values in :any:`VALID_ARCHIVE_MODES`.
- The ignore file must be a non-empty string.
For the ``absoluteExcludePaths`` list, validation is accomplished through the
:any:`util.AbsolutePathList` list implementation that overrides common list
methods and transparently does the absolute path validation for us.
*Note:* Lists within this class are "unordered" for equality comparisons.
"""
def __init__(self, absolutePath=None, collectMode=None, archiveMode=None, ignoreFile=None,
absoluteExcludePaths=None, relativeExcludePaths=None, excludePatterns=None,
linkDepth=None, dereference=False, recursionLevel=None):
"""
Constructor for the ``CollectDir`` class.
Args:
absolutePath: Absolute path of the directory to collect
collectMode: Overridden collect mode for this directory
archiveMode: Overridden archive mode for this directory
ignoreFile: Overidden ignore file name for this directory
linkDepth: Maximum at which soft links should be followed
dereference: Whether to dereference links that are followed
absoluteExcludePaths: List of absolute paths to exclude
relativeExcludePaths: List of relative paths to exclude
excludePatterns: List of regular expression patterns to exclude
Raises:
ValueError: If one of the values is invalid
"""
self._absolutePath = None
self._collectMode = None
self._archiveMode = None
self._ignoreFile = None
self._linkDepth = None
self._dereference = None
self._recursionLevel = None
self._absoluteExcludePaths = None
self._relativeExcludePaths = None
self._excludePatterns = None
self.absolutePath = absolutePath
self.collectMode = collectMode
self.archiveMode = archiveMode
self.ignoreFile = ignoreFile
self.linkDepth = linkDepth
self.dereference = dereference
self.recursionLevel = recursionLevel
self.absoluteExcludePaths = absoluteExcludePaths
self.relativeExcludePaths = relativeExcludePaths
self.excludePatterns = excludePatterns
def __repr__(self):
"""
Official string representation for class instance.
"""
return "CollectDir(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" % (self.absolutePath, self.collectMode,
self.archiveMode, self.ignoreFile,
self.absoluteExcludePaths,
self.relativeExcludePaths,
self.excludePatterns,
self.linkDepth, self.dereference,
self.recursionLevel)
def __str__(self):
"""
Informal string representation for class instance.
"""
return self.__repr__()
def __eq__(self, other):
"""Equals operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) == 0
def __lt__(self, other):
"""Less-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) < 0
def __gt__(self, other):
"""Greater-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) > 0
def __cmp__(self, other):
"""
Original Python 2 comparison operator.
Lists within this class are "unordered" for equality comparisons.
Args:
other: Other object to compare to
Returns:
-1/0/1 depending on whether self is ``<``, ``=`` or ``>`` other
"""
if other is None:
return 1
if self.absolutePath != other.absolutePath:
if str(self.absolutePath or "") < str(other.absolutePath or ""):
return -1
else:
return 1
if self.collectMode != other.collectMode:
if str(self.collectMode or "") < str(other.collectMode or ""):
return -1
else:
return 1
if self.archiveMode != other.archiveMode:
if str(self.archiveMode or "") < str(other.archiveMode or ""):
return -1
else:
return 1
if self.ignoreFile != other.ignoreFile:
if str(self.ignoreFile or "") < str(other.ignoreFile or ""):
return -1
else:
return 1
if self.linkDepth != other.linkDepth:
if int(self.linkDepth or 0) < int(other.linkDepth or 0):
return -1
else:
return 1
if self.dereference != other.dereference:
if self.dereference < other.dereference:
return -1
else:
return 1
if self.recursionLevel != other.recursionLevel:
if int(self.recursionLevel or 0) < int(other.recursionLevel or 0):
return -1
else:
return 1
if self.absoluteExcludePaths != other.absoluteExcludePaths:
if self.absoluteExcludePaths < other.absoluteExcludePaths:
return -1
else:
return 1
if self.relativeExcludePaths != other.relativeExcludePaths:
if self.relativeExcludePaths < other.relativeExcludePaths:
return -1
else:
return 1
if self.excludePatterns != other.excludePatterns:
if self.excludePatterns < other.excludePatterns:
return -1
else:
return 1
return 0
def _setAbsolutePath(self, value):
"""
Property target used to set the absolute path.
The value must be an absolute path if it is not ``None``.
It does not have to exist on disk at the time of assignment.
Raises:
ValueError: If the value is not an absolute path
ValueError: If the value cannot be encoded properly
"""
if value is not None:
if not os.path.isabs(value):
raise ValueError("Not an absolute path: [%s]" % value)
self._absolutePath = encodePath(value)
def _getAbsolutePath(self):
"""
Property target used to get the absolute path.
"""
return self._absolutePath
def _setCollectMode(self, value):
"""
Property target used to set the collect mode.
If not ``None``, the mode must be one of the values in :any:`VALID_COLLECT_MODES`.
Raises:
ValueError: If the value is not valid
"""
if value is not None:
if value not in VALID_COLLECT_MODES:
raise ValueError("Collect mode must be one of %s." % VALID_COLLECT_MODES)
self._collectMode = value
def _getCollectMode(self):
"""
Property target used to get the collect mode.
"""
return self._collectMode
def _setArchiveMode(self, value):
"""
Property target used to set the archive mode.
If not ``None``, the mode must be one of the values in :any:`VALID_ARCHIVE_MODES`.
Raises:
ValueError: If the value is not valid
"""
if value is not None:
if value not in VALID_ARCHIVE_MODES:
raise ValueError("Archive mode must be one of %s." % VALID_ARCHIVE_MODES)
self._archiveMode = value
def _getArchiveMode(self):
"""
Property target used to get the archive mode.
"""
return self._archiveMode
def _setIgnoreFile(self, value):
"""
Property target used to set the ignore file.
The value must be a non-empty string if it is not ``None``.
Raises:
ValueError: If the value is an empty string
"""
if value is not None:
if len(value) < 1:
raise ValueError("The ignore file must be a non-empty string.")
self._ignoreFile = value
def _getIgnoreFile(self):
"""
Property target used to get the ignore file.
"""
return self._ignoreFile
def _setLinkDepth(self, value):
"""
Property target used to set the link depth.
The value must be an integer >= 0.
Raises:
ValueError: If the value is not valid
"""
if value is None:
self._linkDepth = None
else:
try:
value = int(value)
except TypeError:
raise ValueError("Link depth value must be an integer >= 0.")
if value < 0:
raise ValueError("Link depth value must be an integer >= 0.")
self._linkDepth = value
def _getLinkDepth(self):
"""
Property target used to get the action linkDepth.
"""
return self._linkDepth
def _setDereference(self, value):
"""
Property target used to set the dereference flag.
No validations, but we normalize the value to ``True`` or ``False``.
"""
if value:
self._dereference = True
else:
self._dereference = False
def _getDereference(self):
"""
Property target used to get the dereference flag.
"""
return self._dereference
def _setRecursionLevel(self, value):
"""
Property target used to set the recursionLevel.
The value must be an integer.
Raises:
ValueError: If the value is not valid
"""
if value is None:
self._recursionLevel = None
else:
try:
value = int(value)
except TypeError:
raise ValueError("Recusion level value must be an integer.")
self._recursionLevel = value
def _getRecursionLevel(self):
"""
Property target used to get the action recursionLevel.
"""
return self._recursionLevel
def _setAbsoluteExcludePaths(self, value):
"""
Property target used to set the absolute exclude paths list.
Either the value must be ``None`` or each element must be an absolute path.
Elements do not have to exist on disk at the time of assignment.
Raises:
ValueError: If the value is not an absolute path
"""
if value is None:
self._absoluteExcludePaths = None
else:
try:
saved = self._absoluteExcludePaths
self._absoluteExcludePaths = AbsolutePathList()
self._absoluteExcludePaths.extend(value)
except Exception as e:
self._absoluteExcludePaths = saved
raise e
def _getAbsoluteExcludePaths(self):
"""
Property target used to get the absolute exclude paths list.
"""
return self._absoluteExcludePaths
def _setRelativeExcludePaths(self, value):
"""
Property target used to set the relative exclude paths list.
Elements do not have to exist on disk at the time of assignment.
"""
if value is None:
self._relativeExcludePaths = None
else:
try:
saved = self._relativeExcludePaths
self._relativeExcludePaths = UnorderedList()
self._relativeExcludePaths.extend(value)
except Exception as e:
self._relativeExcludePaths = saved
raise e
def _getRelativeExcludePaths(self):
"""
Property target used to get the relative exclude paths list.
"""
return self._relativeExcludePaths
def _setExcludePatterns(self, value):
"""
Property target used to set the exclude patterns list.
"""
if value is None:
self._excludePatterns = None
else:
try:
saved = self._excludePatterns
self._excludePatterns = RegexList()
self._excludePatterns.extend(value)
except Exception as e:
self._excludePatterns = saved
raise e
def _getExcludePatterns(self):
"""
Property target used to get the exclude patterns list.
"""
return self._excludePatterns
absolutePath = property(_getAbsolutePath, _setAbsolutePath, None, doc="Absolute path of the directory to collect.")
collectMode = property(_getCollectMode, _setCollectMode, None, doc="Overridden collect mode for this directory.")
archiveMode = property(_getArchiveMode, _setArchiveMode, None, doc="Overridden archive mode for this directory.")
ignoreFile = property(_getIgnoreFile, _setIgnoreFile, None, doc="Overridden ignore file name for this directory.")
linkDepth = property(_getLinkDepth, _setLinkDepth, None, doc="Maximum at which soft links should be followed.")
dereference = property(_getDereference, _setDereference, None, doc="Whether to dereference links that are followed.")
recursionLevel = property(_getRecursionLevel, _setRecursionLevel, None, "Recursion level to use for recursive directory collection")
absoluteExcludePaths = property(_getAbsoluteExcludePaths, _setAbsoluteExcludePaths, None, "List of absolute paths to exclude.")
relativeExcludePaths = property(_getRelativeExcludePaths, _setRelativeExcludePaths, None, "List of relative paths to exclude.")
excludePatterns = property(_getExcludePatterns, _setExcludePatterns, None, "List of regular expression patterns to exclude.")
########################################################################
# PurgeDir class definition
########################################################################
@total_ordering
class PurgeDir(object):
"""
Class representing a Cedar Backup purge directory.
The following restrictions exist on data in this class:
- The absolute path must be an absolute path
- The retain days value must be an integer >= 0.
"""
def __init__(self, absolutePath=None, retainDays=None):
"""
Constructor for the ``PurgeDir`` class.
Args:
absolutePath: Absolute path of the directory to be purged
retainDays: Number of days content within directory should be retained
Raises:
ValueError: If one of the values is invalid
"""
self._absolutePath = None
self._retainDays = None
self.absolutePath = absolutePath
self.retainDays = retainDays
def __repr__(self):
"""
Official string representation for class instance.
"""
return "PurgeDir(%s, %s)" % (self.absolutePath, self.retainDays)
def __str__(self):
"""
Informal string representation for class instance.
"""
return self.__repr__()
def __eq__(self, other):
"""Equals operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) == 0
def __lt__(self, other):
"""Less-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) < 0
def __gt__(self, other):
"""Greater-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) > 0
def __cmp__(self, other):
"""
Original Python 2 comparison operator.
Args:
other: Other object to compare to
Returns:
-1/0/1 depending on whether self is ``<``, ``=`` or ``>`` other
"""
if other is None:
return 1
if self.absolutePath != other.absolutePath:
if str(self.absolutePath or "") < str(other.absolutePath or ""):
return -1
else:
return 1
if self.retainDays != other.retainDays:
if int(self.retainDays or 0) < int(other.retainDays or 0):
return -1
else:
return 1
return 0
def _setAbsolutePath(self, value):
"""
Property target used to set the absolute path.
The value must be an absolute path if it is not ``None``.
It does not have to exist on disk at the time of assignment.
Raises:
ValueError: If the value is not an absolute path
ValueError: If the value cannot be encoded properly
"""
if value is not None:
if not os.path.isabs(value):
raise ValueError("Absolute path must, er, be an absolute path.")
self._absolutePath = encodePath(value)
def _getAbsolutePath(self):
"""
Property target used to get the absolute path.
"""
return self._absolutePath
def _setRetainDays(self, value):
"""
Property target used to set the retain days value.
The value must be an integer >= 0.
Raises:
ValueError: If the value is not valid
"""
if value is None:
self._retainDays = None
else:
try:
value = int(value)
except TypeError:
raise ValueError("Retain days value must be an integer >= 0.")
if value < 0:
raise ValueError("Retain days value must be an integer >= 0.")
self._retainDays = value
def _getRetainDays(self):
"""
Property target used to get the absolute path.
"""
return self._retainDays
absolutePath = property(_getAbsolutePath, _setAbsolutePath, None, "Absolute path of directory to purge.")
retainDays = property(_getRetainDays, _setRetainDays, None, "Number of days content within directory should be retained.")
########################################################################
# LocalPeer class definition
########################################################################
@total_ordering
class LocalPeer(object):
"""
Class representing a Cedar Backup peer.
The following restrictions exist on data in this class:
- The peer name must be a non-empty string.
- The collect directory must be an absolute path.
- The ignore failure mode must be one of the values in ``VALID_FAILURE_MODES``.
"""
def __init__(self, name=None, collectDir=None, ignoreFailureMode=None):
"""
Constructor for the ``LocalPeer`` class.
Args:
name: Name of the peer, typically a valid hostname
collectDir: Collect directory to stage files from on peer
ignoreFailureMode: Ignore failure mode for peer
Raises:
ValueError: If one of the values is invalid
"""
self._name = None
self._collectDir = None
self._ignoreFailureMode = None
self.name = name
self.collectDir = collectDir
self.ignoreFailureMode = ignoreFailureMode
def __repr__(self):
"""
Official string representation for class instance.
"""
return "LocalPeer(%s, %s, %s)" % (self.name, self.collectDir, self.ignoreFailureMode)
def __str__(self):
"""
Informal string representation for class instance.
"""
return self.__repr__()
def __eq__(self, other):
"""Equals operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) == 0
def __lt__(self, other):
"""Less-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) < 0
def __gt__(self, other):
"""Greater-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) > 0
def __cmp__(self, other):
"""
Original Python 2 comparison operator.
Args:
other: Other object to compare to
Returns:
-1/0/1 depending on whether self is ``<``, ``=`` or ``>`` other
"""
if other is None:
return 1
if self.name != other.name:
if str(self.name or "") < str(other.name or ""):
return -1
else:
return 1
if self.collectDir != other.collectDir:
if str(self.collectDir or "") < str(other.collectDir or ""):
return -1
else:
return 1
if self.ignoreFailureMode != other.ignoreFailureMode:
if str(self.ignoreFailureMode or "") < str(other.ignoreFailureMode or ""):
return -1
else:
return 1
return 0
def _setName(self, value):
"""
Property target used to set the peer name.
The value must be a non-empty string if it is not ``None``.
Raises:
ValueError: If the value is an empty string
"""
if value is not None:
if len(value) < 1:
raise ValueError("The peer name must be a non-empty string.")
self._name = value
def _getName(self):
"""
Property target used to get the peer name.
"""
return self._name
def _setCollectDir(self, value):
"""
Property target used to set the collect directory.
The value must be an absolute path if it is not ``None``.
It does not have to exist on disk at the time of assignment.
Raises:
ValueError: If the value is not an absolute path
ValueError: If the value cannot be encoded properly
"""
if value is not None:
if not os.path.isabs(value):
raise ValueError("Collect directory must be an absolute path.")
self._collectDir = encodePath(value)
def _getCollectDir(self):
"""
Property target used to get the collect directory.
"""
return self._collectDir
def _setIgnoreFailureMode(self, value):
"""
Property target used to set the ignoreFailure mode.
If not ``None``, the mode must be one of the values in ``VALID_FAILURE_MODES``.
Raises:
ValueError: If the value is not valid
"""
if value is not None:
if value not in VALID_FAILURE_MODES:
raise ValueError("Ignore failure mode must be one of %s." % VALID_FAILURE_MODES)
self._ignoreFailureMode = value
def _getIgnoreFailureMode(self):
"""
Property target used to get the ignoreFailure mode.
"""
return self._ignoreFailureMode
name = property(_getName, _setName, None, "Name of the peer, typically a valid hostname.")
collectDir = property(_getCollectDir, _setCollectDir, None, "Collect directory to stage files from on peer.")
ignoreFailureMode = property(_getIgnoreFailureMode, _setIgnoreFailureMode, None, "Ignore failure mode for peer.")
########################################################################
# RemotePeer class definition
########################################################################
@total_ordering
class RemotePeer(object):
"""
Class representing a Cedar Backup peer.
The following restrictions exist on data in this class:
- The peer name must be a non-empty string.
- The collect directory must be an absolute path.
- The remote user must be a non-empty string.
- The rcp command must be a non-empty string.
- The rsh command must be a non-empty string.
- The cback command must be a non-empty string.
- Any managed action name must be a non-empty string matching ``ACTION_NAME_REGEX``
- The ignore failure mode must be one of the values in ``VALID_FAILURE_MODES``.
"""
def __init__(self, name=None, collectDir=None, remoteUser=None,
rcpCommand=None, rshCommand=None, cbackCommand=None,
managed=False, managedActions=None, ignoreFailureMode=None):
"""
Constructor for the ``RemotePeer`` class.
Args:
name: Name of the peer, must be a valid hostname
collectDir: Collect directory to stage files from on peer
remoteUser: Name of backup user on remote peer
rcpCommand: Overridden rcp-compatible copy command for peer
rshCommand: Overridden rsh-compatible remote shell command for peer
cbackCommand: Overridden cback-compatible command to use on remote peer
managed: Indicates whether this is a managed peer
managedActions: Overridden set of actions that are managed on the peer
ignoreFailureMode: Ignore failure mode for peer
Raises:
ValueError: If one of the values is invalid
"""
self._name = None
self._collectDir = None
self._remoteUser = None
self._rcpCommand = None
self._rshCommand = None
self._cbackCommand = None
self._managed = None
self._managedActions = None
self._ignoreFailureMode = None
self.name = name
self.collectDir = collectDir
self.remoteUser = remoteUser
self.rcpCommand = rcpCommand
self.rshCommand = rshCommand
self.cbackCommand = cbackCommand
self.managed = managed
self.managedActions = managedActions
self.ignoreFailureMode = ignoreFailureMode
def __repr__(self):
"""
Official string representation for class instance.
"""
return "RemotePeer(%s, %s, %s, %s, %s, %s, %s, %s, %s)" % (self.name, self.collectDir, self.remoteUser,
self.rcpCommand, self.rshCommand, self.cbackCommand,
self.managed, self.managedActions, self.ignoreFailureMode)
def __str__(self):
"""
Informal string representation for class instance.
"""
return self.__repr__()
def __eq__(self, other):
"""Equals operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) == 0
def __lt__(self, other):
"""Less-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) < 0
def __gt__(self, other):
"""Greater-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) > 0
def __cmp__(self, other):
"""
Original Python 2 comparison operator.
Args:
other: Other object to compare to
Returns:
-1/0/1 depending on whether self is ``<``, ``=`` or ``>`` other
"""
if other is None:
return 1
if self.name != other.name:
if str(self.name or "") < str(other.name or ""):
return -1
else:
return 1
if self.collectDir != other.collectDir:
if str(self.collectDir or "") < str(other.collectDir or ""):
return -1
else:
return 1
if self.remoteUser != other.remoteUser:
if str(self.remoteUser or "") < str(other.remoteUser or ""):
return -1
else:
return 1
if self.rcpCommand != other.rcpCommand:
if str(self.rcpCommand or "") < str(other.rcpCommand or ""):
return -1
else:
return 1
if self.rshCommand != other.rshCommand:
if str(self.rshCommand or "") < str(other.rshCommand or ""):
return -1
else:
return 1
if self.cbackCommand != other.cbackCommand:
if str(self.cbackCommand or "") < str(other.cbackCommand or ""):
return -1
else:
return 1
if self.managed != other.managed:
if str(self.managed or "") < str(other.managed or ""):
return -1
else:
return 1
if self.managedActions != other.managedActions:
if self.managedActions < other.managedActions:
return -1
else:
return 1
if self.ignoreFailureMode != other.ignoreFailureMode:
if str(self.ignoreFailureMode or "") < str(other.ignoreFailureMode or ""):
return -1
else:
return 1
return 0
def _setName(self, value):
"""
Property target used to set the peer name.
The value must be a non-empty string if it is not ``None``.
Raises:
ValueError: If the value is an empty string
"""
if value is not None:
if len(value) < 1:
raise ValueError("The peer name must be a non-empty string.")
self._name = value
def _getName(self):
"""
Property target used to get the peer name.
"""
return self._name
def _setCollectDir(self, value):
"""
Property target used to set the collect directory.
The value must be an absolute path if it is not ``None``.
It does not have to exist on disk at the time of assignment.
Raises:
ValueError: If the value is not an absolute path
ValueError: If the value cannot be encoded properly
"""
if value is not None:
if not os.path.isabs(value):
raise ValueError("Collect directory must be an absolute path.")
self._collectDir = encodePath(value)
def _getCollectDir(self):
"""
Property target used to get the collect directory.
"""
return self._collectDir
def _setRemoteUser(self, value):
"""
Property target used to set the remote user.
The value must be a non-empty string if it is not ``None``.
Raises:
ValueError: If the value is an empty string
"""
if value is not None:
if len(value) < 1:
raise ValueError("The remote user must be a non-empty string.")
self._remoteUser = value
def _getRemoteUser(self):
"""
Property target used to get the remote user.
"""
return self._remoteUser
def _setRcpCommand(self, value):
"""
Property target used to set the rcp command.
The value must be a non-empty string if it is not ``None``.
Raises:
ValueError: If the value is an empty string
"""
if value is not None:
if len(value) < 1:
raise ValueError("The rcp command must be a non-empty string.")
self._rcpCommand = value
def _getRcpCommand(self):
"""
Property target used to get the rcp command.
"""
return self._rcpCommand
def _setRshCommand(self, value):
"""
Property target used to set the rsh command.
The value must be a non-empty string if it is not ``None``.
Raises:
ValueError: If the value is an empty string
"""
if value is not None:
if len(value) < 1:
raise ValueError("The rsh command must be a non-empty string.")
self._rshCommand = value
def _getRshCommand(self):
"""
Property target used to get the rsh command.
"""
return self._rshCommand
def _setCbackCommand(self, value):
"""
Property target used to set the cback command.
The value must be a non-empty string if it is not ``None``.
Raises:
ValueError: If the value is an empty string
"""
if value is not None:
if len(value) < 1:
raise ValueError("The cback command must be a non-empty string.")
self._cbackCommand = value
def _getCbackCommand(self):
"""
Property target used to get the cback command.
"""
return self._cbackCommand
def _setManaged(self, value):
"""
Property target used to set the managed flag.
No validations, but we normalize the value to ``True`` or ``False``.
"""
if value:
self._managed = True
else:
self._managed = False
def _getManaged(self):
"""
Property target used to get the managed flag.
"""
return self._managed
def _setManagedActions(self, value):
"""
Property target used to set the managed actions list.
Elements do not have to exist on disk at the time of assignment.
"""
if value is None:
self._managedActions = None
else:
try:
saved = self._managedActions
self._managedActions = RegexMatchList(ACTION_NAME_REGEX, emptyAllowed=False, prefix="Action name")
self._managedActions.extend(value)
except Exception as e:
self._managedActions = saved
raise e
def _getManagedActions(self):
"""
Property target used to get the managed actions list.
"""
return self._managedActions
def _setIgnoreFailureMode(self, value):
"""
Property target used to set the ignoreFailure mode.
If not ``None``, the mode must be one of the values in ``VALID_FAILURE_MODES``.
Raises:
ValueError: If the value is not valid
"""
if value is not None:
if value not in VALID_FAILURE_MODES:
raise ValueError("Ignore failure mode must be one of %s." % VALID_FAILURE_MODES)
self._ignoreFailureMode = value
def _getIgnoreFailureMode(self):
"""
Property target used to get the ignoreFailure mode.
"""
return self._ignoreFailureMode
name = property(_getName, _setName, None, "Name of the peer, must be a valid hostname.")
collectDir = property(_getCollectDir, _setCollectDir, None, "Collect directory to stage files from on peer.")
remoteUser = property(_getRemoteUser, _setRemoteUser, None, "Name of backup user on remote peer.")
rcpCommand = property(_getRcpCommand, _setRcpCommand, None, "Overridden rcp-compatible copy command for peer.")
rshCommand = property(_getRshCommand, _setRshCommand, None, "Overridden rsh-compatible remote shell command for peer.")
cbackCommand = property(_getCbackCommand, _setCbackCommand, None, "Overridden cback-compatible command to use on remote peer.")
managed = property(_getManaged, _setManaged, None, "Indicates whether this is a managed peer.")
managedActions = property(_getManagedActions, _setManagedActions, None, "Overridden set of actions that are managed on the peer.")
ignoreFailureMode = property(_getIgnoreFailureMode, _setIgnoreFailureMode, None, "Ignore failure mode for peer.")
########################################################################
# ReferenceConfig class definition
########################################################################
@total_ordering
class ReferenceConfig(object):
"""
Class representing a Cedar Backup reference configuration.
The reference information is just used for saving off metadata about
configuration and exists mostly for backwards-compatibility with Cedar
Backup 1.x.
"""
def __init__(self, author=None, revision=None, description=None, generator=None):
"""
Constructor for the ``ReferenceConfig`` class.
Args:
author: Author of the configuration file
revision: Revision of the configuration file
description: Description of the configuration file
generator: Tool that generated the configuration file
"""
self._author = None
self._revision = None
self._description = None
self._generator = None
self.author = author
self.revision = revision
self.description = description
self.generator = generator
def __repr__(self):
"""
Official string representation for class instance.
"""
return "ReferenceConfig(%s, %s, %s, %s)" % (self.author, self.revision, self.description, self.generator)
def __str__(self):
"""
Informal string representation for class instance.
"""
return self.__repr__()
def __eq__(self, other):
"""Equals operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) == 0
def __lt__(self, other):
"""Less-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) < 0
def __gt__(self, other):
"""Greater-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) > 0
def __cmp__(self, other):
"""
Original Python 2 comparison operator.
Args:
other: Other object to compare to
Returns:
-1/0/1 depending on whether self is ``<``, ``=`` or ``>`` other
"""
if other is None:
return 1
if self.author != other.author:
if str(self.author or "") < str(other.author or ""):
return -1
else:
return 1
if self.revision != other.revision:
if str(self.revision or "") < str(other.revision or ""):
return -1
else:
return 1
if self.description != other.description:
if str(self.description or "") < str(other.description or ""):
return -1
else:
return 1
if self.generator != other.generator:
if str(self.generator or "") < str(other.generator or ""):
return -1
else:
return 1
return 0
def _setAuthor(self, value):
"""
Property target used to set the author value.
No validations.
"""
self._author = value
def _getAuthor(self):
"""
Property target used to get the author value.
"""
return self._author
def _setRevision(self, value):
"""
Property target used to set the revision value.
No validations.
"""
self._revision = value
def _getRevision(self):
"""
Property target used to get the revision value.
"""
return self._revision
def _setDescription(self, value):
"""
Property target used to set the description value.
No validations.
"""
self._description = value
def _getDescription(self):
"""
Property target used to get the description value.
"""
return self._description
def _setGenerator(self, value):
"""
Property target used to set the generator value.
No validations.
"""
self._generator = value
def _getGenerator(self):
"""
Property target used to get the generator value.
"""
return self._generator
author = property(_getAuthor, _setAuthor, None, "Author of the configuration file.")
revision = property(_getRevision, _setRevision, None, "Revision of the configuration file.")
description = property(_getDescription, _setDescription, None, "Description of the configuration file.")
generator = property(_getGenerator, _setGenerator, None, "Tool that generated the configuration file.")
########################################################################
# ExtensionsConfig class definition
########################################################################
@total_ordering
class ExtensionsConfig(object):
"""
Class representing Cedar Backup extensions configuration.
Extensions configuration is used to specify "extended actions" implemented
by code external to Cedar Backup. For instance, a hypothetical third party
might write extension code to collect database repository data. If they
write a properly-formatted extension function, they can use the extension
configuration to map a command-line Cedar Backup action (i.e. "database")
to their function.
The following restrictions exist on data in this class:
- If set, the order mode must be one of the values in ``VALID_ORDER_MODES``
- The actions list must be a list of ``ExtendedAction`` objects.
"""
def __init__(self, actions=None, orderMode=None):
"""
Constructor for the ``ExtensionsConfig`` class.
Args:
actions: List of extended actions
"""
self._orderMode = None
self._actions = None
self.orderMode = orderMode
self.actions = actions
def __repr__(self):
"""
Official string representation for class instance.
"""
return "ExtensionsConfig(%s, %s)" % (self.orderMode, self.actions)
def __str__(self):
"""
Informal string representation for class instance.
"""
return self.__repr__()
def __eq__(self, other):
"""Equals operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) == 0
def __lt__(self, other):
"""Less-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) < 0
def __gt__(self, other):
"""Greater-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) > 0
def __cmp__(self, other):
"""
Original Python 2 comparison operator.
Args:
other: Other object to compare to
Returns:
-1/0/1 depending on whether self is ``<``, ``=`` or ``>`` other
"""
if other is None:
return 1
if self.orderMode != other.orderMode:
if str(self.orderMode or "") < str(other.orderMode or ""):
return -1
else:
return 1
if self.actions != other.actions:
if self.actions < other.actions:
return -1
else:
return 1
return 0
def _setOrderMode(self, value):
"""
Property target used to set the order mode.
The value must be one of :any:`VALID_ORDER_MODES`.
Raises:
ValueError: If the value is not valid
"""
if value is not None:
if value not in VALID_ORDER_MODES:
raise ValueError("Order mode must be one of %s." % VALID_ORDER_MODES)
self._orderMode = value
def _getOrderMode(self):
"""
Property target used to get the order mode.
"""
return self._orderMode
def _setActions(self, value):
"""
Property target used to set the actions list.
Either the value must be ``None`` or each element must be an ``ExtendedAction``.
Raises:
ValueError: If the value is not a ``ExtendedAction``
"""
if value is None:
self._actions = None
else:
try:
saved = self._actions
self._actions = ObjectTypeList(ExtendedAction, "ExtendedAction")
self._actions.extend(value)
except Exception as e:
self._actions = saved
raise e
def _getActions(self):
"""
Property target used to get the actions list.
"""
return self._actions
orderMode = property(_getOrderMode, _setOrderMode, None, "Order mode for extensions, to control execution ordering.")
actions = property(_getActions, _setActions, None, "List of extended actions.")
########################################################################
# OptionsConfig class definition
########################################################################
@total_ordering
class OptionsConfig(object):
"""
Class representing a Cedar Backup global options configuration.
The options section is used to store global configuration options and
defaults that can be applied to other sections.
The following restrictions exist on data in this class:
- The working directory must be an absolute path.
- The starting day must be a day of the week in English, i.e. ``"monday"``, ``"tuesday"``, etc.
- All of the other values must be non-empty strings if they are set to something other than ``None``.
- The overrides list must be a list of ``CommandOverride`` objects.
- The hooks list must be a list of ``ActionHook`` objects.
- The cback command must be a non-empty string.
- Any managed action name must be a non-empty string matching ``ACTION_NAME_REGEX``
"""
def __init__(self, startingDay=None, workingDir=None, backupUser=None,
backupGroup=None, rcpCommand=None, overrides=None,
hooks=None, rshCommand=None, cbackCommand=None,
managedActions=None):
"""
Constructor for the ``OptionsConfig`` class.
Args:
startingDay: Day that starts the week
workingDir: Working (temporary) directory to use for backups
backupUser: Effective user that backups should run as
backupGroup: Effective group that backups should run as
rcpCommand: Default rcp-compatible copy command for staging
rshCommand: Default rsh-compatible command to use for remote shells
cbackCommand: Default cback-compatible command to use on managed remote peers
overrides: List of configured command path overrides, if any
hooks: List of configured pre- and post-action hooks
managedActions: Default set of actions that are managed on remote peers
Raises:
ValueError: If one of the values is invalid
"""
self._startingDay = None
self._workingDir = None
self._backupUser = None
self._backupGroup = None
self._rcpCommand = None
self._rshCommand = None
self._cbackCommand = None
self._overrides = None
self._hooks = None
self._managedActions = None
self.startingDay = startingDay
self.workingDir = workingDir
self.backupUser = backupUser
self.backupGroup = backupGroup
self.rcpCommand = rcpCommand
self.rshCommand = rshCommand
self.cbackCommand = cbackCommand
self.overrides = overrides
self.hooks = hooks
self.managedActions = managedActions
def __repr__(self):
"""
Official string representation for class instance.
"""
return "OptionsConfig(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" % (self.startingDay, self.workingDir,
self.backupUser, self.backupGroup,
self.rcpCommand, self.overrides,
self.hooks, self.rshCommand,
self.cbackCommand, self.managedActions)
def __str__(self):
"""
Informal string representation for class instance.
"""
return self.__repr__()
def __eq__(self, other):
"""Equals operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) == 0
def __lt__(self, other):
"""Less-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) < 0
def __gt__(self, other):
"""Greater-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) > 0
def __cmp__(self, other):
"""
Original Python 2 comparison operator.
Args:
other: Other object to compare to
Returns:
-1/0/1 depending on whether self is ``<``, ``=`` or ``>`` other
"""
if other is None:
return 1
if self.startingDay != other.startingDay:
if str(self.startingDay or "") < str(other.startingDay or ""):
return -1
else:
return 1
if self.workingDir != other.workingDir:
if str(self.workingDir or "") < str(other.workingDir or ""):
return -1
else:
return 1
if self.backupUser != other.backupUser:
if str(self.backupUser or "") < str(other.backupUser or ""):
return -1
else:
return 1
if self.backupGroup != other.backupGroup:
if str(self.backupGroup or "") < str(other.backupGroup or ""):
return -1
else:
return 1
if self.rcpCommand != other.rcpCommand:
if str(self.rcpCommand or "") < str(other.rcpCommand or ""):
return -1
else:
return 1
if self.rshCommand != other.rshCommand:
if str(self.rshCommand or "") < str(other.rshCommand or ""):
return -1
else:
return 1
if self.cbackCommand != other.cbackCommand:
if str(self.cbackCommand or "") < str(other.cbackCommand or ""):
return -1
else:
return 1
if self.overrides != other.overrides:
if self.overrides < other.overrides:
return -1
else:
return 1
if self.hooks != other.hooks:
if self.hooks < other.hooks:
return -1
else:
return 1
if self.managedActions != other.managedActions:
if self.managedActions < other.managedActions:
return -1
else:
return 1
return 0
def addOverride(self, command, absolutePath):
"""
If no override currently exists for the command, add one.
Args:
command: Name of command to be overridden
absolutePath: Absolute path of the overrridden command
"""
override = CommandOverride(command, absolutePath)
if self.overrides is None:
self.overrides = [ override, ]
else:
exists = False
for obj in self.overrides:
if obj.command == override.command:
exists = True
break
if not exists:
self.overrides.append(override)
def replaceOverride(self, command, absolutePath):
"""
If override currently exists for the command, replace it; otherwise add it.
Args:
command: Name of command to be overridden
absolutePath: Absolute path of the overrridden command
"""
override = CommandOverride(command, absolutePath)
if self.overrides is None:
self.overrides = [ override, ]
else:
exists = False
for obj in self.overrides:
if obj.command == override.command:
exists = True
obj.absolutePath = override.absolutePath
break
if not exists:
self.overrides.append(override)
def _setStartingDay(self, value):
"""
Property target used to set the starting day.
If it is not ``None``, the value must be a valid English day of the week,
one of ``"monday"``, ``"tuesday"``, ``"wednesday"``, etc.
Raises:
ValueError: If the value is not a valid day of the week
"""
if value is not None:
if value not in ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday", ]:
raise ValueError("Starting day must be an English day of the week, i.e. \"monday\".")
self._startingDay = value
def _getStartingDay(self):
"""
Property target used to get the starting day.
"""
return self._startingDay
def _setWorkingDir(self, value):
"""
Property target used to set the working directory.
The value must be an absolute path if it is not ``None``.
It does not have to exist on disk at the time of assignment.
Raises:
ValueError: If the value is not an absolute path
ValueError: If the value cannot be encoded properly
"""
if value is not None:
if not os.path.isabs(value):
raise ValueError("Working directory must be an absolute path.")
self._workingDir = encodePath(value)
def _getWorkingDir(self):
"""
Property target used to get the working directory.
"""
return self._workingDir
def _setBackupUser(self, value):
"""
Property target used to set the backup user.
The value must be a non-empty string if it is not ``None``.
Raises:
ValueError: If the value is an empty string
"""
if value is not None:
if len(value) < 1:
raise ValueError("Backup user must be a non-empty string.")
self._backupUser = value
def _getBackupUser(self):
"""
Property target used to get the backup user.
"""
return self._backupUser
def _setBackupGroup(self, value):
"""
Property target used to set the backup group.
The value must be a non-empty string if it is not ``None``.
Raises:
ValueError: If the value is an empty string
"""
if value is not None:
if len(value) < 1:
raise ValueError("Backup group must be a non-empty string.")
self._backupGroup = value
def _getBackupGroup(self):
"""
Property target used to get the backup group.
"""
return self._backupGroup
def _setRcpCommand(self, value):
"""
Property target used to set the rcp command.
The value must be a non-empty string if it is not ``None``.
Raises:
ValueError: If the value is an empty string
"""
if value is not None:
if len(value) < 1:
raise ValueError("The rcp command must be a non-empty string.")
self._rcpCommand = value
def _getRcpCommand(self):
"""
Property target used to get the rcp command.
"""
return self._rcpCommand
def _setRshCommand(self, value):
"""
Property target used to set the rsh command.
The value must be a non-empty string if it is not ``None``.
Raises:
ValueError: If the value is an empty string
"""
if value is not None:
if len(value) < 1:
raise ValueError("The rsh command must be a non-empty string.")
self._rshCommand = value
def _getRshCommand(self):
"""
Property target used to get the rsh command.
"""
return self._rshCommand
def _setCbackCommand(self, value):
"""
Property target used to set the cback command.
The value must be a non-empty string if it is not ``None``.
Raises:
ValueError: If the value is an empty string
"""
if value is not None:
if len(value) < 1:
raise ValueError("The cback command must be a non-empty string.")
self._cbackCommand = value
def _getCbackCommand(self):
"""
Property target used to get the cback command.
"""
return self._cbackCommand
def _setOverrides(self, value):
"""
Property target used to set the command path overrides list.
Either the value must be ``None`` or each element must be a ``CommandOverride``.
Raises:
ValueError: If the value is not a ``CommandOverride``
"""
if value is None:
self._overrides = None
else:
try:
saved = self._overrides
self._overrides = ObjectTypeList(CommandOverride, "CommandOverride")
self._overrides.extend(value)
except Exception as e:
self._overrides = saved
raise e
def _getOverrides(self):
"""
Property target used to get the command path overrides list.
"""
return self._overrides
def _setHooks(self, value):
"""
Property target used to set the pre- and post-action hooks list.
Either the value must be ``None`` or each element must be an ``ActionHook``.
Raises:
ValueError: If the value is not a ``CommandOverride``
"""
if value is None:
self._hooks = None
else:
try:
saved = self._hooks
self._hooks = ObjectTypeList(ActionHook, "ActionHook")
self._hooks.extend(value)
except Exception as e:
self._hooks = saved
raise e
def _getHooks(self):
"""
Property target used to get the command path hooks list.
"""
return self._hooks
def _setManagedActions(self, value):
"""
Property target used to set the managed actions list.
Elements do not have to exist on disk at the time of assignment.
"""
if value is None:
self._managedActions = None
else:
try:
saved = self._managedActions
self._managedActions = RegexMatchList(ACTION_NAME_REGEX, emptyAllowed=False, prefix="Action name")
self._managedActions.extend(value)
except Exception as e:
self._managedActions = saved
raise e
def _getManagedActions(self):
"""
Property target used to get the managed actions list.
"""
return self._managedActions
startingDay = property(_getStartingDay, _setStartingDay, None, "Day that starts the week.")
workingDir = property(_getWorkingDir, _setWorkingDir, None, "Working (temporary) directory to use for backups.")
backupUser = property(_getBackupUser, _setBackupUser, None, "Effective user that backups should run as.")
backupGroup = property(_getBackupGroup, _setBackupGroup, None, "Effective group that backups should run as.")
rcpCommand = property(_getRcpCommand, _setRcpCommand, None, "Default rcp-compatible copy command for staging.")
rshCommand = property(_getRshCommand, _setRshCommand, None, "Default rsh-compatible command to use for remote shells.")
cbackCommand = property(_getCbackCommand, _setCbackCommand, None, "Default cback-compatible command to use on managed remote peers.")
overrides = property(_getOverrides, _setOverrides, None, "List of configured command path overrides, if any.")
hooks = property(_getHooks, _setHooks, None, "List of configured pre- and post-action hooks.")
managedActions = property(_getManagedActions, _setManagedActions, None, "Default set of actions that are managed on remote peers.")
########################################################################
# PeersConfig class definition
########################################################################
@total_ordering
class PeersConfig(object):
"""
Class representing Cedar Backup global peer configuration.
This section contains a list of local and remote peers in a master's backup
pool. The section is optional. If a master does not define this section,
then all peers are unmanaged, and the stage configuration section must
explicitly list any peer that is to be staged. If this section is
configured, then peers may be managed or unmanaged, and the stage section
peer configuration (if any) completely overrides this configuration.
The following restrictions exist on data in this class:
- The list of local peers must contain only ``LocalPeer`` objects
- The list of remote peers must contain only ``RemotePeer`` objects
*Note:* Lists within this class are "unordered" for equality comparisons.
"""
def __init__(self, localPeers=None, remotePeers=None):
"""
Constructor for the ``PeersConfig`` class.
Args:
localPeers: List of local peers
remotePeers: List of remote peers
Raises:
ValueError: If one of the values is invalid
"""
self._localPeers = None
self._remotePeers = None
self.localPeers = localPeers
self.remotePeers = remotePeers
def __repr__(self):
"""
Official string representation for class instance.
"""
return "PeersConfig(%s, %s)" % (self.localPeers, self.remotePeers)
def __str__(self):
"""
Informal string representation for class instance.
"""
return self.__repr__()
def __eq__(self, other):
"""Equals operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) == 0
def __lt__(self, other):
"""Less-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) < 0
def __gt__(self, other):
"""Greater-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) > 0
def __cmp__(self, other):
"""
Original Python 2 comparison operator.
Lists within this class are "unordered" for equality comparisons.
Args:
other: Other object to compare to
Returns:
-1/0/1 depending on whether self is ``<``, ``=`` or ``>`` other
"""
if other is None:
return 1
if self.localPeers != other.localPeers:
if self.localPeers < other.localPeers:
return -1
else:
return 1
if self.remotePeers != other.remotePeers:
if self.remotePeers < other.remotePeers:
return -1
else:
return 1
return 0
def hasPeers(self):
"""
Indicates whether any peers are filled into this object.
Returns:
Boolean true if any local or remote peers are filled in, false otherwise
"""
return ((self.localPeers is not None and len(self.localPeers) > 0) or
(self.remotePeers is not None and len(self.remotePeers) > 0))
def _setLocalPeers(self, value):
"""
Property target used to set the local peers list.
Either the value must be ``None`` or each element must be a ``LocalPeer``.
Raises:
ValueError: If the value is not an absolute path
"""
if value is None:
self._localPeers = None
else:
try:
saved = self._localPeers
self._localPeers = ObjectTypeList(LocalPeer, "LocalPeer")
self._localPeers.extend(value)
except Exception as e:
self._localPeers = saved
raise e
def _getLocalPeers(self):
"""
Property target used to get the local peers list.
"""
return self._localPeers
def _setRemotePeers(self, value):
"""
Property target used to set the remote peers list.
Either the value must be ``None`` or each element must be a ``RemotePeer``.
Raises:
ValueError: If the value is not a ``RemotePeer``
"""
if value is None:
self._remotePeers = None
else:
try:
saved = self._remotePeers
self._remotePeers = ObjectTypeList(RemotePeer, "RemotePeer")
self._remotePeers.extend(value)
except Exception as e:
self._remotePeers = saved
raise e
def _getRemotePeers(self):
"""
Property target used to get the remote peers list.
"""
return self._remotePeers
localPeers = property(_getLocalPeers, _setLocalPeers, None, "List of local peers.")
remotePeers = property(_getRemotePeers, _setRemotePeers, None, "List of remote peers.")
########################################################################
# CollectConfig class definition
########################################################################
@total_ordering
class CollectConfig(object):
"""
Class representing a Cedar Backup collect configuration.
The following restrictions exist on data in this class:
- The target directory must be an absolute path.
- The collect mode must be one of the values in :any:`VALID_COLLECT_MODES`.
- The archive mode must be one of the values in :any:`VALID_ARCHIVE_MODES`.
- The ignore file must be a non-empty string.
- Each of the paths in ``absoluteExcludePaths`` must be an absolute path
- The collect file list must be a list of ``CollectFile`` objects.
- The collect directory list must be a list of ``CollectDir`` objects.
For the ``absoluteExcludePaths`` list, validation is accomplished through the
:any:`util.AbsolutePathList` list implementation that overrides common list
methods and transparently does the absolute path validation for us.
For the ``collectFiles`` and ``collectDirs`` list, validation is accomplished
through the :any:`util.ObjectTypeList` list implementation that overrides common
list methods and transparently ensures that each element has an appropriate
type.
*Note:* Lists within this class are "unordered" for equality comparisons.
"""
def __init__(self, targetDir=None, collectMode=None, archiveMode=None, ignoreFile=None,
absoluteExcludePaths=None, excludePatterns=None, collectFiles=None,
collectDirs=None):
"""
Constructor for the ``CollectConfig`` class.
Args:
targetDir: Directory to collect files into
collectMode: Default collect mode
archiveMode: Default archive mode for collect files
ignoreFile: Default ignore file name
absoluteExcludePaths: List of absolute paths to exclude
excludePatterns: List of regular expression patterns to exclude
collectFiles: List of collect files
collectDirs: List of collect directories
Raises:
ValueError: If one of the values is invalid
"""
self._targetDir = None
self._collectMode = None
self._archiveMode = None
self._ignoreFile = None
self._absoluteExcludePaths = None
self._excludePatterns = None
self._collectFiles = None
self._collectDirs = None
self.targetDir = targetDir
self.collectMode = collectMode
self.archiveMode = archiveMode
self.ignoreFile = ignoreFile
self.absoluteExcludePaths = absoluteExcludePaths
self.excludePatterns = excludePatterns
self.collectFiles = collectFiles
self.collectDirs = collectDirs
def __repr__(self):
"""
Official string representation for class instance.
"""
return "CollectConfig(%s, %s, %s, %s, %s, %s, %s, %s)" % (self.targetDir, self.collectMode, self.archiveMode,
self.ignoreFile, self.absoluteExcludePaths,
self.excludePatterns, self.collectFiles, self.collectDirs)
def __str__(self):
"""
Informal string representation for class instance.
"""
return self.__repr__()
def __eq__(self, other):
"""Equals operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) == 0
def __lt__(self, other):
"""Less-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) < 0
def __gt__(self, other):
"""Greater-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) > 0
def __cmp__(self, other):
"""
Original Python 2 comparison operator.
Lists within this class are "unordered" for equality comparisons.
Args:
other: Other object to compare to
Returns:
-1/0/1 depending on whether self is ``<``, ``=`` or ``>`` other
"""
if other is None:
return 1
if self.targetDir != other.targetDir:
if str(self.targetDir or "") < str(other.targetDir or ""):
return -1
else:
return 1
if self.collectMode != other.collectMode:
if str(self.collectMode or "") < str(other.collectMode or ""):
return -1
else:
return 1
if self.archiveMode != other.archiveMode:
if str(self.archiveMode or "") < str(other.archiveMode or ""):
return -1
else:
return 1
if self.ignoreFile != other.ignoreFile:
if str(self.ignoreFile or "") < str(other.ignoreFile or ""):
return -1
else:
return 1
if self.absoluteExcludePaths != other.absoluteExcludePaths:
if self.absoluteExcludePaths < other.absoluteExcludePaths:
return -1
else:
return 1
if self.excludePatterns != other.excludePatterns:
if self.excludePatterns < other.excludePatterns:
return -1
else:
return 1
if self.collectFiles != other.collectFiles:
if self.collectFiles < other.collectFiles:
return -1
else:
return 1
if self.collectDirs != other.collectDirs:
if self.collectDirs < other.collectDirs:
return -1
else:
return 1
return 0
def _setTargetDir(self, value):
"""
Property target used to set the target directory.
The value must be an absolute path if it is not ``None``.
It does not have to exist on disk at the time of assignment.
Raises:
ValueError: If the value is not an absolute path
ValueError: If the value cannot be encoded properly
"""
if value is not None:
if not os.path.isabs(value):
raise ValueError("Target directory must be an absolute path.")
self._targetDir = encodePath(value)
def _getTargetDir(self):
"""
Property target used to get the target directory.
"""
return self._targetDir
def _setCollectMode(self, value):
"""
Property target used to set the collect mode.
If not ``None``, the mode must be one of :any:`VALID_COLLECT_MODES`.
Raises:
ValueError: If the value is not valid
"""
if value is not None:
if value not in VALID_COLLECT_MODES:
raise ValueError("Collect mode must be one of %s." % VALID_COLLECT_MODES)
self._collectMode = value
def _getCollectMode(self):
"""
Property target used to get the collect mode.
"""
return self._collectMode
def _setArchiveMode(self, value):
"""
Property target used to set the archive mode.
If not ``None``, the mode must be one of :any:`VALID_ARCHIVE_MODES`.
Raises:
ValueError: If the value is not valid
"""
if value is not None:
if value not in VALID_ARCHIVE_MODES:
raise ValueError("Archive mode must be one of %s." % VALID_ARCHIVE_MODES)
self._archiveMode = value
def _getArchiveMode(self):
"""
Property target used to get the archive mode.
"""
return self._archiveMode
def _setIgnoreFile(self, value):
"""
Property target used to set the ignore file.
The value must be a non-empty string if it is not ``None``.
Raises:
ValueError: If the value is an empty string
ValueError: If the value cannot be encoded properly
"""
if value is not None:
if len(value) < 1:
raise ValueError("The ignore file must be a non-empty string.")
self._ignoreFile = encodePath(value)
def _getIgnoreFile(self):
"""
Property target used to get the ignore file.
"""
return self._ignoreFile
def _setAbsoluteExcludePaths(self, value):
"""
Property target used to set the absolute exclude paths list.
Either the value must be ``None`` or each element must be an absolute path.
Elements do not have to exist on disk at the time of assignment.
Raises:
ValueError: If the value is not an absolute path
"""
if value is None:
self._absoluteExcludePaths = None
else:
try:
saved = self._absoluteExcludePaths
self._absoluteExcludePaths = AbsolutePathList()
self._absoluteExcludePaths.extend(value)
except Exception as e:
self._absoluteExcludePaths = saved
raise e
def _getAbsoluteExcludePaths(self):
"""
Property target used to get the absolute exclude paths list.
"""
return self._absoluteExcludePaths
def _setExcludePatterns(self, value):
"""
Property target used to set the exclude patterns list.
"""
if value is None:
self._excludePatterns = None
else:
try:
saved = self._excludePatterns
self._excludePatterns = RegexList()
self._excludePatterns.extend(value)
except Exception as e:
self._excludePatterns = saved
raise e
def _getExcludePatterns(self):
"""
Property target used to get the exclude patterns list.
"""
return self._excludePatterns
def _setCollectFiles(self, value):
"""
Property target used to set the collect files list.
Either the value must be ``None`` or each element must be a ``CollectFile``.
Raises:
ValueError: If the value is not a ``CollectFile``
"""
if value is None:
self._collectFiles = None
else:
try:
saved = self._collectFiles
self._collectFiles = ObjectTypeList(CollectFile, "CollectFile")
self._collectFiles.extend(value)
except Exception as e:
self._collectFiles = saved
raise e
def _getCollectFiles(self):
"""
Property target used to get the collect files list.
"""
return self._collectFiles
def _setCollectDirs(self, value):
"""
Property target used to set the collect dirs list.
Either the value must be ``None`` or each element must be a ``CollectDir``.
Raises:
ValueError: If the value is not a ``CollectDir``
"""
if value is None:
self._collectDirs = None
else:
try:
saved = self._collectDirs
self._collectDirs = ObjectTypeList(CollectDir, "CollectDir")
self._collectDirs.extend(value)
except Exception as e:
self._collectDirs = saved
raise e
def _getCollectDirs(self):
"""
Property target used to get the collect dirs list.
"""
return self._collectDirs
targetDir = property(_getTargetDir, _setTargetDir, None, "Directory to collect files into.")
collectMode = property(_getCollectMode, _setCollectMode, None, "Default collect mode.")
archiveMode = property(_getArchiveMode, _setArchiveMode, None, "Default archive mode for collect files.")
ignoreFile = property(_getIgnoreFile, _setIgnoreFile, None, "Default ignore file name.")
absoluteExcludePaths = property(_getAbsoluteExcludePaths, _setAbsoluteExcludePaths, None, "List of absolute paths to exclude.")
excludePatterns = property(_getExcludePatterns, _setExcludePatterns, None, "List of regular expressions patterns to exclude.")
collectFiles = property(_getCollectFiles, _setCollectFiles, None, "List of collect files.")
collectDirs = property(_getCollectDirs, _setCollectDirs, None, "List of collect directories.")
########################################################################
# StageConfig class definition
########################################################################
@total_ordering
class StageConfig(object):
"""
Class representing a Cedar Backup stage configuration.
The following restrictions exist on data in this class:
- The target directory must be an absolute path
- The list of local peers must contain only ``LocalPeer`` objects
- The list of remote peers must contain only ``RemotePeer`` objects
*Note:* Lists within this class are "unordered" for equality comparisons.
"""
def __init__(self, targetDir=None, localPeers=None, remotePeers=None):
"""
Constructor for the ``StageConfig`` class.
Args:
targetDir: Directory to stage files into, by peer name
localPeers: List of local peers
remotePeers: List of remote peers
Raises:
ValueError: If one of the values is invalid
"""
self._targetDir = None
self._localPeers = None
self._remotePeers = None
self.targetDir = targetDir
self.localPeers = localPeers
self.remotePeers = remotePeers
def __repr__(self):
"""
Official string representation for class instance.
"""
return "StageConfig(%s, %s, %s)" % (self.targetDir, self.localPeers, self.remotePeers)
def __str__(self):
"""
Informal string representation for class instance.
"""
return self.__repr__()
def __eq__(self, other):
"""Equals operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) == 0
def __lt__(self, other):
"""Less-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) < 0
def __gt__(self, other):
"""Greater-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) > 0
def __cmp__(self, other):
"""
Original Python 2 comparison operator.
Lists within this class are "unordered" for equality comparisons.
Args:
other: Other object to compare to
Returns:
-1/0/1 depending on whether self is ``<``, ``=`` or ``>`` other
"""
if other is None:
return 1
if self.targetDir != other.targetDir:
if str(self.targetDir or "") < str(other.targetDir or ""):
return -1
else:
return 1
if self.localPeers != other.localPeers:
if self.localPeers < other.localPeers:
return -1
else:
return 1
if self.remotePeers != other.remotePeers:
if self.remotePeers < other.remotePeers:
return -1
else:
return 1
return 0
def hasPeers(self):
"""
Indicates whether any peers are filled into this object.
Returns:
Boolean true if any local or remote peers are filled in, false otherwise
"""
return ((self.localPeers is not None and len(self.localPeers) > 0) or
(self.remotePeers is not None and len(self.remotePeers) > 0))
def _setTargetDir(self, value):
"""
Property target used to set the target directory.
The value must be an absolute path if it is not ``None``.
It does not have to exist on disk at the time of assignment.
Raises:
ValueError: If the value is not an absolute path
ValueError: If the value cannot be encoded properly
"""
if value is not None:
if not os.path.isabs(value):
raise ValueError("Target directory must be an absolute path.")
self._targetDir = encodePath(value)
def _getTargetDir(self):
"""
Property target used to get the target directory.
"""
return self._targetDir
def _setLocalPeers(self, value):
"""
Property target used to set the local peers list.
Either the value must be ``None`` or each element must be a ``LocalPeer``.
Raises:
ValueError: If the value is not an absolute path
"""
if value is None:
self._localPeers = None
else:
try:
saved = self._localPeers
self._localPeers = ObjectTypeList(LocalPeer, "LocalPeer")
self._localPeers.extend(value)
except Exception as e:
self._localPeers = saved
raise e
def _getLocalPeers(self):
"""
Property target used to get the local peers list.
"""
return self._localPeers
def _setRemotePeers(self, value):
"""
Property target used to set the remote peers list.
Either the value must be ``None`` or each element must be a ``RemotePeer``.
Raises:
ValueError: If the value is not a ``RemotePeer``
"""
if value is None:
self._remotePeers = None
else:
try:
saved = self._remotePeers
self._remotePeers = ObjectTypeList(RemotePeer, "RemotePeer")
self._remotePeers.extend(value)
except Exception as e:
self._remotePeers = saved
raise e
def _getRemotePeers(self):
"""
Property target used to get the remote peers list.
"""
return self._remotePeers
targetDir = property(_getTargetDir, _setTargetDir, None, "Directory to stage files into, by peer name.")
localPeers = property(_getLocalPeers, _setLocalPeers, None, "List of local peers.")
remotePeers = property(_getRemotePeers, _setRemotePeers, None, "List of remote peers.")
########################################################################
# StoreConfig class definition
########################################################################
@total_ordering
class StoreConfig(object):
"""
Class representing a Cedar Backup store configuration.
The following restrictions exist on data in this class:
- The source directory must be an absolute path.
- The media type must be one of the values in :any:`VALID_MEDIA_TYPES`.
- The device type must be one of the values in :any:`VALID_DEVICE_TYPES`.
- The device path must be an absolute path.
- The SCSI id, if provided, must be in the form specified by :any:`validateScsiId`.
- The drive speed must be an integer >= 1
- The blanking behavior must be a ``BlankBehavior`` object
- The refresh media delay must be an integer >= 0
- The eject delay must be an integer >= 0
Note that although the blanking factor must be a positive floating point
number, it is stored as a string. This is done so that we can losslessly go
back and forth between XML and object representations of configuration.
"""
def __init__(self, sourceDir=None, mediaType=None, deviceType=None,
devicePath=None, deviceScsiId=None, driveSpeed=None,
checkData=False, warnMidnite=False, noEject=False,
checkMedia=False, blankBehavior=None, refreshMediaDelay=None,
ejectDelay=None):
"""
Constructor for the ``StoreConfig`` class.
Args:
sourceDir: Directory whose contents should be written to media
mediaType: Type of the media (see notes above)
deviceType: Type of the device (optional, see notes above)
devicePath: Filesystem device name for writer device, i.e. ``/dev/cdrw``
deviceScsiId: SCSI id for writer device, i.e. ``[<method>:]scsibus,target,lun``
driveSpeed: Speed of the drive, i.e. ``2`` for 2x drive, etc
checkData: Whether resulting image should be validated
checkMedia: Whether media should be checked before being written to
warnMidnite: Whether to generate warnings for crossing midnite
noEject: Indicates that the writer device should not be ejected
blankBehavior: Controls optimized blanking behavior
refreshMediaDelay: Delay, in seconds, to add after refreshing media
ejectDelay: Delay, in seconds, to add after ejecting media before closing the tray
Raises:
ValueError: If one of the values is invalid
"""
self._sourceDir = None
self._mediaType = None
self._deviceType = None
self._devicePath = None
self._deviceScsiId = None
self._driveSpeed = None
self._checkData = None
self._checkMedia = None
self._warnMidnite = None
self._noEject = None
self._blankBehavior = None
self._refreshMediaDelay = None
self._ejectDelay = None
self.sourceDir = sourceDir
self.mediaType = mediaType
self.deviceType = deviceType
self.devicePath = devicePath
self.deviceScsiId = deviceScsiId
self.driveSpeed = driveSpeed
self.checkData = checkData
self.checkMedia = checkMedia
self.warnMidnite = warnMidnite
self.noEject = noEject
self.blankBehavior = blankBehavior
self.refreshMediaDelay = refreshMediaDelay
self.ejectDelay = ejectDelay
def __repr__(self):
"""
Official string representation for class instance.
"""
return "StoreConfig(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" % (
self.sourceDir, self.mediaType, self.deviceType,
self.devicePath, self.deviceScsiId, self.driveSpeed,
self.checkData, self.warnMidnite, self.noEject,
self.checkMedia, self.blankBehavior, self.refreshMediaDelay,
self.ejectDelay)
def __str__(self):
"""
Informal string representation for class instance.
"""
return self.__repr__()
def __eq__(self, other):
"""Equals operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) == 0
def __lt__(self, other):
"""Less-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) < 0
def __gt__(self, other):
"""Greater-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) > 0
def __cmp__(self, other):
"""
Original Python 2 comparison operator.
Args:
other: Other object to compare to
Returns:
-1/0/1 depending on whether self is ``<``, ``=`` or ``>`` other
"""
if other is None:
return 1
if self.sourceDir != other.sourceDir:
if str(self.sourceDir or "") < str(other.sourceDir or ""):
return -1
else:
return 1
if self.mediaType != other.mediaType:
if str(self.mediaType or "") < str(other.mediaType or ""):
return -1
else:
return 1
if self.deviceType != other.deviceType:
if str(self.deviceType or "") < str(other.deviceType or ""):
return -1
else:
return 1
if self.devicePath != other.devicePath:
if str(self.devicePath or "") < str(other.devicePath or ""):
return -1
else:
return 1
if self.deviceScsiId != other.deviceScsiId:
if str(self.deviceScsiId or "") < str(other.deviceScsiId or ""):
return -1
else:
return 1
if self.driveSpeed != other.driveSpeed:
if str(self.driveSpeed or "") < str(other.driveSpeed or ""):
return -1
else:
return 1
if self.checkData != other.checkData:
if self.checkData < other.checkData:
return -1
else:
return 1
if self.checkMedia != other.checkMedia:
if self.checkMedia < other.checkMedia:
return -1
else:
return 1
if self.warnMidnite != other.warnMidnite:
if self.warnMidnite < other.warnMidnite:
return -1
else:
return 1
if self.noEject != other.noEject:
if self.noEject < other.noEject:
return -1
else:
return 1
if self.blankBehavior != other.blankBehavior:
if str(self.blankBehavior or "") < str(other.blankBehavior or ""):
return -1
else:
return 1
if self.refreshMediaDelay != other.refreshMediaDelay:
if int(self.refreshMediaDelay or 0) < int(other.refreshMediaDelay or 0):
return -1
else:
return 1
if self.ejectDelay != other.ejectDelay:
if int(self.ejectDelay or 0) < int(other.ejectDelay or 0):
return -1
else:
return 1
return 0
def _setSourceDir(self, value):
"""
Property target used to set the source directory.
The value must be an absolute path if it is not ``None``.
It does not have to exist on disk at the time of assignment.
Raises:
ValueError: If the value is not an absolute path
ValueError: If the value cannot be encoded properly
"""
if value is not None:
if not os.path.isabs(value):
raise ValueError("Source directory must be an absolute path.")
self._sourceDir = encodePath(value)
def _getSourceDir(self):
"""
Property target used to get the source directory.
"""
return self._sourceDir
def _setMediaType(self, value):
"""
Property target used to set the media type.
The value must be one of :any:`VALID_MEDIA_TYPES`.
Raises:
ValueError: If the value is not valid
"""
if value is not None:
if value not in VALID_MEDIA_TYPES:
raise ValueError("Media type must be one of %s." % VALID_MEDIA_TYPES)
self._mediaType = value
def _getMediaType(self):
"""
Property target used to get the media type.
"""
return self._mediaType
def _setDeviceType(self, value):
"""
Property target used to set the device type.
The value must be one of :any:`VALID_DEVICE_TYPES`.
Raises:
ValueError: If the value is not valid
"""
if value is not None:
if value not in VALID_DEVICE_TYPES:
raise ValueError("Device type must be one of %s." % VALID_DEVICE_TYPES)
self._deviceType = value
def _getDeviceType(self):
"""
Property target used to get the device type.
"""
return self._deviceType
def _setDevicePath(self, value):
"""
Property target used to set the device path.
The value must be an absolute path if it is not ``None``.
It does not have to exist on disk at the time of assignment.
Raises:
ValueError: If the value is not an absolute path
ValueError: If the value cannot be encoded properly
"""
if value is not None:
if not os.path.isabs(value):
raise ValueError("Device path must be an absolute path.")
self._devicePath = encodePath(value)
def _getDevicePath(self):
"""
Property target used to get the device path.
"""
return self._devicePath
def _setDeviceScsiId(self, value):
"""
Property target used to set the SCSI id
The SCSI id must be valid per :any:`validateScsiId`.
Raises:
ValueError: If the value is not valid
"""
if value is None:
self._deviceScsiId = None
else:
self._deviceScsiId = validateScsiId(value)
def _getDeviceScsiId(self):
"""
Property target used to get the SCSI id.
"""
return self._deviceScsiId
def _setDriveSpeed(self, value):
"""
Property target used to set the drive speed.
The drive speed must be valid per :any:`validateDriveSpeed`.
Raises:
ValueError: If the value is not valid
"""
self._driveSpeed = validateDriveSpeed(value)
def _getDriveSpeed(self):
"""
Property target used to get the drive speed.
"""
return self._driveSpeed
def _setCheckData(self, value):
"""
Property target used to set the check data flag.
No validations, but we normalize the value to ``True`` or ``False``.
"""
if value:
self._checkData = True
else:
self._checkData = False
def _getCheckData(self):
"""
Property target used to get the check data flag.
"""
return self._checkData
def _setCheckMedia(self, value):
"""
Property target used to set the check media flag.
No validations, but we normalize the value to ``True`` or ``False``.
"""
if value:
self._checkMedia = True
else:
self._checkMedia = False
def _getCheckMedia(self):
"""
Property target used to get the check media flag.
"""
return self._checkMedia
def _setWarnMidnite(self, value):
"""
Property target used to set the midnite warning flag.
No validations, but we normalize the value to ``True`` or ``False``.
"""
if value:
self._warnMidnite = True
else:
self._warnMidnite = False
def _getWarnMidnite(self):
"""
Property target used to get the midnite warning flag.
"""
return self._warnMidnite
def _setNoEject(self, value):
"""
Property target used to set the no-eject flag.
No validations, but we normalize the value to ``True`` or ``False``.
"""
if value:
self._noEject = True
else:
self._noEject = False
def _getNoEject(self):
"""
Property target used to get the no-eject flag.
"""
return self._noEject
def _setBlankBehavior(self, value):
"""
Property target used to set blanking behavior configuration.
If not ``None``, the value must be a ``BlankBehavior`` object.
Raises:
ValueError: If the value is not a ``BlankBehavior``
"""
if value is None:
self._blankBehavior = None
else:
if not isinstance(value, BlankBehavior):
raise ValueError("Value must be a ``BlankBehavior`` object.")
self._blankBehavior = value
def _getBlankBehavior(self):
"""
Property target used to get the blanking behavior configuration.
"""
return self._blankBehavior
def _setRefreshMediaDelay(self, value):
"""
Property target used to set the refreshMediaDelay.
The value must be an integer >= 0.
Raises:
ValueError: If the value is not valid
"""
if value is None:
self._refreshMediaDelay = None
else:
try:
value = int(value)
except TypeError:
raise ValueError("Action refreshMediaDelay value must be an integer >= 0.")
if value < 0:
raise ValueError("Action refreshMediaDelay value must be an integer >= 0.")
if value == 0:
value = None # normalize this out, since it's the default
self._refreshMediaDelay = value
def _getRefreshMediaDelay(self):
"""
Property target used to get the action refreshMediaDelay.
"""
return self._refreshMediaDelay
def _setEjectDelay(self, value):
"""
Property target used to set the ejectDelay.
The value must be an integer >= 0.
Raises:
ValueError: If the value is not valid
"""
if value is None:
self._ejectDelay = None
else:
try:
value = int(value)
except TypeError:
raise ValueError("Action ejectDelay value must be an integer >= 0.")
if value < 0:
raise ValueError("Action ejectDelay value must be an integer >= 0.")
if value == 0:
value = None # normalize this out, since it's the default
self._ejectDelay = value
def _getEjectDelay(self):
"""
Property target used to get the action ejectDelay.
"""
return self._ejectDelay
sourceDir = property(_getSourceDir, _setSourceDir, None, "Directory whose contents should be written to media.")
mediaType = property(_getMediaType, _setMediaType, None, "Type of the media (see notes above).")
deviceType = property(_getDeviceType, _setDeviceType, None, "Type of the device (optional, see notes above).")
devicePath = property(_getDevicePath, _setDevicePath, None, "Filesystem device name for writer device.")
deviceScsiId = property(_getDeviceScsiId, _setDeviceScsiId, None, "SCSI id for writer device (optional, see notes above).")
driveSpeed = property(_getDriveSpeed, _setDriveSpeed, None, "Speed of the drive.")
checkData = property(_getCheckData, _setCheckData, None, "Whether resulting image should be validated.")
checkMedia = property(_getCheckMedia, _setCheckMedia, None, "Whether media should be checked before being written to.")
warnMidnite = property(_getWarnMidnite, _setWarnMidnite, None, "Whether to generate warnings for crossing midnite.")
noEject = property(_getNoEject, _setNoEject, None, "Indicates that the writer device should not be ejected.")
blankBehavior = property(_getBlankBehavior, _setBlankBehavior, None, "Controls optimized blanking behavior.")
refreshMediaDelay = property(_getRefreshMediaDelay, _setRefreshMediaDelay, None, "Delay, in seconds, to add after refreshing media.")
ejectDelay = property(_getEjectDelay, _setEjectDelay, None, "Delay, in seconds, to add after ejecting media before closing the tray")
########################################################################
# PurgeConfig class definition
########################################################################
@total_ordering
class PurgeConfig(object):
"""
Class representing a Cedar Backup purge configuration.
The following restrictions exist on data in this class:
- The purge directory list must be a list of ``PurgeDir`` objects.
For the ``purgeDirs`` list, validation is accomplished through the
:any:`util.ObjectTypeList` list implementation that overrides common list
methods and transparently ensures that each element is a ``PurgeDir``.
*Note:* Lists within this class are "unordered" for equality comparisons.
"""
def __init__(self, purgeDirs=None):
"""
Constructor for the ``Purge`` class.
Args:
purgeDirs: List of purge directories
Raises:
ValueError: If one of the values is invalid
"""
self._purgeDirs = None
self.purgeDirs = purgeDirs
def __repr__(self):
"""
Official string representation for class instance.
"""
return "PurgeConfig(%s)" % self.purgeDirs
def __str__(self):
"""
Informal string representation for class instance.
"""
return self.__repr__()
def __eq__(self, other):
"""Equals operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) == 0
def __lt__(self, other):
"""Less-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) < 0
def __gt__(self, other):
"""Greater-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) > 0
def __cmp__(self, other):
"""
Original Python 2 comparison operator.
Lists within this class are "unordered" for equality comparisons.
Args:
other: Other object to compare to
Returns:
-1/0/1 depending on whether self is ``<``, ``=`` or ``>`` other
"""
if other is None:
return 1
if self.purgeDirs != other.purgeDirs:
if self.purgeDirs < other.purgeDirs:
return -1
else:
return 1
return 0
def _setPurgeDirs(self, value):
"""
Property target used to set the purge dirs list.
Either the value must be ``None`` or each element must be a ``PurgeDir``.
Raises:
ValueError: If the value is not a ``PurgeDir``
"""
if value is None:
self._purgeDirs = None
else:
try:
saved = self._purgeDirs
self._purgeDirs = ObjectTypeList(PurgeDir, "PurgeDir")
self._purgeDirs.extend(value)
except Exception as e:
self._purgeDirs = saved
raise e
def _getPurgeDirs(self):
"""
Property target used to get the purge dirs list.
"""
return self._purgeDirs
purgeDirs = property(_getPurgeDirs, _setPurgeDirs, None, "List of directories to purge.")
########################################################################
# Config class definition
########################################################################
@total_ordering
class Config(object):
######################
# Class documentation
######################
"""
Class representing a Cedar Backup XML configuration document.
The ``Config`` class is a Python object representation of a Cedar Backup XML
configuration file. It is intended to be the only Python-language interface
to Cedar Backup configuration on disk for both Cedar Backup itself and for
external applications.
The object representation is two-way: XML data can be used to create a
``Config`` object, and then changes to the object can be propogated back to
disk. A ``Config`` object can even be used to create a configuration file
from scratch programmatically.
This class and the classes it is composed from often use Python's
``property`` construct to validate input and limit access to values. Some
validations can only be done once a document is considered "complete"
(see module notes for more details).
Assignments to the various instance variables must match the expected
type, i.e. ``reference`` must be a ``ReferenceConfig``. The internal check
uses the built-in ``isinstance`` function, so it should be OK to use
subclasses if you want to.
If an instance variable is not set, its value will be ``None``. When an
object is initialized without using an XML document, all of the values
will be ``None``. Even when an object is initialized using XML, some of
the values might be ``None`` because not every section is required.
*Note:* Lists within this class are "unordered" for equality comparisons.
"""
##############
# Constructor
##############
def __init__(self, xmlData=None, xmlPath=None, validate=True):
"""
Initializes a configuration object.
If you initialize the object without passing either ``xmlData`` or
``xmlPath``, then configuration will be empty and will be invalid until it
is filled in properly.
No reference to the original XML data or original path is saved off by
this class. Once the data has been parsed (successfully or not) this
original information is discarded.
Unless the ``validate`` argument is ``False``, the :any:`Config.validate`
method will be called (with its default arguments) against configuration
after successfully parsing any passed-in XML. Keep in mind that even if
``validate`` is ``False``, it might not be possible to parse the passed-in
XML document if lower-level validations fail.
*Note:* It is strongly suggested that the ``validate`` option always be set
to ``True`` (the default) unless there is a specific need to read in
invalid configuration from disk.
Args:
xmlData (String data): XML data representing configuration
xmlPath (Absolute path to a file on disk): Path to an XML file on disk
validate (Boolean true/false): Validate the document after parsing it
Raises:
ValueError: If both ``xmlData`` and ``xmlPath`` are passed-in
ValueError: If the XML data in ``xmlData`` or ``xmlPath`` cannot be parsed
ValueError: If the parsed configuration document is not valid
"""
self._reference = None
self._extensions = None
self._options = None
self._peers = None
self._collect = None
self._stage = None
self._store = None
self._purge = None
self.reference = None
self.extensions = None
self.options = None
self.peers = None
self.collect = None
self.stage = None
self.store = None
self.purge = None
if xmlData is not None and xmlPath is not None:
raise ValueError("Use either xmlData or xmlPath, but not both.")
if xmlData is not None:
self._parseXmlData(xmlData)
if validate:
self.validate()
elif xmlPath is not None:
with open(xmlPath) as f:
xmlData = f.read()
self._parseXmlData(xmlData)
if validate:
self.validate()
#########################
# String representations
#########################
def __repr__(self):
"""
Official string representation for class instance.
"""
return "Config(%s, %s, %s, %s, %s, %s, %s, %s)" % (self.reference, self.extensions, self.options,
self.peers, self.collect, self.stage, self.store,
self.purge)
def __str__(self):
"""
Informal string representation for class instance.
"""
return self.__repr__()
#############################
# Standard comparison method
#############################
def __eq__(self, other):
"""Equals operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) == 0
def __lt__(self, other):
"""Less-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) < 0
def __gt__(self, other):
"""Greater-than operator, implemented in terms of original Python 2 compare operator."""
return self.__cmp__(other) > 0
def __cmp__(self, other):
"""
Original Python 2 comparison operator.
Lists within this class are "unordered" for equality comparisons.
Args:
other: Other object to compare to
Returns:
-1/0/1 depending on whether self is ``<``, ``=`` or ``>`` other
"""
if other is None:
return 1
if self.reference != other.reference:
if self.reference < other.reference:
return -1
else:
return 1
if self.extensions != other.extensions:
if self.extensions < other.extensions:
return -1
else:
return 1
if self.options != other.options:
if self.options < other.options:
return -1
else:
return 1
if self.peers != other.peers:
if self.peers < other.peers:
return -1
else:
return 1
if self.collect != other.collect:
if self.collect < other.collect:
return -1
else:
return 1
if self.stage != other.stage:
if self.stage < other.stage:
return -1
else:
return 1
if self.store != other.store:
if self.store < other.store:
return -1
else:
return 1
if self.purge != other.purge:
if self.purge < other.purge:
return -1
else:
return 1
return 0
#############
# Properties
#############
def _setReference(self, value):
"""
Property target used to set the reference configuration value.
If not ``None``, the value must be a ``ReferenceConfig`` object.
Raises:
ValueError: If the value is not a ``ReferenceConfig``
"""
if value is None:
self._reference = None
else:
if not isinstance(value, ReferenceConfig):
raise ValueError("Value must be a ``ReferenceConfig`` object.")
self._reference = value
def _getReference(self):
"""
Property target used to get the reference configuration value.
"""
return self._reference
def _setExtensions(self, value):
"""
Property target used to set the extensions configuration value.
If not ``None``, the value must be a ``ExtensionsConfig`` object.
Raises:
ValueError: If the value is not a ``ExtensionsConfig``
"""
if value is None:
self._extensions = None
else:
if not isinstance(value, ExtensionsConfig):
raise ValueError("Value must be a ``ExtensionsConfig`` object.")
self._extensions = value
def _getExtensions(self):
"""
Property target used to get the extensions configuration value.
"""
return self._extensions
def _setOptions(self, value):
"""
Property target used to set the options configuration value.
If not ``None``, the value must be an ``OptionsConfig`` object.
Raises:
ValueError: If the value is not a ``OptionsConfig``
"""
if value is None:
self._options = None
else:
if not isinstance(value, OptionsConfig):
raise ValueError("Value must be a ``OptionsConfig`` object.")
self._options = value
def _getOptions(self):
"""
Property target used to get the options configuration value.
"""
return self._options
def _setPeers(self, value):
"""
Property target used to set the peers configuration value.
If not ``None``, the value must be an ``PeersConfig`` object.
Raises:
ValueError: If the value is not a ``PeersConfig``
"""
if value is None:
self._peers = None
else:
if not isinstance(value, PeersConfig):
raise ValueError("Value must be a ``PeersConfig`` object.")
self._peers = value
def _getPeers(self):
"""
Property target used to get the peers configuration value.
"""
return self._peers
def _setCollect(self, value):
"""
Property target used to set the collect configuration value.
If not ``None``, the value must be a ``CollectConfig`` object.
Raises:
ValueError: If the value is not a ``CollectConfig``
"""
if value is None:
self._collect = None
else:
if not isinstance(value, CollectConfig):
raise ValueError("Value must be a ``CollectConfig`` object.")
self._collect = value
def _getCollect(self):
"""
Property target used to get the collect configuration value.
"""
return self._collect
def _setStage(self, value):
"""
Property target used to set the stage configuration value.
If not ``None``, the value must be a ``StageConfig`` object.
Raises:
ValueError: If the value is not a ``StageConfig``
"""
if value is None:
self._stage = None
else:
if not isinstance(value, StageConfig):
raise ValueError("Value must be a ``StageConfig`` object.")
self._stage = value
def _getStage(self):
"""
Property target used to get the stage configuration value.
"""
return self._stage
def _setStore(self, value):
"""
Property target used to set the store configuration value.
If not ``None``, the value must be a ``StoreConfig`` object.
Raises:
ValueError: If the value is not a ``StoreConfig``
"""
if value is None:
self._store = None
else:
if not isinstance(value, StoreConfig):
raise ValueError("Value must be a ``StoreConfig`` object.")
self._store = value
def _getStore(self):
"""
Property target used to get the store configuration value.
"""
return self._store
def _setPurge(self, value):
"""
Property target used to set the purge configuration value.
If not ``None``, the value must be a ``PurgeConfig`` object.
Raises:
ValueError: If the value is not a ``PurgeConfig``
"""
if value is None:
self._purge = None
else:
if not isinstance(value, PurgeConfig):
raise ValueError("Value must be a ``PurgeConfig`` object.")
self._purge = value
def _getPurge(self):
"""
Property target used to get the purge configuration value.
"""
return self._purge
reference = property(_getReference, _setReference, None, "Reference configuration in terms of a ``ReferenceConfig`` object.")
extensions = property(_getExtensions, _setExtensions, None, "Extensions configuration in terms of a ``ExtensionsConfig`` object.")
options = property(_getOptions, _setOptions, None, "Options configuration in terms of a ``OptionsConfig`` object.")
peers = property(_getPeers, _setPeers, None, "Peers configuration in terms of a ``PeersConfig`` object.")
collect = property(_getCollect, _setCollect, None, "Collect configuration in terms of a ``CollectConfig`` object.")
stage = property(_getStage, _setStage, None, "Stage configuration in terms of a ``StageConfig`` object.")
store = property(_getStore, _setStore, None, "Store configuration in terms of a ``StoreConfig`` object.")
purge = property(_getPurge, _setPurge, None, "Purge configuration in terms of a ``PurgeConfig`` object.")
#################
# Public methods
#################
def extractXml(self, xmlPath=None, validate=True):
"""
Extracts configuration into an XML document.
If ``xmlPath`` is not provided, then the XML document will be returned as
a string. If ``xmlPath`` is provided, then the XML document will be written
to the file and ``None`` will be returned.
Unless the ``validate`` parameter is ``False``, the :any:`Config.validate`
method will be called (with its default arguments) against the
configuration before extracting the XML. If configuration is not valid,
then an XML document will not be extracted.
*Note:* It is strongly suggested that the ``validate`` option always be set
to ``True`` (the default) unless there is a specific need to write an
invalid configuration file to disk.
Args:
xmlPath (Absolute path to a file): Path to an XML file to create on disk
validate (Boolean true/false): Validate the document before extracting it
Returns:
XML string data or ``None`` as described above
Raises:
ValueError: If configuration within the object is not valid
IOError: If there is an error writing to the file
OSError: If there is an error writing to the file
"""
if validate:
self.validate()
xmlData = self._extractXml()
if xmlPath is not None:
with open(xmlPath, "w") as f:
f.write(xmlData)
return None
else:
return xmlData
def validate(self, requireOneAction=True, requireReference=False, requireExtensions=False, requireOptions=True,
requireCollect=False, requireStage=False, requireStore=False, requirePurge=False, requirePeers=False):
"""
Validates configuration represented by the object.
This method encapsulates all of the validations that should apply to a
fully "complete" document but are not already taken care of by earlier
validations. It also provides some extra convenience functionality which
might be useful to some people. The process of validation is laid out in
the *Validation* section in the class notes (above).
Args:
requireOneAction: Require at least one of the collect, stage, store or purge sections
requireReference: Require the reference section
requireExtensions: Require the extensions section
requireOptions: Require the options section
requirePeers: Require the peers section
requireCollect: Require the collect section
requireStage: Require the stage section
requireStore: Require the store section
requirePurge: Require the purge section
Raises:
ValueError: If one of the validations fails
"""
if requireOneAction and (self.collect, self.stage, self.store, self.purge) == (None, None, None, None):
raise ValueError("At least one of the collect, stage, store and purge sections is required.")
if requireReference and self.reference is None:
raise ValueError("The reference is section is required.")
if requireExtensions and self.extensions is None:
raise ValueError("The extensions is section is required.")
if requireOptions and self.options is None:
raise ValueError("The options is section is required.")
if requirePeers and self.peers is None:
raise ValueError("The peers is section is required.")
if requireCollect and self.collect is None:
raise ValueError("The collect is section is required.")
if requireStage and self.stage is None:
raise ValueError("The stage is section is required.")
if requireStore and self.store is None:
raise ValueError("The store is section is required.")
if requirePurge and self.purge is None:
raise ValueError("The purge is section is required.")
self._validateContents()
#####################################
# High-level methods for parsing XML
#####################################
def _parseXmlData(self, xmlData):
"""
Internal method to parse an XML string into the object.
This method parses the XML document into a DOM tree (``xmlDom``) and then
calls individual static methods to parse each of the individual
configuration sections.
Most of the validation we do here has to do with whether the document can
be parsed and whether any values which exist are valid. We don't do much
validation as to whether required elements actually exist unless we have
to to make sense of the document (instead, that's the job of the
:any:`validate` method).
Args:
xmlData (String data): XML data to be parsed
Raises:
ValueError: If the XML cannot be successfully parsed
"""
(xmlDom, parentNode) = createInputDom(xmlData)
self._reference = Config._parseReference(parentNode)
self._extensions = Config._parseExtensions(parentNode)
self._options = Config._parseOptions(parentNode)
self._peers = Config._parsePeers(parentNode)
self._collect = Config._parseCollect(parentNode)
self._stage = Config._parseStage(parentNode)
self._store = Config._parseStore(parentNode)
self._purge = Config._parsePurge(parentNode)
@staticmethod
def _parseReference(parentNode):
"""
Parses a reference configuration section.
We read the following fields::
author //cb_config/reference/author
revision //cb_config/reference/revision
description //cb_config/reference/description
generator //cb_config/reference/generator
Args:
parentNode: Parent node to search beneath
Returns:
``ReferenceConfig`` object or ``None`` if the section does not exist
Raises:
ValueError: If some filled-in value is invalid
"""
reference = None
sectionNode = readFirstChild(parentNode, "reference")
if sectionNode is not None:
reference = ReferenceConfig()
reference.author = readString(sectionNode, "author")
reference.revision = readString(sectionNode, "revision")
reference.description = readString(sectionNode, "description")
reference.generator = readString(sectionNode, "generator")
return reference
@staticmethod
def _parseExtensions(parentNode):
"""
Parses an extensions configuration section.
We read the following fields::
orderMode //cb_config/extensions/order_mode
We also read groups of the following items, one list element per item::
name //cb_config/extensions/action/name
module //cb_config/extensions/action/module
function //cb_config/extensions/action/function
index //cb_config/extensions/action/index
dependencies //cb_config/extensions/action/depends
The extended actions are parsed by :any:`_parseExtendedActions`.
Args:
parentNode: Parent node to search beneath
Returns:
``ExtensionsConfig`` object or ``None`` if the section does not exist
Raises:
ValueError: If some filled-in value is invalid
"""
extensions = None
sectionNode = readFirstChild(parentNode, "extensions")
if sectionNode is not None:
extensions = ExtensionsConfig()
extensions.orderMode = readString(sectionNode, "order_mode")
extensions.actions = Config._parseExtendedActions(sectionNode)
return extensions
@staticmethod
def _parseOptions(parentNode):
"""
Parses a options configuration section.
We read the following fields::
startingDay //cb_config/options/starting_day
workingDir //cb_config/options/working_dir
backupUser //cb_config/options/backup_user
backupGroup //cb_config/options/backup_group
rcpCommand //cb_config/options/rcp_command
rshCommand //cb_config/options/rsh_command
cbackCommand //cb_config/options/cback_command
managedActions //cb_config/options/managed_actions
The list of managed actions is a comma-separated list of action names.
We also read groups of the following items, one list element per
item::
overrides //cb_config/options/override
hooks //cb_config/options/hook
The overrides are parsed by :any:`_parseOverrides` and the hooks are parsed
by :any:`_parseHooks`.
Args:
parentNode: Parent node to search beneath
Returns:
``OptionsConfig`` object or ``None`` if the section does not exist
Raises:
ValueError: If some filled-in value is invalid
"""
options = None
sectionNode = readFirstChild(parentNode, "options")
if sectionNode is not None:
options = OptionsConfig()
options.startingDay = readString(sectionNode, "starting_day")
options.workingDir = readString(sectionNode, "working_dir")
options.backupUser = readString(sectionNode, "backup_user")
options.backupGroup = readString(sectionNode, "backup_group")
options.rcpCommand = readString(sectionNode, "rcp_command")
options.rshCommand = readString(sectionNode, "rsh_command")
options.cbackCommand = readString(sectionNode, "cback_command")
options.overrides = Config._parseOverrides(sectionNode)
options.hooks = Config._parseHooks(sectionNode)
managedActions = readString(sectionNode, "managed_actions")
options.managedActions = parseCommaSeparatedString(managedActions)
return options
@staticmethod
def _parsePeers(parentNode):
"""
Parses a peers configuration section.
We read groups of the following items, one list element per
item::
localPeers //cb_config/stage/peer
remotePeers //cb_config/stage/peer
The individual peer entries are parsed by :any:`_parsePeerList`.
Args:
parentNode: Parent node to search beneath
Returns:
``StageConfig`` object or ``None`` if the section does not exist
Raises:
ValueError: If some filled-in value is invalid
"""
peers = None
sectionNode = readFirstChild(parentNode, "peers")
if sectionNode is not None:
peers = PeersConfig()
(peers.localPeers, peers.remotePeers) = Config._parsePeerList(sectionNode)
return peers
@staticmethod
def _parseCollect(parentNode):
"""
Parses a collect configuration section.
We read the following individual fields::
targetDir //cb_config/collect/collect_dir
collectMode //cb_config/collect/collect_mode
archiveMode //cb_config/collect/archive_mode
ignoreFile //cb_config/collect/ignore_file
We also read groups of the following items, one list element per
item::
absoluteExcludePaths //cb_config/collect/exclude/abs_path
excludePatterns //cb_config/collect/exclude/pattern
collectFiles //cb_config/collect/file
collectDirs //cb_config/collect/dir
The exclusions are parsed by :any:`_parseExclusions`, the collect files are
parsed by :any:`_parseCollectFiles`, and the directories are parsed by
:any:`_parseCollectDirs`.
Args:
parentNode: Parent node to search beneath
Returns:
``CollectConfig`` object or ``None`` if the section does not exist
Raises:
ValueError: If some filled-in value is invalid
"""
collect = None
sectionNode = readFirstChild(parentNode, "collect")
if sectionNode is not None:
collect = CollectConfig()
collect.targetDir = readString(sectionNode, "collect_dir")
collect.collectMode = readString(sectionNode, "collect_mode")
collect.archiveMode = readString(sectionNode, "archive_mode")
collect.ignoreFile = readString(sectionNode, "ignore_file")
(collect.absoluteExcludePaths, unused, collect.excludePatterns) = Config._parseExclusions(sectionNode)
collect.collectFiles = Config._parseCollectFiles(sectionNode)
collect.collectDirs = Config._parseCollectDirs(sectionNode)
return collect
@staticmethod
def _parseStage(parentNode):
"""
Parses a stage configuration section.
We read the following individual fields::
targetDir //cb_config/stage/staging_dir
We also read groups of the following items, one list element per
item::
localPeers //cb_config/stage/peer
remotePeers //cb_config/stage/peer
The individual peer entries are parsed by :any:`_parsePeerList`.
Args:
parentNode: Parent node to search beneath
Returns:
``StageConfig`` object or ``None`` if the section does not exist
Raises:
ValueError: If some filled-in value is invalid
"""
stage = None
sectionNode = readFirstChild(parentNode, "stage")
if sectionNode is not None:
stage = StageConfig()
stage.targetDir = readString(sectionNode, "staging_dir")
(stage.localPeers, stage.remotePeers) = Config._parsePeerList(sectionNode)
return stage
@staticmethod
def _parseStore(parentNode):
"""
Parses a store configuration section.
We read the following fields::
sourceDir //cb_config/store/source_dir
mediaType //cb_config/store/media_type
deviceType //cb_config/store/device_type
devicePath //cb_config/store/target_device
deviceScsiId //cb_config/store/target_scsi_id
driveSpeed //cb_config/store/drive_speed
checkData //cb_config/store/check_data
checkMedia //cb_config/store/check_media
warnMidnite //cb_config/store/warn_midnite
noEject //cb_config/store/no_eject
Blanking behavior configuration is parsed by the ``_parseBlankBehavior``
method.
Args:
parentNode: Parent node to search beneath
Returns:
``StoreConfig`` object or ``None`` if the section does not exist
Raises:
ValueError: If some filled-in value is invalid
"""
store = None
sectionNode = readFirstChild(parentNode, "store")
if sectionNode is not None:
store = StoreConfig()
store.sourceDir = readString(sectionNode, "source_dir")
store.mediaType = readString(sectionNode, "media_type")
store.deviceType = readString(sectionNode, "device_type")
store.devicePath = readString(sectionNode, "target_device")
store.deviceScsiId = readString(sectionNode, "target_scsi_id")
store.driveSpeed = readInteger(sectionNode, "drive_speed")
store.checkData = readBoolean(sectionNode, "check_data")
store.checkMedia = readBoolean(sectionNode, "check_media")
store.warnMidnite = readBoolean(sectionNode, "warn_midnite")
store.noEject = readBoolean(sectionNode, "no_eject")
store.blankBehavior = Config._parseBlankBehavior(sectionNode)
store.refreshMediaDelay = readInteger(sectionNode, "refresh_media_delay")
store.ejectDelay = readInteger(sectionNode, "eject_delay")
return store
@staticmethod
def _parsePurge(parentNode):
"""
Parses a purge configuration section.
We read groups of the following items, one list element per
item::
purgeDirs //cb_config/purge/dir
The individual directory entries are parsed by :any:`_parsePurgeDirs`.
Args:
parentNode: Parent node to search beneath
Returns:
``PurgeConfig`` object or ``None`` if the section does not exist
Raises:
ValueError: If some filled-in value is invalid
"""
purge = None
sectionNode = readFirstChild(parentNode, "purge")
if sectionNode is not None:
purge = PurgeConfig()
purge.purgeDirs = Config._parsePurgeDirs(sectionNode)
return purge
@staticmethod
def _parseExtendedActions(parentNode):
"""
Reads extended actions data from immediately beneath the parent.
We read the following individual fields from each extended action::
name name
module module
function function
index index
dependencies depends
Dependency information is parsed by the ``_parseDependencies`` method.
Args:
parentNode: Parent node to search beneath
Returns:
List of extended actions
Raises:
ValueError: If the data at the location can't be read
"""
lst = []
for entry in readChildren(parentNode, "action"):
if isElement(entry):
action = ExtendedAction()
action.name = readString(entry, "name")
action.module = readString(entry, "module")
action.function = readString(entry, "function")
action.index = readInteger(entry, "index")
action.dependencies = Config._parseDependencies(entry)
lst.append(action)
if lst == []:
lst = None
return lst
@staticmethod
def _parseExclusions(parentNode):
"""
Reads exclusions data from immediately beneath the parent.
We read groups of the following items, one list element per item::
absolute exclude/abs_path
relative exclude/rel_path
patterns exclude/pattern
If there are none of some pattern (i.e. no relative path items) then
``None`` will be returned for that item in the tuple.
This method can be used to parse exclusions on both the collect
configuration level and on the collect directory level within collect
configuration.
Args:
parentNode: Parent node to search beneath
Returns:
Tuple of (absolute, relative, patterns) exclusions
"""
sectionNode = readFirstChild(parentNode, "exclude")
if sectionNode is None:
return (None, None, None)
else:
absolute = readStringList(sectionNode, "abs_path")
relative = readStringList(sectionNode, "rel_path")
patterns = readStringList(sectionNode, "pattern")
return (absolute, relative, patterns)
@staticmethod
def _parseOverrides(parentNode):
"""
Reads a list of ``CommandOverride`` objects from immediately beneath the parent.
We read the following individual fields::
command command
absolutePath abs_path
Args:
parentNode: Parent node to search beneath
Returns:
List of ``CommandOverride`` objects or ``None`` if none are found
Raises:
ValueError: If some filled-in value is invalid
"""
lst = []
for entry in readChildren(parentNode, "override"):
if isElement(entry):
override = CommandOverride()
override.command = readString(entry, "command")
override.absolutePath = readString(entry, "abs_path")
lst.append(override)
if lst == []:
lst = None
return lst
@staticmethod
def _parseHooks(parentNode):
"""
Reads a list of ``ActionHook`` objects from immediately beneath the parent.
We read the following individual fields::
action action
command command
Args:
parentNode: Parent node to search beneath
Returns:
List of ``ActionHook`` objects or ``None`` if none are found
Raises:
ValueError: If some filled-in value is invalid
"""
lst = []
for entry in readChildren(parentNode, "pre_action_hook"):
if isElement(entry):
hook = PreActionHook()
hook.action = readString(entry, "action")
hook.command = readString(entry, "command")
lst.append(hook)
for entry in readChildren(parentNode, "post_action_hook"):
if isElement(entry):
hook = PostActionHook()
hook.action = readString(entry, "action")
hook.command = readString(entry, "command")
lst.append(hook)
if lst == []:
lst = None
return lst
@staticmethod
def _parseCollectFiles(parentNode):
"""
Reads a list of ``CollectFile`` objects from immediately beneath the parent.
We read the following individual fields::
absolutePath abs_path
collectMode mode *or* collect_mode
archiveMode archive_mode
The collect mode is a special case. Just a ``mode`` tag is accepted, but
we prefer ``collect_mode`` for consistency with the rest of the config
file and to avoid confusion with the archive mode. If both are provided,
only ``mode`` will be used.
Args:
parentNode: Parent node to search beneath
Returns:
List of ``CollectFile`` objects or ``None`` if none are found
Raises:
ValueError: If some filled-in value is invalid
"""
lst = []
for entry in readChildren(parentNode, "file"):
if isElement(entry):
cfile = CollectFile()
cfile.absolutePath = readString(entry, "abs_path")
cfile.collectMode = readString(entry, "mode")
if cfile.collectMode is None:
cfile.collectMode = readString(entry, "collect_mode")
cfile.archiveMode = readString(entry, "archive_mode")
lst.append(cfile)
if lst == []:
lst = None
return lst
@staticmethod
def _parseCollectDirs(parentNode):
"""
Reads a list of ``CollectDir`` objects from immediately beneath the parent.
We read the following individual fields::
absolutePath abs_path
collectMode mode *or* collect_mode
archiveMode archive_mode
ignoreFile ignore_file
linkDepth link_depth
dereference dereference
recursionLevel recursion_level
The collect mode is a special case. Just a ``mode`` tag is accepted for
backwards compatibility, but we prefer ``collect_mode`` for consistency
with the rest of the config file and to avoid confusion with the archive
mode. If both are provided, only ``mode`` will be used.
We also read groups of the following items, one list element per
item::
absoluteExcludePaths exclude/abs_path
relativeExcludePaths exclude/rel_path
excludePatterns exclude/pattern
The exclusions are parsed by :any:`_parseExclusions`.
Args:
parentNode: Parent node to search beneath
Returns:
List of ``CollectDir`` objects or ``None`` if none are found
Raises:
ValueError: If some filled-in value is invalid
"""
lst = []
for entry in readChildren(parentNode, "dir"):
if isElement(entry):
cdir = CollectDir()
cdir.absolutePath = readString(entry, "abs_path")
cdir.collectMode = readString(entry, "mode")
if cdir.collectMode is None:
cdir.collectMode = readString(entry, "collect_mode")
cdir.archiveMode = readString(entry, "archive_mode")
cdir.ignoreFile = readString(entry, "ignore_file")
cdir.linkDepth = readInteger(entry, "link_depth")
cdir.dereference = readBoolean(entry, "dereference")
cdir.recursionLevel = readInteger(entry, "recursion_level")
(cdir.absoluteExcludePaths, cdir.relativeExcludePaths, cdir.excludePatterns) = Config._parseExclusions(entry)
lst.append(cdir)
if lst == []:
lst = None
return lst
@staticmethod
def _parsePurgeDirs(parentNode):
"""
Reads a list of ``PurgeDir`` objects from immediately beneath the parent.
We read the following individual fields::
absolutePath <baseExpr>/abs_path
retainDays <baseExpr>/retain_days
Args:
parentNode: Parent node to search beneath
Returns:
List of ``PurgeDir`` objects or ``None`` if none are found
Raises:
ValueError: If the data at the location can't be read
"""
lst = []
for entry in readChildren(parentNode, "dir"):
if isElement(entry):
cdir = PurgeDir()
cdir.absolutePath = readString(entry, "abs_path")
cdir.retainDays = readInteger(entry, "retain_days")
lst.append(cdir)
if lst == []:
lst = None
return lst
@staticmethod
def _parsePeerList(parentNode):
"""
Reads remote and local peer data from immediately beneath the parent.
We read the following individual fields for both remote
and local peers::
name name
collectDir collect_dir
We also read the following individual fields for remote peers
only::
remoteUser backup_user
rcpCommand rcp_command
rshCommand rsh_command
cbackCommand cback_command
managed managed
managedActions managed_actions
Additionally, the value in the ``type`` field is used to determine whether
this entry is a remote peer. If the type is ``"remote"``, it's a remote
peer, and if the type is ``"local"``, it's a remote peer.
If there are none of one type of peer (i.e. no local peers) then ``None``
will be returned for that item in the tuple.
Args:
parentNode: Parent node to search beneath
Returns:
Tuple of (local, remote) peer lists
Raises:
ValueError: If the data at the location can't be read
"""
localPeers = []
remotePeers = []
for entry in readChildren(parentNode, "peer"):
if isElement(entry):
peerType = readString(entry, "type")
if peerType == "local":
localPeer = LocalPeer()
localPeer.name = readString(entry, "name")
localPeer.collectDir = readString(entry, "collect_dir")
localPeer.ignoreFailureMode = readString(entry, "ignore_failures")
localPeers.append(localPeer)
elif peerType == "remote":
remotePeer = RemotePeer()
remotePeer.name = readString(entry, "name")
remotePeer.collectDir = readString(entry, "collect_dir")
remotePeer.remoteUser = readString(entry, "backup_user")
remotePeer.rcpCommand = readString(entry, "rcp_command")
remotePeer.rshCommand = readString(entry, "rsh_command")
remotePeer.cbackCommand = readString(entry, "cback_command")
remotePeer.ignoreFailureMode = readString(entry, "ignore_failures")
remotePeer.managed = readBoolean(entry, "managed")
managedActions = readString(entry, "managed_actions")
remotePeer.managedActions = parseCommaSeparatedString(managedActions)
remotePeers.append(remotePeer)
if localPeers == []:
localPeers = None
if remotePeers == []:
remotePeers = None
return (localPeers, remotePeers)
@staticmethod
def _parseDependencies(parentNode):
"""
Reads extended action dependency information from a parent node.
We read the following individual fields::
runBefore depends/run_before
runAfter depends/run_after
Each of these fields is a comma-separated list of action names.
The result is placed into an ``ActionDependencies`` object.
If the dependencies parent node does not exist, ``None`` will be returned.
Otherwise, an ``ActionDependencies`` object will always be created, even
if it does not contain any actual dependencies in it.
Args:
parentNode: Parent node to search beneath
Returns:
``ActionDependencies`` object or ``None``
Raises:
ValueError: If the data at the location can't be read
"""
sectionNode = readFirstChild(parentNode, "depends")
if sectionNode is None:
return None
else:
runBefore = readString(sectionNode, "run_before")
runAfter = readString(sectionNode, "run_after")
beforeList = parseCommaSeparatedString(runBefore)
afterList = parseCommaSeparatedString(runAfter)
return ActionDependencies(beforeList, afterList)
@staticmethod
def _parseBlankBehavior(parentNode):
"""
Reads a single ``BlankBehavior`` object from immediately beneath the parent.
We read the following individual fields::
blankMode blank_behavior/mode
blankFactor blank_behavior/factor
Args:
parentNode: Parent node to search beneath
Returns:
``BlankBehavior`` object or ``None`` if none if the section is not found
Raises:
ValueError: If some filled-in value is invalid
"""
blankBehavior = None
sectionNode = readFirstChild(parentNode, "blank_behavior")
if sectionNode is not None:
blankBehavior = BlankBehavior()
blankBehavior.blankMode = readString(sectionNode, "mode")
blankBehavior.blankFactor = readString(sectionNode, "factor")
return blankBehavior
########################################
# High-level methods for generating XML
########################################
def _extractXml(self):
"""
Internal method to extract configuration into an XML string.
This method assumes that the internal :any:`validate` method has been called
prior to extracting the XML, if the caller cares. No validation will be
done internally.
As a general rule, fields that are set to ``None`` will be extracted into
the document as empty tags. The same goes for container tags that are
filled based on lists - if the list is empty or ``None``, the container
tag will be empty.
"""
(xmlDom, parentNode) = createOutputDom()
Config._addReference(xmlDom, parentNode, self.reference)
Config._addExtensions(xmlDom, parentNode, self.extensions)
Config._addOptions(xmlDom, parentNode, self.options)
Config._addPeers(xmlDom, parentNode, self.peers)
Config._addCollect(xmlDom, parentNode, self.collect)
Config._addStage(xmlDom, parentNode, self.stage)
Config._addStore(xmlDom, parentNode, self.store)
Config._addPurge(xmlDom, parentNode, self.purge)
xmlData = serializeDom(xmlDom)
xmlDom.unlink()
return xmlData
@staticmethod
def _addReference(xmlDom, parentNode, referenceConfig):
"""
Adds a <reference> configuration section as the next child of a parent.
We add the following fields to the document::
author //cb_config/reference/author
revision //cb_config/reference/revision
description //cb_config/reference/description
generator //cb_config/reference/generator
If ``referenceConfig`` is ``None``, then no container will be added.
Args:
xmlDom: DOM tree as from :any:`createOutputDom`
parentNode: Parent that the section should be appended to
referenceConfig: Reference configuration section to be added to the document
"""
if referenceConfig is not None:
sectionNode = addContainerNode(xmlDom, parentNode, "reference")
addStringNode(xmlDom, sectionNode, "author", referenceConfig.author)
addStringNode(xmlDom, sectionNode, "revision", referenceConfig.revision)
addStringNode(xmlDom, sectionNode, "description", referenceConfig.description)
addStringNode(xmlDom, sectionNode, "generator", referenceConfig.generator)
@staticmethod
def _addExtensions(xmlDom, parentNode, extensionsConfig):
"""
Adds an <extensions> configuration section as the next child of a parent.
We add the following fields to the document::
order_mode //cb_config/extensions/order_mode
We also add groups of the following items, one list element per item::
actions //cb_config/extensions/action
The extended action entries are added by :any:`_addExtendedAction`.
If ``extensionsConfig`` is ``None``, then no container will be added.
Args:
xmlDom: DOM tree as from :any:`createOutputDom`
parentNode: Parent that the section should be appended to
extensionsConfig: Extensions configuration section to be added to the document
"""
if extensionsConfig is not None:
sectionNode = addContainerNode(xmlDom, parentNode, "extensions")
addStringNode(xmlDom, sectionNode, "order_mode", extensionsConfig.orderMode)
if extensionsConfig.actions is not None:
for action in extensionsConfig.actions:
Config._addExtendedAction(xmlDom, sectionNode, action)
@staticmethod
def _addOptions(xmlDom, parentNode, optionsConfig):
"""
Adds a <options> configuration section as the next child of a parent.
We add the following fields to the document::
startingDay //cb_config/options/starting_day
workingDir //cb_config/options/working_dir
backupUser //cb_config/options/backup_user
backupGroup //cb_config/options/backup_group
rcpCommand //cb_config/options/rcp_command
rshCommand //cb_config/options/rsh_command
cbackCommand //cb_config/options/cback_command
managedActions //cb_config/options/managed_actions
We also add groups of the following items, one list element per
item::
overrides //cb_config/options/override
hooks //cb_config/options/pre_action_hook
hooks //cb_config/options/post_action_hook
The individual override items are added by :any:`_addOverride`. The
individual hook items are added by :any:`_addHook`.
If ``optionsConfig`` is ``None``, then no container will be added.
Args:
xmlDom: DOM tree as from :any:`createOutputDom`
parentNode: Parent that the section should be appended to
optionsConfig: Options configuration section to be added to the document
"""
if optionsConfig is not None:
sectionNode = addContainerNode(xmlDom, parentNode, "options")
addStringNode(xmlDom, sectionNode, "starting_day", optionsConfig.startingDay)
addStringNode(xmlDom, sectionNode, "working_dir", optionsConfig.workingDir)
addStringNode(xmlDom, sectionNode, "backup_user", optionsConfig.backupUser)
addStringNode(xmlDom, sectionNode, "backup_group", optionsConfig.backupGroup)
addStringNode(xmlDom, sectionNode, "rcp_command", optionsConfig.rcpCommand)
addStringNode(xmlDom, sectionNode, "rsh_command", optionsConfig.rshCommand)
addStringNode(xmlDom, sectionNode, "cback_command", optionsConfig.cbackCommand)
managedActions = Config._buildCommaSeparatedString(optionsConfig.managedActions)
addStringNode(xmlDom, sectionNode, "managed_actions", managedActions)
if optionsConfig.overrides is not None:
for override in optionsConfig.overrides:
Config._addOverride(xmlDom, sectionNode, override)
if optionsConfig.hooks is not None:
for hook in optionsConfig.hooks:
Config._addHook(xmlDom, sectionNode, hook)
@staticmethod
def _addPeers(xmlDom, parentNode, peersConfig):
"""
Adds a <peers> configuration section as the next child of a parent.
We add groups of the following items, one list element per
item::
localPeers //cb_config/peers/peer
remotePeers //cb_config/peers/peer
The individual local and remote peer entries are added by
:any:`_addLocalPeer` and :any:`_addRemotePeer`, respectively.
If ``peersConfig`` is ``None``, then no container will be added.
Args:
xmlDom: DOM tree as from :any:`createOutputDom`
parentNode: Parent that the section should be appended to
peersConfig: Peers configuration section to be added to the document
"""
if peersConfig is not None:
sectionNode = addContainerNode(xmlDom, parentNode, "peers")
if peersConfig.localPeers is not None:
for localPeer in peersConfig.localPeers:
Config._addLocalPeer(xmlDom, sectionNode, localPeer)
if peersConfig.remotePeers is not None:
for remotePeer in peersConfig.remotePeers:
Config._addRemotePeer(xmlDom, sectionNode, remotePeer)
@staticmethod
def _addCollect(xmlDom, parentNode, collectConfig):
"""
Adds a <collect> configuration section as the next child of a parent.
We add the following fields to the document::
targetDir //cb_config/collect/collect_dir
collectMode //cb_config/collect/collect_mode
archiveMode //cb_config/collect/archive_mode
ignoreFile //cb_config/collect/ignore_file
We also add groups of the following items, one list element per
item::
absoluteExcludePaths //cb_config/collect/exclude/abs_path
excludePatterns //cb_config/collect/exclude/pattern
collectFiles //cb_config/collect/file
collectDirs //cb_config/collect/dir
The individual collect files are added by :any:`_addCollectFile` and
individual collect directories are added by :any:`_addCollectDir`.
If ``collectConfig`` is ``None``, then no container will be added.
Args:
xmlDom: DOM tree as from :any:`createOutputDom`
parentNode: Parent that the section should be appended to
collectConfig: Collect configuration section to be added to the document
"""
if collectConfig is not None:
sectionNode = addContainerNode(xmlDom, parentNode, "collect")
addStringNode(xmlDom, sectionNode, "collect_dir", collectConfig.targetDir)
addStringNode(xmlDom, sectionNode, "collect_mode", collectConfig.collectMode)
addStringNode(xmlDom, sectionNode, "archive_mode", collectConfig.archiveMode)
addStringNode(xmlDom, sectionNode, "ignore_file", collectConfig.ignoreFile)
if ((collectConfig.absoluteExcludePaths is not None and collectConfig.absoluteExcludePaths != []) or
(collectConfig.excludePatterns is not None and collectConfig.excludePatterns != [])):
excludeNode = addContainerNode(xmlDom, sectionNode, "exclude")
if collectConfig.absoluteExcludePaths is not None:
for absolutePath in collectConfig.absoluteExcludePaths:
addStringNode(xmlDom, excludeNode, "abs_path", absolutePath)
if collectConfig.excludePatterns is not None:
for pattern in collectConfig.excludePatterns:
addStringNode(xmlDom, excludeNode, "pattern", pattern)
if collectConfig.collectFiles is not None:
for collectFile in collectConfig.collectFiles:
Config._addCollectFile(xmlDom, sectionNode, collectFile)
if collectConfig.collectDirs is not None:
for collectDir in collectConfig.collectDirs:
Config._addCollectDir(xmlDom, sectionNode, collectDir)
@staticmethod
def _addStage(xmlDom, parentNode, stageConfig):
"""
Adds a <stage> configuration section as the next child of a parent.
We add the following fields to the document::
targetDir //cb_config/stage/staging_dir
We also add groups of the following items, one list element per
item::
localPeers //cb_config/stage/peer
remotePeers //cb_config/stage/peer
The individual local and remote peer entries are added by
:any:`_addLocalPeer` and :any:`_addRemotePeer`, respectively.
If ``stageConfig`` is ``None``, then no container will be added.
Args:
xmlDom: DOM tree as from :any:`createOutputDom`
parentNode: Parent that the section should be appended to
stageConfig: Stage configuration section to be added to the document
"""
if stageConfig is not None:
sectionNode = addContainerNode(xmlDom, parentNode, "stage")
addStringNode(xmlDom, sectionNode, "staging_dir", stageConfig.targetDir)
if stageConfig.localPeers is not None:
for localPeer in stageConfig.localPeers:
Config._addLocalPeer(xmlDom, sectionNode, localPeer)
if stageConfig.remotePeers is not None:
for remotePeer in stageConfig.remotePeers:
Config._addRemotePeer(xmlDom, sectionNode, remotePeer)
@staticmethod
def _addStore(xmlDom, parentNode, storeConfig):
"""
Adds a <store> configuration section as the next child of a parent.
We add the following fields to the document::
sourceDir //cb_config/store/source_dir
mediaType //cb_config/store/media_type
deviceType //cb_config/store/device_type
devicePath //cb_config/store/target_device
deviceScsiId //cb_config/store/target_scsi_id
driveSpeed //cb_config/store/drive_speed
checkData //cb_config/store/check_data
checkMedia //cb_config/store/check_media
warnMidnite //cb_config/store/warn_midnite
noEject //cb_config/store/no_eject
refreshMediaDelay //cb_config/store/refresh_media_delay
ejectDelay //cb_config/store/eject_delay
Blanking behavior configuration is added by the :any:`_addBlankBehavior`
method.
If ``storeConfig`` is ``None``, then no container will be added.
Args:
xmlDom: DOM tree as from :any:`createOutputDom`
parentNode: Parent that the section should be appended to
storeConfig: Store configuration section to be added to the document
"""
if storeConfig is not None:
sectionNode = addContainerNode(xmlDom, parentNode, "store")
addStringNode(xmlDom, sectionNode, "source_dir", storeConfig.sourceDir)
addStringNode(xmlDom, sectionNode, "media_type", storeConfig.mediaType)
addStringNode(xmlDom, sectionNode, "device_type", storeConfig.deviceType)
addStringNode(xmlDom, sectionNode, "target_device", storeConfig.devicePath)
addStringNode(xmlDom, sectionNode, "target_scsi_id", storeConfig.deviceScsiId)
addIntegerNode(xmlDom, sectionNode, "drive_speed", storeConfig.driveSpeed)
addBooleanNode(xmlDom, sectionNode, "check_data", storeConfig.checkData)
addBooleanNode(xmlDom, sectionNode, "check_media", storeConfig.checkMedia)
addBooleanNode(xmlDom, sectionNode, "warn_midnite", storeConfig.warnMidnite)
addBooleanNode(xmlDom, sectionNode, "no_eject", storeConfig.noEject)
addIntegerNode(xmlDom, sectionNode, "refresh_media_delay", storeConfig.refreshMediaDelay)
addIntegerNode(xmlDom, sectionNode, "eject_delay", storeConfig.ejectDelay)
Config._addBlankBehavior(xmlDom, sectionNode, storeConfig.blankBehavior)
@staticmethod
def _addPurge(xmlDom, parentNode, purgeConfig):
"""
Adds a <purge> configuration section as the next child of a parent.
We add the following fields to the document::
purgeDirs //cb_config/purge/dir
The individual directory entries are added by :any:`_addPurgeDir`.
If ``purgeConfig`` is ``None``, then no container will be added.
Args:
xmlDom: DOM tree as from :any:`createOutputDom`
parentNode: Parent that the section should be appended to
purgeConfig: Purge configuration section to be added to the document
"""
if purgeConfig is not None:
sectionNode = addContainerNode(xmlDom, parentNode, "purge")
if purgeConfig.purgeDirs is not None:
for purgeDir in purgeConfig.purgeDirs:
Config._addPurgeDir(xmlDom, sectionNode, purgeDir)
@staticmethod
def _addExtendedAction(xmlDom, parentNode, action):
"""
Adds an extended action container as the next child of a parent.
We add the following fields to the document::
name action/name
module action/module
function action/function
index action/index
dependencies action/depends
Dependencies are added by the :any:`_addDependencies` method.
The <action> node itself is created as the next child of the parent node.
This method only adds one action node. The parent must loop for each action
in the ``ExtensionsConfig`` object.
If ``action`` is ``None``, this method call will be a no-op.
Args:
xmlDom: DOM tree as from :any:`createOutputDom`
parentNode: Parent that the section should be appended to
action: Purge directory to be added to the document
"""
if action is not None:
sectionNode = addContainerNode(xmlDom, parentNode, "action")
addStringNode(xmlDom, sectionNode, "name", action.name)
addStringNode(xmlDom, sectionNode, "module", action.module)
addStringNode(xmlDom, sectionNode, "function", action.function)
addIntegerNode(xmlDom, sectionNode, "index", action.index)
Config._addDependencies(xmlDom, sectionNode, action.dependencies)
@staticmethod
def _addOverride(xmlDom, parentNode, override):
"""
Adds a command override container as the next child of a parent.
We add the following fields to the document::
command override/command
absolutePath override/abs_path
The <override> node itself is created as the next child of the parent
node. This method only adds one override node. The parent must loop for
each override in the ``OptionsConfig`` object.
If ``override`` is ``None``, this method call will be a no-op.
Args:
xmlDom: DOM tree as from :any:`createOutputDom`
parentNode: Parent that the section should be appended to
override: Command override to be added to the document
"""
if override is not None:
sectionNode = addContainerNode(xmlDom, parentNode, "override")
addStringNode(xmlDom, sectionNode, "command", override.command)
addStringNode(xmlDom, sectionNode, "abs_path", override.absolutePath)
@staticmethod
def _addHook(xmlDom, parentNode, hook):
"""
Adds an action hook container as the next child of a parent.
The behavior varies depending on the value of the ``before`` and ``after``
flags on the hook. If the ``before`` flag is set, it's a pre-action hook,
and we'll add the following fields::
action pre_action_hook/action
command pre_action_hook/command
If the ``after`` flag is set, it's a post-action hook, and we'll add the
following fields::
action post_action_hook/action
command post_action_hook/command
The <pre_action_hook> or <post_action_hook> node itself is created as the
next child of the parent node. This method only adds one hook node. The
parent must loop for each hook in the ``OptionsConfig`` object.
If ``hook`` is ``None``, this method call will be a no-op.
Args:
xmlDom: DOM tree as from :any:`createOutputDom`
parentNode: Parent that the section should be appended to
hook: Command hook to be added to the document
"""
if hook is not None:
if hook.before:
sectionNode = addContainerNode(xmlDom, parentNode, "pre_action_hook")
else:
sectionNode = addContainerNode(xmlDom, parentNode, "post_action_hook")
addStringNode(xmlDom, sectionNode, "action", hook.action)
addStringNode(xmlDom, sectionNode, "command", hook.command)
@staticmethod
def _addCollectFile(xmlDom, parentNode, collectFile):
"""
Adds a collect file container as the next child of a parent.
We add the following fields to the document::
absolutePath dir/abs_path
collectMode dir/collect_mode
archiveMode dir/archive_mode
Note that for consistency with collect directory handling we'll only emit
the preferred ``collect_mode`` tag.
The <file> node itself is created as the next child of the parent node.
This method only adds one collect file node. The parent must loop
for each collect file in the ``CollectConfig`` object.
If ``collectFile`` is ``None``, this method call will be a no-op.
Args:
xmlDom: DOM tree as from :any:`createOutputDom`
parentNode: Parent that the section should be appended to
collectFile: Collect file to be added to the document
"""
if collectFile is not None:
sectionNode = addContainerNode(xmlDom, parentNode, "file")
addStringNode(xmlDom, sectionNode, "abs_path", collectFile.absolutePath)
addStringNode(xmlDom, sectionNode, "collect_mode", collectFile.collectMode)
addStringNode(xmlDom, sectionNode, "archive_mode", collectFile.archiveMode)
@staticmethod
def _addCollectDir(xmlDom, parentNode, collectDir):
"""
Adds a collect directory container as the next child of a parent.
We add the following fields to the document::
absolutePath dir/abs_path
collectMode dir/collect_mode
archiveMode dir/archive_mode
ignoreFile dir/ignore_file
linkDepth dir/link_depth
dereference dir/dereference
recursionLevel dir/recursion_level
Note that an original XML document might have listed the collect mode
using the ``mode`` tag, since we accept both ``collect_mode`` and ``mode``.
However, here we'll only emit the preferred ``collect_mode`` tag.
We also add groups of the following items, one list element per item::
absoluteExcludePaths dir/exclude/abs_path
relativeExcludePaths dir/exclude/rel_path
excludePatterns dir/exclude/pattern
The <dir> node itself is created as the next child of the parent node.
This method only adds one collect directory node. The parent must loop
for each collect directory in the ``CollectConfig`` object.
If ``collectDir`` is ``None``, this method call will be a no-op.
Args:
xmlDom: DOM tree as from :any:`createOutputDom`
parentNode: Parent that the section should be appended to
collectDir: Collect directory to be added to the document
"""
if collectDir is not None:
sectionNode = addContainerNode(xmlDom, parentNode, "dir")
addStringNode(xmlDom, sectionNode, "abs_path", collectDir.absolutePath)
addStringNode(xmlDom, sectionNode, "collect_mode", collectDir.collectMode)
addStringNode(xmlDom, sectionNode, "archive_mode", collectDir.archiveMode)
addStringNode(xmlDom, sectionNode, "ignore_file", collectDir.ignoreFile)
addIntegerNode(xmlDom, sectionNode, "link_depth", collectDir.linkDepth)
addBooleanNode(xmlDom, sectionNode, "dereference", collectDir.dereference)
addIntegerNode(xmlDom, sectionNode, "recursion_level", collectDir.recursionLevel)
if ((collectDir.absoluteExcludePaths is not None and collectDir.absoluteExcludePaths != []) or
(collectDir.relativeExcludePaths is not None and collectDir.relativeExcludePaths != []) or
(collectDir.excludePatterns is not None and collectDir.excludePatterns != [])):
excludeNode = addContainerNode(xmlDom, sectionNode, "exclude")
if collectDir.absoluteExcludePaths is not None:
for absolutePath in collectDir.absoluteExcludePaths:
addStringNode(xmlDom, excludeNode, "abs_path", absolutePath)
if collectDir.relativeExcludePaths is not None:
for relativePath in collectDir.relativeExcludePaths:
addStringNode(xmlDom, excludeNode, "rel_path", relativePath)
if collectDir.excludePatterns is not None:
for pattern in collectDir.excludePatterns:
addStringNode(xmlDom, excludeNode, "pattern", pattern)
@staticmethod
def _addLocalPeer(xmlDom, parentNode, localPeer):
"""
Adds a local peer container as the next child of a parent.
We add the following fields to the document::
name peer/name
collectDir peer/collect_dir
ignoreFailureMode peer/ignore_failures
Additionally, ``peer/type`` is filled in with ``"local"``, since this is a
local peer.
The <peer> node itself is created as the next child of the parent node.
This method only adds one peer node. The parent must loop for each peer
in the ``StageConfig`` object.
If ``localPeer`` is ``None``, this method call will be a no-op.
Args:
xmlDom: DOM tree as from :any:`createOutputDom`
parentNode: Parent that the section should be appended to
localPeer: Purge directory to be added to the document
"""
if localPeer is not None:
sectionNode = addContainerNode(xmlDom, parentNode, "peer")
addStringNode(xmlDom, sectionNode, "name", localPeer.name)
addStringNode(xmlDom, sectionNode, "type", "local")
addStringNode(xmlDom, sectionNode, "collect_dir", localPeer.collectDir)
addStringNode(xmlDom, sectionNode, "ignore_failures", localPeer.ignoreFailureMode)
@staticmethod
def _addRemotePeer(xmlDom, parentNode, remotePeer):
"""
Adds a remote peer container as the next child of a parent.
We add the following fields to the document::
name peer/name
collectDir peer/collect_dir
remoteUser peer/backup_user
rcpCommand peer/rcp_command
rcpCommand peer/rcp_command
rshCommand peer/rsh_command
cbackCommand peer/cback_command
ignoreFailureMode peer/ignore_failures
managed peer/managed
managedActions peer/managed_actions
Additionally, ``peer/type`` is filled in with ``"remote"``, since this is a
remote peer.
The <peer> node itself is created as the next child of the parent node.
This method only adds one peer node. The parent must loop for each peer
in the ``StageConfig`` object.
If ``remotePeer`` is ``None``, this method call will be a no-op.
Args:
xmlDom: DOM tree as from :any:`createOutputDom`
parentNode: Parent that the section should be appended to
remotePeer: Purge directory to be added to the document
"""
if remotePeer is not None:
sectionNode = addContainerNode(xmlDom, parentNode, "peer")
addStringNode(xmlDom, sectionNode, "name", remotePeer.name)
addStringNode(xmlDom, sectionNode, "type", "remote")
addStringNode(xmlDom, sectionNode, "collect_dir", remotePeer.collectDir)
addStringNode(xmlDom, sectionNode, "backup_user", remotePeer.remoteUser)
addStringNode(xmlDom, sectionNode, "rcp_command", remotePeer.rcpCommand)
addStringNode(xmlDom, sectionNode, "rsh_command", remotePeer.rshCommand)
addStringNode(xmlDom, sectionNode, "cback_command", remotePeer.cbackCommand)
addStringNode(xmlDom, sectionNode, "ignore_failures", remotePeer.ignoreFailureMode)
addBooleanNode(xmlDom, sectionNode, "managed", remotePeer.managed)
managedActions = Config._buildCommaSeparatedString(remotePeer.managedActions)
addStringNode(xmlDom, sectionNode, "managed_actions", managedActions)
@staticmethod
def _addPurgeDir(xmlDom, parentNode, purgeDir):
"""
Adds a purge directory container as the next child of a parent.
We add the following fields to the document::
absolutePath dir/abs_path
retainDays dir/retain_days
The <dir> node itself is created as the next child of the parent node.
This method only adds one purge directory node. The parent must loop for
each purge directory in the ``PurgeConfig`` object.
If ``purgeDir`` is ``None``, this method call will be a no-op.
Args:
xmlDom: DOM tree as from :any:`createOutputDom`
parentNode: Parent that the section should be appended to
purgeDir: Purge directory to be added to the document
"""
if purgeDir is not None:
sectionNode = addContainerNode(xmlDom, parentNode, "dir")
addStringNode(xmlDom, sectionNode, "abs_path", purgeDir.absolutePath)
addIntegerNode(xmlDom, sectionNode, "retain_days", purgeDir.retainDays)
@staticmethod
def _addDependencies(xmlDom, parentNode, dependencies):
"""
Adds a extended action dependencies to parent node.
We add the following fields to the document::
runBefore depends/run_before
runAfter depends/run_after
If ``dependencies`` is ``None``, this method call will be a no-op.
Args:
xmlDom: DOM tree as from :any:`createOutputDom`
parentNode: Parent that the section should be appended to
dependencies: ``ActionDependencies`` object to be added to the document
"""
if dependencies is not None:
sectionNode = addContainerNode(xmlDom, parentNode, "depends")
runBefore = Config._buildCommaSeparatedString(dependencies.beforeList)
runAfter = Config._buildCommaSeparatedString(dependencies.afterList)
addStringNode(xmlDom, sectionNode, "run_before", runBefore)
addStringNode(xmlDom, sectionNode, "run_after", runAfter)
@staticmethod
def _buildCommaSeparatedString(valueList):
"""
Creates a comma-separated string from a list of values.
As a special case, if ``valueList`` is ``None``, then ``None`` will be
returned.
Args:
valueList: List of values to be placed into a string
Returns:
Values from valueList as a comma-separated string
"""
if valueList is None:
return None
return ",".join(valueList)
@staticmethod
def _addBlankBehavior(xmlDom, parentNode, blankBehavior):
"""
Adds a blanking behavior container as the next child of a parent.
We add the following fields to the document::
blankMode blank_behavior/mode
blankFactor blank_behavior/factor
The <blank_behavior> node itself is created as the next child of the
parent node.
If ``blankBehavior`` is ``None``, this method call will be a no-op.
Args:
xmlDom: DOM tree as from :any:`createOutputDom`
parentNode: Parent that the section should be appended to
blankBehavior: Blanking behavior to be added to the document
"""
if blankBehavior is not None:
sectionNode = addContainerNode(xmlDom, parentNode, "blank_behavior")
addStringNode(xmlDom, sectionNode, "mode", blankBehavior.blankMode)
addStringNode(xmlDom, sectionNode, "factor", blankBehavior.blankFactor)
#################################################
# High-level methods used for validating content
#################################################
def _validateContents(self):
"""
Validates configuration contents per rules discussed in module
documentation.
This is the second pass at validation. It ensures that any filled-in
section contains valid data. Any sections which is not set to ``None`` is
validated per the rules for that section, laid out in the module
documentation (above).
Raises:
ValueError: If configuration is invalid
"""
self._validateReference()
self._validateExtensions()
self._validateOptions()
self._validatePeers()
self._validateCollect()
self._validateStage()
self._validateStore()
self._validatePurge()
def _validateReference(self):
"""
Validates reference configuration.
There are currently no reference-related validations.
Raises:
ValueError: If reference configuration is invalid
"""
pass
def _validateExtensions(self):
"""
Validates extensions configuration.
The list of actions may be either ``None`` or an empty list ``[]`` if
desired. Each extended action must include a name, a module, and a
function.
Then, if the order mode is None or "index", an index is required; and if
the order mode is "dependency", dependency information is required.
Raises:
ValueError: If reference configuration is invalid
"""
if self.extensions is not None:
if self.extensions.actions is not None:
names = []
for action in self.extensions.actions:
if action.name is None:
raise ValueError("Each extended action must set a name.")
names.append(action.name)
if action.module is None:
raise ValueError("Each extended action must set a module.")
if action.function is None:
raise ValueError("Each extended action must set a function.")
if self.extensions.orderMode is None or self.extensions.orderMode == "index":
if action.index is None:
raise ValueError("Each extended action must set an index, based on order mode.")
elif self.extensions.orderMode == "dependency":
if action.dependencies is None:
raise ValueError("Each extended action must set dependency information, based on order mode.")
checkUnique("Duplicate extension names exist:", names)
def _validateOptions(self):
"""
Validates options configuration.
All fields must be filled in except the rsh command. The rcp and rsh
commands are used as default values for all remote peers. Remote peers
can also rely on the backup user as the default remote user name if they
choose.
Raises:
ValueError: If reference configuration is invalid
"""
if self.options is not None:
if self.options.startingDay is None:
raise ValueError("Options section starting day must be filled in.")
if self.options.workingDir is None:
raise ValueError("Options section working directory must be filled in.")
if self.options.backupUser is None:
raise ValueError("Options section backup user must be filled in.")
if self.options.backupGroup is None:
raise ValueError("Options section backup group must be filled in.")
if self.options.rcpCommand is None:
raise ValueError("Options section remote copy command must be filled in.")
def _validatePeers(self):
"""
Validates peers configuration per rules in :any:`_validatePeerList`.
Raises:
ValueError: If peers configuration is invalid
"""
if self.peers is not None:
self._validatePeerList(self.peers.localPeers, self.peers.remotePeers)
def _validateCollect(self):
"""
Validates collect configuration.
The target directory must be filled in. The collect mode, archive mode,
ignore file, and recursion level are all optional. The list of absolute
paths to exclude and patterns to exclude may be either ``None`` or an
empty list ``[]`` if desired.
Each collect directory entry must contain an absolute path to collect,
and then must either be able to take collect mode, archive mode and
ignore file configuration from the parent ``CollectConfig`` object, or
must set each value on its own. The list of absolute paths to exclude,
relative paths to exclude and patterns to exclude may be either ``None``
or an empty list ``[]`` if desired. Any list of absolute paths to exclude
or patterns to exclude will be combined with the same list in the
``CollectConfig`` object to make the complete list for a given directory.
Raises:
ValueError: If collect configuration is invalid
"""
if self.collect is not None:
if self.collect.targetDir is None:
raise ValueError("Collect section target directory must be filled in.")
if self.collect.collectFiles is not None:
for collectFile in self.collect.collectFiles:
if collectFile.absolutePath is None:
raise ValueError("Each collect file must set an absolute path.")
if self.collect.collectMode is None and collectFile.collectMode is None:
raise ValueError("Collect mode must either be set in parent collect section or individual collect file.")
if self.collect.archiveMode is None and collectFile.archiveMode is None:
raise ValueError("Archive mode must either be set in parent collect section or individual collect file.")
if self.collect.collectDirs is not None:
for collectDir in self.collect.collectDirs:
if collectDir.absolutePath is None:
raise ValueError("Each collect directory must set an absolute path.")
if self.collect.collectMode is None and collectDir.collectMode is None:
raise ValueError("Collect mode must either be set in parent collect section or individual collect directory.")
if self.collect.archiveMode is None and collectDir.archiveMode is None:
raise ValueError("Archive mode must either be set in parent collect section or individual collect directory.")
if self.collect.ignoreFile is None and collectDir.ignoreFile is None:
raise ValueError("Ignore file must either be set in parent collect section or individual collect directory.")
if (collectDir.linkDepth is None or collectDir.linkDepth < 1) and collectDir.dereference:
raise ValueError("Dereference flag is only valid when a non-zero link depth is in use.")
def _validateStage(self):
"""
Validates stage configuration.
The target directory must be filled in, and the peers are
also validated.
Peers are only required in this section if the peers configuration
section is not filled in. However, if any peers are filled in
here, they override the peers configuration and must meet the
validation criteria in :any:`_validatePeerList`.
Raises:
ValueError: If stage configuration is invalid
"""
if self.stage is not None:
if self.stage.targetDir is None:
raise ValueError("Stage section target directory must be filled in.")
if self.peers is None:
# In this case, stage configuration is our only configuration and must be valid.
self._validatePeerList(self.stage.localPeers, self.stage.remotePeers)
else:
# In this case, peers configuration is the default and stage configuration overrides.
# Validation is only needed if it's stage configuration is actually filled in.
if self.stage.hasPeers():
self._validatePeerList(self.stage.localPeers, self.stage.remotePeers)
def _validateStore(self):
"""
Validates store configuration.
The device type, drive speed, and blanking behavior are optional. All
other values are required. Missing booleans will be set to defaults.
If blanking behavior is provided, then both a blanking mode and a
blanking factor are required.
The image writer functionality in the ``writer`` module is supposed to be
able to handle a device speed of ``None``.
Any caller which needs a "real" (non-``None``) value for the device type
can use ``DEFAULT_DEVICE_TYPE``, which is guaranteed to be sensible.
This is also where we make sure that the media type -- which is already a
valid type -- matches up properly with the device type.
Raises:
ValueError: If store configuration is invalid
"""
if self.store is not None:
if self.store.sourceDir is None:
raise ValueError("Store section source directory must be filled in.")
if self.store.mediaType is None:
raise ValueError("Store section media type must be filled in.")
if self.store.devicePath is None:
raise ValueError("Store section device path must be filled in.")
if self.store.deviceType is None or self.store.deviceType == "cdwriter":
if self.store.mediaType not in VALID_CD_MEDIA_TYPES:
raise ValueError("Media type must match device type.")
elif self.store.deviceType == "dvdwriter":
if self.store.mediaType not in VALID_DVD_MEDIA_TYPES:
raise ValueError("Media type must match device type.")
if self.store.blankBehavior is not None:
if self.store.blankBehavior.blankMode is None and self.store.blankBehavior.blankFactor is None:
raise ValueError("If blanking behavior is provided, all values must be filled in.")
def _validatePurge(self):
"""
Validates purge configuration.
The list of purge directories may be either ``None`` or an empty list
``[]`` if desired. All purge directories must contain a path and a retain
days value.
Raises:
ValueError: If purge configuration is invalid
"""
if self.purge is not None:
if self.purge.purgeDirs is not None:
for purgeDir in self.purge.purgeDirs:
if purgeDir.absolutePath is None:
raise ValueError("Each purge directory must set an absolute path.")
if purgeDir.retainDays is None:
raise ValueError("Each purge directory must set a retain days value.")
def _validatePeerList(self, localPeers, remotePeers):
"""
Validates the set of local and remote peers.
Local peers must be completely filled in, including both name and collect
directory. Remote peers must also fill in the name and collect
directory, but can leave the remote user and rcp command unset. In this
case, the remote user is assumed to match the backup user from the
options section and rcp command is taken directly from the options
section.
Args:
localPeers: List of local peers
remotePeers: List of remote peers
Raises:
ValueError: If stage configuration is invalid
"""
if localPeers is None and remotePeers is None:
raise ValueError("Peer list must contain at least one backup peer.")
if localPeers is None and remotePeers is not None:
if len(remotePeers) < 1:
raise ValueError("Peer list must contain at least one backup peer.")
elif localPeers is not None and remotePeers is None:
if len(localPeers) < 1:
raise ValueError("Peer list must contain at least one backup peer.")
elif localPeers is not None and remotePeers is not None:
if len(localPeers) + len(remotePeers) < 1:
raise ValueError("Peer list must contain at least one backup peer.")
names = []
if localPeers is not None:
for localPeer in localPeers:
if localPeer.name is None:
raise ValueError("Local peers must set a name.")
names.append(localPeer.name)
if localPeer.collectDir is None:
raise ValueError("Local peers must set a collect directory.")
if remotePeers is not None:
for remotePeer in remotePeers:
if remotePeer.name is None:
raise ValueError("Remote peers must set a name.")
names.append(remotePeer.name)
if remotePeer.collectDir is None:
raise ValueError("Remote peers must set a collect directory.")
if (self.options is None or self.options.backupUser is None) and remotePeer.remoteUser is None:
raise ValueError("Remote user must either be set in options section or individual remote peer.")
if (self.options is None or self.options.rcpCommand is None) and remotePeer.rcpCommand is None:
raise ValueError("Remote copy command must either be set in options section or individual remote peer.")
if remotePeer.managed:
if (self.options is None or self.options.rshCommand is None) and remotePeer.rshCommand is None:
raise ValueError("Remote shell command must either be set in options section or individual remote peer.")
if (self.options is None or self.options.cbackCommand is None) and remotePeer.cbackCommand is None:
raise ValueError("Remote cback command must either be set in options section or individual remote peer.")
if ((self.options is None or self.options.managedActions is None or len(self.options.managedActions) < 1)
and (remotePeer.managedActions is None or len(remotePeer.managedActions) < 1)):
raise ValueError("Managed actions list must be set in options section or individual remote peer.")
checkUnique("Duplicate peer names exist:", names)
########################################################################
# General utility functions
########################################################################
def readByteQuantity(parent, name):
"""
Read a byte size value from an XML document.
A byte size value is an interpreted string value. If the string value
ends with "MB" or "GB", then the string before that is interpreted as
megabytes or gigabytes. Otherwise, it is intepreted as bytes.
Args:
parent: Parent node to search beneath
name: Name of node to search for
Returns:
ByteQuantity parsed from XML document
"""
data = readString(parent, name)
if data is None:
return None
data = data.strip()
if data.endswith("KB"):
quantity = data[0:data.rfind("KB")].strip()
units = UNIT_KBYTES
elif data.endswith("MB"):
quantity = data[0:data.rfind("MB")].strip()
units = UNIT_MBYTES
elif data.endswith("GB"):
quantity = data[0:data.rfind("GB")].strip()
units = UNIT_GBYTES
else:
quantity = data.strip()
units = UNIT_BYTES
return ByteQuantity(quantity, units)
def addByteQuantityNode(xmlDom, parentNode, nodeName, byteQuantity):
"""
Adds a text node as the next child of a parent, to contain a byte size.
If the ``byteQuantity`` is None, then the node will be created, but will
be empty (i.e. will contain no text node child).
The size in bytes will be normalized. If it is larger than 1.0 GB, it will
be shown in GB ("1.0 GB"). If it is larger than 1.0 MB ("1.0 MB"), it will
be shown in MB. Otherwise, it will be shown in bytes ("423413").
Args:
xmlDom: DOM tree as from ``impl.createDocument()``
parentNode: Parent node to create child for
nodeName: Name of the new container node
byteQuantity: ByteQuantity object to put into the XML document
Returns:
Reference to the newly-created node
"""
if byteQuantity is None:
byteString = None
elif byteQuantity.units == UNIT_KBYTES:
byteString = "%s KB" % byteQuantity.quantity
elif byteQuantity.units == UNIT_MBYTES:
byteString = "%s MB" % byteQuantity.quantity
elif byteQuantity.units == UNIT_GBYTES:
byteString = "%s GB" % byteQuantity.quantity
else:
byteString = byteQuantity.quantity
return addStringNode(xmlDom, parentNode, nodeName, byteString)
|