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
|
##########################################################################
# SUBCMD.TCL, module sub-commands procedures
# Copyright (C) 2002-2004 Mark Lakata
# Copyright (C) 2004-2017 Kent Mein
# Copyright (C) 2016-2025 Xavier Delaruelle
#
# This program 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 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##########################################################################
proc cmdModuleList {show_oneperline show_mtime search_match args} {
set json [isStateEqual report_format json]
# load tags from loaded modules
cacheCurrentModules
if {[llength $args]} {
defineModEqProc [isIcase] [getConf extended_default]
# match passed name against any part of loaded module names
set mtest [expr {{contains} in $search_match ? {matchin} : {match}}]
set search_queries $args
# prepare header message which depend if search is performed
set loadedmsg {Currently Loaded Matching Modulefiles}
} else {
set search_queries {}
set loadedmsg {Currently Loaded Modulefiles}
}
set report_indesym [isEltInReport indesym 0]
set report_alias [expr {[isEltInReport alias 0] || [isEltInReport\
provided-alias 0]}]
# build list of loaded modules and symbolics and aliases if reported
set loadedmodlist [list]
foreach mod [getEnvLoadedModulePropertyParsedList name] {
set modfile [getModulefileFromLoadedModule $mod]
set mtime [expr {$show_mtime && [file exists $modfile] ?\
[getFileMtime $modfile] : {}}]
set mod_list($mod) [list modulefile $mtime $modfile]
# fetch symbols from loaded environment information
set modname [file dirname $mod]
set sym_list {}
foreach altname [getLoadedAltname $mod sym] {
# skip non-symbol entry
if {$altname ne $modname} {
lappend sym_list [file tail $altname]
# fill loaded list structure with symbolic versions in case
# indesym report is activated
if {$report_indesym} {
set mod_list($altname) [list version $mod]
lappend loadedmodlist $altname
}
}
}
set ::g_symbolHash($mod) [lsort -dictionary $sym_list]
# fetch aliases from loaded environment information
if {$report_alias} {
foreach altname [getLoadedAltname $mod alias] {
set mod_list($altname) [list alias $mod]
lappend loadedmodlist $altname
}
}
lappend loadedmodlist $mod
}
# filter-out hidden loaded modules unless all module should be seen
if {[getState hiding_threshold] <= 1} {
set newloadedmodlist [list]
foreach mod $loadedmodlist {
if {![isModuleTagged $mod hidden-loaded 1]} {
lappend newloadedmodlist $mod
}
}
set loadedmodlist $newloadedmodlist
}
# same header msg if no module loaded at all whether search is made or not
set noloadedmsg [expr {![llength $loadedmodlist] ? {No Modulefiles\
Currently Loaded.} : {No Matching Modulefiles Currently Loaded.}}]
# filter loaded modules not matching any of the mod spec passed
if {[llength $args]} {
# include alt name comparison (alias/sym) when checking module name
# depends if alias and/or sym are reported independently
set modeq_altname_mode [switch -- $report_indesym$report_alias {
11 {expr {0}}
10 {expr {7}}
01 {expr {6}}
00 {expr {2}}
}]
set matchlist [list]
foreach mod $loadedmodlist {
foreach pattern $args {
# compare pattern against loaded module, its variant set and its
# alternative names
if {[modEq $pattern $mod $mtest 1 $modeq_altname_mode 1 0 *]} {
lappend matchlist $mod
break
}
}
}
set loadedmodlist $matchlist
}
if {![llength $loadedmodlist]} {
if {!$json && [isEltInReport header]} {
report $noloadedmsg
}
} else {
set one_per_line [expr {$show_mtime || $show_oneperline}]
set show_idx [expr {!$show_mtime && [isEltInReport idx]}]
set header [expr {!$json && [isEltInReport header] ? $loadedmsg :\
{noheader}}]
set theader_cols [list hi Package 39 Versions 19 {Last mod.} 19]
reportModules $search_queries $header {} terse $show_mtime $show_idx\
$one_per_line $theader_cols loaded $loadedmodlist
# display output key
if {!$show_mtime && !$json && [isEltInReport key]} {
displayKey
}
}
}
proc cmdModuleDisplay {args} {
lappendState mode display
set first_report 1
foreach mod $args {
lassign [getPathToModule $mod] modfile modname modnamevr
if {$modfile ne {}} {
# only one separator lines between 2 modules
if {$first_report} {
displaySeparatorLine
set first_report 0
}
report [sgr hi $modfile]:\n
execute-modulefile $modfile $modname modnamevr $mod 1
displaySeparatorLine
}
}
lpopState mode
}
proc cmdModulePaths {mod} {
set dir_list [getModulePathList exiterronundef]
foreach dir $dir_list {
array unset mod_list
array set mod_list [getModules $dir $mod 0 [list rc_defs_included]]
# prepare list of dirs for alias/symbol target search, will first search
# in currently looked dir, then in other dirs following precedence order
set target_dir_list [list $dir {*}[replaceFromList $dir_list $dir]]
# forcibly enable implicit_default to resolve alias target when it
# points to a directory
setConf implicit_default 1
# build list of modulefile to print
foreach elt [array names mod_list] {
switch -- [lindex $mod_list($elt) 0] {
modulefile {
lappend ::g_return_text $dir/$elt
}
virtual {
lappend ::g_return_text [lindex $mod_list($elt) 2]
}
alias - version {
# resolve alias target
set aliastarget [lindex $mod_list($elt) 1]
lassign [getPathToModule $aliastarget $target_dir_list 0]\
modfile modname modnamevr
# add module target as result instead of alias
if {$modfile ne {} && ![info exists mod_list($modname)]} {
lappend ::g_return_text $modfile
}
}
}
}
# reset implicit_default to restore behavior defined
unsetConf implicit_default
}
# sort results if any and remove duplicates
if {[info exists ::g_return_text]} {
set ::g_return_text [lsort -dictionary -unique $::g_return_text]
} else {
# set empty value to return empty if no result
set ::g_return_text {}
}
}
proc cmdModulePath {mod} {
lassign [getPathToModule $mod] modfile modname modnamevr
# if no result set empty value to return empty
if {$modfile eq {}} {
set ::g_return_text {}
} else {
lappend ::g_return_text $modfile
}
}
proc cmdModuleSearch {args} {
# disable error report to avoid modulefile errors to mix with valid results
set mod_pattern_list [lassign $args search]
set json [isStateEqual report_format json]
set icase [isIcase]
defineModEqProc $icase [getConf extended_default]
lappend searchmod rc_defs_included
if {![llength $mod_pattern_list]} {
lappend mod_pattern_list {}
lappend searchmod wild
} else {
foreach mod_pattern $mod_pattern_list {
if {![string length $mod_pattern]} {
reportError [getEmptyNameMsg module]
return
}
}
}
inhibitErrorReport
set foundmod 0
lappendState mode whatis
set dir_list [getModulePathList exiterronundef]
foreach dir $dir_list {
array unset mod_list
array set mod_list [getMatchingAnyModules $dir $mod_pattern_list 0\
$searchmod {}]
array unset interp_list
array set interp_list {}
# forcibly enable implicit_default to resolve alias target when it
# points to a directory
setConf implicit_default 1
# build list of modulefile to interpret
foreach elt [array names mod_list] {
switch -- [lindex $mod_list($elt) 0] {
modulefile {
if {[isModuleTagged $elt forbidden 0 $dir/$elt]} {
# register any error occurring on element matching search
if {[modEqAny $mod_pattern_list $elt]} {
set err_list($elt) [list accesserr [getForbiddenMsg\
$elt $dir/$elt]]
}
} else {
set interp_list($elt) $dir/$elt
# register module name in a global list (shared across
# modulepaths) to get hints when solving aliases/version
set full_list($elt) 1
}
}
virtual {
if {[isModuleTagged $elt forbidden 0 [lindex $mod_list($elt)\
2]]} {
# register any error occurring on element matching search
if {[modEqAny $mod_pattern_list $elt]} {
set err_list($elt) [list accesserr [getForbiddenMsg\
$elt [lindex $mod_list($elt) 2]]]
}
} else {
set interp_list($elt) [lindex $mod_list($elt) 2]
set full_list($elt) 1
}
}
alias {
# resolve alias target
set elt_target [lindex $mod_list($elt) 1]
if {![info exists full_list($elt_target)]} {
lassign [getPathToModule $elt_target $dir 0]\
modfile modname modnamevr issuetype issuemsg
# add module target as result instead of alias
if {$modfile ne {} && ![info exists mod_list($modname)]} {
set interp_list($modname) $modfile
set full_list($modname) 1
} elseif {$modfile eq {}} {
# if module target not found in current modulepath add to
# list for global search after initial modulepath lookup
if {[string first {Unable to locate} $issuemsg] == 0} {
set extra_search($modname) [list $dir [modEqAny\
$mod_pattern_list $elt]]
# register resolution error if alias name matches search
} elseif {[modEqAny $mod_pattern_list $elt]} {
set err_list($modname) [list $issuetype $issuemsg]
}
}
}
}
version {
# report error of version target if matching query
set elt_target [getArrayKey mod_list [lindex $mod_list($elt)\
1] $icase]
if {[info exists mod_list($elt_target)] && [lindex\
$mod_list($elt_target) 0] in [list invalid accesserr] &&\
[modEqAny $mod_pattern_list $elt]} {
set err_list($elt_target) $mod_list($elt_target)
} elseif {![info exists mod_list($elt_target)]} {
set extra_search($elt_target) [list $dir [modEqAny\
$mod_pattern_list $elt]]
}
}
invalid - accesserr {
# register any error occurring on element matching search
if {[modEqAny $mod_pattern_list $elt]} {
set err_list($elt) $mod_list($elt)
}
}
}
}
# reset implicit_default to restore behavior defined
unsetConf implicit_default
# in case during modulepath lookup we find an alias target we were
# looking for in previous modulepath, remove this element from global
# search list
foreach elt [array names extra_search] {
if {[info exists full_list($elt)]} {
unset extra_search($elt)
}
}
# save results from this modulepath for interpretation step as there
# is an extra round of search to match missing alias target, we cannot
# process modulefiles found immediately
if {[array size interp_list]} {
set interp_save($dir) [array get interp_list]
}
}
# forcibly enable implicit_default to resolve alias target when it points
# to a directory
setConf implicit_default 1
# find target of aliases in all modulepath except the one already tried
foreach elt [array names extra_search] {
lassign [getPathToModule $elt {} 0 no [lindex $extra_search($elt) 0]]\
modfile modname modnamevr issuetype issuemsg issuefile
# found target so append it to results in corresponding modulepath
if {$modfile ne {}} {
# get belonging modulepath dir depending of module kind
if {[isModuleVirtual $modname $modfile]} {
set dir [findModulepathFromModulefile\
$::g_sourceVirtual($modname)]
} else {
set dir [getModulepathFromModuleName $modfile $modname]
}
array unset interp_list
if {[info exists interp_save($dir)]} {
array set interp_list $interp_save($dir)
}
set interp_list($modname) $modfile
set interp_save($dir) [array get interp_list]
# register resolution error if primal alias name matches search
} elseif {$modfile eq {} && [lindex $extra_search($elt) 1]} {
set err_list($modname) [list $issuetype $issuemsg $issuefile]
}
}
# reset implicit_default to restore behavior defined
unsetConf implicit_default
# prepare string translation to highlight search query string
set matchmodmap [prepareMapToHightlightSubstr {*}$mod_pattern_list]
set matchsearchmap [prepareMapToHightlightSubstr $search]
# interpret all modulefile we got for each modulepath
foreach dir $dir_list {
if {[info exists interp_save($dir)]} {
array unset interp_list
array set interp_list $interp_save($dir)
set foundmod 1
set display_list {}
# interpret every modulefiles obtained to get their whatis text
foreach elt [lsort -dictionary [array names interp_list]] {
set ::g_whatis {}
##nagelfar ignore Suspicious variable name
execute-modulefile $interp_list($elt) $elt $elt $elt 0 0
# treat whatis as a multi-line text
if {$search eq {} || [regexp -nocase $search $::g_whatis]} {
if {$json} {
lappend display_list [formatListEltToJsonDisplay $elt\
whatis a $::g_whatis 1]
} else {
set eltsgr [string map $matchmodmap $elt]
foreach line $::g_whatis {
set linesgr [string map $matchsearchmap $line]
lappend display_list "[string repeat { } [expr {20 -\
[string length $elt]}]]$eltsgr: $linesgr"
}
}
}
}
displayElementList $dir mp sepline 1 0 0 $display_list
}
}
lpopState mode
setState inhibit_errreport 0
# report errors if a modulefile was searched but not found
if {{wild} ni $searchmod && !$foundmod} {
# no error registered means nothing was found to match search
if {![array exists err_list]} {
foreach mod_pattern $mod_pattern_list {
set err_list($mod_pattern) [list none "Unable to locate a\
modulefile for '$mod_pattern'"]
}
}
foreach elt [array names err_list] {
reportIssue {*}$err_list($elt)
}
}
}
# Intermediate procedure between module and cmdModuleSwitch
# Adapt options and arguments depending on context to call cmdModuleSwitch
proc cmdModuleIntSwitch {mode tag_list args} {
# pass 'user asked state' to switch procedure
set uasked [isTopEvaluation]
# CAUTION: it is not recommended to use the `switch` sub-command in
# modulefiles as this command is intended for the command-line for a 2in1
# operation. Could be removed from the modfile scope in a future release.
# Use `module unload` and `module load` commands in modulefiles instead.
if {$uasked || $mode eq {load}} {
set ret [cmdModuleSwitch $uasked $tag_list {*}$args]
if {!$uasked && $ret && ![getState force]} {
knerror {} MODULES_ERR_SUBFAILED
}
} else {
# find what has been asked for unload and load
lassign $args swunmod swlomod
if {$swlomod eq {} && $swunmod ne {}} {
set swlomod $swunmod
}
# apply same mechanisms than for 'module load' and 'module unload' for
# an unload evaluation: nothing done for switched-off module and unload
# of switched-on module. If auto handling is enabled switched-on module
# is handled via UReqUn mechanism (unless if implicit_requirement has
# been inhibited). Also unloads are triggered by ongoing reload, purge,
# restore, reset, stash or stashpop cmds
if {(![getConf auto_handling] || [getState inhibit_req_record] eq\
[currentState evalid]) && $swlomod ne {} && [aboveCommandName] ni\
[list purge reload restore reset stash stashpop]} {
# unload mod if it was loaded prior this mod, not user asked and not
# required by another loaded module
set modlist [getEnvLoadedModulePropertyParsedList name]
set modidx [lsearch -exact $modlist [currentState modulename]]
if {$modidx != 0} {
set priormodlist [lrange $modlist 0 $modidx]
if {[set unmod [getLoadedMatchingName $swlomod {} 0\
$priormodlist]] ne {}} {
cmdModuleUnload urequn match 1 s 1 $unmod
}
}
}
}
}
proc cmdModuleSwitch {uasked tag_list old {new {}}} {
# if a single name is provided it matches for the module to load and in
# this case the module to unload is searched to find the closest match
# (loaded module that shares at least the same root name)
if {$new eq {}} {
set new $old
set unload_match close
} else {
set unload_match match
}
# save orig names to register them as deps if called from modulefile
set argnew $new
if {$new eq $old} {
set argold {}
} else {
set argold $old
}
reportDebug "old='$old' new='$new' (uasked=$uasked)"
# extend requirement recording inhibition to switch subcontext
set inhibit_req_rec [expr {[currentState inhibit_req_record] ==\
[currentState evalid]}]
# record sumup messages from underlying unload/load actions under the same
# switch message record id to report (evaluation messages still go under
# their respective unload/load block
if {$uasked} {
pushMsgRecordId switch-$old-$new-[depthState modulename]
}
if {$inhibit_req_rec} {
lappendState inhibit_req_record [currentState evalid]
}
pushSettings
# enable unload of sticky mod if stickiness is preserved on swapped-on mod
# need to resolve swapped-off module here to get stickiness details
lassign [getPathToModule $old {} 0 $unload_match] modfile oldmod oldmodvr
set swunmod_is_supersticky [isModuleTagged $oldmod super-sticky 1 $modfile]
lassign [getPathToModule $new {} 0] newmodfile newmod newmodvr
set sticky_reload [isStickinessReloading $oldmodvr [list $newmodvr]]
set supersticky_reload [isStickinessReloading $oldmodvr [list $newmodvr]\
super-sticky]
set report_newmod_issue 0
# do not set sticky or supersticky reload states if swap-on module cannot
# be found
if {($supersticky_reload || $sticky_reload) && $newmodfile eq {}} {
set report_newmod_issue 1
set sticky_reload 0
set supersticky_reload 0
}
if {$sticky_reload} {
lappendState reloading_sticky $oldmod
}
if {$supersticky_reload} {
lappendState reloading_supersticky $oldmod
}
##nagelfar implicitvarcmd {cmdModuleUnload swunload *} oldhidden olduasked\
oldmsgrecid
set ret_unload [cmdModuleUnload swunload $unload_match 1 s 0 $old]
if {$sticky_reload} {
lpopState reloading_sticky
}
if {$supersticky_reload} {
lpopState reloading_supersticky
}
# register modulefile to unload as conflict if an unload module is
# mentioned on this module switch command set in a modulefile
# skip conflict declaration if old spec matches new as in this case switch
# means *replace loaded version of mod by this specific version*
if {!$uasked && $argold ne {} && ($newmod eq {} || ![modEq $argold $newmod\
eqstart])} {
registerCurrentModuleConflict $argold
}
# attempt load and depre reload only if unload succeed (or if top switch
# evaluation has "continue on error" behavior enabled and switched-off
# module is not super-sticky or if sub-evaluation is forced)
if {!$ret_unload || ([isTopEvaluation] && ![commandAbortOnError] &&\
![commandAbortOnError switch_unload] && !$swunmod_is_supersticky) ||
(![isTopEvaluation] && [getState force])} {
##nagelfar implicitvarcmd {cmdModuleLoad swload *} newhidden newmsgrecid
set ret_load [cmdModuleLoad swload $uasked 0 0 $tag_list {} $new]
# rollback settings if load evaluation went wrong and abort behavior is
# enabled for this switch phase
if {$ret_load && [commandAbortOnError]} {
restoreSettings
} else {
set ret_auto 0
if {[getConf auto_handling] && [isTopEvaluation]} {
removeUReqUnFromDepReAndConvertEval
unloadUReqUnModules
# DepRe load phase now other mechanisms are done
# Try DepRe load phase: load failure will not make switch fail
if {[set ret_auto [catch {
reloadDepReModules
} errMsg]]} {
reportError $errMsg
restoreSettings
}
}
# report a summary of automated evaluations if no error
if {!$ret_auto && $uasked} {
reportModuleEval
}
}
} else {
# re-run switched-on module search to report locating issue
if {$report_newmod_issue} {
getPathToModule $new
}
# initialize dummy load phase msg rec id to query designation
set newmsgrecid {}
}
popSettings
# report all recorded sumup messages for this evaluation unless both old
# and new modules are set hidden, old was auto loaded and this switch is
# done by a modfile
if {$uasked} {
reportMsgRecord "Switching from [getModuleDesignation $oldmsgrecid {}\
2] to [getModuleDesignation $newmsgrecid $new 2]" [expr {$oldhidden\
&& !$olduasked && $newhidden && !$uasked}]
popMsgRecordId
}
if {$inhibit_req_rec} {
lpopState inhibit_req_record
}
# register modulefile load attempt as prereq when called from modulefile
if {!$uasked && [info exists ret_load] && $argnew ne {}} {
prereqAnyModfileCmd 0 0 $argnew
}
return [expr {$ret_unload || $ret_load}]
}
proc cmdModuleSave {{coll default}} {
if {![areModuleConstraintsSatisfied]} {
reportErrorAndExit {Cannot save collection, some module constraints are\
not satisfied}
}
# format collection content, version number of modulefile are saved if
# version pinning is enabled
if {[getConf collection_pin_version]} {
set curr_mod_list [getLoadedModuleWithVariantList]
set curr_tag_arrser [getLoadedModuleWithVariantSaveTagArrayList]
} else {
lassign [getSimplifiedLoadedModuleList] curr_mod_list curr_tag_arrser
}
# generate collection content with header indicating oldest Modules version
# compatible with collection syntax
set coll_header [expr {[llength $curr_tag_arrser] ? {#%Module5.1} :\
{}}]
set save [formatCollectionContent [getModulePathList returnempty 0]\
$curr_mod_list $curr_tag_arrser $coll_header]
if {![string length $save]} {
reportErrorAndExit {Nothing to save in a collection}
}
# get corresponding filename and its directory
lassign [findCollections $coll name] collfile colldesc
set colldir [file dirname $collfile]
if {![file exists $colldir]} {
reportDebug "Creating $colldir"
if {[catch {file mkdir $colldir} errMsg]} {
reportErrorAndExit "Collection directory cannot be created.\n$errMsg"
}
} elseif {![file isdirectory $colldir]} {
reportErrorAndExit "$colldir exists but is not a directory"
}
reportDebug "Saving $collfile"
if {[catch {
set fid [open $collfile w]
puts $fid $save
close $fid
} errMsg ]} {
reportErrorAndExit "Collection $colldesc cannot be saved.\n$errMsg"
}
}
proc cmdModuleRestore {args} {
# distinguish between zero and one argument provided
if {![llength $args]} {
set arg_provided 0
set coll default
} else {
set arg_provided 1
set coll [lindex $args 0]
}
# get corresponding collection, raise error if it does not exist unless
# if no collection name has been provided or if __init__
lassign [findCollections $coll exact [expr {!$arg_provided}]\
$arg_provided] collfile colldesc
# forcibly enable implicit_default to restore colls saved in this mode
setConf implicit_default 1
# fetch collection content and differences compared current environment
lassign [getDiffBetweenCurEnvAndColl $collfile $colldesc] coll_path_list\
coll_mod_list coll_tag_arrser coll_nuasked_list mod_to_unload\
mod_to_load path_to_unuse path_to_use is_tags_diff
array set coll_tag_arr $coll_tag_arrser
# create an eval id to track successful/failed module evaluations
pushMsgRecordId restore-$coll-[depthState modulename] 0
# unload modules one by one (no dependency auto unload)
foreach mod [lreverse $mod_to_unload] {
# test stickiness over full module name version variant designation
set modvr [getAndParseLoadedModuleWithVariant $mod]
# sticky modules can be unloaded when restoring collection
lappendState unloading_sticky $mod
if {[set supersticky_reload [isStickinessReloading $modvr $mod_to_load\
super-sticky]]} {
lappendState reloading_supersticky $mod
}
cmdModuleUnload unload match 0 s 0 $mod
lpopState unloading_sticky
if {$supersticky_reload} {
lpopState reloading_supersticky
}
}
# unuse paths
if {[llength $path_to_unuse]} {
cmdModuleUnuse load {*}[lreverse $path_to_unuse]
}
# since unloading a module may unload other modules or
# paths, what to load/use has to be determined after
# the undo phase, so current situation is fetched again
set curr_path_list [getModulePathList returnempty 0]
set curr_mod_list [getEnvLoadedModulePropertyParsedList name]
set curr_nuasked_list [getTaggedLoadedModuleList auto-loaded]
# update tags sets on the modules already loaded at correct position
# remove extra tags that are not defined in collection
foreach modvr [getLoadedModuleWithVariantList] {
if {[info exists coll_tag_arr($modvr)]} {
set tag_list $coll_tag_arr($modvr)
} else {
set tag_list {}
}
# indicate if module has been asked by user
cmdModuleTag 1 [expr {![isModuleTagged $modvr auto-loaded 1]}]\
$tag_list $modvr
}
# determine what module to load to restore collection from current
# situation with preservation of the load order
# list of alternative and simplified names for loaded modules has been
# gathered and cached during the previous getMovementBetweenList call on
# modules, so here the getMovementBetweenList call will correctly get these
# alternative names for module comparison even if no modulepath is left set
lassign [getMovementBetweenList $curr_mod_list $coll_mod_list\
$curr_nuasked_list $coll_nuasked_list modeq] mod_to_unload mod_to_load
# proceed as well for modulepath
lassign [getMovementBetweenList $curr_path_list $coll_path_list] \
path_to_unuse path_to_use
# reset implicit_default to restore behavior defined
unsetConf implicit_default
# use paths
if {[llength $path_to_use]} {
# always append path here to guaranty the order
# computed above in the movement lists
cmdModuleUse load append {*}$path_to_use
}
# load modules one by one with user asked state preserved
foreach mod $mod_to_load {
cmdModuleLoad load [expr {$mod ni $coll_nuasked_list}] 0 0\
$coll_tag_arr($mod) {} $mod
}
popMsgRecordId 0
}
proc cmdModuleSaverm {{coll default}} {
# avoid to remove any kind of file with this command
if {[string first / $coll] > -1} {
reportErrorAndExit {Command does not remove collection specified as\
filepath}
}
# get corresponding collection, raise error if it does not exist, but do
# not check if collection is valid
lassign [findCollections $coll exact 0 1 0] collfile colldesc
# attempt to delete specified collection
if {[catch {
file delete $collfile
} errMsg ]} {
reportErrorAndExit "Collection $colldesc cannot be removed.\n$errMsg"
}
}
proc cmdModuleSaveshow {args} {
# distinguish between zero and one argument provided
if {![llength $args]} {
set arg_provided 0
set coll default
} else {
set arg_provided 1
set coll [lindex $args 0]
}
# get corresponding collection, raise error if it does not exist unless
# if no collection name has been provided or if __init__
lassign [findCollections $coll exact [expr {!$arg_provided}]\
$arg_provided] collfile colldesc
# read specific __init__ collection from __MODULES_LMINIT env var
if {$collfile eq {__init__}} {
lassign [parseCollectionContent [getEnvLoadedModulePropertyParsedList\
init]] coll_path_list coll_mod_list coll_tag_arrser
set collfile {initial environment}
set coll __init__
} else {
lassign [readCollectionContent $collfile $colldesc] coll_path_list\
coll_mod_list coll_tag_arrser
}
# collection should at least define a path or a mod, but initial env may be
# totally empty
if {$coll ne {__init__} && ![llength $coll_path_list] && ![llength\
$coll_mod_list]} {
reportErrorAndExit "$colldesc is not a valid collection"
}
displaySeparatorLine
report [sgr hi $collfile]:\n
report [formatCollectionContent $coll_path_list $coll_mod_list\
$coll_tag_arrser {} 1]
displaySeparatorLine
}
proc cmdModuleSavelist {show_oneperline show_mtime search_match args} {
# if a target is set, only list collection matching this target (means
# having target as suffix in their name) unless if --all option is set
set colltarget [getConf collection_target]
if {$colltarget ne {} && [getState hiding_threshold] < 2} {
set suffix .$colltarget
set targetdesc " (for target \"$colltarget\")"
} else {
set suffix {}
set targetdesc {}
}
set json [isStateEqual report_format json]
reportDebug "list collections$targetdesc"
# if only stash collection are expected, start result index at 0, sort
# results in reverse order (latest first) and ensure only collection from
# current target (and no-target if none set) are returned.
if {[getCallingProcName] eq {cmdModuleStashlist}} {
set start_idx 0
set sort_opts [list -dictionary -decreasing]
set find_no_other_target 1
set typedesc stash
# no icase match as stash collections are only lowercases
set icase 0
} else {
set start_idx 1
set sort_opts [list -dictionary]
set find_no_other_target 0
set typedesc named
set icase [isIcase]
}
if {[llength $args]} {
defineModEqProc $icase 0
# match passed name against any part of collection names
set mtest [expr {{contains} in $search_match ? {matchin} : {match}}]
}
# prepare header message which depend if search is performed (no search
# considered if listing stash collections)
if {[llength $args] && $typedesc ne {stash}} {
set collmsg "Matching $typedesc collection list$targetdesc:"
} else {
set collmsg "[string totitle $typedesc] collection list$targetdesc:"
}
foreach collfile [findCollections * glob 0 0 1 $find_no_other_target] {
# remove target suffix from names to display
regsub $suffix$ [file tail $collfile] {} coll
# filter stash collections unless called by stashlist or --all opt set
if {$typedesc ne {named} || ![regexp {stash-\d+} $coll] || [getState\
hiding_threshold] >= 2} {
set coll_arr($coll) $collfile
}
}
# same header msg if no collection at all whether search is made or not
if {![array exists coll_arr] || $typedesc eq {stash}} {
set nocollmsg "No $typedesc collection$targetdesc."
} else {
set nocollmsg "No matching $typedesc collection$targetdesc."
}
# filter collection not matching any of the passed specification
if {[llength $args]} {
set matchlist [list]
foreach coll [array names coll_arr] {
set match 0
foreach pattern $args {
# compare pattern against collections using comparison module proc
# useful for suffix/prefix/icase checks, disabling module-specific
# checks (variants, alternative names, etc)
if {[modEq $pattern $coll $mtest 0 0 0 0 *]} {
set match 1
break
}
}
if {!$match} {
unset coll_arr($coll)
}
}
}
if {![array size coll_arr]} {
if {!$json} {
report $nocollmsg
}
} else {
if {!$json} {
if {$show_mtime} {
displayTableHeader hi Collection 59 {Last mod.} 19
}
report $collmsg
}
set display_list {}
set len_list {}
set max_len 0
set one_per_line [expr {$show_mtime || $show_oneperline}]
set show_idx [expr {!$one_per_line}]
# prepare query to highlight
set himatchmap [prepareMapToHightlightSubstr {*}$args]
foreach coll [lsort {*}$sort_opts [array names coll_arr]] {
if {$json} {
lappend display_list [formatListEltToJsonDisplay $coll target s\
$colltarget 1 pathname s $coll_arr($coll) 1]
# no need to test coll consistency as findCollections does not return
# collection whose name starts with "."
} else {
set collsgr [sgr {} $coll $himatchmap]
if {$show_mtime} {
set filetime [clock format [getFileMtime $coll_arr($coll)]\
-format {%Y/%m/%d %H:%M:%S}]
lappend display_list [format %-60s%19s $collsgr $filetime]
} else {
lappend display_list $collsgr
lappend len_list [set len [string length $coll]]
if {$len > $max_len} {
set max_len $len
}
}
}
}
displayElementList noheader {} {} $one_per_line $show_idx $start_idx\
$display_list $len_list $max_len
}
}
proc cmdModuleSource {mode args} {
foreach mod $args {
set rawarg [getRawArgumentFromVersSpec $mod]
if {$mod eq {}} {
reportErrorAndExit {File name empty}
# first check if raw specification is an existing file
} elseif {[file exists [set absfpath [getAbsolutePath $rawarg]]]} {
set modfile $absfpath
set modname $absfpath
set modnamevr $absfpath
# unset module specification not to confuse specific char in file
# path (like '+') with variant specification
unsetModuleVersSpec $mod
set mod $absfpath
# if not a path specification, try to resolve a modulefile
} elseif {![isModuleFullPath $rawarg]} {
lassign [getPathToModule $mod] modfile modname modnamevr
# stop if no module found, issue has been reported by getPathToModule
if {$modfile eq {}} {
break
}
} else {
reportErrorAndExit "File $rawarg does not exist"
}
##nagelfar ignore Found constant
lappendState mode $mode
# sourced file must also have a magic cookie set at their start
##nagelfar ignore Suspicious variable name
execute-modulefile $modfile $modname $modnamevr $mod 1 0 0
##nagelfar ignore Found constant
lpopState mode
}
}
# Intermediate procedure between module and cmdModuleLoad/prereq
# Adapt options and arguments depending on context to call cmdModuleLoad or
# one of the prereq procedures
proc cmdModuleIntLoad {topcall command mode tag_list args} {
# ignore flag used in collection to track non-user asked state
set args [replaceFromList $args --notuasked]
# no error raised on empty argument list to cope with initadd command that
# may expect this behavior
if {![llength $args]} {
return
}
set ret 0
# if top command is source, consider module load commands made within
# sourced file evaluation as top load command
if {[isTopEvaluation]} {
# is eval a regular attempt or a try (silence not found error)
set tryload [expr {$command in {try-load load-any}}]
set loadany [expr {$command eq {load-any}}]
set ret [cmdModuleLoad load 1 $tryload $loadany $tag_list {} {*}$args]
} elseif {$mode eq {load}} {
# auto load is inhibited if currently in DepRe context only register
# requirement
set subauto [expr {[currentModuleEvalContext] eq {depre} ? {0} : {1}}]
if {$command eq {try-load}} {
# attempt load of not already loaded modules
if {$subauto} {
foreach arg $args {
lassign [loadRequirementModuleList 1 0 $tag_list {} $arg] retlo
# update return value if an issue occurred unless force mode is
# enabled
if {$retlo != 0 && ![getState force]} {
set ret $retlo
}
# record requirement prior raising error
prereqAllModfileCmd 1 0 --optional --tag [join $tag_list :]\
$arg
# report error message and raise error
if {$retlo != 0} {
reportMissingPrereqError [currentState modulenamevr] {} $arg
}
}
} else {
# record requirement as optional: no error if not loaded but
# reload will be triggered if loaded later on
prereqAllModfileCmd 1 0 --optional --tag [join $tag_list :]\
{*}$args
}
} elseif {$command eq {load-any}} {
# load and register requirement in a OR-operation
prereqAnyModfileCmd 1 $subauto --tag [join $tag_list :] {*}$args
} else {
# load and register requirement in a AND-operation
prereqAllModfileCmd 0 $subauto --tag [join $tag_list :] {*}$args
}
# mods unload is handled via UReqUn mechanism when auto enabled (unless if
# implicit_requirement has been inhibited) also unloads are triggered by
# ongoing reload, purge, restore, reset, stash or stashpop cmds
} elseif {(![getConf auto_handling] || [getState inhibit_req_record] eq\
[currentState evalid]) && [aboveCommandName] ni [list purge reload\
restore reset stash stashpop]} {
# on unload mode, unload mods in reverse order, if loaded prior this
# mod, if not user asked and not required by other loaded mods
set modlist [getEnvLoadedModulePropertyParsedList name]
set modidx [lsearch -exact $modlist [currentState modulename]]
if {$modidx != 0} {
set priormodlist [lrange $modlist 0 $modidx]
foreach arg [lreverse $args] {
if {[set unmod [getLoadedMatchingName $arg {} 0 $priormodlist]]\
ne {}} {
cmdModuleUnload urequn match 1 s 1 $unmod
}
}
}
}
# sub-module interpretation failed, raise error
if {$ret && !$topcall} {
knerror {} MODULES_ERR_SUBFAILED
}
}
proc cmdModuleLoad {context uasked tryload loadany tag_list modulepath_list\
args} {
reportDebug "loading $args (context=$context, uasked=$uasked,\
tryload=$tryload, loadany=$loadany, tag_list=$tag_list,\
modulepath_list=$modulepath_list)"
set ret 0
set one_mod_loaded 0
lappendState mode load
foreach mod $args {
set mod_load_in_error 0
# stop when first module in list is loaded if any mode enabled
if {$one_mod_loaded && $loadany} {
break
}
# if a switch action is ongoing...
if {$context eq {swload}} {
set swprocessing 1
# context is ReqLo if switch is called from a modulefile
if {![isTopEvaluation]} {
set context reqlo
}
upvar newhidden hidden
upvar newmsgrecid msgrecid
}
lappendState eval_context $context
# loading module is visible by default
set hidden 0
# error if module not found or forbidden
set notfounderr [expr {!$tryload}]
# first try to resolve over loaded mods unless spec corresponds to
# multiple module designations, otherwise search avail mods
unset -nocomplain modfile
if {[getCmpSpecFromVersSpec $mod] eq {eq}} {
lassign [getPathToModule $mod $modulepath_list 0 exact] modfile\
modname modnamevr
}
if {![info exists modfile] || ![string length $modfile]} {
lassign [getPathToModule $mod $modulepath_list $notfounderr] modfile\
modname modnamevr
}
# record evaluation attempt on specified module name
registerModuleEvalAttempt $context $mod $modfile
# set a unique id to record messages related to this evaluation.
set msgrecid load-$modnamevr-[depthState modulename]
# go to next module to load if not matching module found
if {$modfile eq {}} {
set ret $notfounderr
continue
}
if {[isModuleEvalFailed load $modnamevr]} {
reportDebug "$modnamevr ($modfile) load was already tried and failed"
# nullify this evaluation attempt to avoid duplicate issue report
unregisterModuleEvalAttempt $context $mod $modfile
continue
}
# if a switch action is ongoing...
if {[info exists swprocessing]} {
# transmit loaded mod name for switch report summary
uplevel 1 set new "{$modnamevr}"
}
# register record message unique id (now we know mod will be evaluated)
pushMsgRecordId $msgrecid
# record evaluation attempt on actual module name
registerModuleEvalAttempt $context $modnamevr $modfile
registerModuleEvalAttempt $context $modfile $modfile
# check if passed modname correspond to an already loaded modfile
# and get its loaded name (in case it has been loaded as full path)
set loadedmodname [getLoadedMatchingName $modnamevr]
if {$loadedmodname ne {}} {
set modname $loadedmodname
set modnamevr [getAndParseLoadedModuleWithVariant $modname]
}
# record module title (with the variant specified on load call, and no
# tag list) prior module evaluation to get this title ready in case of
# eval error
registerModuleDesignation $msgrecid $modname [getVariantList $mod 7 0\
1] {}
pushSettings
if {[set errCode [catch {
if {[set isloaded [isModuleLoaded $modname]]} {
set isloading 0
} else {
set isloading [isModuleLoading $modname]
}
if {$isloaded || $isloading} {
# stop if same mod is loaded but from a modulepath not part of
# constrained list
if {($isloaded && ![isLoadedMatchSpecificPath $modname\
$modulepath_list]) || ($isloading &&\
![isLoadingMatchSpecificPath $modname $modulepath_list])} {
# no error if ConUn mechanism handles unload of this module
if {![getConf auto_handling] || ![getConf conflict_unload] ||\
$isloading} {
knerror [getModFromDiffPathIsLoadedMsg]
}
# stop if same mod is loaded but with a different set of variants
} elseif {[isOtherVariantOfModuleLoaded $modnamevr] ||\
[isOtherVariantOfModuleLoading $modnamevr]} {
# no error if ConUn mechanism handles unload of this module
if {![getConf auto_handling] || ![getConf conflict_unload] ||\
$isloading} {
knerror [getModWithAltVrIsLoadedMsg $modname $isloading]
}
} else {
reportDebug "$modname ($modfile) already loaded/loading"
# apply missing tag to loaded module
set rettag [cmdModuleTag 0 $uasked $tag_list $modname]
# report module is already loaded if verbose2 or higher level
# and no new tag set
if {$isloaded && $rettag != 2 && [isVerbosityLevel verbose2]} {
reportInfo "Module '$modname' is already loaded"
registerModuleDesignation $msgrecid $modname\
[getVariantList $modname 7] [getExportTagList $modname]
reportMsgRecord "Loading [getModuleDesignation $msgrecid {}\
2]"
}
# exit treatment but no need to restore settings
set one_mod_loaded 1
continue
}
}
if {[isTopEvaluation] && ![info exists swprocessing]} {
clearLoadedReqOfReloadingModuleList
clearLoadedReqOfUnloadingModuleList
clearUReqUnFromDepReList
clearDepReList
}
set unload_mod_list {}
# register altname of modname prior any conflict check
setLoadedAltname $modname {*}[getAllModuleResolvedName $modname 1\
$mod]
if {[getConf auto_handling]} {
if {[getConf conflict_unload]} {
# get loaded conflicting modules and unload them (ConUn)
set conun_mod_list [getModuleLoadedConflict $modnamevr\
$modulepath_list]
reportDebug "conun mod list is '$conun_mod_list'"
if {[llength $conun_mod_list]} {
foreach conun_mod [lreverse $conun_mod_list] {
if {[cmdModuleUnload conun match 1 s 0 $conun_mod]} {
# error message already sent within cmdModuleUnload
knerrorOrWarningIfForced {}
}
}
}
lappend unload_mod_list {*}$conun_mod_list
}
# get loaded modules holding a requirement on modname and able to
# be reloaded
set depre_list [getUnmetDependentLoadedModuleList $modnamevr\
$modfile]
reportDebug "depre mod list is '$depre_list'"
if {[isTopEvaluation]} {
saveLoadedReqOfReloadingModuleList $depre_list $unload_mod_list
identityUReqUnFromDepRe $depre_list $unload_mod_list
}
# Reload all modules that have declared a prereq on mod as they
# may take benefit from their prereq availability if it is newly
# loaded. First perform unload phase of the reload, prior mod load
# to ensure these dependent modules are unloaded with the same
# loaded prereq as when they were loaded
unloadDepUnDepReModules {} $depre_list
}
# record additional tags passed through --tag option prior mod eval
# to make them known within evaluation
if {[llength $tag_list]} {
# record tags set with --tag as extra tag excluding tags relative
# to the way module is loaded (auto, keep)
lassign [getDiffBetweenList $tag_list [list auto-loaded\
keep-loaded]] extratag_list
setModuleAndVariantsTag $modname $modnamevr {*}$tag_list
if {[llength $extratag_list]} {
setModuleAndVariantsExtraTag $modname $modnamevr\
{*}$extratag_list
}
}
if {!$uasked} {
# set auto-loaded tag now to be able to query it during eval
setModuleAndVariantsTag $modname $modnamevr auto-loaded
# hide auto loaded modules if hide_auto_loaded config is enabled
if {[getConf hide_auto_loaded]} {
setModuleAndVariantsTag $modname $modnamevr hidden-loaded
}
}
if {[execute-modulefile $modfile $modname modnamevr $mod $uasked]} {
break
}
# register this evaluation on the main one that triggered it (after
# load evaluation to report correct order with other evaluations)
registerModuleEval $context $msgrecid
# loading visibility depends on hidden-loaded tag
set hidden [isModuleTagged $modnamevr hidden-loaded 1 $modfile]
append-path LOADEDMODULES $modname
# allow duplicate modfile entries for virtual modules
append-path --duplicates _LMFILES_ $modfile
# update cache arrays
setLoadedModule $modname $modfile $uasked $modnamevr [expr {$modname\
in [getState refresh_qualified]}]
# register declared source-sh in environment
setEnvLoadedModuleProperty $modname sourcesh [getLoadedSourceSh\
$modname]
# register declared conflict in environment
setEnvLoadedModuleProperty $modname conflict [getLoadedConflict\
$modname]
# declare the prereq of this module
setEnvLoadedModuleProperty $modname prereq [getLoadedPrereq\
$modname]
setEnvLoadedModuleProperty $modname prereqpath [getLoadedPrereqPath\
$modname]
setEnvLoadedModuleProperty $modname use [getLoadedUse $modname]
# declare the alternative names of this module
setEnvLoadedModuleProperty $modname altname [getLoadedAltname\
$modname {sym alias autosym} 1]
# declare the variant of this module
setEnvLoadedModuleProperty $modname variant [getLoadedVariant\
$modname]
# declare the tags of this module
setEnvLoadedModuleProperty $modname tag [getExportTagList $modnamevr\
$modfile]
setEnvLoadedModuleProperty $modname extratag [getExtraTagList\
$modnamevr]
setEnvLoadedModuleProperty $modname stickyrule [getStickyRuleList\
$modnamevr $modfile]
# declare module qualified for refresh evaluation
if {[isModuleRefreshQualified $modname]} {
append-path __MODULES_LMREFRESH $modname
}
if {[getConf auto_handling] && [isTopEvaluation] && ![info exists\
swprocessing]} {
# UReqUn: Useless Requirement to Unload (autoloaded requirements
# not required by any remaining mods)
removeUReqUnFromDepReAndConvertEval
unloadUReqUnModules
# Load phase of dependent module reloading. These modules now can
# adapt since mod is seen loaded.
reloadDepReModules
}
# record module title (name, variants and tags)
registerModuleDesignation $msgrecid $modname [getVariantList\
$modname 7] [getExportTagList $modname $modfile]
# consider evaluation hidden if hidden loaded module is auto loaded
# and no specific messages are recorded for this evaluation
if {$hidden && !$uasked && ![isMsgRecorded]} {
registerModuleEvalHidden $context $msgrecid
}
# report a summary of automated evaluations if no error
reportModuleEval
} errMsg]] != 0 && $errCode != 4} {
set mod_load_in_error 1
# in case of error report module info even if set hidden
set hidden 0
reportError $errMsg
# rollback settings if some evaluation went wrong
set ret 1
restoreSettings
# remove from successfully evaluated module list
registerModuleEval $context $msgrecid $modnamevr load
}
popSettings
# report all recorded messages for this evaluation except if module were
# already loaded
if {$errCode != 4} {
reportMsgRecord "Loading [getModuleDesignation $msgrecid {} 2]"\
[expr {$hidden && !$uasked}]
}
popMsgRecordId
if {$mod_load_in_error} {
# report load issue on the message block of the above action
switch -- $context {
swload {
reportError "Load of switched-on [getModuleDesignation\
$msgrecid] failed"
}
}
}
if {!$mod_load_in_error} {
set one_mod_loaded 1
}
# abort evaluation if error and behavior configured this way (abort
# means stop to evaluate modulefile and flush changes of previous ones)
# applies to top evaluation context for supported sub-commands
if {$ret && $context eq {load} && [commandAbortOnError]} {
flushEnvSettings
break
}
}
lpopState eval_context
lpopState mode
# raise error if no module has been loaded or has produced an error during
# its load attempt in case of top-level load-any sub-command
if {!$ret && !$one_mod_loaded && $context eq {load} && $loadany} {
knerror "No module has been loaded"
}
return $ret
}
# Intermediate procedure between module and cmdModuleUnload
# Adapt options and arguments depending on context to call cmdModuleUnload
proc cmdModuleIntUnload {mode args} {
# if top command is source, consider module load commands made within
# sourced file evaluation as top load command
if {[isTopEvaluation]} {
set ret [cmdModuleUnload unload match 1 s 0 {*}$args]
} elseif {$mode eq {load}} {
# unload mods only on load mode, nothing done on unload mode as the
# registered conflict guarantees the target module cannot be loaded
# unless forced
# enable auto unload and allow force mode if both auto handling and
# conflict unload features are enabled
if {[getConf conflict_unload] && [getConf auto_handling]} {
set conun_mod_list {}
foreach conun_arg $args {
# unload attempt in reverse load order
appendNoDupToList conun_mod_list {*}[lreverse\
[getLoadedMatchingName $conun_arg returnall]]
}
set ret 0
foreach conun_mod $conun_mod_list {
if {[cmdModuleUnload conun match 1 s 0 $conun_mod] && ![getState\
force]} {
set ret 1
break
}
}
# otherwise module required by others are not unloaded and force mode is
# disabled
} else {
set ret [cmdModuleUnload conun match 0 0 0 {*}$args]
}
# register modulefiles to unload as individual conflicts
registerCurrentModuleConflict {*}$args
# sub-module interpretation failed, raise error unless if forced
if {$ret && ![getState force]} {
knerror {} MODULES_ERR_SUBFAILED
}
}
}
proc cmdModuleUnload {context match auto force onlyureq args} {
reportDebug "unloading $args (context=$context, match=$match, auto=$auto,\
force=$force, onlyureq=$onlyureq)"
# inherit force mode from force state if asked through arg
if {$force eq {s}} {
##nagelfar ignore Found constant
set force [getState force]
}
set ret 0
lappendState mode unload
foreach mod $args {
set mod_unload_in_error 0
# if a switch action is ongoing...
if {$context eq {swunload}} {
set swprocessing 1
# context is ConUn if switch is called from a modulefile
if {![isTopEvaluation]} {
set context conun
}
upvar oldhidden hidden
upvar olduasked uasked
upvar oldmsgrecid msgrecid
}
lappendState eval_context $context
# unloading module is visible by default
set hidden 0
set uasked 1
# resolve by also looking at matching loaded module and update mod
# specification to fully match obtained loaded module
# enable report_issue flag to report empty module name issue
lassign [getPathToModule $mod {} 1 $match] modfile modname\
modnamevr errkind
# record evaluation attempt on specified module name
registerModuleEvalAttempt $context $mod $modfile
# set a unique id to record messages related to this evaluation.
set msgrecid unload-$modnamevr-[depthState modulename]
# record module title (with the variant specified on unload call, and no
# tag list) prior module evaluation to get this title ready in case of
# eval error
registerModuleDesignation $msgrecid $modname [getVariantList $modnamevr\
7 0 1] {}
# if a switch action is ongoing...
if {[info exists swprocessing]} {
# transmit unloaded mod name for switch report summary
uplevel 1 set old "{$modnamevr}"
}
if {$modfile eq {}} {
# no error return if module is not loaded
if {$errkind eq {notloaded}} {
reportDebug "$modname is not loaded"
# report module is not loaded if >=verbose2 and not auto context
if {[isVerbosityLevel verbose2] && $context ni {urequn}} {
pushMsgRecordId $msgrecid
reportInfo "Module '$modname' is not loaded"
reportMsgRecord "Unloading [getModuleDesignation $msgrecid {}\
2]"
popMsgRecordId
}
} else {
# return error code in case of empty module name
set ret 1
}
# go to next module to unload
continue
}
if {$onlyureq && ![isModuleUnloadable $modname\
[getUnloadingModuleList]]} {
reportDebug "$modname ($modfile) is required by loaded module or\
asked by user"
continue
}
if {[isModuleEvalFailed unload $modnamevr]} {
reportDebug "$modnamevr ($modfile) unload was already tried and\
failed"
# nullify this evaluation attempt to avoid duplicate issue report
unregisterModuleEvalAttempt $context $mod $modfile
set ret 1
continue
}
# register record message unique id (now we know mod will be evaluated)
pushMsgRecordId $msgrecid
# record evaluation attempt on actual module name
registerModuleEvalAttempt $context $modnamevr $modfile
registerModuleEvalAttempt $context $modfile $modfile
# record module title (name, variants and tags)
registerModuleDesignation $msgrecid $modname [getVariantList $modname\
7] [getExportTagList $modname]
pushSettings
if {[set errCode [catch {
if {[failOrSkipUnloadIfSticky $modname $modfile]} {
continue
}
# stop unless forced or auto handling mode enabled if unloading
# module violates a registered prereq
set prereq_list [getDependentLoadedModuleList [list $modname]]
set prereq_loaded_list [getDependentLoadedModuleList [list $modname]\
1 1 0 0]
if {[llength $prereq_loaded_list] && (![getConf auto_handling] ||\
!$auto)} {
# force mode should not affect if we only look for mods w/o dep
if {$force} {
# in case unload is called for a DepRe mechanism do not warn
# about prereq violation enforced as it is due to the dependent
# module which is already in a violation state
if {$context ne {depre_un}} {
reportWarning [getDepLoadedMsg $prereq_loaded_list]
}
} else {
knerror [expr {[isModuleEvaluated any $modnamevr {}\
{*}$prereq_loaded_list] ? [getDepLoadedMsg\
$prereq_loaded_list] : [getErrPrereqMsg $prereq_loaded_list\
0]}]
}
}
# stop unless forced if loading module are part of dependent modules
# to unload (means module dependencies are inconsistent)
lassign [getDiffBetweenList $prereq_list $prereq_loaded_list]\
prereq_loading_list
if {[llength $prereq_loading_list]} {
knerrorOrWarningIfForced [getDepLoadingMsg $prereq_loading_list]
}
if {[getConf auto_handling] && $auto} {
# compute lists of modules to update due to modname unload prior
# unload to get requirement info before it vanishes
# DepUn: Dependent to Unload (modules actively requiring modname
# or a module part of this DepUn batch)
set depun_list [getDepUnModuleList $modname]
reportDebug "depun mod list is '$depun_list'"
if {[isTopEvaluation]} {
clearLoadedReqOfReloadingModuleList
clearLoadedReqOfUnloadingModuleList
clearUReqUnFromDepReList
clearDepReList
}
set unload_mod_list [list {*}$depun_list $modname]
# DepRe: Dependent to Reload (modules optionally dependent or in
# conflict with modname, DepUn modules + modules dependent of a
# module part of this DepRe batch)
set depre_list [getDependentLoadedModuleList $unload_mod_list 0 0\
1 0 1 1]
# DepUn mods are merged into the DepRe list if this is a conflict
# unload or an ongoing switch
if {[info exists swprocessing] || $context eq {conun}} {
set depre_list [sortModulePerLoadedAndDepOrder [list\
{*}$depun_list {*}$depre_list] 1]
set depun_list {}
set unload_mod_list [list $modname]
reportDebug "updated depun mod list is '$depun_list'"
reportDebug "updated depre mod list is '$depre_list'"
}
if {[isTopEvaluation]} {
saveLoadedReqOfReloadingModuleList $depre_list $unload_mod_list
identityUReqUnFromDepRe $depre_list $unload_mod_list
}
# Unload DepUn modules and unload DepRe modules (unload phase of
# their reload process). These modules are unloaded prior main mod
# unload and they are mixed to be unloaded in their reverse load
# order. They are unloaded this way prior eventually unloading any
# of their requirements.
unloadDepUnDepReModules $depun_list $depre_list
}
# register this evaluation on the main one that triggered it (prior
# unload evaluation to report correct order with other evaluations)
registerModuleEval $context $msgrecid
# module was asked by user if tagged loaded instead of auto-loaded
set uasked [isModuleTagged $modname loaded 1]
# no need to update modnamevr and tags after evaluation as these
# information were already complete in persistent environment
##nagelfar ignore Suspicious variable name
if {[execute-modulefile $modfile $modname $modnamevr $mod $uasked 0\
0]} {
break
}
# unloading visibility depends on hidden-loaded tag
set hidden [isModuleTagged $modname hidden-loaded 1]
# unset module from list of loaded modules qualified for refresh eval
if {[isModuleRefreshQualified $modname]} {
remove-path __MODULES_LMREFRESH $modname
}
saveLoadedReqOfUnloadingModule $modname
# get module position in loaded list to remove corresponding loaded
# modulefile (entry at same position in _LMFILES_)
# need the unfiltered loaded module list to get correct index
set lmidx [lsearch -exact [getEnvLoadedModulePropertyList name]\
$modname]
remove-path LOADEDMODULES $modname
remove-path --index _LMFILES_ $lmidx
# update cache arrays
unsetLoadedModule $modname $modfile
# unregister declared source-sh
unsetEnvLoadedModuleProperty $modname sourcesh
unsetLoadedSourceSh $modname
# unregister declared conflict
unsetEnvLoadedModuleProperty $modname conflict
unsetLoadedConflict $modname
# unset prereq declared for this module
unsetEnvLoadedModuleProperty $modname prereq
unsetLoadedPrereq $modname
unsetEnvLoadedModuleProperty $modname prereqpath
unsetLoadedPrereqPath $modname
unsetEnvLoadedModuleProperty $modname use
unsetLoadedUse $modname
# unset alternative names declared for this module
unsetEnvLoadedModuleProperty $modname altname
unsetLoadedAltname $modname
# unset variant declared for this module
unsetEnvLoadedModuleProperty $modname variant
unsetLoadedVariant $modname
# unset tags declared for this module
unsetEnvLoadedModuleProperty $modname tag
# also remove tags from in-memory knowledge not to re-apply them if
# module is reloaded in other conditions
unsetModuleAndVariantsTag $modname $modnamevr
unsetEnvLoadedModuleProperty $modname extratag
unsetModuleAndVariantsExtraTag $modname $modnamevr
unsetEnvLoadedModuleProperty $modname stickyrule
if {[getConf auto_handling] && $auto && [isTopEvaluation] &&\
![info exists swprocessing]} {
# UReqUn: Useless Requirement to Unload (autoloaded requirements
# not required by any remaining mods)
removeUReqUnFromDepReAndConvertEval
unloadUReqUnModules
# DepRe modules load phase now DepUn+UReqUn+main mods are unloaded
reloadDepReModules
}
# consider evaluation hidden if hidden loaded module was auto loaded
# and no specific messages are recorded for this evaluation
if {$hidden && !$uasked && ![isMsgRecorded]} {
registerModuleEvalHidden $context $msgrecid
}
# report a summary of automated evaluations if no error
reportModuleEval
} errMsg]] != 0 && $errCode != 4} {
set mod_unload_in_error 1
# report module error even if set hidden
set hidden 0
reportError $errMsg
# rollback settings if some evaluation went wrong
set ret 1
restoreSettings
# remove from successfully evaluated module list
registerModuleEval $context $msgrecid $modnamevr unload
}
popSettings
# report all recorded messages for this evaluation (hide evaluation if
# loaded mod is set hidden, has been automatically loaded and unloaded)
reportMsgRecord "Unloading [getModuleDesignation $msgrecid {} 2]" [expr\
{$hidden && !$uasked && [depthState evalid] != 1}]
popMsgRecordId
if {$mod_unload_in_error} {
# report unload issue on the message block of the above action
switch -- $context {
swunload {
reportError "Unload of switched-off [getModuleDesignation\
loaded $modname] failed"
}
conun {
setConflictErrorAsReported $modname
reportErrorOrWarningIfForced [getErrConUnMsg\
[getModuleDesignation loaded $modname]]
}
urequn {
# warn and do not count urequn unload error
reportWarning "Unload of useless requirement\
[getModuleDesignation loaded $modname] failed"
decrErrorCount
}
}
}
# abort evaluation if error and behavior configured this way (abort
# means stop to evaluate modulefile and flush changes of previous ones)
# applies to top evaluation context for supported sub-commands
if {$ret && $context eq {unload} && [commandAbortOnError]} {
flushEnvSettings
break
}
}
lpopState eval_context
lpopState mode
return $ret
}
proc cmdModulePurge {} {
# create an eval id to track successful/failed module evaluations
pushMsgRecordId purge-[depthState modulename] 0
# unload one by one to ensure same behavior whatever auto_handling state
# force it to handle loaded modules in violation state
# remove dependent modules if force mode enabled
cmdModuleUnload unload match 0 s 0 {*}[lreverse\
[getEnvLoadedModulePropertyParsedList name]]
popMsgRecordId 0
}
proc cmdModuleReload {} {
# reload all loaded modules
set loaded_mod_list [getEnvLoadedModulePropertyParsedList name]
reportDebug "reloading $loaded_mod_list"
# create an eval id to track successful/failed module evaluations
pushMsgRecordId reload-[depthState modulename] 0
# no reload of all loaded modules attempt if constraints are violated
if {![areModuleConstraintsSatisfied]} {
reportError {Cannot reload modules, some of their constraints are not\
satisfied}
} else {
pushSettings
if {[set errCode [catch {
# run unload then load-again phases
set loaded_mod_list [reloadModuleListUnloadPhase $loaded_mod_list]
reloadModuleListLoadPhase $loaded_mod_list
} errMsg]] == 1} {
# rollback settings if some evaluation went wrong
restoreSettings
}
popSettings
}
popMsgRecordId 0
}
proc cmdModuleAliases {} {
# disable error reporting to avoid modulefile errors
# to mix with avail results
inhibitErrorReport
# parse paths to fill g_moduleAlias and g_moduleVersion
foreach dir [getModulePathList exiterronundef] {
getModules $dir {} 0 {}
}
setState inhibit_errreport 0
set display_list {}
foreach name [lsort -dictionary [array names ::g_moduleAlias]] {
# exclude hidden aliases from result
if {![isModuleHidden $name]} {
lappend display_list "[sgr al $name] -> $::g_moduleAlias($name)"
}
}
displayElementList Aliases hi sepline 1 0 0 $display_list
set display_list {}
foreach name [lsort -dictionary [array names ::g_moduleVersion]] {
# exclude hidden versions or versions targeting an hidden module
if {![isModuleHidden $name] && ![isModuleHidden\
$::g_moduleVersion($name)]} {
lappend display_list "[sgr sy $name] -> $::g_moduleVersion($name)"
}
}
displayElementList Versions hi sepline 1 0 0 $display_list
}
proc cmdModuleAvail {show_oneperline show_mtime show_filter search_filter\
search_match modpath_list args} {
if {![llength $args]} {
lappend args *
}
if {$show_mtime || $show_oneperline} {
set one_per_line 1
set hstyle terse
set theader_cols [list hi Package/Alias 39 Versions 19 {Last mod.} 19]
} else {
set one_per_line 0
set hstyle sepline
set theader_cols {}
}
# set a default filter (do not print dirs with no sym) if none set
if {$show_filter eq {}} {
set show_filter noplaindir
}
# elements to include in output
set report_modulepath [isEltInReport modulepath]
# consolidate search filters
lappend search_filter $search_match wild
set search_rc_filter $search_filter
lappend search_rc_filter rc_alias_only
# disable error report to avoid modulefile errors to mix with avail results
inhibitErrorReport
# look if aliases have been defined in the global or user-specific rc
array set mod_list [getMatchingAnyModules {} $args $show_mtime\
$search_rc_filter $show_filter]
if {$report_modulepath} {
reportModules $args {global/user modulerc} hi $hstyle $show_mtime 0\
$one_per_line $theader_cols hidden-loaded
}
foreach dir $modpath_list {
set dir_mod_list [getMatchingAnyModules $dir $args $show_mtime\
$search_filter $show_filter]
if {$report_modulepath} {
array unset mod_list
array set mod_list $dir_mod_list
reportModules $args $dir mp $hstyle $show_mtime 0 $one_per_line\
$theader_cols hidden-loaded
} else {
# add result if not already added from an upper priority modpath
foreach {elt props} $dir_mod_list {
if {![info exists mod_list($elt)]} {
set mod_list($elt) $props
}
}
}
}
# no report by modulepath, mix all aggregated results
if {!$report_modulepath} {
reportModules $args noheader {} {} $show_mtime 0 $one_per_line\
$theader_cols hidden-loaded
}
# display output key
if {!$show_mtime && ![isStateEqual report_format json] && [isEltInReport\
key]} {
displayKey
}
setState inhibit_errreport 0
}
proc runModuleUse {cmd mode pos args} {
if {$args eq {}} {
showModulePath
} else {
if {$pos eq {remove}} {
# get current module path list
set modpathlist [getModulePathList returnempty 0 0]
}
foreach path $args {
switch -glob -- $path {
--remove-on-unload - --append-on-unload - --prepend-on-unload -\
--noop-on-unload {
if {$cmd ne {unuse}} {
knerror "Invalid option '$path'"
} else {
lappend pathlist $path
}
}
-* {
knerror "Invalid option '$path'"
}
{} {
reportError [getEmptyNameMsg directory]
}
$* {
lappend pathlist $path
}
default {
if {$pos eq {remove}} {
if {$path in $modpathlist} {
lappend pathlist $path
# transform given path in an absolute path which should have
# been registered in the MODULEPATH env var. however for
# compatibility with previous behavior where relative paths
# were registered in MODULEPATH given path is first checked
# against current path list
} elseif {[set abspath [getAbsolutePath $path]] in\
$modpathlist} {
lappend pathlist $abspath
# even if not found, transmit this path to remove-path in
# case several path elements have been joined as one string
} else {
lappend pathlist $path
}
} else {
# transform given path in an absolute path to avoid
# dependency to the current work directory. except if this
# path starts with a variable reference
lappend pathlist [getAbsolutePath $path]
}
}
}
}
# added directory may not exist at this time
# pass all paths specified at once to append-path/prepend-path
if {[info exists pathlist]} {
set optlist [list]
# define path command to call
set pathcmd [expr {$pos eq {remove} ? {unload-path} : {add-path}}]
# by-pass any reference counter in case use is called from top level
# not to increase reference counter if paths are already defined
if {[isTopEvaluation]} {
lappend optlist --ignore-refcount
}
if {[isTopEvaluation]} {
##nagelfar ignore Found constant
lappendState mode load
}
$pathcmd $pos-path $mode $pos {*}$optlist MODULEPATH {*}$pathlist
if {[isTopEvaluation]} {
##nagelfar ignore Found constant
lpopState mode
}
}
}
}
proc cmdModuleUse {mode pos args} {
if {$mode eq {unload}} {
set pos remove
}
runModuleUse use $mode $pos {*}$args
}
proc cmdModuleUnuse {mode args} {
runModuleUse unuse $mode remove {*}$args
}
proc cmdModuleAutoinit {} {
# skip autoinit process if found already ongoing in current environment
if {[envVarEquals __MODULES_AUTOINIT_INPROGRESS 1]} {
return
}
# set environment variable to state autoinit process is ongoing
setenv __MODULES_AUTOINIT_INPROGRESS 1
# flag to make renderSettings define the module command
setState autoinit 1
# initialize env variables around module command
lappendState mode load
# register command location
setenv MODULES_CMD [getAbsolutePath $::argv0]
# define current Modules version if versioning enabled
##nagelfar ignore #4 Strange command
@VERSIONING@if {![isEnvVarDefined MODULE_VERSION]} {
@VERSIONING@ setenv MODULE_VERSION @MODULES_RELEASE@@MODULES_BUILD@
@VERSIONING@ setenv MODULE_VERSION_STACK @MODULES_RELEASE@@MODULES_BUILD@
@VERSIONING@}
# initialize MODULEPATH and LOADEDMODULES if found unset
if {![isEnvVarDefined MODULEPATH]} {
setenv MODULEPATH {}
}
if {![isEnvVarDefined LOADEDMODULES]} {
setenv LOADEDMODULES {}
}
# initialize user environment if found undefined (both MODULEPATH and
# LOADEDMODULES empty)
if {[get-env MODULEPATH] eq {} && [get-env LOADEDMODULES] eq {}} {
# set modpaths defined in modulespath config file if it exists
# use .modulespath file in initdir if conf file are located in this dir
if {[file readable {@modulespath@}]} {
set fdata [split [readFile {@modulespath@}] \n]
foreach fline $fdata {
if {[regexp {^\s*(.*?)\s*(#.*|)$} $fline match patharg] &&\
$patharg ne {}} {
foreach path [split $patharg :] {
# resolve path directory in case wildcard character used
set globlist [glob -types d -nocomplain $path]
if {![llength $globlist]} {
lappend pathlist $path
} else {
lappend pathlist {*}$globlist
}
}
}
}
if {[info exists pathlist]} {
cmdModuleUse load append {*}$pathlist
}
}
# source initialization initrc after modulespaths if it exists
# use modulerc file in initdir if conf files are located in this dir
if {[file exists {@initrc@}]} {
lappendState commandname source
cmdModuleSource load {@initrc@}
lpopState commandname
}
# record what has just been loaded in the virtual init collection
setenv __MODULES_LMINIT [getLoadedInit]
# if user environment is already initialized, refresh the already loaded
# modules unless if environment is inconsistent
} elseif {![catch {cacheCurrentModules}]} {
cmdModuleRefresh
}
# default MODULESHOME
setenv MODULESHOME [getConf home]
# append dir where to find module function for ksh (to get it defined in
# interactive and non-interactive sub-shells). also applies for shells
# listed in shells_with_ksh_fpath conf
if {[getState shell] in [list {*}[getConfList shells_with_ksh_fpath] \
ksh]} {
append-path FPATH {@initdir@/ksh-functions}
}
# define Modules init script as shell startup file
if {[getConf set_shell_startup] && [getState shelltype] in [list sh csh\
fish]} {
# setup ENV variables to get module defined in sub-shells (works for
# 'sh' and 'ksh' in interactive mode and 'sh' (zsh-compat), 'bash' and
# 'ksh' (zsh-compat) in non-interactive mode.
setenv ENV {@initdir@/profile.sh}
setenv BASH_ENV {@initdir@/bash}
}
if {[getState shelltype] in {sh csh fish}} {
# add Modules bin directory to PATH if enabled but do not increase ref
# counter variable if already there
##nagelfar ignore #26 Strange command
@setbinpath@if {{@bindir@} ni [split [get-env PATH] :]} {
@setbinpath@@appendbinpath@-path --ignore-refcount PATH {@bindir@}
@setbinpath@}
# add Modules man directory to MANPATH if enabled
# initialize MANPATH if not set with a value that preserves manpath
# system configuration even after addition of paths to this variable by
# modulefiles
@setmanpath@set manpath {}
# use manpath tool if found at configure step, use MANPATH otherwise
##nagelfar ignore +2 Too long line
##nagelfar ignore Found constant
@setmanpath@@usemanpath@catch {set manpath [exec -ignorestderr 2>/dev/null manpath]}
@setmanpath@@notusemanpath@if {[isEnvVarDefined MANPATH]} {
@setmanpath@@notusemanpath@ set manpath $::env(MANPATH)
@setmanpath@@notusemanpath@}
@setmanpath@if {{@mandir@} ni [split $manpath :]} {
@setmanpath@ if {![isEnvVarDefined MANPATH]} {
@setmanpath@ append-path MANPATH {}
@setmanpath@ # ensure no duplicate ':' is set
@setmanpath@ } elseif {[envVarEquals MANPATH :]} {
@setmanpath@ remove-path MANPATH {}
@setmanpath@ append-path MANPATH {}
@setmanpath@ }
@setmanpath@ @appendmanpath@-path MANPATH {@mandir@}
@setmanpath@}
}
# source shell completion script if available, not installed in default
# completion locations and only if shell is interactive
if {[getState shell] in {@shellcompsource@} && [getState is_stderr_tty]} {
set compfile "@initdir@/[getState shell]_completion"
if {[file readable $compfile]} {
putsModfileCmd dummy "source '$compfile';"
}
}
# clear in progress flag
unsetenv __MODULES_AUTOINIT_INPROGRESS
lpopState mode
}
proc cmdModuleInit {args} {
set init_cmd [lindex $args 0]
set init_list [lrange $args 1 end]
set notdone 1
set nomatch 1
# Define startup files for each shell
set files(csh) [list .modules .cshrc .cshrc_variables .login]
set files(tcsh) [list .modules .tcshrc .cshrc .cshrc_variables .login]
set files(sh) [list .modules .bash_profile .bash_login .profile .bashrc]
set files(bash) $files(sh)
set files(ksh) $files(sh)
set files(fish) [list .modules .config/fish/config.fish]
set files(zsh) [list .modules .zshrc .zshenv .zlogin]
# Process startup files for this shell
set current_files $files([getState shell])
foreach filename $current_files {
if {$notdone} {
set filepath $::env(HOME)
append filepath / $filename
reportDebug "Looking at $filepath"
if {[file readable $filepath] && [file isfile $filepath]} {
set newinit {}
set thismatch 0
foreach curline [split [readFile $filepath] \n] {
# Find module load/add command in startup file
set comments {}
if {$notdone && [regexp {^([ \t]*module[ \t]+(load|add)[\
\t]*)(.*)} $curline match cmd subcmd modules]} {
set nomatch 0
set thismatch 1
regexp {([ \t]*\#.+)} $modules match comments
regsub {\#.+} $modules {} modules
# remove existing references to the named module from
# the list Change the module command line to reflect the
# given command
switch -- $init_cmd {
list {
if {![info exists notheader]} {
report "[getState shell] initialization file\
\$HOME/$filename loads modules:"
set notheader 0
}
report \t$modules
}
add {
foreach newmodule $init_list {
set modules [replaceFromList $modules $newmodule]
}
lappend newinit "$cmd$modules $init_list$comments"
# delete new modules in potential next lines
set init_cmd rm
}
prepend {
foreach newmodule $init_list {
set modules [replaceFromList $modules $newmodule]
}
lappend newinit "$cmd$init_list $modules$comments"
# delete new modules in potential next lines
set init_cmd rm
}
rm {
set oldmodcount [llength $modules]
foreach oldmodule $init_list {
set modules [replaceFromList $modules $oldmodule]
}
set modcount [llength $modules]
lappend newinit [expr {$modcount ?\
"$cmd$modules$comments" : [string trim $cmd]}]
if {$oldmodcount > $modcount} {
set notdone 0
}
}
switch {
set oldmodule [lindex $init_list 0]
set newmodule [lindex $init_list 1]
set newmodules [replaceFromList $modules\
$oldmodule $newmodule]
lappend newinit $cmd$newmodules$comments
if {$modules ne $newmodules} {
set notdone 0
}
}
clear {
lappend newinit [string trim $cmd]
}
}
} elseif {$curline ne {}} {
# copy the line from the old file to the new
lappend newinit $curline
}
}
if {$init_cmd ne {list} && $thismatch} {
reportDebug "Writing $filepath"
if {[catch {
set fid [open $filepath w]
puts $fid [join $newinit \n]
close $fid
} errMsg ]} {
reportErrorAndExit "Init file $filepath cannot be\
written.\n$errMsg"
}
}
}
}
}
# quit in error if command was not performed due to no match
if {$nomatch && $init_cmd ne {list}} {
reportErrorAndExit "Cannot find a 'module load' command in any of the\
'[getState shell]' startup files"
}
}
# provide access to modulefile specific commands from the command-line, making
# them standing as a module sub-command (see module procedure)
proc cmdModuleResurface {cmd args} {
lappendState mode load
lappendState commandname $cmd
set optlist [list]
switch -- $cmd {
prepend-path - append-path - remove-path {
# by-pass any reference counter, as call is from top level
# append/prepend-path: not to increase reference counter if paths are
# already defined. remove-path: to ensure paths are removed whatever
# their reference counter value
lappend optlist --ignore-refcount
}
}
# run modulefile command and get its result
if {[catch {$cmd {*}$optlist {*}$args} res]} {
# report error if any and return false
reportError $res
} else {
# register result depending of return kind (false or text)
switch -- $cmd {
module-info {
set ::g_return_text $res
}
default {
if {$res == 0} {
# render false if command returned false
setState return_false 1
}
}
}
}
lpopState commandname
lpopState mode
}
proc cmdModuleTest {args} {
lappendState mode test
set first_report 1
foreach mod $args {
lassign [getPathToModule $mod] modfile modname modnamevr
if {$modfile ne {}} {
# only one separator lines between 2 modules
if {$first_report} {
displaySeparatorLine
set first_report 0
}
report "Module Specific Test for [sgr hi $modfile]:\n"
execute-modulefile $modfile $modname modnamevr $mod 1
displaySeparatorLine
}
}
lpopState mode
}
proc cmdModuleClear {args} {
# fetch confirmation if no arg passed and force mode disabled
if {![llength $args] && ![getState force]} {
# ask for it if stdin is attached to a terminal
if {![catch {fconfigure stdin -mode}]} {
report "Are you sure you want to clear all loaded modules!? \[n\] " 1
flush [getState reportfd]
}
# fetch stdin content even if not attached to terminal in case some
# content has been piped to this channel
set doit [gets stdin]
} else {
set doit [lindex $args 0]
}
# should be confirmed or forced to proceed
if {[string equal -nocase -length 1 $doit y] || [getState force]} {
lappendState mode load
# unset all Modules runtime variables
foreach globvar [getModulesEnvVarGlobList 1] {
foreach var [array names ::env -glob $globvar] {
unset-env $var
}
}
lpopState mode
} else {
reportInfo "Modules runtime information were not cleared"
}
}
proc cmdModuleState {args} {
if {[llength $args]} {
set name [lindex $args 0]
}
if {[info exists name] && $name ni [concat [array names ::g_state_defs]\
[array names ::g_states]]} {
knerror "State '$name' does not exist"
}
# report module version unless if called by cmdModuleConfig
if {[getCallingProcName] ne {cmdModuleConfig}} {
reportVersion
reportSeparateNextContent
}
displayTableHeader hi {State name} 24 {Value} 54
# fetch specified state or all states
if {[info exists name]} {
if {$name in [array names ::g_state_defs]} {
set stateval($name) [getState $name <undef> 1]
} else {
set stateval($name) [getState $name]
}
} else {
# define each attribute/fetched state value pair
foreach state [array names ::g_state_defs] {
set stateval($state) [getState $state <undef> 1]
}
# also get dynamic states (with no prior definition)
foreach state [array names ::g_states] {
if {![info exists stateval($state)]} {
set stateval($state) [getState $state]
}
}
}
foreach state [lsort [array names stateval]] {
append displist [format {%-25s %s} $state $stateval($state)] \n
}
report $displist 1
reportSeparateNextContent
# only report specified state if any
if {[info exists name]} {
return
}
# report environment variable set related to Modules
displayTableHeader hi {Env. variable} 24 {Value} 54
set envvar_list {}
foreach var [getModulesEnvVarGlobList] {
lappend envvar_list {*}[array names ::env -glob $var]
}
unset displist
foreach var [lsort -unique $envvar_list] {
append displist [format {%-25s %s} $var $::env($var)] \n
}
report $displist 1
}
proc cmdModuleConfig {dump_state args} {
# parse arguments
set nameunset 0
switch -- [llength $args] {
1 {
lassign $args name
}
2 {
lassign $args name value
# check if configuration should be set or unset
if {$name eq {--reset}} {
set name $value
set nameunset 1
unset value
}
}
}
reportDebug "dump_state='$dump_state', reset=$nameunset,\
name=[expr {[info exists name] ? "'$name'" : {<undef>}}], value=[expr\
{[info exists value] ? "'$value'" : {<undef>}}]"
foreach option [array names ::g_config_defs] {
lassign $::g_config_defs($option) confvar($option) defval\
conflockable($option) confkind($option) confvalid($option) vtrans\
initproc confvalidkind($option)
set confval($option) [getConf $option <undef>]
set confvtrans($option) {}
for {set i 0} {$i < [llength $vtrans]} {incr i} {
lappend confvtrans($option) [lindex $vtrans $i] [lindex\
$confvalid($option) $i]
}
}
# catch any environment variable set for modulecmd run-time execution
foreach runenvvar [array names ::env -glob MODULES_RUNENV_*] {
set runenvconf [string tolower [string range $runenvvar 8 end]]
set confval($runenvconf) [get-env $runenvvar]
# enable modification of runenv conf
set confvar($runenvconf) $runenvvar
set confvalid($runenvconf) {}
set conflockable($runenvconf) {}
set confkind($runenvconf) s
set confvtrans($runenvconf) {}
set confvalidkind($runenvconf) {}
}
if {[info exists name] && ![info exists confval($name)]} {
reportErrorAndExit "Configuration option '$name' does not exist"
# set configuration
} elseif {[info exists name] && ($nameunset || [info exists value])} {
# append or subtract value to existing configuration value if new value
# starts with '+' or '-' (for colon-separated list option only)
if {[info exists value] && $confkind($name) eq {l}} {
set curconfvallist [getConfList $name]
switch -- [string index $value 0] {
+ {
appendNoDupToList curconfvallist {*}[split [string range\
$value 1 end] :]
set value [join $curconfvallist :]
}
- {
lassign [getDiffBetweenList $curconfvallist [split [string\
range $value 1 end] :]] curconfvallist
set value [join $curconfvallist :]
}
}
}
if {$confvar($name) eq {}} {
reportErrorAndExit "Configuration option '$name' cannot be altered"
} elseif {$conflockable($name) eq {1} && [isConfigLocked $name]} {
reportErrorAndExit "Configuration option '$name' is locked"
} elseif {$nameunset} {
# unset configuration variable
lappendState mode load
unsetenv $confvar($name)
lpopState mode
} elseif {[llength $confvalid($name)]} {
switch -- $confvalidkind($name) {
eltlist {
# check each element in value list
if {[isDiffBetweenList [split $value :] $confvalid($name)]} {
reportErrorAndExit "Invalid element in value list for\
config. option '$name'\nAllowed elements are:\
$confvalid($name) (separated by ':')"
} else {
set validval 1
}
}
intbe {
if {[string is integer -strict $value] && $value >= [lindex\
$confvalid($name) 0] && $value <= [lindex $confvalid($name)\
1]} {
set validval 1
} else {
reportErrorAndExit "Invalid value for configuration option\
'$name'\nValue should be an integer comprised between\
[lindex $confvalid($name) 0] and [lindex\
$confvalid($name) 1]"
}
}
{} {
##nagelfar ignore +2 Non static subcommand
if {([llength $confvalid($name)] == 1 && ![string is\
$confvalid($name) -strict $value]) || ([llength\
$confvalid($name)] > 1 && $value ni $confvalid($name))} {
reportErrorAndExit "Valid values for configuration option\
'$name' are: $confvalid($name)"
} else {
set validval 1
}
}
}
} else {
set validval 1
}
if {[info exists validval]} {
# effectively set configuration variable
lappendState mode load
setenv $confvar($name) $value
lpopState mode
}
# clear cached value for config if any
unsetConf $name
# report configuration
} else {
reportVersion
reportSeparateNextContent
displayTableHeader hi {Config. name} 24 {Value (set by if default\
overridden)} 54
# report all configs or just queried one
if {[info exists name]} {
set varlist [list $name]
} else {
set varlist [lsort [array names confval]]
}
foreach var $varlist {
##nagelfar ignore +2 Suspicious variable name
set valrep [displayConfig $confval($var) $confvar($var) [info exists\
::asked_$var] $confvtrans($var) [expr {$conflockable($var) eq {1}\
&& [isConfigLocked $var]}]]
append displist [format {%-25s %s} $var $valrep] \n
}
report $displist 1
reportSeparateNextContent
if {$dump_state} {
cmdModuleState
}
}
}
proc cmdModuleShToMod {args} {
set scriptargs [lassign $args shell script]
# evaluate script and get the environment changes it performs translated
# into modulefile commands
set modcontent [sh-to-mod {} {*}$args]
# output resulting modulefile
if {[llength $modcontent]} {
report "#%Module"
# format each command with tabs and colors if enabled
foreach modcmd $modcontent {
reportCmd -nativeargrep {*}$modcmd
}
}
}
proc cmdModuleEdit {mod} {
lassign [getPathToModule $mod] modfile modname
# error message has already been produced if mod not found or forbidden
if {$modfile ne {}} {
# redirect stdout to stderr as stdout is evaluated by module shell func
if {[catch {runCommand [getConf editor] $modfile >@stderr 2>@stderr}\
errMsg]} {
# re-throw error but as an external one (not as a module issue)
knerror $errMsg
}
}
}
proc cmdModuleRefresh {} {
lappendState mode refresh
# create an eval id to track successful/failed module evaluations
pushMsgRecordId refresh-[depthState modulename] 0
# load variants from loaded modules
cacheCurrentModules
foreach lm [getEnvLoadedModulePropertyParsedList refresh] {
# prepare info to execute modulefile
set lmvr [getAndParseLoadedModuleWithVariant $lm]
set lmfile [getModulefileFromLoadedModule $lm]
set taglist [getExportTagList $lm]
# refreshing module is visible by default
set hidden 0
set uasked 1
# set a unique id to record messages related to this evaluation.
set msgrecid refresh-$lmvr-[depthState modulename]
# register record message unique id (now we know mod will be evaluated)
pushMsgRecordId $msgrecid
# record module title (with the variants and tags of loaded module)
# prior module evaluation to get this title ready in case of eval error
registerModuleDesignation $msgrecid $lm [getVariantList $lm 7]\
$taglist
# run modulefile, restore settings prior evaluation if error and
# continue to evaluate the remaining loaded modules
pushSettings
if {[set errCode [catch {
if {[execute-modulefile $lmfile $lm lmvr $lm 0]} {
break
}
# unloading visibility depends on hidden-loaded tag
set hidden [isModuleTagged $lm hidden-loaded 1]
# module was asked by user if tagged loaded instead of auto-loaded
set uasked [isModuleTagged $lm loaded 1]
} errMsg]] != 0 && $errCode != 4} {
restoreSettings
}
popSettings
# report all recorded messages for this evaluation (hide evaluation if
# loaded mod is set hidden, has been automatically loaded and unloaded)
reportMsgRecord "Refreshing [getModuleDesignation $msgrecid {} 2]"\
[expr {$hidden && !$uasked && [depthState evalid] != 1}]
popMsgRecordId
}
popMsgRecordId 0
lpopState mode
}
proc cmdModuleHelp {args} {
lappendState mode help
set first_report 1
foreach arg $args {
lassign [getPathToModule $arg] modfile modname modnamevr
if {$modfile ne {}} {
# only one separator lines between 2 modules
if {$first_report} {
displaySeparatorLine
set first_report 0
}
report "Module Specific Help for [sgr hi $modfile]:\n"
execute-modulefile $modfile $modname modnamevr $arg 1
displaySeparatorLine
}
}
lpopState mode
if {![llength $args]} {
reportUsage
}
}
proc cmdModuleTag {unset_extra uasked tag_list args} {
reportDebug "tagging $args (unset_extra=$unset_extra, uasked=$uasked,\
tag_list=$tag_list)"
set ret 0
foreach mod $args {
# find mod among loaded modules
lassign [getPathToModule $mod {} 1 match] modfile modname modnamevr\
errkind
if {$modfile eq {}} {
set ret 1
# go to next module to unload
continue
}
# record tags not already set and if asked unset extra tags not set
# anymore
lassign [getDiffBetweenList $tag_list [getTagList $modname]] diff_list
lassign [getDiffBetweenList [getExtraTagList $modname] $tag_list] \
unset_list
if {[llength $diff_list] || ($unset_extra && [llength $unset_list])} {
# set a unique id to record messages related to this evaluation.
set msgrecid tag-$modnamevr-[depthState modulename]
pushMsgRecordId $msgrecid
# record module title (with the variant but no tag list) prior
# evaluation to get this title ready in case of error
registerModuleDesignation $msgrecid $modname [getVariantList\
$modnamevr 7] {}
lappendState mode unload
# first unset tags declared for this module on LM env var
unsetEnvLoadedModuleProperty $modname tag
unsetEnvLoadedModuleProperty $modname extratag
lpopState mode
# remove extra tags currently set not part of tag list if asked
if {$unset_extra && [llength $unset_list]} {
unsetModuleAndVariantsTag $modname $modnamevr {*}$unset_list
unsetModuleAndVariantsExtraTag $modname $modnamevr {*}$unset_list
}
# ensure auto-loaded tag is not preserved if not part of target tags
if {$unset_extra && {auto-loaded} ni $tag_list} {
unsetModuleAndVariantsTag $modname $modnamevr auto-loaded
}
# record new tags as extra tag excluding tags relative to the way
# module is loaded (auto, keep)
lassign [getDiffBetweenList $diff_list [list auto-loaded\
keep-loaded]] extradiff_list
setModuleAndVariantsTag $modname $modnamevr {*}$diff_list
if {[llength $extradiff_list]} {
setModuleAndVariantsExtraTag $modname $modnamevr\
{*}$extradiff_list
}
# set the new tag set for module on LM env var
lappendState mode load
setEnvLoadedModuleProperty $modname tag [getExportTagList $modnamevr]
setEnvLoadedModuleProperty $modname extratag [getExtraTagList\
$modnamevr]
lpopState mode
# update module designation now the additional tags are set
registerModuleDesignation $msgrecid $modname [getVariantList\
$modname 7] [getExportTagList $modname]
# report tagging evaluation unless hidden and auto-loaded
set hidden [isModuleTagged $modnamevr hidden-loaded 1]
reportMsgRecord "Tagging [getModuleDesignation $msgrecid {} 2]"\
[expr {$hidden && !$uasked}]
popMsgRecordId
# indicates that new tags have been applied
set ret 2
}
}
return $ret
}
proc cmdModuleLint {args} {
# stop if no linter defined
if {![llength [getConf tcl_linter]]} {
knerror {No Tcl linter program configured}
}
# extract linter program name
set linter [file rootname [file tail [lindex [getConf tcl_linter] 0]]]
# build command line
set linter_mfile [getConf tcl_linter]
set linter_mrc [getConf tcl_linter]
set linter_gmrc [getConf tcl_linter]
set linter_mcache [getConf tcl_linter]
# add module-specific syntax database in addition to regular Tcl one
##nagelfar ignore #11 Strange command
@nagelfaraddons@if {$linter eq {nagelfar}} {
@nagelfaraddons@ lappend linter_mfile -s _\
@nagelfaraddons@ -s {@nagelfardatadir@/syntaxdb_modulefile.tcl}\
@nagelfaraddons@ -plugin {@nagelfardatadir@/plugin_modulefile.tcl}
@nagelfaraddons@ lappend linter_mrc -s _\
@nagelfaraddons@ -s {@nagelfardatadir@/syntaxdb_modulerc.tcl}\
@nagelfaraddons@ -plugin {@nagelfardatadir@/plugin_modulerc.tcl}
@nagelfaraddons@ lappend linter_gmrc -s _\
@nagelfaraddons@ -s {@nagelfardatadir@/syntaxdb_modulefile.tcl}\
@nagelfaraddons@ -plugin {@nagelfardatadir@/plugin_globalrc.tcl}
@nagelfaraddons@ lappend linter_mcache -s _\
@nagelfaraddons@ -s {@nagelfardatadir@/syntaxdb_modulecache.tcl}\
@nagelfaraddons@ -plugin {@nagelfardatadir@/plugin_modulecache.tcl}
@nagelfaraddons@}
set global_rclist [getGlobalRcFileList]
set modfilelist {}
# fetch every available modulefiles if no argument provided
if {![llength $args]} {
# add global RC files
foreach rc $global_rclist {
set tolint($rc) gmrc
}
inhibitErrorReport
foreach dir [getModulePathList exiterronundef] {
set cachefile [getModuleCacheFilename $dir]
if {[file readable $cachefile]} {
set tolint($cachefile) mcache
}
# fetch all existing rc file current user has access to
foreach {elt props} [findModules $dir * 0 0] {
switch -- [lindex $props 0] {
modulerc {
set tolint($dir/$elt) mrc
}
}
}
# collect all modulefile from dir that current user has access to
# getModules will reuse the result collected for findModules
foreach {elt props} [getModules $dir *] {
switch -- [lindex $props 0] {
modulefile - virtual {
set tolint([lindex $props 2]) mfile
}
}
}
}
setState inhibit_errreport 0
} else {
foreach mod $args {
lassign [getPathToModule $mod] modfile modname modnamevr
# error mesg has already been produced if mod not found or forbidden
if {$modfile ne {}} {
if {$modfile in $global_rclist} {
set mkind gmrc
} else {
switch -- [file tail $modfile] {
.modulerc - .version {
set mkind mrc
}
.modulecache {
set mkind mcache
}
default {
set mkind mfile
}
}
}
set tolint($modfile) $mkind
}
}
}
# execute linter program over every gathered file
foreach lintfile [lsort -dictionary [array names tolint]] {
# set a record message unique id and record modulefile title
set msgrecid lint-$lintfile
pushMsgRecordId $msgrecid
registerModuleDesignation $msgrecid $lintfile {} {}
##nagelfar ignore Suspicious variable name
if {[catch {set out [runCommand {*}[set linter_$tolint($lintfile)]\
$lintfile]} errMsg]} {
# re-throw error but as an external one (not as a module issue)
knerror $errMsg
}
# report linting messages
displayLinterOutput $linter $out
# report all lint messages for this modulefile
reportMsgRecord "Linting [getModuleDesignation $msgrecid {} 2]"
popMsgRecordId
}
}
proc cmdModuleModToSh {shell args} {
# save shell modulecmd is initialized to
##nagelfar ignore Found constant
setState modtosh_real_shell [getState shell]
# set shell and shellType states to mod-to-sh target value
if {$shell ni [getState supported_shells]} {
reportErrorAndExit "Unsupported shell type '$shell'"
}
##nagelfar ignore Found constant
setState shell $shell
unsetState shelltype
# silence message report (avoid mix with produced shell code) unless if
# a debugging mode is set
if {![isVerbosityLevel trace]} {
unsetConf verbosity
set ::asked_verbosity silent
}
# modulefile evaluation is done against mod-to-sh target shell which means
# module-info will return mod-to-sh shell value
return [cmdModuleLoad load 1 0 0 {} {} {*}$args]
# after evaluation, renderSettings will produce shell code for mod-to-sh
# target shell. modtosh_real_shell state helps to know that shell code has
# to be output on report message channel
}
proc cmdModuleReset {} {
# use reset_target_state configuration option to know the environment state
# to restore
if {[getConf reset_target_state] eq {__purge__}} {
cmdModulePurge
} else {
cmdModuleRestore [getConf reset_target_state]
}
}
proc cmdModuleStash {} {
# check if there is something to stash
if {[getConf reset_target_state] eq {__purge__}} {
# load tags from loaded modules
cacheCurrentModules
# current environment differs from initial 'purge' state when at least
# a module is loaded and it is not super-sticky and not sticky or force
# mode is enabled to allow sticky tag unload
set diff_from_init 0
foreach mod [getEnvLoadedModulePropertyParsedList name] {
if {![isModuleSticky $mod]} {
set diff_from_init 1
break
}
}
} else {
# compare current environment against initial collection to check if
# something differ
set coll [getConf reset_target_state]
# get corresponding collection or init, raise error if it does not exist
lassign [findCollections $coll exact 0 1] collfile colldesc
# fetch collection content and differences compared current environment
lassign [getDiffBetweenCurEnvAndColl $collfile $colldesc]\
coll_path_list coll_mod_list coll_tag_arrser coll_nuasked_list\
mod_to_unload mod_to_load path_to_unuse path_to_use is_tags_diff
array set coll_tag_arr $coll_tag_arrser
set diff_from_init [expr {[llength $mod_to_unload] || [llength\
$mod_to_load] || [llength $path_to_unuse] || [llength $path_to_use]\
|| $is_tags_diff}]
}
if {!$diff_from_init} {
reportWarning {No specific environment to save}
return
}
# record current environment
cmdModuleSave stash-[clock milliseconds]
# restore initial environment
cmdModuleReset
}
proc cmdModuleStashpop {{stash 0}} {
# determine stash collection name from argument
set coll [getCollectionFromStash $stash]
# restore stash collection environment state
cmdModuleRestore $coll
# delete stash collection file
cmdModuleSaverm $coll
}
proc cmdModuleStashrm {{stash 0}} {
# determine stash collection name from argument
set coll [getCollectionFromStash $stash]
# delete stash collection file
cmdModuleSaverm $coll
}
proc cmdModuleStashshow {{stash 0}} {
# determine stash collection name from argument
set coll [getCollectionFromStash $stash]
# display stash collection file
cmdModuleSaveshow $coll
}
proc cmdModuleStashclear {} {
# get all stash collections (only from current target)
set collfile_list [findCollections stash-* glob 0 0 1 1]
# delete all stash collections starting from most recent
foreach collfile [lsort -decreasing $collfile_list] {
# extract collection name (without path and target extension)
set coll [file rootname [file tail $collfile]]
# delete stash collection file
cmdModuleSaverm $coll
}
}
proc cmdModuleStashlist {show_oneperline show_mtime} {
cmdModuleSavelist $show_oneperline $show_mtime {} stash-*
}
proc cmdModuleCachebuild {args} {
# use enabled modulepaths when no arg is provided
if {[llength $args]} {
set modpath_list $args
} else {
set modpath_list [getModulePathList exiterronundef]
}
# record cache with module header check options enabled
setConf mcookie_check always
setConf mcookie_version_check 1
# ignore cache when building cache
setConf ignore_cache 1
foreach modpath $modpath_list {
set cachefile [getModuleCacheFilename $modpath]
# set a record message unique id and record cachefile title
set msgrecid cachebuild-$cachefile
pushMsgRecordId $msgrecid
registerModuleDesignation $msgrecid $cachefile {} {}
if {[file isdirectory $modpath]} {
if {[file writable $modpath]} {
if {[catch {
# get cache content for modulepath
set cache [formatModuleCacheContent $modpath]
if {![string length $cache]} {
reportWarning {Nothing to record in cache file}
} else {
# record cache content in file
set fid [open $cachefile w]
# use defined buffer size to limit num of write system call
fconfigure $fid -buffersize [getConf cache_buffer_bytes]
puts $fid $cache
close $fid
}
} errMsg]} {
# report error occurring during cache content format or cache
# file write
reportError $errMsg
}
} else {
reportWarning {Cannot build cache file, directory is not writable}
}
} else {
reportError "'$modpath' is not a directory"
}
# report all messages for this cachefile creation
reportMsgRecord "Creating [getModuleDesignation $msgrecid {} 2]"
popMsgRecordId
}
}
proc cmdModuleCacheclear {} {
foreach modpath [getModulePathList exiterronundef] {
set cachefile [getModuleCacheFilename $modpath]
if {[file exists $cachefile]} {
# set a record message unique id and record cachefile title
set msgrecid cacheclear-$cachefile
pushMsgRecordId $msgrecid
registerModuleDesignation $msgrecid $cachefile {} {}
if {[file writable $modpath]} {
if {[catch {file delete $cachefile} errMsg]} {
reportError $errMsg
}
} else {
reportWarning {Cannot remove cache file, directory is not\
writable}
}
# report all messages for this cachefile deletion
reportMsgRecord "Deleting [getModuleDesignation $msgrecid {} 2]"
popMsgRecordId
}
}
}
proc cmdModuleSpider {show_oneperline show_mtime show_filter search_filter\
search_match args} {
# recursively collect all modulepath used among available modules
inhibitErrorReport
setConf advanced_version_spec 1
defineParseModuleSpecificationProc 1
set modpath_list [getModulePathList exiterronundef]
set use_xt_query [parseModuleSpecification 0 1 1 0 use:*]
for {set i -1} {$i < [llength $modpath_list]} {incr i} {
if {$i < 0} {
set modpath {}
getModules $modpath $use_xt_query 0 {rc_alias_only}
} else {
set modpath [lindex $modpath_list $i]
getModules $modpath $use_xt_query
}
foreach {new_modpath from_mod_list} [getScanModuleElt $modpath use] {
if {[string length $new_modpath] && $new_modpath ni $modpath_list} {
lappend modpath_list $new_modpath
setLoadedUse [lindex $from_mod_list 0] $new_modpath
}
}
}
unsetConf advanced_version_spec
defineParseModuleSpecificationProc [getConf advanced_version_spec]
setState inhibit_errreport 0
reportTrace $modpath_list {Collect modulepaths}
# perform an avail on all collected modulepaths
cmdModuleAvail $show_oneperline $show_mtime $show_filter $search_filter\
$search_match $modpath_list {*}$args
}
# ;;; Local Variables: ***
# ;;; mode:tcl ***
# ;;; End: ***
# vim:set tabstop=3 shiftwidth=3 expandtab autoindent:
|