/usr/share/pyshared/CedarBackup2/config.py is in cedar-backup2 2.22.0-1.
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 | # -*- 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 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 (>= 2.5)
# Project : Cedar Backup, release 2
# Revision : $Id: config.py 1041 2013-05-10 02:05:13Z pronovic $
# 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 C{cback.conf}. The standard location for this document is in
C{/etc}, but users can specify a different location if they want to.
The C{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 C{Config} object, and then changes to the object can be propogated
back to disk. A C{Config} object can even be used to create a configuration
file from scratch programmatically.
The C{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 C{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 I{must} result in a C{Config} object which
passes the validations laid out below in the I{Validation} section.
An XML configuration file is composed of seven sections:
- I{reference}: specifies reference information about the file (author, revision, etc)
- I{extensions}: specifies mappings to Cedar Backup extensions (external code)
- I{options}: specifies global configuration options
- I{peers}: specifies the set of peers in a master's backup pool
- I{collect}: specifies configuration related to the collect action
- I{stage}: specifies configuration related to the stage action
- I{store}: specifies configuration related to the store action
- I{purge}: specifies configuration related to the purge action
Each section is represented by an class in this module, and then the overall
C{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 C{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 I{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. C{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 L{util.encodePath}. The main exception is
the various C{absoluteExcludePath} and C{relativeExcludePath} lists. These
are I{not} converted, because they are generally only used for filtering,
not for filesystem operations.
Validation
==========
There are two main levels of validation in the C{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 C{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
C{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
L{Config.validate} method. This method can be called at any time by a
client, and will always be called immediately after creating a C{Config}
object from XML data and before exporting a C{Config} object to XML. This
way, we get decent ease-of-use but we also don't accept or emit invalid
configuration files.
The L{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 C{None} is validated according
to the rules for that section (see below).
I{Reference Validations}
No validations.
I{Extensions Validations}
The list of actions may be either C{None} or an empty list C{[]} 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.
I{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.
I{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.
I{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 C{None} or an empty list C{[]} 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 C{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 C{None} or an empty list C{[]}
if desired. Any list of absolute paths to exclude or patterns to exclude
will be combined with the same list in the C{CollectConfig} object to make
the complete list for a given directory.
I{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 C{None} or an empty list C{[]} if desired.
If a set of peers is provided, this configuration completely overrides
configuration in the peers configuration section, and the same validations
apply.
I{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 C{writer} module is supposed to be
able to handle a device speed of C{None}. Any caller which needs a "real"
(non-C{None}) value for the device type can use C{DEFAULT_DEVICE_TYPE},
which is guaranteed to be sensible.
I{Purge Validations}
The list of purge directories may be either C{None} or an empty list C{[]}
if desired. All purge directories must contain a path and a retain days
value.
@sort: ActionDependencies, ActionHook, PreActionHook, PostActionHook,
ExtendedAction, CommandOverride, CollectFile, CollectDir, PurgeDir, LocalPeer,
RemotePeer, ReferenceConfig, ExtensionsConfig, OptionsConfig, PeersConfig,
CollectConfig, StageConfig, StoreConfig, PurgeConfig, Config,
DEFAULT_DEVICE_TYPE, DEFAULT_MEDIA_TYPE,
VALID_DEVICE_TYPES, VALID_MEDIA_TYPES,
VALID_COLLECT_MODES, VALID_ARCHIVE_MODES,
VALID_ORDER_MODES
@var DEFAULT_DEVICE_TYPE: The default device type.
@var DEFAULT_MEDIA_TYPE: The default media type.
@var VALID_DEVICE_TYPES: List of valid device types.
@var VALID_MEDIA_TYPES: List of valid media types.
@var VALID_COLLECT_MODES: List of valid collect modes.
@var VALID_COMPRESS_MODES: List of valid compress modes.
@var VALID_ARCHIVE_MODES: List of valid archive modes.
@var 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
# Cedar Backup modules
from CedarBackup2.writers.util import validateScsiId, validateDriveSpeed
from CedarBackup2.util import UnorderedList, AbsolutePathList, ObjectTypeList, parseCommaSeparatedString
from CedarBackup2.util import RegexMatchList, RegexList, encodePath, checkUnique
from CedarBackup2.util import convertSize, UNIT_BYTES, UNIT_KBYTES, UNIT_MBYTES, UNIT_GBYTES
from CedarBackup2.xmlutil import isElement, readChildren, readFirstChild
from CedarBackup2.xmlutil import readStringList, readString, readInteger, readBoolean
from CedarBackup2.xmlutil import addContainerNode, addStringNode, addIntegerNode, addBooleanNode
from CedarBackup2.xmlutil import createInputDom, createOutputDom, serializeDom
########################################################################
# Module-wide constants and variables
########################################################################
logger = logging.getLogger("CedarBackup2.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
########################################################################
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.
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.
@sort: __init__, __repr__, __str__, __cmp__, quantity, units
"""
def __init__(self, quantity=None, units=None):
"""
Constructor for the C{ByteQuantity} class.
@param quantity: Quantity of bytes, as string ("1.25")
@param units: Unit of bytes, one of VALID_BYTE_UNITS
@raise 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 self.__repr__()
def __cmp__(self, other):
"""
Definition of equals operator for this class.
Lists within this class are "unordered" for equality comparisons.
@param other: Other object to compare to.
@return: -1/0/1 depending on whether self is C{<}, C{=} or C{>} other.
"""
if other is None:
return 1
if self.quantity != other.quantity:
if self.quantity < other.quantity:
return -1
else:
return 1
if self.units != other.units:
if self.units < other.units:
return -1
else:
return 1
return 0
def _setQuantity(self, value):
"""
Property target used to set the quantity
The value must be a non-empty string if it is not C{None}.
@raise ValueError: If the value is an empty string.
@raise ValueError: If the value is not a valid floating point number
@raise ValueError: If the value is less than zero
"""
if value is not None:
if len(value) < 1:
raise ValueError("Quantity must be a non-empty string.")
floatValue = float(value)
if floatValue < 0.0:
raise ValueError("Quantity cannot be negative.")
self._quantity = 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 C{None}, the units value must be one of the values in L{VALID_BYTE_UNITS}.
@raise ValueError: If the value is not valid.
"""
if value is not None:
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
########################################################################
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 C{ACTION_NAME_REGEX}
@sort: __init__, __repr__, __str__, __cmp__, beforeList, afterList
"""
def __init__(self, beforeList=None, afterList=None):
"""
Constructor for the C{ActionDependencies} class.
@param beforeList: List of named actions that this action must be run before
@param afterList: List of named actions that this action must be run after
@raise 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 __cmp__(self, other):
"""
Definition of equals operator for this class.
@param other: Other object to compare to.
@return: -1/0/1 depending on whether self is C{<}, C{=} or C{>} 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 C{None} or each element must be a string matching ACTION_NAME_REGEX.
@raise 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, 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 C{None} or each element must be a string matching ACTION_NAME_REGEX.
@raise 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, 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
########################################################################
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 C{ACTION_NAME_REGEX}
- The shell command must be a non-empty string.
The internal C{before} and C{after} instance variables are always set to
False in this parent class.
@sort: __init__, __repr__, __str__, __cmp__, action, command, before, after
"""
def __init__(self, action=None, command=None):
"""
Constructor for the C{ActionHook} class.
@param action: Action this hook is associated with
@param command: Shell command to execute
@raise 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 __cmp__(self, other):
"""
Definition of equals operator for this class.
@param other: Other object to compare to.
@return: -1/0/1 depending on whether self is C{<}, C{=} or C{>} other.
"""
if other is None:
return 1
if self.action != other.action:
if self.action < other.action:
return -1
else:
return 1
if self.command != other.command:
if self.command < other.command:
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 C{None}.
It must also consist only of lower-case letters and digits.
@raise 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 C{None}.
@raise 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.")
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 C{before} instance variable is always set to True in this
class.
@sort: __init__, __repr__, __str__, __cmp__, action, command, before, after
"""
def __init__(self, action=None, command=None):
"""
Constructor for the C{PreActionHook} class.
@param action: Action this hook is associated with
@param command: Shell command to execute
@raise 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)
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 C{before} instance variable is always set to True in this
class.
@sort: __init__, __repr__, __str__, __cmp__, action, command, before, after
"""
def __init__(self, action=None, command=None):
"""
Constructor for the C{PostActionHook} class.
@param action: Action this hook is associated with
@param command: Shell command to execute
@raise 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
########################################################################
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 L{VALID_BLANK_MODES}
- The blanking factor must be a positive floating point number
@sort: __init__, __repr__, __str__, __cmp__, blankMode, blankFactor
"""
def __init__(self, blankMode=None, blankFactor=None):
"""
Constructor for the C{BlankBehavior} class.
@param blankMode: Blanking mode
@param blankFactor: Blanking factor
@raise 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 __cmp__(self, other):
"""
Definition of equals operator for this class.
@param other: Other object to compare to.
@return: -1/0/1 depending on whether self is C{<}, C{=} or C{>} other.
"""
if other is None:
return 1
if self.blankMode != other.blankMode:
if self.blankMode < other.blankMode:
return -1
else:
return 1
if self.blankFactor != other.blankFactor:
if self.blankFactor < other.blankFactor:
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 L{VALID_BLANK_MODES}.
@raise 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 C{None}.
@raise ValueError: If the value is an empty string.
@raise ValueError: If the value is not a valid floating point number
@raise 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
########################################################################
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 C{ActionDependencies} object.
@sort: __init__, __repr__, __str__, __cmp__, name, module, function, index, dependencies
"""
def __init__(self, name=None, module=None, function=None, index=None, dependencies=None):
"""
Constructor for the C{ExtendedAction} class.
@param name: Name of the extended action
@param module: Name of the module containing the extended action function
@param function: Name of the extended action function
@param index: Index of action, used for execution ordering
@param dependencies: Dependencies for action, used for execution ordering
@raise 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 __cmp__(self, other):
"""
Definition of equals operator for this class.
@param other: Other object to compare to.
@return: -1/0/1 depending on whether self is C{<}, C{=} or C{>} other.
"""
if other is None:
return 1
if self.name != other.name:
if self.name < other.name:
return -1
else:
return 1
if self.module != other.module:
if self.module < other.module:
return -1
else:
return 1
if self.function != other.function:
if self.function < other.function:
return -1
else:
return 1
if self.index != other.index:
if self.index < other.index:
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 C{None}.
It must also consist only of lower-case letters and digits.
@raise 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 C{None}.
It must also be a valid Python identifier.
@raise 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 C{None}.
It must also be a valid Python identifier.
@raise 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.
@raise 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 C{None}, the value must be a C{ActionDependecies} object.
@raise ValueError: If the value is not a C{ActionDependencies} object.
"""
if value is None:
self._dependencies = None
else:
if not isinstance(value, ActionDependencies):
raise ValueError("Value must be a C{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
########################################################################
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.
@sort: __init__, __repr__, __str__, __cmp__, command, absolutePath
"""
def __init__(self, command=None, absolutePath=None):
"""
Constructor for the C{CommandOverride} class.
@param command: Name of command to be overridden.
@param absolutePath: Absolute path of the overrridden command.
@raise 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 __cmp__(self, other):
"""
Definition of equals operator for this class.
@param other: Other object to compare to.
@return: -1/0/1 depending on whether self is C{<}, C{=} or C{>} other.
"""
if other is None:
return 1
if self.command != other.command:
if self.command < other.command:
return -1
else:
return 1
if self.absolutePath != other.absolutePath:
if self.absolutePath < other.absolutePath:
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 C{None}.
@raise 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 C{None}.
It does not have to exist on disk at the time of assignment.
@raise ValueError: If the value is not an absolute path.
@raise 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
########################################################################
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 L{VALID_COLLECT_MODES}.
- The archive mode must be one of the values in L{VALID_ARCHIVE_MODES}.
@sort: __init__, __repr__, __str__, __cmp__, absolutePath, collectMode, archiveMode
"""
def __init__(self, absolutePath=None, collectMode=None, archiveMode=None):
"""
Constructor for the C{CollectFile} class.
@param absolutePath: Absolute path of the file to collect.
@param collectMode: Overridden collect mode for this file.
@param archiveMode: Overridden archive mode for this file.
@raise 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 __cmp__(self, other):
"""
Definition of equals operator for this class.
@param other: Other object to compare to.
@return: -1/0/1 depending on whether self is C{<}, C{=} or C{>} other.
"""
if other is None:
return 1
if self.absolutePath != other.absolutePath:
if self.absolutePath < other.absolutePath:
return -1
else:
return 1
if self.collectMode != other.collectMode:
if self.collectMode < other.collectMode:
return -1
else:
return 1
if self.archiveMode != other.archiveMode:
if self.archiveMode < other.archiveMode:
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 C{None}.
It does not have to exist on disk at the time of assignment.
@raise ValueError: If the value is not an absolute path.
@raise 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 C{None}, the mode must be one of the values in L{VALID_COLLECT_MODES}.
@raise 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 C{None}, the mode must be one of the values in L{VALID_ARCHIVE_MODES}.
@raise 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
########################################################################
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 L{VALID_COLLECT_MODES}.
- The archive mode must be one of the values in L{VALID_ARCHIVE_MODES}.
- The ignore file must be a non-empty string.
For the C{absoluteExcludePaths} list, validation is accomplished through the
L{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.
@sort: __init__, __repr__, __str__, __cmp__, absolutePath, collectMode,
archiveMode, ignoreFile, linkDepth, dereference, absoluteExcludePaths,
relativeExcludePaths, excludePatterns
"""
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 C{CollectDir} class.
@param absolutePath: Absolute path of the directory to collect.
@param collectMode: Overridden collect mode for this directory.
@param archiveMode: Overridden archive mode for this directory.
@param ignoreFile: Overidden ignore file name for this directory.
@param linkDepth: Maximum at which soft links should be followed.
@param dereference: Whether to dereference links that are followed.
@param absoluteExcludePaths: List of absolute paths to exclude.
@param relativeExcludePaths: List of relative paths to exclude.
@param excludePatterns: List of regular expression patterns to exclude.
@raise 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 __cmp__(self, other):
"""
Definition of equals operator for this class.
Lists within this class are "unordered" for equality comparisons.
@param other: Other object to compare to.
@return: -1/0/1 depending on whether self is C{<}, C{=} or C{>} other.
"""
if other is None:
return 1
if self.absolutePath != other.absolutePath:
if self.absolutePath < other.absolutePath:
return -1
else:
return 1
if self.collectMode != other.collectMode:
if self.collectMode < other.collectMode:
return -1
else:
return 1
if self.archiveMode != other.archiveMode:
if self.archiveMode < other.archiveMode:
return -1
else:
return 1
if self.ignoreFile != other.ignoreFile:
if self.ignoreFile < other.ignoreFile:
return -1
else:
return 1
if self.linkDepth != other.linkDepth:
if self.linkDepth < other.linkDepth:
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 self.recursionLevel < other.recursionLevel:
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 C{None}.
It does not have to exist on disk at the time of assignment.
@raise ValueError: If the value is not an absolute path.
@raise 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 C{None}, the mode must be one of the values in L{VALID_COLLECT_MODES}.
@raise 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 C{None}, the mode must be one of the values in L{VALID_ARCHIVE_MODES}.
@raise 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 C{None}.
@raise 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.
@raise 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 C{True} or C{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.
@raise 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 C{None} or each element must be an absolute path.
Elements do not have to exist on disk at the time of assignment.
@raise 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, 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, 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, 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
########################################################################
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.
@sort: __init__, __repr__, __str__, __cmp__, absolutePath, retainDays
"""
def __init__(self, absolutePath=None, retainDays=None):
"""
Constructor for the C{PurgeDir} class.
@param absolutePath: Absolute path of the directory to be purged.
@param retainDays: Number of days content within directory should be retained.
@raise 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 __cmp__(self, other):
"""
Definition of equals operator for this class.
@param other: Other object to compare to.
@return: -1/0/1 depending on whether self is C{<}, C{=} or C{>} other.
"""
if other is None:
return 1
if self.absolutePath != other.absolutePath:
if self.absolutePath < other.absolutePath:
return -1
else:
return 1
if self.retainDays != other.retainDays:
if self.retainDays < other.retainDays:
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 C{None}.
It does not have to exist on disk at the time of assignment.
@raise ValueError: If the value is not an absolute path.
@raise 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.
@raise 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
########################################################################
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 L{VALID_FAILURE_MODES}.
@sort: __init__, __repr__, __str__, __cmp__, name, collectDir
"""
def __init__(self, name=None, collectDir=None, ignoreFailureMode=None):
"""
Constructor for the C{LocalPeer} class.
@param name: Name of the peer, typically a valid hostname.
@param collectDir: Collect directory to stage files from on peer.
@param ignoreFailureMode: Ignore failure mode for peer.
@raise 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 __cmp__(self, other):
"""
Definition of equals operator for this class.
@param other: Other object to compare to.
@return: -1/0/1 depending on whether self is C{<}, C{=} or C{>} other.
"""
if other is None:
return 1
if self.name != other.name:
if self.name < other.name:
return -1
else:
return 1
if self.collectDir != other.collectDir:
if self.collectDir < other.collectDir:
return -1
else:
return 1
if self.ignoreFailureMode != other.ignoreFailureMode:
if self.ignoreFailureMode < other.ignoreFailureMode:
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 C{None}.
@raise 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 C{None}.
It does not have to exist on disk at the time of assignment.
@raise ValueError: If the value is not an absolute path.
@raise 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 C{None}, the mode must be one of the values in L{VALID_FAILURE_MODES}.
@raise 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
########################################################################
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 C{ACTION_NAME_REGEX}
- The ignore failure mode must be one of the values in L{VALID_FAILURE_MODES}.
@sort: __init__, __repr__, __str__, __cmp__, name, collectDir, remoteUser, rcpCommand
"""
def __init__(self, name=None, collectDir=None, remoteUser=None,
rcpCommand=None, rshCommand=None, cbackCommand=None,
managed=False, managedActions=None, ignoreFailureMode=None):
"""
Constructor for the C{RemotePeer} class.
@param name: Name of the peer, must be a valid hostname.
@param collectDir: Collect directory to stage files from on peer.
@param remoteUser: Name of backup user on remote peer.
@param rcpCommand: Overridden rcp-compatible copy command for peer.
@param rshCommand: Overridden rsh-compatible remote shell command for peer.
@param cbackCommand: Overridden cback-compatible command to use on remote peer.
@param managed: Indicates whether this is a managed peer.
@param managedActions: Overridden set of actions that are managed on the peer.
@param ignoreFailureMode: Ignore failure mode for peer.
@raise 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 __cmp__(self, other):
"""
Definition of equals operator for this class.
@param other: Other object to compare to.
@return: -1/0/1 depending on whether self is C{<}, C{=} or C{>} other.
"""
if other is None:
return 1
if self.name != other.name:
if self.name < other.name:
return -1
else:
return 1
if self.collectDir != other.collectDir:
if self.collectDir < other.collectDir:
return -1
else:
return 1
if self.remoteUser != other.remoteUser:
if self.remoteUser < other.remoteUser:
return -1
else:
return 1
if self.rcpCommand != other.rcpCommand:
if self.rcpCommand < other.rcpCommand:
return -1
else:
return 1
if self.rshCommand != other.rshCommand:
if self.rshCommand < other.rshCommand:
return -1
else:
return 1
if self.cbackCommand != other.cbackCommand:
if self.cbackCommand < other.cbackCommand:
return -1
else:
return 1
if self.managed != other.managed:
if self.managed < other.managed:
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 self.ignoreFailureMode < other.ignoreFailureMode:
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 C{None}.
@raise 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 C{None}.
It does not have to exist on disk at the time of assignment.
@raise ValueError: If the value is not an absolute path.
@raise 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 C{None}.
@raise 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 C{None}.
@raise 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 C{None}.
@raise 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 C{None}.
@raise 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 C{True} or C{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, 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 C{None}, the mode must be one of the values in L{VALID_FAILURE_MODES}.
@raise 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
########################################################################
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.
@sort: __init__, __repr__, __str__, __cmp__, author, revision, description, generator
"""
def __init__(self, author=None, revision=None, description=None, generator=None):
"""
Constructor for the C{ReferenceConfig} class.
@param author: Author of the configuration file.
@param revision: Revision of the configuration file.
@param description: Description of the configuration file.
@param 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 __cmp__(self, other):
"""
Definition of equals operator for this class.
@param other: Other object to compare to.
@return: -1/0/1 depending on whether self is C{<}, C{=} or C{>} other.
"""
if other is None:
return 1
if self.author != other.author:
if self.author < other.author:
return -1
else:
return 1
if self.revision != other.revision:
if self.revision < other.revision:
return -1
else:
return 1
if self.description != other.description:
if self.description < other.description:
return -1
else:
return 1
if self.generator != other.generator:
if self.generator < other.generator:
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
########################################################################
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 C{VALID_ORDER_MODES}
- The actions list must be a list of C{ExtendedAction} objects.
@sort: __init__, __repr__, __str__, __cmp__, orderMode, actions
"""
def __init__(self, actions=None, orderMode=None):
"""
Constructor for the C{ExtensionsConfig} class.
@param 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 __cmp__(self, other):
"""
Definition of equals operator for this class.
@param other: Other object to compare to.
@return: -1/0/1 depending on whether self is C{<}, C{=} or C{>} other.
"""
if other is None:
return 1
if self.orderMode != other.orderMode:
if self.orderMode < other.orderMode:
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 L{VALID_ORDER_MODES}.
@raise 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 C{None} or each element must be an C{ExtendedAction}.
@raise ValueError: If the value is not a C{ExtendedAction}
"""
if value is None:
self._actions = None
else:
try:
saved = self._actions
self._actions = ObjectTypeList(ExtendedAction, "ExtendedAction")
self._actions.extend(value)
except Exception, 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
########################################################################
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. C{"monday"}, C{"tuesday"}, etc.
- All of the other values must be non-empty strings if they are set to something other than C{None}.
- The overrides list must be a list of C{CommandOverride} objects.
- The hooks list must be a list of C{ActionHook} objects.
- The cback command must be a non-empty string.
- Any managed action name must be a non-empty string matching C{ACTION_NAME_REGEX}
@sort: __init__, __repr__, __str__, __cmp__, startingDay, workingDir,
backupUser, backupGroup, rcpCommand, rshCommand, overrides
"""
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 C{OptionsConfig} class.
@param startingDay: Day that starts the week.
@param workingDir: Working (temporary) directory to use for backups.
@param backupUser: Effective user that backups should run as.
@param backupGroup: Effective group that backups should run as.
@param rcpCommand: Default rcp-compatible copy command for staging.
@param rshCommand: Default rsh-compatible command to use for remote shells.
@param cbackCommand: Default cback-compatible command to use on managed remote peers.
@param overrides: List of configured command path overrides, if any.
@param hooks: List of configured pre- and post-action hooks.
@param managedActions: Default set of actions that are managed on remote peers.
@raise 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 __cmp__(self, other):
"""
Definition of equals operator for this class.
@param other: Other object to compare to.
@return: -1/0/1 depending on whether self is C{<}, C{=} or C{>} other.
"""
if other is None:
return 1
if self.startingDay != other.startingDay:
if self.startingDay < other.startingDay:
return -1
else:
return 1
if self.workingDir != other.workingDir:
if self.workingDir < other.workingDir:
return -1
else:
return 1
if self.backupUser != other.backupUser:
if self.backupUser < other.backupUser:
return -1
else:
return 1
if self.backupGroup != other.backupGroup:
if self.backupGroup < other.backupGroup:
return -1
else:
return 1
if self.rcpCommand != other.rcpCommand:
if self.rcpCommand < other.rcpCommand:
return -1
else:
return 1
if self.rshCommand != other.rshCommand:
if self.rshCommand < other.rshCommand:
return -1
else:
return 1
if self.cbackCommand != other.cbackCommand:
if self.cbackCommand < other.cbackCommand:
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.
@param command: Name of command to be overridden.
@param 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.
@param command: Name of command to be overridden.
@param 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 C{None}, the value must be a valid English day of the week,
one of C{"monday"}, C{"tuesday"}, C{"wednesday"}, etc.
@raise 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 C{None}.
It does not have to exist on disk at the time of assignment.
@raise ValueError: If the value is not an absolute path.
@raise 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 C{None}.
@raise 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 C{None}.
@raise 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 C{None}.
@raise 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 C{None}.
@raise 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 C{None}.
@raise 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 C{None} or each element must be a C{CommandOverride}.
@raise ValueError: If the value is not a C{CommandOverride}
"""
if value is None:
self._overrides = None
else:
try:
saved = self._overrides
self._overrides = ObjectTypeList(CommandOverride, "CommandOverride")
self._overrides.extend(value)
except Exception, 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 C{None} or each element must be an C{ActionHook}.
@raise ValueError: If the value is not a C{CommandOverride}
"""
if value is None:
self._hooks = None
else:
try:
saved = self._hooks
self._hooks = ObjectTypeList(ActionHook, "ActionHook")
self._hooks.extend(value)
except Exception, 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, 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
########################################################################
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 C{LocalPeer} objects
- The list of remote peers must contain only C{RemotePeer} objects
@note: Lists within this class are "unordered" for equality comparisons.
@sort: __init__, __repr__, __str__, __cmp__, localPeers, remotePeers
"""
def __init__(self, localPeers=None, remotePeers=None):
"""
Constructor for the C{PeersConfig} class.
@param localPeers: List of local peers.
@param remotePeers: List of remote peers.
@raise 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 __cmp__(self, other):
"""
Definition of equals operator for this class.
Lists within this class are "unordered" for equality comparisons.
@param other: Other object to compare to.
@return: -1/0/1 depending on whether self is C{<}, C{=} or C{>} 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.
@return: 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 C{None} or each element must be a C{LocalPeer}.
@raise 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, 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 C{None} or each element must be a C{RemotePeer}.
@raise ValueError: If the value is not a C{RemotePeer}
"""
if value is None:
self._remotePeers = None
else:
try:
saved = self._remotePeers
self._remotePeers = ObjectTypeList(RemotePeer, "RemotePeer")
self._remotePeers.extend(value)
except Exception, 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
########################################################################
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 L{VALID_COLLECT_MODES}.
- The archive mode must be one of the values in L{VALID_ARCHIVE_MODES}.
- The ignore file must be a non-empty string.
- Each of the paths in C{absoluteExcludePaths} must be an absolute path
- The collect file list must be a list of C{CollectFile} objects.
- The collect directory list must be a list of C{CollectDir} objects.
For the C{absoluteExcludePaths} list, validation is accomplished through the
L{util.AbsolutePathList} list implementation that overrides common list
methods and transparently does the absolute path validation for us.
For the C{collectFiles} and C{collectDirs} list, validation is accomplished
through the L{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.
@sort: __init__, __repr__, __str__, __cmp__, targetDir,
collectMode, archiveMode, ignoreFile, absoluteExcludePaths,
excludePatterns, collectFiles, collectDirs
"""
def __init__(self, targetDir=None, collectMode=None, archiveMode=None, ignoreFile=None,
absoluteExcludePaths=None, excludePatterns=None, collectFiles=None,
collectDirs=None):
"""
Constructor for the C{CollectConfig} class.
@param targetDir: Directory to collect files into.
@param collectMode: Default collect mode.
@param archiveMode: Default archive mode for collect files.
@param ignoreFile: Default ignore file name.
@param absoluteExcludePaths: List of absolute paths to exclude.
@param excludePatterns: List of regular expression patterns to exclude.
@param collectFiles: List of collect files.
@param collectDirs: List of collect directories.
@raise 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 __cmp__(self, other):
"""
Definition of equals operator for this class.
Lists within this class are "unordered" for equality comparisons.
@param other: Other object to compare to.
@return: -1/0/1 depending on whether self is C{<}, C{=} or C{>} other.
"""
if other is None:
return 1
if self.targetDir != other.targetDir:
if self.targetDir < other.targetDir:
return -1
else:
return 1
if self.collectMode != other.collectMode:
if self.collectMode < other.collectMode:
return -1
else:
return 1
if self.archiveMode != other.archiveMode:
if self.archiveMode < other.archiveMode:
return -1
else:
return 1
if self.ignoreFile != other.ignoreFile:
if self.ignoreFile < other.ignoreFile:
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 C{None}.
It does not have to exist on disk at the time of assignment.
@raise ValueError: If the value is not an absolute path.
@raise 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 C{None}, the mode must be one of L{VALID_COLLECT_MODES}.
@raise 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 C{None}, the mode must be one of L{VALID_ARCHIVE_MODES}.
@raise 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 C{None}.
@raise ValueError: If the value is an empty string.
@raise 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 C{None} or each element must be an absolute path.
Elements do not have to exist on disk at the time of assignment.
@raise 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, 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, 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 C{None} or each element must be a C{CollectFile}.
@raise ValueError: If the value is not a C{CollectFile}
"""
if value is None:
self._collectFiles = None
else:
try:
saved = self._collectFiles
self._collectFiles = ObjectTypeList(CollectFile, "CollectFile")
self._collectFiles.extend(value)
except Exception, 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 C{None} or each element must be a C{CollectDir}.
@raise ValueError: If the value is not a C{CollectDir}
"""
if value is None:
self._collectDirs = None
else:
try:
saved = self._collectDirs
self._collectDirs = ObjectTypeList(CollectDir, "CollectDir")
self._collectDirs.extend(value)
except Exception, 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
########################################################################
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 C{LocalPeer} objects
- The list of remote peers must contain only C{RemotePeer} objects
@note: Lists within this class are "unordered" for equality comparisons.
@sort: __init__, __repr__, __str__, __cmp__, targetDir, localPeers, remotePeers
"""
def __init__(self, targetDir=None, localPeers=None, remotePeers=None):
"""
Constructor for the C{StageConfig} class.
@param targetDir: Directory to stage files into, by peer name.
@param localPeers: List of local peers.
@param remotePeers: List of remote peers.
@raise 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 __cmp__(self, other):
"""
Definition of equals operator for this class.
Lists within this class are "unordered" for equality comparisons.
@param other: Other object to compare to.
@return: -1/0/1 depending on whether self is C{<}, C{=} or C{>} other.
"""
if other is None:
return 1
if self.targetDir != other.targetDir:
if self.targetDir < other.targetDir:
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.
@return: 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 C{None}.
It does not have to exist on disk at the time of assignment.
@raise ValueError: If the value is not an absolute path.
@raise 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 C{None} or each element must be a C{LocalPeer}.
@raise 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, 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 C{None} or each element must be a C{RemotePeer}.
@raise ValueError: If the value is not a C{RemotePeer}
"""
if value is None:
self._remotePeers = None
else:
try:
saved = self._remotePeers
self._remotePeers = ObjectTypeList(RemotePeer, "RemotePeer")
self._remotePeers.extend(value)
except Exception, 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
########################################################################
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 L{VALID_MEDIA_TYPES}.
- The device type must be one of the values in L{VALID_DEVICE_TYPES}.
- The device path must be an absolute path.
- The SCSI id, if provided, must be in the form specified by L{validateScsiId}.
- The drive speed must be an integer >= 1
- The blanking behavior must be a C{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.
@sort: __init__, __repr__, __str__, __cmp__, sourceDir,
mediaType, deviceType, devicePath, deviceScsiId,
driveSpeed, checkData, checkMedia, warnMidnite, noEject,
blankBehavior, refreshMediaDelay, ejectDelay
"""
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 C{StoreConfig} class.
@param sourceDir: Directory whose contents should be written to media.
@param mediaType: Type of the media (see notes above).
@param deviceType: Type of the device (optional, see notes above).
@param devicePath: Filesystem device name for writer device, i.e. C{/dev/cdrw}.
@param deviceScsiId: SCSI id for writer device, i.e. C{[<method>:]scsibus,target,lun}.
@param driveSpeed: Speed of the drive, i.e. C{2} for 2x drive, etc.
@param checkData: Whether resulting image should be validated.
@param checkMedia: Whether media should be checked before being written to.
@param warnMidnite: Whether to generate warnings for crossing midnite.
@param noEject: Indicates that the writer device should not be ejected.
@param blankBehavior: Controls optimized blanking behavior.
@param refreshMediaDelay: Delay, in seconds, to add after refreshing media
@param ejectDelay: Delay, in seconds, to add after ejecting media before closing the tray
@raise 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 __cmp__(self, other):
"""
Definition of equals operator for this class.
@param other: Other object to compare to.
@return: -1/0/1 depending on whether self is C{<}, C{=} or C{>} other.
"""
if other is None:
return 1
if self.sourceDir != other.sourceDir:
if self.sourceDir < other.sourceDir:
return -1
else:
return 1
if self.mediaType != other.mediaType:
if self.mediaType < other.mediaType:
return -1
else:
return 1
if self.deviceType != other.deviceType:
if self.deviceType < other.deviceType:
return -1
else:
return 1
if self.devicePath != other.devicePath:
if self.devicePath < other.devicePath:
return -1
else:
return 1
if self.deviceScsiId != other.deviceScsiId:
if self.deviceScsiId < other.deviceScsiId:
return -1
else:
return 1
if self.driveSpeed != other.driveSpeed:
if self.driveSpeed < other.driveSpeed:
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 self.blankBehavior < other.blankBehavior:
return -1
else:
return 1
if self.refreshMediaDelay != other.refreshMediaDelay:
if self.refreshMediaDelay < other.refreshMediaDelay:
return -1
else:
return 1
if self.ejectDelay != other.ejectDelay:
if self.ejectDelay < other.ejectDelay:
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 C{None}.
It does not have to exist on disk at the time of assignment.
@raise ValueError: If the value is not an absolute path.
@raise 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 L{VALID_MEDIA_TYPES}.
@raise 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 L{VALID_DEVICE_TYPES}.
@raise 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 C{None}.
It does not have to exist on disk at the time of assignment.
@raise ValueError: If the value is not an absolute path.
@raise 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 L{validateScsiId}.
@raise 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 L{validateDriveSpeed}.
@raise 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 C{True} or C{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 C{True} or C{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 C{True} or C{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 C{True} or C{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 C{None}, the value must be a C{BlankBehavior} object.
@raise ValueError: If the value is not a C{BlankBehavior}
"""
if value is None:
self._blankBehavior = None
else:
if not isinstance(value, BlankBehavior):
raise ValueError("Value must be a C{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.
@raise 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.
@raise 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
########################################################################
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 C{PurgeDir} objects.
For the C{purgeDirs} list, validation is accomplished through the
L{util.ObjectTypeList} list implementation that overrides common list
methods and transparently ensures that each element is a C{PurgeDir}.
@note: Lists within this class are "unordered" for equality comparisons.
@sort: __init__, __repr__, __str__, __cmp__, purgeDirs
"""
def __init__(self, purgeDirs=None):
"""
Constructor for the C{Purge} class.
@param purgeDirs: List of purge directories.
@raise 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 __cmp__(self, other):
"""
Definition of equals operator for this class.
Lists within this class are "unordered" for equality comparisons.
@param other: Other object to compare to.
@return: -1/0/1 depending on whether self is C{<}, C{=} or C{>} 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 C{None} or each element must be a C{PurgeDir}.
@raise ValueError: If the value is not a C{PurgeDir}
"""
if value is None:
self._purgeDirs = None
else:
try:
saved = self._purgeDirs
self._purgeDirs = ObjectTypeList(PurgeDir, "PurgeDir")
self._purgeDirs.extend(value)
except Exception, 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
########################################################################
class Config(object):
######################
# Class documentation
######################
"""
Class representing a Cedar Backup XML configuration document.
The C{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
C{Config} object, and then changes to the object can be propogated back to
disk. A C{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
C{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. C{reference} must be a C{ReferenceConfig}. The internal check
uses the built-in C{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 C{None}. When an
object is initialized without using an XML document, all of the values
will be C{None}. Even when an object is initialized using XML, some of
the values might be C{None} because not every section is required.
@note: Lists within this class are "unordered" for equality comparisons.
@sort: __init__, __repr__, __str__, __cmp__, extractXml, validate,
reference, extensions, options, collect, stage, store, purge,
_getReference, _setReference, _getExtensions, _setExtensions,
_getOptions, _setOptions, _getPeers, _setPeers, _getCollect,
_setCollect, _getStage, _setStage, _getStore, _setStore,
_getPurge, _setPurge
"""
##############
# Constructor
##############
def __init__(self, xmlData=None, xmlPath=None, validate=True):
"""
Initializes a configuration object.
If you initialize the object without passing either C{xmlData} or
C{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 C{validate} argument is C{False}, the L{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
C{validate} is C{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 C{validate} option always be set
to C{True} (the default) unless there is a specific need to read in
invalid configuration from disk.
@param xmlData: XML data representing configuration.
@type xmlData: String data.
@param xmlPath: Path to an XML file on disk.
@type xmlPath: Absolute path to a file on disk.
@param validate: Validate the document after parsing it.
@type validate: Boolean true/false.
@raise ValueError: If both C{xmlData} and C{xmlPath} are passed-in.
@raise ValueError: If the XML data in C{xmlData} or C{xmlPath} cannot be parsed.
@raise 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:
xmlData = open(xmlPath).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 __cmp__(self, other):
"""
Definition of equals operator for this class.
Lists within this class are "unordered" for equality comparisons.
@param other: Other object to compare to.
@return: -1/0/1 depending on whether self is C{<}, C{=} or C{>} 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 C{None}, the value must be a C{ReferenceConfig} object.
@raise ValueError: If the value is not a C{ReferenceConfig}
"""
if value is None:
self._reference = None
else:
if not isinstance(value, ReferenceConfig):
raise ValueError("Value must be a C{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 C{None}, the value must be a C{ExtensionsConfig} object.
@raise ValueError: If the value is not a C{ExtensionsConfig}
"""
if value is None:
self._extensions = None
else:
if not isinstance(value, ExtensionsConfig):
raise ValueError("Value must be a C{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 C{None}, the value must be an C{OptionsConfig} object.
@raise ValueError: If the value is not a C{OptionsConfig}
"""
if value is None:
self._options = None
else:
if not isinstance(value, OptionsConfig):
raise ValueError("Value must be a C{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 C{None}, the value must be an C{PeersConfig} object.
@raise ValueError: If the value is not a C{PeersConfig}
"""
if value is None:
self._peers = None
else:
if not isinstance(value, PeersConfig):
raise ValueError("Value must be a C{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 C{None}, the value must be a C{CollectConfig} object.
@raise ValueError: If the value is not a C{CollectConfig}
"""
if value is None:
self._collect = None
else:
if not isinstance(value, CollectConfig):
raise ValueError("Value must be a C{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 C{None}, the value must be a C{StageConfig} object.
@raise ValueError: If the value is not a C{StageConfig}
"""
if value is None:
self._stage = None
else:
if not isinstance(value, StageConfig):
raise ValueError("Value must be a C{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 C{None}, the value must be a C{StoreConfig} object.
@raise ValueError: If the value is not a C{StoreConfig}
"""
if value is None:
self._store = None
else:
if not isinstance(value, StoreConfig):
raise ValueError("Value must be a C{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 C{None}, the value must be a C{PurgeConfig} object.
@raise ValueError: If the value is not a C{PurgeConfig}
"""
if value is None:
self._purge = None
else:
if not isinstance(value, PurgeConfig):
raise ValueError("Value must be a C{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 C{ReferenceConfig} object.")
extensions = property(_getExtensions, _setExtensions, None, "Extensions configuration in terms of a C{ExtensionsConfig} object.")
options = property(_getOptions, _setOptions, None, "Options configuration in terms of a C{OptionsConfig} object.")
peers = property(_getPeers, _setPeers, None, "Peers configuration in terms of a C{PeersConfig} object.")
collect = property(_getCollect, _setCollect, None, "Collect configuration in terms of a C{CollectConfig} object.")
stage = property(_getStage, _setStage, None, "Stage configuration in terms of a C{StageConfig} object.")
store = property(_getStore, _setStore, None, "Store configuration in terms of a C{StoreConfig} object.")
purge = property(_getPurge, _setPurge, None, "Purge configuration in terms of a C{PurgeConfig} object.")
#################
# Public methods
#################
def extractXml(self, xmlPath=None, validate=True):
"""
Extracts configuration into an XML document.
If C{xmlPath} is not provided, then the XML document will be returned as
a string. If C{xmlPath} is provided, then the XML document will be written
to the file and C{None} will be returned.
Unless the C{validate} parameter is C{False}, the L{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 C{validate} option always be set
to C{True} (the default) unless there is a specific need to write an
invalid configuration file to disk.
@param xmlPath: Path to an XML file to create on disk.
@type xmlPath: Absolute path to a file.
@param validate: Validate the document before extracting it.
@type validate: Boolean true/false.
@return: XML string data or C{None} as described above.
@raise ValueError: If configuration within the object is not valid.
@raise IOError: If there is an error writing to the file.
@raise OSError: If there is an error writing to the file.
"""
if validate:
self.validate()
xmlData = self._extractXml()
if xmlPath is not None:
open(xmlPath, "w").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 I{Validation} section in the class notes (above).
@param requireOneAction: Require at least one of the collect, stage, store or purge sections.
@param requireReference: Require the reference section.
@param requireExtensions: Require the extensions section.
@param requireOptions: Require the options section.
@param requirePeers: Require the peers section.
@param requireCollect: Require the collect section.
@param requireStage: Require the stage section.
@param requireStore: Require the store section.
@param requirePurge: Require the purge section.
@raise 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 (C{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
L{validate} method).
@param xmlData: XML data to be parsed
@type xmlData: String data
@raise 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
@param parentNode: Parent node to search beneath.
@return: C{ReferenceConfig} object or C{None} if the section does not exist.
@raise 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 L{_parseExtendedActions}.
@param parentNode: Parent node to search beneath.
@return: C{ExtensionsConfig} object or C{None} if the section does not exist.
@raise 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 L{_parseOverrides} and the hooks are parsed
by L{_parseHooks}.
@param parentNode: Parent node to search beneath.
@return: C{OptionsConfig} object or C{None} if the section does not exist.
@raise 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 L{_parsePeerList}.
@param parentNode: Parent node to search beneath.
@return: C{StageConfig} object or C{None} if the section does not exist.
@raise 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 L{_parseExclusions}, the collect files are
parsed by L{_parseCollectFiles}, and the directories are parsed by
L{_parseCollectDirs}.
@param parentNode: Parent node to search beneath.
@return: C{CollectConfig} object or C{None} if the section does not exist.
@raise 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 L{_parsePeerList}.
@param parentNode: Parent node to search beneath.
@return: C{StageConfig} object or C{None} if the section does not exist.
@raise 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 C{_parseBlankBehavior}
method.
@param parentNode: Parent node to search beneath.
@return: C{StoreConfig} object or C{None} if the section does not exist.
@raise 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 L{_parsePurgeDirs}.
@param parentNode: Parent node to search beneath.
@return: C{PurgeConfig} object or C{None} if the section does not exist.
@raise 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 C{_parseDependencies} method.
@param parentNode: Parent node to search beneath.
@return: List of extended actions.
@raise 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
C{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.
@param parentNode: Parent node to search beneath.
@return: 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 C{CommandOverride} objects from immediately beneath the parent.
We read the following individual fields::
command command
absolutePath abs_path
@param parentNode: Parent node to search beneath.
@return: List of C{CommandOverride} objects or C{None} if none are found.
@raise 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 C{ActionHook} objects from immediately beneath the parent.
We read the following individual fields::
action action
command command
@param parentNode: Parent node to search beneath.
@return: List of C{ActionHook} objects or C{None} if none are found.
@raise 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 C{CollectFile} objects from immediately beneath the parent.
We read the following individual fields::
absolutePath abs_path
collectMode mode I{or} collect_mode
archiveMode archive_mode
The collect mode is a special case. Just a C{mode} tag is accepted, but
we prefer C{collect_mode} for consistency with the rest of the config
file and to avoid confusion with the archive mode. If both are provided,
only C{mode} will be used.
@param parentNode: Parent node to search beneath.
@return: List of C{CollectFile} objects or C{None} if none are found.
@raise 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 C{CollectDir} objects from immediately beneath the parent.
We read the following individual fields::
absolutePath abs_path
collectMode mode I{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 C{mode} tag is accepted for
backwards compatibility, but we prefer C{collect_mode} for consistency
with the rest of the config file and to avoid confusion with the archive
mode. If both are provided, only C{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 L{_parseExclusions}.
@param parentNode: Parent node to search beneath.
@return: List of C{CollectDir} objects or C{None} if none are found.
@raise 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 C{PurgeDir} objects from immediately beneath the parent.
We read the following individual fields::
absolutePath <baseExpr>/abs_path
retainDays <baseExpr>/retain_days
@param parentNode: Parent node to search beneath.
@return: List of C{PurgeDir} objects or C{None} if none are found.
@raise 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 C{type} field is used to determine whether
this entry is a remote peer. If the type is C{"remote"}, it's a remote
peer, and if the type is C{"local"}, it's a remote peer.
If there are none of one type of peer (i.e. no local peers) then C{None}
will be returned for that item in the tuple.
@param parentNode: Parent node to search beneath.
@return: Tuple of (local, remote) peer lists.
@raise 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 C{ActionDependencies} object.
If the dependencies parent node does not exist, C{None} will be returned.
Otherwise, an C{ActionDependencies} object will always be created, even
if it does not contain any actual dependencies in it.
@param parentNode: Parent node to search beneath.
@return: C{ActionDependencies} object or C{None}.
@raise 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 C{BlankBehavior} object from immediately beneath the parent.
We read the following individual fields::
blankMode blank_behavior/mode
blankFactor blank_behavior/factor
@param parentNode: Parent node to search beneath.
@return: C{BlankBehavior} object or C{None} if none if the section is not found
@raise 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 L{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 C{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 C{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 C{referenceConfig} is C{None}, then no container will be added.
@param xmlDom: DOM tree as from L{createOutputDom}.
@param parentNode: Parent that the section should be appended to.
@param 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 L{_addExtendedAction}.
If C{extensionsConfig} is C{None}, then no container will be added.
@param xmlDom: DOM tree as from L{createOutputDom}.
@param parentNode: Parent that the section should be appended to.
@param 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 L{_addOverride}. The
individual hook items are added by L{_addHook}.
If C{optionsConfig} is C{None}, then no container will be added.
@param xmlDom: DOM tree as from L{createOutputDom}.
@param parentNode: Parent that the section should be appended to.
@param 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
L{_addLocalPeer} and L{_addRemotePeer}, respectively.
If C{peersConfig} is C{None}, then no container will be added.
@param xmlDom: DOM tree as from L{createOutputDom}.
@param parentNode: Parent that the section should be appended to.
@param 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 L{_addCollectFile} and
individual collect directories are added by L{_addCollectDir}.
If C{collectConfig} is C{None}, then no container will be added.
@param xmlDom: DOM tree as from L{createOutputDom}.
@param parentNode: Parent that the section should be appended to.
@param 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
L{_addLocalPeer} and L{_addRemotePeer}, respectively.
If C{stageConfig} is C{None}, then no container will be added.
@param xmlDom: DOM tree as from L{createOutputDom}.
@param parentNode: Parent that the section should be appended to.
@param 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 L{_addBlankBehavior}
method.
If C{storeConfig} is C{None}, then no container will be added.
@param xmlDom: DOM tree as from L{createOutputDom}.
@param parentNode: Parent that the section should be appended to.
@param 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 L{_addPurgeDir}.
If C{purgeConfig} is C{None}, then no container will be added.
@param xmlDom: DOM tree as from L{createOutputDom}.
@param parentNode: Parent that the section should be appended to.
@param 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 L{_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 C{ExtensionsConfig} object.
If C{action} is C{None}, this method call will be a no-op.
@param xmlDom: DOM tree as from L{createOutputDom}.
@param parentNode: Parent that the section should be appended to.
@param 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 C{OptionsConfig} object.
If C{override} is C{None}, this method call will be a no-op.
@param xmlDom: DOM tree as from L{createOutputDom}.
@param parentNode: Parent that the section should be appended to.
@param 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 C{before} and C{after}
flags on the hook. If the C{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 C{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 C{OptionsConfig} object.
If C{hook} is C{None}, this method call will be a no-op.
@param xmlDom: DOM tree as from L{createOutputDom}.
@param parentNode: Parent that the section should be appended to.
@param 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 C{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 C{CollectConfig} object.
If C{collectFile} is C{None}, this method call will be a no-op.
@param xmlDom: DOM tree as from L{createOutputDom}.
@param parentNode: Parent that the section should be appended to.
@param 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 C{mode} tag, since we accept both C{collect_mode} and C{mode}.
However, here we'll only emit the preferred C{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 C{CollectConfig} object.
If C{collectDir} is C{None}, this method call will be a no-op.
@param xmlDom: DOM tree as from L{createOutputDom}.
@param parentNode: Parent that the section should be appended to.
@param 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, C{peer/type} is filled in with C{"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 C{StageConfig} object.
If C{localPeer} is C{None}, this method call will be a no-op.
@param xmlDom: DOM tree as from L{createOutputDom}.
@param parentNode: Parent that the section should be appended to.
@param 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, C{peer/type} is filled in with C{"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 C{StageConfig} object.
If C{remotePeer} is C{None}, this method call will be a no-op.
@param xmlDom: DOM tree as from L{createOutputDom}.
@param parentNode: Parent that the section should be appended to.
@param 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 C{PurgeConfig} object.
If C{purgeDir} is C{None}, this method call will be a no-op.
@param xmlDom: DOM tree as from L{createOutputDom}.
@param parentNode: Parent that the section should be appended to.
@param 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 C{dependencies} is C{None}, this method call will be a no-op.
@param xmlDom: DOM tree as from L{createOutputDom}.
@param parentNode: Parent that the section should be appended to.
@param dependencies: C{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 C{valueList} is C{None}, then C{None} will be
returned.
@param valueList: List of values to be placed into a string
@return: 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 C{blankBehavior} is C{None}, this method call will be a no-op.
@param xmlDom: DOM tree as from L{createOutputDom}.
@param parentNode: Parent that the section should be appended to.
@param 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 C{None} is
validated per the rules for that section, laid out in the module
documentation (above).
@raise 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.
@raise ValueError: If reference configuration is invalid.
"""
pass
def _validateExtensions(self):
"""
Validates extensions configuration.
The list of actions may be either C{None} or an empty list C{[]} 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.
@raise 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.
@raise 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 L{_validatePeerList}.
@raise 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 C{None} or an
empty list C{[]} 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 C{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 C{None}
or an empty list C{[]} if desired. Any list of absolute paths to exclude
or patterns to exclude will be combined with the same list in the
C{CollectConfig} object to make the complete list for a given directory.
@raise 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 L{_validatePeerList}.
@raise 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 C{writer} module is supposed to be
able to handle a device speed of C{None}.
Any caller which needs a "real" (non-C{None}) value for the device type
can use C{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.
@raise 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 == 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 C{None} or an empty list
C{[]} if desired. All purge directories must contain a path and a retain
days value.
@raise 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.
@param localPeers: List of local peers
@param remotePeers: List of remote peers
@raise 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.
@param parent: Parent node to search beneath.
@param name: Name of node to search for.
@return: 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 C{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").
@param xmlDom: DOM tree as from C{impl.createDocument()}.
@param parentNode: Parent node to create child for.
@param nodeName: Name of the new container node.
@param byteQuantity: ByteQuantity object to put into the XML document
@return: 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)
|