diff options
| -rw-r--r-- | debian/changelog | 25 | ||||
| -rw-r--r-- | debian/control | 16 | ||||
| -rw-r--r-- | debian/python-dep | 6 | ||||
| -rwxr-xr-x | debian/rules | 16 | ||||
| -rw-r--r-- | doc/examples/depcache.py | 102 | ||||
| -rw-r--r-- | python/apt_pkgmodule.h | 4 | ||||
| -rw-r--r-- | python/depcache.cc | 256 | ||||
| -rw-r--r-- | python/tar.cc | 2 |
8 files changed, 345 insertions, 82 deletions
diff --git a/debian/changelog b/debian/changelog index e8dbbb37..69831041 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,8 +1,29 @@ +python-apt (0.5.36) hoary; urgency=low + + * Fix build-depends, somehow lost in merge + + -- Matt Zimmerman <mdz@ubuntu.com> Sat, 26 Feb 2005 18:53:54 -0800 + +python-apt (0.5.35) hoary; urgency=low + + * Target hoary this time + + -- Matt Zimmerman <mdz@ubuntu.com> Sat, 26 Feb 2005 15:57:21 -0800 + +python-apt (0.5.34) unstable; urgency=low + + * Restore Ubuntu changes + - Build python 2.4 as default, add python2.3-apt + - Typo fix (Ubuntu #4677) + + -- Matt Zimmerman <mdz@ubuntu.com> Sat, 26 Feb 2005 15:53:30 -0800 + python-apt (0.5.33) unstable; urgency=low - * added basic support for the depcache (python/depcache.cc) + * Merge michael.vogt@ubuntu.com--2005/python-apt--pkgDepCache--0 + - Basic depcache API (Ubuntu #6889) - -- Michael Vogt <michael.vogt@ubuntu.com> Wed, 23 Feb 2005 12:02:44 +0100 + -- Matt Zimmerman <mdz@ubuntu.com> Sat, 26 Feb 2005 15:37:48 -0800 python-apt (0.5.32) unstable; urgency=low diff --git a/debian/control b/debian/control index 0cc070e7..1d3e1314 100644 --- a/debian/control +++ b/debian/control @@ -4,7 +4,7 @@ Priority: optional Maintainer: APT Development Team <deity@lists.debian.org> Uploaders: Matt Zimmerman <mdz@debian.org> Standards-Version: 3.1.1 -Build-Depends: debhelper, libapt-pkg-dev (>= 0.5.32), apt-utils, python-dev (>= 2.4) +Build-Depends: debhelper (>= 4.2.28), libapt-pkg-dev (>= 0.5.32), apt-utils, python, python-dev (>= 2.4), python2.3-dev Package: python-apt Architecture: any @@ -19,3 +19,17 @@ Description: Python interface to libapt-pkg - Access to the APT package information database - Parsing of Debian package control files, and other files with a similar structure + +Package: python2.3-apt +Architecture: any +Depends: ${python:Depends}, ${shlibs:Depends} +Priority: optional +Description: Python interface to libapt-pkg + The apt-pkg Python interface will provide full access to the internal + libapt-pkg structures allowing Python programs to easily perform a + variety of functions, such as: + . + - Access to the APT configuration system + - Access to the APT package information database + - Parsing of Debian package control files, and other files with a + similar structure diff --git a/debian/python-dep b/debian/python-dep deleted file mode 100644 index bc688ef8..00000000 --- a/debian/python-dep +++ /dev/null @@ -1,6 +0,0 @@ -import sys; - -if sys.version[:3] != "1.5": - print "python:Depends=python (>= %s), python (<< %s)" % (sys.version[:3],float(sys.version[:3])+0.1) -else: - print "python:Depends=python-base (>= 1.5) | python1.5" diff --git a/debian/rules b/debian/rules index 2716f760..8180834a 100755 --- a/debian/rules +++ b/debian/rules @@ -8,6 +8,9 @@ PYTHON=/usr/bin/python2.4 +DEBVER=$(shell dpkg-parsechangelog |sed -n -e '/^Version:/s/^Version: //p') +DEB_BUILD_PROG:=debuild --preserve-envvar PATH --preserve-envvar CCACHE_DIR -us -uc $(DEB_BUILD_PROG_OPTS) + build: build-stamp build-stamp: dh_testdir @@ -19,9 +22,10 @@ build-stamp: clean: dh_testdir dh_testroot - rm -f build-stamp + rm -rf build-stamp debian/arch-build $(PYTHON) setup.py clean --all + /usr/bin/python2.3 setup.py clean --all dh_clean @@ -37,6 +41,7 @@ binary-arch: build dh_clean -k $(PYTHON) setup.py install --prefix=`pwd`/debian/tmp/usr + /usr/bin/python2.3 setup.py install --prefix=`pwd`/debian/python2.3-apt/usr dh_installdocs # Hooks for doc-base. doc-base doesn't support `pdf' yet, @@ -55,7 +60,7 @@ binary-arch: build dh_fixperms dh_installdeb dh_shlibdeps - $(PYTHON) debian/python-dep >> debian/substvars + dh_python dh_gencontrol # dh_makeshlibs dh_md5sums @@ -64,5 +69,12 @@ binary-arch: build source diff: @echo >&2 'source and diff are obsolete - use dpkg-source -b'; false +arch-build: + rm -rf debian/arch-build + mkdir -p debian/arch-build/python-apt-$(DEBVER) + baz inventory -s | xargs cp -a --parents --target=debian/arch-build/python-apt-$(DEBVER) + (cd debian/arch-build/python-apt-$(DEBVER); $(DEB_BUILD_PROG)) + + binary: binary-indep binary-arch .PHONY: build clean binary-indep binary-arch binary diff --git a/doc/examples/depcache.py b/doc/examples/depcache.py index 7c8a33ea..92416b3e 100644 --- a/doc/examples/depcache.py +++ b/doc/examples/depcache.py @@ -3,35 +3,85 @@ import apt_pkg -class TextProgress: - def __init__(self): - self.last = 1 - def show(self,Percent): - if self.last < Percent: - print "\r%.2f " % Percent, - self.last = Percent+0.1 - if Percent >= 100: - print "\r100.0 " - self.last = 0 - -def Update(Percent, data): - # data is a TextProgress class - progress = data - progress.show(Percent) - - +# init apt_pkg.init() - -progress = TextProgress() -cache = apt_pkg.GetCache(Update, progress) -print cache.PackageCount +cache = apt_pkg.GetCache() +print "Available packages: %s " % cache.PackageCount iter = cache["base-config"] -print iter +print "example package iter: %s" % iter -depcache = apt_pkg.GetDepCache(cache, Update, progress) -print depcache -print depcache.InstCount +# get depcache +depcache = apt_pkg.GetDepCache(cache) +print "got a depcache: %s " % depcache +print "Marked for install: %s " % depcache.InstCount +# get a canidate version ver= depcache.GetCandidateVer(iter) -print ver +print "Candidate version: %s " % ver + +print "\n\nQuerry interface" +print "%s.IsUpgradable(): %s" % (iter.Name, depcache.IsUpgradable(iter)) + +print "\nMarking interface" +print "Marking '%s' for install" % iter.Name +depcache.MarkInstall(iter) +print "Install count: %s " % depcache.InstCount +print "%s.MarkedInstall(): %s" % (iter.Name, depcache.MarkedInstall(iter)) +print "%s.MarkedUpgrade(): %s" % (iter.Name, depcache.MarkedUpgrade(iter)) +print "%s.MarkedDelete(): %s" % (iter.Name, depcache.MarkedDelete(iter)) + +print "Marking %s for delete" % iter.Name +depcache.MarkDelete(iter) +print "DelCount: %s " % depcache.DelCount +print "%s.MarkedDelete(): %s" % (iter.Name, depcache.MarkedDelete(iter)) + + +iter = cache["3dchess"] +print "\nMarking '%s' for install" % iter.Name +depcache.MarkInstall(iter) +print "Install count: %s " % depcache.InstCount +print "%s.MarkedInstall(): %s" % (iter.Name, depcache.MarkedInstall(iter)) +print "%s.MarkedUpgrade(): %s" % (iter.Name, depcache.MarkedUpgrade(iter)) +print "%s.MarkedDelete(): %s" % (iter.Name, depcache.MarkedDelete(iter)) + +print "Marking %s for keep" % iter.Name +depcache.MarkKeep(iter) +print "Install: %s " % depcache.InstCount + +iter = cache["3dwm-server"] +print "\nMarking '%s' for install" % iter.Name +depcache.MarkInstall(iter) +print "Install: %s " % depcache.InstCount +print "Broken count: %s" % depcache.BrokenCount +print "FixBroken() " +depcache.FixBroken() +print "Broken count: %s" % depcache.BrokenCount + +print "\nPerforming Upgrade" +depcache.Upgrade() +print "Keep: %s " % depcache.KeepCount +print "Install: %s " % depcache.InstCount +print "Delete: %s " % depcache.DelCount +print "UsrSize: %s " % apt_pkg.SizeToStr(depcache.UsrSize) +print "DebSize: %s " % apt_pkg.SizeToStr(depcache.DebSize) + +print "\nPerforming DistUpgrade" +depcache.Upgrade(True) +print "Keep: %s " % depcache.KeepCount +print "Install: %s " % depcache.InstCount +print "Delete: %s " % depcache.DelCount +print "UsrSize: %s " % apt_pkg.SizeToStr(depcache.UsrSize) +print "DebSize: %s " % apt_pkg.SizeToStr(depcache.DebSize) + +# overview about what would happen +for pkg in cache.Packages: + if depcache.MarkedInstall(pkg): + if pkg.CurrentVer != None: + print "Marked upgrade: %s " % pkg.Name + else: + print "Marked install: %s" % pkg.Name + elif depcache.MarkedDelete(pkg): + print "Marked delete: %s" % pkg.Name + elif depcache.MarkedKeep(pkg): + print "Marked keep: %s" % pkg.Name diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index 82389590..bc4c5509 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -63,10 +63,6 @@ PyObject *TmpGetCache(PyObject *Self,PyObject *Args); extern PyTypeObject PkgDepCacheType; PyObject *GetDepCache(PyObject *Self,PyObject *Args); -// Progress -bool AddOpProgressToModule(PyObject *Dict); -PyObject *GetOpProgress(PyObject *Self,PyObject *Args); - // PkgRecords Stuff extern PyTypeObject PkgRecordsType; PyObject *GetPkgRecords(PyObject *Self,PyObject *Args); 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; } diff --git a/python/tar.cc b/python/tar.cc index 38844a75..20fb1f5f 100644 --- a/python/tar.cc +++ b/python/tar.cc @@ -161,7 +161,7 @@ PyObject *debExtract(PyObject *Self,PyObject *Args) const ARArchive::Member *Member = Deb.GotoMember(Chunk); if (Member == 0) { - _error->Error("Cannot fund chunk %s",Chunk); + _error->Error("Cannot find chunk %s",Chunk); return HandleErrors(); } |
