#include <cmt_awk.h>
Public Member Functions | |
PathScanner () | |
bool | scan_path (const cmt_string &path, actor &a) |
bool | scan_package (const cmt_string &path, const cmt_string &package) |
Private Member Functions | |
void | scan_path (const cmt_string &path, int level, actor &a) |
Private Attributes | |
bool | _running |
int | _level |
Whenever it finds one, it applies the specified actor to it.
Definition at line 105 of file cmt_awk.h.
|
Definition at line 584 of file cmt_awk.cxx. References _level, and _running.
|
|
Definition at line 847 of file cmt_awk.cxx. References CmtSystem::basename(), CmtSystem::cmt_string_vector, cmt_string::erase(), CmtSystem::file_separator(), cmt_string::find(), CmtSystem::is_version_directory(), cmt_string::read(), CmtSystem::scan_dir(), cmt_vector< T >::size(), CmtSystem::test_directory(), and CmtSystem::test_file(). Referenced by Project::scan_paths_for_package().
00849 { 00850 // 00851 // Only do something if it is a directory. 00852 // 00853 00854 if (!CmtSystem::test_directory (path)) return (false); 00855 00856 cmt_string pattern = path; 00857 pattern += CmtSystem::file_separator (); 00858 pattern += package; 00859 00860 if (!CmtSystem::test_directory (pattern)) return (false); 00861 00862 CmtSystem::cmt_string_vector list; 00863 00864 CmtSystem::scan_dir (pattern, list); 00865 00866 if (list.size () == 0) 00867 { 00868 return (false); 00869 } 00870 00871 bool result = false; 00872 00873 int i; 00874 for (i = 0; i < list.size (); i++) 00875 { 00876 const cmt_string& name = list[i]; 00877 00878 cmt_string version; 00879 CmtSystem::basename (name, version); 00880 00881 if (version == "cmt") 00882 { 00883 cmt_string req; 00884 00885 req = name; 00886 req += CmtSystem::file_separator (); 00887 req += "requirements"; 00888 00889 if (CmtSystem::test_file (req)) 00890 { 00891 //cout << " -> no version" << endl; 00892 00893 cmt_string req; 00894 00895 req = name; 00896 req += CmtSystem::file_separator (); 00897 req += "version.cmt"; 00898 00899 cmt_string version; 00900 if (CmtSystem::test_file (req)) 00901 { 00902 version.read (req); 00903 int pos; 00904 pos = version.find ('\n'); 00905 if (pos != cmt_string::npos) version.erase (pos); 00906 pos = version.find ('\r'); 00907 if (pos != cmt_string::npos) version.erase (pos); 00908 } 00909 else 00910 { 00911 version = "v*"; 00912 } 00913 00914 cout << package << " " << version << " " << path << endl; 00915 00916 result = true; 00917 } 00918 } 00919 else if (CmtSystem::is_version_directory (version)) 00920 { 00921 cmt_string req; 00922 00923 req = name; 00924 req += CmtSystem::file_separator (); 00925 req += "cmt"; 00926 req += CmtSystem::file_separator (); 00927 req += "requirements"; 00928 00929 if (CmtSystem::test_file (req)) 00930 { 00931 //cout << " -> cmt" << endl; 00932 00933 cout << package << " " << version << " " << path << endl; 00934 00935 result = true; 00936 } 00937 else 00938 { 00939 //cout << " -> no cmt" << endl; 00940 00941 req = name; 00942 req += CmtSystem::file_separator (); 00943 req += "mgr"; 00944 req += CmtSystem::file_separator (); 00945 req += "requirements"; 00946 00947 if (CmtSystem::test_file (req)) 00948 { 00949 //cout << " -> mgr" << endl; 00950 00951 cout << package << " " << version << " " << path << endl; 00952 00953 result = true; 00954 } 00955 else 00956 { 00957 //cout << " -> no mgr" << endl; 00958 } 00959 } 00960 } 00961 else 00962 { 00963 //cout << " -> stop" << endl; 00964 } 00965 } 00966 00967 return (result); 00968 } |
|
Definition at line 609 of file cmt_awk.cxx. References _level, CmtSystem::basename(), CmtSystem::cmt_string_vector, CmtSystem::dirname(), cmt_string::erase(), CmtSystem::file_separator(), cmt_string::find(), CmtSystem::is_version_directory(), cmt_string::read(), cmt_string::replace_all(), PathScanner::actor::run(), CmtSystem::scan_dir(), scan_path(), cmt_vector< T >::size(), CmtSystem::test_directory(), and CmtSystem::test_file().
00610 { 00611 if (level > 10) 00612 { 00613 //cout << "#PathScanner::scan_path> too deep search path=" << path << endl; 00614 return; 00615 } 00616 00617 // 00618 // Only do something if it is a directory. 00619 // 00620 00621 if (!CmtSystem::test_directory (path)) return; 00622 00623 CmtSystem::cmt_string_vector list; 00624 CmtSystem::cmt_string_vector entrylist; 00625 00626 CmtSystem::scan_dir (path, list); 00627 00628 if (list.size () == 0) return; 00629 00630 _level++; 00631 00632 // Will be set if at least one directory is a version directory 00633 bool has_package = false; 00634 00635 cmt_string name; 00636 cmt_string version; 00637 cmt_string where; 00638 00639 int i; 00640 00641 for (i = 0; i < list.size (); i++) 00642 { 00643 const cmt_string& here = list[i]; 00644 00645 if (!CmtSystem::test_directory (here)) continue; 00646 00647 name = ""; 00648 version = ""; 00649 00650 cmt_string entry; 00651 CmtSystem::basename (here, entry); 00652 CmtSystem::dirname (path, where); 00653 00654 // cout << "## here=" << here << " entry=" << entry << " where=" << where << endl; 00655 00656 if ((level == 0) && (entry == "InstallArea")) continue; 00657 00658 cmt_string req; 00659 00660 req = here; 00661 req += CmtSystem::file_separator (); 00662 req += "mgr"; 00663 req += CmtSystem::file_separator (); 00664 req += "requirements"; 00665 00666 if (CmtSystem::test_file (req)) 00667 { 00668 // We have found <path>/mgr/requirements 00669 // this is an old directory convention. 00670 // The version directory is the directory above 00671 00672 version = entry; 00673 CmtSystem::basename (path, name); 00674 00675 // cout << "#1" << endl; 00676 00677 a.run (name, version, where); 00678 has_package = true; 00679 00680 continue; 00681 } 00682 00683 req = here; 00684 req += CmtSystem::file_separator (); 00685 req += "cmt"; 00686 req += CmtSystem::file_separator (); 00687 req += "requirements"; 00688 00689 if (CmtSystem::test_file (req)) 00690 { 00691 // We have found <path>/cmt/requirements 00692 // Question now is to detect the directory structure: 00693 // 00694 // if cmt/version.cmt exists it's a non-version-directory structure 00695 // else 00696 // if there is a package statement in the requirements file we find it upward 00697 // else 00698 // if up is a version directory 00699 // else 00700 // 00701 00702 cmt_string vreq; 00703 vreq = here; 00704 vreq += CmtSystem::file_separator (); 00705 vreq += "cmt"; 00706 vreq += CmtSystem::file_separator (); 00707 vreq += "version.cmt"; 00708 00709 if (CmtSystem::test_file (vreq)) 00710 { 00711 version.read (vreq); 00712 int pos; 00713 pos = version.find ('\n'); 00714 if (pos != cmt_string::npos) version.erase (pos); 00715 pos = version.find ('\r'); 00716 if (pos != cmt_string::npos) version.erase (pos); 00717 00718 //cout << "#2" << endl; 00719 00720 a.run (entry, version, path); 00721 has_package = true; 00722 00723 continue; 00724 } 00725 00726 cmt_string p; 00727 00728 p.read (req); 00729 int pos; 00730 pos = p.find ("package"); 00731 if (pos != cmt_string::npos) 00732 { 00733 p.erase (0, pos+8); 00734 pos = p.find ('\n'); 00735 if (pos != cmt_string::npos) p.erase (pos); 00736 pos = p.find ('\r'); 00737 if (pos != cmt_string::npos) p.erase (pos); 00738 p.replace_all (" ", ""); 00739 p.replace_all ("\t", ""); 00740 if (p != "") name = p; 00741 } 00742 00743 if (name != "") 00744 { 00745 // The package name was specified in the requirements file 00746 00747 if (entry == name) 00748 { 00749 // The structure is without the version directory. 00750 00751 //cout << "#3" << endl; 00752 00753 a.run (name, "v1", path); 00754 has_package = true; 00755 00756 continue; 00757 } 00758 00759 version = entry; 00760 CmtSystem::basename (path, entry); 00761 00762 if (entry == name) 00763 { 00764 // The structure is with the version directory. 00765 00766 //cout << "#4" << endl; 00767 00768 a.run (name, version, where); 00769 has_package = true; 00770 00771 continue; 00772 } 00773 00774 // No directory structure matches the package name 00775 // Is it a typo in the requirements file ? 00776 // probably we should display it and quit... 00777 } 00778 else 00779 { 00780 version = entry; 00781 CmtSystem::basename (path, entry); 00782 } 00783 00784 // The package name is not specified in the requirements file 00785 // or did not match the directory structure 00786 // We'll have to guess it from the structure 00787 00788 if (CmtSystem::is_version_directory (version)) 00789 { 00790 // cout << "#5" << endl; 00791 00792 a.run (entry, version, where); 00793 has_package = true; 00794 00795 continue; 00796 } 00797 00798 name = version; 00799 00800 where += CmtSystem::file_separator (); 00801 where += entry; 00802 00803 // cout << "#6" << endl; 00804 00805 a.run (name, "v1", where); 00806 has_package = true; 00807 00808 continue; 00809 } 00810 00811 //cout << "#7" << endl; 00812 00813 scan_path (here, level + 1, a); 00814 } 00815 00816 if (has_package) 00817 { 00818 // 00819 // At least one version was found here. Thus we want to scan further down. 00820 // 00821 00822 for (i = 0; i < entrylist.size (); i++) 00823 { 00824 const cmt_string& e = entrylist[i]; 00825 00826 cmt_string p = path; 00827 p += CmtSystem::file_separator (); 00828 p += e; 00829 00830 /* 00831 for (j = 1; j < _level; j++) cout << " "; 00832 cout << "Restarting scan_path on p=" << p << endl; 00833 */ 00834 00835 cout << "#PathScanner::scan_path> Restarting scan_path on p=" << p << endl; 00836 00837 00838 scan_path (p, 1, a); 00839 } 00840 } 00841 00842 _level--; 00843 } |
|
Definition at line 591 of file cmt_awk.cxx. References _level, _running, and CmtSystem::compress_path(). Referenced by Cmt::do_show_packages(), scan_path(), and Project::scan_paths().
00592 { 00593 if (_running) return (false); 00594 00595 _level = 0; 00596 _running = true; 00597 00598 cmt_string compressed_path = path; 00599 CmtSystem::compress_path (compressed_path); 00600 scan_path (compressed_path, 0, a); 00601 00602 _running = false; 00603 _level = 0; 00604 00605 return (true); 00606 } |
|
Definition at line 126 of file cmt_awk.h. Referenced by PathScanner(), and scan_path(). |
|
Definition at line 125 of file cmt_awk.h. Referenced by PathScanner(), and scan_path(). |