summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2005-02-23 20:45:52 +0000
committerMichael Vogt <michael.vogt@ubuntu.com>2005-02-23 20:45:52 +0000
commit157fcc2665301c168dabc02eec9105db3d860b53 (patch)
tree633b56e9ec59b4ff273d8148e7fad1210a64ad03 /python
parent8bd15f69297702d22bd4dc958f2a0eb221b8e6f9 (diff)
downloadpython-apt-157fcc2665301c168dabc02eec9105db3d860b53.tar.gz
* apt_pkg.GetCache() supports a progress callback now too
Diffstat (limited to 'python')
-rw-r--r--python/cache.cc25
-rw-r--r--python/depcache.cc83
-rw-r--r--python/makefile2
-rw-r--r--python/progress.h29
4 files changed, 69 insertions, 70 deletions
diff --git a/python/cache.cc b/python/cache.cc
index 954aed92..ceffba20 100644
--- a/python/cache.cc
+++ b/python/cache.cc
@@ -16,6 +16,8 @@
#include <apt-pkg/sptr.h>
#include <Python.h>
+#include "progress.h"
+
/*}}}*/
struct PkgListStruct
@@ -740,14 +742,25 @@ PyTypeObject RDepListType =
PyObject *TmpGetCache(PyObject *Self,PyObject *Args)
{
- if (PyArg_ParseTuple(Args,"") == 0)
+ pkgCacheFile *Cache = new pkgCacheFile();
+
+ PyObject *pyCallbackObj = 0;
+ PyObject *pyCallbackArgs = 0;
+ if (PyArg_ParseTuple(Args, "|OO", &pyCallbackObj, &pyCallbackArgs) == 0)
return 0;
- pkgCacheFile *Cache = new pkgCacheFile();
- OpTextProgress Prog;
- if (Cache->Open(Prog,false) == false)
- return HandleErrors();
-
+ if(pyCallbackObj != 0) {
+ PyOpProgressStruct progress;
+ progress.py_update_callback_func = pyCallbackObj;
+ progress.py_update_callback_args = pyCallbackArgs;
+ if (Cache->Open(progress,false) == false)
+ return HandleErrors();
+ } else {
+ OpTextProgress Prog;
+ if (Cache->Open(Prog,false) == false)
+ return HandleErrors();
+ }
+
CppOwnedPyObject<pkgCacheFile> *CacheFileObj =
CppOwnedPyObject_NEW<pkgCacheFile>(0,&PkgCacheFileType, *Cache);
diff --git a/python/depcache.cc b/python/depcache.cc
index eea76999..50611713 100644
--- a/python/depcache.cc
+++ b/python/depcache.cc
@@ -17,36 +17,12 @@
#include <apt-pkg/sptr.h>
#include <Python.h>
-
+#include "progress.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) {};
-};
@@ -68,27 +44,7 @@ struct PkgDepCacheStruct
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)
{
@@ -119,7 +75,6 @@ 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"},
{}
};
@@ -143,20 +98,6 @@ static PyObject *DepCacheAttr(PyObject *Self,char *Name)
return Py_BuildValue("i", Struct.depcache.DebSize());
-#if 0
- if (strcmp("FileList",Name) == 0)
- {
- PyObject *List = PyList_New(0);
- for (pkgCache::PkgFileIterator I = Cache->FileBegin(); I.end() == false; I++)
- {
- PyObject *Obj;
- Obj = CppOwnedPyObject_NEW<pkgCache::PkgFileIterator>(Self,&PackageFileType,I);
- PyList_Append(List,Obj);
- Py_DECREF(Obj);
- }
- return List;
- }
-#endif
return Py_FindMethod(PkgDepCacheMethods,Self,Name);
}
@@ -187,12 +128,28 @@ PyTypeObject PkgDepCacheType =
PyObject *GetDepCache(PyObject *Self,PyObject *Args)
{
PyObject *Owner;
- if (PyArg_ParseTuple(Args,"O!",&PkgCacheType,&Owner) == 0)
+ PyObject *pyCallbackObj = 0;
+ PyObject *pyCallbackArgs = 0;
+ if (PyArg_ParseTuple(Args,"O!|OO",&PkgCacheType,&Owner,
+ &pyCallbackObj, &pyCallbackArgs) == 0)
return 0;
- return HandleErrors(CppOwnedPyObject_NEW<PkgDepCacheStruct>(Owner,
+ PyObject *DepCachePyObj = CppOwnedPyObject_NEW<PkgDepCacheStruct>(Owner,
&PkgDepCacheType,
- GetCpp<pkgCache *>(Owner)));
+ GetCpp<pkgCache *>(Owner));
+ HandleErrors(DepCachePyObj);
+ PkgDepCacheStruct &Struct = GetCpp<PkgDepCacheStruct>(DepCachePyObj);
+ if(pyCallbackObj != 0) {
+ PyOpProgressStruct progress;
+
+ progress.py_update_callback_func = pyCallbackObj;
+ progress.py_update_callback_args = pyCallbackArgs;
+ Struct.depcache.Init(&progress);
+ } else {
+ Struct.depcache.Init(0);
+ }
+
+ return DepCachePyObj;
}
diff --git a/python/makefile b/python/makefile
index f6f77993..481d51ea 100644
--- a/python/makefile
+++ b/python/makefile
@@ -13,7 +13,7 @@ APT_PKG_SRC = apt_pkgmodule.cc configuration.cc generic.cc tag.cc string.cc \
cache.cc pkgrecords.cc pkgsrcrecords.cc sourcelist.cc \
depcache.cc
SOURCE := $(APT_PKG_SRC)
-include $(PYTHON_H)
+include $(PYTHON_H) progress.h
# The apt_int module..
MODULE=apt_inst
diff --git a/python/progress.h b/python/progress.h
new file mode 100644
index 00000000..d653b42d
--- /dev/null
+++ b/python/progress.h
@@ -0,0 +1,29 @@
+#ifndef PROGRESS_H
+#define PROGRESS_H
+
+struct PyOpProgressStruct : public OpProgress
+{
+
+ PyObject *py_update_callback_func;
+ PyObject *py_update_callback_args;
+
+ virtual void Update() {
+ if(py_update_callback_func == 0)
+ 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) {};
+};
+
+#endif