/usr/lib/python3/dist-packages/raphodo/rapid.py is in rapid-photo-downloader 0.9.9-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 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 | #!/usr/bin/env python3
# Copyright (C) 2011-2018 Damon Lynch <damonlynch@gmail.com>
# This file is part of Rapid Photo Downloader.
#
# Rapid Photo Downloader is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Rapid Photo Downloader 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. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Rapid Photo Downloader. If not,
# see <http://www.gnu.org/licenses/>.
"""
Primary logic for Rapid Photo Downloader.
Qt related class method and variable names use CamelCase.
Everything else should follow PEP 8.
Project line length: 100 characters (i.e. word wrap at 99)
"Hamburger" Menu Icon by Daniel Bruce -- www.entypo.com
"""
__author__ = 'Damon Lynch'
__copyright__ = "Copyright 2011-2018, Damon Lynch"
import sys
import logging
import shutil
import datetime
import locale
# Use the default locale as defined by the LANG variable
locale.setlocale(locale.LC_ALL, '')
import pickle
from collections import namedtuple, defaultdict
import platform
import argparse
from typing import Optional, Tuple, List, Sequence, Dict, Set, Any, DefaultDict
import faulthandler
import pkg_resources
import webbrowser
import time
import shlex
import subprocess
from urllib.request import pathname2url
import tarfile
import inspect
from gettext import gettext as _
import gi
gi.require_version('Notify', '0.7')
from gi.repository import Notify
try:
gi.require_version('Unity', '7.0')
from gi.repository import Unity
have_unity = True
except (ImportError, ValueError):
have_unity = False
import zmq
import psutil
import gphoto2 as gp
import sip
from PyQt5 import QtCore
from PyQt5.QtCore import (
QThread, Qt, QStorageInfo, QSettings, QPoint, QSize, QTimer, QTextStream, QModelIndex,
pyqtSlot, QRect, pyqtSignal, QObject
)
from PyQt5.QtGui import (
QIcon, QPixmap, QImage, QColor, QPalette, QFontMetrics, QFont, QPainter, QMoveEvent, QBrush,
QPen, QColor
)
from PyQt5.QtWidgets import (
QAction, QApplication, QMainWindow, QMenu, QWidget, QDialogButtonBox,
QProgressBar, QSplitter, QHBoxLayout, QVBoxLayout, QDialog, QLabel, QComboBox, QGridLayout,
QCheckBox, QSizePolicy, QMessageBox, QSplashScreen, QStackedWidget, QScrollArea,
QDesktopWidget, QStyledItemDelegate, QPushButton
)
from PyQt5.QtNetwork import QLocalSocket, QLocalServer
from raphodo.storage import (
ValidMounts, CameraHotplug, UDisks2Monitor, GVolumeMonitor, have_gio,
has_one_or_more_folders, mountPaths, get_desktop_environment, get_desktop,
gvfs_controls_mounts, get_default_file_manager, validate_download_folder,
validate_source_folder, get_fdo_cache_thumb_base_directory, WatchDownloadDirs, get_media_dir,
StorageSpace, gvfs_gphoto2_path
)
from raphodo.interprocess import (
ScanArguments, CopyFilesArguments, RenameAndMoveFileData, BackupArguments,
BackupFileData, OffloadData, ProcessLoggingManager, ThumbnailDaemonData, ThreadNames,
OffloadManager, CopyFilesManager, ThumbnailDaemonManager,
ScanManager, BackupManager, stop_process_logging_manager, RenameMoveFileManager,
create_inproc_msg)
from raphodo.devices import (
Device, DeviceCollection, BackupDevice, BackupDeviceCollection, FSMetadataErrors
)
from raphodo.preferences import Preferences
from raphodo.constants import (
BackupLocationType, DeviceType, ErrorType, FileType, DownloadStatus, RenameAndMoveStatus,
ApplicationState, CameraErrorCode, TemporalProximityState, ThumbnailBackgroundName,
Desktop, BackupFailureType, DeviceState, Sort, Show, DestinationDisplayType,
DisplayingFilesOfType, DownloadingFileTypes, RememberThisMessage, RightSideButton,
CheckNewVersionDialogState, CheckNewVersionDialogResult, RememberThisButtons,
BackupStatus, CompletedDownloads, disable_version_check
)
from raphodo.thumbnaildisplay import (
ThumbnailView, ThumbnailListModel, ThumbnailDelegate, DownloadStats, MarkedSummary
)
from raphodo.devicedisplay import (DeviceModel, DeviceView, DeviceDelegate)
from raphodo.proximity import (TemporalProximityGroups, TemporalProximity)
from raphodo.utilities import (
same_device, make_internationalized_list, thousands, addPushButtonLabelSpacer,
make_html_path_non_breaking, prefs_list_from_gconftool2_string,
pref_bool_from_gconftool2_string, extract_file_from_tar, format_size_for_user
)
from raphodo.rememberthisdialog import RememberThisDialog
import raphodo.utilities
from raphodo.rpdfile import (
RPDFile, file_types_by_number, PHOTO_EXTENSIONS, VIDEO_EXTENSIONS, OTHER_PHOTO_EXTENSIONS,
FileTypeCounter, Video
)
import raphodo.downloadtracker as downloadtracker
from raphodo.cache import ThumbnailCacheSql
from raphodo.metadataphoto import exiv2_version, gexiv2_version
from raphodo.metadatavideo import EXIFTOOL_VERSION, pymedia_version_info, libmediainfo_missing
from raphodo.camera import gphoto2_version, python_gphoto2_version, dump_camera_details
from raphodo.rpdsql import DownloadedSQL
from raphodo.generatenameconfig import *
from raphodo.rotatedpushbutton import RotatedButton, FlatButton
from raphodo.primarybutton import TopPushButton, DownloadButton
from raphodo.filebrowse import (
FileSystemView, FileSystemModel, FileSystemFilter, FileSystemDelegate
)
from raphodo.toggleview import QToggleView
import raphodo.__about__ as __about__
import raphodo.iplogging as iplogging
import raphodo.excepthook
from raphodo.panelview import QPanelView
from raphodo.computerview import ComputerWidget
from raphodo.folderspreview import DownloadDestination, FoldersPreview
from raphodo.destinationdisplay import DestinationDisplay
from raphodo.aboutdialog import AboutDialog
import raphodo.constants as constants
from raphodo.menubutton import MenuButton
from raphodo.renamepanel import RenamePanel
from raphodo.jobcodepanel import JobCodePanel
from raphodo.backuppanel import BackupPanel
import raphodo
import raphodo.exiftool as exiftool
from raphodo.newversion import (
NewVersion, NewVersionCheckDialog, version_details, DownloadNewVersionDialog
)
from raphodo.chevroncombo import ChevronCombo
from raphodo.preferencedialog import PreferencesDialog
from raphodo.errorlog import ErrorReport, SpeechBubble
from raphodo.problemnotification import (
FsMetadataWriteProblem, Problem, Problems, CopyingProblems, RenamingProblems, BackingUpProblems
)
from raphodo.viewutils import standardIconSize
import raphodo.didyouknow as didyouknow
from raphodo.thumbnailextractor import gst_version, libraw_version, rawkit_version
# Avoid segfaults at exit:
# http://pyqt.sourceforge.net/Docs/PyQt5/gotchas.html#crashes-on-exit
app = None # type: 'QtSingleApplication'
faulthandler.enable()
logger = None
sys.excepthook = raphodo.excepthook.excepthook
class FolderPreviewManager(QObject):
"""
Manages sending FoldersPreview() off to the offload process to
generate new provisional download subfolders, and removing provisional download subfolders
in the main process, using QFileSystemModel.
Queues operations if they need to be, or runs them immediately when it can.
Sadly we must delete provisional download folders only in the main process, using
QFileSystemModel. Otherwise the QFileSystemModel is liable to issue a large number of
messages like this:
QInotifyFileSystemWatcherEngine::addPaths: inotify_add_watch failed: No such file or directory
Yet we must generate and create folders in the offload process, because that
can be expensive for a large number of rpd_files.
New for PyQt 5.7: Inherits from QObject to allow for Qt signals and slots using PyQt slot
decorator.
"""
def __init__(self, fsmodel: FileSystemModel,
prefs: Preferences,
photoDestinationFSView: FileSystemView,
videoDestinationFSView: FileSystemView,
devices: DeviceCollection,
rapidApp: 'RapidWindow') -> None:
"""
:param fsmodel: FileSystemModel powering the destination and this computer views
:param prefs: program preferences
:param photoDestinationFSView: photo destination view
:param videoDestinationFSView: video destination view
:param devices: the device collection
:param rapidApp: main application window
"""
super().__init__()
self.rpd_files_queue = [] # type: List[RPDFile]
self.clean_for_scan_id_queue = [] # type: List[int]
self.change_destination_queued = False # type: bool
self.subfolder_rebuild_queued = False # type: bool
self.offloaded = False
self.process_destination = False
self.fsmodel = fsmodel
self.prefs = prefs
self.devices = devices
self.rapidApp = rapidApp
self.photoDestinationFSView = photoDestinationFSView
self.videoDestinationFSView = videoDestinationFSView
self.folders_preview = FoldersPreview()
# Set the initial download destination values, using the values
# in the program prefs:
self._change_destination()
def add_rpd_files(self, rpd_files: List[RPDFile]) -> None:
"""
Generate new provisional download folders for the rpd_files, either
by sending them off for generation to the offload process, or if some
are already being generated, queueing the operation
:param rpd_files: the list of rpd files
"""
if self.offloaded:
self.rpd_files_queue.extend(rpd_files)
else:
if self.rpd_files_queue:
rpd_files = rpd_files + self.rpd_files_queue
self.rpd_files_queue = [] # type: List[RPDFile]
self._generate_folders(rpd_files=rpd_files)
def _generate_folders(self, rpd_files: List[RPDFile]) -> None:
if not self.devices.scanning or self.rapidApp.downloadIsRunning():
logging.info("Generating provisional download folders for %s files", len(rpd_files))
data = OffloadData(
rpd_files=rpd_files, strip_characters=self.prefs.strip_characters,
folders_preview=self.folders_preview
)
self.offloaded = True
self.rapidApp.sendToOffload(data=data)
def change_destination(self) -> None:
if self.offloaded:
self.change_destination_queued = True
else:
self._change_destination()
self._update_model_and_views()
def change_subfolder_structure(self) -> None:
self.change_destination()
if self.offloaded:
assert self.change_destination_queued == True
self.subfolder_rebuild_queued = True
else:
self._change_subfolder_structure()
def _change_destination(self) -> None:
destination = DownloadDestination(
photo_download_folder=self.prefs.photo_download_folder,
video_download_folder=self.prefs.video_download_folder,
photo_subfolder=self.prefs.photo_subfolder,
video_subfolder=self.prefs.video_subfolder
)
self.folders_preview.process_destination(
destination=destination, fsmodel=self.fsmodel
)
def _change_subfolder_structure(self) -> None:
rpd_files = self.rapidApp.thumbnailModel.getAllDownloadableRPDFiles()
if rpd_files:
self.add_rpd_files(rpd_files=rpd_files)
@pyqtSlot(FoldersPreview)
def folders_generated(self, folders_preview: FoldersPreview) -> None:
"""
Receive the folders_preview from the offload process, and
handle any tasks that may have been queued in the time it was
being processed in the offload process
:param folders_preview: the folders_preview as worked on by the
offload process
"""
logging.debug("Provisional download folders received")
self.offloaded = False
self.folders_preview = folders_preview
dirty = self.folders_preview.dirty
self.folders_preview.dirty = False
if dirty:
logging.debug("Provisional download folders change detected")
if not self.rapidApp.downloadIsRunning():
for scan_id in self.clean_for_scan_id_queue:
dirty = True
self._remove_provisional_folders_for_device(scan_id=scan_id)
self.clean_for_scan_id_queue = [] # type: List[int]
if self.change_destination_queued:
self.change_destination_queued = False
dirty = True
logging.debug("Changing destination of provisional download folders")
self._change_destination()
if self.subfolder_rebuild_queued:
self.subfolder_rebuild_queued = False
logging.debug("Rebuilding provisional download folders")
self._change_subfolder_structure()
else:
logging.debug(
"Not removing or moving provisional download folders becausea download is running"
)
if dirty:
self._update_model_and_views()
if self.rpd_files_queue:
logging.debug("Assigning queued provisional download folders to be generated")
self._generate_folders(rpd_files=self.rpd_files_queue)
self.rpd_files_queue = [] # type: List[RPDFile]
# self.folders_preview.dump()
def _update_model_and_views(self):
logging.debug("Updating file system model and views")
self.fsmodel.preview_subfolders = self.folders_preview.preview_subfolders()
self.fsmodel.download_subfolders = self.folders_preview.download_subfolders()
# Update the view
self.photoDestinationFSView.reset()
self.videoDestinationFSView.reset()
# Ensure the file system model caches are refreshed:
self.fsmodel.setRootPath(self.folders_preview.photo_download_folder)
self.fsmodel.setRootPath(self.folders_preview.video_download_folder)
self.fsmodel.setRootPath('/')
self.photoDestinationFSView.expandPreviewFolders(self.prefs.photo_download_folder)
self.videoDestinationFSView.expandPreviewFolders(self.prefs.video_download_folder)
# self.photoDestinationFSView.update()
# self.videoDestinationFSView.update()
def remove_folders_for_device(self, scan_id: int) -> None:
"""
Remove provisional download folders unique to this scan_id
using the offload process.
:param scan_id: scan id of the device
"""
if self.offloaded:
self.clean_for_scan_id_queue.append(scan_id)
else:
self._remove_provisional_folders_for_device(scan_id=scan_id)
self._update_model_and_views()
def queue_folder_removal_for_device(self, scan_id: int) -> None:
"""
Queues provisional download files for removal after
all files have been downloaded for a device.
:param scan_id: scan id of the device
"""
self.clean_for_scan_id_queue.append(scan_id)
def remove_folders_for_queued_devices(self) -> None:
"""
Once all files have been downloaded (i.e. no more remain
to be downloaded) and there was a disparity between
modification times and creation times that was discovered during
the download, clean any provisional download folders now that the
download has finished.
"""
for scan_id in self.clean_for_scan_id_queue:
self._remove_provisional_folders_for_device(scan_id=scan_id)
self.clean_for_scan_id_queue = [] # type: List[int]
self._update_model_and_views()
def _remove_provisional_folders_for_device(self, scan_id: int) -> None:
if scan_id in self.devices:
logging.info("Cleaning provisional download folders for %s",
self.devices[scan_id].display_name)
else:
logging.info("Cleaning provisional download folders for device %d", scan_id)
self.folders_preview.clean_generated_folders_for_scan_id(
scan_id=scan_id, fsmodel=self.fsmodel
)
def remove_preview_folders(self) -> None:
"""
Called when application is exiting.
"""
self.folders_preview.clean_all_generated_folders(fsmodel=self.fsmodel)
class RapidWindow(QMainWindow):
"""
Main application window, and primary controller of program logic
Such attributes unfortunately make it very complex.
For better or worse, Qt's state machine technology is not used.
State indicating whether a download or scan is occurring is
thus kept in the device collection, self.devices
"""
checkForNewVersionRequest = pyqtSignal()
downloadNewVersionRequest = pyqtSignal(str, str)
reverifyDownloadedTar = pyqtSignal(str)
udisks2Unmount = pyqtSignal(str)
def __init__(self, splash: 'SplashScreen',
photo_rename: Optional[bool]=None,
video_rename: Optional[bool]=None,
auto_detect: Optional[bool]=None,
this_computer_source: Optional[str]=None,
this_computer_location: Optional[str]=None,
photo_download_folder: Optional[str]=None,
video_download_folder: Optional[str]=None,
backup: Optional[bool]=None,
backup_auto_detect: Optional[bool]=None,
photo_backup_identifier: Optional[str]=None,
video_backup_identifier: Optional[str]=None,
photo_backup_location: Optional[str]=None,
video_backup_location: Optional[str]=None,
ignore_other_photo_types: Optional[bool]=None,
thumb_cache: Optional[bool]=None,
auto_download_startup: Optional[bool]=None,
auto_download_insertion: Optional[bool]=None,
log_gphoto2: Optional[bool]=None) -> None:
super().__init__()
self.splash = splash
# Process Qt events - in this case, possible closing of splash screen
app.processEvents()
# Three values to handle window position quirks under X11:
self.window_show_requested_time = None # type: datetime.datetime
self.window_move_triggered_count = 0
self.windowPositionDelta = QPoint(0, 0)
self.setFocusPolicy(Qt.StrongFocus)
self.ignore_other_photo_types = ignore_other_photo_types
self.application_state = ApplicationState.normal
self.prompting_for_user_action = {} # type: Dict[Device, QMessageBox]
self.close_event_run = False
for version in get_versions():
logging.info('%s', version)
if EXIFTOOL_VERSION is None:
logging.error("ExifTool is either missing or has a problem")
if pymedia_version_info() is None:
if libmediainfo_missing:
logging.error(
"pymediainfo is installed, but the library libmediainfo appears to be missing"
)
self.log_gphoto2 = log_gphoto2 == True
self.setWindowTitle(_("Rapid Photo Downloader"))
# app is a module level global
self.readWindowSettings(app)
self.prefs = Preferences()
self.checkPrefsUpgrade()
self.prefs.program_version = __about__.__version__
# track devices on which there was an error setting a file's filesystem metadata
self.copy_metadata_errors = FSMetadataErrors()
self.backup_metadata_errors = FSMetadataErrors()
if thumb_cache is not None:
logging.debug("Use thumbnail cache: %s", thumb_cache)
self.prefs.use_thumbnail_cache = thumb_cache
self.setupWindow()
splash.setProgress(10)
if photo_rename is not None:
if photo_rename:
self.prefs.photo_rename = PHOTO_RENAME_SIMPLE
else:
self.prefs.photo_rename = self.prefs.rename_defaults['photo_rename']
if video_rename is not None:
if video_rename:
self.prefs.video_rename = VIDEO_RENAME_SIMPLE
else:
self.prefs.video_rename = self.prefs.rename_defaults['video_rename']
if auto_detect is not None:
self.prefs.device_autodetection = auto_detect
else:
logging.info("Device autodetection: %s", self.prefs.device_autodetection)
if self.prefs.device_autodetection:
if not self.prefs.scan_specific_folders:
logging.info("Devices do not need specific folders to be scanned")
else:
logging.info(
"For automatically detected devices, only the contents the following "
"folders will be scanned: %s", ', '.join(self.prefs.folders_to_scan)
)
if this_computer_source is not None:
self.prefs.this_computer_source = this_computer_source
if this_computer_location is not None:
self.prefs.this_computer_path = this_computer_location
if self.prefs.this_computer_source:
if self.prefs.this_computer_path:
logging.info(
"This Computer is set to be used as a download source, using: %s",
self.prefs.this_computer_path
)
else:
logging.info(
"This Computer is set to be used as a download source, but the location is "
"not yet set"
)
else:
logging.info("This Computer is not used as a download source")
if photo_download_folder is not None:
self.prefs.photo_download_folder = photo_download_folder
logging.info("Photo download location: %s", self.prefs.photo_download_folder)
if video_download_folder is not None:
self.prefs.video_download_folder = video_download_folder
logging.info("Video download location: %s", self.prefs.video_download_folder)
if backup is not None:
self.prefs.backup_files = backup
else:
logging.info("Backing up files: %s", self.prefs.backup_files)
if backup_auto_detect is not None:
self.prefs.backup_device_autodetection = backup_auto_detect
elif self.prefs.backup_files:
logging.info("Backup device auto detection: %s", self.prefs.backup_device_autodetection)
if photo_backup_identifier is not None:
self.prefs.photo_backup_identifier = photo_backup_identifier
elif self.prefs.backup_files and self.prefs.backup_device_autodetection:
logging.info("Photo backup identifier: %s", self.prefs.photo_backup_identifier)
if video_backup_identifier is not None:
self.prefs.video_backup_identifier = video_backup_identifier
elif self.prefs.backup_files and self.prefs.backup_device_autodetection:
logging.info("video backup identifier: %s", self.prefs.video_backup_identifier)
if photo_backup_location is not None:
self.prefs.backup_photo_location = photo_backup_location
elif self.prefs.backup_files and not self.prefs.backup_device_autodetection:
logging.info("Photo backup location: %s", self.prefs.backup_photo_location)
if video_backup_location is not None:
self.prefs.backup_video_location = video_backup_location
elif self.prefs.backup_files and not self.prefs.backup_device_autodetection:
logging.info("video backup location: %s", self.prefs.backup_video_location)
if auto_download_startup is not None:
self.prefs.auto_download_at_startup = auto_download_startup
elif self.prefs.auto_download_at_startup:
logging.info("Auto download at startup is on")
if auto_download_insertion is not None:
self.prefs.auto_download_upon_device_insertion = auto_download_insertion
elif self.prefs.auto_download_upon_device_insertion:
logging.info("Auto download upon device insertion is on")
if self.prefs.list_not_empty('volume_whitelist'):
logging.info("Whitelisted devices: %s", " ; ".join(self.prefs.volume_whitelist))
if self.prefs.list_not_empty('volume_blacklist'):
logging.info("Blacklisted devices: %s", " ; ".join(self.prefs.volume_blacklist))
if self.prefs.list_not_empty('camera_blacklist'):
logging.info("Blacklisted cameras: %s", " ; ".join(self.prefs.camera_blacklist))
self.prefs.verify_file = False
logging.debug("Starting main ExifTool process")
self.exiftool_process = exiftool.ExifTool()
self.exiftool_process.start()
self.prefs.validate_max_CPU_cores()
self.prefs.validate_ignore_unhandled_file_exts()
# Don't call processEvents() after initiating 0MQ, as it can
# cause "Interrupted system call" errors
app.processEvents()
self.download_paused = False
self.startThreadControlSockets()
self.startProcessLogger()
def checkPrefsUpgrade(self) -> None:
if self.prefs.program_version != __about__.__version__:
previous_version = self.prefs.program_version
if not len(previous_version):
logging.debug("Initial program run detected")
else:
pv = pkg_resources.parse_version(previous_version)
rv = pkg_resources.parse_version(__about__.__version__)
if pv < rv:
logging.info(
"Version upgrade detected, from %s to %s",
previous_version, __about__.__version__
)
self.prefs.upgrade_prefs(pv)
elif pv > rv:
logging.info(
"Version downgrade detected, from %s to %s",
__about__.__version__, previous_version
)
if pv < pkg_resources.parse_version('0.9.7b1'):
# Remove any duplicate subfolder generation or file renaming custom presets
self.prefs.filter_duplicate_generation_prefs()
def startThreadControlSockets(self) -> None:
"""
Create and bind inproc sockets to communicate with threads that
handle inter process communication via zmq.
See 'Signaling Between Threads (PAIR Sockets)' in 'ØMQ - The Guide'
http://zguide.zeromq.org/page:all#toc46
"""
context = zmq.Context.instance()
inproc = "inproc://{}"
self.logger_controller = context.socket(zmq.PAIR)
self.logger_controller.bind(inproc.format(ThreadNames.logger))
self.rename_controller = context.socket(zmq.PAIR)
self.rename_controller.bind(inproc.format(ThreadNames.rename))
self.scan_controller = context.socket(zmq.PAIR)
self.scan_controller.bind(inproc.format(ThreadNames.scan))
self.copy_controller = context.socket(zmq.PAIR)
self.copy_controller.bind(inproc.format(ThreadNames.copy))
self.backup_controller = context.socket(zmq.PAIR)
self.backup_controller.bind(inproc.format(ThreadNames.backup))
self.thumbnail_deamon_controller = context.socket(zmq.PAIR)
self.thumbnail_deamon_controller.bind(inproc.format(ThreadNames.thumbnail_daemon))
self.offload_controller = context.socket(zmq.PAIR)
self.offload_controller.bind(inproc.format(ThreadNames.offload))
self.new_version_controller = context.socket(zmq.PAIR)
self.new_version_controller.bind(inproc.format(ThreadNames.new_version))
def sendStopToThread(self, socket: zmq.Socket) -> None:
socket.send_multipart(create_inproc_msg(b'STOP'))
def sendTerminateToThread(self, socket: zmq.Socket) -> None:
socket.send_multipart(create_inproc_msg(b'TERMINATE'))
def sendStopWorkerToThread(self, socket: zmq.Socket, worker_id: int) -> None:
socket.send_multipart(create_inproc_msg(b'STOP_WORKER', worker_id=worker_id))
def sendStartToThread(self, socket: zmq.Socket) -> None:
socket.send_multipart(create_inproc_msg(b'START'))
def sendStartWorkerToThread(self, socket: zmq.Socket, worker_id: int, data: Any) -> None:
socket.send_multipart(create_inproc_msg(b'START_WORKER', worker_id=worker_id, data=data))
def sendResumeToThread(self, socket: zmq.Socket, worker_id: Optional[int]=None) -> None:
socket.send_multipart(create_inproc_msg(b'RESUME', worker_id=worker_id))
def sendPauseToThread(self, socket: zmq.Socket) -> None:
socket.send_multipart(create_inproc_msg(b'PAUSE'))
def sendDataMessageToThread(self, socket: zmq.Socket,
data: Any,
worker_id: Optional[int]=None) -> None:
socket.send_multipart(create_inproc_msg(b'SEND_TO_WORKER', worker_id=worker_id, data=data))
def sendToOffload(self, data: Any) -> None:
self.offload_controller.send_multipart(
create_inproc_msg(b'SEND_TO_WORKER', worker_id=None, data=data)
)
def startProcessLogger(self) -> None:
self.loggermq = ProcessLoggingManager()
self.loggermqThread = QThread()
self.loggermq.moveToThread(self.loggermqThread)
self.loggermqThread.started.connect(self.loggermq.startReceiver)
self.loggermq.ready.connect(self.initStage2)
logging.debug("Starting logging subscription manager...")
QTimer.singleShot(0, self.loggermqThread.start)
@pyqtSlot(int)
def initStage2(self, logging_port: int) -> None:
logging.debug("...logging subscription manager started")
self.logging_port = logging_port
self.splash.setProgress(20)
logging.debug("Stage 2 initialization")
if self.prefs.purge_thumbnails:
cache = ThumbnailCacheSql(create_table_if_not_exists=False)
logging.info("Purging thumbnail cache...")
cache.purge_cache()
logging.info("...thumbnail Cache has been purged")
self.prefs.purge_thumbnails = False
# Recreate the cache on the file system
ThumbnailCacheSql(create_table_if_not_exists=True)
elif self.prefs.optimize_thumbnail_db:
cache = ThumbnailCacheSql(create_table_if_not_exists=True)
logging.info("Optimizing thumbnail cache...")
db, fs, size = cache.optimize()
logging.info("...thumbnail cache has been optimized.")
if db:
logging.info("Removed %s files from thumbnail database", db)
if fs:
logging.info("Removed %s thumbnails from file system", fs)
if size:
logging.info("Thumbnail database size reduction: %s", format_size_for_user(size))
self.prefs.optimize_thumbnail_db = False
else:
# Recreate the cache on the file system
ThumbnailCacheSql(create_table_if_not_exists=True)
# For meaning of 'Devices', see devices.py
self.devices = DeviceCollection(self.exiftool_process, self)
self.backup_devices = BackupDeviceCollection(rapidApp=self)
logging.debug("Starting thumbnail daemon model")
self.thumbnaildaemonmqThread = QThread()
self.thumbnaildaemonmq = ThumbnailDaemonManager(logging_port=logging_port)
self.thumbnaildaemonmq.moveToThread(self.thumbnaildaemonmqThread)
self.thumbnaildaemonmqThread.started.connect(self.thumbnaildaemonmq.run_sink)
self.thumbnaildaemonmq.message.connect(self.thumbnailReceivedFromDaemon)
self.thumbnaildaemonmq.sinkStarted.connect(self.initStage3)
QTimer.singleShot(0, self.thumbnaildaemonmqThread.start)
@pyqtSlot()
def initStage3(self) -> None:
logging.debug("Stage 3 initialization")
self.splash.setProgress(30)
self.sendStartToThread(self.thumbnail_deamon_controller)
logging.debug("...thumbnail daemon model started")
self.thumbnailView = ThumbnailView(self)
self.thumbnailModel = ThumbnailListModel(
parent=self, logging_port=self.logging_port, log_gphoto2=self.log_gphoto2
)
self.thumbnailView.setModel(self.thumbnailModel)
self.thumbnailView.setItemDelegate(ThumbnailDelegate(rapidApp=self))
@pyqtSlot(int)
def initStage4(self, frontend_port: int) -> None:
logging.debug("Stage 4 initialization")
self.splash.setProgress(40)
self.sendDataMessageToThread(
self.thumbnail_deamon_controller, worker_id=None,
data=ThumbnailDaemonData(frontend_port=frontend_port)
)
centralWidget = QWidget()
self.setCentralWidget(centralWidget)
self.temporalProximity = TemporalProximity(rapidApp=self, prefs=self.prefs)
# Respond to the user selecting / deslecting temporal proximity (timeline) cells:
self.temporalProximity.proximitySelectionHasChanged.connect(
self.updateThumbnailModelAfterProximityChange
)
self.temporalProximity.temporalProximityView.proximitySelectionHasChanged.connect(
self.updateThumbnailModelAfterProximityChange
)
self.file_manager, self.file_manager_type = get_default_file_manager()
if self.file_manager:
logging.info("Default file manager: %s", self.file_manager)
else:
logging.warning("Default file manager could not be determined")
# Setup notification system
try:
self.have_libnotify = Notify.init('rapid-photo-downloader')
self.ctime_update_notification = None # type: Optional[Notify.Notification]
self.ctime_notification_issued = False
except:
logging.error("Notification intialization problem")
self.have_libnotify = False
logging.debug("Locale directory: %s", raphodo.localedir)
# Initialise use of libgphoto2
logging.debug("Getting gphoto2 context")
try:
self.gp_context = gp.Context()
except:
logging.critical("Error getting gphoto2 context")
self.gp_context = None
logging.debug("Probing for valid mounts")
self.validMounts = ValidMounts(onlyExternalMounts=self.prefs.only_external_mounts)
logging.debug("Freedesktop.org thumbnails location: %s",
get_fdo_cache_thumb_base_directory())
logging.debug("Probing desktop environment")
desktop_env = get_desktop_environment()
if desktop_env is not None:
logging.debug("Desktop environment: %s", desktop_env)
else:
logging.debug("Desktop environment variable not set")
self.unity_progress = False
self.desktop_launchers = []
if get_desktop() in (Desktop.unity, Desktop.ubuntugnome):
if not have_unity:
logging.warning(
"Desktop environment is Unity Launcher API compatible, but could not load "
"Unity 7.0 module"
)
else:
# Unity auto-generated desktop files use underscores, it seems
launchers = (
'net.damonlynch.rapid-photo-downloader.desktop',
'net.damonlynch.rapid_photo_downloader.desktop',
)
for launcher in launchers:
desktop_launcher = Unity.LauncherEntry.get_for_desktop_id(launcher)
if desktop_launcher is not None:
self.desktop_launchers.append(desktop_launcher)
self.unity_progress = True
if not self.desktop_launchers:
logging.warning(
"Desktop environment is Unity Launcher API compatible, but could not "
"find program's .desktop file"
)
else:
logging.debug(
"Unity progress indicator found, using %s launcher(s)",
len(self.desktop_launchers)
)
self.createPathViews()
self.createActions()
logging.debug("Laying out main window")
self.createMenus()
self.createLayoutAndButtons(centralWidget)
logging.debug("Have GIO module: %s", have_gio)
self.gvfsControlsMounts = gvfs_controls_mounts() and have_gio
if have_gio:
logging.debug("Using GIO: %s", self.gvfsControlsMounts)
if not self.gvfsControlsMounts:
# Monitor when the user adds or removes a camera
self.cameraHotplug = CameraHotplug()
self.cameraHotplugThread = QThread()
self.cameraHotplugThread.started.connect(self.cameraHotplug.startMonitor)
self.cameraHotplug.moveToThread(self.cameraHotplugThread)
self.cameraHotplug.cameraAdded.connect(self.cameraAdded)
self.cameraHotplug.cameraRemoved.connect(self.cameraRemoved)
# Start the monitor only on the thread it will be running on
logging.debug("Starting camera hotplug monitor...")
QTimer.singleShot(0, self.cameraHotplugThread.start)
# Monitor when the user adds or removes a partition
self.udisks2Monitor = UDisks2Monitor(self.validMounts)
self.udisks2MonitorThread = QThread()
self.udisks2MonitorThread.started.connect(self.udisks2Monitor.startMonitor)
self.udisks2Unmount.connect(self.udisks2Monitor.unmount_volume)
self.udisks2Monitor.moveToThread(self.udisks2MonitorThread)
self.udisks2Monitor.partitionMounted.connect(self.partitionMounted)
self.udisks2Monitor.partitionUnmounted.connect(self.partitionUmounted)
# Start the monitor only on the thread it will be running on
logging.debug("Starting UDisks2 monitor...")
QTimer.singleShot(0, self.udisks2MonitorThread.start)
if self.gvfsControlsMounts:
# Gio.VolumeMonitor must be in the main thread, according to
# Gnome documentation
logging.debug("Starting GVolumeMonitor...")
self.gvolumeMonitor = GVolumeMonitor(self.validMounts)
logging.debug("...GVolumeMonitor started")
self.gvolumeMonitor.cameraUnmounted.connect(self.cameraUnmounted)
self.gvolumeMonitor.cameraMounted.connect(self.cameraMounted)
self.gvolumeMonitor.partitionMounted.connect(self.partitionMounted)
self.gvolumeMonitor.partitionUnmounted.connect(self.partitionUmounted)
self.gvolumeMonitor.volumeAddedNoAutomount.connect(self.noGVFSAutoMount)
self.gvolumeMonitor.cameraPossiblyRemoved.connect(self.cameraRemoved)
if disable_version_check:
logging.debug("Version check disabled")
else:
logging.debug("Starting version check")
self.newVersion = NewVersion(self)
self.newVersionThread = QThread()
self.newVersionThread.started.connect(self.newVersion.start)
self.newVersion.checkMade.connect(self.newVersionCheckMade)
self.newVersion.bytesDownloaded.connect(self.newVersionBytesDownloaded)
self.newVersion.fileDownloaded.connect(self.newVersionDownloaded)
self.reverifyDownloadedTar.connect(self.newVersion.reVerifyDownload)
self.newVersion.downloadSize.connect(self.newVersionDownloadSize)
self.newVersion.reverified.connect(self.installNewVersion)
self.newVersion.moveToThread(self.newVersionThread)
QTimer.singleShot(0, self.newVersionThread.start)
self.newVersionCheckDialog = NewVersionCheckDialog(self)
self.newVersionCheckDialog.finished.connect(self.newVersionCheckDialogFinished)
# if values set, indicates the latest version of the program, and the main
# download page on the Rapid Photo Downloader website
self.latest_version = None # type: version_details
self.latest_version_download_page = None # type: str
# Track the creation of temporary directories
self.temp_dirs_by_scan_id = {}
# Track the time a download commences - used in file renaming
self.download_start_datetime = None # type: Optional[datetime.datetime]
# The timestamp for when a download started / resumed after a pause
self.download_start_time = None # type: Optional[float]
logging.debug("Starting download tracker")
self.download_tracker = downloadtracker.DownloadTracker()
# Values used to display how much longer a download will take
self.time_remaining = downloadtracker.TimeRemaining()
self.time_check = downloadtracker.TimeCheck()
logging.debug("Setting up download update timer")
self.dl_update_timer = QTimer(self)
self.dl_update_timer.setInterval(constants.DownloadUpdateMilliseconds)
self.dl_update_timer.timeout.connect(self.displayDownloadRunningInStatusBar)
# Offload process is used to offload work that could otherwise
# cause this process and thus the GUI to become unresponsive
logging.debug("Starting offload manager...")
self.offloadThread = QThread()
self.offloadmq = OffloadManager(logging_port=self.logging_port)
self.offloadThread.started.connect(self.offloadmq.run_sink)
self.offloadmq.sinkStarted.connect(self.initStage5)
self.offloadmq.message.connect(self.proximityGroupsGenerated)
self.offloadmq.moveToThread(self.offloadThread)
QTimer.singleShot(0, self.offloadThread.start)
@pyqtSlot()
def initStage5(self) -> None:
logging.debug("...offload manager started")
self.sendStartToThread(self.offload_controller)
self.splash.setProgress(50)
self.folder_preview_manager = FolderPreviewManager(
fsmodel=self.fileSystemModel,
prefs=self.prefs,
photoDestinationFSView=self.photoDestinationFSView,
videoDestinationFSView=self.videoDestinationFSView,
devices=self.devices,
rapidApp=self
)
self.offloadmq.downloadFolders.connect(self.folder_preview_manager.folders_generated)
self.renameThread = QThread()
self.renamemq = RenameMoveFileManager(logging_port=self.logging_port)
self.renameThread.started.connect(self.renamemq.run_sink)
self.renamemq.sinkStarted.connect(self.initStage6)
self.renamemq.message.connect(self.fileRenamedAndMoved)
self.renamemq.sequencesUpdate.connect(self.updateSequences)
self.renamemq.renameProblems.connect(self.addErrorLogMessage)
self.renamemq.moveToThread(self.renameThread)
logging.debug("Starting rename manager...")
QTimer.singleShot(0, self.renameThread.start)
@pyqtSlot()
def initStage6(self) -> None:
logging.debug("...rename manager started")
self.splash.setProgress(60)
self.sendStartToThread(self.rename_controller)
# Setup the scan processes
self.scanThread = QThread()
self.scanmq = ScanManager(logging_port=self.logging_port)
self.scanThread.started.connect(self.scanmq.run_sink)
self.scanmq.sinkStarted.connect(self.initStage7)
self.scanmq.scannedFiles.connect(self.scanFilesReceived)
self.scanmq.deviceError.connect(self.scanErrorReceived)
self.scanmq.deviceDetails.connect(self.scanDeviceDetailsReceived)
self.scanmq.scanProblems.connect(self.scanProblemsReceived)
self.scanmq.workerFinished.connect(self.scanFinished)
self.scanmq.fatalError.connect(self.scanFatalError)
self.scanmq.moveToThread(self.scanThread)
logging.debug("Starting scan manager...")
QTimer.singleShot(0, self.scanThread.start)
@pyqtSlot()
def initStage7(self) -> None:
logging.debug("...scan manager started")
self.splash.setProgress(70)
# Setup the copyfiles process
self.copyfilesThread = QThread()
self.copyfilesmq = CopyFilesManager(logging_port=self.logging_port)
self.copyfilesThread.started.connect(self.copyfilesmq.run_sink)
self.copyfilesmq.sinkStarted.connect(self.initStage8)
self.copyfilesmq.message.connect(self.copyfilesDownloaded)
self.copyfilesmq.bytesDownloaded.connect(self.copyfilesBytesDownloaded)
self.copyfilesmq.tempDirs.connect(self.tempDirsReceivedFromCopyFiles)
self.copyfilesmq.copyProblems.connect(self.copyfilesProblems)
self.copyfilesmq.workerFinished.connect(self.copyfilesFinished)
self.copyfilesmq.moveToThread(self.copyfilesThread)
logging.debug("Starting copy files manager...")
QTimer.singleShot(0, self.copyfilesThread.start)
@pyqtSlot()
def initStage8(self) -> None:
logging.debug("...copy files manager started")
self.splash.setProgress(80)
self.backupThread = QThread()
self.backupmq = BackupManager(logging_port=self.logging_port)
self.backupThread.started.connect(self.backupmq.run_sink)
self.backupmq.sinkStarted.connect(self.initStage9)
self.backupmq.message.connect(self.fileBackedUp)
self.backupmq.bytesBackedUp.connect(self.backupFileBytesBackedUp)
self.backupmq.backupProblems.connect(self.backupFileProblems)
self.backupmq.moveToThread(self.backupThread)
logging.debug("Starting backup manager ...")
QTimer.singleShot(0, self.backupThread.start)
@pyqtSlot()
def initStage9(self) -> None:
logging.debug("...backup manager started")
self.splash.setProgress(90)
if self.prefs.backup_files:
self.setupBackupDevices()
else:
self.download_tracker.set_no_backup_devices(0, 0)
settings = QSettings()
settings.beginGroup("MainWindow")
self.proximityButton.setChecked(settings.value("proximityButtonPressed", True, bool))
self.proximityButtonClicked()
self.sourceButton.setChecked(settings.value("sourceButtonPressed", True, bool))
self.sourceButtonClicked()
# Default to displaying the destination panels if the value has never been
# set
index = settings.value("rightButtonPressed", 0, int)
if index >= 0:
try:
button = self.rightSideButtonMapper[index]
except ValueError:
logging.error("Unexpected preference value for right side button")
index = RightSideButton.destination
button = self.rightSideButtonMapper[index]
button.setChecked(True)
self.setRightPanelsAndButtons(RightSideButton(index))
settings.endGroup()
prefs_valid, msg = self.prefs.check_prefs_for_validity()
self.setupErrorLogWindow(settings=settings)
self.setDownloadCapabilities()
self.searchForCameras(on_startup=True)
self.setupNonCameraDevices(on_startup=True)
self.splash.setProgress(100)
self.setupManualPath(on_startup=True)
self.updateSourceButton()
self.displayMessageInStatusBar()
self.showMainWindow()
if EXIFTOOL_VERSION is None and self.prefs.warn_broken_or_missing_libraries:
message = _(
'<b>ExifTool has a problem</b><br><br> '
'Rapid Photo Downloader uses ExifTool to get metadata from videos and photos. '
'The program will run without it, but installing it is <b>highly</b> recommended.'
)
warning = RememberThisDialog(
message=message,
icon=':/rapid-photo-downloader.svg',
remember=RememberThisMessage.do_not_warn_again_about_missing_libraries,
parent=self,
buttons=RememberThisButtons.ok,
title=_('Problem with libmediainfo')
)
warning.exec_()
if warning.remember:
self.prefs.warn_broken_or_missing_libraries = False
if libmediainfo_missing and self.prefs.warn_broken_or_missing_libraries:
message = _(
'<b>The library libmediainfo appears to be missing</b><br><br> '
'Rapid Photo Downloader uses libmediainfo to get the date and time a video was '
'shot. The program will run without it, but installing it is recommended.'
)
warning = RememberThisDialog(
message=message,
icon=':/rapid-photo-downloader.svg',
remember=RememberThisMessage.do_not_warn_again_about_missing_libraries,
parent=self,
buttons=RememberThisButtons.ok,
title=_('Problem with libmediainfo')
)
warning.exec_()
if warning.remember:
self.prefs.warn_broken_or_missing_libraries = False
self.tip = didyouknow.DidYouKnowDialog(self.prefs, self)
if self.prefs.did_you_know_on_startup:
self.tip.activate()
if not prefs_valid:
self.notifyPrefsAreInvalid(details=msg)
else:
self.checkForNewVersionRequest.emit()
logging.debug("Completed stage 9 initializing main window")
def showMainWindow(self) -> None:
if not self.isVisible():
self.splash.finish(self)
self.window_show_requested_time = datetime.datetime.now()
self.show()
self.errorLog.setVisible(self.errorLogAct.isChecked())
def mapModel(self, scan_id: int) -> DeviceModel:
"""
Map a scan_id onto Devices' or This Computer's device model.
:param scan_id: scan id of the device
:return: relevant device model
"""
return self._mapModel[self.devices[scan_id].device_type]
def mapView(self, scan_id: int) -> DeviceView:
"""
Map a scan_id onto Devices' or This Computer's device view.
:param scan_id: scan id of the device
:return: relevant device view
"""
return self._mapView[self.devices[scan_id].device_type]
def setupErrorLogWindow(self, settings: QSettings) -> None:
"""
Creates, moves and resizes error log window, but does not show it.
"""
default_x = self.pos().x()
default_y = self.pos().y()
default_width = int(self.size().width() * 0.5)
default_height = int(self.size().height() * 0.5)
settings.beginGroup("ErrorLog")
pos = settings.value("windowPosition", QPoint(default_x, default_y))
size = settings.value("windowSize", QSize(default_width, default_height))
visible = settings.value('visible', False, type=bool)
settings.endGroup()
self.errorLog = ErrorReport(rapidApp=self)
self.errorLogAct.setChecked(visible)
self.errorLog.move(pos)
self.errorLog.resize(size)
self.errorLog.finished.connect(self.setErrorLogAct)
self.errorLog.dialogShown.connect(self.setErrorLogAct)
self.errorLog.dialogActivated.connect(self.errorsPending.reset)
self.errorsPending.clicked.connect(self.errorLog.activate)
def readWindowSettings(self, app: 'QtSingleApplication'):
settings = QSettings()
settings.beginGroup("MainWindow")
desktop = app.desktop() # type: QDesktopWidget
# Calculate window sizes
available = desktop.availableGeometry(desktop.primaryScreen()) # type: QRect
screen = desktop.screenGeometry(desktop.primaryScreen()) # type: QRect
default_width = max(960, available.width() // 2)
default_width = min(default_width, available.width())
default_x = screen.width() - default_width
default_height = available.height()
default_y = screen.height() - default_height
pos = settings.value("windowPosition", QPoint(default_x, default_y))
size = settings.value("windowSize", QSize(default_width, default_height))
settings.endGroup()
self.resize(size)
self.move(pos)
def writeWindowSettings(self):
logging.debug("Writing window settings")
settings = QSettings()
settings.beginGroup("MainWindow")
windowPos = self.pos() + self.windowPositionDelta
if windowPos.x() < 0:
windowPos.setX(0)
if windowPos.y() < 0:
windowPos.setY(0)
settings.setValue("windowPosition", windowPos)
settings.setValue("windowSize", self.size())
settings.setValue("centerSplitterSizes", self.centerSplitter.saveState())
settings.setValue("sourceButtonPressed", self.sourceButton.isChecked())
settings.setValue("rightButtonPressed", self.rightSideButtonPressed())
settings.setValue("proximityButtonPressed", self.proximityButton.isChecked())
settings.setValue("leftPanelSplitterSizes", self.leftPanelSplitter.saveState())
settings.setValue("rightPanelSplitterSizes", self.rightPanelSplitter.saveState())
settings.endGroup()
settings.beginGroup("ErrorLog")
settings.setValue("windowPosition", self.errorLog.pos())
settings.setValue("windowSize", self.errorLog.size())
settings.setValue('visible', self.errorLog.isVisible())
settings.endGroup()
def moveEvent(self, event: QMoveEvent) -> None:
"""
Handle quirks in window positioning.
X11 has a feature where the window managager can decorate the
windows. A side effect of this is that the position returned by
window.pos() can be different between restoring the position
from the settings, and saving the position at application exit, even if
the user never moved the window.
"""
super().moveEvent(event)
self.window_move_triggered_count += 1
if self.window_show_requested_time is None:
pass
# self.windowPositionDelta = QPoint(0, 0)
elif self.window_move_triggered_count == 2:
if (datetime.datetime.now() - self.window_show_requested_time).total_seconds() < 1.0:
self.windowPositionDelta = event.oldPos() - self.pos()
logging.debug("Window position quirk delta: %s", self.windowPositionDelta)
self.window_show_requested_time = None
def setupWindow(self):
status = self.statusBar()
status.setStyleSheet("QStatusBar::item { border: 0px solid black }; ")
self.downloadProgressBar = QProgressBar()
self.downloadProgressBar.setMaximumWidth(QFontMetrics(QFont()).height() * 9)
self.errorsPending = SpeechBubble(self)
self.errorsPending.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
status.addPermanentWidget(self.errorsPending)
status.addPermanentWidget(self.downloadProgressBar, 1)
def anyFilesSelected(self) -> bool:
"""
:return: True if any files are selected
"""
return self.thumbnailView.selectionModel().hasSelection()
def applyJobCode(self, job_code: str) -> None:
"""
Apply job code to all selected photos/videos.
:param job_code: job code to apply
"""
delegate = self.thumbnailView.itemDelegate() # type: ThumbnailDelegate
delegate.applyJobCode(job_code=job_code)
@pyqtSlot(bool, version_details, version_details, str, bool, bool)
def newVersionCheckMade(self, success: bool,
stable_version: version_details,
dev_version: version_details,
download_page: str,
no_upgrade: bool,
pip_install: bool) -> None:
"""
Respond to a version check, either initiated at program startup, or from the
application's main menu.
If the check was initiated at program startup, then the new version dialog box
will not be showing.
:param success: whether the version check was successful or not
:param stable_version: latest stable version
:param dev_version: latest development version
:param download_page: url of the download page on the Rapid
Photo Downloader website
:param no_upgrade: if True, don't offer to do an inplace upgrade
:param pip_install: whether pip was used to install this
program version
"""
if success:
self.latest_version = None
current_version = pkg_resources.parse_version(__about__.__version__)
check_dev_version = (current_version.is_prerelease or
self.prefs.include_development_release)
if current_version < stable_version.version:
self.latest_version = stable_version
if check_dev_version and (
current_version < dev_version.version or
current_version < stable_version.version
):
if dev_version.version > stable_version.version:
self.latest_version = dev_version
else:
self.latest_version = stable_version
if (
self.latest_version is not None and str(self.latest_version.version) not in
self.prefs.ignore_versions):
version = str(self.latest_version.version)
changelog_url = self.latest_version.changelog_url
if pip_install:
logging.debug("Installation performed via pip")
if no_upgrade:
logging.info("Cannot perform in-place upgrade to this version")
state = CheckNewVersionDialogState.open_website
else:
download_page = None
state = CheckNewVersionDialogState.prompt_for_download
else:
logging.debug("Installation not performed via pip")
state = CheckNewVersionDialogState.open_website
self.latest_version_download_page = download_page
self.newVersionCheckDialog.displayUserMessage(
new_state=state,
version=version,
download_page=download_page,
changelog_url=changelog_url
)
if not self.newVersionCheckDialog.isVisible():
self.newVersionCheckDialog.show()
elif self.newVersionCheckDialog.isVisible():
self.newVersionCheckDialog.displayUserMessage(
CheckNewVersionDialogState.have_latest_version)
elif self.newVersionCheckDialog.isVisible():
# Failed to reach update server
self.newVersionCheckDialog.displayUserMessage(
CheckNewVersionDialogState.failed_to_contact)
@pyqtSlot(int)
def newVersionCheckDialogFinished(self, result: int) -> None:
current_state = self.newVersionCheckDialog.current_state
if current_state in (
CheckNewVersionDialogState.prompt_for_download,
CheckNewVersionDialogState.open_website):
if self.newVersionCheckDialog.dialog_detailed_result == \
CheckNewVersionDialogResult.skip:
version = str(self.latest_version.version)
logging.info(
"Adding version %s to the list of program versions to ignore", version
)
self.prefs.add_list_value(key='ignore_versions', value=version)
elif self.newVersionCheckDialog.dialog_detailed_result == \
CheckNewVersionDialogResult.open_website:
webbrowser.open_new_tab(self.latest_version_download_page)
elif self.newVersionCheckDialog.dialog_detailed_result == \
CheckNewVersionDialogResult.download:
url = self.latest_version.url
md5 = self.latest_version.md5
self.downloadNewVersionRequest.emit(url, md5)
self.downloadNewVersionDialog = DownloadNewVersionDialog(parent=self)
self.downloadNewVersionDialog.rejected.connect(self.newVersionDownloadCancelled)
self.downloadNewVersionDialog.show()
@pyqtSlot('PyQt_PyObject')
def newVersionBytesDownloaded(self, bytes_downloaded: int) -> None:
if self.downloadNewVersionDialog.isVisible():
self.downloadNewVersionDialog.updateProgress(bytes_downloaded)
@pyqtSlot('PyQt_PyObject')
def newVersionDownloadSize(self, download_size: int) -> None:
if self.downloadNewVersionDialog.isVisible():
self.downloadNewVersionDialog.setDownloadSize(download_size)
@pyqtSlot(str, bool)
def newVersionDownloaded(self, path: str, download_cancelled: bool) -> None:
self.downloadNewVersionDialog.accept()
if not path and not download_cancelled:
msgBox = QMessageBox(parent=self)
msgBox.setIcon(QMessageBox.Warning)
msgBox.setWindowTitle(_("Download failed"))
msgBox.setText(
_('Sorry, the download of the new version of Rapid Photo Downloader failed.')
)
msgBox.exec_()
elif path:
logging.info("New program version downloaded to %s", path)
message = _(
'The new version was successfully downloaded. Do you want to '
'close Rapid Photo Downloader and install it now?'
)
msgBox = QMessageBox(parent=self)
msgBox.setWindowTitle(_('Update Rapid Photo Downloader'))
msgBox.setText(message)
msgBox.setIcon(QMessageBox.Question)
msgBox.setStandardButtons(QMessageBox.Cancel)
installButton = msgBox.addButton(_('Install'), QMessageBox.AcceptRole)
msgBox.setDefaultButton(installButton)
if msgBox.exec_() == QMessageBox.AcceptRole:
self.reverifyDownloadedTar.emit(path)
else:
# extract the install.py script and move it to the correct location
# for testing:
# path = '/home/damon/rapid090a7/dist/rapid-photo-downloader-0.9.0a7.tar.gz'
extract_file_from_tar(full_tar_path=path, member_filename='install.py')
installer_dir = os.path.dirname(path)
if self.file_manager:
uri = pathname2url(path)
cmd = '{} {}'.format(self.file_manager, uri)
logging.debug("Launching: %s", cmd)
args = shlex.split(cmd)
subprocess.Popen(args)
else:
msgBox = QMessageBox(parent=self)
msgBox.setWindowTitle(_('New version saved'))
message = _(
'The tar file and installer script are saved at:\n\n %s'
) % installer_dir
msgBox.setText(message)
msgBox.setIcon(QMessageBox.Information)
msgBox.exec_()
@pyqtSlot(bool, str)
def installNewVersion(self, reverified: bool, full_tar_path: str) -> None:
"""
Launch script to install new version of Rapid Photo Downloader
via upgrade.py.
:param reverified: whether file has been reverified or not
:param full_tar_path: path to the tarball
"""
if not reverified:
msgBox = QMessageBox(parent=self)
msgBox.setIcon(QMessageBox.Warning)
msgBox.setWindowTitle(_("Upgrade failed"))
msgBox.setText(
_(
'Sorry, upgrading Rapid Photo Downloader failed because there was '
'an error opening the installer.'
)
)
msgBox.exec_()
else:
# for testing:
# full_tar_path = '/home/damon/rapid090a7/dist/rapid-photo-downloader-0.9.0a7.tar.gz'
upgrade_py = 'upgrade.py'
installer_dir = os.path.dirname(full_tar_path)
if extract_file_from_tar(full_tar_path, upgrade_py):
upgrade_script = os.path.join(installer_dir, upgrade_py)
cmd = shlex.split('{} {} {}'.format(sys.executable, upgrade_script, full_tar_path))
subprocess.Popen(cmd)
self.quit()
@pyqtSlot()
def newVersionDownloadCancelled(self) -> None:
logging.info("Download of new program version cancelled")
self.new_version_controller.send(b'STOP')
def updateProgressBarState(self, thumbnail_generated: bool=None) -> None:
"""
Updates the state of the ProgessBar in the main window's lower right corner.
If any device is downloading, the progress bar displays
download progress.
Else, if any device is thumbnailing, the progress bar
displays thumbnailing progress.
Else, if any device is scanning, the progress bar shows a busy status.
Else, the progress bar is set to an idle status.
"""
if self.downloadIsRunning():
logging.debug("Setting progress bar to show download progress")
self.downloadProgressBar.setMaximum(100)
return
if self.unity_progress:
for launcher in self.desktop_launchers:
launcher.set_property('progress_visible', False)
if len(self.devices.thumbnailing):
if self.downloadProgressBar.maximum() != self.thumbnailModel.total_thumbs_to_generate:
logging.debug(
"Setting progress bar maximum to %s",
self.thumbnailModel.total_thumbs_to_generate
)
self.downloadProgressBar.setMaximum(self.thumbnailModel.total_thumbs_to_generate)
if thumbnail_generated:
self.downloadProgressBar.setValue(self.thumbnailModel.thumbnails_generated)
elif len(self.devices.scanning):
logging.debug("Setting progress bar to show scanning activity")
self.downloadProgressBar.setMaximum(0)
else:
logging.debug("Resetting progress bar")
self.downloadProgressBar.reset()
self.downloadProgressBar.setMaximum(100)
def updateSourceButton(self) -> None:
text, icon = self.devices.get_main_window_display_name_and_icon()
self.sourceButton.setText(addPushButtonLabelSpacer(text))
self.sourceButton.setIcon(icon)
def setLeftPanelVisibility(self) -> None:
self.leftPanelSplitter.setVisible(
self.sourceButton.isChecked() or self.proximityButton.isChecked()
)
def setRightPanelsAndButtons(self, buttonPressed: RightSideButton) -> None:
"""
Set visibility of right panel based on which right bar buttons
is pressed, and ensure only one button is pressed at any one time.
Cannot use exclusive QButtonGroup because with that, one button needs to be
pressed. We allow no button to be pressed.
"""
widget = self.rightSideButtonMapper[buttonPressed] # type: RotatedButton
if widget.isChecked():
self.rightPanels.setVisible(True)
for button in RightSideButton:
if button == buttonPressed:
self.rightPanels.setCurrentIndex(buttonPressed.value)
else:
self.rightSideButtonMapper[button].setChecked(False)
else:
self.rightPanels.setVisible(False)
def rightSideButtonPressed(self) -> int:
"""
Determine which right side button is currently pressed, if any.
:return: -1 if no button is pressed, else the index into
RightSideButton
"""
for button in RightSideButton:
widget = self.rightSideButtonMapper[button]
if widget.isChecked():
return int(button.value)
return -1
@pyqtSlot()
def sourceButtonClicked(self) -> None:
self.deviceToggleView.setVisible(self.sourceButton.isChecked())
self.thisComputerToggleView.setVisible(self.sourceButton.isChecked())
self.setLeftPanelVisibility()
@pyqtSlot()
def destinationButtonClicked(self) -> None:
self.setRightPanelsAndButtons(RightSideButton.destination)
@pyqtSlot()
def renameButtonClicked(self) -> None:
self.setRightPanelsAndButtons(RightSideButton.rename)
@pyqtSlot()
def backupButtonClicked(self) -> None:
self.setRightPanelsAndButtons(RightSideButton.backup)
@pyqtSlot()
def jobcodButtonClicked(self) -> None:
self.jobCodePanel.updateDefaultMessage()
self.setRightPanelsAndButtons(RightSideButton.jobcode)
@pyqtSlot()
def proximityButtonClicked(self) -> None:
self.temporalProximity.setVisible(self.proximityButton.isChecked())
self.setLeftPanelVisibility()
self.adjustLeftPanelSliderHandles()
def adjustLeftPanelSliderHandles(self):
"""
Move left panel splitter handles in response to devices / this computer
changes.
"""
preferred_devices_height = self.deviceToggleView.minimumHeight()
min_this_computer_height = self.thisComputerToggleView.minimumHeight()
if self.thisComputerToggleView.on():
this_computer_height = max(
min_this_computer_height, self.centerSplitter.height() - preferred_devices_height
)
else:
this_computer_height = min_this_computer_height
if self.proximityButton.isChecked():
if not self.thisComputerToggleView.on():
proximity_height = (
self.centerSplitter.height() - this_computer_height - preferred_devices_height
)
else:
proximity_height = this_computer_height // 2
this_computer_height = this_computer_height // 2
else:
proximity_height = 0
self.leftPanelSplitter.setSizes(
[preferred_devices_height, this_computer_height, proximity_height]
)
@pyqtSlot(int)
def showComboChanged(self, index: int) -> None:
self.sortComboChanged(index=-1)
self.thumbnailModel.updateAllDeviceDisplayCheckMarks()
def showOnlyNewFiles(self) -> bool:
"""
User can use combo switch to show only so-called "hew" files, i.e. files that
have not been previously downloaded.
:return: True if only new files are shown
"""
return self.showCombo.currentData() == Show.new_only
@pyqtSlot(int)
def sortComboChanged(self, index: int) -> None:
sort = self.sortCombo.currentData()
order = self.sortOrder.currentData()
show = self.showCombo.currentData()
self.thumbnailModel.setFileSort(sort=sort, order=order, show=show)
@pyqtSlot(int)
def sortOrderChanged(self, index: int) -> None:
self.sortComboChanged(index=-1)
@pyqtSlot(int)
def selectAllPhotosCheckboxChanged(self, state: int) -> None:
select_all = state == Qt.Checked
self.thumbnailModel.selectAll(select_all=select_all, file_type=FileType.photo)
@pyqtSlot(int)
def selectAllVideosCheckboxChanged(self, state: int) -> None:
select_all = state == Qt.Checked
self.thumbnailModel.selectAll(select_all=select_all, file_type=FileType.video)
@pyqtSlot()
def setErrorLogAct(self) -> None:
self.errorLogAct.setChecked(self.errorLog.isVisible())
def createActions(self) -> None:
self.downloadAct = QAction(
_("Download"), self, shortcut="Ctrl+Return", triggered=self.doDownloadAction
)
self.refreshAct = QAction(
_("&Refresh..."), self, shortcut="Ctrl+R", triggered=self.doRefreshAction
)
self.preferencesAct = QAction(
_("&Preferences"), self, shortcut="Ctrl+P", triggered=self.doPreferencesAction
)
self.quitAct = QAction(
_("&Quit"), self, shortcut="Ctrl+Q", triggered=self.close
)
self.errorLogAct = QAction(
_("Error &Reports"), self, enabled=True, checkable=True, triggered=self.doErrorLogAction
)
self.clearDownloadsAct = QAction(
_("Clear Completed Downloads"), self, triggered=self.doClearDownloadsAction
)
self.helpAct = QAction(
_("Get Help Online..."), self, shortcut="F1", triggered=self.doHelpAction
)
self.didYouKnowAct = QAction(
_("&Tip of the Day..."), self, triggered=self.doDidYouKnowAction
)
self.reportProblemAct = QAction(
_("Report a Problem..."), self, triggered=self.doReportProblemAction
)
self.makeDonationAct = QAction(
_("Make a Donation..."), self, triggered=self.doMakeDonationAction
)
self.translateApplicationAct = QAction(
_("Translate this Application..."), self, triggered=self.doTranslateApplicationAction
)
self.aboutAct = QAction(
_("&About..."), self, triggered=self.doAboutAction
)
self.newVersionAct = QAction(
_("Check for Updates..."), self, triggered=self.doCheckForNewVersion
)
def createLayoutAndButtons(self, centralWidget) -> None:
"""
Create widgets used to display the GUI.
:param centralWidget: the widget in which to layout the new widgets
"""
settings = QSettings()
settings.beginGroup("MainWindow")
verticalLayout = QVBoxLayout()
verticalLayout.setContentsMargins(0, 0, 0, 0)
centralWidget.setLayout(verticalLayout)
self.standard_spacing = verticalLayout.spacing()
topBar = self.createTopBar()
verticalLayout.addLayout(topBar)
centralLayout = QHBoxLayout()
centralLayout.setContentsMargins(0, 0, 0, 0)
self.leftBar = self.createLeftBar()
self.rightBar = self.createRightBar()
self.createCenterPanels()
self.createDeviceThisComputerViews()
self.createDestinationViews()
self.createRenamePanels()
self.createJobCodePanel()
self.createBackupPanel()
self.configureCenterPanels(settings)
self.createBottomControls()
centralLayout.addLayout(self.leftBar)
centralLayout.addWidget(self.centerSplitter)
centralLayout.addLayout(self.rightBar)
verticalLayout.addLayout(centralLayout)
verticalLayout.addWidget(self.thumbnailControl)
def createTopBar(self) -> QHBoxLayout:
topBar = QHBoxLayout()
menu_margin = int(QFontMetrics(QFont()).height() / 3)
topBar.setContentsMargins(0, 0, menu_margin, 0)
topBar.setSpacing(int(QFontMetrics(QFont()).height() / 2))
self.sourceButton = TopPushButton(
addPushButtonLabelSpacer(_('Select Source')), extra_top=self.standard_spacing
)
self.sourceButton.clicked.connect(self.sourceButtonClicked)
vlayout = QVBoxLayout()
vlayout.setContentsMargins(0, 0, 0, 0)
vlayout.setSpacing(0)
vlayout.addSpacing(self.standard_spacing)
hlayout = QHBoxLayout()
hlayout.setContentsMargins(0, 0, 0, 0)
hlayout.setSpacing(menu_margin)
vlayout.addLayout(hlayout)
self.downloadButton = DownloadButton(self.downloadAct.text())
self.downloadButton.addAction(self.downloadAct)
self.downloadButton.setDefault(True)
self.downloadButton.clicked.connect(self.downloadButtonClicked)
self.menuButton.setIconSize(
QSize(self.sourceButton.top_row_icon_size, self.sourceButton.top_row_icon_size)
)
topBar.addWidget(self.sourceButton)
topBar.addStretch()
topBar.addLayout(vlayout)
hlayout.addWidget(self.downloadButton)
hlayout.addWidget(self.menuButton)
return topBar
def createLeftBar(self) -> QVBoxLayout:
leftBar = QVBoxLayout()
leftBar.setContentsMargins(0, 0, 0, 0)
self.proximityButton = RotatedButton(_('Timeline'), RotatedButton.leftSide)
self.proximityButton.clicked.connect(self.proximityButtonClicked)
leftBar.addWidget(self.proximityButton)
leftBar.addStretch()
return leftBar
def createRightBar(self) -> QVBoxLayout:
rightBar = QVBoxLayout()
rightBar.setContentsMargins(0, 0, 0, 0)
self.destinationButton = RotatedButton(_('Destination'), RotatedButton.rightSide)
self.renameButton = RotatedButton(_('Rename'), RotatedButton.rightSide)
self.jobcodeButton = RotatedButton(_('Job Code'), RotatedButton.rightSide)
self.backupButton = RotatedButton(_('Back Up'), RotatedButton.rightSide)
self.destinationButton.clicked.connect(self.destinationButtonClicked)
self.renameButton.clicked.connect(self.renameButtonClicked)
self.jobcodeButton.clicked.connect(self.jobcodButtonClicked)
self.backupButton.clicked.connect(self.backupButtonClicked)
self.rightSideButtonMapper = {
RightSideButton.destination: self.destinationButton,
RightSideButton.rename: self.renameButton,
RightSideButton.jobcode: self.jobcodeButton,
RightSideButton.backup: self.backupButton
}
rightBar.addWidget(self.destinationButton)
rightBar.addWidget(self.renameButton)
rightBar.addWidget(self.jobcodeButton)
rightBar.addWidget(self.backupButton)
rightBar.addStretch()
return rightBar
def createPathViews(self) -> None:
self.deviceView = DeviceView(rapidApp=self)
self.deviceModel = DeviceModel(self, "Devices")
self.deviceView.setModel(self.deviceModel)
self.deviceView.setItemDelegate(DeviceDelegate(rapidApp=self))
# This computer is any local path
self.thisComputerView = DeviceView(rapidApp=self)
self.thisComputerModel = DeviceModel(self, "This Computer")
self.thisComputerView.setModel(self.thisComputerModel)
self.thisComputerView.setItemDelegate(DeviceDelegate(self))
# Map different device types onto their appropriate view and model
self._mapModel = {
DeviceType.path: self.thisComputerModel,
DeviceType.camera: self.deviceModel,
DeviceType.volume: self.deviceModel
}
self._mapView = {
DeviceType.path: self.thisComputerView,
DeviceType.camera: self.deviceView,
DeviceType.volume: self.deviceView
}
# Be cautious: validate paths. The settings file can alwasy be edited by hand, and
# the user can set it to whatever value they want using the command line options.
logging.debug("Checking path validity")
this_computer_sf = validate_source_folder(self.prefs.this_computer_path)
if this_computer_sf.valid:
if this_computer_sf.absolute_path != self.prefs.this_computer_path:
self.prefs.this_computer_path = this_computer_sf.absolute_path
elif self.prefs.this_computer_source and self.prefs.this_computer_path != '':
logging.warning(
"Ignoring invalid 'This Computer' path: %s", self.prefs.this_computer_path
)
self.prefs.this_computer_path = ''
photo_df = validate_download_folder(self.prefs.photo_download_folder)
if photo_df.valid:
if photo_df.absolute_path != self.prefs.photo_download_folder:
self.prefs.photo_download_folder = photo_df.absolute_path
else:
if self.prefs.photo_download_folder:
logging.error(
"Ignoring invalid Photo Destination path: %s", self.prefs.photo_download_folder
)
self.prefs.photo_download_folder = ''
video_df = validate_download_folder(self.prefs.video_download_folder)
if video_df.valid:
if video_df.absolute_path != self.prefs.video_download_folder:
self.prefs.video_download_folder = video_df.absolute_path
else:
if self.prefs.video_download_folder:
logging.error(
"Ignoring invalid Video Destination path: %s", self.prefs.video_download_folder
)
self.prefs.video_download_folder = ''
self.watchedDownloadDirs = WatchDownloadDirs()
self.watchedDownloadDirs.updateWatchPathsFromPrefs(self.prefs)
self.watchedDownloadDirs.directoryChanged.connect(self.watchedFolderChange)
self.fileSystemModel = FileSystemModel(parent=self)
self.fileSystemFilter = FileSystemFilter(self)
self.fileSystemFilter.setSourceModel(self.fileSystemModel)
self.fileSystemDelegate = FileSystemDelegate()
index = self.fileSystemFilter.mapFromSource(self.fileSystemModel.index('/'))
self.thisComputerFSView = FileSystemView(model=self.fileSystemModel, rapidApp=self)
self.thisComputerFSView.setModel(self.fileSystemFilter)
self.thisComputerFSView.setItemDelegate(self.fileSystemDelegate)
self.thisComputerFSView.hideColumns()
self.thisComputerFSView.setRootIndex(index)
if this_computer_sf.valid:
self.thisComputerFSView.goToPath(self.prefs.this_computer_path)
self.thisComputerFSView.activated.connect(self.thisComputerPathChosen)
self.thisComputerFSView.clicked.connect(self.thisComputerPathChosen)
self.photoDestinationFSView = FileSystemView(model=self.fileSystemModel, rapidApp=self)
self.photoDestinationFSView.setModel(self.fileSystemFilter)
self.photoDestinationFSView.setItemDelegate(self.fileSystemDelegate)
self.photoDestinationFSView.hideColumns()
self.photoDestinationFSView.setRootIndex(index)
if photo_df.valid:
self.photoDestinationFSView.goToPath(self.prefs.photo_download_folder)
self.photoDestinationFSView.activated.connect(self.photoDestinationPathChosen)
self.photoDestinationFSView.clicked.connect(self.photoDestinationPathChosen)
self.videoDestinationFSView = FileSystemView(model=self.fileSystemModel, rapidApp=self)
self.videoDestinationFSView.setModel(self.fileSystemFilter)
self.videoDestinationFSView.setItemDelegate(self.fileSystemDelegate)
self.videoDestinationFSView.hideColumns()
self.videoDestinationFSView.setRootIndex(index)
if video_df.valid:
self.videoDestinationFSView.goToPath(self.prefs.video_download_folder)
self.videoDestinationFSView.activated.connect(self.videoDestinationPathChosen)
self.videoDestinationFSView.clicked.connect(self.videoDestinationPathChosen)
def createDeviceThisComputerViews(self) -> None:
# Devices Header and View
tip = _('Turn on or off the use of devices attached to this computer as download sources')
self.deviceToggleView = QToggleView(
label=_('Devices'),
display_alternate=True,
toggleToolTip=tip,
headerColor=QColor(ThumbnailBackgroundName),
headerFontColor=QColor(Qt.white),
on=self.prefs.device_autodetection
)
self.deviceToggleView.addWidget(self.deviceView)
self.deviceToggleView.valueChanged.connect(self.deviceToggleViewValueChange)
self.deviceToggleView.setSizePolicy(
QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding
)
# This Computer Header and View
tip = _('Turn on or off the use of a folder on this computer as a download source')
self.thisComputerToggleView = QToggleView(
label=_('This Computer'),
display_alternate=True,
toggleToolTip=tip,
headerColor=QColor(ThumbnailBackgroundName),
headerFontColor=QColor(Qt.white),
on=bool(self.prefs.this_computer_source)
)
self.thisComputerToggleView.valueChanged.connect(self.thisComputerToggleValueChanged)
self.thisComputer = ComputerWidget(
objectName='thisComputer',
view=self.thisComputerView,
fileSystemView=self.thisComputerFSView,
select_text=_('Select a source folder')
)
if self.prefs.this_computer_source:
self.thisComputer.setViewVisible(self.prefs.this_computer_source)
self.thisComputerToggleView.addWidget(self.thisComputer)
def createDestinationViews(self) -> None:
"""
Create the widgets that let the user choose where to download photos and videos to,
and that show them how much storage space there is available for their files.
"""
self.photoDestination = QPanelView(
label=_('Photos'),
headerColor=QColor(ThumbnailBackgroundName),
headerFontColor=QColor(Qt.white)
)
self.videoDestination = QPanelView(
label=_('Videos'),
headerColor=QColor(ThumbnailBackgroundName),
headerFontColor=QColor(Qt.white)
)
# Display storage space when photos and videos are being downloaded to the same
# partition
self.combinedDestinationDisplay = DestinationDisplay(parent=self)
self.combinedDestinationDisplayContainer = QPanelView(
_('Projected Storage Use'),
headerColor=QColor(ThumbnailBackgroundName),
headerFontColor=QColor(Qt.white)
)
self.combinedDestinationDisplayContainer.addWidget(self.combinedDestinationDisplay)
# Display storage space when photos and videos are being downloaded to different
# partitions.
# Also display the file system folder chooser for both destinations.
self.photoDestinationDisplay = DestinationDisplay(
menu=True, file_type=FileType.photo, parent=self
)
self.photoDestinationDisplay.setDestination(self.prefs.photo_download_folder)
self.photoDestinationWidget = ComputerWidget(
objectName='photoDestination',
view=self.photoDestinationDisplay,
fileSystemView=self.photoDestinationFSView,
select_text=_('Select a destination folder')
)
self.photoDestination.addWidget(self.photoDestinationWidget)
self.videoDestinationDisplay = DestinationDisplay(
menu=True, file_type=FileType.video, parent=self
)
self.videoDestinationDisplay.setDestination(self.prefs.video_download_folder)
self.videoDestinationWidget = ComputerWidget(
objectName='videoDestination',
view=self.videoDestinationDisplay,
fileSystemView=self.videoDestinationFSView,
select_text=_('Select a destination folder')
)
self.videoDestination.addWidget(self.videoDestinationWidget)
self.photoDestinationContainer = QWidget()
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
self.photoDestinationContainer.setLayout(layout)
layout.addWidget(self.combinedDestinationDisplayContainer)
layout.addWidget(self.photoDestination)
def createRenamePanels(self) -> None:
"""
Create the file renaming panel
"""
self.renamePanel = RenamePanel(parent=self)
def createJobCodePanel(self) -> None:
"""
Create the job code panel
"""
self.jobCodePanel = JobCodePanel(parent=self)
def createBackupPanel(self) -> None:
"""
Create the backup options panel
"""
self.backupPanel = BackupPanel(parent=self)
def createBottomControls(self) -> None:
self.thumbnailControl = QWidget()
layout = QHBoxLayout()
# left and right align at edge of left & right bar
hmargin = self.proximityButton.sizeHint().width()
hmargin += self.standard_spacing
vmargin = int(QFontMetrics(QFont()).height() / 2 )
layout.setContentsMargins(hmargin, vmargin, hmargin, vmargin)
layout.setSpacing(self.standard_spacing)
self.thumbnailControl.setLayout(layout)
font = self.font() # type: QFont
font.setPointSize(font.pointSize() - 2)
self.showCombo = ChevronCombo()
self.showCombo.addItem(_('All'), Show.all)
self.showCombo.addItem(_('New'), Show.new_only)
self.showCombo.currentIndexChanged.connect(self.showComboChanged)
self.showLabel = self.showCombo.makeLabel(_("Show:"))
self.sortCombo = ChevronCombo()
self.sortCombo.addItem(_("Modification Time"), Sort.modification_time)
self.sortCombo.addItem(_("Checked State"), Sort.checked_state)
self.sortCombo.addItem(_("Filename"), Sort.filename)
self.sortCombo.addItem(_("Extension"), Sort.extension)
self.sortCombo.addItem(_("File Type"), Sort.file_type)
self.sortCombo.addItem(_("Device"), Sort.device)
self.sortCombo.currentIndexChanged.connect(self.sortComboChanged)
self.sortLabel= self.sortCombo.makeLabel(_("Sort:"))
self.sortOrder = ChevronCombo()
self.sortOrder.addItem(_("Ascending"), Qt.AscendingOrder)
self.sortOrder.addItem(_("Descending"), Qt.DescendingOrder)
self.sortOrder.currentIndexChanged.connect(self.sortOrderChanged)
for widget in (
self.showLabel, self.sortLabel, self.sortCombo, self.showCombo, self.sortOrder):
widget.setFont(font)
self.checkAllLabel = QLabel(_('Select All:'))
# Remove the border when the widget is highlighted
style = """
QCheckBox {
border: none;
outline: none;
spacing: %(spacing)d;
}
""" % dict(spacing=self.standard_spacing // 2)
self.selectAllPhotosCheckbox = QCheckBox(_("Photos") + " ")
self.selectAllVideosCheckbox = QCheckBox(_("Videos"))
self.selectAllPhotosCheckbox.setStyleSheet(style)
self.selectAllVideosCheckbox.setStyleSheet(style)
for widget in (self.checkAllLabel, self.selectAllPhotosCheckbox,
self.selectAllVideosCheckbox):
widget.setFont(font)
self.selectAllPhotosCheckbox.stateChanged.connect(self.selectAllPhotosCheckboxChanged)
self.selectAllVideosCheckbox.stateChanged.connect(self.selectAllVideosCheckboxChanged)
layout.addWidget(self.showLabel)
layout.addWidget(self.showCombo)
layout.addSpacing(QFontMetrics(QFont()).height() * 2)
layout.addWidget(self.sortLabel)
layout.addWidget(self.sortCombo)
layout.addWidget(self.sortOrder)
layout.addStretch()
layout.addWidget(self.checkAllLabel)
layout.addWidget(self.selectAllPhotosCheckbox)
layout.addWidget(self.selectAllVideosCheckbox)
def createCenterPanels(self) -> None:
self.centerSplitter = QSplitter()
self.centerSplitter.setOrientation(Qt.Horizontal)
self.leftPanelSplitter = QSplitter()
self.leftPanelSplitter.setOrientation(Qt.Vertical)
self.rightPanelSplitter = QSplitter()
self.rightPanelSplitter.setOrientation(Qt.Vertical)
self.rightPanels = QStackedWidget()
def configureCenterPanels(self, settings: QSettings) -> None:
self.leftPanelSplitter.addWidget(self.deviceToggleView)
self.leftPanelSplitter.addWidget(self.thisComputerToggleView)
self.leftPanelSplitter.addWidget(self.temporalProximity)
self.rightPanelSplitter.addWidget(self.photoDestinationContainer)
self.rightPanelSplitter.addWidget(self.videoDestination)
self.leftPanelSplitter.setCollapsible(0, False)
self.leftPanelSplitter.setCollapsible(1, False)
self.leftPanelSplitter.setCollapsible(2, False)
self.leftPanelSplitter.setStretchFactor(0, 0)
self.leftPanelSplitter.setStretchFactor(1, 1)
self.leftPanelSplitter.setStretchFactor(2, 1)
self.rightPanels.addWidget(self.rightPanelSplitter)
self.rightPanels.addWidget(self.renamePanel)
self.rightPanels.addWidget(self.jobCodePanel)
self.rightPanels.addWidget(self.backupPanel)
self.centerSplitter.addWidget(self.leftPanelSplitter)
self.centerSplitter.addWidget(self.thumbnailView)
self.centerSplitter.addWidget(self.rightPanels)
self.centerSplitter.setStretchFactor(0, 0)
self.centerSplitter.setStretchFactor(1, 2)
self.centerSplitter.setStretchFactor(2, 0)
self.centerSplitter.setCollapsible(0, False)
self.centerSplitter.setCollapsible(1, False)
self.centerSplitter.setCollapsible(2, False)
self.rightPanelSplitter.setCollapsible(0, False)
self.rightPanelSplitter.setCollapsible(1, False)
splitterSetting = settings.value("centerSplitterSizes")
if splitterSetting is not None:
self.centerSplitter.restoreState(splitterSetting)
else:
self.centerSplitter.setSizes([200, 400, 200])
splitterSetting = settings.value("leftPanelSplitterSizes")
if splitterSetting is not None:
self.leftPanelSplitter.restoreState(splitterSetting)
else:
self.leftPanelSplitter.setSizes([200, 200, 400])
splitterSetting = settings.value("rightPanelSplitterSizes")
if splitterSetting is not None:
self.rightPanelSplitter.restoreState(splitterSetting)
else:
self.rightPanelSplitter.setSizes([200,200])
def setDownloadCapabilities(self) -> bool:
"""
Update the destination displays and download button
:return: True if download destinations are capable of having
all marked files downloaded to them
"""
marked_summary = self.thumbnailModel.getMarkedSummary()
if self.prefs.backup_files:
downloading_to = self.backup_devices.get_download_backup_device_overlap(
photo_download_folder=self.prefs.photo_download_folder,
video_download_folder=self.prefs.video_download_folder
)
self.backupPanel.setDownloadingTo(downloading_to=downloading_to)
backups_good = self.updateBackupView(marked_summary=marked_summary)
else:
backups_good = True
downloading_to = defaultdict(set)
destinations_good = self.updateDestinationViews(
marked_summary=marked_summary, downloading_to=downloading_to
)
download_good = destinations_good and backups_good
self.setDownloadActionState(download_good)
self.destinationButton.setHighlighted(not destinations_good)
self.backupButton.setHighlighted(not backups_good)
return download_good
def updateDestinationViews(self,
marked_summary: MarkedSummary,
downloading_to: Optional[DefaultDict[int, Set[FileType]]]=None) -> bool:
"""
Updates the the header bar and storage space view for the
photo and video download destinations.
:return True if destinations required for the download exist,
and there is sufficient space on them, else False.
"""
size_photos_marked = marked_summary.size_photos_marked
size_videos_marked = marked_summary.size_videos_marked
marked = marked_summary.marked
if self.unity_progress:
available = self.thumbnailModel.getNoFilesMarkedForDownload()
for launcher in self.desktop_launchers:
if available:
launcher.set_property("count", available)
launcher.set_property("count_visible", True)
else:
launcher.set_property("count_visible", False)
destinations_good = True
# Assume that invalid destination folders have already been reset to ''
if self.prefs.photo_download_folder and self.prefs.video_download_folder:
same_dev = same_device(self.prefs.photo_download_folder,
self.prefs.video_download_folder)
else:
same_dev = False
merge = self.downloadIsRunning()
if same_dev:
files_to_display = DisplayingFilesOfType.photos_and_videos
self.combinedDestinationDisplay.downloading_to = downloading_to
self.combinedDestinationDisplay.setDestination(self.prefs.photo_download_folder)
self.combinedDestinationDisplay.setDownloadAttributes(
marked=marked,
photos_size=size_photos_marked,
videos_size=size_videos_marked,
files_to_display=files_to_display,
display_type=DestinationDisplayType.usage_only,
merge=merge
)
display_type = DestinationDisplayType.folder_only
self.combinedDestinationDisplayContainer.setVisible(True)
destinations_good = self.combinedDestinationDisplay.sufficientSpaceAvailable()
else:
files_to_display = DisplayingFilesOfType.photos
display_type = DestinationDisplayType.folders_and_usage
self.combinedDestinationDisplayContainer.setVisible(False)
if self.prefs.photo_download_folder:
self.photoDestinationDisplay.downloading_to = downloading_to
self.photoDestinationDisplay.setDownloadAttributes(
marked=marked,
photos_size=size_photos_marked,
videos_size=0,
files_to_display=files_to_display,
display_type=display_type,
merge=merge
)
self.photoDestinationWidget.setViewVisible(True)
if display_type == DestinationDisplayType.folders_and_usage:
destinations_good = self.photoDestinationDisplay.sufficientSpaceAvailable()
else:
# Photo download folder was invalid or simply not yet set
self.photoDestinationWidget.setViewVisible(False)
if size_photos_marked:
destinations_good = False
if not same_dev:
files_to_display = DisplayingFilesOfType.videos
if self.prefs.video_download_folder:
self.videoDestinationDisplay.downloading_to = downloading_to
self.videoDestinationDisplay.setDownloadAttributes(
marked=marked,
photos_size=0,
videos_size=size_videos_marked,
files_to_display=files_to_display,
display_type=display_type,
merge=merge
)
self.videoDestinationWidget.setViewVisible(True)
if display_type == DestinationDisplayType.folders_and_usage:
destinations_good = (
self.videoDestinationDisplay.sufficientSpaceAvailable() and destinations_good
)
else:
# Video download folder was invalid or simply not yet set
self.videoDestinationWidget.setViewVisible(False)
if size_videos_marked:
destinations_good = False
return destinations_good
@pyqtSlot()
def updateThumbnailModelAfterProximityChange(self) -> None:
"""
Respond to the user selecting / deslecting temporal proximity
cells
"""
self.thumbnailModel.updateAllDeviceDisplayCheckMarks()
self.thumbnailModel.updateSelectionAfterProximityChange()
self.thumbnailModel.resetHighlighting()
def updateBackupView(self, marked_summary: MarkedSummary) -> bool:
merge = self.downloadIsRunning()
self.backupPanel.setDownloadAttributes(
marked=marked_summary.marked,
photos_size=marked_summary.size_photos_marked,
videos_size=marked_summary.size_videos_marked,
merge=merge
)
return self.backupPanel.sufficientSpaceAvailable()
def setDownloadActionState(self, download_destinations_good: bool) -> None:
"""
Sets sensitivity of Download action to enable or disable it.
Affects download button and menu item.
:param download_destinations_good: whether the download destinations
are valid and contain sufficient space for the download to proceed
"""
if not self.downloadIsRunning():
files_marked = False
# Don't enable starting a download while devices are being scanned
if len(self.devices.scanning) == 0:
files_marked = self.thumbnailModel.filesAreMarkedForDownload()
enabled = files_marked and download_destinations_good
self.downloadAct.setEnabled(enabled)
self.downloadButton.setEnabled(enabled)
if files_marked:
marked = self.thumbnailModel.getNoFilesAndTypesMarkedForDownload()
files = marked.file_types_present_details()
text = _("Download %(files)s") % dict(files=files) # type: str
self.downloadButton.setText(text)
else:
self.downloadButton.setText(self.downloadAct.text())
else:
self.downloadAct.setEnabled(True)
self.downloadButton.setEnabled(True)
def setDownloadActionLabel(self) -> None:
"""
Sets download action and download button text to correct value, depending on
whether a download is occurring or not, including whether it is paused
"""
if self.devices.downloading:
if self.download_paused:
text = _("Resume Download")
else:
text = _("Pause")
else:
text = _("Download")
self.downloadAct.setText(text)
self.downloadButton.setText(text)
def createMenus(self) -> None:
self.menu = QMenu()
self.menu.addAction(self.downloadAct)
self.menu.addAction(self.preferencesAct)
self.menu.addSeparator()
self.menu.addAction(self.errorLogAct)
self.menu.addAction(self.clearDownloadsAct)
self.menu.addSeparator()
self.menu.addAction(self.helpAct)
self.menu.addAction(self.didYouKnowAct)
if not disable_version_check:
self.menu.addAction(self.newVersionAct)
self.menu.addAction(self.reportProblemAct)
self.menu.addAction(self.makeDonationAct)
self.menu.addAction(self.translateApplicationAct)
self.menu.addAction(self.aboutAct)
self.menu.addAction(self.quitAct)
self.menuButton = MenuButton(icon=QIcon(':/menu.svg'), menu=self.menu)
def doCheckForNewVersion(self) -> None:
"""Check online for a new program version"""
if not disable_version_check:
self.newVersionCheckDialog.reset()
self.newVersionCheckDialog.show()
self.checkForNewVersionRequest.emit()
def doSourceAction(self) -> None:
self.sourceButton.animateClick()
def doDownloadAction(self) -> None:
self.downloadButton.animateClick()
def doRefreshAction(self) -> None:
pass
def doPreferencesAction(self) -> None:
self.scan_all_again = self.scan_non_camera_devices_again = False
self.search_for_devices_again = False
dialog = PreferencesDialog(prefs=self.prefs, parent=self)
dialog.exec()
self.prefs.sync()
if self.scan_all_again or self.scan_non_camera_devices_again:
self.rescanDevicesAndComputer(
ignore_cameras=not self.scan_all_again,
rescan_path=self.scan_all_again
)
if self.search_for_devices_again:
# Update the list of valid mounts
logging.debug(
"Updating the list of valid mounts after preference change to only_external_mounts"
)
self.validMounts = ValidMounts(onlyExternalMounts=self.prefs.only_external_mounts)
self.searchForDevicesAgain()
# Just to be extra safe, reset these values to their 'off' state:
self.scan_all_again = self.scan_non_camera_devices_again = False
self.search_for_devices_again = False
def doErrorLogAction(self) -> None:
self.errorLog.setVisible(self.errorLogAct.isChecked())
def doClearDownloadsAction(self):
self.thumbnailModel.clearCompletedDownloads()
def doHelpAction(self) -> None:
webbrowser.open_new_tab("http://www.damonlynch.net/rapid/help.html")
def doDidYouKnowAction(self) -> None:
try:
self.tip.activate()
except AttributeError:
self.tip = didyouknow.DidYouKnowDialog(self.prefs, self)
self.tip.activate()
def makeProblemReportDialog(self, header: str, title: Optional[str]=None) -> None:
log_path, log_file = os.path.split(iplogging.full_log_file_path())
log_uri = pathname2url(log_path)
body = _(
r"""Please report the problem at <a href="{website}">{website}</a>.<br><br>
Attach the log file <i>{log_file}</i> to your report (click
<a href="{log_path}">here</a> to open the log directory).
"""
).format(
website='https://bugs.launchpad.net/rapid', log_path=log_uri, log_file=log_file
)
message = '{header}<br><br>{body}'.format(header=header, body=body)
errorbox = self.standardMessageBox(message=message, rich_text=True, title=title)
errorbox.exec_()
def doReportProblemAction(self) -> None:
header = _('Thank you for reporting a problem in Rapid Photo Downloader')
header = '<b>{}</b>'.format(header)
self.makeProblemReportDialog(header)
def doMakeDonationAction(self) -> None:
webbrowser.open_new_tab("http://www.damonlynch.net/rapid/donate.html")
def doTranslateApplicationAction(self) -> None:
webbrowser.open_new_tab("http://www.damonlynch.net/rapid/translate.html")
def doAboutAction(self) -> None:
about = AboutDialog(self)
about.exec()
def standardMessageBox(self, message: str,
rich_text: bool,
title: Optional[str]=None) -> QMessageBox:
"""
Create a standard messagebox to be displayed to the user
:param message: the text to display
:param rich_text: whether it text to display is in HTML format
:param title: optional title for message box, else defaults to
localized 'Rapid Photo Downloader'
:return: the message box
"""
msgBox = QMessageBox()
icon = QIcon(':/rapid-photo-downloader.svg').pixmap(standardIconSize())
if title is None:
title = _("Rapid Photo Downloader")
if rich_text:
msgBox.setTextFormat(Qt.RichText)
msgBox.setIconPixmap(icon)
msgBox.setWindowTitle(title)
msgBox.setText(message)
return msgBox
@pyqtSlot(bool)
def thisComputerToggleValueChanged(self, on: bool) -> None:
"""
Respond to This Computer Toggle Switch
:param on: whether switch is on or off
"""
if on:
self.thisComputer.setViewVisible(bool(self.prefs.this_computer_path))
self.prefs.this_computer_source = on
if not on:
if len(self.devices.this_computer) > 0:
scan_id = list(self.devices.this_computer)[0]
self.removeDevice(scan_id=scan_id)
self.prefs.this_computer_path = ''
self.thisComputerFSView.clearSelection()
self.adjustLeftPanelSliderHandles()
@pyqtSlot(bool)
def deviceToggleViewValueChange(self, on: bool) -> None:
"""
Respond to Devices Toggle Switch
:param on: whether switch is on or off
"""
self.prefs.device_autodetection = on
if not on:
for scan_id in list(self.devices.volumes_and_cameras):
self.removeDevice(scan_id=scan_id, adjust_temporal_proximity=False)
state = self.proximityStatePostDeviceRemoval()
if state == TemporalProximityState.empty:
self.temporalProximity.setState(TemporalProximityState.empty)
else:
self.generateTemporalProximityTableData("devices were removed as a download source")
else:
# This is a real hack -- but I don't know a better way to let the
# slider redraw itself
QTimer.singleShot(100, self.devicesViewToggledOn)
self.adjustLeftPanelSliderHandles()
def proximityStatePostDeviceRemoval(self) -> TemporalProximityState:
"""
:return: set correct proximity state after a device is removed
"""
# ignore devices that are scanning - we don't care about them, because the scan
# could take a long time, especially with phones
if len(self.devices) - len(self.devices.scanning) > 0:
# Other already scanned devices are present
return TemporalProximityState.regenerate
else:
return TemporalProximityState.empty
@pyqtSlot()
def devicesViewToggledOn(self) -> None:
self.searchForCameras()
self.setupNonCameraDevices()
@pyqtSlot(QModelIndex)
def thisComputerPathChosen(self, index: QModelIndex) -> None:
"""
Handle user selecting new device location path.
Called after single click or folder being activated.
:param index: cell clicked
"""
path = self.fileSystemModel.filePath(index.model().mapToSource(index))
if self.downloadIsRunning() and self.prefs.this_computer_path:
message = _(
"<b>Changing This Computer source path</b><br><br>Do you really want to "
"change the source path to %(new_path)s?<br><br>You are currently "
"downloading from %(source_path)s.<br><br>"
"If you do change the path, the current download from This Computer "
"will be cancelled."
) % dict(
new_path=make_html_path_non_breaking(path),
source_path=make_html_path_non_breaking(self.prefs.this_computer_path)
)
msgbox = self.standardMessageBox(message=message, rich_text=True)
msgbox.setIcon(QMessageBox.Question)
msgbox.setStandardButtons(QMessageBox.Yes|QMessageBox.No)
if msgbox.exec() == QMessageBox.No:
self.thisComputerFSView.goToPath(self.prefs.this_computer_path)
return
if path != self.prefs.this_computer_path:
if self.prefs.this_computer_path:
scan_id = self.devices.scan_id_from_path(
self.prefs.this_computer_path, DeviceType.path
)
if scan_id is not None:
logging.debug(
"Removing path from device view %s", self.prefs.this_computer_path
)
self.removeDevice(scan_id=scan_id)
self.prefs.this_computer_path = path
self.thisComputer.setViewVisible(True)
self.setupManualPath()
@pyqtSlot(QModelIndex)
def photoDestinationPathChosen(self, index: QModelIndex) -> None:
"""
Handle user setting new photo download location
Called after single click or folder being activated.
:param index: cell clicked
"""
path = self.fileSystemModel.filePath(index.model().mapToSource(index))
if not self.checkChosenDownloadDestination(path, FileType.photo):
return
if validate_download_folder(path).valid:
if path != self.prefs.photo_download_folder:
self.prefs.photo_download_folder = path
self.watchedDownloadDirs.updateWatchPathsFromPrefs(self.prefs)
self.folder_preview_manager.change_destination()
self.photoDestinationDisplay.setDestination(path=path)
self.setDownloadCapabilities()
else:
logging.error("Invalid photo download destination chosen: %s", path)
self.handleInvalidDownloadDestination(file_type=FileType.photo)
def checkChosenDownloadDestination(self, path: str, file_type: FileType) -> bool:
"""
Check the path the user has chosen to ensure it's not a provisional
download subfolder. If it is a download subfolder that already existed,
confirm with the user that they did in fact want to use that destination.
:param path: path chosen
:param file_type: whether for photos or videos
:return: False if the path is problematic and should be ignored, else True
"""
problematic = self.downloadIsRunning()
if problematic:
message = _("You cannot change the download destination while downloading.")
msgbox = self.standardMessageBox(message=message, rich_text=False)
msgbox.setIcon(QMessageBox.Warning)
msgbox.exec()
else:
problematic = path in self.fileSystemModel.preview_subfolders
if not problematic and path in self.fileSystemModel.download_subfolders:
message = _(
"<b>Confirm Download Destination</b><br><br>Are you sure you want to set "
"the %(file_type)s download destination to %(path)s?"
) % dict(
file_type=file_type.name, path=make_html_path_non_breaking(path)
)
msgbox = self.standardMessageBox(message=message, rich_text=True)
msgbox.setStandardButtons(QMessageBox.Yes|QMessageBox.No)
msgbox.setIcon(QMessageBox.Question)
problematic = msgbox.exec() == QMessageBox.No
if problematic:
if file_type == FileType.photo and self.prefs.photo_download_folder:
self.photoDestinationFSView.goToPath(self.prefs.photo_download_folder)
elif file_type == FileType.video and self.prefs.video_download_folder:
self.videoDestinationFSView.goToPath(self.prefs.video_download_folder)
return False
return True
def handleInvalidDownloadDestination(self, file_type: FileType, do_update: bool=True) -> None:
"""
Handle cases where user clicked on an invalid download directory,
or the directory simply having disappeared
:param file_type: type of destination to work on
:param do_update: if True, update watched folders, provisional
download folders and update the UI to reflect new download
capabilities
"""
if file_type == FileType.photo:
self.prefs.photo_download_folder = ''
self.photoDestinationWidget.setViewVisible(False)
else:
self.prefs.video_download_folder = ''
self.videoDestinationWidget.setViewVisible(False)
if do_update:
self.watchedDownloadDirs.updateWatchPathsFromPrefs(self.prefs)
self.folder_preview_manager.change_destination()
self.setDownloadCapabilities()
@pyqtSlot(QModelIndex)
def videoDestinationPathChosen(self, index: QModelIndex) -> None:
"""
Handle user setting new video download location
Called after single click or folder being activated.
:param index: cell clicked
"""
path = self.fileSystemModel.filePath(index.model().mapToSource(index))
if not self.checkChosenDownloadDestination(path, FileType.video):
return
if validate_download_folder(path).valid:
if path != self.prefs.video_download_folder:
self.prefs.video_download_folder = path
self.watchedDownloadDirs.updateWatchPathsFromPrefs(self.prefs)
self.folder_preview_manager.change_destination()
self.videoDestinationDisplay.setDestination(path=path)
self.setDownloadCapabilities()
else:
logging.error("Invalid video download destination chosen: %s", path)
self.handleInvalidDownloadDestination(file_type=FileType.video)
@pyqtSlot()
def downloadButtonClicked(self) -> None:
if self.download_paused:
logging.debug("Download resumed")
self.resumeDownload()
else:
if self.downloadIsRunning():
self.pauseDownload()
else:
start_download = True
if self.prefs.warn_downloading_all and \
self.thumbnailModel.anyCheckedFilesFiltered():
message = _(
"""
<b>Downloading all files</b><br><br>
A download always includes all files that are checked for download,
including those that are not currently displayed because the Timeline
is being used or because only new files are being shown.<br><br>
Do you want to proceed with the download?
"""
)
warning = RememberThisDialog(
message=message,
icon=':/rapid-photo-downloader.svg',
remember=RememberThisMessage.do_not_ask_again,
parent=self
)
start_download = warning.exec_()
if warning.remember:
self.prefs.warn_downloading_all = False
if start_download:
logging.debug("Download activated")
if self.jobCodePanel.needToPromptForJobCode():
if self.jobCodePanel.getJobCodeBeforeDownload():
self.startDownload()
else:
self.startDownload()
def pauseDownload(self) -> None:
"""
Pause the copy files processes
"""
self.dl_update_timer.stop()
self.download_paused = True
self.sendPauseToThread(self.copy_controller)
self.setDownloadActionLabel()
self.time_check.pause()
self.displayMessageInStatusBar()
def resumeDownload(self) -> None:
"""
Resume a download after it has been paused, and start
downloading from any queued auto-start downloads
"""
for scan_id in self.devices.downloading:
self.time_remaining.set_time_mark(scan_id)
self.time_check.set_download_mark()
self.sendResumeToThread(self.copy_controller)
self.download_paused = False
self.dl_update_timer.start()
self.download_start_time = time.time()
self.setDownloadActionLabel()
self.immediatelyDisplayDownloadRunningInStatusBar()
for scan_id in self.devices.queued_to_download:
self.startDownload(scan_id=scan_id)
self.devices.queued_to_download = set() # type: Set[int]
def downloadIsRunning(self) -> bool:
"""
:return True if a file is currently being downloaded, renamed
or backed up, else False
"""
if not self.devices.downloading:
if self.prefs.backup_files:
return not self.download_tracker.all_files_backed_up()
else:
return False
else:
return True
def startDownload(self, scan_id: int=None) -> None:
"""
Start download, renaming and backup of files.
:param scan_id: if specified, only files matching it will be
downloaded
"""
logging.debug("Start Download phase 1 has started")
if self.prefs.backup_files:
self.initializeBackupThumbCache()
self.download_files = self.thumbnailModel.getFilesMarkedForDownload(scan_id)
# model, port
camera_unmounts_called = set() # type: Set[Tuple(str, str)]
stop_thumbnailing_cmd_issued = False
stop_thumbnailing = [scan_id for scan_id in self.download_files.camera_access_needed
if scan_id in self.devices.thumbnailing]
for scan_id in stop_thumbnailing:
device = self.devices[scan_id]
if not scan_id in self.thumbnailModel.generating_thumbnails:
logging.debug(
"Not terminating thumbnailing of %s because it's not in the thumbnail manager",
device.display_name
)
else:
logging.debug(
"Terminating thumbnailing for %s because a download is starting",
device.display_name
)
self.thumbnailModel.terminateThumbnailGeneration(scan_id)
self.devices.cameras_to_stop_thumbnailing.add(scan_id)
stop_thumbnailing_cmd_issued = True
if self.gvfsControlsMounts:
mount_points = {}
# If a device was being thumbnailed, then it wasn't mounted by GVFS
# Therefore filter out the cameras we've already requested their
# thumbnailing be stopped
still_to_check = [
scan_id for scan_id in self.download_files.camera_access_needed
if scan_id not in stop_thumbnailing
]
for scan_id in still_to_check:
# This next value is likely *always* True, but check nonetheless
if self.download_files.camera_access_needed[scan_id]:
device = self.devices[scan_id]
model = device.camera_model
port = device.camera_port
mount_point = self.gvolumeMonitor.ptpCameraMountPoint(model, port)
if mount_point is not None:
self.devices.cameras_to_gvfs_unmount_for_download.add(scan_id)
camera_unmounts_called.add((model, port))
mount_points[(model, port)] = mount_point
if len(camera_unmounts_called):
logging.info(
"%s camera(s) need to be unmounted by GVFS before the download begins",
len(camera_unmounts_called)
)
for model, port in camera_unmounts_called:
self.gvolumeMonitor.unmountCamera(
model, port, download_starting=True, mount_point=mount_points[(model, port)]
)
if not camera_unmounts_called and not stop_thumbnailing_cmd_issued:
self.startDownloadPhase2()
def startDownloadPhase2(self) -> None:
logging.debug("Start Download phase 2 has started")
download_files = self.download_files
invalid_dirs = self.invalidDownloadFolders(download_files.download_types)
if invalid_dirs:
if len(invalid_dirs) > 1:
msg = _(
"These download folders are invalid:\n%(folder1)s\n%(folder2)s"
) % {'folder1': invalid_dirs[0], 'folder2': invalid_dirs[1]}
else:
msg = _("This download folder is invalid:\n%s") % invalid_dirs[0]
msgBox = QMessageBox(self)
msgBox.setIcon(QMessageBox.Critical)
msgBox.setWindowTitle(_("Download Failure"))
msgBox.setText(_("The download cannot proceed."))
msgBox.setInformativeText(msg)
msgBox.exec()
else:
missing_destinations = self.backup_devices.backup_destinations_missing(
download_files.download_types
)
if missing_destinations is not None:
# Warn user that they have specified that they want to
# backup a file type, but no such folder exists on backup
# devices
if self.prefs.backup_device_autodetection:
if missing_destinations == BackupFailureType.photos_and_videos:
logging.warning(
"Photos and videos will not be backed up because there "
"is nowhere to back them up"
)
msg = _(
"Photos and videos will not be backed up because there is nowhere "
"to back them up. Do you still want to start the download?"
)
elif missing_destinations == BackupFailureType.photos:
logging.warning("No backup device exists for backing up photos")
# Translators: filetype will be replaced with 'photos' or 'videos'
msg = _(
"No backup device exists for backing up %(filetype)s. Do you "
"still want to start the download?"
) % {'filetype': _('photos')}
else:
logging.warning(
"No backup device contains a valid folder for backing up videos"
)
# Translators: filetype will be replaced with 'photos' or 'videos'
msg = _(
"No backup device exists for backing up %(filetype)s. Do you "
"still want to start the download?"
) % {'filetype': _('videos')}
else:
if missing_destinations == BackupFailureType.photos_and_videos:
logging.warning(
"The manually specified photo and videos backup paths do "
"not exist or are not writable"
)
msg = _(
"<b>The photo and video backup destinations do not exist or cannot "
"be written to.</b><br><br>Do you still want to start the download?"
)
elif missing_destinations == BackupFailureType.photos:
logging.warning(
"The manually specified photo backup path does not exist "
"or is not writable"
)
# Translators: filetype will be replaced by either 'photo' or 'video'
msg = _(
"<b>The %(filetype)s backup destination does not exist or cannot be "
"written to.</b><br><br>Do you still want to start the download?"
) % {'filetype': _('photo')}
else:
logging.warning(
"The manually specified video backup path does not exist "
"or is not writable"
)
msg = _(
"<b>The %(filetype)s backup destination does not exist or cannot be "
"written to.</b><br><br>Do you still want to start the download?"
) % {'filetype': _('video')}
if self.prefs.warn_backup_problem:
warning = RememberThisDialog(
message=msg,
icon=':/rapid-photo-downloader.svg',
remember=RememberThisMessage.do_not_ask_again,
parent=self,
title=_("Backup problem")
)
do_download = warning.exec()
if warning.remember:
self.prefs.warn_backup_problem = False
if not do_download:
return
# Suppress showing a notification message about any timeline
# and provisional folders rebuild - download takes priority
self.ctime_notification_issued = False
# Set time download is starting if it is not already set
# it is unset when all downloads are completed
# It is used in file renaming
if self.download_start_datetime is None:
self.download_start_datetime = datetime.datetime.now()
# The download start time (not datetime) is used to determine
# when to show the time remaining and download speed in the status bar
if self.download_start_time is None:
self.download_start_time = time.time()
# Set status to download pending
self.thumbnailModel.markDownloadPending(download_files.files)
# disable refresh and the changing of various preferences while
# the download is occurring
self.enablePrefsAndRefresh(enabled=False)
# notify renameandmovefile process to read any necessary values
# from the program preferences
data = RenameAndMoveFileData(message=RenameAndMoveStatus.download_started)
self.sendDataMessageToThread(self.rename_controller, data=data)
# notify backup processes to reset their problem reports
self.sendBackupStartFinishMessageToWorkers(BackupStatus.backup_started)
# Maximum value of progress bar may have been set to the number
# of thumbnails being generated. Reset it to use a percentage.
self.downloadProgressBar.setMaximum(100)
for scan_id in download_files.files:
files = download_files.files[scan_id]
# if generating thumbnails for this scan_id, stop it
if self.thumbnailModel.terminateThumbnailGeneration(scan_id):
generate_thumbnails = self.thumbnailModel.markThumbnailsNeeded(files)
else:
generate_thumbnails = False
self.downloadFiles(
files=files,
scan_id=scan_id,
download_stats=download_files.download_stats[scan_id],
generate_thumbnails=generate_thumbnails
)
self.setDownloadActionLabel()
def downloadFiles(self, files: List[RPDFile],
scan_id: int,
download_stats: DownloadStats,
generate_thumbnails: bool) -> None:
"""
:param files: list of the files to download
:param scan_id: the device from which to download the files
:param download_stats: count of files and their size
:param generate_thumbnails: whether thumbnails must be
generated in the copy files process.
"""
model = self.mapModel(scan_id)
model.setSpinnerState(scan_id, DeviceState.downloading)
if download_stats.no_photos > 0:
photo_download_folder = self.prefs.photo_download_folder
else:
photo_download_folder = None
if download_stats.no_videos > 0:
video_download_folder = self.prefs.video_download_folder
else:
video_download_folder = None
self.download_tracker.init_stats(scan_id=scan_id, stats=download_stats)
download_size = download_stats.photos_size_in_bytes + \
download_stats.videos_size_in_bytes
if self.prefs.backup_files:
download_size += (
(
len(self.backup_devices.photo_backup_devices) *
download_stats.photos_size_in_bytes
) + (
len(self.backup_devices.video_backup_devices) *
download_stats.videos_size_in_bytes
)
)
self.time_remaining[scan_id] = download_size
self.time_check.set_download_mark()
self.devices.set_device_state(scan_id, DeviceState.downloading)
self.updateProgressBarState()
self.immediatelyDisplayDownloadRunningInStatusBar()
self.setDownloadActionState(True)
if not self.dl_update_timer.isActive():
self.dl_update_timer.start()
if self.autoStart(scan_id) and self.prefs.generate_thumbnails:
for rpd_file in files:
rpd_file.generate_thumbnail = True
generate_thumbnails = True
verify_file = self.prefs.verify_file
# Initiate copy files process
device = self.devices[scan_id]
copyfiles_args = CopyFilesArguments(
scan_id=scan_id,
device=device,
photo_download_folder=photo_download_folder,
video_download_folder=video_download_folder,
files=files,
verify_file=verify_file,
generate_thumbnails=generate_thumbnails,
log_gphoto2=self.log_gphoto2
)
self.sendStartWorkerToThread(self.copy_controller, worker_id=scan_id, data=copyfiles_args)
@pyqtSlot(int, str, str)
def tempDirsReceivedFromCopyFiles(self, scan_id: int,
photo_temp_dir: str,
video_temp_dir: str) -> None:
self.fileSystemFilter.setTempDirs([photo_temp_dir, video_temp_dir])
self.temp_dirs_by_scan_id[scan_id] = list(
filter(None,[photo_temp_dir, video_temp_dir])
)
def cleanAllTempDirs(self):
"""
Deletes temporary files and folders used in all downloads.
"""
if self.temp_dirs_by_scan_id:
logging.debug("Cleaning temporary directories")
for scan_id in self.temp_dirs_by_scan_id:
self.cleanTempDirsForScanId(scan_id, remove_entry=False)
self.temp_dirs_by_scan_id = {}
def cleanTempDirsForScanId(self, scan_id: int, remove_entry: bool=True):
"""
Deletes temporary files and folders used in download.
:param scan_id: the scan id associated with the temporary
directory
:param remove_entry: if True, remove the scan_id from the
dictionary tracking temporary directories
"""
home_dir = os.path.expanduser("~")
for d in self.temp_dirs_by_scan_id[scan_id]:
assert d != home_dir
if os.path.isdir(d):
try:
shutil.rmtree(d, ignore_errors=True)
except:
logging.error("Unknown error deleting temporary directory %s", d)
if remove_entry:
del self.temp_dirs_by_scan_id[scan_id]
@pyqtSlot(bool, RPDFile, int, 'PyQt_PyObject')
def copyfilesDownloaded(self, download_succeeded: bool,
rpd_file: RPDFile,
download_count: int,
mdata_exceptions: Optional[Tuple[Exception]]) -> None:
scan_id = rpd_file.scan_id
if scan_id not in self.devices:
logging.debug(
"Ignoring file %s because its device has been removed", rpd_file.full_file_name
)
return
self.download_tracker.set_download_count_for_file(rpd_file.uid, download_count)
self.download_tracker.set_download_count(scan_id, download_count)
rpd_file.download_start_time = self.download_start_datetime
if rpd_file.file_type == FileType.photo:
rpd_file.generate_extension_case = self.prefs.photo_extension
else:
rpd_file.generate_extension_case = self.prefs.video_extension
if mdata_exceptions is not None and self.prefs.warn_fs_metadata_error:
self.copy_metadata_errors.add_problem(
worker_id=scan_id, path=rpd_file.temp_full_file_name,
mdata_exceptions=mdata_exceptions
)
self.sendDataMessageToThread(
self.rename_controller,
data=RenameAndMoveFileData(rpd_file=rpd_file,
download_count=download_count,
download_succeeded=download_succeeded)
)
@pyqtSlot(int, 'PyQt_PyObject', 'PyQt_PyObject')
def copyfilesBytesDownloaded(self, scan_id: int,
total_downloaded: int,
chunk_downloaded: int) -> None:
"""
Update the tracking and display of how many bytes have been
downloaded / copied.
"""
if scan_id not in self.devices:
return
try:
assert total_downloaded >= 0
assert chunk_downloaded >= 0
except AssertionError:
logging.critical("Unexpected negative values for total / chunk downloaded: %s %s ",
total_downloaded, chunk_downloaded)
self.download_tracker.set_total_bytes_copied(scan_id, total_downloaded)
if len(self.devices.have_downloaded_from) > 1:
model = self.mapModel(scan_id)
model.percent_complete[scan_id] = self.download_tracker.get_percent_complete(scan_id)
self.time_check.increment(bytes_downloaded=chunk_downloaded)
self.time_remaining.update(scan_id, bytes_downloaded=chunk_downloaded)
self.updateFileDownloadDeviceProgress()
@pyqtSlot(int, 'PyQt_PyObject')
def copyfilesProblems(self, scan_id: int, problems: CopyingProblems) -> None:
for problem in self.copy_metadata_errors.problems(worker_id=scan_id):
problems.append(problem)
if problems:
device = self.devices[scan_id]
problems.name = device.display_name
problems.uri=device.uri
self.addErrorLogMessage(problems=problems)
@pyqtSlot(int)
def copyfilesFinished(self, scan_id: int) -> None:
if scan_id in self.devices:
logging.debug("All files finished copying for %s", self.devices[scan_id].display_name)
@pyqtSlot(bool, RPDFile, int)
def fileRenamedAndMoved(self, move_succeeded: bool,
rpd_file: RPDFile,
download_count: int) -> None:
"""
Called after a file has been renamed -- that is, moved from the
temp dir it was downloaded into, and renamed using the file
renaming rules
"""
scan_id = rpd_file.scan_id
if scan_id not in self.devices:
logging.debug(
"Ignoring file %s because its device has been removed",
rpd_file.download_full_file_name or rpd_file.full_file_name
)
return
if rpd_file.mdatatime_caused_ctime_change and scan_id not in \
self.thumbnailModel.ctimes_differ:
self.thumbnailModel.addCtimeDisparity(rpd_file=rpd_file)
if self.thumbnailModel.sendToDaemonThumbnailer(rpd_file=rpd_file):
if rpd_file.status in constants.Downloaded:
logging.debug(
"Assigning daemon thumbnailer to work on %s", rpd_file.download_full_file_name
)
self.sendDataMessageToThread(
self.thumbnail_deamon_controller,
data=ThumbnailDaemonData(
rpd_file=rpd_file,
write_fdo_thumbnail=self.prefs.save_fdo_thumbnails,
use_thumbnail_cache=self.prefs.use_thumbnail_cache
)
)
else:
logging.debug(
'%s was not downloaded, so adjusting download tracking', rpd_file.full_file_name
)
self.download_tracker.thumbnail_generated_post_download(scan_id)
if rpd_file.status in constants.Downloaded and \
self.fileSystemModel.add_subfolder_downloaded_into(
path=rpd_file.download_path, download_folder=rpd_file.download_folder):
if rpd_file.file_type == FileType.photo:
self.photoDestinationFSView.expandPath(rpd_file.download_path)
self.photoDestinationFSView.update()
else:
self.videoDestinationFSView.expandPath(rpd_file.download_path)
self.videoDestinationFSView.update()
if self.prefs.backup_files:
if self.backup_devices.backup_possible(rpd_file.file_type):
self.backupFile(rpd_file, move_succeeded, download_count)
else:
self.fileDownloadFinished(move_succeeded, rpd_file)
else:
self.fileDownloadFinished(move_succeeded, rpd_file)
@pyqtSlot(RPDFile, QPixmap)
def thumbnailReceivedFromDaemon(self, rpd_file: RPDFile, thumbnail: QPixmap) -> None:
"""
A thumbnail will be received directly from the daemon process when
it was able to get a thumbnail from the FreeDesktop.org 256x256
cache, and there was thus no need write another
:param rpd_file: rpd_file details of the file the thumbnail was
generated for
:param thumbnail: a thumbnail for display in the thumbnail view,
"""
self.thumbnailModel.thumbnailReceived(rpd_file=rpd_file, thumbnail=thumbnail)
def thumbnailGeneratedPostDownload(self, rpd_file: RPDFile) -> None:
"""
Adjust download tracking to note that a thumbnail was generated
after a file was downloaded. Possibly handle situation where
all files have been downloaded.
A thumbnail will be generated post download if
the sole task of the thumbnail extractors was to write out the
FreeDesktop.org thumbnails, and/or if we didn't generate it before
the download started.
:param rpd_file: details of the file
"""
uid = rpd_file.uid
scan_id = rpd_file.scan_id
if self.prefs.backup_files and rpd_file.fdo_thumbnail_128_name:
self.generated_fdo_thumbnails[uid] = rpd_file.fdo_thumbnail_128_name
if uid in self.backup_fdo_thumbnail_cache:
self.sendDataMessageToThread(
self.thumbnail_deamon_controller,
data=ThumbnailDaemonData(
rpd_file=rpd_file,
write_fdo_thumbnail=True,
backup_full_file_names=self.backup_fdo_thumbnail_cache[uid],
fdo_name=rpd_file.fdo_thumbnail_128_name
)
)
del self.backup_fdo_thumbnail_cache[uid]
self.download_tracker.thumbnail_generated_post_download(scan_id=scan_id)
completed, files_remaining = self.isDownloadCompleteForScan(scan_id)
if completed:
self.fileDownloadCompleteFromDevice(scan_id=scan_id, files_remaining=files_remaining)
def thumbnailGenerationStopped(self, scan_id: int) -> None:
"""
Slot for when a the thumbnail worker has been forcefully stopped,
rather than merely finished in its work
:param scan_id: scan_id of the device that was being thumbnailed
"""
if scan_id not in self.devices:
logging.debug(
"Ignoring scan_id %s from terminated thumbailing, as its device does "
"not exist anymore", scan_id
)
else:
device = self.devices[scan_id]
if scan_id in self.devices.cameras_to_stop_thumbnailing:
self.devices.cameras_to_stop_thumbnailing.remove(scan_id)
logging.debug("Thumbnailing successfully terminated for %s", device.display_name)
if not self.devices.download_start_blocked():
self.startDownloadPhase2()
else:
logging.debug(
"Ignoring the termination of thumbnailing from %s, as it's "
"not for a camera from which a download was waiting to be started",
device.display_name
)
@pyqtSlot(int, 'PyQt_PyObject')
def backupFileProblems(self, device_id: int, problems: BackingUpProblems) -> None:
for problem in self.backup_metadata_errors.problems(worker_id=device_id):
problems.append(problem)
if problems:
self.addErrorLogMessage(problems=problems)
def sendBackupStartFinishMessageToWorkers(self, message: BackupStatus) -> None:
if self.prefs.backup_files:
download_types = self.download_files.download_types
for path in self.backup_devices:
backup_type = self.backup_devices[path].backup_type
if (
(
backup_type == BackupLocationType.photos_and_videos or
download_types == DownloadingFileTypes.photos_and_videos
) or backup_type == download_types):
device_id = self.backup_devices.device_id(path)
data = BackupFileData(message=message)
self.sendDataMessageToThread(
self.backup_controller, worker_id=device_id, data=data
)
def backupFile(self, rpd_file: RPDFile, move_succeeded: bool, download_count: int) -> None:
if self.prefs.backup_device_autodetection:
if rpd_file.file_type == FileType.photo:
path_suffix = self.prefs.photo_backup_identifier
else:
path_suffix = self.prefs.video_backup_identifier
else:
path_suffix = None
if rpd_file.file_type == FileType.photo:
logging.debug("Backing up photo %s", rpd_file.download_name)
else:
logging.debug("Backing up video %s", rpd_file.download_name)
for path in self.backup_devices:
backup_type = self.backup_devices[path].backup_type
do_backup = (
(backup_type == BackupLocationType.photos_and_videos) or
(
rpd_file.file_type == FileType.photo and backup_type ==
BackupLocationType.photos
) or (
rpd_file.file_type == FileType.video and backup_type ==
BackupLocationType.videos
)
)
if do_backup:
logging.debug("Backing up to %s", path)
else:
logging.debug("Not backing up to %s", path)
# Even if not going to backup to this device, need to send it
# anyway so progress bar can be updated. Not this most efficient
# but the code is more simpler
# TODO: investigate a more optimal approach!
device_id = self.backup_devices.device_id(path)
data = BackupFileData(
rpd_file=rpd_file,
move_succeeded=move_succeeded,
do_backup=do_backup,
path_suffix=path_suffix,
backup_duplicate_overwrite=self.prefs.backup_duplicate_overwrite,
verify_file=self.prefs.verify_file,
download_count=download_count,
save_fdo_thumbnail=self.prefs.save_fdo_thumbnails
)
self.sendDataMessageToThread(self.backup_controller, worker_id=device_id, data=data)
@pyqtSlot(int, bool, bool, RPDFile, str, 'PyQt_PyObject')
def fileBackedUp(self, device_id: int,
backup_succeeded: bool,
do_backup: bool,
rpd_file: RPDFile,
backup_full_file_name: str,
mdata_exceptions: Optional[Tuple[Exception]]) -> None:
if do_backup:
if self.prefs.generate_thumbnails and self.prefs.save_fdo_thumbnails and \
rpd_file.should_write_fdo() and backup_succeeded:
self.backupGenerateFdoThumbnail(
rpd_file=rpd_file, backup_full_file_name=backup_full_file_name
)
self.download_tracker.file_backed_up(rpd_file.scan_id, rpd_file.uid)
if mdata_exceptions is not None and self.prefs.warn_fs_metadata_error:
self.backup_metadata_errors.add_problem(
worker_id=device_id, path=backup_full_file_name,
mdata_exceptions=mdata_exceptions
)
if self.download_tracker.file_backed_up_to_all_locations(
rpd_file.uid, rpd_file.file_type):
logging.debug(
"File %s will not be backed up to any more locations", rpd_file.download_name
)
self.fileDownloadFinished(backup_succeeded, rpd_file)
@pyqtSlot('PyQt_PyObject', 'PyQt_PyObject')
def backupFileBytesBackedUp(self, scan_id: int, chunk_downloaded: int) -> None:
self.download_tracker.increment_bytes_backed_up(scan_id, chunk_downloaded)
self.time_check.increment(bytes_downloaded=chunk_downloaded)
self.time_remaining.update(scan_id, bytes_downloaded=chunk_downloaded)
self.updateFileDownloadDeviceProgress()
def initializeBackupThumbCache(self) -> None:
"""
Prepare tracking of thumbnail generation for backed up files
"""
# indexed by uid, deque of full backup paths
self.generated_fdo_thumbnails = dict() # type: Dict[str]
self.backup_fdo_thumbnail_cache = defaultdict(list) # type: Dict[List[str]]
def backupGenerateFdoThumbnail(self, rpd_file: RPDFile, backup_full_file_name: str) -> None:
uid = rpd_file.uid
if uid not in self.generated_fdo_thumbnails:
logging.debug(
"Caching FDO thumbnail creation for backup %s", backup_full_file_name
)
self.backup_fdo_thumbnail_cache[uid].append(backup_full_file_name)
else:
# An FDO thumbnail has already been generated for the downloaded file
assert uid not in self.backup_fdo_thumbnail_cache
logging.debug(
"Assigning daemon thumbnailer to create FDO thumbnail for %s", backup_full_file_name
)
self.sendDataMessageToThread(
self.thumbnail_deamon_controller,
data=ThumbnailDaemonData(
rpd_file=rpd_file,
write_fdo_thumbnail=True,
backup_full_file_names=[backup_full_file_name],
fdo_name=self.generated_fdo_thumbnails[uid]
)
)
@pyqtSlot(int, list)
def updateSequences(self, stored_sequence_no: int, downloads_today: List[str]) -> None:
"""
Called at conclusion of a download, with values coming from
renameandmovefile process
"""
self.prefs.stored_sequence_no = stored_sequence_no
self.prefs.downloads_today = downloads_today
self.prefs.sync()
logging.debug("Saved sequence values to preferences")
if self.application_state == ApplicationState.exiting:
self.close()
else:
self.renamePanel.updateSequences(
downloads_today=downloads_today, stored_sequence_no=stored_sequence_no
)
@pyqtSlot()
def fileRenamedAndMovedFinished(self) -> None:
"""Currently not called"""
pass
def isDownloadCompleteForScan(self, scan_id: int) -> Tuple[bool, int]:
"""
Determine if all files have been downloaded and backed up for a device
:param scan_id: device's scan id
:return: True if the download is completed for that scan_id,
and the number of files remaining for the scan_id, BUT
the files remaining value is valid ONLY if the download is
completed
"""
completed = self.download_tracker.all_files_downloaded_by_scan_id(scan_id)
if completed:
logging.debug("All files downloaded for %s", self.devices[scan_id].display_name)
if self.download_tracker.no_post_download_thumb_generation_by_scan_id[scan_id]:
logging.debug(
"Thumbnails generated for %s thus far during download: %s of %s",
self.devices[scan_id].display_name,
self.download_tracker.post_download_thumb_generation[scan_id],
self.download_tracker.no_post_download_thumb_generation_by_scan_id[scan_id]
)
completed = completed and \
self.download_tracker.all_post_download_thumbs_generated_for_scan(scan_id)
if completed and self.prefs.backup_files:
completed = self.download_tracker.all_files_backed_up(scan_id)
if completed:
files_remaining = self.thumbnailModel.getNoFilesRemaining(scan_id)
else:
files_remaining = 0
return completed, files_remaining
def updateFileDownloadDeviceProgress(self):
"""
Updates progress bar and optionally the Unity progress bar
"""
percent_complete = self.download_tracker.get_overall_percent_complete()
self.downloadProgressBar.setValue(round(percent_complete * 100))
if self.unity_progress:
for launcher in self.desktop_launchers:
launcher.set_property('progress', percent_complete)
launcher.set_property('progress_visible', True)
def fileDownloadFinished(self, succeeded: bool, rpd_file: RPDFile) -> None:
"""
Called when a file has been downloaded i.e. copied, renamed,
and backed up
"""
scan_id = rpd_file.scan_id
if self.prefs.move:
# record which files to automatically delete when download
# completes
self.download_tracker.add_to_auto_delete(rpd_file)
self.thumbnailModel.updateStatusPostDownload(rpd_file)
self.download_tracker.file_downloaded_increment(
scan_id, rpd_file.file_type, rpd_file.status
)
device = self.devices[scan_id]
device.download_statuses.add(rpd_file.status)
completed, files_remaining = self.isDownloadCompleteForScan(scan_id)
if completed:
self.fileDownloadCompleteFromDevice(scan_id=scan_id, files_remaining=files_remaining)
def fileDownloadCompleteFromDevice(self, scan_id: int, files_remaining: int) -> None:
device = self.devices[scan_id]
device_finished = files_remaining == 0
if device_finished:
logging.debug("All files from %s are downloaded; none remain", device.display_name)
state = DeviceState.finished
else:
logging.debug(
"Download finished from %s; %s remain be be potentially downloaded",
device.display_name, files_remaining
)
state = DeviceState.idle
self.devices.set_device_state(scan_id=scan_id, state=state)
self.mapModel(scan_id).setSpinnerState(scan_id, state)
# Rebuild temporal proximity if it needs it
if scan_id in self.thumbnailModel.ctimes_differ and not \
self.thumbnailModel.filesRemainToDownload(scan_id=scan_id):
self.thumbnailModel.processCtimeDisparity(scan_id=scan_id)
self.folder_preview_manager.queue_folder_removal_for_device(scan_id=scan_id)
# Last file for this scan id has been downloaded, so clean temp
# directory
logging.debug("Purging temp directories")
self.cleanTempDirsForScanId(scan_id)
if self.prefs.move:
logging.debug("Deleting downloaded source files")
self.deleteSourceFiles(scan_id)
self.download_tracker.clear_auto_delete(scan_id)
self.updateProgressBarState()
self.thumbnailModel.updateDeviceDisplayCheckMark(scan_id=scan_id)
del self.time_remaining[scan_id]
self.notifyDownloadedFromDevice(scan_id)
if files_remaining == 0 and self.prefs.auto_unmount:
self.unmountVolume(scan_id)
if not self.downloadIsRunning():
logging.debug("Download completed")
self.dl_update_timer.stop()
self.enablePrefsAndRefresh(enabled=True)
self.notifyDownloadComplete()
self.downloadProgressBar.reset()
if self.prefs.backup_files:
self.initializeBackupThumbCache()
self.backupPanel.updateLocationCombos()
if self.unity_progress:
for launcher in self.desktop_launchers:
launcher.set_property('progress_visible', False)
self.folder_preview_manager.remove_folders_for_queued_devices()
# Update prefs with stored sequence number and downloads today
# values
data = RenameAndMoveFileData(message=RenameAndMoveStatus.download_completed)
self.sendDataMessageToThread(self.rename_controller, data=data)
# Ask backup processes to send problem reports
self.sendBackupStartFinishMessageToWorkers(message=BackupStatus.backup_completed)
if ((self.prefs.auto_exit and self.download_tracker.no_errors_or_warnings())
or self.prefs.auto_exit_force):
if not self.thumbnailModel.filesRemainToDownload():
logging.debug("Auto exit is initiated")
self.close()
self.download_tracker.purge_all()
self.setDownloadActionLabel()
self.setDownloadCapabilities()
self.download_start_datetime = None
self.download_start_time = None
@pyqtSlot('PyQt_PyObject')
def addErrorLogMessage(self, problems: Problems) -> None:
self.errorLog.addProblems(problems)
increment = len(problems)
if not self.errorLog.isActiveWindow():
self.errorsPending.incrementCounter(increment=increment)
def immediatelyDisplayDownloadRunningInStatusBar(self):
"""
Without any delay, immediately change the status bar message so the
user knows the download has started.
"""
self.statusBar().showMessage(self.devices.downloading_from())
@pyqtSlot()
def displayDownloadRunningInStatusBar(self):
"""
Display a message in the status bar about the current download
"""
if not self.downloadIsRunning():
self.dl_update_timer.stop()
self.displayMessageInStatusBar()
return
updated, download_speed = self.time_check.update_download_speed()
if updated:
downloading = self.devices.downloading_from()
time_remaining = self.time_remaining.time_remaining(self.prefs.detailed_time_remaining)
if (time_remaining is None or
time.time() < self.download_start_time + constants.ShowTimeAndSpeedDelay):
message = downloading
else:
# Translators - in the middle is a unicode em dash - please retain it
# This string is displayed in the status bar when the download is running
message = _(
'%(downloading_from)s — %(time_left)s left (%(speed)s)'
) % dict(
downloading_from=downloading,
time_left=time_remaining,
speed=download_speed
)
self.statusBar().showMessage(message)
def enablePrefsAndRefresh(self, enabled: bool) -> None:
"""
Disable the user being to access the refresh command or change various
program preferences while a download is occurring.
:param enabled: if True, then the user is able to activate the
preferences and refresh commands.
"""
self.refreshAct.setEnabled(enabled)
self.preferencesAct.setEnabled(enabled)
self.renamePanel.setEnabled(enabled)
self.backupPanel.setEnabled(enabled)
self.jobCodePanel.setEnabled(enabled)
def unmountVolume(self, scan_id: int) -> None:
"""
Cameras are already unmounted, so no need to unmount them!
:param scan_id: the scan id of the device to be umounted
"""
device = self.devices[scan_id] # type: Device
if device.device_type == DeviceType.volume:
if self.gvfsControlsMounts:
self.gvolumeMonitor.unmountVolume(path=device.path)
else:
self.udisks2Unmount.emit(device.path)
def deleteSourceFiles(self, scan_id: int) -> None:
"""
Delete files from download device at completion of download
"""
# TODO delete from cameras and from other devices
# TODO should assign this to a process or a thread, and delete then
to_delete = self.download_tracker.get_files_to_auto_delete(scan_id)
def notifyDownloadedFromDevice(self, scan_id: int) -> None:
"""
Display a system notification to the user using libnotify
that the files have been downloaded from the device
:param scan_id: identifies which device
"""
device = self.devices[scan_id]
notification_name = device.display_name
no_photos_downloaded = self.download_tracker.get_no_files_downloaded(
scan_id, FileType.photo
)
no_videos_downloaded = self.download_tracker.get_no_files_downloaded(
scan_id, FileType.video
)
no_photos_failed = self.download_tracker.get_no_files_failed(scan_id, FileType.photo)
no_videos_failed = self.download_tracker.get_no_files_failed(scan_id, FileType.video)
no_files_downloaded = no_photos_downloaded + no_videos_downloaded
no_files_failed = no_photos_failed + no_videos_failed
no_warnings = self.download_tracker.get_no_warnings(scan_id)
file_types = file_types_by_number(no_photos_downloaded, no_videos_downloaded)
file_types_failed = file_types_by_number(no_photos_failed, no_videos_failed)
# Translators: e.g. 23 photos downloaded
message = _(
"%(noFiles)s %(filetypes)s downloaded"
) % {
'noFiles': thousands(no_files_downloaded), 'filetypes': file_types
}
if no_files_failed:
# Translators: e.g. 2 videos failed to download
message += "\n" + _(
"%(noFiles)s %(filetypes)s failed to download"
) % {
'noFiles': thousands(no_files_failed), 'filetypes': file_types_failed
}
if no_warnings:
message = "%s\n%s " % (message, no_warnings) + _("warnings")
message_shown = False
if self.have_libnotify:
n = Notify.Notification.new(notification_name, message, 'rapid-photo-downloader')
try:
message_shown = n.show()
except:
logging.error(
"Unable to display downloaded from device message using notification system"
)
if not message_shown:
logging.error(
"Unable to display downloaded from device message using notification system"
)
logging.info("{}: {}".format(notification_name, message))
def notifyDownloadComplete(self) -> None:
"""
Notify all downloads are complete
If having downloaded from more than one device, display a
system notification to the user using libnotify that all files
have been downloaded.
Regardless of how many downloads have been downloaded
from, display message in status bar.
"""
show_notification = len(self.devices.have_downloaded_from) > 1
n_message = _("All downloads complete")
# photo downloads
photo_downloads = self.download_tracker.total_photos_downloaded
if photo_downloads and show_notification:
filetype = file_types_by_number(photo_downloads, 0)
# Translators: e.g. 23 photos downloaded
n_message += "\n" + _(
"%(number)s %(numberdownloaded)s"
) % dict(
number=thousands(photo_downloads),
numberdownloaded=_("%(filetype)s downloaded") % dict(filetype=filetype)
)
# photo failures
photo_failures = self.download_tracker.total_photo_failures
if photo_failures and show_notification:
filetype = file_types_by_number(photo_failures, 0)
n_message += "\n" + _(
"%(number)s %(numberdownloaded)s"
) % dict(
number=thousands(photo_failures),
numberdownloaded=_("%(filetype)s failed to download") % dict(filetype=filetype)
)
# video downloads
video_downloads = self.download_tracker.total_videos_downloaded
if video_downloads and show_notification:
filetype = file_types_by_number(0, video_downloads)
n_message += "\n" + _(
"%(number)s %(numberdownloaded)s"
) % dict(
number=thousands(video_downloads),
numberdownloaded=_("%(filetype)s downloaded") % dict(filetype=filetype)
)
# video failures
video_failures = self.download_tracker.total_video_failures
if video_failures and show_notification:
filetype = file_types_by_number(0, video_failures)
n_message += "\n" + _(
"%(number)s %(numberdownloaded)s"
) % dict(
number=thousands(video_failures),
numberdownloaded=_("%(filetype)s failed to download") % dict(filetype=filetype)
)
# warnings
warnings = self.download_tracker.total_warnings
if warnings and show_notification:
n_message += "\n" + _(
"%(number)s %(numberdownloaded)s"
) % dict(
number=thousands(warnings),
numberdownloaded=_("warnings")
)
if show_notification:
message_shown = False
if self.have_libnotify:
n = Notify.Notification.new(
_('Rapid Photo Downloader'), n_message, 'rapid-photo-downloader'
)
try:
message_shown = n.show()
except Exception:
logging.error(
"Unable to display download complete message using notification system"
)
if not message_shown:
logging.error(
"Unable to display download complete message using notification system"
)
failures = photo_failures + video_failures
if failures == 1:
f = _('1 failure')
elif failures > 1:
f = _('%d failures') % failures
else:
f = ''
if warnings == 1:
w = _('1 warning')
elif warnings > 1:
w = _('%d warnings') % warnings
else:
w = ''
if f and w:
fw = make_internationalized_list((f, w))
elif f:
fw = f
elif w:
fw = w
else:
fw = ''
devices = self.devices.reset_and_return_have_downloaded_from()
if photo_downloads + video_downloads:
ftc = FileTypeCounter(
{FileType.photo: photo_downloads, FileType.video: video_downloads}
)
no_files_and_types = ftc.file_types_present_details().lower()
if not fw:
downloaded = _(
'Downloaded %(no_files_and_types)s from %(devices)s'
) % dict(no_files_and_types=no_files_and_types, devices=devices)
else:
downloaded = _(
'Downloaded %(no_files_and_types)s from %(devices)s — %(failures)s'
) % dict(no_files_and_types=no_files_and_types, devices=devices, failures=fw)
else:
if fw:
downloaded = _('No files downloaded — %(failures)s') % dict(failures=fw)
else:
downloaded = _('No files downloaded')
logging.info('%s', downloaded)
self.statusBar().showMessage(downloaded)
def notifyFoldersProximityRebuild(self, scan_id) -> None:
"""
Inform the user that a timeline rebuild and folder preview update is pending,
taking into account they may have already been notified.
"""
if self.have_libnotify:
device = self.devices[scan_id]
notification_devices = self.thumbnailModel.ctimes_differ
logging.info(
"Need to rebuild timeline and subfolder previews for %s", device.display_name
)
simple_message = len(notification_devices) == 1
this_computer = len(
[
scan_id for scan_id in notification_devices
if self.devices[scan_id].device_type == DeviceType.path
]
) > 0
if simple_message:
if device.device_type == DeviceType.camera:
message = _(
"The Destination subfolders and Timeline will be rebuilt after "
"all thumbnails have been generated for the %(camera)s"
) % dict(camera=device.display_name)
elif this_computer:
message = _(
"The Destination subfolders and Timeline will be rebuilt after "
"all thumbnails have been generated for this computer"
)
else:
message = _(
"The Destination subfolders and Timeline will be rebuilt after "
"all thumbnails have been generated for %(device)s"
) % dict(device=device.display_name)
else:
no_devices = len(notification_devices)
if this_computer:
no_devices -= 1
if no_devices > 1:
message = _("The Destination subfolders and Timeline will be rebuilt "
"after all thumbnails have been generated for "
"%(number_devices)s devices and this computer"
) % dict(number_devices=no_devices)
else:
assert no_devices == 1
if device.device_type != DeviceType.path:
other_device = device
else:
# the other device must be the first one
other_device = self.devices[notification_devices[0]]
name = other_device.display_name
if other_device.device_type == DeviceType.camera:
message = _("The Destination subfolders and Timeline will be rebuilt "
"after all thumbnails have been generated for the "
"%(camera)s and this computer") % dict(camera=name)
else:
message = _("The Destination subfolders and Timeline will be rebuilt "
"after all thumbnails have been generated for "
"%(device)s and this computer") % dict(device=name)
else:
message = _("The Destination subfolders and Timeline will be rebuilt "
"after all thumbnails have been generated for "
"%(number_devices)s devices") % dict(number_devices=no_devices)
if self.ctime_update_notification is None:
notify = Notify.Notification.new(_('Rapid Photo Downloader'), message,
'rapid-photo-downloader')
else:
notify = self.ctime_update_notification
notify.update(_('Rapid Photo Downloader'), message, 'rapid-photo-downloader')
try:
message_shown = notify.show()
if message_shown:
self.ctime_notification_issued = True
notify.connect('closed', self.notificationFoldersProximityRefreshClosed)
except:
logging.error("Unable to display message using notification system")
self.ctime_update_notification = notify
def notifyFoldersProximityRebuilt(self) -> None:
"""
Inform the user that the the refresh has occurred, updating the existing
message if need be.
"""
if self.have_libnotify:
message = _(
"The Destination subfolders and Timeline have been rebuilt"
)
if self.ctime_update_notification is None:
notify = Notify.Notification.new(
_('Rapid Photo Downloader'), message, 'rapid-photo-downloader'
)
else:
notify = self.ctime_update_notification
notify.update(_('Rapid Photo Downloader'), message, 'rapid-photo-downloader')
try:
message_shown = notify.show()
except:
logging.error("Unable to display message using notification system")
self.ctime_update_notification = None
def notificationFoldersProximityRefreshClosed(self, notify: Notify.Notification) -> None:
"""
Delete our reference to the notification that was used to inform the user
that the timeline and preview folders will be. If it's not deleted, there will
be glib problems at program exit, when the reference is deleted.
:param notify: the notification itself
"""
self.ctime_update_notification = None
def invalidDownloadFolders(self, downloading: DownloadingFileTypes) -> List[str]:
"""
Checks validity of download folders based on the file types the
user is attempting to download.
:return list of the invalid directories, if any, or empty list.
"""
invalid_dirs = []
# sadly this causes an exception on python 3.4:
# downloading.photos or downloading.photos_and_videos
if downloading in (DownloadingFileTypes.photos, DownloadingFileTypes.photos_and_videos):
if not validate_download_folder(self.prefs.photo_download_folder).valid:
invalid_dirs.append(self.prefs.photo_download_folder)
if downloading in (DownloadingFileTypes.videos, DownloadingFileTypes.photos_and_videos):
if not validate_download_folder(self.prefs.video_download_folder).valid:
invalid_dirs.append(self.prefs.video_download_folder)
return invalid_dirs
def notifyPrefsAreInvalid(self, details: str) -> None:
"""
Notifies the user that the preferences are invalid.
Assumes that the main window is already showing
:param details: preference error details
"""
logging.error("Program preferences are invalid: %s", details)
title = _("Program preferences are invalid")
message = "<b>%(title)s</b><br><br>%(details)s" % dict(title=title, details=details)
msgBox = self.standardMessageBox(message=message, rich_text=True)
msgBox.exec()
def deviceState(self, scan_id: int) -> DeviceState:
"""
What the device is being used for at the present moment.
:param scan_id: device to check
:return: DeviceState
"""
return self.devices.device_state[scan_id]
@pyqtSlot('PyQt_PyObject', 'PyQt_PyObject', FileTypeCounter, 'PyQt_PyObject', bool)
def scanFilesReceived(self, rpd_files: List[RPDFile],
sample_files: List[RPDFile],
file_type_counter: FileTypeCounter,
file_size_sum: int,
entire_video_required: bool) -> None:
"""
Process scanned file information received from the scan process
"""
# Update scan running totals
scan_id = rpd_files[0].scan_id
if scan_id not in self.devices:
return
device = self.devices[scan_id]
sample_photo, sample_video = sample_files
if sample_photo is not None:
logging.info(
"Updating example file name using sample photo from %s", device.display_name
)
self.devices.sample_photo = sample_photo
self.renamePanel.setSamplePhoto(self.devices.sample_photo)
# sample required for editing download subfolder generation
self.photoDestinationDisplay.sample_rpd_file = self.devices.sample_photo
if sample_video is not None:
logging.info(
"Updating example file name using sample video from %s", device.display_name
)
self.devices.sample_video = sample_video # type: Video
self.renamePanel.setSampleVideo(self.devices.sample_video)
# sample required for editing download subfolder generation
self.videoDestinationDisplay.sample_rpd_file = self.devices.sample_video
if device.device_type == DeviceType.camera:
device.entire_video_required = entire_video_required
device.file_type_counter = file_type_counter
device.file_size_sum = file_size_sum
self.mapModel(scan_id).updateDeviceScan(scan_id)
self.thumbnailModel.addFiles(
scan_id=scan_id, rpd_files=rpd_files, generate_thumbnail=not self.autoStart(scan_id)
)
self.folder_preview_manager.add_rpd_files(rpd_files=rpd_files)
@pyqtSlot(int, CameraErrorCode)
def scanErrorReceived(self, scan_id: int, error_code: CameraErrorCode) -> None:
"""
Notify the user their camera/phone is inaccessible.
:param scan_id: scan id of the device
:param error_code: the specific libgphoto2 error, mapped onto our own
enum
"""
if scan_id not in self.devices:
return
# During program startup, the main window may not yet be showing
self.showMainWindow()
# An error occurred
device = self.devices[scan_id]
camera_model = device.display_name
if error_code == CameraErrorCode.locked:
title =_('Rapid Photo Downloader')
message = _(
'<b>All files on the %(camera)s are inaccessible</b>.<br><br>It '
'may be locked or not configured for file transfers using MTP. '
'You can unlock it and try again.<br><br>On some models you also '
'need to change the setting <i>USB for charging</i> to <i>USB for '
'file transfers</i>.<br><br>Alternatively, you can ignore this '
'device.'
) % {'camera': camera_model}
else:
assert error_code == CameraErrorCode.inaccessible
title = _('Rapid Photo Downloader')
message = _(
'<b>The %(camera)s appears to be in use by another '
'application.</b><br><br>You can close any other application (such as a file '
'browser) that is using it and try again. If that does not work, unplug the '
'%(camera)s from the computer and plug it in again.<br><br>Alternatively, you '
'can ignore this device.'
) % {'camera':camera_model}
msgBox = QMessageBox(
QMessageBox.Warning, title, message, QMessageBox.NoButton, self
)
msgBox.setIconPixmap(self.devices[scan_id].get_pixmap())
msgBox.addButton(_("&Try Again"), QMessageBox.AcceptRole)
msgBox.addButton(_("&Ignore This Device"), QMessageBox.RejectRole)
self.prompting_for_user_action[device] = msgBox
role = msgBox.exec_()
if role == QMessageBox.AcceptRole:
self.sendResumeToThread(self.scan_controller, worker_id=scan_id)
else:
self.removeDevice(scan_id=scan_id, show_warning=False)
del self.prompting_for_user_action[device]
@pyqtSlot(int, 'PyQt_PyObject', 'PyQt_PyObject', str)
def scanDeviceDetailsReceived(self, scan_id: int,
storage_space: List[StorageSpace],
storage_descriptions: List[str],
optimal_display_name: str) -> None:
"""
Update GUI display and rows DB with definitive camera display name
:param scan_id: scan id of the device
:param storage_space: storage information on the device e.g.
memory card(s) capacity and use
:param storage_desctriptions: names of storage on a camera
:param optimal_display_name: canonical name of the device, as
reported by libgphoto2
"""
if scan_id in self.devices:
device = self.devices[scan_id]
logging.debug(
'%s with scan id %s is now known as %s',
device.display_name, scan_id, optimal_display_name
)
if len(storage_space) > 1:
logging.debug(
'%s has %s storage devices', optimal_display_name, len(storage_space)
)
if not storage_descriptions:
logging.warning("No storage descriptors available for %s", optimal_display_name)
else:
if len(storage_descriptions) == 1:
msg = 'description'
else:
msg = 'descriptions'
logging.debug("Storage %s: %s", msg, ', '.join(storage_descriptions))
device.update_camera_attributes(
display_name=optimal_display_name, storage_space=storage_space,
storage_descriptions=storage_descriptions
)
self.updateSourceButton()
self.deviceModel.updateDeviceNameAndStorage(scan_id, device)
self.thumbnailModel.addOrUpdateDevice(scan_id=scan_id)
self.adjustLeftPanelSliderHandles()
else:
logging.debug(
"Ignoring optimal display name %s and other details because that device was "
"removed", optimal_display_name
)
@pyqtSlot(int, 'PyQt_PyObject')
def scanProblemsReceived(self, scan_id: int, problems: Problems) -> None:
self.addErrorLogMessage(problems=problems)
@pyqtSlot(int)
def scanFatalError(self, scan_id: int) -> None:
try:
device = self.devices[scan_id]
except KeyError:
logging.debug("Got scan error from device that no longer exists (scan_id %s)", scan_id)
return
h1 = _('Sorry, an unexpected problem occurred while scanning %s.') % device.display_name
h2 = _('Unfortunately you cannot download from this device.')
header = '<b>{}</b><br><br>{}'.format(h1, h2)
if device.device_type == DeviceType.camera and not device.is_mtp_device:
h3 = _(
"A possible workaround for the problem might be downloading from the camera's "
"memory card using a card reader."
)
header = '{}<br><br><i>{}</i>'.format(header, h3)
title = _('Device scan failed')
self.makeProblemReportDialog(header=header, title=title)
self.removeDevice(scan_id=scan_id, show_warning=False)
@pyqtSlot(int)
def scanFinished(self, scan_id: int) -> None:
"""
A single device has finished its scan. Other devices can be in any
one of a number of states.
:param scan_id: scan id of the device that finished scanning
"""
if scan_id not in self.devices:
return
device = self.devices[scan_id]
self.devices.set_device_state(scan_id, DeviceState.idle)
self.thumbnailModel.flushAddBuffer()
self.updateProgressBarState()
self.thumbnailModel.updateAllDeviceDisplayCheckMarks()
results_summary, file_types_present = device.file_type_counter.summarize_file_count()
self.download_tracker.set_file_types_present(scan_id, file_types_present)
model = self.mapModel(scan_id)
model.updateDeviceScan(scan_id)
destinations_good = self.setDownloadCapabilities()
self.logState()
if len(self.devices.scanning) == 0:
self.generateTemporalProximityTableData("a download source has finished being scanned")
else:
self.temporalProximity.setState(TemporalProximityState.pending)
if not destinations_good:
auto_start = False
else:
auto_start = self.autoStart(scan_id)
if not auto_start and self.prefs.generate_thumbnails:
# Generate thumbnails for finished scan
model.setSpinnerState(scan_id, DeviceState.idle)
if scan_id in self.thumbnailModel.no_thumbnails_by_scan:
self.devices.set_device_state(scan_id, DeviceState.thumbnailing)
self.updateProgressBarState()
self.thumbnailModel.generateThumbnails(scan_id, self.devices[scan_id])
self.displayMessageInStatusBar()
elif auto_start:
self.displayMessageInStatusBar()
if self.jobCodePanel.needToPromptForJobCode():
model.setSpinnerState(scan_id, DeviceState.idle)
start_download = self.jobCodePanel.getJobCodeBeforeDownload()
if not start_download:
logging.debug(
"Not auto-starting download, because a job code is already being "
"prompted for."
)
else:
start_download = True
if start_download:
if self.download_paused:
self.devices.queued_to_download.add(scan_id)
else:
self.startDownload(scan_id=scan_id)
else:
# not generating thumbnails, and auto start is not on
model.setSpinnerState(scan_id, DeviceState.idle)
self.displayMessageInStatusBar()
def autoStart(self, scan_id: int) -> bool:
"""
Determine if the download for this device should start automatically
:param scan_id: scan id of the device
:return: True if the should start automatically, else False,
"""
prefs_valid, msg = self.prefs.check_prefs_for_validity()
if not prefs_valid:
return False
if not self.thumbnailModel.filesAreMarkedForDownload(scan_id):
logging.debug(
"No files are marked for download for %s", self.devices[scan_id].display_name
)
return False
if scan_id in self.devices.startup_devices:
return self.prefs.auto_download_at_startup
else:
return self.prefs.auto_download_upon_device_insertion
def quit(self) -> None:
"""
Convenience function to quit the application.
Issues a signal to initiate the quit. The signal will be acted
on when Qt gets the chance.
"""
QTimer.singleShot(0, self.close)
def generateTemporalProximityTableData(self, reason: str) -> None:
"""
Initiate Timeline generation if it's right to do so
"""
if self.temporalProximity.state == TemporalProximityState.ctime_rebuild:
logging.info(
"Was tasked to generate Timeline because %s, but ignoring request "
"because a rebuild is required ", reason
)
return
rows = self.thumbnailModel.dataForProximityGeneration()
if rows:
logging.info("Generating Timeline because %s", reason)
self.temporalProximity.setState(TemporalProximityState.generating)
data = OffloadData(thumbnail_rows=rows, proximity_seconds=self.prefs.proximity_seconds)
self.sendToOffload(data=data)
else:
logging.info(
"Was tasked to generate Timeline because %s, but there is nothing to generate",
reason
)
@pyqtSlot(TemporalProximityGroups)
def proximityGroupsGenerated(self, proximity_groups: TemporalProximityGroups) -> None:
if self.temporalProximity.setGroups(proximity_groups=proximity_groups):
self.thumbnailModel.assignProximityGroups(proximity_groups.col1_col2_uid)
if self.ctime_notification_issued:
self.notifyFoldersProximityRebuilt()
self.ctime_notification_issued = False
def closeEvent(self, event) -> None:
logging.debug("Close event activated")
if self.close_event_run:
logging.debug("Close event already run: accepting close event")
event.accept()
return
if self.application_state == ApplicationState.normal:
self.application_state = ApplicationState.exiting
self.sendStopToThread(self.scan_controller)
self.thumbnailModel.stopThumbnailer()
self.sendStopToThread(self.copy_controller)
if self.downloadIsRunning():
logging.debug("Exiting while download is running. Cleaning up...")
# Update prefs with stored sequence number and downloads today
# values
data = RenameAndMoveFileData(message=RenameAndMoveStatus.download_completed)
self.sendDataMessageToThread(self.rename_controller, data=data)
# renameandmovefile process will send a message with the
# updated sequence values. When that occurs,
# this application will save the sequence values to the
# program preferences, resume closing and this close event
# will again be called, but this time the application state
# flag will indicate the need to resume below.
logging.debug("Ignoring close event")
event.ignore()
return
# Incidentally, it's the renameandmovefile process that
# updates the SQL database with the file downloads,
# so no need to update or close it in this main process
self.writeWindowSettings()
logging.debug("Cleaning up provisional download folders")
self.folder_preview_manager.remove_preview_folders()
# write settings before closing error log window
self.errorLog.done(0)
logging.debug("Terminating main ExifTool process")
self.exiftool_process.terminate()
if self.ctime_update_notification is not None:
self.ctime_update_notification = None
self.sendStopToThread(self.offload_controller)
self.offloadThread.quit()
if not self.offloadThread.wait(500):
self.sendTerminateToThread(self.offload_controller)
self.sendStopToThread(self.rename_controller)
self.renameThread.quit()
if not self.renameThread.wait(500):
self.sendTerminateToThread(self.rename_controller)
self.scanThread.quit()
if not self.scanThread.wait(2000):
self.sendTerminateToThread(self.scan_controller)
self.copyfilesThread.quit()
if not self.copyfilesThread.wait(1000):
self.sendTerminateToThread(self.copy_controller)
self.sendStopToThread(self.backup_controller)
self.backupThread.quit()
if not self.backupThread.wait(1000):
self.sendTerminateToThread(self.backup_controller)
if not self.gvfsControlsMounts:
self.udisks2MonitorThread.quit()
self.udisks2MonitorThread.wait()
self.cameraHotplugThread.quit()
self.cameraHotplugThread.wait()
else:
del self.gvolumeMonitor
if not disable_version_check:
self.newVersionThread.quit()
self.newVersionThread.wait(100)
self.sendStopToThread(self.thumbnail_deamon_controller)
self.thumbnaildaemonmqThread.quit()
if not self.thumbnaildaemonmqThread.wait(2000):
self.sendTerminateToThread(self.thumbnail_deamon_controller)
# Tell logging thread to stop: uses slightly different approach
# than other threads
stop_process_logging_manager(info_port=self.logging_port)
self.loggermqThread.quit()
self.loggermqThread.wait()
self.watchedDownloadDirs.closeWatch()
self.cleanAllTempDirs()
logging.debug("Cleaning any device cache dirs and sample video")
self.devices.delete_cache_dirs_and_sample_video()
tc = ThumbnailCacheSql(create_table_if_not_exists=False)
logging.debug("Cleaning up Thumbnail cache")
tc.cleanup_cache(days=self.prefs.keep_thumbnails_days)
Notify.uninit()
self.close_event_run = True
logging.debug("Accepting close event")
event.accept()
def getIconsAndEjectableForMount(self, mount: QStorageInfo) -> Tuple[List[str], bool]:
"""
Given a mount, get the icon names suggested by udev or
GVFS, and determine whether the mount is ejectable or not.
:param mount: the mount to check
:return: icon names and eject boolean
:rtype Tuple[str, bool]
"""
if self.gvfsControlsMounts:
iconNames, canEject = self.gvolumeMonitor.getProps(
mount.rootPath())
else:
# get the system device e.g. /dev/sdc1
systemDevice = bytes(mount.device()).decode()
iconNames, canEject = self.udisks2Monitor.get_device_props(
systemDevice)
return (iconNames, canEject)
def addToDeviceDisplay(self, device: Device, scan_id: int) -> None:
self.mapModel(scan_id).addDevice(scan_id, device)
self.adjustLeftPanelSliderHandles()
# Resize the "This Computer" view after a device has been added
# If not done, the widget geometry will not be updated to reflect
# the new view.
if device.device_type == DeviceType.path:
self.thisComputerView.updateGeometry()
@pyqtSlot()
def cameraAdded(self) -> None:
if not self.prefs.device_autodetection:
logging.debug("Ignoring camera as device auto detection is off")
else:
logging.debug("Assuming camera will not be mounted: immediately proceeding with scan")
self.searchForCameras()
@pyqtSlot()
def cameraRemoved(self) -> None:
"""
Handle the possible removal of a camera by comparing the
cameras the OS knows about compared to the cameras we are
tracking. Remove tracked cameras if they are not on the OS.
We need this brute force method because I don't know if it's
possible to query GIO or udev to return the info needed by
libgphoto2
"""
sc = self.gp_context.camera_autodetect()
system_cameras = ((model, port) for model, port in sc if not
port.startswith('disk:'))
kc = self.devices.cameras.items()
known_cameras = ((model, port) for port, model in kc)
removed_cameras = set(known_cameras) - set(system_cameras)
for model, port in removed_cameras:
scan_id = self.devices.scan_id_from_camera_model_port(model, port)
device = self.devices[scan_id]
# Don't log a warning when the camera was removed while the user was being
# informed it was locked or inaccessible
show_warning = not device in self.prompting_for_user_action
self.removeDevice(scan_id=scan_id, show_warning=show_warning)
if removed_cameras:
self.setDownloadCapabilities()
@pyqtSlot()
def noGVFSAutoMount(self) -> None:
"""
In Gnome like environment we rely on Gnome automatically
mounting cameras and devices with file systems. But sometimes
it will not automatically mount them, for whatever reason.
Try to handle those cases.
"""
#TODO Implement noGVFSAutoMount()
# however, I have no idea under what circumstances it is called
logging.error("Implement noGVFSAutoMount()")
@pyqtSlot()
def cameraMounted(self):
if have_gio:
self.searchForCameras()
def unmountCameraToEnableScan(self, model: str,
port: str,
on_startup: bool) -> bool:
"""
Possibly "unmount" a camera or phone controlled by GVFS so it can be scanned
:param model: camera model
:param port: port used by camera
:param on_startup: if True, the unmount is occurring during
the program's startup phase
:return: True if unmount operation initiated, else False
"""
if self.gvfsControlsMounts:
self.devices.cameras_to_gvfs_unmount_for_scan[port] = model
if self.gvolumeMonitor.unmountCamera(model=model, port=port, on_startup=on_startup):
return True
else:
del self.devices.cameras_to_gvfs_unmount_for_scan[port]
return False
@pyqtSlot(bool, str, str, bool, bool)
def cameraUnmounted(self, result: bool,
model: str,
port: str,
download_started: bool,
on_startup: bool) -> None:
"""
Handle the attempt to unmount a GVFS mounted camera.
Note: cameras that have not yet been scanned do not yet have a scan_id assigned!
An obvious point, but easy to forget.
:param result: result from the GVFS operation
:param model: camera model
:param port: camera port
:param download_started: whether the unmount happened because a download
was initiated
:param on_startup: if the unmount happened on a device during program startup
"""
if not download_started:
assert self.devices.cameras_to_gvfs_unmount_for_scan[port] == model
del self.devices.cameras_to_gvfs_unmount_for_scan[port]
if result:
self.startCameraScan(model=model, port=port, on_startup=on_startup)
else:
# Get the camera's short model name, instead of using the exceptionally
# long name that gphoto2 can sometimes use. Get the icon too.
camera = Device()
camera.set_download_from_camera(model, port)
logging.debug(
"Not scanning %s because it could not be unmounted", camera.display_name
)
message = _(
'<b>The %(camera)s cannot be scanned because it cannot be '
'unmounted.</b><br><br>You can close any other application (such as a '
'file browser) that is using it and try again. If that does not work, '
'unplug the %(camera)s from the computer and plug it in again.'
) % dict(camera=camera.display_name)
# Show the main window if it's not yet visible
self.showMainWindow()
msgBox = self.standardMessageBox(message=message, rich_text=True)
msgBox.setIconPixmap(camera.get_pixmap())
msgBox.exec()
else:
# A download was initiated
scan_id = self.devices.scan_id_from_camera_model_port(model, port)
self.devices.cameras_to_gvfs_unmount_for_download.remove(scan_id)
if result:
if not self.devices.download_start_blocked():
self.startDownloadPhase2()
else:
camera = self.devices[scan_id]
display_name = camera.display_name
title = _('Rapid Photo Downloader')
message = _(
'<b>The download cannot start because the %(camera)s cannot be '
'unmounted.</b><br><br>You '
'can close any other application (such as a file browser) that is '
'using it and try again. If that '
'does not work, unplug the %(camera)s from the computer and plug '
'it in again, and choose which files you want to download from it.'
) % dict(camera=display_name)
msgBox = QMessageBox(QMessageBox.Warning, title, message, QMessageBox.Ok)
msgBox.setIconPixmap(camera.get_pixmap())
msgBox.exec_()
def searchForCameras(self, on_startup: bool=False) -> None:
"""
Detect using gphoto2 any cameras attached to the computer.
Initiates unmount of cameras that are mounted by GIO/GVFS.
:param on_startup: if True, the search is occurring during
the program's startup phase
"""
if self.prefs.device_autodetection:
cameras = self.gp_context.camera_autodetect()
for model, port in cameras:
if port in self.devices.cameras_to_gvfs_unmount_for_scan:
assert self.devices.cameras_to_gvfs_unmount_for_scan[port] == model
logging.debug("Already unmounting %s", model)
elif self.devices.known_camera(model, port):
logging.debug("Camera %s is known", model)
elif self.devices.user_marked_camera_as_ignored(model, port):
logging.debug("Ignoring camera marked as removed by user %s", model)
elif not port.startswith('disk:'):
device = Device()
device.set_download_from_camera(model, port)
if device.udev_name in self.prefs.camera_blacklist:
logging.debug("Ignoring blacklisted camera %s", model)
else:
logging.debug("Detected %s on port %s", model, port)
# almost always, libgphoto2 cannot access a camera when
# it is mounted by another process, like Gnome's GVFS
# or any other system. Before attempting to scan the
# camera, check to see if it's mounted and if so,
# unmount it. Unmounting is asynchronous.
if not self.unmountCameraToEnableScan(
model=model, port=port, on_startup=on_startup):
self.startCameraScan(model=model, port=port, on_startup=on_startup)
def startCameraScan(self, model: str,
port: str,
on_startup: bool=False) -> None:
"""
Initiate the scan of an unmounted camera
:param model: camera model
:param port: camera port
:param on_startup: if True, the scan is occurring during
the program's startup phase
"""
device = Device()
device.set_download_from_camera(model, port)
self.startDeviceScan(device=device, on_startup=on_startup)
def startDeviceScan(self, device: Device, on_startup: bool=False) -> None:
"""
Initiate the scan of a device (camera, this computer path, or external device)
:param device: device to scan
:param on_startup: if True, the scan is occurring during
the program's startup phase
"""
scan_id = self.devices.add_device(device=device, on_startup=on_startup)
logging.debug("Assigning scan id %s to %s", scan_id, device.name())
self.thumbnailModel.addOrUpdateDevice(scan_id)
self.addToDeviceDisplay(device, scan_id)
self.updateSourceButton()
scan_arguments = ScanArguments(
device=device,
ignore_other_types=self.ignore_other_photo_types,
log_gphoto2=self.log_gphoto2,
)
self.sendStartWorkerToThread(self.scan_controller, worker_id=scan_id, data=scan_arguments)
self.devices.set_device_state(scan_id, DeviceState.scanning)
self.setDownloadCapabilities()
self.updateProgressBarState()
self.displayMessageInStatusBar()
if not on_startup and self.thumbnailModel.anyCompletedDownloads():
if self.prefs.completed_downloads == int(CompletedDownloads.prompt):
logging.info("Querying whether to clear completed downloads")
counter = self.thumbnailModel.getFileDownloadsCompleted()
numbers = counter.file_types_present_details(singular_natural=True).capitalize()
plural = sum(counter.values()) > 1
if plural:
title = _('Completed Downloads Present')
body = _(
'%s whose download have completed are displayed.'
) % numbers
question = _('Do you want to clear the completed downloads?')
else:
title = _('Completed Download Present')
body = _(
'%s whose download has completed is displayed.'
) % numbers
question = _('Do you want to clear the completed download?')
message = "<b>{}</b><br><br>{}<br><br>{}".format(title, body, question)
questionDialog = RememberThisDialog(
message=message,
icon=':/rapid-photo-downloader.svg',
remember=RememberThisMessage.do_not_ask_again,
parent=self
)
clear = questionDialog.exec_()
if clear:
self.thumbnailModel.clearCompletedDownloads()
if questionDialog.remember:
if clear:
self.prefs.completed_downloads = int(CompletedDownloads.clear)
else:
self.prefs.completed_downloads = int(CompletedDownloads.keep)
elif self.prefs.completed_downloads == int(CompletedDownloads.clear):
logging.info("Clearing completed downloads")
self.thumbnailModel.clearCompletedDownloads()
else:
logging.info("Keeping completed downloads")
def partitionValid(self, mount: QStorageInfo) -> bool:
"""
A valid partition is one that is:
1) available
2) the mount name should not be blacklisted
:param mount: the mount point to check
:return: True if valid, False otherwise
"""
if mount.isValid() and mount.isReady():
if mount.displayName() in self.prefs.volume_blacklist:
logging.info("blacklisted device %s ignored", mount.displayName())
return False
else:
return True
return False
def shouldScanMount(self, mount: QStorageInfo) -> bool:
if self.prefs.device_autodetection:
path = mount.rootPath()
if (not self.prefs.scan_specific_folders or has_one_or_more_folders(
path=path, folders=self.prefs.folders_to_scan)):
if not self.devices.user_marked_volume_as_ignored(path):
return True
else:
logging.debug(
'Not scanning volume with path %s because it was set to be temporarily '
'ignored', path
)
else:
logging.debug(
'Not scanning volume with path %s because it lacks a folder at the base '
'level that indicates it should be scanned', path
)
return False
def prepareNonCameraDeviceScan(self, device: Device, on_startup: bool=False) -> None:
"""
Initiates a device scan for volume.
If non-DCIM device scans are enabled, and the device is not whitelisted
(determined by the display name), then the user is prompted whether to download
from the device.
:param device: device to scan
:param on_startup: if True, the search is occurring during
the program's startup phase
"""
if not self.devices.known_device(device):
if (self.scanEvenIfNoFoldersLikeDCIM() and
not device.display_name in self.prefs.volume_whitelist):
logging.debug("Prompting whether to use device %s", device.display_name)
# prompt user to see if device should be used or not
self.showMainWindow()
message = _(
'Do you want to download photos and videos from the device <i>%('
'device)s</i>?'
) % dict(device=device.display_name)
use = RememberThisDialog(
message=message, icon=device.get_pixmap(),
remember=RememberThisMessage.remember_choice,
parent=self, title=device.display_name
)
if use.exec():
if use.remember:
logging.debug("Whitelisting device %s", device.display_name)
self.prefs.add_list_value(key='volume_whitelist', value=device.display_name)
self.startDeviceScan(device=device, on_startup=on_startup)
else:
logging.debug("Device %s rejected as a download device", device.display_name)
if use.remember and device.display_name not in self.prefs.volume_blacklist:
logging.debug("Blacklisting device %s", device.display_name)
self.prefs.add_list_value(key='volume_blacklist', value=device.display_name)
else:
self.startDeviceScan(device=device, on_startup=on_startup)
@pyqtSlot(str, list, bool)
def partitionMounted(self, path: str, iconNames: List[str], canEject: bool) -> None:
"""
Setup devices from which to download from and backup to, and
if relevant start scanning them
:param path: the path of the mounted partition
:param iconNames: a list of names of icons used in themed icons
associated with this partition
:param canEject: whether the partition can be ejected or not
"""
assert path in mountPaths()
if self.monitorPartitionChanges():
mount = QStorageInfo(path)
if self.partitionValid(mount):
backup_file_type = self.isBackupPath(path)
if backup_file_type is not None:
if path not in self.backup_devices:
device = BackupDevice(mount=mount, backup_type=backup_file_type)
self.backup_devices[path] = device
self.addDeviceToBackupManager(path)
self.download_tracker.set_no_backup_devices(
len(self.backup_devices.photo_backup_devices),
len(self.backup_devices.video_backup_devices)
)
self.displayMessageInStatusBar()
self.backupPanel.addBackupVolume(
mount_details=self.backup_devices.get_backup_volume_details(path)
)
if self.prefs.backup_device_autodetection:
self.backupPanel.updateExample()
elif self.shouldScanMount(mount):
device = Device()
device.set_download_from_volume(
path, mount.displayName(), iconNames, canEject, mount
)
self.prepareNonCameraDeviceScan(device)
@pyqtSlot(str)
def partitionUmounted(self, path: str) -> None:
"""
Handle the unmounting of partitions by the system / user.
:param path: the path of the partition just unmounted
"""
if not path:
return
if self.devices.known_path(path, DeviceType.volume):
# four scenarios -
# the mount is being scanned
# the mount has been scanned but downloading has not yet started
# files are being downloaded from mount
# files have finished downloading from mount
scan_id = self.devices.scan_id_from_path(path, DeviceType.volume)
self.removeDevice(scan_id=scan_id)
elif path in self.backup_devices:
self.removeBackupDevice(path)
self.backupPanel.removeBackupVolume(path=path)
self.displayMessageInStatusBar()
self.download_tracker.set_no_backup_devices(
len(self.backup_devices.photo_backup_devices),
len(self.backup_devices.video_backup_devices)
)
if self.prefs.backup_device_autodetection:
self.backupPanel.updateExample()
self.setDownloadCapabilities()
def removeDevice(self, scan_id: int,
show_warning: bool=True,
adjust_temporal_proximity: bool=True,
ignore_in_this_program_instantiation: bool=False) -> None:
"""
Remove a device from internal tracking and display.
:param scan_id: scan id of device to remove
:param show_warning: log warning if the device was having
something done to it e.g. scan
:param adjust_temporal_proximity: if True, update the temporal
proximity table to reflect device removal
:param ignore_in_this_program_instantiation: don't scan this
device again during this instance of the program being run
"""
assert scan_id is not None
if scan_id in self.devices:
device = self.devices[scan_id]
device_state = self.deviceState(scan_id)
if show_warning:
if device_state == DeviceState.scanning:
logging.warning("Removed device %s was being scanned", device.name())
elif device_state == DeviceState.downloading:
logging.error("Removed device %s was being downloaded from", device.name())
elif device_state == DeviceState.thumbnailing:
logging.warning(
"Removed device %s was having thumbnails generated", device.name()
)
else:
logging.info("Device removed: %s", device.name())
else:
logging.debug("Device removed: %s", device.name())
if device in self.prompting_for_user_action:
self.prompting_for_user_action[device].reject()
files_removed = self.thumbnailModel.clearAll(
scan_id=scan_id, keep_downloaded_files=True
)
self.mapModel(scan_id).removeDevice(scan_id)
was_downloading = self.downloadIsRunning()
if device_state == DeviceState.scanning:
self.sendStopWorkerToThread(self.scan_controller, scan_id)
elif device_state == DeviceState.downloading:
self.sendStopWorkerToThread(self.copy_controller, scan_id)
self.download_tracker.device_removed_mid_download(scan_id, device.display_name)
del self.time_remaining[scan_id]
self.notifyDownloadedFromDevice(scan_id=scan_id)
# TODO need correct check for "is thumbnailing", given is now asynchronous
elif device_state == DeviceState.thumbnailing:
self.thumbnailModel.terminateThumbnailGeneration(scan_id)
if ignore_in_this_program_instantiation:
self.devices.ignore_device(scan_id=scan_id)
self.folder_preview_manager.remove_folders_for_device(scan_id=scan_id)
del self.devices[scan_id]
self.adjustLeftPanelSliderHandles()
if device.device_type == DeviceType.path:
self.thisComputer.setViewVisible(False)
self.updateSourceButton()
self.setDownloadCapabilities()
if adjust_temporal_proximity:
state = self.proximityStatePostDeviceRemoval()
if state == TemporalProximityState.empty:
self.temporalProximity.setState(TemporalProximityState.empty)
elif files_removed:
self.generateTemporalProximityTableData("a download source was removed")
elif self.temporalProximity.state == TemporalProximityState.pending:
self.generateTemporalProximityTableData(
"a download source was removed and a build is pending"
)
self.logState()
self.updateProgressBarState()
self.displayMessageInStatusBar()
# Reset Download button from "Pause" to "Download"
if was_downloading and not self.downloadIsRunning():
self.setDownloadActionLabel()
def rescanDevice(self, scan_id: int) -> None:
"""
Remove a device and scan it again.
:param scan_id: scan id of the device
"""
device = self.devices[scan_id]
logging.debug("Rescanning %s", device.display_name)
self.removeDevice(scan_id=scan_id)
if device.device_type == DeviceType.camera:
self.startCameraScan(device.camera_model, device.camera_port)
else:
if device.device_type == DeviceType.path:
self.thisComputer.setViewVisible(True)
self.startDeviceScan(device=device)
def rescanDevicesAndComputer(self, ignore_cameras: bool, rescan_path: bool) -> None:
"""
After a preference change, rescan already scanned devices
:param ignore_cameras: if True, don't rescan cameras
:param rescan_path: if True, include manually specified paths
(i.e. This Computer)
"""
if rescan_path:
logging.info("Rescanning all paths and devices")
if ignore_cameras:
logging.info("Rescanning non camera devices")
# Collect the scan ids to work on - don't modify the
# collection of devices in place!
scan_ids = []
for scan_id in self.devices:
device = self.devices[scan_id]
if not ignore_cameras or device.device_type == DeviceType.volume:
scan_ids.append(scan_id)
elif rescan_path and device.device_type == DeviceType.path:
scan_ids.append(scan_id)
for scan_id in scan_ids:
self.rescanDevice(scan_id=scan_id)
def searchForDevicesAgain(self) -> None:
"""
Called after a preference change to only_external_mounts
"""
# only scan again if the new pref value is more permissive than the former
# (don't remove existing devices)
if not self.prefs.only_external_mounts:
logging.debug("Searching for new volumes to scan...")
self.setupNonCameraDevices(scanning_again=True)
logging.debug("... finished searching for volumes to scan")
def blacklistDevice(self, scan_id: int) -> None:
"""
Query user if they really want to to permanently ignore a camera or
volume. If they do, the device is removed and blacklisted.
:param scan_id: scan id of the device
"""
device = self.devices[scan_id]
if device.device_type == DeviceType.camera:
text = _("<b>Do you want to ignore the %s whenever this program is run?</b>")
text = text % device.display_name
info_text = _(
"All cameras, phones and tablets with the same model name will be ignored."
)
else:
assert device.device_type == DeviceType.volume
text = _("<b>Do you want to ignore the device %s whenever this program is run?</b>")
text = text % device.display_name
info_text = _("Any device with the same name will be ignored.")
msgbox = QMessageBox()
msgbox.setWindowTitle(_("Rapid Photo Downloader"))
msgbox.setIcon(QMessageBox.Question)
msgbox.setText(text)
msgbox.setTextFormat(Qt.RichText)
msgbox.setInformativeText(info_text)
msgbox.setStandardButtons(QMessageBox.Yes|QMessageBox.No)
if msgbox.exec() == QMessageBox.Yes:
if device.device_type == DeviceType.camera:
self.prefs.add_list_value(key='camera_blacklist', value=device.udev_name)
logging.debug('Added %s to camera blacklist',device.udev_name)
else:
self.prefs.add_list_value(key='volume_blacklist', value=device.display_name)
logging.debug('Added %s to volume blacklist', device.display_name)
self.removeDevice(scan_id=scan_id)
def logState(self) -> None:
self.devices.logState()
self.thumbnailModel.logState()
self.deviceModel.logState()
self.thisComputerModel.logState()
def setupBackupDevices(self) -> None:
"""
Setup devices to back up to.
Includes both auto detected back up devices, and manually
specified paths.
"""
if self.prefs.backup_device_autodetection:
for mount in self.validMounts.mountedValidMountPoints():
if self.partitionValid(mount):
path = mount.rootPath()
backup_type = self.isBackupPath(path)
if backup_type is not None:
self.backup_devices[path] = BackupDevice(
mount=mount, backup_type=backup_type
)
self.addDeviceToBackupManager(path)
self.backupPanel.updateExample()
else:
self.setupManualBackup()
for path in self.backup_devices:
self.addDeviceToBackupManager(path)
self.download_tracker.set_no_backup_devices(
len(self.backup_devices.photo_backup_devices),
len(self.backup_devices.video_backup_devices))
self.backupPanel.setupBackupDisplay()
def removeBackupDevice(self, path: str) -> None:
device_id = self.backup_devices.device_id(path)
self.sendStopWorkerToThread(self.backup_controller, worker_id=device_id)
del self.backup_devices[path]
def resetupBackupDevices(self) -> None:
"""
Change backup preferences in response to preference change.
Assumes backups may have already been setup.
"""
try:
assert not self.downloadIsRunning()
except AssertionError:
logging.critical("Backup devices should never be reset when a download is occurring")
return
logging.info("Resetting backup devices configuration...")
# Clear all existing backup devices
for path in self.backup_devices.all_paths():
self.removeBackupDevice(path)
self.download_tracker.set_no_backup_devices(0, 0)
self.backupPanel.resetBackupDisplay()
self.setupBackupDevices()
self.setDownloadCapabilities()
logging.info("...backup devices configuration is reset")
def setupNonCameraDevices(self, on_startup: bool=False, scanning_again: bool=False) -> None:
"""
Setup devices from which to download and initiates their scan.
:param on_startup: if True, the search is occurring during
the program's startup phase
:param scanning_again: if True, the search is occurring after a preference
value change, where devices may have already been scanned.
"""
if not self.prefs.device_autodetection:
return
mounts = [] # type: List[QStorageInfo]
for mount in self.validMounts.mountedValidMountPoints():
if self.partitionValid(mount):
path = mount.rootPath()
if scanning_again and \
self.devices.known_path(path=path, device_type=DeviceType.volume):
logging.debug(
"Will not scan %s, because it's associated with an existing device",
mount.displayName()
)
continue
if path not in self.backup_devices and self.shouldScanMount(mount):
logging.debug("Will scan %s", mount.displayName())
mounts.append(mount)
else:
logging.debug("Will not scan %s", mount.displayName())
for mount in mounts:
icon_names, can_eject = self.getIconsAndEjectableForMount(mount)
device = Device()
device.set_download_from_volume(
mount.rootPath(), mount.displayName(), icon_names, can_eject, mount
)
self.prepareNonCameraDeviceScan(device=device, on_startup=on_startup)
def setupManualPath(self, on_startup: bool=False) -> None:
"""
Setup This Computer path from which to download and initiates scan.
:param on_startup: if True, the setup is occurring during
the program's startup phase
"""
if not self.prefs.this_computer_source:
return
if self.prefs.this_computer_path:
if not self.confirmManualDownloadLocation():
logging.debug(
"This Computer path %s rejected as download source",
self.prefs.this_computer_path
)
self.prefs.this_computer_path = ''
self.thisComputer.setViewVisible(False)
return
# user manually specified the path from which to download
path = self.prefs.this_computer_path
if path:
if os.path.isdir(path) and os.access(path, os.R_OK):
logging.debug("Using This Computer path %s", path)
device = Device()
device.set_download_from_path(path)
self.startDeviceScan(device=device, on_startup=on_startup)
else:
logging.error("This Computer download path is invalid: %s", path)
else:
logging.warning("This Computer download path is not specified")
def addDeviceToBackupManager(self, path: str) -> None:
device_id = self.backup_devices.device_id(path)
self.backup_controller.send_multipart(create_inproc_msg(b'START_WORKER',
worker_id=device_id,
data=BackupArguments(path, self.backup_devices.name(path))))
def setupManualBackup(self) -> None:
"""
Setup backup devices that the user has manually specified.
Depending on the folder the user has chosen, the paths for
photo and video backup will either be the same or they will
differ.
Because the paths are manually specified, there is no mount
associated with them.
"""
backup_photo_location = self.prefs.backup_photo_location
backup_video_location = self.prefs.backup_video_location
if not self.manualBackupPathAvailable(backup_photo_location):
logging.warning("Photo backup path unavailable: %s", backup_photo_location)
if not self.manualBackupPathAvailable(backup_video_location):
logging.warning("Video backup path unavailable: %s", backup_video_location)
if backup_photo_location != backup_video_location:
backup_photo_device = BackupDevice(mount=None, backup_type=BackupLocationType.photos)
backup_video_device = BackupDevice(mount=None, backup_type=BackupLocationType.videos)
self.backup_devices[backup_photo_location] = backup_photo_device
self.backup_devices[backup_video_location] = backup_video_device
logging.info("Backing up photos to %s", backup_photo_location)
logging.info("Backing up videos to %s", backup_video_location)
else:
# videos and photos are being backed up to the same location
backup_device = BackupDevice(mount=None,
backup_type=BackupLocationType.photos_and_videos)
self.backup_devices[backup_photo_location] = backup_device
logging.info("Backing up photos and videos to %s", backup_photo_location)
def isBackupPath(self, path: str) -> Optional[BackupLocationType]:
"""
Checks to see if backups are enabled and path represents a
valid backup location. It must be writeable.
Checks against user preferences.
:return The type of file that should be backed up to the path,
else if nothing should be, None
"""
if self.prefs.backup_files:
if self.prefs.backup_device_autodetection:
# Determine if the auto-detected backup device is
# to be used to backup only photos, or videos, or both.
# Use the presence of a corresponding directory to
# determine this.
# The directory must be writable.
photo_path = os.path.join(path, self.prefs.photo_backup_identifier)
p_backup = os.path.isdir(photo_path) and os.access(photo_path, os.W_OK)
video_path = os.path.join(path, self.prefs.video_backup_identifier)
v_backup = os.path.isdir(video_path) and os.access(video_path, os.W_OK)
if p_backup and v_backup:
logging.info("Photos and videos will be backed up to %s", path)
return BackupLocationType.photos_and_videos
elif p_backup:
logging.info("Photos will be backed up to %s", path)
return BackupLocationType.photos
elif v_backup:
logging.info("Videos will be backed up to %s", path)
return BackupLocationType.videos
elif path == self.prefs.backup_photo_location:
# user manually specified the path
if self.manualBackupPathAvailable(path):
return BackupLocationType.photos
elif path == self.prefs.backup_video_location:
# user manually specified the path
if self.manualBackupPathAvailable(path):
return BackupLocationType.videos
return None
def manualBackupPathAvailable(self, path: str) -> bool:
return os.access(path, os.W_OK)
def monitorPartitionChanges(self) -> bool:
"""
If the user is downloading from a manually specified location,
and is not using any automatically detected backup devices,
then there is no need to monitor for devices with filesystems
being added or removed
:return: True if should monitor, False otherwise
"""
return (self.prefs.device_autodetection or
self.prefs.backup_device_autodetection)
@pyqtSlot(str)
def watchedFolderChange(self, path: str) -> None:
"""
Handle case where a download folder has been removed or altered
:param path: watched path
"""
logging.debug("Change in watched folder %s; validating download destinations", path)
valid = True
if self.prefs.photo_download_folder and not validate_download_folder(
self.prefs.photo_download_folder).valid:
valid = False
logging.debug(
"Photo download destination %s is now invalid", self.prefs.photo_download_folder
)
self.handleInvalidDownloadDestination(file_type=FileType.photo, do_update=False)
if self.prefs.video_download_folder and not validate_download_folder(
self.prefs.video_download_folder).valid:
valid = False
logging.debug(
"Video download destination %s is now invalid", self.prefs.video_download_folder
)
self.handleInvalidDownloadDestination(file_type=FileType.video, do_update=False)
if not valid:
self.watchedDownloadDirs.updateWatchPathsFromPrefs(self.prefs)
self.folder_preview_manager.change_destination()
self.setDownloadCapabilities()
def confirmManualDownloadLocation(self) -> bool:
"""
Queries the user to ask if they really want to download from locations
that could take a very long time to scan. They can choose yes or no.
Returns True if yes or there was no need to ask the user, False if the
user said no.
"""
self.showMainWindow()
path = self.prefs.this_computer_path
if path in (
'/media', '/run', os.path.expanduser('~'), '/', '/bin', '/boot', '/dev',
'/lib', '/lib32', '/lib64', '/mnt', '/opt', '/sbin', '/snap', '/sys', '/tmp',
'/usr', '/var', '/proc'):
message = "<b>" + _(
"Downloading from %(location)s on This Computer."
) % dict(
location=make_html_path_non_breaking(path)
) + "</b><br><br>" + _(
"Do you really want to download from here?<br><br>On some systems, scanning this "
"location can take a very long time."
)
msgbox = self.standardMessageBox(message=message, rich_text=True)
msgbox.setStandardButtons(QMessageBox.Yes|QMessageBox.No)
return msgbox.exec() == QMessageBox.Yes
return True
def scanEvenIfNoFoldersLikeDCIM(self) -> bool:
"""
Determines if partitions should be scanned even if there is
no specific folder like a DCIM folder present in the base folder of the file system.
:return: True if scans of such partitions should occur, else
False
"""
return self.prefs.device_autodetection and not self.prefs.scan_specific_folders
def displayMessageInStatusBar(self) -> None:
"""
Displays message on status bar.
Notifies user if scanning or thumbnailing.
If neither scanning or thumbnailing, displays:
1. files checked for download
2. total number files available
3. how many not shown (user chose to show only new files)
"""
if self.downloadIsRunning():
if self.download_paused:
downloading = self.devices.downloading_from()
# Translators - in the middle is a unicode em dash - please retain it
# This string is displayed in the status bar when the download is paused
msg = '%(downloading_from)s — download paused' % dict(downloading_from=downloading)
else:
# status message updates while downloading are handled in another function
return
elif self.devices.thumbnailing:
devices = [self.devices[scan_id].display_name for scan_id in self.devices.thumbnailing]
msg = _("Generating thumbnails for %s") % make_internationalized_list(devices)
elif self.devices.scanning:
devices = [self.devices[scan_id].display_name for scan_id in self.devices.scanning]
msg = _("Scanning %s") % make_internationalized_list(devices)
else:
files_avilable = self.thumbnailModel.getNoFilesAvailableForDownload()
if sum(files_avilable.values()) != 0:
files_to_download = self.thumbnailModel.getNoFilesMarkedForDownload()
files_avilable_sum = files_avilable.summarize_file_count()[0]
files_hidden = self.thumbnailModel.getNoHiddenFiles()
if files_hidden:
files_checked = _(
'%(number)s of %(available files)s checked for download (%(hidden)s hidden)'
) % {
'number': thousands(files_to_download),
'available files': files_avilable_sum,
'hidden': files_hidden
}
else:
files_checked = _(
'%(number)s of %(available files)s checked for download'
) % {
'number': thousands(files_to_download),
'available files': files_avilable_sum
}
msg = files_checked
else:
msg = ''
self.statusBar().showMessage(msg)
class QtSingleApplication(QApplication):
"""
Taken from
http://stackoverflow.com/questions/12712360/qtsingleapplication
-for-pyside-or-pyqt
"""
messageReceived = pyqtSignal(str)
def __init__(self, programId: str, *argv) -> None:
super().__init__(*argv)
self._id = programId
self._activationWindow = None # type: RapidWindow
self._activateOnMessage = False # type: bool
# Is there another instance running?
self._outSocket = QLocalSocket() # type: QLocalSocket
self._outSocket.connectToServer(self._id)
self._isRunning = self._outSocket.waitForConnected() # type: bool
self._outStream = None # type: QTextStream
self._inSocket = None
self._inStream = None # type: QTextStream
self._server = None
if self._isRunning:
# Yes, there is.
self._outStream = QTextStream(self._outSocket)
self._outStream.setCodec('UTF-8')
else:
# No, there isn't, at least not properly.
# Cleanup any past, crashed server.
error = self._outSocket.error()
if error == QLocalSocket.ConnectionRefusedError:
self.close()
QLocalServer.removeServer(self._id)
self._outSocket = None
self._server = QLocalServer()
self._server.listen(self._id)
self._server.newConnection.connect(self._onNewConnection)
def close(self) -> None:
if self._inSocket:
self._inSocket.disconnectFromServer()
if self._outSocket:
self._outSocket.disconnectFromServer()
if self._server:
self._server.close()
def isRunning(self) -> bool:
return self._isRunning
def id(self) -> str:
return self._id
def activationWindow(self) -> RapidWindow:
return self._activationWindow
def setActivationWindow(self, activationWindow: RapidWindow,
activateOnMessage: bool = True) -> None:
self._activationWindow = activationWindow
self._activateOnMessage = activateOnMessage
def activateWindow(self) -> None:
if not self._activationWindow:
return
self._activationWindow.setWindowState(
self._activationWindow.windowState() & ~Qt.WindowMinimized)
self._activationWindow.raise_()
self._activationWindow.activateWindow()
def sendMessage(self, msg) -> bool:
if not self._outStream:
return False
self._outStream << msg << '\n'
self._outStream.flush()
return self._outSocket.waitForBytesWritten()
def _onNewConnection(self) -> None:
if self._inSocket:
self._inSocket.readyRead.disconnect(self._onReadyRead)
self._inSocket = self._server.nextPendingConnection()
if not self._inSocket:
return
self._inStream = QTextStream(self._inSocket)
self._inStream.setCodec('UTF-8')
self._inSocket.readyRead.connect(self._onReadyRead)
if self._activateOnMessage:
self.activateWindow()
def _onReadyRead(self) -> None:
while True:
msg = self._inStream.readLine()
if not msg: break
self.messageReceived.emit(msg)
def get_versions() -> List[str]:
if 'cython' in zmq.zmq_version_info.__module__:
pyzmq_backend = 'cython'
else:
pyzmq_backend = 'cffi'
try:
ram = psutil.virtual_memory()
total = format_size_for_user(ram.total)
used = format_size_for_user(ram.used)
except Exception:
total = used = 'unknown'
versions = [
'Rapid Photo Downloader: {}'.format(__about__.__version__),
'Platform: {}'.format(platform.platform()),
'Memory: {} used of {}'.format(used, total),
'Python: {}'.format(platform.python_version()),
'Python executable: {}'.format(sys.executable),
'Qt: {}'.format(QtCore.QT_VERSION_STR),
'PyQt: {}'.format(QtCore.PYQT_VERSION_STR),
'SIP: {}'.format(sip.SIP_VERSION_STR),
'ZeroMQ: {}'.format(zmq.zmq_version()),
'Python ZeroMQ: {} ({} backend)'.format(zmq.pyzmq_version(), pyzmq_backend),
'gPhoto2: {}'.format(gphoto2_version()),
'Python gPhoto2: {}'.format(python_gphoto2_version()),
'ExifTool: {}'.format(EXIFTOOL_VERSION),
'pymediainfo: {}'.format(pymedia_version_info()),
'GExiv2: {}'.format(gexiv2_version()),
'Gstreamer: {}'.format(gst_version()),
'PyGObject: {}'.format('.'.join(map(str, gi.version_info))),
'libraw: {}'.format(libraw_version()),
'rawkit: {}'.format(rawkit_version()),
'psutil: {}'.format('.'.join(map(str, psutil.version_info)))
]
v = exiv2_version()
if v:
versions.append('Exiv2: {}'.format(v))
try:
versions.append('{}: {}'.format(*platform.libc_ver()))
except:
pass
try:
import tornado
versions.append('Tornado: {}'.format(tornado.version))
except ImportError:
pass
return versions
# def darkFusion(app: QApplication):
# app.setStyle("Fusion")
#
# dark_palette = QPalette()
#
# dark_palette.setColor(QPalette.Window, QColor(53, 53, 53))
# dark_palette.setColor(QPalette.WindowText, Qt.white)
# dark_palette.setColor(QPalette.Base, QColor(25, 25, 25))
# dark_palette.setColor(QPalette.AlternateBase, QColor(53, 53, 53))
# dark_palette.setColor(QPalette.ToolTipBase, Qt.white)
# dark_palette.setColor(QPalette.ToolTipText, Qt.white)
# dark_palette.setColor(QPalette.Text, Qt.white)
# dark_palette.setColor(QPalette.Button, QColor(53, 53, 53))
# dark_palette.setColor(QPalette.ButtonText, Qt.white)
# dark_palette.setColor(QPalette.BrightText, Qt.red)
# dark_palette.setColor(QPalette.Link, QColor(42, 130, 218))
# dark_palette.setColor(QPalette.Highlight, QColor(42, 130, 218))
# dark_palette.setColor(QPalette.HighlightedText, Qt.black)
#
# app.setPalette(dark_palette)
# style = """
# QToolTip { color: #ffffff; background-color: #2a82da; border: 1px solid white; }
# """
# app.setStyleSheet(style)
class SplashScreen(QSplashScreen):
def __init__(self, pixmap: QPixmap, flags) -> None:
super().__init__(pixmap, flags)
self.progress = 0
self.image_width = pixmap.width()
self.progressBarPen = QPen(QBrush(QColor(Qt.white)), 2.0)
def drawContents(self, painter: QPainter):
painter.save()
painter.setPen(QColor(Qt.black))
painter.drawText(18, 64, __about__.__version__)
if self.progress:
painter.setPen(self.progressBarPen)
x = int(self.progress / 100 * self.image_width)
painter.drawLine(0, 360, x, 360)
painter.restore()
def setProgress(self, value: int) -> None:
"""
Update splash screen progress bar
:param value: percent done, between 0 and 100
"""
self.progress = value
self.repaint()
def parser_options(formatter_class=argparse.HelpFormatter):
parser = argparse.ArgumentParser(prog=__about__.__title__,
description=__about__.__summary__,
formatter_class=formatter_class)
parser.add_argument('--version', action='version', version=
'%(prog)s {}'.format(__about__.__version__))
parser.add_argument('--detailed-version', action='store_true',
help="Show version numbers of program and its libraries and exit.")
parser.add_argument("-v", "--verbose", action="store_true", dest="verbose",
help=_("Display program information when run from the command line."))
parser.add_argument("--debug", action="store_true", dest="debug",
help=_("Display debugging information when run from the command line."))
parser.add_argument("-e", "--extensions", action="store_true",
dest="extensions",
help=_("List photo and video file extensions the program recognizes "
"and exit."))
parser.add_argument("--photo-renaming", choices=['on','off'],
dest="photo_renaming", help=_("Turn on or off the the renaming of photos."))
parser.add_argument("--video-renaming", choices=['on','off'],
dest="video_renaming", help=_("turn on or off the the renaming of videos."))
parser.add_argument("-a", "--auto-detect", choices=['on','off'],
dest="auto_detect", help=_("Turn on or off the automatic detection of devices from which "
"to download."))
parser.add_argument("-t", "--this-computer", choices=['on','off'],
dest="this_computer_source",
help=_("Turn on or off downloading from this computer."))
parser.add_argument("--this-computer-location", type=str,
metavar=_("PATH"), dest="this_computer_location",
help=_("The PATH on this computer from which to download."))
parser.add_argument("--photo-destination", type=str,
metavar=_("PATH"), dest="photo_location",
help=_("The PATH where photos will be downloaded to."))
parser.add_argument("--video-destination", type=str,
metavar=_("PATH"), dest="video_location",
help=_("The PATH where videos will be downloaded to."))
parser.add_argument("-b", "--backup", choices=['on','off'],
dest="backup", help=_("Turn on or off the backing up of photos and videos while "
"downloading."))
parser.add_argument("--backup-auto-detect", choices=['on','off'],
dest="backup_auto_detect",
help=_("Turn on or off the automatic detection of backup devices."))
parser.add_argument("--photo-backup-identifier", type=str,
metavar=_("FOLDER"), dest="photo_backup_identifier",
help=_("The FOLDER in which backups are stored on the automatically detected photo backup "
"device, with the folder's name being used to identify whether or not the device "
"is used for backups. For each device you wish to use for backing photos up to, "
"create a folder on it with this name."))
parser.add_argument("--video-backup-identifier", type=str,
metavar=_("FOLDER"), dest="video_backup_identifier",
help=_("The FOLDER in which backups are stored on the automatically detected video backup "
"device, with the folder's name being used to identify whether or not the device "
"is used for backups. For each device you wish to use for backing up videos to, "
"create a folder on it with this name."))
parser.add_argument("--photo-backup-location", type=str,
metavar=_("PATH"), dest="photo_backup_location",
help=_("The PATH where photos will be backed up when automatic "
"detection of backup devices is turned off."))
parser.add_argument("--video-backup-location", type=str,
metavar=_("PATH"), dest="video_backup_location",
help=_("The PATH where videos will be backed up when automatic "
"detection of backup devices is turned off."))
parser.add_argument("--ignore-other-photo-file-types", action="store_true", dest="ignore_other",
help=_('Ignore photos with the following extensions: %s') %
make_internationalized_list([s.upper() for s in OTHER_PHOTO_EXTENSIONS]))
parser.add_argument("--auto-download-startup", dest="auto_download_startup",
choices=['on', 'off'],
help=_("Turn on or off starting downloads as soon as the program itself starts."))
parser.add_argument("--auto-download-device-insertion", dest="auto_download_insertion",
choices=['on', 'off'],
help=_("Turn on or off starting downloads as soon as a device is inserted."))
parser.add_argument("--thumbnail-cache", dest="thumb_cache",
choices=['on','off'],
help=_("Turn on or off use of the Rapid Photo Downloader Thumbnail Cache. "
"Turning it off does not delete existing cache contents."))
parser.add_argument("--delete-thumbnail-cache", dest="delete_thumb_cache",
action="store_true",
help=_("Delete all thumbnails in the Rapid Photo Downloader Thumbnail "
"Cache, and exit."))
parser.add_argument("--forget-remembered-files", dest="forget_files",
action="store_true",
help=_("Forget which files have been previously downloaded, and exit."))
parser.add_argument("--import-old-version-preferences", action="store_true",
dest="import_prefs",
help=_("Import preferences from an old program version and exit. Requires the "
"command line program gconftool-2."))
parser.add_argument("--reset", action="store_true", dest="reset",
help=_("Reset all program settings to their default values, delete all thumbnails "
"in the Thumbnail cache, forget which files have been previously "
"downloaded, and exit."))
parser.add_argument("--log-gphoto2", action="store_true",
help=_("Include gphoto2 debugging information in log files."))
parser.add_argument(
"--camera-info", action="store_true", help=_(
"Print information to the terminal about attached cameras and exit."
)
)
parser.add_argument('path', nargs='?')
return parser
def import_prefs() -> None:
"""
Import program preferences from the Gtk+ 2 version of the program.
Requires the command line program gconftool-2.
"""
def run_cmd(k: str) -> str:
command_line = '{} --get /apps/rapid-photo-downloader/{}'.format(cmd, k)
args = shlex.split(command_line)
try:
return subprocess.check_output(args=args).decode().strip()
except subprocess.SubprocessError:
return ''
cmd = shutil.which('gconftool-2')
keys = (('image_rename', 'photo_rename', prefs_list_from_gconftool2_string),
('video_rename', 'video_rename', prefs_list_from_gconftool2_string),
('subfolder', 'photo_subfolder', prefs_list_from_gconftool2_string),
('video_subfolder', 'video_subfolder', prefs_list_from_gconftool2_string),
('download_folder', 'photo_download_folder', str),
('video_download_folder','video_download_folder', str),
('device_autodetection', 'device_autodetection', pref_bool_from_gconftool2_string),
('device_location', 'this_computer_path', str),
('device_autodetection_psd', 'scan_specific_folders',
pref_bool_from_gconftool2_string),
('ignored_paths', 'ignored_paths', prefs_list_from_gconftool2_string),
('use_re_ignored_paths', 'use_re_ignored_paths', pref_bool_from_gconftool2_string),
('backup_images', 'backup_files', pref_bool_from_gconftool2_string),
('backup_device_autodetection', 'backup_device_autodetection',
pref_bool_from_gconftool2_string),
('backup_identifier', 'photo_backup_identifier', str),
('video_backup_identifier', 'video_backup_identifier', str),
('backup_location', 'backup_photo_location', str),
('backup_video_location', 'backup_video_location', str),
('strip_characters', 'strip_characters', pref_bool_from_gconftool2_string),
('synchronize_raw_jpg', 'synchronize_raw_jpg', pref_bool_from_gconftool2_string),
('auto_download_at_startup', 'auto_download_at_startup',
pref_bool_from_gconftool2_string),
('auto_download_upon_device_insertion', 'auto_download_upon_device_insertion',
pref_bool_from_gconftool2_string),
('auto_unmount', 'auto_unmount', pref_bool_from_gconftool2_string),
('auto_exit', 'auto_exit', pref_bool_from_gconftool2_string),
('auto_exit_force', 'auto_exit_force', pref_bool_from_gconftool2_string),
('verify_file', 'verify_file', pref_bool_from_gconftool2_string),
('job_codes', 'job_codes', prefs_list_from_gconftool2_string),
('generate_thumbnails', 'generate_thumbnails', pref_bool_from_gconftool2_string),
('download_conflict_resolution', 'conflict_resolution', str),
('backup_duplicate_overwrite', 'backup_duplicate_overwrite',
pref_bool_from_gconftool2_string))
if cmd is None:
print(_("To import preferences from the old version of Rapid Photo Downloader, you must "
"install the program gconftool-2."))
return
prefs = Preferences()
with raphodo.utilities.stdchannel_redirected(sys.stderr, os.devnull):
value = run_cmd('program_version')
if not value:
print(_("No prior program preferences detected: exiting"))
return
else:
print(_("Importing preferences from Rapid Photo Downloader %(version)s") % dict(
version=value))
print()
for key_triplet in keys:
key = key_triplet[0]
value = run_cmd(key)
if value:
try:
new_value = key_triplet[2](value)
except:
print("Skipping malformed value for key {}".format(key))
else:
if key == 'device_autodetection':
if new_value:
print("Setting device_autodetection to True")
print("Setting this_computer_source to False")
prefs.device_autodetection = True
prefs.this_computer_source = False
else:
print("Setting device_autodetection to False")
print("Setting this_computer_source to True")
prefs.device_autodetection = False
prefs.this_computer_source = True
elif key == 'device_autodetection_psd':
print("Setting scan_specific_folders to", not new_value)
prefs.scan_specific_folders = not new_value
elif key == 'device_location' and prefs.this_computer_source:
print("Setting this_computer_path to", new_value)
prefs.this_computer_path = new_value
elif key == 'download_conflict_resolution':
if new_value == "skip download":
prefs.conflict_resolution = int(constants.ConflictResolution.skip)
else:
prefs.conflict_resolution = \
int(constants.ConflictResolution.add_identifier)
else:
new_key = key_triplet[1]
if new_key in ('photo_rename', 'video_rename'):
pref_list, case = upgrade_pre090a4_rename_pref(new_value)
print("Setting", new_key, "to", pref_list)
setattr(prefs, new_key, pref_list)
if case is not None:
if new_key == 'photo_rename':
ext_key = 'photo_extension'
else:
ext_key = 'video_extension'
print("Setting", ext_key, "to", case)
setattr(prefs, ext_key, case)
else:
print("Setting", new_key, "to", new_value)
setattr(prefs, new_key, new_value)
key = 'stored_sequence_no'
with raphodo.utilities.stdchannel_redirected(sys.stderr, os.devnull):
value = run_cmd(key)
if value:
try:
new_value = int(value)
# we need to add 1 to the number for historic reasons
new_value += 1
except ValueError:
print("Skipping malformed value for key stored_sequence_no")
else:
if new_value and raphodo.utilities.confirm(
'\n' + _(
'Do you want to copy the stored sequence number, which has the value %d?'
) % new_value, resp=False):
prefs.stored_sequence_no = new_value
def critical_startup_error(message: str) -> None:
errorapp = QApplication(sys.argv)
msg = QMessageBox()
msg.setWindowTitle(_("Rapid Photo Downloader"))
msg.setIcon(QMessageBox.Critical)
msg.setText('<b>%s</b>' % message)
msg.setInformativeText(_('Program aborting.'))
msg.setStandardButtons(QMessageBox.Ok)
msg.show()
errorapp.exec_()
def main():
if sys.platform.startswith('linux') and os.getuid() == 0:
sys.stderr.write("Never run this program as the sudo / root user.\n")
critical_startup_error(_("Never run this program as the sudo / root user."))
sys.exit(1)
if not shutil.which('exiftool'):
critical_startup_error(_('You must install ExifTool to run Rapid Photo Downloader.'))
sys.exit(1)
rapid_path = os.path.realpath(os.path.dirname(inspect.getfile(inspect.currentframe())))
import_path = os.path.realpath(os.path.dirname(inspect.getfile(downloadtracker)))
if rapid_path != import_path:
sys.stderr.write(
"Rapid Photo Downloader is installed in multiple locations. Uninstall all copies "
"except the version you want to run.\n"
)
critical_startup_error(
_(
"Rapid Photo Downloader is installed in multiple locations.\n\nUninstall all "
"copies except the version you want to run."
)
)
sys.exit(1)
parser = parser_options()
args = parser.parse_args()
if args.detailed_version:
print('\n'.join(get_versions()))
sys.exit(0)
if args.extensions:
photos = list((ext.upper() for ext in PHOTO_EXTENSIONS))
videos = list((ext.upper() for ext in VIDEO_EXTENSIONS))
extensions = ((photos, _("Photos")),
(videos, _("Videos")))
for exts, file_type in extensions:
extensions = make_internationalized_list(exts)
print('{}: {}'.format(file_type, extensions))
sys.exit(0)
if args.debug:
logging_level = logging.DEBUG
elif args.verbose:
logging_level = logging.INFO
else:
logging_level = logging.ERROR
global logger
logger = iplogging.setup_main_process_logging(logging_level=logging_level)
logging.info("Rapid Photo Downloader is starting")
if args.photo_renaming:
photo_rename = args.photo_renaming == 'on'
if photo_rename:
logging.info("Photo renaming turned on from command line")
else:
logging.info("Photo renaming turned off from command line")
else:
photo_rename = None
if args.video_renaming:
video_rename = args.video_renaming == 'on'
if video_rename:
logging.info("Video renaming turned on from command line")
else:
logging.info("Video renaming turned off from command line")
else:
video_rename = None
if args.path:
if args.auto_detect or args.this_computer_source:
msg = _(
'When specifying a path on the command line, do not also specify an\n'
'option for device auto detection or a path on "This Computer".'
)
print(msg)
critical_startup_error(msg.replace('\n', ' '))
sys.exit(1)
media_dir = get_media_dir()
auto_detect = args.path.startswith(media_dir) or gvfs_gphoto2_path(args.path)
if auto_detect:
this_computer_source = False
this_computer_location = None
logging.info(
"Device auto detection turned on from command line using positional PATH argument"
)
if not auto_detect:
this_computer_source = True
this_computer_location = os.path.abspath(args.path)
logging.info(
"Downloading from This Computer turned on from command line using positional "
"PATH argument"
)
else:
if args.auto_detect:
auto_detect= args.auto_detect == 'on'
if auto_detect:
logging.info("Device auto detection turned on from command line")
else:
logging.info("Device auto detection turned off from command line")
else:
auto_detect=None
if args.this_computer_source:
this_computer_source = args.this_computer_source == 'on'
if this_computer_source:
logging.info("Downloading from This Computer turned on from command line")
else:
logging.info("Downloading from This Computer turned off from command line")
else:
this_computer_source=None
if args.this_computer_location:
this_computer_location = os.path.abspath(args.this_computer_location)
logging.info("This Computer path set from command line: %s", this_computer_location)
else:
this_computer_location=None
if args.photo_location:
photo_location = os.path.abspath(args.photo_location)
logging.info("Photo location set from command line: %s", photo_location)
else:
photo_location=None
if args.video_location:
video_location = os.path.abspath(args.video_location)
logging.info("video location set from command line: %s", video_location)
else:
video_location=None
if args.backup:
backup = args.backup == 'on'
if backup:
logging.info("Backup turned on from command line")
else:
logging.info("Backup turned off from command line")
else:
backup=None
if args.backup_auto_detect:
backup_auto_detect = args.backup_auto_detect == 'on'
if backup_auto_detect:
logging.info("Automatic detection of backup devices turned on from command line")
else:
logging.info("Automatic detection of backup devices turned off from command line")
else:
backup_auto_detect=None
if args.photo_backup_identifier:
photo_backup_identifier = args.photo_backup_identifier
logging.info("Photo backup identifier set from command line: %s", photo_backup_identifier)
else:
photo_backup_identifier=None
if args.video_backup_identifier:
video_backup_identifier = args.video_backup_identifier
logging.info("Video backup identifier set from command line: %s", video_backup_identifier)
else:
video_backup_identifier=None
if args.photo_backup_location:
photo_backup_location = os.path.abspath(args.photo_backup_location)
logging.info("Photo backup location set from command line: %s", photo_backup_location)
else:
photo_backup_location=None
if args.video_backup_location:
video_backup_location = os.path.abspath(args.video_backup_location)
logging.info("Video backup location set from command line: %s", video_backup_location)
else:
video_backup_location=None
if args.thumb_cache:
thumb_cache = args.thumb_cache == 'on'
else:
thumb_cache = None
if args.auto_download_startup:
auto_download_startup = args.auto_download_startup == 'on'
if auto_download_startup:
logging.info("Automatic download at startup turned on from command line")
else:
logging.info("Automatic download at startup turned off from command line")
else:
auto_download_startup=None
if args.auto_download_insertion:
auto_download_insertion = args.auto_download_insertion == 'on'
if auto_download_insertion:
logging.info("Automatic download upon device insertion turned on from command line")
else:
logging.info("Automatic download upon device insertion turned off from command line")
else:
auto_download_insertion=None
if args.log_gphoto2:
gp.use_python_logging()
if args.camera_info:
dump_camera_details()
sys.exit(0)
# keep appGuid value in sync with value in upgrade.py
appGuid = '8dbfb490-b20f-49d3-9b7d-2016012d2aa8'
# See note at top regarding avoiding crashes
global app
app = QtSingleApplication(appGuid, sys.argv)
if app.isRunning():
print('Rapid Photo Downloader is already running')
sys.exit(0)
app.setOrganizationName("Rapid Photo Downloader")
app.setOrganizationDomain("damonlynch.net")
app.setApplicationName("Rapid Photo Downloader")
app.setWindowIcon(QIcon(':/rapid-photo-downloader.svg'))
# darkFusion(app)
# app.setStyle('Fusion')
# Resetting preferences must occur after QApplication is instantiated
if args.reset:
prefs = Preferences()
prefs.reset()
prefs.sync()
d = DownloadedSQL()
d.update_table(reset=True)
cache = ThumbnailCacheSql(create_table_if_not_exists=False)
cache.purge_cache()
print(_("All settings and caches have been reset"))
logging.debug("Exiting immediately after full reset")
sys.exit(0)
if args.delete_thumb_cache or args.forget_files or args.import_prefs:
if args.delete_thumb_cache:
cache = ThumbnailCacheSql(create_table_if_not_exists=False)
cache.purge_cache()
print(_("Thumbnail Cache has been reset"))
logging.debug("Thumbnail Cache has been reset")
if args.forget_files:
d = DownloadedSQL()
d.update_table(reset=True)
print(_("Remembered files have been forgotten"))
logging.debug("Remembered files have been forgotten")
if args.import_prefs:
import_prefs()
logging.debug("Exiting immediately after thumbnail cache / remembered files reset")
sys.exit(0)
splash = SplashScreen(QPixmap(':/splashscreen.png'), Qt.WindowStaysOnTopHint)
splash.show()
app.processEvents()
rw = RapidWindow(
photo_rename=photo_rename,
video_rename=video_rename,
auto_detect=auto_detect,
this_computer_source=this_computer_source,
this_computer_location=this_computer_location,
photo_download_folder=photo_location,
video_download_folder=video_location,
backup=backup,
backup_auto_detect=backup_auto_detect,
photo_backup_identifier=photo_backup_identifier,
video_backup_identifier=video_backup_identifier,
photo_backup_location=photo_backup_location,
video_backup_location=video_backup_location,
ignore_other_photo_types=args.ignore_other,
thumb_cache=thumb_cache,
auto_download_startup=auto_download_startup,
auto_download_insertion=auto_download_insertion,
log_gphoto2=args.log_gphoto2,
splash=splash
)
app.setActivationWindow(rw)
code = app.exec_()
logging.debug("Exiting")
sys.exit(code)
if __name__ == "__main__":
main()
|