diff options
| author | Michael Vogt <michael.vogt@ubuntu.com> | 2005-07-01 22:23:46 +0000 |
|---|---|---|
| committer | Michael Vogt <michael.vogt@ubuntu.com> | 2005-07-01 22:23:46 +0000 |
| commit | a1c38f628ef497e196cfebb9677dbf687dc13f1c (patch) | |
| tree | bc2b14fcc2da0cbc8d7afa644989dfc792278f88 /python | |
| parent | 2f8f815efac944fdaf1f0670f8322a229bf993ee (diff) | |
| download | python-apt-a1c38f628ef497e196cfebb9677dbf687dc13f1c.tar.gz | |
* added Cache.Open(),Close(); fixed some refcout problems
Diffstat (limited to 'python')
| -rw-r--r-- | python/cache.cc | 58 |
1 files changed, 53 insertions, 5 deletions
diff --git a/python/cache.cc b/python/cache.cc index cf5e963b..a8e4bfd9 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -88,18 +88,21 @@ static PyObject *PkgCacheUpdate(PyObject *Self,PyObject *Args) } pkgSourceList List; - if(!List.ReadMainList()) + if(!List.ReadMainList()) { + Py_INCREF(Py_None); return HandleErrors(Py_None); - + } + PyFetchProgress progress; progress.setCallbackInst(pyFetchProgressInst); pkgAcquire Fetcher(&progress); if (!List.GetIndexes(&Fetcher)) return HandleErrors(); - if (Fetcher.Run() == pkgAcquire::Failed) + if (Fetcher.Run() == pkgAcquire::Failed) { + Py_INCREF(Py_None); return HandleErrors(Py_None); - + } if(pyOpProgressInst != 0) { @@ -109,18 +112,63 @@ static PyObject *PkgCacheUpdate(PyObject *Self,PyObject *Args) return HandleErrors(); } else { OpTextProgress Prog; - if (Cache->Open(Prog,false) == false) + if (Cache->Open(Prog,false) == false) { + Py_INCREF(Py_None); return HandleErrors(Py_None); + } } + + Py_INCREF(Py_None); return HandleErrors(Py_None); } +static PyObject *PkgCacheClose(PyObject *Self,PyObject *Args) +{ + PyObject *CacheFilePy = GetOwner<pkgCache*>(Self); + pkgCacheFile *Cache = GetCpp<pkgCacheFile*>(CacheFilePy); + Cache->Close(); + + Py_INCREF(Py_None); + return HandleErrors(Py_None); +} + +static PyObject *PkgCacheOpen(PyObject *Self,PyObject *Args) +{ + PyObject *CacheFilePy = GetOwner<pkgCache*>(Self); + pkgCacheFile *Cache = GetCpp<pkgCacheFile*>(CacheFilePy); + + PyObject *pyCallbackInst = 0; + if (PyArg_ParseTuple(Args, "|O", &pyCallbackInst) == 0) + return 0; + + if(pyCallbackInst != 0) { + PyOpProgress progress; + progress.setCallbackInst(pyCallbackInst); + if (Cache->Open(progress,false) == false) + return HandleErrors(); + } else { + OpTextProgress Prog; + if (Cache->Open(Prog,false) == false) + return HandleErrors(); + } + + //std::cout << "new cache is " << (pkgCache*)(*Cache) << std::endl; + + // update the cache pointer after the cache was rebuild + ((CppPyObject<pkgCache*> *)Self)->Object = (pkgCache*)(*Cache); + + + Py_INCREF(Py_None); + return HandleErrors(Py_None); +} static PyMethodDef PkgCacheMethods[] = { {"Update",PkgCacheUpdate,METH_VARARGS,"Update the cache"}, + {"Open", PkgCacheOpen, METH_VARARGS,"Open the cache"}, + {"Close", PkgCacheClose, METH_VARARGS,"Close the cache"}, {} }; |
