Main Page ? Class Hierarchy ? Compound List ? File List ? Compound Members ? File Members ?

PathScanner Class Reference

This scans a path and looks for CMT packages. More...

#include <cmt_awk.h>

List of all members.


Public Methods

? PathScanner ()
bool? scan_path (const cmt_string &path, actor &a)
bool? scan_package (const cmt_string &path, const cmt_string &package)

Private Methods

void? scan_path (const cmt_string &path, int level, actor &a)

Private Attributes

bool? _running
int? _level

Detailed Description

This scans a path and looks for CMT packages.

Whenever it finds one, it applies the specified actor to it.

Definition at line 105 of file cmt_awk.h.


Constructor & Destructor Documentation

PathScanner::PathScanner (? ? )?
?

Definition at line 584 of file cmt_awk.cxx.

References _level, and _running.

00585 {
00586   _running = false;
00587   _level = 0;
00588 }

Member Function Documentation

bool PathScanner::scan_package (? const cmt_string &? ? path,
const cmt_string &? ? package
)?
?

Definition at line 846 of file cmt_awk.cxx.

References CmtSystem::basename(), cmt_string::erase(), CmtSystem::file_separator(), cmt_string::find(), CmtSystem::is_version_directory(), cmt_string::npos, cmt_string::read(), CmtSystem::scan_dir(), cmt_vector< cmt_string >::size(), CmtSystem::test_directory(), and CmtSystem::test_file().

Referenced by Project::scan_paths_for_package().

00848 {
00849   //
00850   // Only do something if it is a directory.
00851   //
00852 
00853   if (!CmtSystem::test_directory (path)) return (false);
00854 
00855   cmt_string pattern = path;
00856   pattern += CmtSystem::file_separator ();
00857   pattern += package;
00858 
00859   if (!CmtSystem::test_directory (pattern)) return (false);
00860 
00861   CmtSystem::cmt_string_vector list;
00862 
00863   CmtSystem::scan_dir (pattern, list);
00864 
00865   if (list.size () == 0) 
00866     {
00867       return (false);
00868     }
00869 
00870   bool result = false;
00871 
00872   int i;
00873   for (i = 0; i < list.size (); i++)
00874     {
00875       const cmt_string& name = list[i];
00876 
00877       cmt_string version;
00878       CmtSystem::basename (name, version);
00879 
00880       if (version == "cmt")
00881         {
00882           cmt_string req;
00883 
00884           req = name;
00885           req += CmtSystem::file_separator ();
00886           req += "requirements";
00887 
00888           if (CmtSystem::test_file (req))
00889             {
00890               //cout << " -> no version" << endl;
00891 
00892               cmt_string req;
00893               
00894               req = name;
00895               req += CmtSystem::file_separator ();
00896               req += "version.cmt";
00897 
00898               cmt_string version;
00899               if (CmtSystem::test_file (req))
00900                 {
00901                   version.read (req);
00902                   int pos;
00903                   pos = version.find ('\n');
00904                   if (pos != cmt_string::npos) version.erase (pos);
00905                   pos = version.find ('\r');
00906                   if (pos != cmt_string::npos) version.erase (pos);
00907                 }
00908               else
00909                 {
00910                   version = "v*";
00911                 }
00912 
00913               cout << package << " " << version << " " << path << endl;
00914 
00915               result = true;
00916             }
00917         }
00918       else if (CmtSystem::is_version_directory (version))
00919         {
00920           cmt_string req;
00921 
00922           req = name;
00923           req += CmtSystem::file_separator ();
00924           req += "cmt";
00925           req += CmtSystem::file_separator ();
00926           req += "requirements";
00927 
00928           if (CmtSystem::test_file (req))
00929             {
00930               //cout << " -> cmt" << endl;
00931 
00932               cout << package << " " << version << " " << path << endl;
00933 
00934               result = true;
00935             }
00936           else
00937             {
00938               //cout << " -> no cmt" << endl;
00939 
00940               req = name;
00941               req += CmtSystem::file_separator ();
00942               req += "mgr";
00943               req += CmtSystem::file_separator ();
00944               req += "requirements";
00945 
00946               if (CmtSystem::test_file (req))
00947                 {
00948                   //cout << " -> mgr" << endl;
00949 
00950                   cout << package << " " << version << " " << path << endl;
00951 
00952                   result = true;
00953                 }
00954               else
00955                 {
00956                   //cout << " -> no mgr" << endl;
00957                 }
00958             }
00959         }
00960       else
00961         {
00962           //cout << " -> stop" << endl;
00963         }
00964     }
00965 
00966   return (result);
00967 }

