diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/apt_pkgmodule.cc | 3 | ||||
| -rw-r--r-- | python/apt_pkgmodule.h | 8 | ||||
| -rw-r--r-- | python/depcache.cc | 74 | ||||
| -rw-r--r-- | python/makefile | 3 |
4 files changed, 76 insertions, 12 deletions
diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index d9d0911f..95201f35 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -331,6 +331,7 @@ static PyMethodDef methods[] = // Cache {"GetCache",TmpGetCache,METH_VARARGS,"GetCache() -> PkgCache"}, + {"GetDepCache",GetDepCache,METH_VARARGS,"GetDepCache(Cache) -> DepCache"}, {"GetPkgRecords",GetPkgRecords,METH_VARARGS,"GetPkgRecords(Cache) -> PkgRecords"}, {"GetPkgSrcRecords",GetPkgSrcRecords,METH_VARARGS,"GetPkgSrcRecords() -> PkgSrcRecords"}, {"GetPkgSourceList",GetPkgSourceList,METH_VARARGS,"GetPkgSourceList() -> PkgSourceList"}, @@ -394,6 +395,8 @@ extern "C" void initapt_pkg() AddInt(Dict,"PriStandard",pkgCache::State::Standard); AddInt(Dict,"PriOptional",pkgCache::State::Optional); AddInt(Dict,"PriExtra",pkgCache::State::Extra); + + } /*}}}*/ diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index b2222df4..82389590 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -59,6 +59,14 @@ extern PyTypeObject DependencyType; extern PyTypeObject RDepListType; PyObject *TmpGetCache(PyObject *Self,PyObject *Args); +// DepCache +extern PyTypeObject PkgDepCacheType; +PyObject *GetDepCache(PyObject *Self,PyObject *Args); + +// Progress +bool AddOpProgressToModule(PyObject *Dict); +PyObject *GetOpProgress(PyObject *Self,PyObject *Args); + // PkgRecords Stuff extern PyTypeObject PkgRecordsType; PyObject *GetPkgRecords(PyObject *Self,PyObject *Args); diff --git a/python/depcache.cc b/python/depcache.cc index ea86bf3c..eea76999 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -19,34 +19,83 @@ #include <Python.h> +#include <iostream> + + + +struct PyOpProgressStruct : public OpProgress +{ + + PyObject *py_update_callback_func; + PyObject *py_update_callback_args; + + virtual void Update() { + if(py_update_callback_func == NULL) + return; + + // Build up the argument list... + PyObject *arglist = Py_BuildValue("(fO)", Percent, py_update_callback_args); + + // ...for calling the Python compare function. + PyObject *result = PyEval_CallObject(py_update_callback_func,arglist); + + Py_XDECREF(result); + Py_DECREF(arglist); + + return; + }; + + PyOpProgressStruct() : OpProgress(), py_update_callback_func(0) {}; +}; + + + + // DepCache Class /*{{{*/ // --------------------------------------------------------------------- struct PkgDepCacheStruct { pkgDepCache depcache; + PyOpProgressStruct progress; PkgDepCacheStruct(pkgCache *Cache, pkgPolicy *Policy) : depcache(Cache,Policy) {}; // FIXME: wrap pkgPolicy as well and remove this "new() memory leak" PkgDepCacheStruct(pkgCache *Cache) : depcache(Cache,new pkgPolicy(Cache) ) {}; + PkgDepCacheStruct() : depcache(NULL, NULL) {abort();}; }; +static PyObject *PkgDepCacheProgressCallback(PyObject *Self, PyObject *Args) +{ + PyObject *pyCallbackObj; + PyObject *pyCallbackArgs; + + PkgDepCacheStruct &Struct = GetCpp<PkgDepCacheStruct>(Self); + if (!PyArg_ParseTuple(Args, "OO", &pyCallbackObj, &pyCallbackArgs)) + return NULL; + // make sure second argument is a function + if (!PyCallable_Check(pyCallbackObj)) { + PyErr_SetString(PyExc_TypeError, "Need a callable object!"); + return 0; + } + + // save the compare func. + Struct.progress.py_update_callback_func = pyCallbackObj; + Struct.progress.py_update_callback_args = pyCallbackArgs; + + Py_INCREF(Py_None); + return Py_None; +} + static PyObject *PkgDepCacheInit(PyObject *Self,PyObject *Args) { PkgDepCacheStruct &Struct = GetCpp<PkgDepCacheStruct>(Self); - // FIXME: argument should be OpProgress -#if 0 - PyObject *PkgFObj; - long int Index; - if (PyArg_ParseTuple(Args,"(O!l)",&PackageFileType,&PkgFObj,&Index) == 0) - return 0; -#endif - - Struct.depcache.Init(0); + OpProgress *progress = &Struct.progress; + Struct.depcache.Init(progress); return HandleErrors(Py_None); } @@ -70,6 +119,7 @@ static PyMethodDef PkgDepCacheMethods[] = { {"Init",PkgDepCacheInit,METH_VARARGS,"Init the depcache"}, {"GetCandidateVer",PkgDepCacheGetCandidateVer,METH_VARARGS,"Get candidate version"}, + {"SetProgressCallback",PkgDepCacheProgressCallback,METH_VARARGS,"Set a progress callback, first argument is the function, second a optional data argument that will be passed to the function"}, {} }; @@ -118,10 +168,10 @@ PyTypeObject PkgDepCacheType = PyObject_HEAD_INIT(&PyType_Type) 0, // ob_size "pkgDepCache", // tp_name - sizeof(CppOwnedPyObject<pkgDepCache *>), // tp_basicsize + sizeof(CppOwnedPyObject<PkgDepCacheStruct>), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc<pkgDepCache *>, // tp_dealloc + CppOwnedDealloc<PkgDepCacheStruct>, // tp_dealloc 0, // tp_print DepCacheAttr, // tp_getattr 0, // tp_setattr @@ -146,4 +196,6 @@ PyObject *GetDepCache(PyObject *Self,PyObject *Args) } + + /*}}}*/ diff --git a/python/makefile b/python/makefile index 0817c806..f6f77993 100644 --- a/python/makefile +++ b/python/makefile @@ -10,7 +10,8 @@ MODULE=apt_pkg 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 + cache.cc pkgrecords.cc pkgsrcrecords.cc sourcelist.cc \ + depcache.cc SOURCE := $(APT_PKG_SRC) include $(PYTHON_H) |
