From e85acde9ac66221e7dae0ead2bb9d79140a1826b Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 14 Mar 2005 15:39:53 +0000 Subject: * basic fetch interface, mostly stubs right now --- python/cache.cc | 61 +++++++++++++++++++++++++++++++++++++++--- python/progress.cc | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ python/progress.h | 27 +++++++++++++++++++ 3 files changed, 162 insertions(+), 4 deletions(-) (limited to 'python') diff --git a/python/cache.cc b/python/cache.cc index 7ba53fd9..aff5854a 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -14,6 +14,9 @@ #include #include #include +#include +#include +#include #include #include "progress.h" @@ -66,6 +69,57 @@ static PyObject *CreateProvides(PyObject *Owner,pkgCache::PrvIterator I) // Cache Class /*{{{*/ // --------------------------------------------------------------------- +static PyObject *PkgCacheUpdate(PyObject *Self,PyObject *Args) +{ + pkgCacheFile *Cache = GetCpp(Self); + + PyObject *pyOpProgressInst = 0; + PyObject *pyFetchProgressInst = 0; + if (PyArg_ParseTuple(Args, "O|O", &pyFetchProgressInst,&pyOpProgressInst) == 0) + return 0; + + FileFd Lock; + if (_config->FindB("Debug::NoLocking", false) == false) { + Lock.Fd(GetLock(_config->FindDir("Dir::State::Lists") + "lock")); + if (_error->PendingError() == true) + return HandleErrors(); + } + + pkgSourceList List; + if(!List.ReadMainList()) + return HandleErrors(Py_None); + + PyFetchProgress progress; + progress.setCallbackInst(pyFetchProgressInst); + + pkgAcquire Fetcher(&progress); + if (!List.GetIndexes(&Fetcher)) + return HandleErrors(); + if (Fetcher.Run() == pkgAcquire::Failed) + return HandleErrors(Py_None); + + + + if(pyOpProgressInst != 0) { + PyOpProgress progress; + progress.setCallbackInst(pyOpProgressInst); + if (Cache->Open(progress,false) == false) + return HandleErrors(); + } else { + OpTextProgress Prog; + if (Cache->Open(Prog,false) == false) + return HandleErrors(Py_None); + } + + return HandleErrors(Py_None); +} + + +static PyMethodDef PkgCacheMethods[] = +{ + {"Update",PkgCacheUpdate,METH_VARARGS,"Update the cache"}, +}; + static PyObject *CacheAttr(PyObject *Self,char *Name) { pkgCache *Cache = GetCpp(Self); @@ -96,9 +150,8 @@ static PyObject *CacheAttr(PyObject *Self,char *Name) } return List; } - - PyErr_SetString(PyExc_AttributeError,Name); - return 0; + + return Py_FindMethod(PkgCacheMethods,Self,Name); } // Map access, operator [] @@ -766,6 +819,6 @@ PyObject *TmpGetCache(PyObject *Self,PyObject *Args) CppOwnedPyObject_NEW(CacheFileObj,&PkgCacheType, (pkgCache *)(*Cache)); - Py_DECREF(CacheFileObj); + //Py_DECREF(CacheFileObj); return CacheObj; } diff --git a/python/progress.cc b/python/progress.cc index d414ca15..75c531fe 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -6,9 +6,12 @@ ##################################################################### */ +#include #include "progress.h" +// OpProgress interface +// FIXME: add "string Op, string SubOp" as attribute to the callbackInst void PyOpProgress::Update() { if(callbackInst == 0) @@ -33,6 +36,7 @@ void PyOpProgress::Update() return; }; + void PyOpProgress::Done() { if(callbackInst == 0) @@ -53,3 +57,77 @@ void PyOpProgress::Done() Py_XDECREF(method); Py_DECREF(arglist); } + + + +// fetcher interface +// PyFetchProgress:: + +// apt interface +bool PyFetchProgress::MediaChange(string Media, string Drive) +{ + std::cout << "MediaChange" << std::endl; +} + +void PyFetchProgress::IMSHit(pkgAcquire::ItemDesc &Itm) +{ + std::cout << "IMSHit" << std::endl; +} + +void PyFetchProgress::Fetch(pkgAcquire::ItemDesc &Itm) +{ + std::cout << "Fetch" << std::endl; +} + +void PyFetchProgress::Done(pkgAcquire::ItemDesc &Itm) +{ + std::cout << "Done" << std::endl; +} + +void PyFetchProgress::Fail(pkgAcquire::ItemDesc &Itm) +{ + std::cout << "Fail" << std::endl; +} + +void PyFetchProgress::Start() +{ + std::cout << "Start" << std::endl; + pkgAcquireStatus::Start(); + +} + +void PyFetchProgress::Stop() +{ + std::cout << "Stop" << std::endl; + pkgAcquireStatus::Stop(); +} + +// FIXME: it should just set the attribute for +// CurrentCPS, Current... +bool PyFetchProgress::Pulse(pkgAcquire * Owner) +{ + pkgAcquireStatus::Pulse(Owner); + + //std::cout << "Pulse" << std::endl; + if(callbackInst == 0) + return false; + + // Build up the argument list... + PyObject *arglist = Py_BuildValue("(ffi)", CurrentCPS, CurrentBytes, CurrentItems); + + // ...for calling the Python compare function. + PyObject *method = PyObject_GetAttrString(callbackInst, "Pulse"); + if(method == NULL) { + // FIXME: make this silent + Py_DECREF(arglist); + return false; + } + PyObject *result = PyEval_CallObject(method,arglist); + + Py_XDECREF(result); + Py_XDECREF(method); + Py_DECREF(arglist); + + // this can be canceld by returning false + return true; +} diff --git a/python/progress.h b/python/progress.h index b18778b1..6ea0b16b 100644 --- a/python/progress.h +++ b/python/progress.h @@ -10,6 +10,7 @@ #define PROGRESS_H #include +#include #include struct PyOpProgress : public OpProgress @@ -26,4 +27,30 @@ struct PyOpProgress : public OpProgress PyOpProgress() : OpProgress(), callbackInst(0) {}; }; + +struct PyFetchProgress : public pkgAcquireStatus +{ + PyObject *callbackInst; + + void setCallbackInst(PyObject *o) { + callbackInst = o; + } + + + void updateStatus(pkgAcquire::ItemDesc & Itm, int status); + + // apt interface + virtual bool MediaChange(string Media, string Drive); + virtual void IMSHit(pkgAcquire::ItemDesc &Itm); + virtual void Fetch(pkgAcquire::ItemDesc &Itm); + virtual void Done(pkgAcquire::ItemDesc &Itm); + virtual void Fail(pkgAcquire::ItemDesc &Itm); + virtual void Start(); + virtual void Stop(); + + bool Pulse(pkgAcquire * Owner); +}; + + + #endif -- cgit v1.2.3