int main(int argc, char *argv[]) {
  // Set the python interpreter.
  setup_python(argc, argv);

  std::string filepath(argv[0]);

  // Get the path to the helper script.
  std::string helper_path;
  size_t path_end = filepath.find_last_of('\\');
  if (path_end != std::string::npos)
    helper_path = filepath.substr(0, path_end + 1);

  helper_path += "wbadminhelper.py";

  // Configures the execution of the script to take the same
  // parameters as this helper tool.
  Py_SetProgramName(argv[0]);

  PySys_SetArgv(argc, argv);

  // Executes the helper script.
  PyObject *pFileObject = PyFile_FromString(const_cast<char *>(helper_path.c_str()), "r");

  PyRun_SimpleFileEx(PyFile_AsFile(pFileObject), "wbadminhelper.py", 1);

  finalize_python();

  return 0;
}
Ejemplo n.º 2
0
int assimilate_handler(WORKUNIT& wu, std::vector<RESULT>& results, RESULT& canonical_result)
{
  PyObject *retval;

  initialize_python();
#if 0// OLD
  retval = py_user_code_on_workunit(results, &canonical_result, "assimilators");
  if(retval == NULL)
    {
      fprintf(stderr,"[%s:%d] There was a python error when assimilating %s.\nExiting.\n",__FILE__,__LINE__,canonical_result.name);
      finalize_python();
      exit(1);
    }
  Py_DECREF(retval);

  if(PyErr_Occurred())
    {
      printf("Assimilation failed\n");
      PyErr_Print();
      finalize_python();
      return 1;
    }
#else // New
    std::string command;
  
  if(PyRun_SimpleString("import boinctools;results = []"))
    {
      fprintf(stderr,"Could not import boinctools python module.\n");
      if(PyErr_Occurred())
	PyErr_Print();
      finalize_python();
      exit(1);
    }
  
  // Create Result Class
  command = "canonical = " + result_init_string(canonical_result);
  if(PyRun_SimpleString(command.c_str()))
    {
      fprintf(stderr,"Could not create result object.\n");
      fprintf(stderr,"Python command: %s",command.c_str());
      if(PyErr_Occurred())
	PyErr_Print();
      finalize_python();
      exit(1);
    }

  for(std::vector<RESULT>::const_iterator result = results.begin();result != results.end();result++)
    {
      command = "results.append(" + result_init_string(*result) + ")";
      if(PyRun_SimpleString(command.c_str()))
	{
	  fprintf(stderr,"Could not add result object to assimilation result list.\n");
	  fprintf(stderr,"Python command: %s",command.c_str());
	  if(PyErr_Occurred())
	    PyErr_Print();
	  finalize_python();
	  exit(1);
	}
    }
  
  command = "boinctools.assimilator(results,canonical)";
  if(PyRun_SimpleString(command.c_str()))
    {
      fprintf(stderr,"Could not assimilate result objects.\n");
      fprintf(stderr,"Python command: %s",command.c_str());
      if(PyErr_Occurred())
	PyErr_Print();
      finalize_python();
      exit(1);
    }
  
#endif
  return 0;


}