void PathScanner::scan_path (? const cmt_string &? ? path,
int? ? level,
actor &? ? a
)? [private]
?

Definition at line 609 of file cmt_awk.cxx.

References _level, CmtSystem::basename(), CmtSystem::dirname(), cmt_string::erase(), CmtSystem::file_separator(), cmt_string::find(), CmtSystem::is_version_directory(), cmt_string::npos, cmt_string::read(), cmt_string::replace_all(), PathScanner::actor::run(), CmtSystem::scan_dir(), scan_path(), cmt_vector< cmt_string >::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     }
00615 
00616   //
00617   // Only do something if it is a directory.
00618   //
00619 
00620   if (!CmtSystem::test_directory (path)) return;
00621 
00622   CmtSystem::cmt_string_vector list;
00623   CmtSystem::cmt_string_vector entrylist;
00624 
00625   CmtSystem::scan_dir (path, list);
00626 
00627   if (list.size () == 0) return;
00628 
00629   _level++;
00630 
00631   // Will be set if at least one directory is a version directory
00632   bool has_package = false;
00633 
00634   cmt_string name;
00635   cmt_string version;
00636   cmt_string where;
00637 
00638   int i;
00639 
00640   for (i = 0; i < list.size (); i++)
00641     {
00642       const cmt_string& here = list[i];
00643 
00644       if (!CmtSystem::test_directory (here)) continue;
00645 
00646       name = "";
00647       version = "";
00648 
00649       cmt_string entry;
00650       CmtSystem::basename (here, entry);
00651       CmtSystem::dirname (path, where);
00652 
00653       // cout << "## here=" << here << " entry=" << entry << " where=" << where << endl;
00654 
00655       if ((level == 0) && (entry == "InstallArea")) continue;
00656 
00657       cmt_string req;
00658 
00659       req = here;
00660       req += CmtSystem::file_separator ();
00661       req += "mgr";
00662       req += CmtSystem::file_separator ();
00663       req += "requirements";
00664 
00665       if (CmtSystem::test_file (req))
00666         {
00667           // We have found /mgr/requirements
00668           // this is an old directory convention. 
00669           // The version directory is the directory above
00670 
00671           version = entry;
00672           CmtSystem::basename (path, name);
00673 
00674           // cout << "#1" << endl;
00675 
00676           a.run (name, version, where);
00677           has_package = true;
00678 
00679           continue;
00680         }
00681 
00682       req = here;
00683       req += CmtSystem::file_separator ();
00684       req += "cmt";
00685       req += CmtSystem::file_separator ();
00686       req += "requirements";
00687 
00688       if (CmtSystem::test_file (req))
00689         {
00690           // We have found /cmt/requirements
00691           // Question now is to detect the directory structure:
00692           //
00693           // if cmt/version.cmt exists it's a non-version-directory structure
00694           // else
00695           //   if there is a package statement in the requirements file we find it upward
00696           //   else
00697           //     if up is a version directory
00698           //     else
00699           //
00700 
00701           cmt_string vreq;
00702           vreq = here;
00703           vreq += CmtSystem::file_separator ();
00704           vreq += "cmt";
00705           vreq += CmtSystem::file_separator ();
00706           vreq += "version.cmt";
00707 
00708           if (CmtSystem::test_file (vreq))
00709             {
00710               version.read (vreq);
00711               int pos;
00712               pos = version.find ('\n');
00713               if (pos != cmt_string::npos) version.erase (pos);
00714               pos = version.find ('\r');
00715               if (pos != cmt_string::npos) version.erase (pos);
00716 
00717               //cout << "#2" << endl;
00718 
00719               a.run (entry, version, path);
00720               has_package = true;
00721               
00722               continue;
00723             }
00724 
00725           cmt_string p;
00726 
00727           p.read (req);
00728           int pos;
00729           pos = p.find ("package");
00730           if (pos != cmt_string::npos)
00731             {
00732               p.erase (0, pos+8);
00733               pos = p.find ('\n');
00734               if (pos != cmt_string::npos) p.erase (pos);
00735               pos = p.find ('\r');
00736               if (pos != cmt_string::npos) p.erase (pos);
00737               p.replace_all (" ", "");
00738               p.replace_all ("\t", "");
00739               if (p != "") name = p;
00740             }
00741 
00742           if (name != "")
00743             {
00744               // The package name was specified in the requirements file
00745 
00746               if (entry == name)
00747                 {
00748                   // The structure is without the version directory.
00749 
00750                   //cout << "#3" << endl;
00751 
00752                   a.run (name, "v1", path);
00753                   has_package = true;
00754                   
00755                   continue;
00756                 }
00757               
00758               version = entry;
00759               CmtSystem::basename (path, entry);
00760               
00761               if (entry == name)
00762                 {
00763                   // The structure is with the version directory.
00764                   
00765                   //cout << "#4" << endl;
00766 
00767                   a.run (name, version, where);
00768                   has_package = true;
00769                   
00770                   continue;
00771                 }
00772 
00773               // No directory structure matches the package name
00774               // Is it a typo in the requirements file ?
00775               // probably we should display it and quit...
00776             }
00777           else
00778             {
00779               version = entry;
00780               CmtSystem::basename (path, entry);
00781             }
00782 
00783           // The package name is not specified in the requirements file
00784           // or did not match the directory structure
00785           // We'll have to guess it from the structure
00786               
00787           if (CmtSystem::is_version_directory (version))
00788             {
00789               // cout << "#5" << endl;
00790 
00791               a.run (entry, version, where);
00792               has_package = true;
00793               
00794               continue;
00795             }
00796 
00797           name = version;
00798 
00799           where += CmtSystem::file_separator ();
00800           where += entry;
00801 
00802           // cout << "#6" << endl;
00803 
00804           a.run (name, "v1", where);
00805           has_package = true;
00806           
00807           continue;
00808         }
00809 
00810       //cout << "#7" << endl;
00811 
00812       scan_path (here, level + 1, a);
00813     }
00814 
00815   if (has_package)
00816     {
00817       //
00818       // At least one version was found here. Thus we want to scan further down.
00819       //
00820 
00821       for (i = 0; i < entrylist.size (); i++)
00822         {
00823           const cmt_string& e = entrylist[i];
00824 
00825           cmt_string p = path;
00826           p += CmtSystem::file_separator ();
00827           p += e;
00828 
00829             /*
00830           for (j = 1; j < _level; j++) cout << "  ";
00831           cout << "Restarting scan_path on p=" << p << endl;
00832             */
00833 
00834           cout << "#PathScanner::scan_path> Restarting scan_path on p=" << p << endl;
00835 
00836 
00837           scan_path (p, 1, a);
00838         }
00839     }
00840 
00841   _level--;
00842 }

bool PathScanner::scan_path (? const cmt_string &? ? path,
actor &? ? a
)?
?

Definition at line 591 of file cmt_awk.cxx.

References _level, _running, and CmtSystem::compress_path().

Referenced by Cmt::do_show_clients(), 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 }

Member Data Documentation

int PathScanner::_level [private]
?

Definition at line 126 of file cmt_awk.h.

Referenced by PathScanner(), and scan_path().

bool PathScanner::_running [private]
?

Definition at line 125 of file cmt_awk.h.

Referenced by PathScanner(), and scan_path().


The documentation for this class was generated from the following files:
Generated on Wed Sep 1 11:00:48 2004 for CMT by 1.2.18