2 #include <boost/filesystem/path.hpp>
3 #include <boost/filesystem/operations.hpp>
4 #include <boost/bind.hpp>
5 #include <boost/mem_fn.hpp>
7 #include <boost/program_options.hpp>
27 using namespace edmplugin;
30 ostream& operator<<(std::ostream& o, const vector<std::string>& iValue) {
32 std::string commaSep(
",");
33 for(std::vector<std::string>::const_iterator it=iValue.begin(), itEnd=iValue.end();
48 iBase->
newPluginAdded_.connect(boost::bind(boost::mem_fn(&Listener::newPlugin),
this,_1,_2));
51 nameAndTypes_.push_back(NameAndType(iInfo.
name_,iCategory));
54 NameAndTypes nameAndTypes_;
57 int main (
int argc,
char **argv)
59 using namespace boost::program_options;
61 static const char*
const kPathsOpt =
"paths";
62 static const char*
const kPathsCommandOpt =
"paths,p";
65 static const char*
const kHelpOpt =
"help";
68 std::string descString(argv[0]);
69 descString +=
" [options] [[--";
70 descString += kPathsOpt;
71 descString +=
"] path [path]] \nAllowed options";
72 options_description desc(descString);
73 std::string defaultDir(
".");
75 if( not defaultDirList.empty() ) {
76 defaultDir = defaultDirList[0];
80 (kPathsCommandOpt,
value<std::vector<std::string> >()->default_value(
81 std::vector<std::string>(1,defaultDir))
82 ,
"a directory or a list of files to scan")
86 positional_options_description
p;
91 store(command_line_parser(argc,argv).
options(desc).positional(
p).
run(),vm);
93 }
catch(
const error& iException) {
111 int returnValue = EXIT_SUCCESS;
114 std::vector<std::string> requestedPaths(vm[kPathsOpt].as<std::vector<std::string> >());
118 std::vector<std::string>
files;
119 bool removeMissingFiles =
false;
120 if(boost::filesystem::is_directory(directory)) {
121 if (requestedPaths.size()>1) {
122 std::cerr <<
"if a directory is given then only one argument is allowed"<<std::endl;
127 removeMissingFiles =
true;
129 boost::filesystem::directory_iterator
file (directory);
130 boost::filesystem::directory_iterator
end;
132 path cacheFile(directory);
135 std::time_t cacheLastChange(0);
136 if(exists(cacheFile)) {
137 cacheLastChange = last_write_time(cacheFile);
143 path shortName(file->leaf());
144 std::string stringName = shortName.string();
147 if (stringName.size() < kPluginPrefix.size()) {
150 if(stringName.substr(0,kPluginPrefix.size()) != kPluginPrefix) {
154 if(last_write_time(filename) > cacheLastChange) {
155 files.push_back(stringName);
160 directory = directory.branch_path();
161 for(std::vector<std::string>::iterator it=requestedPaths.begin(), itEnd=requestedPaths.end();
164 if ( not exists(f) ) {
165 std::cerr <<
"the file '"<<f.native_file_string()<<
"' does not exist"<<std::endl;
168 if (is_directory(f) ) {
169 std::cerr <<
"either one directory or a list of files are allowed as arguments"<<std::endl;
172 if(directory != f.branch_path()) {
173 std::cerr <<
"all files must have be in the same directory ("<<directory.native_file_string()<<
")\n"
174 " the file "<<f.native_file_string()<<
" does not."<<std::endl;
176 files.push_back(f.leaf());
180 path cacheFile(directory);
184 if(exists(cacheFile) ) {
185 std::ifstream cf(cacheFile.native_file_string().c_str());
187 cms::Exception(
"FailedToOpen")<<
"unable to open file '"<<cacheFile.native_file_string()<<
"' for reading even though it is present.\n"
188 "Please check permissions on the file.";
197 pfm->
newFactory_.connect(boost::bind(boost::mem_fn(&Listener::newFactory),&listener,_1));
198 edm::for_all(*pfm, boost::bind(boost::mem_fn(&Listener::newFactory),&listener,_1));
200 for(std::vector<std::string>::iterator itFile = files.begin();
201 itFile != files.end();
204 path loadableFile(directory);
205 loadableFile /=(*itFile);
206 listener.nameAndTypes_.clear();
214 ltp[*itFile]=listener.nameAndTypes_;
216 if(iException.
category() ==
"PluginLibraryLoadError") {
217 std::cerr <<
"Caught exception "<<iException.
what()<<
" will ignore "<<*itFile<<
" and continue."<<std::endl;
224 if(removeMissingFiles) {
225 for(CacheParser::LoadableToPlugins::iterator itFile = ltp.begin();
228 path loadableFile(directory);
229 loadableFile /=(itFile->first);
230 if(not exists(loadableFile)) {
231 std::cout <<
"removing file '"<<loadableFile.native_file_string()<<
"'"<<std::endl;
232 CacheParser::LoadableToPlugins::iterator itToItemBeingRemoved = itFile;
235 ltp.erase(itToItemBeingRemoved);
244 std::ofstream cf(cacheFile.native_file_string().c_str());
246 cms::Exception(
"FailedToOpen")<<
"unable to open file '"<<cacheFile.native_file_string()<<
"' for writing.\n"
247 "Please check permissions on the file.";
251 std::cerr <<
"Caught exception "<<iException.what()<<std::endl;
virtual char const * what() const
const boost::filesystem::path & cachefileName()
std::pair< std::string, std::string > NameAndType
bool tryToFind(const SharedLibrary &iLoadable)
Check to see if any capabilities are in the file, returns 'true' if found.
const std::string & pluginPrefix()
int main(int argc, char **argv)
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
std::map< boost::filesystem::path, NameAndTypes > LoadableToPlugins
PluginManager::Config config()
std::vector< NameAndType > NameAndTypes
static PluginCapabilities * get()
sigc::signal< void, const std::string &, const PluginInfo & > newPluginAdded_
signal containing plugin category, and plugin info for newly added plugin
static void write(const CategoryToInfos &, std::ostream &)
static const char *const kHelpCommandOpt
Config & searchPath(const SearchPath &iPath)
sigc::signal< void, const PluginFactoryBase * > newFactory_
static void read(std::istream &, const boost::filesystem::path &iDirectory, CategoryToInfos &oOut)
static const char *const kHelpOpt
static PluginFactoryManager * get()
std::string category() const