// Clint - Source code checker for C++ // Copyright (C) 2001 David Pashley // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include #include "python_plugin.h" #include "python_rule.h" #include #include #include "python_module.h" void PythonPlugin::initialize(){ interpreter = python::Python::Instance(); interpreter->add_directory_to_path(PY_RULES_DIR); register_module(); } void PythonPlugin::finalize() { } void PythonPlugin::register_rules(RuleList & rules) { load_directory(rules,clint::find_home()+"/.clint/plugins/python"); load_directory(rules,PY_RULES_DIR "/python_rules"); } void PythonPlugin::load_directory(RuleList & rules, std::string directory) { interpreter->add_directory_to_path(directory); struct dirent * dir_entry; std::string filename; DIR *curdir = opendir(directory.c_str()); if (curdir) { while ( ( dir_entry = readdir(curdir) ) ) { filename = dir_entry->d_name; std::string extension(filename.begin()+filename.find(".py"),filename.end()); if ( extension ==".py" ){ PythonRule *rule = new PythonRule(); rule->load_module( filename ); rules.push_back( rule ); } } closedir(curdir); } else { // There is something wrong with the directory. Probably doesn't // exist } return; } // }}} extern "C" { class proxy { public: proxy(){ // register the maker with the factory plugins.push_back(new PythonPlugin); } }; // our one instance of the proxy proxy p; }