{
std::string pkgName;
std::string userModule;
po::options_description generic("Generic options");
generic.add_options()
("help,h",
"produce this help message")
("package-name,p",
po::value<string>(),
"name of the package for which we create the configurables file")
("input-libraries,i",
po::value<string>(),
"libraries to extract the component configurables from")
("input-cfg,c",
po::value<string>(),
"path to the cfg file holding the description of the Configurable base "
"classes, the python module holding the Configurable definitions, etc...")
("output-dir,o",
po::value<string>()->default_value("../genConf"),
"output directory for genconf files.")
("debug-level,d",
po::value<int>()->default_value(0),
"debug level")
("load-library,l",
po::value< Strings_t >()->composing(),
"preloading library")
("user-module,m",
po::value<string>(),
"user-defined module to be imported by the genConf-generated one")
("no-init",
"do not generate the (empty) __init__.py")
;
po::options_description
config(
"Configuration");
("configurable-module",
po::value<string>()->default_value("AthenaCommon"),
"Name of the module holding the configurable classes")
("configurable-default-name",
po::value<string>()->default_value("Configurable.DefaultName"),
"Default name for the configurable instance")
("configurable-algorithm",
po::value<string>()->default_value("ConfigurableAlgorithm"),
"Name of the configurable base class for Algorithm components")
("configurable-algtool",
po::value<string>()->default_value("ConfigurableAlgTool"),
"Name of the configurable base class for AlgTool components")
("configurable-auditor",
po::value<string>()->default_value("ConfigurableAuditor"),
"Name of the configurable base class for Auditor components")
("configurable-service",
po::value<string>()->default_value("ConfigurableService"),
"Name of the configurable base class for Service components")
;
po::options_description cmdline_options;
cmdline_options.add(
generic).add(
config);
po::options_description config_file_options;
config_file_options.add(
config);
po::options_description visible("Allowed options");
visible.add(
generic).add(
config);
po::variables_map vm;
try {
po::store( po::command_line_parser(
argc,
argv).
vm );
po::notify(vm);
if( vm.count("input-cfg") ) {
string cfgFileName = vm["input-cfg"].as<string>();
cfgFileName = fs::system_complete(
fs::path( cfgFileName ) ).string();
std::ifstream ifs( cfgFileName.c_str() );
po::store( parse_config_file( ifs, config_file_options ), vm );
}
po::notify(vm);
}
catch ( po::error& err ) {
cout << "ERROR: error detected while parsing command options: "<< err.what() << endl;
return EXIT_FAILURE;
}
if( vm.count("help")) {
cout << visible << endl;
return EXIT_FAILURE;
}
if( vm.count("package-name") ) {
pkgName = vm["package-name"].as<string>();
}
else {
cout << "ERROR: 'package-name' required" << endl;
cout << visible << endl;
return EXIT_FAILURE;
}
if( vm.count("user-module") ) {
userModule = vm["user-module"].as<string>();
cout << "INFO: will import user module " << userModule << endl;
}
if( vm.count("input-libraries") ) {
{
string tmp = vm["input-libraries"].as<string>();
boost::split( inputLibs, tmp,
boost::is_any_of(" "),
boost::token_compress_on );
}
libs.reserve( inputLibs.size() );
for ( Strings_t::const_iterator iLib = inputLibs.begin();
iLib != inputLibs.end();
++iLib ) {
std::string lib =
fs::path(*iLib).stem().string();
if ( 0 == lib.find("lib") ) {
lib = lib.substr(3);
}
if ( !lib.empty() &&
std::find( libs.begin(), libs.end(), lib ) == libs.end() ) {
libs.push_back( lib );
}
}
if ( libs.empty() ) {
cout << "ERROR: input component library(ies) required !\n"
<< "ERROR: 'input-libraries' argument was ["
<< vm["input-libraries"].as<string>()
<< "]"
<< endl;
return EXIT_FAILURE;
}
}
else {
cout << "ERROR: input component library(ies) required" << endl;
cout << visible << endl;
return EXIT_FAILURE;
}
if( vm.count("output-dir") ) {
out = fs::system_complete(
fs::path( vm[
"output-dir"].as<string>() ) );
}
if ( vm.count("debug-level") ) {
}
if ( vm.count("load-library") ) {
for (Strings_t::const_iterator lLib=lLib_list.begin();
lLib != lLib_list.end();
++lLib) {
if (err != 1) {
cout << "WARNING: failed to load: "<< *lLib << endl;
}
}
}
if ( !fs::exists( out ) ) {
try {
fs::create_directory(out);
}
catch ( fs::filesystem_error &err ) {
cout << "ERROR: error creating directory: "<< err.what() << endl;
return EXIT_FAILURE;
}
}
cout << ":::::: libraries : [ ";
copy( libs.begin(), libs.end(), ostream_iterator<string>(cout, " ") );
cout << "] ::::::" << endl;
py.setConfigurableDefaultName(vm["configurable-default-name"].as<string>());
py.setConfigurableAlgorithm (vm["configurable-algorithm"].as<string>());
py.setConfigurableAlgTool (vm["configurable-algtool"].as<string>());
py.setConfigurableAuditor (vm["configurable-auditor"].as<string>());
py.setConfigurableService (vm["configurable-service"].as<string>());
try {
sc = py.genConfig( libs, userModule );
}
catch ( exception& e ) {
cout << "ERROR: Could not generate Configurable(s) !\n"
<< "ERROR: Got exception: " << e.what() << endl;
return EXIT_FAILURE;
}
if ( EXIT_SUCCESS == sc && ! vm.count("no-init")) {
fstream initPy( ( out /
fs::path(
"__init__.py" ) ).
string().c_str(),
std::ios_base::out|std::ios_base::trunc );
initPy << "## Hook for " << pkgName << " genConf module\n" << flush;
}
cout << ":::::: libraries : [ ";
copy( libs.begin(), libs.end(), ostream_iterator<string>(cout, " ") );
cout << "] :::::: [DONE]" << endl;
}