Exemplo n.º 1
0
Pyramid::Pyramid(const char* script)
{
	freopen("pyramid.log", "w", stdout);
	freopen("pyramid.log", "a", stderr);
	Py_SetProgramName(".\\pyramid");
	Py_Initialize();
	init_pyramid();

	PyRun_SimpleString(
	"import sys\n"
	"sys.path.append('./')\n"
	"sys.stderr = open('python_errors.log', 'w', 0)\n"
	"sys.stdout = open('pyramid.log', 'a', 0)\n"
	"import pyramid\n");

	char* fn_local = new char[strlen(script)+1];
	strcpy(fn_local, script);

	PyObject* fp = PyFile_FromString(fn_local, "r");
	if(!fp)
	{
		printf("Could not load mapping script '%s' for reading.\n", script);
		Py_Finalize();
		exit(1);
	}
	FILE* sfp = PyFile_AsFile(fp);

	PyRun_AnyFileEx(sfp, script, 1);

	delete[] fn_local;
}
Exemplo n.º 2
0
 static void ExecuteFile(const char* file_name)
 {
     FILE* file = NULL;
     file = fopen(file_name, "r");
     if ( file != NULL ) {
         // PyRun_AnyFileEx will close the file after execution ...
         if ( PyRun_AnyFileEx(file, file_name, 1) == -1 ) {
             // throw CError ("Unable to execute a file");
         throw string("Couldn't execute file '") + file_name + "'";
         }
     }
 }
Exemplo n.º 3
0
int
PyRun_AnyFile(FILE *fp, char *filename)
{
	return PyRun_AnyFileEx(fp, filename, 0);
}