2 #if defined(WITH_PYTHONEMBED)
9 #define _RPMIOB_INTERNAL
14 #define _RPMPYTHON_INTERNAL
31 #if defined(WITH_PYTHONEMBED)
46 if (_rpmpythonPool == NULL) {
55 #if defined(WITH_PYTHONEMBED)
56 static const char * _rpmpythonI_init =
"\
58 from cStringIO import StringIO;\
59 sys.stdout = StringIO();\
74 static char * _av[] = { (
char *)
"rpmpython", NULL };
75 #if defined(WITH_PYTHONEMBED)
76 int initialize = (!(flags & 0x80000000) ||
_rpmpythonI == NULL);
82 fprintf(stderr,
"==> %s(%p, %d) python %p\n", __FUNCTION__, av, flags, python);
84 if (av == NULL) av = _av;
86 #if defined(WITH_PYTHONEMBED)
87 if (!Py_IsInitialized()) {
88 Py_SetProgramName((
char *)_av[0]);
91 if (PycStringIO == NULL)
92 PycStringIO = (
struct PycStringIO_CAPI *)
93 PyCObject_Import(
"cStringIO",
"cStringIO_CAPI");
96 static const char _pythonI_init[] =
"%{?_pythonI_init}";
97 const char * s =
rpmExpand(_rpmpythonI_init, _pythonI_init, NULL);
99 (void) PySys_SetArgv(ac, (
char **)av);
101 fprintf(stderr,
"==========\n%s\n==========\n", s);
115 fprintf(stderr,
"==> %s(%p,%s)\n", __FUNCTION__, python, fn);
120 #if defined(WITH_PYTHONEMBED)
121 const char * pyfn = ((fn == NULL || !strcmp(fn,
"-")) ?
"<stdin>" : fn);
122 FILE * pyfp = (!strcmp(pyfn,
"<stdin>") ? stdin : fopen(fn,
"rb"));
123 int closeit = (pyfp != stdin);
124 PyCompilerFlags cf = { 0 };
127 PyRun_AnyFileExFlags(pyfp, pyfn, closeit, &cf);
139 const char * val = NULL;
143 if (!strcmp(arg,
"-")) {
146 if ((arg[0] ==
'/' || strchr(arg,
' ') == NULL)
148 && S_ISREG(sb.st_mode)) {
164 fprintf(stderr,
"==> %s(%p,%s,%p)\n", __FUNCTION__, python, str, resultp);
170 #if defined(WITH_PYTHONEMBED)
171 PyCompilerFlags cf = { 0 };
172 PyObject * m = PyImport_AddModule(
"__main__");
173 PyObject *
d = (m ? PyModule_GetDict(m) : NULL);
174 PyObject *
v = (m ? PyRun_StringFlags(val, Py_single_input, d, d, &cf) : NULL);
179 if (resultp != NULL) {
180 PyObject * sys_stdout = PySys_GetObject((
char *)
"stdout");
181 if (sys_stdout != NULL && PycStringIO_OutputCheck(sys_stdout)) {
182 PyObject * o = (*PycStringIO->cgetvalue)(sys_stdout);
183 *resultp = (PyString_Check(o) ? PyString_AsString(o) :
"");
184 PyObject_CallMethod(sys_stdout,
"seek",
"i",0);
185 PyObject_CallMethod(sys_stdout,
"truncate", NULL);
const char const double d
char * xstrdup(const char *str)
static rpmpython rpmpythonI(void)
int Stat(const char *path, struct stat *st)
stat(2) clone.
rpmRC rpmpythonRunFile(rpmpython python, const char *fn, const char **resultp)
Execute python from a file.
rpmiob rpmiobFree(rpmiob iob)
Destroy a I/O buffer instance.
rpmiob rpmiobAppend(rpmiob iob, const char *s, size_t nl)
Append string to I/O buffer.
int rpmiobSlurp(const char *fn, rpmiob *iobp)
static void rpmpythonFini(void *_python)
static rpmpython rpmpythonGetPool(rpmioPool pool)
static const char * rpmpythonSlurp(const char *arg)
const char const bson_bool_t v
rpmioItem rpmioGetPool(rpmioPool pool, size_t size)
Get unused item from pool, or alloc a new item.
rpmRC rpmpythonRun(rpmpython python, const char *str, const char **resultp)
Execute python string.
int argvCount(const ARGV_t argv)
Return no.
struct rpmpython_s * rpmpython
rpmpython rpmpythonNew(char **av, uint32_t flags)
Create and load a python interpreter.
char * rpmExpand(const char *arg,...)
Return (malloc'ed) concatenated macro expansion(s).
const char const char int arg
rpmiob rpmiobNew(size_t len)
Create an I/O buffer.
const char const bson int mongo_write_concern int flags
enum rpmRC_e rpmRC
RPM return codes.
char * rpmiobStr(rpmiob iob)
Return I/O buffer (as string).
rpmioPool rpmioNewPool(const char *name, size_t size, int limit, int flags, char *(*dbg)(void *item), void(*init)(void *item), void(*fini)(void *item))
Create a memory pool.
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
rpmpython rpmpythonLink(rpmpython python)
Reference a python interpreter instance.