From d06566c40340c80db43e47b171ceda579291ef66 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 9 Mar 2005 16:59:16 +0000 Subject: * OpProgress interface added for DepCache --- doc/examples/depcache.py | 16 +++++++++++----- python/depcache.cc | 26 +++++++++++++++++++++----- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/doc/examples/depcache.py b/doc/examples/depcache.py index 5e5699e7..baf2d875 100644 --- a/doc/examples/depcache.py +++ b/doc/examples/depcache.py @@ -11,8 +11,10 @@ class MyProgress: def Update(self, percent): if (self.last + 1.0) <= percent: - print "lala %s " % (percent) + print "Progress: %s " % (percent) self.last = percent + if percent >= 100: + self.last = 0.0 def Done(self): self.last = 0.0 @@ -25,18 +27,22 @@ progress = MyProgress() cache = apt_pkg.GetCache(progress) print "Available packages: %s " % cache.PackageCount -sys.exit() - iter = cache["base-config"] print "example package iter: %s" % iter - # get depcache -depcache = apt_pkg.GetDepCache(cache) +print "\n\n depcache" +depcache = apt_pkg.GetDepCache(cache, progress) depcache.ReadPinFile() print "got a depcache: %s " % depcache print "Marked for install: %s " % depcache.InstCount +print "\n\n Reinit" +depcache.Init(progress) + +#sys.exit() + + # get a canidate version ver= depcache.GetCandidateVer(iter) print "Candidate version: %s " % ver diff --git a/python/depcache.cc b/python/depcache.cc index ac779063..4bd1f390 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -20,7 +20,7 @@ #include #include - +#include "progress.h" // DepCache Class /*{{{*/ // --------------------------------------------------------------------- @@ -49,7 +49,17 @@ static PyObject *PkgDepCacheInit(PyObject *Self,PyObject *Args) { PkgDepCacheStruct &Struct = GetCpp(Self); - Struct.depcache->Init(0); + PyObject *pyCallbackInst = 0; + if (PyArg_ParseTuple(Args, "|O", &pyCallbackInst) == 0) + return 0; + + if(pyCallbackInst != 0) { + PyOpProgress progress; + progress.setCallbackInst(pyCallbackInst); + Struct.depcache->Init(&progress); + } else { + Struct.depcache->Init(0); + } return HandleErrors(Py_None); } @@ -330,7 +340,8 @@ PyTypeObject PkgDepCacheType = PyObject *GetDepCache(PyObject *Self,PyObject *Args) { PyObject *Owner; - if (PyArg_ParseTuple(Args,"O!",&PkgCacheType,&Owner) == 0) + PyObject *pyCallbackInst = 0; + if (PyArg_ParseTuple(Args,"O!|O",&PkgCacheType,&Owner,&pyCallbackInst) == 0) return 0; PyObject *DepCachePyObj; @@ -340,8 +351,13 @@ PyObject *GetDepCache(PyObject *Self,PyObject *Args) HandleErrors(DepCachePyObj); PkgDepCacheStruct &Struct = GetCpp(DepCachePyObj); - // init without progress obj - Struct.depcache->Init(0); + if(pyCallbackInst != 0) { + PyOpProgress progress; + progress.setCallbackInst(pyCallbackInst); + Struct.depcache->Init(&progress); + } else { + Struct.depcache->Init(0); + } return DepCachePyObj; } -- cgit v1.2.3