12 #include <boost/python.hpp>
15 using namespace boost::python;
18 const std::string& postAction ) {
22 object main_module( ( handle<>( borrowed( PyImport_AddModule(
"__main__" ) ) ) ) );
23 object main_namespace = main_module.attr(
"__dict__" );
26 main_namespace[
"PythonAdaptor"] =
27 class_<PythonAdaptor>(
"PythonAdaptor", boost::python::init<Gaudi::Interfaces::IOptionsSvc*>() )
32 main_namespace[
"adaptor"] = ptr( &adaptor );
35 std::string
command( preAction );
38 command +=
" with open(name) as f:\n";
39 command +=
" code = compile(f.read(), name, 'exec')\n";
41 command +=
"from GaudiKernel.Configurable import expandvars\nfrom GaudiKernel.Proxy.Configurable import "
42 "applyConfigurableUsers\napplyConfigurableUsers()\n";
44 command +=
"\nfor n, c in Configurable.allConfigurables.items():\n for p, v in c.getValuedProperties().items() "
45 ":\n v = expandvars(v)\n if type(v) == str : v = repr(v) # need double quotes\n elif "
46 "type(v) == long: v = '%d' % v # prevent pending 'L'\n adaptor.addPropertyToJobOptions(n,p,str(v))";
49 handle<> ignored( ( PyRun_String(
command.c_str(), Py_file_input, main_namespace.ptr(), main_namespace.ptr() ) ) );
50 }
catch (
const error_already_set& ) {
51 std::cout <<
"Error in python script:" << std::endl;