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

FileScanner Class Reference

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

List of all members.

Public Methods

 FileScanner ()
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 85 of file cmt_parser.cxx.


Constructor & Destructor Documentation

FileScanner::FileScanner ( )
 

Definition at line 159 of file cmt_parser.cxx.

00160 {
00161   _running = false;
00162   _level = 0;
00163 }


Member Function Documentation

bool FileScanner::scan_package ( const cmt_string & path,
const cmt_string & package )
 

Definition at line 285 of file cmt_parser.cxx.

Referenced by Cmt::do_show_versions().

00287 {
00288   //
00289   // Only do something if it is a directory.
00290   //
00291 
00292   if (!CmtSystem::test_directory (path)) return (false);
00293 
00294   cmt_string pattern = path;
00295   pattern += CmtSystem::file_separator ();
00296   pattern += package;
00297 
00298   if (!CmtSystem::test_directory (pattern)) return (false);
00299 
00300   CmtSystem::cmt_string_vector list;
00301 
00302   CmtSystem::scan_dir (pattern, list);
00303 
00304   if (list.size () == 0) return (false);
00305 
00306   bool result = false;
00307 
00308   int i;
00309   for (i = 0; i < list.size (); i++)
00310     {
00311       const cmt_string& name = list[i];
00312 
00313       cmt_string version;
00314       CmtSystem::basename (name, version);
00315 
00316       if (CmtSystem::is_version_directory (version))
00317         {
00318           cmt_string req;
00319 
00320           req = name;
00321           req += CmtSystem::file_separator ();
00322           req += "cmt";
00323           req += CmtSystem::file_separator ();
00324           req += "requirements";
00325 
00326           if (CmtSystem::test_file (req))
00327             {
00328               //cout << " -> cmt" << endl;
00329 
00330               cout << package << " " << version << " " << path << endl;
00331 
00332               result = true;
00333             }
00334           else
00335             {
00336               //cout << " -> no cmt" << endl;
00337 
00338               req = name;
00339               req += CmtSystem::file_separator ();
00340               req += "mgr";
00341               req += CmtSystem::file_separator ();
00342               req += "requirements";
00343 
00344               if (CmtSystem::test_file (req))
00345                 {
00346                   //cout << " -> mgr" << endl;
00347 
00348                   cout << package << " " << version << " " << path << endl;
00349 
00350                   result = true;
00351                 }
00352               else
00353                 {
00354                   //cout << " -> no mgr" << endl;
00355                 }
00356             }
00357         }
00358       else
00359         {
00360           //cout << " -> stop" << endl;
00361         }
00362     }
00363 
00364   return (result);
00365 }

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

Definition at line 180 of file cmt_parser.cxx.

00181 {
00182   //
00183   // Only do something if it is a directory.
00184   //
00185 
00186   if (!CmtSystem::test_directory (path)) return;
00187 
00188   CmtSystem::cmt_string_vector list;
00189 
00190   CmtSystem::scan_dir (path, list);
00191 
00192   if (list.size () == 0) return;
00193 
00194   _level++;
00195 
00196   // Will be set if at least one directory is a version directory
00197   bool has_package = false;
00198 
00199   cmt_string pack;
00200   CmtSystem::basename (path, pack);
00201 
00202   int i;
00203   for (i = 0; i < list.size (); i++)
00204     {
00205       const cmt_string& name = list[i];
00206 
00207       //cout << "scan> level=" << level << " name=" << name;
00208 
00209       cmt_string version;
00210       CmtSystem::basename (name, version);
00211 
00212       //
00213       //  All entries at this level may be "legal" version directories.
00214       //
00215       //  So we go down but no more then one level deep.
00216       //  The next level we request that the entry is a version
00217       //  and that there is a mgr/requirements file below.
00218       //
00219 
00220       if (level == 0)
00221         {
00222           //cout << " -> down" << endl;
00223           scan_path (name, level + 1, a);
00224         }
00225       else if (CmtSystem::is_version_directory (version))
00226         {
00227           cmt_string req;
00228 
00229           req = name;
00230           req += CmtSystem::file_separator ();
00231           req += "cmt";
00232           req += CmtSystem::file_separator ();
00233           req += "requirements";
00234 
00235           if (CmtSystem::test_file (req))
00236             {
00237               //cout << " -> cmt" << endl;
00238 
00239               a.run (pack, version, path);
00240 
00241               has_package = true;
00242             }
00243           else
00244             {
00245               //cout << " -> no cmt" << endl;
00246               req = name;
00247               req += CmtSystem::file_separator ();
00248               req += "mgr";
00249               req += CmtSystem::file_separator ();
00250               req += "requirements";
00251 
00252               if (CmtSystem::test_file (req))
00253                 {
00254                   //cout << " -> cmt" << endl;
00255 
00256                   a.run (pack, version, path);
00257 
00258                   has_package = true;
00259                 }
00260               else
00261                 {
00262                   //cout << " -> no mgr" << endl;
00263                 }
00264             }
00265         }
00266       else
00267         {
00268           //cout << " -> stop" << endl;
00269         }
00270     }
00271 
00272   if (has_package)
00273     {
00274       //
00275       // At least one version was found here.
00276       //
00277       scan_path (path, 0, a);
00278     }
00279 
00280   _level--;
00281 }

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

Definition at line 166 of file cmt_parser.cxx.

Referenced by Cmt::do_broadcast(), Cmt::do_show_clients(), Cmt::do_show_packages(), and scan_path().

00167 {
00168   if (_running) return (false);
00169 
00170   _level = 0;
00171   _running = true;
00172   scan_path (path, 0, a);
00173   _running = false;
00174   _level = 0;
00175 
00176   return (true);
00177 }


Member Data Documentation

int FileScanner::_level [private]
 

Definition at line 106 of file cmt_parser.cxx.

bool FileScanner::_running [private]
 

Definition at line 105 of file cmt_parser.cxx.


The documentation for this class was generated from the following file:
Generated at Mon Jun 10 17:58:39 2002 for CMT by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000