diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/cache.cc | 12 | ||||
| -rw-r--r-- | python/makefile | 2 | ||||
| -rw-r--r-- | python/progress.cc | 55 | ||||
| -rw-r--r-- | python/progress.h | 38 |
4 files changed, 79 insertions, 28 deletions
diff --git a/python/cache.cc b/python/cache.cc index ceffba20..7ba53fd9 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -744,15 +744,13 @@ PyObject *TmpGetCache(PyObject *Self,PyObject *Args) { pkgCacheFile *Cache = new pkgCacheFile(); - PyObject *pyCallbackObj = 0; - PyObject *pyCallbackArgs = 0; - if (PyArg_ParseTuple(Args, "|OO", &pyCallbackObj, &pyCallbackArgs) == 0) + PyObject *pyCallbackInst = 0; + if (PyArg_ParseTuple(Args, "|O", &pyCallbackInst) == 0) return 0; - if(pyCallbackObj != 0) { - PyOpProgressStruct progress; - progress.py_update_callback_func = pyCallbackObj; - progress.py_update_callback_args = pyCallbackArgs; + if(pyCallbackInst != 0) { + PyOpProgress progress; + progress.setCallbackInst(pyCallbackInst); if (Cache->Open(progress,false) == false) return HandleErrors(); } else { diff --git a/python/makefile b/python/makefile index 481d51ea..29bbaca9 100644 --- a/python/makefile +++ b/python/makefile @@ -11,7 +11,7 @@ SLIBS = -lapt-pkg LIB_MAKES = apt-pkg/makefile APT_PKG_SRC = apt_pkgmodule.cc configuration.cc generic.cc tag.cc string.cc \ cache.cc pkgrecords.cc pkgsrcrecords.cc sourcelist.cc \ - depcache.cc + depcache.cc progress.cc SOURCE := $(APT_PKG_SRC) include $(PYTHON_H) progress.h diff --git a/python/progress.cc b/python/progress.cc new file mode 100644 index 00000000..d414ca15 --- /dev/null +++ b/python/progress.cc @@ -0,0 +1,55 @@ +// Description /*{{{*/ +// $Id: progress.cc,v 1.5 2003/06/03 03:03:23 mdz Exp $ +/* ###################################################################### + + Progress - Wrapper for the progress related functions + + ##################################################################### */ + +#include "progress.h" + + +void PyOpProgress::Update() +{ + if(callbackInst == 0) + return; + + // Build up the argument list... + PyObject *arglist = Py_BuildValue("(f)", Percent); + + // ...for calling the Python compare function. + PyObject *method = PyObject_GetAttrString(callbackInst, "Update"); + if(method == NULL) { + // FIXME: make this silent + Py_DECREF(arglist); + return; + } + PyObject *result = PyEval_CallObject(method,arglist); + + Py_XDECREF(result); + Py_XDECREF(method); + Py_DECREF(arglist); + + return; +}; + +void PyOpProgress::Done() +{ + if(callbackInst == 0) + return; + + // Build up the argument list... + PyObject *arglist = Py_BuildValue("()", NULL); + + // ...for calling the Python compare function. + PyObject *method = PyObject_GetAttrString(callbackInst, "Done"); + if(method == NULL) { + Py_DECREF(arglist); + return; + } + PyObject *result = PyEval_CallObject(method,arglist); + + Py_XDECREF(result); + Py_XDECREF(method); + Py_DECREF(arglist); +} diff --git a/python/progress.h b/python/progress.h index 5859eea0..b18778b1 100644 --- a/python/progress.h +++ b/python/progress.h @@ -1,31 +1,29 @@ -#ifndef PROGRESS_H -#define PROGRESS_H +// Description /*{{{*/ +// $Id: progress.h,v 1.5 2003/06/03 03:03:23 mdz Exp $ +/* ###################################################################### -#include<iostream> - -struct PyOpProgressStruct : public OpProgress -{ + Progress - Wrapper for the progress related functions - PyObject *py_update_callback_func; - PyObject *py_update_callback_args; + ##################################################################### */ - virtual void Update() { - if(py_update_callback_func == 0) - return; +#ifndef PROGRESS_H +#define PROGRESS_H - // Build up the argument list... - PyObject *arglist = Py_BuildValue("fO", Percent,py_update_callback_args); +#include <apt-pkg/progress.h> +#include <Python.h> - // ...for calling the Python compare function. - PyObject *result = PyEval_CallObject(py_update_callback_func,arglist); +struct PyOpProgress : public OpProgress +{ + PyObject *callbackInst; - Py_XDECREF(result); - Py_DECREF(arglist); + void setCallbackInst(PyObject *o) { + callbackInst = o; + } - return; - }; + virtual void Update(); + virtual void Done(); - PyOpProgressStruct() : OpProgress(), py_update_callback_func(0) {}; + PyOpProgress() : OpProgress(), callbackInst(0) {}; }; #endif |
