3 #define _RPMIOB_INTERNAL
8 #define _RPMPYTHON_INTERNAL
11 #if defined(WITH_PYTHONEMBED)
13 #include <cStringIO.h>
30 #if defined(WITH_PYTHONEMBED)
45 if (_rpmpythonPool ==
NULL) {
54 #if defined(WITH_PYTHONEMBED)
55 static const char * _rpmpythonI_init =
"\
57 from cStringIO import StringIO;\
58 sys.stdout = StringIO();\
73 static char * _av[] = { (
char *)
"rpmpython",
NULL };
74 #if defined(WITH_PYTHONEMBED)
81 fprintf(stderr,
"==> %s(%p, %d) python %p\n", __FUNCTION__, av, flags, python);
83 if (av ==
NULL) av = _av;
85 #if defined(WITH_PYTHONEMBED)
86 if (!Py_IsInitialized()) {
87 Py_SetProgramName((
char *)_av[0]);
90 if (PycStringIO ==
NULL)
91 PycStringIO = (
struct PycStringIO_CAPI *)
92 PyCObject_Import(
"cStringIO",
"cStringIO_CAPI");
95 static const char _pythonI_init[] =
"%{?_pythonI_init}";
98 (
void) PySys_SetArgv(ac, (
char **)
av);
100 fprintf(stderr,
"==========\n%s\n==========\n", s);
114 fprintf(stderr,
"==> %s(%p,%s)\n", __FUNCTION__, python, fn);
119 #if defined(WITH_PYTHONEMBED)
120 const char * pyfn = ((fn ==
NULL || !
strcmp(fn,
"-")) ?
"<stdin>" : fn);
121 FILE * pyfp = (!
strcmp(pyfn,
"<stdin>") ? stdin : fopen(fn,
"rb"));
122 int closeit = (pyfp != stdin);
123 PyCompilerFlags
cf = { 0 };
126 PyRun_AnyFileExFlags(pyfp, pyfn, closeit, &cf);
145 if ((arg[0] ==
'/' || strchr(arg,
' ') ==
NULL)
147 && S_ISREG(sb.st_mode)) {
163 fprintf(stderr,
"==> %s(%p,%s,%p)\n", __FUNCTION__, python, str, resultp);
169 #if defined(WITH_PYTHONEMBED)
170 PyCompilerFlags
cf = { 0 };
171 PyObject *
m = PyImport_AddModule(
"__main__");
172 PyObject * d = (m ? PyModule_GetDict(m) :
NULL);
173 PyObject * v = (m ? PyRun_StringFlags(val, Py_single_input, d, d, &cf) :
NULL);
178 if (resultp !=
NULL) {
179 PyObject * sys_stdout = PySys_GetObject((
char *)
"stdout");
180 if (sys_stdout !=
NULL && PycStringIO_OutputCheck(sys_stdout)) {
181 PyObject *
o = (*PycStringIO->cgetvalue)(sys_stdout);
182 *resultp = (PyString_Check(o) ? PyString_AsString(o) :
"");
183 PyObject_CallMethod(sys_stdout,
"seek",
"i",0);
184 PyObject_CallMethod(sys_stdout,
"truncate",
NULL);
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)
enum rpmRC_e rpmRC
RPM return codes.
static rpmpython rpmpythonGetPool(rpmioPool pool)
static const char * rpmpythonSlurp(const char *arg)
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.
fprintf(stderr,"--> %s(%p,%p,%p) sig %p sigp %p\n", __FUNCTION__, dig, t, rsactx, sig, sigp)
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).
rpmiob rpmiobNew(size_t len)
Create an I/O buffer.
char * rpmiobStr(rpmiob iob)
Return I/O buffer (as string).
return strcmp(ame->name, bme->name)
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
Print copy of spec file, filling in Group/Description/Summary from specspo.
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.