X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fappli%2FbbpConfigurator%2FbbpConfigurator.cpp;h=4de87c8161b0cf4d3611f2f4752842e1eb65b256;hb=6827eadc2157e47cc354282c7992fe052e6b5ca0;hp=8e151da84e477955c648d003e3fe1ffa424c54a5;hpb=9ca9baeef03df0bfaea871676ea7f8566e8124e7;p=bbtk.git diff --git a/kernel/appli/bbpConfigurator/bbpConfigurator.cpp b/kernel/appli/bbpConfigurator/bbpConfigurator.cpp index 8e151da..4de87c8 100644 --- a/kernel/appli/bbpConfigurator/bbpConfigurator.cpp +++ b/kernel/appli/bbpConfigurator/bbpConfigurator.cpp @@ -55,7 +55,7 @@ int main(int argc, char **argv) // Check arguments if (argc != 4) { - std::cout << "usage : bbConfigurator " << std::endl; + std::cout << "bbpConfigurator usage: bbConfigurator " << std::endl; return 1; } @@ -63,11 +63,39 @@ int main(int argc, char **argv) std::string package_name(argv[2]); std::string path_out(argv[3]); + std::cout << "bbpConfigurator launched with bbs path: '" << path_bbs << + "', package: '" << package_name << + "', output path: '" << path_out << "'." << std::endl; + // Get bbs files in path_bbs std::vector files = getFileList(path_bbs); if(files.size() == 0) { - std::cout << "No files to check." << std::endl; + std::cout << "bbpConfigurator: No files to check in bbs path. " + "An empty bbp will be created for the package '" << package_name << "'." << std::endl; + + // Write results to bbp file + #ifdef WIN32 + std::string fname = path_out + "\\" + package_name + ".bbp"; + #else + std::string fname = path_out + "/" + package_name + ".bbp"; + #endif + + std::ofstream out(fname.c_str()); + out << "#-----------------------------------------" << std::endl; + out << "# Include script for bbtk package '" << package_name << "'" << std::endl; + out << "# Automatically generated by bbpConfigurator" << std::endl; + out << "#-----------------------------------------" << std::endl; + out << "load "<< package_name << std::endl; + out << "#-----------------------------------------" << std::endl; + out << "package "<< package_name << std::endl; + out << "#-----------------------------------------" << std::endl; + out << "endpackage" << std::endl; + out << "#-- EOF ----------------------------------" << std::endl; + + out.close(); + + return 0; } @@ -78,15 +106,46 @@ int main(int argc, char **argv) BoxesVector boxs; - for (int i = 0; i < (int)files.size(); ++i) { + for (int i = 0; i < (int)files.size(); ++i) + { bbtk::BBPInterpreter::Pointer I = bbtk::BBPInterpreter::New(); I->InterpretFile(files[i].string()); + + boxs.push_back( ((bbtk::BBPInterpreter*)(I.get()))->boxName ); - deps.push_back( ((bbtk::BBPInterpreter*)(I.get()))->dependencies ); - //print box name and dependencies +// EED 2016/02/19 +// deps.push_back( ((bbtk::BBPInterpreter*)(I.get()))->dependencies ); + //--> Cleanning string package:boxname -> boxname + std::set tmpDependencies1= ((bbtk::BBPInterpreter*)(I.get()))->dependencies ; + std::set tmpDependencies2; + std::set::const_iterator sit(tmpDependencies1.begin()), send(tmpDependencies1.end()); + int pos; + std::string tmpStr; // std::cout << ((bbtk::BBPInterpreter*)(I.get()))->boxName << ": "; -// for( + for(;sit!=send;++sit) + { + pos=(*sit).find(":"); + if (pos== std::string::npos ) + { + tmpDependencies2.insert( *sit ); +// std::cout << *sit << ' '; + } else { + tmpStr=(*sit).substr(pos+1); + tmpDependencies2.insert( tmpStr ); +// std::cout << tmpStr << ' '; + } // if + + } // for +// std::cout << std::endl; + deps.push_back( tmpDependencies2 ); + //<-- + + + +// //print box name and dependencies OLD VERSION +// std::cout << ((bbtk::BBPInterpreter*)(I.get()))->boxName << ": "; +// for( // Dependencies::iterator it = ((bbtk::BBPInterpreter*)(I.get()))->dependencies.begin(); // it != ((bbtk::BBPInterpreter*)(I.get()))->dependencies.end(); // it++) { @@ -94,22 +153,21 @@ int main(int argc, char **argv) // } // std::cout << std::endl; - } + } // for i // Only keep dependencies from package Dependencies boxNamesSet(boxs.begin(), boxs.end()); - //std::cout << "after: " << std::endl; - for (DependenciesVector::iterator it = deps.begin(); it != deps.end(); it++) { +//std::cout << "after: " << std::endl; + for (DependenciesVector::iterator it = deps.begin(); it != deps.end(); it++) + { BoxesVector tmp; std::set_intersection(it->begin(), it->end(), boxNamesSet.begin(), boxNamesSet.end(),std::back_inserter(tmp)); Dependencies tmp1(tmp.begin(),tmp.end()); it->swap( tmp1 ); - //print clean dependencies -// for( -// Dependencies::iterator it1 = it->begin(); -// it1 != it->end(); -// it1++) { +// //print clean dependencies +// for( Dependencies::iterator it1 = it->begin(); it1 != it->end(); it1++) +// { // std::cout << *it1 << ", "; // } // std::cout << std::endl; @@ -138,12 +196,13 @@ int main(int argc, char **argv) // Check there are no cycles in graph if(isCycle(g)) { - std::cout << "there are dependency cycles, please check your scripts." << std::endl; + std::cout << "bbpConfigurator: There are dependency cycles, please check your scripts in '" << + path_bbs << "'. No bbp file created." << std::endl; return 2; } else { - std::cout << "no cycles, we keep going." << std::endl; + std::cout << "bbpConfigurator: No cycles detected in dependency graph." << std::endl; std::vector priorities(boxs.size(), -1); setPriorities(g, priorities); // for (int i = 0; i < (int)priorities.size(); i++) @@ -181,7 +240,9 @@ int main(int argc, char **argv) // find max priority level int mx_priority = 0; for (int i = 0; i < (int)priorities.size(); i++) + { mx_priority = std::max(mx_priority, priorities[i]); + } // for each priority level print scripts in that level. for (int i = 0; i <= mx_priority; i++) @@ -199,6 +260,8 @@ int main(int argc, char **argv) out << "#-- EOF ----------------------------------" << std::endl; out.close(); + + std::cout << "bbpConfigurator: bbp file created at '" << fname << "'." << std::endl; } return 0; } @@ -291,7 +354,7 @@ std::vector getFileList(const std::string& path) } else { - std::cout<< "the path to the bbs's should be a folder and not a file."; + std::cout<< "bbpConfigurator: The path to the bbs's doesn't exist or is not a folder. ('" << path << "')" << std::endl; return files; }