diff options
| author | Michael Vogt <michael.vogt@ubuntu.com> | 2005-03-02 10:21:47 +0000 |
|---|---|---|
| committer | Michael Vogt <michael.vogt@ubuntu.com> | 2005-03-02 10:21:47 +0000 |
| commit | c0b6c9e6812970ac952593abf3d6b4d810b06c9d (patch) | |
| tree | 3b5c1ba69dd5b714e29d8eb4fd59fda033758b39 /python/depcache.cc | |
| parent | 5a4c9edb5772d54a68ca043f4b4ebd85a871bd5d (diff) | |
| download | python-apt-c0b6c9e6812970ac952593abf3d6b4d810b06c9d.tar.gz | |
* merged with matts tree, resolved lots of conflicts
Patches applied:
* apt@packages.debian.org/python-apt--main--0--base-0
tag of apt@arch.ubuntu.com/python-apt--MAIN--0--patch-44
* apt@packages.debian.org/python-apt--main--0--patch-1
Merge michael.vogt@ubuntu.com--2005/python-apt--pkgDepCache--0
* apt@packages.debian.org/python-apt--main--0--patch-2
0.5.33
* apt@packages.debian.org/python-apt--main--0--patch-3
Add arch-build target to rules
* apt@packages.debian.org/python-apt--main--0--patch-4
Fix typo (fund->find)
* apt@packages.debian.org/python-apt--main--0--patch-5
Restore Ubuntu changes
* apt@packages.debian.org/python-apt--main--0--patch-6
0.5.35 -> hoary
* apt@packages.debian.org/python-apt--main--0--patch-7
Fix build-depends, somehow lost in merge
* michael.vogt@ubuntu.com--2005/python-apt--pkgDepCache--0--base-0
tag of apt@arch.ubuntu.com/python-apt--MAIN--0--patch-44
* michael.vogt@ubuntu.com--2005/python-apt--pkgDepCache--0--patch-1
* merged from my mvo tree, removed all non-pkgDepCache releated stuff and cleaned up the code
* michael.vogt@ubuntu.com--2005/python-apt--pkgDepCache--0--patch-2
* beefed up the example code, added DepCache.Upgrade()
* michael.vogt@ubuntu.com--2005/python-apt--pkgDepCache--0--patch-3
* implemented the marking interface
* michael.vogt@ubuntu.com--2005/python-apt--pkgDepCache--0--patch-4
* state information and marking interface
* michael.vogt@ubuntu.com--2005/python-apt--pkgDepCache--0--patch-5
* fixed wrong types for "UsrSize" and "DebSize"
* michael.vogt@ubuntu.com--2005/python-apt--pkgDepCache--0--patch-6
* added DepCache.FixBroken()
* michael.vogt@ubuntu.com--2005/python-apt--pkgDepCache--0--patch-7
* example code how a overview about the changes can be computed
Diffstat (limited to 'python/depcache.cc')
| -rw-r--r-- | python/depcache.cc | 256 |
1 files changed, 216 insertions, 40 deletions
diff --git a/python/depcache.cc b/python/depcache.cc index 50611713..81e73efb 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -13,35 +13,34 @@ #include <apt-pkg/pkgcache.h> #include <apt-pkg/cachefile.h> +#include <apt-pkg/algorithms.h> #include <apt-pkg/policy.h> #include <apt-pkg/sptr.h> #include <Python.h> -#include "progress.h" #include <iostream> - - - - - // DepCache Class /*{{{*/ // --------------------------------------------------------------------- struct PkgDepCacheStruct { - pkgDepCache depcache; - PyOpProgressStruct progress; + pkgDepCache *depcache; + pkgPolicy *policy; + + PkgDepCacheStruct(pkgCache *Cache) { + policy = new pkgPolicy(Cache); + depcache = new pkgDepCache(Cache); + } + virtual ~PkgDepCacheStruct() { + delete depcache; + delete policy; + }; - 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();}; + PkgDepCacheStruct() {abort();}; }; @@ -50,8 +49,7 @@ static PyObject *PkgDepCacheInit(PyObject *Self,PyObject *Args) { PkgDepCacheStruct &Struct = GetCpp<PkgDepCacheStruct>(Self); - OpProgress *progress = &Struct.progress; - Struct.depcache.Init(progress); + Struct.depcache->Init(0); return HandleErrors(Py_None); } @@ -65,16 +63,202 @@ static PyObject *PkgDepCacheGetCandidateVer(PyObject *Self,PyObject *Args) return 0; pkgCache::PkgIterator &Pkg = GetCpp<pkgCache::PkgIterator>(PackageObj); - pkgCache::VerIterator I = Struct.depcache.GetCandidateVer(Pkg); + pkgCache::VerIterator I = Struct.depcache->GetCandidateVer(Pkg); CandidateObj = CppOwnedPyObject_NEW<pkgCache::VerIterator>(PackageObj,&VersionType,I); return CandidateObj; } +static PyObject *PkgDepCacheUpgrade(PyObject *Self,PyObject *Args) +{ + PkgDepCacheStruct &Struct = GetCpp<PkgDepCacheStruct>(Self); + + char *distUpgrade=0; + if (PyArg_ParseTuple(Args,"|b",&distUpgrade) == 0) + return 0; + + if(distUpgrade) + pkgDistUpgrade(*Struct.depcache); + else + pkgAllUpgrade(*Struct.depcache); + + return HandleErrors(Py_None); +} + +static PyObject *PkgDepCacheFixBroken(PyObject *Self,PyObject *Args) +{ + PkgDepCacheStruct &Struct = GetCpp<PkgDepCacheStruct>(Self); + + if (PyArg_ParseTuple(Args,"") == 0) + return 0; + + pkgFixBroken(*Struct.depcache); + + return HandleErrors(Py_None); +} + + +static PyObject *PkgDepCacheMarkKeep(PyObject *Self,PyObject *Args) +{ + PkgDepCacheStruct &Struct = GetCpp<PkgDepCacheStruct>(Self); + + PyObject *PackageObj; + if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + return 0; + + pkgCache::PkgIterator &Pkg = GetCpp<pkgCache::PkgIterator>(PackageObj); + Struct.depcache->MarkKeep(Pkg); + + return HandleErrors(Py_None); +} + +static PyObject *PkgDepCacheMarkDelete(PyObject *Self,PyObject *Args) +{ + PkgDepCacheStruct &Struct = GetCpp<PkgDepCacheStruct>(Self); + + PyObject *PackageObj; + char purge = 0; + if (PyArg_ParseTuple(Args,"O!|b",&PackageType,&PackageObj, &purge) == 0) + return 0; + + pkgCache::PkgIterator &Pkg = GetCpp<pkgCache::PkgIterator>(PackageObj); + Struct.depcache->MarkDelete(Pkg,purge); + + return HandleErrors(Py_None); +} + +static PyObject *PkgDepCacheMarkInstall(PyObject *Self,PyObject *Args) +{ + PkgDepCacheStruct &Struct = GetCpp<PkgDepCacheStruct>(Self); + + PyObject *PackageObj; + if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + return 0; + + pkgCache::PkgIterator &Pkg = GetCpp<pkgCache::PkgIterator>(PackageObj); + Struct.depcache->MarkInstall(Pkg); + + return HandleErrors(Py_None); +} + +static PyObject *PkgDepCacheIsUpgradable(PyObject *Self,PyObject *Args) +{ + PkgDepCacheStruct &Struct = GetCpp<PkgDepCacheStruct>(Self); + + PyObject *PackageObj; + if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + return 0; + + pkgCache::PkgIterator &Pkg = GetCpp<pkgCache::PkgIterator>(PackageObj); + pkgDepCache::StateCache &state = (*Struct.depcache)[Pkg]; + + return HandleErrors(Py_BuildValue("b",state.Upgradable())); +} + +static PyObject *PkgDepCacheIsNowBroken(PyObject *Self,PyObject *Args) +{ + PkgDepCacheStruct &Struct = GetCpp<PkgDepCacheStruct>(Self); + + PyObject *PackageObj; + if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + return 0; + + pkgCache::PkgIterator &Pkg = GetCpp<pkgCache::PkgIterator>(PackageObj); + pkgDepCache::StateCache &state = (*Struct.depcache)[Pkg]; + + return HandleErrors(Py_BuildValue("b",state.NowBroken())); +} + +static PyObject *PkgDepCacheIsInstBroken(PyObject *Self,PyObject *Args) +{ + PkgDepCacheStruct &Struct = GetCpp<PkgDepCacheStruct>(Self); + + PyObject *PackageObj; + if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + return 0; + + pkgCache::PkgIterator &Pkg = GetCpp<pkgCache::PkgIterator>(PackageObj); + pkgDepCache::StateCache &state = (*Struct.depcache)[Pkg]; + + return HandleErrors(Py_BuildValue("b",state.InstBroken())); +} + + +static PyObject *PkgDepCacheMarkedInstall(PyObject *Self,PyObject *Args) +{ + PkgDepCacheStruct &Struct = GetCpp<PkgDepCacheStruct>(Self); + + PyObject *PackageObj; + if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + return 0; + + pkgCache::PkgIterator &Pkg = GetCpp<pkgCache::PkgIterator>(PackageObj); + pkgDepCache::StateCache &state = (*Struct.depcache)[Pkg]; + + return HandleErrors(Py_BuildValue("b",state.Install())); +} + +static PyObject *PkgDepCacheMarkedUpgrade(PyObject *Self,PyObject *Args) +{ + PkgDepCacheStruct &Struct = GetCpp<PkgDepCacheStruct>(Self); + + PyObject *PackageObj; + if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + return 0; + + pkgCache::PkgIterator &Pkg = GetCpp<pkgCache::PkgIterator>(PackageObj); + pkgDepCache::StateCache &state = (*Struct.depcache)[Pkg]; + + return HandleErrors(Py_BuildValue("b",state.Upgrade())); +} + +static PyObject *PkgDepCacheMarkedDelete(PyObject *Self,PyObject *Args) +{ + PkgDepCacheStruct &Struct = GetCpp<PkgDepCacheStruct>(Self); + + PyObject *PackageObj; + if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + return 0; + + pkgCache::PkgIterator &Pkg = GetCpp<pkgCache::PkgIterator>(PackageObj); + pkgDepCache::StateCache &state = (*Struct.depcache)[Pkg]; + + return HandleErrors(Py_BuildValue("b",state.Delete())); +} + +static PyObject *PkgDepCacheMarkedKeep(PyObject *Self,PyObject *Args) +{ + PkgDepCacheStruct &Struct = GetCpp<PkgDepCacheStruct>(Self); + + PyObject *PackageObj; + if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + return 0; + + pkgCache::PkgIterator &Pkg = GetCpp<pkgCache::PkgIterator>(PackageObj); + pkgDepCache::StateCache &state = (*Struct.depcache)[Pkg]; + + return HandleErrors(Py_BuildValue("b",state.Keep())); +} + static PyMethodDef PkgDepCacheMethods[] = { - {"Init",PkgDepCacheInit,METH_VARARGS,"Init the depcache"}, + {"Init",PkgDepCacheInit,METH_VARARGS,"Init the depcache (done on construct automatically)"}, {"GetCandidateVer",PkgDepCacheGetCandidateVer,METH_VARARGS,"Get candidate version"}, + // global cache operations + {"Upgrade",PkgDepCacheUpgrade,METH_VARARGS,"Perform Upgrade (optional boolean argument if dist-upgrade should be performed)"}, + {"FixBroken",PkgDepCacheFixBroken,METH_VARARGS,"Fix broken packages"}, + // Manipulators + {"MarkKeep",PkgDepCacheMarkKeep,METH_VARARGS,"Mark package for keep"}, + {"MarkDelete",PkgDepCacheMarkDelete,METH_VARARGS,"Mark package for delete (optional boolean argument if it should be purged)"}, + {"MarkInstall",PkgDepCacheMarkInstall,METH_VARARGS,"Mark package for Install"}, + // state information + {"IsUpgradable",PkgDepCacheIsUpgradable,METH_VARARGS,"Is pkg upgradable"}, + {"IsNowBroken",PkgDepCacheIsNowBroken,METH_VARARGS,"Is pkg is now broken"}, + {"IsInstBroken",PkgDepCacheIsInstBroken,METH_VARARGS,"Is pkg broken on the current install"}, + {"MarkedInstall",PkgDepCacheMarkedInstall,METH_VARARGS,"Is pkg marked for install"}, + {"MarkedUpgrade",PkgDepCacheMarkedUpgrade,METH_VARARGS,"Is pkg marked for upgrade"}, + {"MarkedDelete",PkgDepCacheMarkedDelete,METH_VARARGS,"Is pkg marked for delete"}, + {"MarkedKeep",PkgDepCacheMarkedDelete,METH_VARARGS,"Is pkg marked for keep"}, {} }; @@ -85,17 +269,17 @@ static PyObject *DepCacheAttr(PyObject *Self,char *Name) // size querries if(strcmp("KeepCount",Name) == 0) - return Py_BuildValue("i", Struct.depcache.KeepCount()); + return Py_BuildValue("l", Struct.depcache->KeepCount()); else if(strcmp("InstCount",Name) == 0) - return Py_BuildValue("i", Struct.depcache.InstCount()); + return Py_BuildValue("l", Struct.depcache->InstCount()); else if(strcmp("DelCount",Name) == 0) - return Py_BuildValue("i", Struct.depcache.DelCount()); + return Py_BuildValue("l", Struct.depcache->DelCount()); else if(strcmp("BrokenCount",Name) == 0) - return Py_BuildValue("i", Struct.depcache.BrokenCount()); + return Py_BuildValue("l", Struct.depcache->BrokenCount()); else if(strcmp("UsrSize",Name) == 0) - return Py_BuildValue("i", Struct.depcache.UsrSize()); + return Py_BuildValue("d", Struct.depcache->UsrSize()); else if(strcmp("DebSize",Name) == 0) - return Py_BuildValue("i", Struct.depcache.DebSize()); + return Py_BuildValue("d", Struct.depcache->DebSize()); return Py_FindMethod(PkgDepCacheMethods,Self,Name); @@ -128,26 +312,18 @@ PyTypeObject PkgDepCacheType = PyObject *GetDepCache(PyObject *Self,PyObject *Args) { PyObject *Owner; - PyObject *pyCallbackObj = 0; - PyObject *pyCallbackArgs = 0; - if (PyArg_ParseTuple(Args,"O!|OO",&PkgCacheType,&Owner, - &pyCallbackObj, &pyCallbackArgs) == 0) + if (PyArg_ParseTuple(Args,"O!",&PkgCacheType,&Owner) == 0) return 0; - PyObject *DepCachePyObj = CppOwnedPyObject_NEW<PkgDepCacheStruct>(Owner, - &PkgDepCacheType, - GetCpp<pkgCache *>(Owner)); + PyObject *DepCachePyObj; + DepCachePyObj = CppOwnedPyObject_NEW<PkgDepCacheStruct>(Owner, + &PkgDepCacheType, + 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); - } + + // init without progress obj + Struct.depcache->Init(0); return DepCachePyObj; } |
