From aeac7fa849373c7a6fddd5daeddc5bfba7e6eba1 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 24 Oct 2005 17:07:22 +0000 Subject: * custom waitChild() added in installProgress --- apt/progress.py | 2 +- python/depcache.cc | 11 +++++------ python/progress.cc | 39 ++++++++++++++++++++++++++++++++------- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/apt/progress.py b/apt/progress.py index 86cd6594..de675587 100644 --- a/apt/progress.py +++ b/apt/progress.py @@ -104,7 +104,7 @@ class TextFetchProgress(FetchProgress): sys.stdout.flush() return True def stop(self): - print "\rDone " + print "\rDone downloading " def mediaChange(self, medium, drive): """ react to media change events """ res = True; diff --git a/python/depcache.cc b/python/depcache.cc index c78d0077..df56da61 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -149,21 +149,20 @@ static PyObject *PkgDepCacheCommit(PyObject *Self,PyObject *Args) _system->UnLock(); pkgPackageManager::OrderResult Res = iprogress.Run(PM); + std::cout << "iprogress.Run() returned: " << (int)Res << std::endl; + //FIXME: return usefull values here if (Res == pkgPackageManager::Failed || _error->PendingError() == true) { - result = Py_BuildValue("b", false); - return result; + return Py_BuildValue("b", false); } if (Res == pkgPackageManager::Completed) { - result = Py_BuildValue("b", true); - return result; + return Py_BuildValue("b", true); } // Reload the fetcher object and loop again for media swapping Fetcher.Shutdown(); if (PM->GetArchives(&Fetcher,&List,&Recs) == false) { - result = Py_BuildValue("b", false); - return result; + return Py_BuildValue("b", false); } _system->Lock(); } diff --git a/python/progress.cc b/python/progress.cc index 12f9c7a8..61343a0b 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -218,7 +218,7 @@ pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) // support custom fork methods if(PyObject_HasAttrString(callbackInst, "fork")) { PyObject *method = PyObject_GetAttrString(callbackInst, "fork"); - //std::cerr << "custom fork found" << std::endl; + std::cerr << "custom fork found" << std::endl; PyObject *arglist = Py_BuildValue("()"); PyObject *result = PyEval_CallObject(method, arglist); Py_DECREF(arglist); @@ -227,11 +227,13 @@ pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) PyErr_Print(); return pkgPackageManager::Failed; } - if(!PyArg_Parse(result, "i", &child_id) ) + if(!PyArg_Parse(result, "i", &child_id) ) { std::cerr << "custom fork() result could not be parsed?"<< std::endl; - //std::cerr << "got: " << child_id << std::endl; + return pkgPackageManager::Failed; + } + std::cerr << "got pid: " << child_id << std::endl; } else { - //std::cerr << "using build-in fork()" << std::endl; + std::cerr << "using build-in fork()" << std::endl; child_id = fork(); } @@ -251,15 +253,38 @@ pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) } else { res = pm->DoInstall(); } + std::cout << "res: " << res << std::endl; _exit(res); } StartUpdate(); - while (waitpid(child_id, &ret, WNOHANG) == 0) - UpdateInterface(); - res = (pkgPackageManager::OrderResult) WEXITSTATUS(ret); + if(PyObject_HasAttrString(callbackInst, "waitChild")) { + PyObject *method = PyObject_GetAttrString(callbackInst, "waitChild"); + std::cerr << "custom waitChild found" << std::endl; + PyObject *arglist = Py_BuildValue("(i)",child_id); + PyObject *result = PyEval_CallObject(method, arglist); + Py_DECREF(arglist); + if (result == NULL) { + std::cerr << "waitChild method invalid" << std::endl; + PyErr_Print(); + return pkgPackageManager::Failed; + } + int child_res; + if(!PyArg_Parse(result, "i", &res) ) { + std::cerr << "custom waitChild() result could not be parsed?"<< std::endl; + return pkgPackageManager::Failed; + } + std::cerr << "got child_res: " << res << std::endl; + } else { + std::cerr << "using build-in waitpid()" << std::endl; + + while (waitpid(child_id, &ret, WNOHANG) == 0) + UpdateInterface(); + + res = (pkgPackageManager::OrderResult) WEXITSTATUS(ret); + } FinishUpdate(); -- cgit v1.2.3 From ec26e26bf3856f8a2548f456905d78aca4c12eec Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 9 Nov 2005 03:48:34 +0000 Subject: * changelog fix --- debian/changelog | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index a31244bb..bf89cc0c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -9,9 +9,9 @@ python-apt (0.6.14) unstable; urgency=low - always run "Restart" before performing a Lookup * export locking via: GetLock(),PkgSystem{Lock,UnLock} * apt/cache.py: - - add __iter__ + - added __iter__ to make "for pkg in apt.Cache:" stuff possible - -- Michael Vogt Tue, 20 Sep 2005 13:24:31 +0200 + -- python-apt (0.6.13) unstable; urgency=low -- cgit v1.2.3 From 25b0cfc0fe92da8a0114bd15aec16e47318b6f48 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 9 Nov 2005 04:28:04 +0000 Subject: * changelog finalized and synced with the debian upload --- debian/changelog | 2 +- debian/control | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index bf89cc0c..de986f32 100644 --- a/debian/changelog +++ b/debian/changelog @@ -11,7 +11,7 @@ python-apt (0.6.14) unstable; urgency=low * apt/cache.py: - added __iter__ to make "for pkg in apt.Cache:" stuff possible - -- + -- Michael Vogt Wed, 9 Nov 2005 04:52:08 +0100 python-apt (0.6.13) unstable; urgency=low diff --git a/debian/control b/debian/control index bfa67c67..8fb8a669 100644 --- a/debian/control +++ b/debian/control @@ -4,7 +4,7 @@ Priority: optional Maintainer: APT Development Team Uploaders: Matt Zimmerman , Michael Vogt Standards-Version: 3.6.1.1 -Build-Depends: debhelper (>= 4.2.28), libapt-pkg-dev (>= 0.6.40), apt-utils, python-dev, python2.4-dev, python2.3-dev +Build-Depends: debhelper (>= 4.2.28), libapt-pkg-dev (>= 0.6.40.1), apt-utils, python-dev, python2.4-dev, python2.3-dev Package: python-apt Architecture: all -- cgit v1.2.3 From 3c3dd501e3105b7623e07b71f1a59b671dafcafd Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 17 Nov 2005 13:03:56 +0000 Subject: * fail if a download fails --- apt/cache.py | 2 +- debian/changelog | 6 ++++++ python/depcache.cc | 20 ++++++++++++++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/apt/cache.py b/apt/cache.py index 973291c0..1fb128a3 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -117,7 +117,7 @@ class Cache(object): def commit(self, fprogress, iprogress): """ Apply the marked changes to the cache """ - self._depcache.Commit(fprogress, iprogress) + return self._depcache.Commit(fprogress, iprogress) # cache changes def cachePostChange(self): diff --git a/debian/changelog b/debian/changelog index de986f32..51041924 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +python-apt (0.6.14.1) unstable; urgency=low + + * fix a invalid return from cache.commit(), fail if a download failed + + -- Michael Vogt Thu, 17 Nov 2005 13:00:14 +0100 + python-apt (0.6.14) unstable; urgency=low * doc/examples/build-deps.py: diff --git a/python/depcache.cc b/python/depcache.cc index df56da61..6d5e9fcd 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -116,17 +116,25 @@ static PyObject *PkgDepCacheCommit(PyObject *Self,PyObject *Args) bool Failed = false; for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++) { + + //std::cout << "looking at: " << (*I)->DestFile + // << " status: " << (*I)->Status << std::endl; + if ((*I)->Status == pkgAcquire::Item::StatDone && (*I)->Complete == true) continue; if ((*I)->Status == pkgAcquire::Item::StatIdle) { + //std::cout << "transient failure" << std::endl; + Transient = true; - // Failed = true; + //Failed = true; continue; } + //std::cout << "something is wrong!" << std::endl; + _error->Warning(_("Failed to fetch %s %s\n"),(*I)->DescURI().c_str(), (*I)->ErrorText.c_str()); Failed = true; @@ -135,6 +143,7 @@ static PyObject *PkgDepCacheCommit(PyObject *Self,PyObject *Args) if (Transient == true && Failed == true) { _error->Error(_("--fix-missing and media swapping is not currently supported")); + Py_INCREF(Py_None); return HandleErrors(Py_None); } @@ -143,13 +152,18 @@ static PyObject *PkgDepCacheCommit(PyObject *Self,PyObject *Args) { //std::cerr << "Unable to correct missing packages." << std::endl; _error->Error("Aborting install."); + Py_INCREF(Py_None); return HandleErrors(Py_None); } + // fail if something else went wrong + //FIXME: make this more flexible, e.g. with a failedDl handler + if(Failed) + return Py_BuildValue("b", false); _system->UnLock(); pkgPackageManager::OrderResult Res = iprogress.Run(PM); - std::cout << "iprogress.Run() returned: " << (int)Res << std::endl; + //std::cout << "iprogress.Run() returned: " << (int)Res << std::endl; //FIXME: return usefull values here if (Res == pkgPackageManager::Failed || _error->PendingError() == true) { @@ -159,6 +173,8 @@ static PyObject *PkgDepCacheCommit(PyObject *Self,PyObject *Args) return Py_BuildValue("b", true); } + //std::cout << "looping again, install unfinished" << std::endl; + // Reload the fetcher object and loop again for media swapping Fetcher.Shutdown(); if (PM->GetArchives(&Fetcher,&List,&Recs) == false) { -- cgit v1.2.3 From bb69f11ba66087db7b5af415e6b465dd01acf38e Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 17 Nov 2005 22:05:50 +0000 Subject: * proper canidateOrigin support --- apt/package.py | 24 +++++++++++++++++++----- debian/changelog | 1 + 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/apt/package.py b/apt/package.py index 9749da52..1d2f6ace 100644 --- a/apt/package.py +++ b/apt/package.py @@ -215,12 +215,26 @@ class Package(object): installedSize = property(installedSize) # canidate origin + class Origin: + def __init__(self,pkg): + ver = pkg._depcache.GetCandidateVer(pkg._pkg) + if not ver: + return None + (VerFileIter,index) = ver.FileList.pop() + #print len(VerFileIter) + #print VerFileIter + #return VerFileIter.Component + self.component = VerFileIter.Component + self.archive = VerFileIter.Archive + self.origin = VerFileIter.Origin + self.label = VerFileIter.Label + self.site = VerFileIter.Site + def __str__(self): + return "%s %s %s %s %s" % (self.component, self.archive, + self.origin, self.label, self.site) + def candidateOrigin(self): - ver = self._depcache.GetCandidateVer(self._pkg) - (VerFileIter,index) = ver.FileList.pop() - print len(VerFileIter) - print VerFileIter - return VerFileIter.Component + return self.Origin(self) candidateOrigin = property(candidateOrigin) # depcache actions diff --git a/debian/changelog b/debian/changelog index 51041924..1eb5022a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,7 @@ python-apt (0.6.14.1) unstable; urgency=low * fix a invalid return from cache.commit(), fail if a download failed + * apt.Package.candidateOrigin returns a class now -- Michael Vogt Thu, 17 Nov 2005 13:00:14 +0100 -- cgit v1.2.3 From 31177397ed5cecec39abb76d4797ef0f3e7eee46 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 17 Nov 2005 22:38:18 +0000 Subject: * make the Origin string a bit nicer --- apt/package.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apt/package.py b/apt/package.py index 1d2f6ace..bf03f515 100644 --- a/apt/package.py +++ b/apt/package.py @@ -230,8 +230,9 @@ class Package(object): self.label = VerFileIter.Label self.site = VerFileIter.Site def __str__(self): - return "%s %s %s %s %s" % (self.component, self.archive, - self.origin, self.label, self.site) + return "component:%s\narchive: %s\norigin: %s\nlabel: %s" \ + "\nsite %s\n"% (self.component, self.archive, + self.origin, self.label, self.site) def candidateOrigin(self): return self.Origin(self) -- cgit v1.2.3 From 4da233eef44c921152daf224a043ab8e2181ef9f Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 17 Nov 2005 23:34:31 +0000 Subject: * fix a bug in the package.markUpgrade() code --- apt/package.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apt/package.py b/apt/package.py index bf03f515..5642496a 100644 --- a/apt/package.py +++ b/apt/package.py @@ -19,8 +19,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA -import apt_pkg, string -import random +import apt_pkg, string, sys, random class Package(object): """ This class represents a package in the cache @@ -271,9 +270,10 @@ class Package(object): def markUpgrade(self): """ mark a package for upgrade """ if self.isUpgradable: - self.MarkInstall() - # FIXME: we may want to throw a exception here - sys.stderr.write("MarkUpgrade() called on a non-upgrable pkg") + self.markInstall() + else: + # FIXME: we may want to throw a exception here + sys.stderr.write("MarkUpgrade() called on a non-upgrable pkg: '%s'\n" %self._pkg.Name) def commit(self, fprogress, iprogress): """ commit the changes, need a FetchProgress and InstallProgress -- cgit v1.2.3 From c187e828e1661d09a8437214b2f90dcc25c05c99 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 18 Nov 2005 01:01:37 +0000 Subject: * basic pkgAcquire + pkgPackageManager support added --- debian/changelog | 3 +- doc/examples/acquire.py | 24 +++++++++++ python/acquire.cc | 106 ++++++++++++++++++++++++++++++++++++++++++++++ python/acquire.h | 6 +++ python/apt_pkgmodule.cc | 6 +++ python/apt_pkgmodule.h | 11 +++++ python/makefile | 2 +- python/pkgmanager.cc | 109 ++++++++++++++++++++++++++++++++++++++++++++++++ python/pkgrecords.cc | 10 +---- python/pkgrecords.h | 10 +++++ python/sourcelist.cc | 7 +--- python/sourcelist.h | 6 +++ 12 files changed, 283 insertions(+), 17 deletions(-) create mode 100644 doc/examples/acquire.py create mode 100644 python/acquire.cc create mode 100644 python/acquire.h create mode 100644 python/pkgmanager.cc create mode 100644 python/pkgrecords.h create mode 100644 python/sourcelist.h diff --git a/debian/changelog b/debian/changelog index 1eb5022a..b0fe307f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,7 +1,8 @@ -python-apt (0.6.14.1) unstable; urgency=low +python-apt (0.6.15) unstable; urgency=low * fix a invalid return from cache.commit(), fail if a download failed * apt.Package.candidateOrigin returns a class now + * added basic pkgAcquire and pkgPackageManager support -- Michael Vogt Thu, 17 Nov 2005 13:00:14 +0100 diff --git a/doc/examples/acquire.py b/doc/examples/acquire.py new file mode 100644 index 00000000..12727232 --- /dev/null +++ b/doc/examples/acquire.py @@ -0,0 +1,24 @@ +import apt_pkg + +apt_pkg.init() + +cache = apt_pkg.GetCache() +depcache = apt_pkg.GetDepCache(cache) + +recs = apt_pkg.GetPkgRecords(cache) +list = apt_pkg.GetPkgSourceList() +list.ReadMainList() + +pkg = cache["3ddesktop"] +depcache.MarkInstall(pkg) + +fetcher = apt_pkg.GetAcquire() +pm = apt_pkg.GetPackageManager(depcache) + +print pm +print fetcher + +pm.GetArchives(fetcher,list,recs) + +fetcher.Run() + diff --git a/python/acquire.cc b/python/acquire.cc new file mode 100644 index 00000000..550deb0e --- /dev/null +++ b/python/acquire.cc @@ -0,0 +1,106 @@ +// Description /*{{{*/ +// $Id: acquire.cc,v 1.1 2003/06/03 03:03:23 mvo Exp $ +/* ###################################################################### + + Acquire - Wrapper for the acquire code + + ##################################################################### */ + +#include "generic.h" +#include "apt_pkgmodule.h" +#include "acquire.h" + +#include + + +static PyObject *PkgAcquireRun(PyObject *Self,PyObject *Args) +{ + PkgAcquireStruct &Struct = GetCpp(Self); + + if (PyArg_ParseTuple(Args, "") == 0) + return 0; + + //FIXME: add pulse interval here + pkgAcquire::RunResult run = Struct.fetcher.Run(); + + return HandleErrors(Py_BuildValue("i",run)); +} + +static PyObject *PkgAcquireShutdown(PyObject *Self,PyObject *Args) +{ + PkgAcquireStruct &Struct = GetCpp(Self); + + if (PyArg_ParseTuple(Args, "") == 0) + return 0; + + Struct.fetcher.Shutdown(); + + Py_INCREF(Py_None); + return HandleErrors(Py_None); +} + +static PyMethodDef PkgAcquireMethods[] = +{ + {"Run",PkgAcquireRun,METH_VARARGS,"Run the fetcher"}, + {} +}; + + +static PyObject *AcquireAttr(PyObject *Self,char *Name) +{ + PkgAcquireStruct &Struct = GetCpp(Self); + + if(strcmp("TotalNeeded",Name) == 0) + return Py_BuildValue("l", Struct.fetcher.TotalNeeded()); + if(strcmp("FetchNeeded",Name) == 0) + return Py_BuildValue("l", Struct.fetcher.FetchNeeded()); + if(strcmp("PartialPresent",Name) == 0) + return Py_BuildValue("l", Struct.fetcher.PartialPresent()); + // some constants + if(strcmp("ResultContinue",Name) == 0) + return Py_BuildValue("i", pkgAcquire::Continue); + if(strcmp("ResultFailed",Name) == 0) + return Py_BuildValue("i", pkgAcquire::Failed); + if(strcmp("ResultCancelled",Name) == 0) + return Py_BuildValue("i", pkgAcquire::Cancelled); + + return Py_FindMethod(PkgAcquireMethods,Self,Name); +} + + + + +PyTypeObject PkgAcquireType = +{ + PyObject_HEAD_INIT(&PyType_Type) + 0, // ob_size + "Acquire", // tp_name + sizeof(CppOwnedPyObject), // tp_basicsize + 0, // tp_itemsize + // Methods + CppOwnedDealloc, // tp_dealloc + 0, // tp_print + AcquireAttr, // tp_getattr + 0, // tp_setattr + 0, // tp_compare + 0, // tp_repr + 0, // tp_as_number + 0, // tp_as_sequence + 0, // tp_as_mapping + 0, // tp_hash +}; + +PyObject *GetAcquire(PyObject *Self,PyObject *Args) +{ + pkgAcquire *fetcher = new pkgAcquire(); + + CppOwnedPyObject *FetcherObj = + CppOwnedPyObject_NEW(0,&PkgAcquireType, *fetcher); + + return FetcherObj; +} + + + + + /*}}}*/ diff --git a/python/acquire.h b/python/acquire.h new file mode 100644 index 00000000..1afcfff3 --- /dev/null +++ b/python/acquire.h @@ -0,0 +1,6 @@ +#include + +struct PkgAcquireStruct +{ + pkgAcquire fetcher; +}; diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index ce337f0f..5731cae4 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -396,6 +396,12 @@ static PyMethodDef methods[] = // Cdrom {"GetCdrom",GetCdrom,METH_VARARGS,"GetCdrom() -> Cdrom"}, + // Acquire + {"GetAcquire",GetAcquire,METH_VARARGS,"GetAcquire() -> Acquire"}, + + // PkgManager + {"GetPackageManager",GetPkgManager,METH_VARARGS,"GetPackageManager() -> PackageManager"}, + {} }; diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index eefa6ca7..93112f89 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -72,11 +72,22 @@ PyObject *GetPkgProblemResolver(PyObject *Self, PyObject *Args); extern PyTypeObject PkgCdromType; PyObject *GetCdrom(PyObject *Self,PyObject *Args); +// acquire +extern PyTypeObject PkgAcquireType; +PyObject *GetAcquire(PyObject *Self,PyObject *Args); + +// packagemanager +extern PyTypeObject PkgManagerType; +PyObject *GetPkgManager(PyObject *Self,PyObject *Args); + // PkgRecords Stuff extern PyTypeObject PkgRecordsType; PyObject *GetPkgRecords(PyObject *Self,PyObject *Args); PyObject *GetPkgSrcRecords(PyObject *Self,PyObject *Args); + +// pkgSourceList +extern PyTypeObject PkgSourceListType; PyObject *GetPkgSourceList(PyObject *Self,PyObject *Args); #endif diff --git a/python/makefile b/python/makefile index 16bfcd88..7fb1d756 100644 --- a/python/makefile +++ b/python/makefile @@ -11,7 +11,7 @@ SLIBS = -lapt-pkg LIB_MAKES = apt-pkg/makefile APT_PKG_SRC = apt_pkgmodule.cc configuration.cc generic.cc tag.cc string.cc \ cache.cc pkgrecords.cc pkgsrcrecords.cc sourcelist.cc \ - depcache.cc progress.cc cdrom.cc + depcache.cc progress.cc cdrom.cc acquire.cc pkgmanager.cc SOURCE := $(APT_PKG_SRC) include $(PYTHON_H) progress.h diff --git a/python/pkgmanager.cc b/python/pkgmanager.cc new file mode 100644 index 00000000..9504fd94 --- /dev/null +++ b/python/pkgmanager.cc @@ -0,0 +1,109 @@ +// Description /*{{{*/ +// $Id: acquire.cc,v 1.1 2003/06/03 03:03:23 mvo Exp $ +/* ###################################################################### + + PkgManager - Wrapper for the pkgPackageManager code + + ##################################################################### */ + +#include "generic.h" +#include "apt_pkgmodule.h" +#include "acquire.h" +#include "sourcelist.h" +#include "pkgrecords.h" + +#include +#include + +#include + + +struct PkgManagerStruct +{ + pkgPackageManager pm; +}; + +static PyObject *PkgManagerGetArchives(PyObject *Self,PyObject *Args) +{ + PkgManagerStruct &Struct = GetCpp(Self); + PyObject *fetcher, *list, *recs; + + if (PyArg_ParseTuple(Args, "O!O!O!", + &PkgAcquireType,&fetcher, + &PkgSourceListType, &list, + &PkgRecordsType, &recs) == 0) + return 0; + + PkgAcquireStruct &s_fetcher = GetCpp(fetcher); + PkgSourceListStruct &s_list = GetCpp(list); + PkgRecordsStruct &s_records = GetCpp(recs); + + bool res = Struct.pm.GetArchives(&s_fetcher.fetcher, + &s_list.List, + &s_records.Records); + + return HandleErrors(Py_None); +} + + +static PyMethodDef PkgManagerMethods[] = +{ + {"GetArchives",PkgManagerGetArchives,METH_VARARGS,"Load the selected archvies into the fetcher"}, + {} +}; + + +static PyObject *PkgManagerAttr(PyObject *Self,char *Name) +{ + PkgManagerStruct &Struct = GetCpp(Self); + + // some constants + if(strcmp("ResultCompleted",Name) == 0) + return Py_BuildValue("i", pkgPackageManager::Completed); + if(strcmp("ResultFailed",Name) == 0) + return Py_BuildValue("i", pkgPackageManager::Failed); + if(strcmp("ResultIncomplete",Name) == 0) + return Py_BuildValue("i", pkgPackageManager::Incomplete); + + return Py_FindMethod(PkgManagerMethods,Self,Name); +} + + +PyTypeObject PkgManagerType = +{ + PyObject_HEAD_INIT(&PyType_Type) + 0, // ob_size + "PackageManager", // tp_name + sizeof(CppOwnedPyObject), // tp_basicsize + 0, // tp_itemsize + // Methods + CppOwnedDealloc, // tp_dealloc + 0, // tp_print + PkgManagerAttr, // tp_getattr + 0, // tp_setattr + 0, // tp_compare + 0, // tp_repr + 0, // tp_as_number + 0, // tp_as_sequence + 0, // tp_as_mapping + 0, // tp_hash +}; + +PyObject *GetPkgManager(PyObject *Self,PyObject *Args) +{ + PyObject *Owner; + if (PyArg_ParseTuple(Args,"O!",&PkgDepCacheType,&Owner) == 0) + return 0; + + pkgPackageManager *pm = _system->CreatePM(GetCpp(Owner)); + + CppOwnedPyObject *PkgManagerObj = + CppOwnedPyObject_NEW(0,&PkgManagerType, *pm); + + return PkgManagerObj; +} + + + + + /*}}}*/ diff --git a/python/pkgrecords.cc b/python/pkgrecords.cc index 7f5aa0e2..a85b570a 100644 --- a/python/pkgrecords.cc +++ b/python/pkgrecords.cc @@ -10,20 +10,12 @@ // Include Files /*{{{*/ #include "generic.h" #include "apt_pkgmodule.h" +#include "pkgrecords.h" -#include #include /*}}}*/ -struct PkgRecordsStruct -{ - pkgRecords Records; - pkgRecords::Parser *Last; - - PkgRecordsStruct(pkgCache *Cache) : Records(*Cache), Last(0) {}; - PkgRecordsStruct() : Records(*(pkgCache *)0) {abort();}; // G++ Bug.. -}; // PkgRecords Class /*{{{*/ // --------------------------------------------------------------------- diff --git a/python/pkgrecords.h b/python/pkgrecords.h new file mode 100644 index 00000000..78787eab --- /dev/null +++ b/python/pkgrecords.h @@ -0,0 +1,10 @@ +#include + +struct PkgRecordsStruct +{ + pkgRecords Records; + pkgRecords::Parser *Last; + + PkgRecordsStruct(pkgCache *Cache) : Records(*Cache), Last(0) {}; + PkgRecordsStruct() : Records(*(pkgCache *)0) {abort();}; // G++ Bug.. +}; diff --git a/python/sourcelist.cc b/python/sourcelist.cc index e2343e1c..06cf58a2 100644 --- a/python/sourcelist.cc +++ b/python/sourcelist.cc @@ -10,16 +10,11 @@ // Include Files /*{{{*/ #include "generic.h" #include "apt_pkgmodule.h" - -#include +#include "sourcelist.h" #include /*}}}*/ -struct PkgSourceListStruct -{ - pkgSourceList List; -}; // PkgsourceList Class /*{{{*/ // --------------------------------------------------------------------- diff --git a/python/sourcelist.h b/python/sourcelist.h new file mode 100644 index 00000000..98684c54 --- /dev/null +++ b/python/sourcelist.h @@ -0,0 +1,6 @@ +#include + +struct PkgSourceListStruct +{ + pkgSourceList List; +}; -- cgit v1.2.3 From a56d4330c45ea9dbb9dd8babb7e8f17ae79a6fdd Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 18 Nov 2005 11:23:10 +0000 Subject: * acquire interface works with progress reporting now --- doc/examples/acquire.py | 10 +++++++++- python/acquire.cc | 16 +++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/doc/examples/acquire.py b/doc/examples/acquire.py index 12727232..98b70ab0 100644 --- a/doc/examples/acquire.py +++ b/doc/examples/acquire.py @@ -1,4 +1,6 @@ +import apt import apt_pkg +import os apt_pkg.init() @@ -9,10 +11,16 @@ recs = apt_pkg.GetPkgRecords(cache) list = apt_pkg.GetPkgSourceList() list.ReadMainList() +os.mkdir("/tmp/pyapt-test") +os.mkdir("/tmp/pyapt-test/partial") +apt_pkg.Config.Set("Dir::Cache::archives","/tmp/pyapt-test") + pkg = cache["3ddesktop"] depcache.MarkInstall(pkg) -fetcher = apt_pkg.GetAcquire() +progress = apt.progress.TextFetchProgress() +fetcher = apt_pkg.GetAcquire(progress) +#fetcher = apt_pkg.GetAcquire() pm = apt_pkg.GetPackageManager(depcache) print pm diff --git a/python/acquire.cc b/python/acquire.cc index 550deb0e..ff01b659 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -9,6 +9,7 @@ #include "generic.h" #include "apt_pkgmodule.h" #include "acquire.h" +#include "progress.h" #include @@ -92,7 +93,20 @@ PyTypeObject PkgAcquireType = PyObject *GetAcquire(PyObject *Self,PyObject *Args) { - pkgAcquire *fetcher = new pkgAcquire(); + pkgAcquire *fetcher; + + PyObject *pyFetchProgressInst = NULL; + if (PyArg_ParseTuple(Args,"|O",&pyFetchProgressInst) == 0) + return 0; + + if (pyFetchProgressInst != NULL) { + // FIXME: memleak? + PyFetchProgress *progress = new PyFetchProgress(); + progress->setCallbackInst(pyFetchProgressInst); + fetcher = new pkgAcquire(progress); + } else { + fetcher = new pkgAcquire(); + } CppOwnedPyObject *FetcherObj = CppOwnedPyObject_NEW(0,&PkgAcquireType, *fetcher); -- cgit v1.2.3 From bf020b8b55739672ce5335850db921277539327e Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 18 Nov 2005 11:54:43 +0000 Subject: * support for the pkgAcquire::ItemIterator added --- doc/examples/acquire.py | 19 +++++++++++-- python/acquire.cc | 75 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 3 deletions(-) diff --git a/doc/examples/acquire.py b/doc/examples/acquire.py index 98b70ab0..f920e5e9 100644 --- a/doc/examples/acquire.py +++ b/doc/examples/acquire.py @@ -11,8 +11,11 @@ recs = apt_pkg.GetPkgRecords(cache) list = apt_pkg.GetPkgSourceList() list.ReadMainList() -os.mkdir("/tmp/pyapt-test") -os.mkdir("/tmp/pyapt-test/partial") +try: + os.mkdir("/tmp/pyapt-test") + os.mkdir("/tmp/pyapt-test/partial") +except OSError: + pass apt_pkg.Config.Set("Dir::Cache::archives","/tmp/pyapt-test") pkg = cache["3ddesktop"] @@ -28,5 +31,15 @@ print fetcher pm.GetArchives(fetcher,list,recs) -fetcher.Run() +for item in fetcher.Items: + print "%s -> %s:\n Status: %s Complete: %s IsTrusted: %s" % (item.DescURI, + item.DestFile, + item.Status, + item.Complete, + item.IsTrusted) + print + + +res = fetcher.Run() +print "fetcher.Run() returned: %s" % res diff --git a/python/acquire.cc b/python/acquire.cc index ff01b659..a65b9592 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -13,6 +13,67 @@ #include +// pkgAcquire::Item +static PyObject *AcquireItemAttr(PyObject *Self,char *Name) +{ + pkgAcquire::ItemIterator &I = GetCpp(Self); + + if (strcmp("ID",Name) == 0) + return Py_BuildValue("i",(*I)->ID); + else if (strcmp("Status",Name) == 0) + return Py_BuildValue("i",(*I)->Status); + else if (strcmp("Complete",Name) == 0) + return Py_BuildValue("i",(*I)->Complete); + else if (strcmp("Local",Name) == 0) + return Py_BuildValue("i",(*I)->Local); + else if (strcmp("IsTrusted",Name) == 0) + return Py_BuildValue("i",(*I)->IsTrusted()); + else if (strcmp("FileSize",Name) == 0) + return Py_BuildValue("i",(*I)->FileSize); + else if (strcmp("ErrorText",Name) == 0) + return Safe_FromString((*I)->ErrorText.c_str()); + else if (strcmp("DestFile",Name) == 0) + return Safe_FromString((*I)->DestFile.c_str()); + else if (strcmp("DescURI",Name) == 0) + return Safe_FromString((*I)->DescURI().c_str()); + + PyErr_SetString(PyExc_AttributeError,Name); + return 0; +} + + +static PyObject *AcquireItemRepr(PyObject *Self) +{ + pkgAcquire::ItemIterator &I = GetCpp(Self); + + char S[300]; + snprintf(S,sizeof(S),"", + (*I)->DestFile.c_str(),(*I)->ID); + return PyString_FromString(S); +} + + +PyTypeObject AcquireItemType = +{ + PyObject_HEAD_INIT(&PyType_Type) + 0, // ob_size + "pkgAcquire::ItemIterator", // tp_name + sizeof(CppOwnedPyObject), // tp_basicsize + 0, // tp_itemsize + // Methods + CppOwnedDealloc, // tp_dealloc + 0, // tp_print + AcquireItemAttr, // tp_getattr + 0, // tp_setattr + 0, // tp_compare + AcquireItemRepr, // tp_repr + 0, // tp_as_number + 0, // tp_as_sequence + 0, // tp_as_mapping + 0, // tp_hash +}; + static PyObject *PkgAcquireRun(PyObject *Self,PyObject *Args) { @@ -57,6 +118,20 @@ static PyObject *AcquireAttr(PyObject *Self,char *Name) return Py_BuildValue("l", Struct.fetcher.FetchNeeded()); if(strcmp("PartialPresent",Name) == 0) return Py_BuildValue("l", Struct.fetcher.PartialPresent()); + if(strcmp("Items",Name) == 0) + { + PyObject *List = PyList_New(0); + for (pkgAcquire::ItemIterator I = Struct.fetcher.ItemsBegin(); + I != Struct.fetcher.ItemsEnd(); I++) + { + PyObject *Obj; + Obj = CppOwnedPyObject_NEW(Self,&AcquireItemType,I); + PyList_Append(List,Obj); + Py_DECREF(Obj); + + } + return List; + } // some constants if(strcmp("ResultContinue",Name) == 0) return Py_BuildValue("i", pkgAcquire::Continue); -- cgit v1.2.3 From 2fa652df49918cbfd8def4868b327bab3b30feb9 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 18 Nov 2005 12:01:37 +0000 Subject: * added stat constants to the acquire-item interface --- doc/examples/acquire.py | 6 +++++- python/acquire.cc | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/doc/examples/acquire.py b/doc/examples/acquire.py index f920e5e9..0031fa18 100644 --- a/doc/examples/acquire.py +++ b/doc/examples/acquire.py @@ -16,7 +16,7 @@ try: os.mkdir("/tmp/pyapt-test/partial") except OSError: pass -apt_pkg.Config.Set("Dir::Cache::archives","/tmp/pyapt-test") +#apt_pkg.Config.Set("Dir::Cache::archives","/tmp/pyapt-test") pkg = cache["3ddesktop"] depcache.MarkInstall(pkg) @@ -37,6 +37,10 @@ for item in fetcher.Items: item.Status, item.Complete, item.IsTrusted) + if item.Status == item.StatError: + print "Some error ocured: '%s'" % item.ErrorText + if item.Complete == False: + print "No error, still nothing downloaded" print diff --git a/python/acquire.cc b/python/acquire.cc index a65b9592..91d75a6b 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -36,6 +36,18 @@ static PyObject *AcquireItemAttr(PyObject *Self,char *Name) return Safe_FromString((*I)->DestFile.c_str()); else if (strcmp("DescURI",Name) == 0) return Safe_FromString((*I)->DescURI().c_str()); + // constants + else if (strcmp("StatIdle",Name) == 0) + return Py_BuildValue("i", pkgAcquire::Item::StatIdle); + else if (strcmp("StatFetching",Name) == 0) + return Py_BuildValue("i", pkgAcquire::Item::StatFetching); + else if (strcmp("StatDone",Name) == 0) + return Py_BuildValue("i", pkgAcquire::Item::StatDone); + else if (strcmp("StatError",Name) == 0) + return Py_BuildValue("i", pkgAcquire::Item::StatError); + else if (strcmp("StatAuthError",Name) == 0) + return Py_BuildValue("i", pkgAcquire::Item::StatAuthError); + PyErr_SetString(PyExc_AttributeError,Name); return 0; -- cgit v1.2.3 From a9d234dfe2ab0358d3e61a53645e4ee1d83e53cb Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 21 Nov 2005 10:33:10 +0000 Subject: * apt_inst.debExtractArchive() added --- apt/progress.py | 2 +- doc/examples/deb_inspect.py | 12 ++++++++++-- python/apt_instmodule.cc | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/apt/progress.py b/apt/progress.py index de675587..6b4a10e3 100644 --- a/apt/progress.py +++ b/apt/progress.py @@ -19,7 +19,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA -import sys +import sys, apt_pkg class OpProgress: """ Abstract class to implement reporting on cache opening diff --git a/doc/examples/deb_inspect.py b/doc/examples/deb_inspect.py index 4173c196..0befd2bb 100755 --- a/doc/examples/deb_inspect.py +++ b/doc/examples/deb_inspect.py @@ -4,6 +4,7 @@ import apt_pkg import apt_inst import sys +import os.path def Callback(What,Name,Link,Mode,UID,GID,Size,MTime,Major,Minor): """ callback for debExtract """ @@ -35,5 +36,12 @@ if __name__ == "__main__": print apt_pkg.ParseDepends(depends) - - + print "extracting archive" + dir = "/tmp/deb" + os.mkdir(dir) + apt_inst.debExtractArchive(open(file),dir) + def visit(arg, dirname, names): + print "%s/" % dirname + for file in names: + print "\t%s" % file + os.path.walk(dir, visit, None) diff --git a/python/apt_instmodule.cc b/python/apt_instmodule.cc index 96bd029b..d672a40a 100644 --- a/python/apt_instmodule.cc +++ b/python/apt_instmodule.cc @@ -66,6 +66,43 @@ static PyObject *debExtractControl(PyObject *Self,PyObject *Args) } /*}}}*/ +// debExtractArchive - Exctract the archive /*{{{*/ +// --------------------------------------------------------------------- +static char *doc_debExtractArchive = +"debExtractArchve(File,rootdir) -> Bool\n" +"Extracts the Archive into the given root dir"; +static PyObject *debExtractArchive(PyObject *Self,PyObject *Args) +{ + char *Rootdir = NULL; + PyObject *File; + if (PyArg_ParseTuple(Args,"O!|s",&PyFile_Type,&File,&Rootdir) == 0) + return 0; + + // Subscope makes sure any clean up errors are properly handled. + bool res = false; + { + if(Rootdir != NULL) + { + chdir(Rootdir); + } + + // Open the file and associate the .deb + FileFd Fd(fileno(PyFile_AsFile(File)),false); + debDebFile Deb(Fd); + if (_error->PendingError() == true) + return HandleErrors(); + + // extracts relative to the current dir + pkgDirStream Extract; + res = Deb.ExtractArchive(Extract); + + if (res == false) + return HandleErrors(); + } + return HandleErrors(Py_BuildValue("b",res)); +} + /*}}}*/ + // initapt_inst - Core Module Initialization /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -73,6 +110,7 @@ static PyMethodDef methods[] = { // Stuff {"debExtractControl",debExtractControl,METH_VARARGS,doc_debExtractControl}, + {"debExtractArchive",debExtractArchive,METH_VARARGS,doc_debExtractArchive}, {"tarExtract",tarExtract,METH_VARARGS,doc_tarExtract}, {"debExtract",debExtract,METH_VARARGS,doc_debExtract}, -- cgit v1.2.3 From c26431eebbd6d9b90bba2498355e1874a15aba60 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Nov 2005 09:04:05 +0000 Subject: * less debug messages --- python/cache.cc | 2 -- python/depcache.cc | 6 +++--- python/progress.cc | 11 ++++++----- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/python/cache.cc b/python/cache.cc index 5c1760d4..5e2d9819 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -637,8 +637,6 @@ static PyObject *PackageFileAttr(PyObject *Self,char *Name) return Py_BuildValue("i",(File->Flags & pkgCache::Flag::NotAutomatic) != 0); else if (strcmp("ID",Name) == 0) return Py_BuildValue("i",File->ID); - /* mtime is really a cookie these days and has no meaning outside the - list handlers */ PyErr_SetString(PyExc_AttributeError,Name); return 0; diff --git a/python/depcache.cc b/python/depcache.cc index 6d5e9fcd..51c25080 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -160,16 +160,16 @@ static PyObject *PkgDepCacheCommit(PyObject *Self,PyObject *Args) //FIXME: make this more flexible, e.g. with a failedDl handler if(Failed) return Py_BuildValue("b", false); - _system->UnLock(); + _system->UnLock(true); pkgPackageManager::OrderResult Res = iprogress.Run(PM); //std::cout << "iprogress.Run() returned: " << (int)Res << std::endl; - //FIXME: return usefull values here if (Res == pkgPackageManager::Failed || _error->PendingError() == true) { - return Py_BuildValue("b", false); + return HandleErrors(Py_BuildValue("b", false)); } if (Res == pkgPackageManager::Completed) { + //std::cout << "iprogress.Run() returned Completed " << std::endl; return Py_BuildValue("b", true); } diff --git a/python/progress.cc b/python/progress.cc index 61343a0b..d0c97839 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -233,7 +233,7 @@ pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) } std::cerr << "got pid: " << child_id << std::endl; } else { - std::cerr << "using build-in fork()" << std::endl; + //std::cerr << "using build-in fork()" << std::endl; child_id = fork(); } @@ -253,7 +253,7 @@ pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) } else { res = pm->DoInstall(); } - std::cout << "res: " << res << std::endl; + //std::cout << "res: " << res << std::endl; _exit(res); } @@ -262,7 +262,7 @@ pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) if(PyObject_HasAttrString(callbackInst, "waitChild")) { PyObject *method = PyObject_GetAttrString(callbackInst, "waitChild"); - std::cerr << "custom waitChild found" << std::endl; + //std::cerr << "custom waitChild found" << std::endl; PyObject *arglist = Py_BuildValue("(i)",child_id); PyObject *result = PyEval_CallObject(method, arglist); Py_DECREF(arglist); @@ -276,14 +276,15 @@ pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) std::cerr << "custom waitChild() result could not be parsed?"<< std::endl; return pkgPackageManager::Failed; } - std::cerr << "got child_res: " << res << std::endl; + //std::cerr << "got child_res: " << res << std::endl; } else { - std::cerr << "using build-in waitpid()" << std::endl; + //std::cerr << "using build-in waitpid()" << std::endl; while (waitpid(child_id, &ret, WNOHANG) == 0) UpdateInterface(); res = (pkgPackageManager::OrderResult) WEXITSTATUS(ret); + //std::cerr << "build-in waitpid() got: " << res << std::endl; } FinishUpdate(); -- cgit v1.2.3 From f398b1a5833fdf50f8c0c541958d5770ea767be8 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Nov 2005 11:21:49 +0000 Subject: * fix in the pkgmanager.cc code (/me needs to be hit with a clue-stick) --- debian/changelog | 2 +- doc/examples/acquire.py | 20 +++++++++++------- python/acquire.cc | 8 +++++-- python/pkgmanager.cc | 56 +++++++++++++++++++++++++++++++++++++------------ 4 files changed, 63 insertions(+), 23 deletions(-) diff --git a/debian/changelog b/debian/changelog index b0fe307f..9ffd5b12 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,7 +2,7 @@ python-apt (0.6.15) unstable; urgency=low * fix a invalid return from cache.commit(), fail if a download failed * apt.Package.candidateOrigin returns a class now - * added basic pkgAcquire and pkgPackageManager support + * added pkgAcquire, pkgPackageManager and a example (acquire.py) -- Michael Vogt Thu, 17 Nov 2005 13:00:14 +0100 diff --git a/doc/examples/acquire.py b/doc/examples/acquire.py index 0031fa18..a5de0029 100644 --- a/doc/examples/acquire.py +++ b/doc/examples/acquire.py @@ -1,9 +1,14 @@ import apt import apt_pkg import os +import sys apt_pkg.init() +#apt_pkg.Config.Set("Debug::pkgDPkgPM","1"); +#apt_pkg.Config.Set("Debug::pkgPackageManager","1"); +#apt_pkg.Config.Set("Debug::pkgDPkgProgressReporting","1"); + cache = apt_pkg.GetCache() depcache = apt_pkg.GetDepCache(cache) @@ -16,7 +21,7 @@ try: os.mkdir("/tmp/pyapt-test/partial") except OSError: pass -#apt_pkg.Config.Set("Dir::Cache::archives","/tmp/pyapt-test") +apt_pkg.Config.Set("Dir::Cache::archives","/tmp/pyapt-test") pkg = cache["3ddesktop"] depcache.MarkInstall(pkg) @@ -32,18 +37,19 @@ print fetcher pm.GetArchives(fetcher,list,recs) for item in fetcher.Items: - print "%s -> %s:\n Status: %s Complete: %s IsTrusted: %s" % (item.DescURI, - item.DestFile, - item.Status, - item.Complete, - item.IsTrusted) + print item if item.Status == item.StatError: print "Some error ocured: '%s'" % item.ErrorText if item.Complete == False: - print "No error, still nothing downloaded" + print "No error, still nothing downloaded (%s)" % item.ErrorText print res = fetcher.Run() print "fetcher.Run() returned: %s" % res +print "now runing pm.DoInstall()" +res = pm.DoInstall(1) +print "pm.DoInstall() returned: %s"% res + + diff --git a/python/acquire.cc b/python/acquire.cc index 91d75a6b..87f2717a 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -60,8 +60,12 @@ static PyObject *AcquireItemRepr(PyObject *Self) char S[300]; snprintf(S,sizeof(S),"", - (*I)->DestFile.c_str(),(*I)->ID); + "Status: %i Complete: %i Local: %i IsTrusted: %i " + "FileSize: %i DestFile:'%s' " + "DescURI: '%s' ID:%i ErrorText: '%s'>", + (*I)->Status, (*I)->Complete, (*I)->Local, (*I)->IsTrusted(), + (*I)->FileSize, (*I)->DestFile.c_str(), (*I)->DescURI().c_str(), + (*I)->ID,(*I)->ErrorText.c_str()); return PyString_FromString(S); } diff --git a/python/pkgmanager.cc b/python/pkgmanager.cc index 9504fd94..b4c64d3e 100644 --- a/python/pkgmanager.cc +++ b/python/pkgmanager.cc @@ -14,18 +14,14 @@ #include #include +#include #include -struct PkgManagerStruct -{ - pkgPackageManager pm; -}; - static PyObject *PkgManagerGetArchives(PyObject *Self,PyObject *Args) { - PkgManagerStruct &Struct = GetCpp(Self); + pkgPackageManager *pm = GetCpp(Self); PyObject *fetcher, *list, *recs; if (PyArg_ParseTuple(Args, "O!O!O!", @@ -38,24 +34,53 @@ static PyObject *PkgManagerGetArchives(PyObject *Self,PyObject *Args) PkgSourceListStruct &s_list = GetCpp(list); PkgRecordsStruct &s_records = GetCpp(recs); - bool res = Struct.pm.GetArchives(&s_fetcher.fetcher, + bool res = pm->GetArchives(&s_fetcher.fetcher, &s_list.List, &s_records.Records); - return HandleErrors(Py_None); + return HandleErrors(Py_BuildValue("b",res)); +} + +static PyObject *PkgManagerDoInstall(PyObject *Self,PyObject *Args) +{ + //PkgManagerStruct &Struct = GetCpp(Self); + pkgPackageManager *pm = GetCpp(Self); + int status_fd = -1; + + if (PyArg_ParseTuple(Args, "|i", &status_fd) == 0) + return 0; + + pkgPackageManager::OrderResult res = pm->DoInstall(status_fd); + + return HandleErrors(Py_BuildValue("i",res)); } +static PyObject *PkgManagerFixMissing(PyObject *Self,PyObject *Args) +{ + //PkgManagerStruct &Struct = GetCpp(Self); + pkgPackageManager *pm = GetCpp(Self); + + if (PyArg_ParseTuple(Args, "") == 0) + return 0; + + bool res = pm->FixMissing(); + + return HandleErrors(Py_BuildValue("b",res)); +} static PyMethodDef PkgManagerMethods[] = { {"GetArchives",PkgManagerGetArchives,METH_VARARGS,"Load the selected archvies into the fetcher"}, + {"DoInstall",PkgManagerDoInstall,METH_VARARGS,"Do the actual install"}, + {"FixMissing",PkgManagerFixMissing,METH_VARARGS,"Fix the install if a pkg couldn't be downloaded"}, {} }; static PyObject *PkgManagerAttr(PyObject *Self,char *Name) { - PkgManagerStruct &Struct = GetCpp(Self); + //PkgManagerStruct &Struct = GetCpp(Self); + pkgPackageManager *pm = GetCpp(Self); // some constants if(strcmp("ResultCompleted",Name) == 0) @@ -74,10 +99,10 @@ PyTypeObject PkgManagerType = PyObject_HEAD_INIT(&PyType_Type) 0, // ob_size "PackageManager", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppOwnedDealloc, // tp_dealloc 0, // tp_print PkgManagerAttr, // tp_getattr 0, // tp_setattr @@ -89,6 +114,9 @@ PyTypeObject PkgManagerType = 0, // tp_hash }; +#include +#include + PyObject *GetPkgManager(PyObject *Self,PyObject *Args) { PyObject *Owner; @@ -97,9 +125,11 @@ PyObject *GetPkgManager(PyObject *Self,PyObject *Args) pkgPackageManager *pm = _system->CreatePM(GetCpp(Owner)); - CppOwnedPyObject *PkgManagerObj = - CppOwnedPyObject_NEW(0,&PkgManagerType, *pm); + CppPyObject *PkgManagerObj = + CppPyObject_NEW(&PkgManagerType,pm); + // FIXME: mem-leak??? + Py_INCREF(PkgManagerObj); return PkgManagerObj; } -- cgit v1.2.3 From c1ee07ec049974cf8a54160b52881404b6347f43 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Nov 2005 11:30:50 +0000 Subject: * another bugfix in the new pkgPackageManager wrapper --- doc/examples/acquire.py | 1 + python/pkgmanager.cc | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/doc/examples/acquire.py b/doc/examples/acquire.py index a5de0029..72d0c74e 100644 --- a/doc/examples/acquire.py +++ b/doc/examples/acquire.py @@ -53,3 +53,4 @@ res = pm.DoInstall(1) print "pm.DoInstall() returned: %s"% res + diff --git a/python/pkgmanager.cc b/python/pkgmanager.cc index b4c64d3e..133db755 100644 --- a/python/pkgmanager.cc +++ b/python/pkgmanager.cc @@ -99,10 +99,10 @@ PyTypeObject PkgManagerType = PyObject_HEAD_INIT(&PyType_Type) 0, // ob_size "PackageManager", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppDealloc, // tp_dealloc 0, // tp_print PkgManagerAttr, // tp_getattr 0, // tp_setattr @@ -128,8 +128,6 @@ PyObject *GetPkgManager(PyObject *Self,PyObject *Args) CppPyObject *PkgManagerObj = CppPyObject_NEW(&PkgManagerType,pm); - // FIXME: mem-leak??? - Py_INCREF(PkgManagerObj); return PkgManagerObj; } -- cgit v1.2.3 From 86fea3ed91794aa9537a3b197dbaac500b82f2d8 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Nov 2005 11:45:03 +0000 Subject: * python/sourcelist.cc cleaned up --- python/pkgmanager.cc | 9 ++++----- python/sourcelist.cc | 18 ++++++++++-------- python/sourcelist.h | 6 ------ 3 files changed, 14 insertions(+), 19 deletions(-) delete mode 100644 python/sourcelist.h diff --git a/python/pkgmanager.cc b/python/pkgmanager.cc index 133db755..ce6d35a8 100644 --- a/python/pkgmanager.cc +++ b/python/pkgmanager.cc @@ -9,11 +9,11 @@ #include "generic.h" #include "apt_pkgmodule.h" #include "acquire.h" -#include "sourcelist.h" #include "pkgrecords.h" #include #include +#include #include #include @@ -31,12 +31,11 @@ static PyObject *PkgManagerGetArchives(PyObject *Self,PyObject *Args) return 0; PkgAcquireStruct &s_fetcher = GetCpp(fetcher); - PkgSourceListStruct &s_list = GetCpp(list); + pkgSourceList *s_list = GetCpp(list); PkgRecordsStruct &s_records = GetCpp(recs); - bool res = pm->GetArchives(&s_fetcher.fetcher, - &s_list.List, - &s_records.Records); + bool res = pm->GetArchives(&s_fetcher.fetcher, s_list, + &s_records.Records); return HandleErrors(Py_BuildValue("b",res)); } diff --git a/python/sourcelist.cc b/python/sourcelist.cc index 06cf58a2..2d65062c 100644 --- a/python/sourcelist.cc +++ b/python/sourcelist.cc @@ -10,7 +10,8 @@ // Include Files /*{{{*/ #include "generic.h" #include "apt_pkgmodule.h" -#include "sourcelist.h" + +#include #include /*}}}*/ @@ -22,17 +23,18 @@ static char *doc_PkgSourceListFindIndex = "xxx"; static PyObject *PkgSourceListFindIndex(PyObject *Self,PyObject *Args) { - PkgSourceListStruct &Struct = GetCpp(Self); + pkgSourceList *list = GetCpp(Self); return Py_BuildValue("i", 1); } static char *doc_PkgSourceListReadMainList = "xxx"; static PyObject *PkgSourceListReadMainList(PyObject *Self,PyObject *Args) { - PkgSourceListStruct &Struct = GetCpp(Self); - Struct.List.ReadMainList(); + // PkgSourceListStruct &Struct = GetCpp(Self); + pkgSourceList *list = GetCpp(Self); + bool res = list->ReadMainList(); - return Py_None; + return HandleErrors(Py_BuildValue("b",res)); } static PyMethodDef PkgSourceListMethods[] = @@ -51,10 +53,10 @@ PyTypeObject PkgSourceListType = PyObject_HEAD_INIT(&PyType_Type) 0, // ob_size "pkgSourceList", // tp_name - sizeof(CppPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppDealloc, // tp_dealloc + CppDealloc, // tp_dealloc 0, // tp_print PkgSourceListAttr, // tp_getattr 0, // tp_setattr @@ -68,6 +70,6 @@ PyTypeObject PkgSourceListType = PyObject *GetPkgSourceList(PyObject *Self,PyObject *Args) { - return CppPyObject_NEW(&PkgSourceListType); + return CppPyObject_NEW(&PkgSourceListType,new pkgSourceList()); } diff --git a/python/sourcelist.h b/python/sourcelist.h deleted file mode 100644 index 98684c54..00000000 --- a/python/sourcelist.h +++ /dev/null @@ -1,6 +0,0 @@ -#include - -struct PkgSourceListStruct -{ - pkgSourceList List; -}; -- cgit v1.2.3 From f505ecbf86d6ab30208c579a5e25c819c3733d89 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Nov 2005 11:52:23 +0000 Subject: * fixes in the acquire interface code (use CppPyObject with pkgAcquire* directly instead of using a PkgAcquireStruct) --- python/acquire.cc | 29 ++++++++++++++--------------- python/acquire.h | 6 ------ python/pkgmanager.cc | 7 +++---- python/sourcelist.cc | 1 - 4 files changed, 17 insertions(+), 26 deletions(-) delete mode 100644 python/acquire.h diff --git a/python/acquire.cc b/python/acquire.cc index 87f2717a..1bbed72a 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -8,7 +8,6 @@ #include "generic.h" #include "apt_pkgmodule.h" -#include "acquire.h" #include "progress.h" #include @@ -93,25 +92,25 @@ PyTypeObject AcquireItemType = static PyObject *PkgAcquireRun(PyObject *Self,PyObject *Args) { - PkgAcquireStruct &Struct = GetCpp(Self); + pkgAcquire *fetcher = GetCpp(Self); if (PyArg_ParseTuple(Args, "") == 0) return 0; //FIXME: add pulse interval here - pkgAcquire::RunResult run = Struct.fetcher.Run(); + pkgAcquire::RunResult run = fetcher->Run(); return HandleErrors(Py_BuildValue("i",run)); } static PyObject *PkgAcquireShutdown(PyObject *Self,PyObject *Args) { - PkgAcquireStruct &Struct = GetCpp(Self); + pkgAcquire *fetcher = GetCpp(Self); if (PyArg_ParseTuple(Args, "") == 0) return 0; - Struct.fetcher.Shutdown(); + fetcher->Shutdown(); Py_INCREF(Py_None); return HandleErrors(Py_None); @@ -126,19 +125,19 @@ static PyMethodDef PkgAcquireMethods[] = static PyObject *AcquireAttr(PyObject *Self,char *Name) { - PkgAcquireStruct &Struct = GetCpp(Self); + pkgAcquire *fetcher = GetCpp(Self); if(strcmp("TotalNeeded",Name) == 0) - return Py_BuildValue("l", Struct.fetcher.TotalNeeded()); + return Py_BuildValue("l", fetcher->TotalNeeded()); if(strcmp("FetchNeeded",Name) == 0) - return Py_BuildValue("l", Struct.fetcher.FetchNeeded()); + return Py_BuildValue("l", fetcher->FetchNeeded()); if(strcmp("PartialPresent",Name) == 0) - return Py_BuildValue("l", Struct.fetcher.PartialPresent()); + return Py_BuildValue("l", fetcher->PartialPresent()); if(strcmp("Items",Name) == 0) { PyObject *List = PyList_New(0); - for (pkgAcquire::ItemIterator I = Struct.fetcher.ItemsBegin(); - I != Struct.fetcher.ItemsEnd(); I++) + for (pkgAcquire::ItemIterator I = fetcher->ItemsBegin(); + I != fetcher->ItemsEnd(); I++) { PyObject *Obj; Obj = CppOwnedPyObject_NEW(Self,&AcquireItemType,I); @@ -167,10 +166,10 @@ PyTypeObject PkgAcquireType = PyObject_HEAD_INIT(&PyType_Type) 0, // ob_size "Acquire", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppDealloc, // tp_dealloc 0, // tp_print AcquireAttr, // tp_getattr 0, // tp_setattr @@ -199,8 +198,8 @@ PyObject *GetAcquire(PyObject *Self,PyObject *Args) fetcher = new pkgAcquire(); } - CppOwnedPyObject *FetcherObj = - CppOwnedPyObject_NEW(0,&PkgAcquireType, *fetcher); + CppPyObject *FetcherObj = + CppPyObject_NEW(&PkgAcquireType, fetcher); return FetcherObj; } diff --git a/python/acquire.h b/python/acquire.h deleted file mode 100644 index 1afcfff3..00000000 --- a/python/acquire.h +++ /dev/null @@ -1,6 +0,0 @@ -#include - -struct PkgAcquireStruct -{ - pkgAcquire fetcher; -}; diff --git a/python/pkgmanager.cc b/python/pkgmanager.cc index ce6d35a8..bcd4c45b 100644 --- a/python/pkgmanager.cc +++ b/python/pkgmanager.cc @@ -8,14 +8,13 @@ #include "generic.h" #include "apt_pkgmodule.h" -#include "acquire.h" #include "pkgrecords.h" #include #include #include #include - +#include #include @@ -30,11 +29,11 @@ static PyObject *PkgManagerGetArchives(PyObject *Self,PyObject *Args) &PkgRecordsType, &recs) == 0) return 0; - PkgAcquireStruct &s_fetcher = GetCpp(fetcher); + pkgAcquire *s_fetcher = GetCpp(fetcher); pkgSourceList *s_list = GetCpp(list); PkgRecordsStruct &s_records = GetCpp(recs); - bool res = pm->GetArchives(&s_fetcher.fetcher, s_list, + bool res = pm->GetArchives(s_fetcher, s_list, &s_records.Records); return HandleErrors(Py_BuildValue("b",res)); diff --git a/python/sourcelist.cc b/python/sourcelist.cc index 2d65062c..4eed21a7 100644 --- a/python/sourcelist.cc +++ b/python/sourcelist.cc @@ -30,7 +30,6 @@ static PyObject *PkgSourceListFindIndex(PyObject *Self,PyObject *Args) static char *doc_PkgSourceListReadMainList = "xxx"; static PyObject *PkgSourceListReadMainList(PyObject *Self,PyObject *Args) { - // PkgSourceListStruct &Struct = GetCpp(Self); pkgSourceList *list = GetCpp(Self); bool res = list->ReadMainList(); -- cgit v1.2.3 From 0a8598b3b728e0445f84186b3f302734d1347371 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 28 Nov 2005 12:27:33 +0000 Subject: * rewrote the cache.commit() code to make use of the new pkgAcquire/pkgPackageManager interface --- apt/cache.py | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++---- debian/changelog | 3 ++ debian/control | 2 +- python/acquire.cc | 7 +++-- 4 files changed, 88 insertions(+), 9 deletions(-) diff --git a/apt/cache.py b/apt/cache.py index 1fb128a3..ab3775aa 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -21,8 +21,9 @@ import apt_pkg from apt import Package -from apt.progress import OpTextProgress -from UserDict import UserDict +import apt.progress +import os +import sys class Cache(object): """ Dictionary-like package cache @@ -48,6 +49,8 @@ class Cache(object): self._cache = apt_pkg.GetCache(progress) self._depcache = apt_pkg.GetDepCache(self._cache) self._records = apt_pkg.GetPkgRecords(self._cache) + self._list = apt_pkg.GetPkgSourceList() + self._list.ReadMainList() self._dict = {} # build the packages dict @@ -115,9 +118,71 @@ class Cache(object): else: self._cache.Update(fetchProgress); - def commit(self, fprogress, iprogress): + def _fetchArchives(self, pm, fetchProgress): + """ fetch the needed archives """ + + # get lock + lockfile = apt_pkg.Config.FindDir("Dir::Cache::Archives") + "lock" + lock = apt_pkg.GetLock(lockfile) + if lock < 0: + raise IOError, "Failed to lock %s" % lockfile + fetcher = apt_pkg.GetAcquire(fetchProgress) + # this may as well throw a SystemError exception + if not pm.GetArchives(fetcher, self._list, self._records): + return False + # do the actual fetching + res = fetcher.Run() + if res == fetcher.ResultFailed: + return False + + # now check the result (this is the code from apt-get.cc) + failed = False + transient = False + errMsg = "" + for item in fetcher.Items: + if item.StatDone and item.Complete: + continue + if item.StatIdle: + transient = True + continue + errMsg += "Failed to fetch %s %s\n" % (item.DescURI,item.ErrorText) + failed = True + + # we raise a exception if the download failed + if failed: + raise IOError, errMsg + + # cleanup + fetcher.Shutdown() + os.close(lock) + return res + + def installArchives(self, pm, installProgress): + return pm.DoInstall() + + def commit(self, fetchProgress=None, installProgress=None): """ Apply the marked changes to the cache """ - return self._depcache.Commit(fprogress, iprogress) + # FIXME: + # use the new acquire/pkgmanager interface here, + # raise exceptions when a download or install fails + # and send proper error strings to the application. + # Current a failed download will just display "error" + # which is less than optimal! + + while True: + pm = apt_pkg.GetPackageManager(self._depcache) + + # fetch archives first + res = self._fetchArchives(pm, fetchProgress) + + # then install + res = self.installArchives(pm, installProgress) + if res == pm.ResultCompleted: + break + if res == pm.ResultFailed: + raise SystemError, "install failed" + + return res # cache changes def cachePostChange(self): @@ -228,7 +293,7 @@ def cache_post_changed(): if __name__ == "__main__": print "Cache self test" apt_pkg.init() - c = Cache(OpTextProgress()) + c = Cache(apt.progress.OpTextProgress()) c.connect("cache_pre_change", cache_pre_changed) c.connect("cache_post_change", cache_post_changed) print c.has_key("aptitude") @@ -246,6 +311,16 @@ if __name__ == "__main__": #print p.name x = p.name + + # see if fetching works + for dir in ["/tmp/pytest", "/tmp/pytest/partial"]: + if not os.path.exists(dir): + os.mkdir(dir) + apt_pkg.Config.Set("Dir::Cache::Archives","/tmp/pytest") + pm = apt_pkg.GetPackageManager(c._depcache) + c._fetchArchives(pm, apt.progress.TextFetchProgress()) + #sys.exit(1) + print "Testing filtered cache (argument is old cache)" f = FilteredCache(c) f.cache.connect("cache_pre_change", cache_pre_changed) diff --git a/debian/changelog b/debian/changelog index 9ffd5b12..1a4cb0a8 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,6 +3,9 @@ python-apt (0.6.15) unstable; urgency=low * fix a invalid return from cache.commit(), fail if a download failed * apt.Package.candidateOrigin returns a class now * added pkgAcquire, pkgPackageManager and a example (acquire.py) + * tightend build-dependencies for new apt and the c++ transition + * rewrote cache.Commit() and make it raise proper Exception if stuff + goes wrong -- Michael Vogt Thu, 17 Nov 2005 13:00:14 +0100 diff --git a/debian/control b/debian/control index 8fb8a669..eec81bd3 100644 --- a/debian/control +++ b/debian/control @@ -4,7 +4,7 @@ Priority: optional Maintainer: APT Development Team Uploaders: Matt Zimmerman , Michael Vogt Standards-Version: 3.6.1.1 -Build-Depends: debhelper (>= 4.2.28), libapt-pkg-dev (>= 0.6.40.1), apt-utils, python-dev, python2.4-dev, python2.3-dev +Build-Depends: debhelper (>= 4.2.28), libapt-pkg-dev (>= 0.6.43ubuntu1), apt-utils, python-dev, python2.4-dev, python2.3-dev Package: python-apt Architecture: all diff --git a/python/acquire.cc b/python/acquire.cc index 1bbed72a..2bcd94c1 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -94,11 +94,11 @@ static PyObject *PkgAcquireRun(PyObject *Self,PyObject *Args) { pkgAcquire *fetcher = GetCpp(Self); - if (PyArg_ParseTuple(Args, "") == 0) + int pulseInterval = 500000; + if (PyArg_ParseTuple(Args, "|i", &pulseInterval) == 0) return 0; - //FIXME: add pulse interval here - pkgAcquire::RunResult run = fetcher->Run(); + pkgAcquire::RunResult run = fetcher->Run(pulseInterval); return HandleErrors(Py_BuildValue("i",run)); } @@ -119,6 +119,7 @@ static PyObject *PkgAcquireShutdown(PyObject *Self,PyObject *Args) static PyMethodDef PkgAcquireMethods[] = { {"Run",PkgAcquireRun,METH_VARARGS,"Run the fetcher"}, + {"Shutdown",PkgAcquireShutdown, METH_VARARGS,"Shutdown the fetcher"}, {} }; -- cgit v1.2.3 From 311111a187216e25957c08e7c2e114b0118a48e2 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 28 Nov 2005 13:01:29 +0000 Subject: * cache.commit() uses the packagemanager python code now (+fix the gui-inst example) --- apt/cache.py | 7 +++++-- apt/progress.py | 2 ++ doc/examples/gui-inst.py | 53 ++++++++++++++++++++++++++++-------------------- 3 files changed, 38 insertions(+), 24 deletions(-) diff --git a/apt/cache.py b/apt/cache.py index ab3775aa..259d7b9d 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -158,8 +158,11 @@ class Cache(object): return res def installArchives(self, pm, installProgress): - return pm.DoInstall() - + installProgress.startUpdate() + res = installProgress.run(pm) + installProgress.finishUpdate() + return res + def commit(self, fetchProgress=None, installProgress=None): """ Apply the marked changes to the cache """ # FIXME: diff --git a/apt/progress.py b/apt/progress.py index 6b4a10e3..552c9e75 100644 --- a/apt/progress.py +++ b/apt/progress.py @@ -123,6 +123,8 @@ class InstallProgress: pass def startUpdate(self): pass + def run(self, pm): + return pm.DoInstall() def finishUpdate(self): pass def updateInterface(self): diff --git a/doc/examples/gui-inst.py b/doc/examples/gui-inst.py index 38417e10..1cb551ef 100755 --- a/doc/examples/gui-inst.py +++ b/doc/examples/gui-inst.py @@ -2,6 +2,7 @@ # example how to install in a custom terminal widget # see also gnome bug: #169201 +import apt import apt_pkg import sys, os, fcntl import copy @@ -13,6 +14,7 @@ pygtk.require('2.0') import gtk import vte import time +import posix from apt.progress import OpProgress, FetchProgress, InstallProgress @@ -50,11 +52,16 @@ class TermInstallProgress(InstallProgress, gtk.Window): self.add(box) self.term = vte.Terminal() self.term.show() + # check for the child + self.reaper = vte.reaper_get() + self.reaper.connect("child-exited",self.child_exited) + self.finished = False + box.pack_start(self.term) self.progressbar = gtk.ProgressBar() self.progressbar.show() box.pack_start(self.progressbar) - + (read, write) = os.pipe() self.writefd=write self.status = os.fdopen(read, "r") @@ -62,7 +69,12 @@ class TermInstallProgress(InstallProgress, gtk.Window): print "read-fd: %s" % self.status.fileno() print "write-fd: %s" % self.writefd self.read = "" - + + def child_exited(self,term, pid, status): + print "child_exited: %s %s %s %s" % (self,term,pid,status) + self.apt_status = posix.WEXITSTATUS(status) + self.finished = True + def startUpdate(self): print "start" self.show() @@ -84,29 +96,26 @@ class TermInstallProgress(InstallProgress, gtk.Window): self.read = "" while gtk.events_pending(): gtk.main_iteration() + def finishUpdate(self): sys.stdin.readline() - def fork(self): + def run(self, pm): print "fork" env = ["VTE_PTY_KEEP_FD=%s"%self.writefd] print env pid = self.term.forkpty(envv=env) + if pid == 0: + res = pm.DoInstall(self.writefd) + print res + sys.exit(res) print "After fork: %s " % pid - return pid - - -# init -apt_pkg.init() - -progress = OpProgress() -cache = apt_pkg.GetCache(progress) -print "Available packages: %s " % cache.PackageCount + while not self.finished: + self.updateInterface() + return self.apt_status +cache = apt.Cache() +print "Available packages: %s " % cache._cache.PackageCount -# get depcache -depcache = apt_pkg.GetDepCache(cache) -depcache.ReadPinFile() -depcache.Init(progress) # update the cache fprogress = GuiFetchProgress() @@ -125,15 +134,15 @@ while gtk.events_pending(): gtk.main_iteration() -iter = cache["3dchess"] -print "\n%s"%iter +pkg = cache["3dchess"] +print "\n%s"%pkg.name # install or remove, the importend thing is to keep us busy :) -if iter.CurrentVer == None: - depcache.MarkInstall(iter) +if pkg.isInstalled: + pkg.markDelete() else: - depcache.MarkDelete(iter) -depcache.Commit(fprogress, iprogress) + pkg.markInstall() +cache.commit(fprogress, iprogress) print "Exiting" sys.exit(0) -- cgit v1.2.3 From ca8c79947fae5f77272e0912b74e13778192e4c1 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 28 Nov 2005 13:52:49 +0000 Subject: * small tweaks, prepared next ubuntu upload --- apt/cache.py | 2 +- debian/changelog | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/apt/cache.py b/apt/cache.py index 259d7b9d..5b95ec35 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -185,7 +185,7 @@ class Cache(object): if res == pm.ResultFailed: raise SystemError, "install failed" - return res + return (res == pm.ResultCompleted) # cache changes def cachePostChange(self): diff --git a/debian/changelog b/debian/changelog index 1a4cb0a8..3d865f90 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,11 +1,16 @@ -python-apt (0.6.15) unstable; urgency=low +python-apt (0.6.14ubuntu2) dapper; urgency=low + + * rewrote cache.Commit() and make it raise proper Exception if stuff + goes wrong + + -- Michael Vogt Mon, 28 Nov 2005 14:48:01 +0100 + +python-apt (0.6.14ubuntu1) dapper; urgency=low * fix a invalid return from cache.commit(), fail if a download failed * apt.Package.candidateOrigin returns a class now * added pkgAcquire, pkgPackageManager and a example (acquire.py) * tightend build-dependencies for new apt and the c++ transition - * rewrote cache.Commit() and make it raise proper Exception if stuff - goes wrong -- Michael Vogt Thu, 17 Nov 2005 13:00:14 +0100 -- cgit v1.2.3 From 4f61703281ce5b7b4902d4d496eb6f0976ac2190 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 28 Nov 2005 14:12:14 +0000 Subject: * make it work with media swaping --- apt/cache.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/apt/cache.py b/apt/cache.py index 5b95ec35..342dbfb5 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -118,7 +118,7 @@ class Cache(object): else: self._cache.Update(fetchProgress); - def _fetchArchives(self, pm, fetchProgress): + def _fetchArchives(self, fetcher, pm, fetchProgress): """ fetch the needed archives """ # get lock @@ -126,7 +126,7 @@ class Cache(object): lock = apt_pkg.GetLock(lockfile) if lock < 0: raise IOError, "Failed to lock %s" % lockfile - fetcher = apt_pkg.GetAcquire(fetchProgress) + # this may as well throw a SystemError exception if not pm.GetArchives(fetcher, self._list, self._records): return False @@ -153,7 +153,6 @@ class Cache(object): raise IOError, errMsg # cleanup - fetcher.Shutdown() os.close(lock) return res @@ -172,11 +171,16 @@ class Cache(object): # Current a failed download will just display "error" # which is less than optimal! - while True: - pm = apt_pkg.GetPackageManager(self._depcache) + if fetchProgress == None: + fetchProgress = apt.progress.FetchProgress() + if installProgress == None: + installProgress = apt.progress.InstallProgress() + pm = apt_pkg.GetPackageManager(self._depcache) + fetcher = apt_pkg.GetAcquire(fetchProgress) + while True: # fetch archives first - res = self._fetchArchives(pm, fetchProgress) + res = self._fetchArchives(fetcher, pm, fetchProgress) # then install res = self.installArchives(pm, installProgress) @@ -184,7 +188,8 @@ class Cache(object): break if res == pm.ResultFailed: raise SystemError, "install failed" - + # reload the fetcher for media swaping + fetcher.Shutdown() return (res == pm.ResultCompleted) # cache changes @@ -321,7 +326,8 @@ if __name__ == "__main__": os.mkdir(dir) apt_pkg.Config.Set("Dir::Cache::Archives","/tmp/pytest") pm = apt_pkg.GetPackageManager(c._depcache) - c._fetchArchives(pm, apt.progress.TextFetchProgress()) + fetcher = apt_pkg.GetAcquire(apt.progress.TextFetchProgress()) + c._fetchArchives(fetcher, pm) #sys.exit(1) print "Testing filtered cache (argument is old cache)" -- cgit v1.2.3 From 06a053521298379ebae54f59901c05b9cfe9f3f8 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 28 Nov 2005 22:48:53 +0000 Subject: * changelog fixes --- debian/changelog | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/debian/changelog b/debian/changelog index 3d865f90..efd6cdca 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,18 +1,13 @@ -python-apt (0.6.14ubuntu2) dapper; urgency=low +python-apt (0.6.15) unstable; urgency=low * rewrote cache.Commit() and make it raise proper Exception if stuff goes wrong - - -- Michael Vogt Mon, 28 Nov 2005 14:48:01 +0100 - -python-apt (0.6.14ubuntu1) dapper; urgency=low - * fix a invalid return from cache.commit(), fail if a download failed * apt.Package.candidateOrigin returns a class now * added pkgAcquire, pkgPackageManager and a example (acquire.py) * tightend build-dependencies for new apt and the c++ transition - -- Michael Vogt Thu, 17 Nov 2005 13:00:14 +0100 + -- Michael Vogt Mon, 28 Nov 2005 23:48:37 +0100 python-apt (0.6.14) unstable; urgency=low -- cgit v1.2.3 From 20ef36a125021a171b831a52d3e9143f5c3682ec Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 28 Nov 2005 22:54:17 +0000 Subject: * fix build-deps --- debian/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/control b/debian/control index eec81bd3..472712d9 100644 --- a/debian/control +++ b/debian/control @@ -4,7 +4,7 @@ Priority: optional Maintainer: APT Development Team Uploaders: Matt Zimmerman , Michael Vogt Standards-Version: 3.6.1.1 -Build-Depends: debhelper (>= 4.2.28), libapt-pkg-dev (>= 0.6.43ubuntu1), apt-utils, python-dev, python2.4-dev, python2.3-dev +Build-Depends: debhelper (>= 4.2.28), libapt-pkg-dev (>= 0.6.43), apt-utils, python-dev, python2.4-dev, python2.3-dev Package: python-apt Architecture: all -- cgit v1.2.3 From a31cea47fc17cb55016fd52a6ab6bafe5a0857a8 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 1 Dec 2005 13:36:35 +0000 Subject: * pkgAcqFile wrapper added --- debian/changelog | 7 ++++++ doc/examples/acquire.py | 7 ++++++ python/acquire.cc | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ python/apt_pkgmodule.cc | 1 + python/apt_pkgmodule.h | 1 + 5 files changed, 83 insertions(+) diff --git a/debian/changelog b/debian/changelog index efd6cdca..402ff2dc 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +python-apt (0.6.16) unstable; urgency=low + + * added GetPkgAcqFile to queue individual file downloads with the + system + + -- Michael Vogt Thu, 1 Dec 2005 14:01:39 +0100 + python-apt (0.6.15) unstable; urgency=low * rewrote cache.Commit() and make it raise proper Exception if stuff diff --git a/doc/examples/acquire.py b/doc/examples/acquire.py index 72d0c74e..2736ad9c 100644 --- a/doc/examples/acquire.py +++ b/doc/examples/acquire.py @@ -34,6 +34,13 @@ pm = apt_pkg.GetPackageManager(depcache) print pm print fetcher +af = apt_pkg.GetPkgAcqFile(fetcher, + uri="ftp://ftp.debian.org/debian/dists/README", + descr="sample descr", + destFile="/tmp/lala2") +fetcher.Run() +sys.exit(1) + pm.GetArchives(fetcher,list,recs) for item in fetcher.Items: diff --git a/python/acquire.cc b/python/acquire.cc index 2bcd94c1..03606ef2 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -208,4 +208,71 @@ PyObject *GetAcquire(PyObject *Self,PyObject *Args) + +// pkgAcquireFile + +static PyObject *AcquireFileAttr(PyObject *Self,char *Name) +{ + pkgAcqFile *acqFile = GetCpp(Self); + + PyErr_SetString(PyExc_AttributeError,Name); + return 0; +} + + + + +PyTypeObject PkgAcquireFileType = +{ + PyObject_HEAD_INIT(&PyType_Type) + 0, // ob_size + "pkgAcquireFile", // tp_name + sizeof(CppPyObject),// tp_basicsize + 0, // tp_itemsize + // Methods + CppDealloc, // tp_dealloc + 0, // tp_print + AcquireFileAttr, // tp_getattr + 0, // tp_setattr + 0, // tp_compare + 0, // tp_repr + 0, // tp_as_number + 0, // tp_as_sequence + 0, // tp_as_mapping + 0, // tp_hash +}; + +PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject * kwds) +{ + PyObject *pyfetcher; + char *uri, *md5, *descr, *shortDescr, *destDir, *destFile; + int size; + uri = md5 = descr = shortDescr = destDir = destFile = ""; + + char * kwlist[] = {"owner","uri", "md5", "size", "descr", "shortDescr", + "destDir", "destFile", NULL}; + + if (PyArg_ParseTupleAndKeywords(Args, kwds, "O!s|sissss", kwlist, + &PkgAcquireType, &pyfetcher, &uri, &md5, + &size, &descr, &shortDescr, &destDir, + &destFile) == 0) + return 0; + + pkgAcquire *fetcher = GetCpp(pyfetcher); + pkgAcqFile *af = new pkgAcqFile(fetcher, // owner + uri, // uri + md5, // md5 + size, // size + descr, // descr + shortDescr, // shortdescr + destDir, // destdir + destFile // destfile + ); + CppPyObject *AcqFileObj = CppPyObject_NEW(&PkgAcquireFileType); + AcqFileObj->Object = af; + + return AcqFileObj; +} + + /*}}}*/ diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 5731cae4..e73628c3 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -398,6 +398,7 @@ static PyMethodDef methods[] = // Acquire {"GetAcquire",GetAcquire,METH_VARARGS,"GetAcquire() -> Acquire"}, + {"GetPkgAcqFile",(PyCFunction)GetPkgAcqFile,METH_KEYWORDS|METH_VARARGS,"GetPkgAcquireFile() -> pkgAcquireFile"}, // PkgManager {"GetPackageManager",GetPkgManager,METH_VARARGS,"GetPackageManager() -> PackageManager"}, diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index 93112f89..84b0069f 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -75,6 +75,7 @@ PyObject *GetCdrom(PyObject *Self,PyObject *Args); // acquire extern PyTypeObject PkgAcquireType; PyObject *GetAcquire(PyObject *Self,PyObject *Args); +PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject *kwds); // packagemanager extern PyTypeObject PkgManagerType; -- cgit v1.2.3 From 1aff3d1820f8efe90d811d96c0f5b3806f20d325 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 1 Dec 2005 14:00:27 +0000 Subject: * fix uninitialized size member in pkgAcqFile --- python/acquire.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/acquire.cc b/python/acquire.cc index 03606ef2..9d30e663 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -246,7 +246,7 @@ PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject * kwds) { PyObject *pyfetcher; char *uri, *md5, *descr, *shortDescr, *destDir, *destFile; - int size; + int size = 0; uri = md5 = descr = shortDescr = destDir = destFile = ""; char * kwlist[] = {"owner","uri", "md5", "size", "descr", "shortDescr", -- cgit v1.2.3 From c89b8408c0115e9fccdd4bfe180e93eb746b12cd Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 2 Dec 2005 23:17:16 +0000 Subject: * added "{candidate,installed}Downloadable" --- TODO | 4 ++++ apt/package.py | 21 +++++++++++++++++++++ apt/progress.py | 2 ++ debian/changelog | 1 + doc/examples/dependant-pkgs.py | 36 ++++++++++++++++++++++++++++++++++++ 5 files changed, 64 insertions(+) create mode 100644 TODO create mode 100644 doc/examples/dependant-pkgs.py diff --git a/TODO b/TODO new file mode 100644 index 00000000..f3f6a995 --- /dev/null +++ b/TODO @@ -0,0 +1,4 @@ +* apt.Package: + - change all candidateInstalledSize() to installSize(useCandidate=True) + same for candidateOrigin() (see downloadable for a example). + - might be better to have "Package.candidate.{downloadable,size,etc} diff --git a/apt/package.py b/apt/package.py index 5642496a..5fb6ade7 100644 --- a/apt/package.py +++ b/apt/package.py @@ -21,6 +21,7 @@ import apt_pkg, string, sys, random + class Package(object): """ This class represents a package in the cache """ @@ -89,6 +90,25 @@ class Package(object): return None candidateVersion = property(candidateVersion) + def _downloadable(self, useCandidate=True): + """ helper, return if the version is downloadable """ + if useCandidate: + ver = self._depcache.GetCandidateVer(self._pkg) + else: + ver = self._pkg.CurrentVer + if ver == None: + return False + return ver.Downloadable + def candidateDownloadable(self): + " returns if the canidate is downloadable " + self._downloadable(useCandidate=True) + candidateDownloadable = property(candidateDownloadable) + + def installedDownloadable(self): + " returns if the installed version is downloadable " + self._downloadable(useCandidate=False) + installedDownloadable = property(installedDownloadable) + def sourcePackageName(self): """ Return the source package name as string """ self._lookupRecord() @@ -298,6 +318,7 @@ if __name__ == "__main__": print "Priority (Installed): %s " % pkg.installedPriority print "Installed: %s " % pkg.installedVersion print "Candidate: %s " % pkg.candidateVersion + print "CandiateDownloadable: %s" % pkg.candidateDownloadable print "CandiateOrigin: %s" % pkg.candidateOrigin print "SourcePkg: %s " % pkg.sourcePackageName print "Section: %s " % pkg.section diff --git a/apt/progress.py b/apt/progress.py index 552c9e75..8c47ab95 100644 --- a/apt/progress.py +++ b/apt/progress.py @@ -62,6 +62,8 @@ class FetchProgress(object): dlIgnored : "Ignored"} def __init__(self): + self.eta = "" + self.percent = 0.0 pass def start(self): diff --git a/debian/changelog b/debian/changelog index 402ff2dc..bda57c52 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,6 +2,7 @@ python-apt (0.6.16) unstable; urgency=low * added GetPkgAcqFile to queue individual file downloads with the system + * added Package.downloadable -- Michael Vogt Thu, 1 Dec 2005 14:01:39 +0100 diff --git a/doc/examples/dependant-pkgs.py b/doc/examples/dependant-pkgs.py new file mode 100644 index 00000000..656e38bf --- /dev/null +++ b/doc/examples/dependant-pkgs.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +import apt +import sys + +pkgs = set() +cache = apt.Cache() +for pkg in cache: + candver = cache._depcache.GetCandidateVer(pkg._pkg) + if candver == None: + continue + dependslist = candver.DependsList + for dep in dependslist.keys(): + # get the list of each dependency object + for depVerList in dependslist[dep]: + for z in depVerList: + # get all TargetVersions of + # the dependency object + for tpkg in z.AllTargets(): + if sys.argv[1] == tpkg.ParentPkg.Name: + pkgs.add(pkg.name) + +main = [] +universe = [] +for pkg in pkgs: + if "universe" in cache[pkg].section: + universe.append(cache[pkg].sourcePackageName) + else: + main.append(cache[pkg].sourcePackageName) + +print "main:" +print "\n".join(main) +print + +print "universe:" +print "\n".join(universe) -- cgit v1.2.3 From bc7a0801357ecb20535efc3aefad1832274bb29c Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 5 Dec 2005 18:34:01 +0000 Subject: * added PkgSourceList.GetIndexes(); rewrote apt.cache.update() to use it --- apt/cache.py | 54 ++++++++++++++++++++++++++++++++++------------------ debian/changelog | 3 ++- python/sourcelist.cc | 17 +++++++++++++++++ 3 files changed, 54 insertions(+), 20 deletions(-) diff --git a/apt/cache.py b/apt/cache.py index 342dbfb5..973ffea5 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -112,24 +112,7 @@ class Cache(object): self._depcache.Upgrade(distUpgrade) self.cachePostChange() - def update(self, fetchProgress=None, opProgress=None): - if(opProgress != None): - self._cache.Update(fetchProgress, opProgress); - else: - self._cache.Update(fetchProgress); - - def _fetchArchives(self, fetcher, pm, fetchProgress): - """ fetch the needed archives """ - - # get lock - lockfile = apt_pkg.Config.FindDir("Dir::Cache::Archives") + "lock" - lock = apt_pkg.GetLock(lockfile) - if lock < 0: - raise IOError, "Failed to lock %s" % lockfile - - # this may as well throw a SystemError exception - if not pm.GetArchives(fetcher, self._list, self._records): - return False + def _runFetcher(self, fetcher): # do the actual fetching res = fetcher.Run() if res == fetcher.ResultFailed: @@ -140,7 +123,8 @@ class Cache(object): transient = False errMsg = "" for item in fetcher.Items: - if item.StatDone and item.Complete: + print item + if item.Status == item.StatDone: continue if item.StatIdle: transient = True @@ -151,10 +135,42 @@ class Cache(object): # we raise a exception if the download failed if failed: raise IOError, errMsg + return res + + def _fetchArchives(self, fetcher, pm, fetchProgress): + """ fetch the needed archives """ + # get lock + lockfile = apt_pkg.Config.FindDir("Dir::Cache::Archives") + "lock" + lock = apt_pkg.GetLock(lockfile) + if lock < 0: + raise IOError, "Failed to lock %s" % lockfile + + # this may as well throw a SystemError exception + if not pm.GetArchives(fetcher, self._list, self._records): + return False + # now run the fetcher, throw exception if something fails to be + # fetched + res = self._runFetcher(fetcher) + # cleanup os.close(lock) return res + + def update(self, fetchProgress=None): + lockfile = apt_pkg.Config.FindDir("Dir::State::Lists") + "lock" + lock = apt_pkg.GetLock(lockfile) + if lock < 0: + raise IOError, "Failed to lock %s" % lockfile + if fetchProgress == None: + fetchProgress = apt.progress.FetchProgress() + fetcher = apt_pkg.GetAcquire(fetchProgress) + # this can throw a exception + self._list.GetIndexes(fetcher) + # now run the fetcher, throw exception if something fails to be + # fetched + res = self._runFetcher(fetcher) + return res def installArchives(self, pm, installProgress): installProgress.startUpdate() diff --git a/debian/changelog b/debian/changelog index bda57c52..99201581 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,7 +2,8 @@ python-apt (0.6.16) unstable; urgency=low * added GetPkgAcqFile to queue individual file downloads with the system - * added Package.downloadable + * added SourceList.GetIndexes() + * rewrote apt.cache.update() to use the improved aquire interface -- Michael Vogt Thu, 1 Dec 2005 14:01:39 +0100 diff --git a/python/sourcelist.cc b/python/sourcelist.cc index 4eed21a7..497731c0 100644 --- a/python/sourcelist.cc +++ b/python/sourcelist.cc @@ -36,10 +36,27 @@ static PyObject *PkgSourceListReadMainList(PyObject *Self,PyObject *Args) return HandleErrors(Py_BuildValue("b",res)); } +static char *doc_PkgSourceListGetIndexes = "Load the indexes into the fetcher"; +static PyObject *PkgSourceListGetIndexes(PyObject *Self,PyObject *Args) +{ + pkgSourceList *list = GetCpp(Self); + + PyObject *pyFetcher; + + if (PyArg_ParseTuple(Args, "O!",&PkgAcquireType,&pyFetcher) == 0) + return 0; + + pkgAcquire *fetcher = GetCpp(pyFetcher); + bool res = list->GetIndexes(fetcher); + + return HandleErrors(Py_BuildValue("b",res)); +} + static PyMethodDef PkgSourceListMethods[] = { {"FindIndex",PkgSourceListFindIndex,METH_VARARGS,doc_PkgSourceListFindIndex}, {"ReadMainList",PkgSourceListReadMainList,METH_VARARGS,doc_PkgSourceListReadMainList}, + {"GetIndexes",PkgSourceListGetIndexes,METH_VARARGS,doc_PkgSourceListReadMainList}, {} }; -- cgit v1.2.3 From e17b802158234e43560e3d82436f745cb159d798 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 6 Dec 2005 12:18:19 +0000 Subject: * removed debug output --- apt/cache.py | 1 - doc/examples/action.py | 3 --- 2 files changed, 4 deletions(-) diff --git a/apt/cache.py b/apt/cache.py index 973ffea5..ed07f2c9 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -123,7 +123,6 @@ class Cache(object): transient = False errMsg = "" for item in fetcher.Items: - print item if item.Status == item.StatDone: continue if item.StatIdle: diff --git a/doc/examples/action.py b/doc/examples/action.py index a794317a..adf26539 100644 --- a/doc/examples/action.py +++ b/doc/examples/action.py @@ -30,9 +30,6 @@ sys.exit(0) - - - iter = cache["base-config"] print "example package iter: %s" % iter -- cgit v1.2.3 From 712fd8a6948cc3f11de57f7abf598a8df18a646b Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 6 Dec 2005 13:13:46 +0000 Subject: * bugfix in the acquire.FetchNeeded code --- doc/examples/acquire.py | 11 +++++++++++ python/acquire.cc | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/doc/examples/acquire.py b/doc/examples/acquire.py index 2736ad9c..516a3d6d 100644 --- a/doc/examples/acquire.py +++ b/doc/examples/acquire.py @@ -16,6 +16,17 @@ recs = apt_pkg.GetPkgRecords(cache) list = apt_pkg.GetPkgSourceList() list.ReadMainList() +# show the amount fetch needed for a dist-upgrade +depcache.Upgrade(True) +progress = apt.progress.TextFetchProgress() +fetcher = apt_pkg.GetAcquire(progress) +pm = apt_pkg.GetPackageManager(depcache) +pm.GetArchives(fetcher,list,recs) +print "%s (%s)" % (apt_pkg.SizeToStr(fetcher.FetchNeeded), fetcher.FetchNeeded) + +for pkg in cache.Packages: + depcache.MarkKeep(pkg) + try: os.mkdir("/tmp/pyapt-test") os.mkdir("/tmp/pyapt-test/partial") diff --git a/python/acquire.cc b/python/acquire.cc index 9d30e663..97064c43 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -129,11 +129,11 @@ static PyObject *AcquireAttr(PyObject *Self,char *Name) pkgAcquire *fetcher = GetCpp(Self); if(strcmp("TotalNeeded",Name) == 0) - return Py_BuildValue("l", fetcher->TotalNeeded()); + return Py_BuildValue("d", fetcher->TotalNeeded()); if(strcmp("FetchNeeded",Name) == 0) - return Py_BuildValue("l", fetcher->FetchNeeded()); + return Py_BuildValue("d", fetcher->FetchNeeded()); if(strcmp("PartialPresent",Name) == 0) - return Py_BuildValue("l", fetcher->PartialPresent()); + return Py_BuildValue("d", fetcher->PartialPresent()); if(strcmp("Items",Name) == 0) { PyObject *List = PyList_New(0); -- cgit v1.2.3 From b1ce3179428c2b1c8384c2b0a12ef9d8c1172f72 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 6 Dec 2005 18:56:25 +0000 Subject: * candidate origin returns a list now --- apt/package.py | 19 +++++++++---------- debian/changelog | 2 ++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/apt/package.py b/apt/package.py index 5fb6ade7..130340f4 100644 --- a/apt/package.py +++ b/apt/package.py @@ -235,14 +235,7 @@ class Package(object): # canidate origin class Origin: - def __init__(self,pkg): - ver = pkg._depcache.GetCandidateVer(pkg._pkg) - if not ver: - return None - (VerFileIter,index) = ver.FileList.pop() - #print len(VerFileIter) - #print VerFileIter - #return VerFileIter.Component + def __init__(self,VerFileIter): self.component = VerFileIter.Component self.archive = VerFileIter.Archive self.origin = VerFileIter.Origin @@ -254,7 +247,13 @@ class Package(object): self.origin, self.label, self.site) def candidateOrigin(self): - return self.Origin(self) + ver = pkg._depcache.GetCandidateVer(pkg._pkg) + if not ver: + return None + origins = [] + for (verFileIter,index) in ver.FileList: + origins.append(self.Origin(verFileIter)) + return origins candidateOrigin = property(candidateOrigin) # depcache actions @@ -319,7 +318,7 @@ if __name__ == "__main__": print "Installed: %s " % pkg.installedVersion print "Candidate: %s " % pkg.candidateVersion print "CandiateDownloadable: %s" % pkg.candidateDownloadable - print "CandiateOrigin: %s" % pkg.candidateOrigin + print "CandiateOrigins: %s" % pkg.candidateOrigin print "SourcePkg: %s " % pkg.sourcePackageName print "Section: %s " % pkg.section print "Summary: %s" % pkg.summary diff --git a/debian/changelog b/debian/changelog index 99201581..2c202597 100644 --- a/debian/changelog +++ b/debian/changelog @@ -4,6 +4,8 @@ python-apt (0.6.16) unstable; urgency=low system * added SourceList.GetIndexes() * rewrote apt.cache.update() to use the improved aquire interface + * apt/ API change: apt.Package.candidateOrigin returns a list of origins + now instead of a single one -- Michael Vogt Thu, 1 Dec 2005 14:01:39 +0100 -- cgit v1.2.3 From 91c285d060448d7053f65ca5909784ae9273e6c8 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 6 Dec 2005 19:12:23 +0000 Subject: * apt.Package.candiateOrigin() fix --- apt/package.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apt/package.py b/apt/package.py index 130340f4..4ca27b81 100644 --- a/apt/package.py +++ b/apt/package.py @@ -247,7 +247,7 @@ class Package(object): self.origin, self.label, self.site) def candidateOrigin(self): - ver = pkg._depcache.GetCandidateVer(pkg._pkg) + ver = self._depcache.GetCandidateVer(self._pkg) if not ver: return None origins = [] -- cgit v1.2.3 From b4141dda949890eaa50f0097b6fc6baeb3c489ac Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 6 Dec 2005 21:59:07 +0000 Subject: * apt.progress.InstallProgress class improved --- apt/progress.py | 53 +++++++++++++++++++++++++++++++++++++++++-- doc/examples/inst.py | 63 ++++++++++++++++++---------------------------------- 2 files changed, 73 insertions(+), 43 deletions(-) diff --git a/apt/progress.py b/apt/progress.py index 8c47ab95..b02fb33a 100644 --- a/apt/progress.py +++ b/apt/progress.py @@ -19,7 +19,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA -import sys, apt_pkg +import sys, apt_pkg, os, fcntl, string class OpProgress: """ Abstract class to implement reporting on cache opening @@ -117,7 +117,7 @@ class TextFetchProgress(FetchProgress): res = false; return res -class InstallProgress: +class DumbInstallProgress: """ Report the install progress Subclass this class to implement install progress reporting """ @@ -132,6 +132,55 @@ class InstallProgress: def updateInterface(self): pass +class InstallProgress(DumbInstallProgress): + """ A InstallProgress that is pretty useful. + It supports the attributes 'percent' 'status' and callbacks + for the dpkg errors and conffiles (not implemented yet) + """ + def __init__(self): + (read, write) = os.pipe() + self.writefd=write + self.statusfd = os.fdopen(read, "r") + fcntl.fcntl(self.statusfd.fileno(), fcntl.F_SETFL,os.O_NONBLOCK) + self.read = "" + self.percent = 0.0 + self.status = "" + def updateInterface(self): + if self.statusfd != None: + try: + self.read += os.read(self.statusfd.fileno(),1) + except OSError, (errno,errstr): + # resource temporarly unavailable is ignored + if errno != 11: + print errstr + if self.read.endswith("\n"): + # FIXME: add errorhandling + s = self.read + #print s + (status, pkg, percent, status_str) = string.split(s, ":") + #print "percent: %s %s" % (pkg, float(percent)/100.0) + self.percent = float(percent) + self.status = string.strip(status_str) + self.read = "" + def fork(self): + return os.fork() + def waitChild(self): + while True: + (pid, res) = os.waitpid(self.child_pid,os.WNOHANG) + if pid == self.child_pid: + break + self.updateInterface() + return os.WEXITSTATUS(res) + def run(self, pm): + pid = self.fork() + if pid == 0: + # child + res = pm.DoInstall(self.writefd) + sys.exit(res) + self.child_pid = pid + res = self.waitChild() + return res + class CdromProgress: """ Report the cdrom add progress Subclass this class to implement cdrom add progress reporting diff --git a/doc/examples/inst.py b/doc/examples/inst.py index fe5ec8e3..66b61c54 100644 --- a/doc/examples/inst.py +++ b/doc/examples/inst.py @@ -2,60 +2,41 @@ # example how to deal with the depcache import apt -import apt_pkg import sys, os import copy +import time -from progress import TextFetchProgress, TextInstallProgress -from apt.progress import OpTextProgress +from apt.progress import InstallProgress class TextInstallProgress(InstallProgress): def __init__(self): - InstallProgress.__init__(self) - self.status = None - def StartUpdate(self): - print "StartUpdate: %s" % self.statusfd - self.status = os.fdopen(self.statusfd, "r") - print self.status - def UpdateInterface(self): - if self.status != None: - s = self.status.readline() - if s: - print s - def FinishUpdate(self): - self.status.close() - -# init -apt_pkg.init() - -progress = OpTextProgress() -cache = apt_pkg.GetCache(progress) -print "Available packages: %s " % cache.PackageCount - -# get depcache -depcache = apt_pkg.GetDepCache(cache) -depcache.ReadPinFile() -depcache.Init(progress) - -# do something -fprogress = TextFetchProgress() + apt.progress.InstallProgress.__init__(self) + self.last = 0.0 + def updateInterface(self): + InstallProgress.updateInterface(self) + if self.last >= self.percent: + return + sys.stdout.write("\r[%s] %s\n" %(self.percent, self.status)) + sys.stdout.flush() + self.last = self.percent + +cache = apt.Cache(apt.progress.OpTextProgress()) + +fprogress = apt.progress.TextFetchProgress() iprogress = TextInstallProgress() -# can be used to set a custom fork method (like vte.Terminal.forkpty) -#iprogress.fork = os.fork - -iter = cache["base-config"] -print "\n%s"%iter +pkg = cache["base-config"] # install or remove, the importend thing is to keep us busy :) -if iter.CurrentVer == None: - depcache.MarkInstall(iter) +if pkg.isInstalled: + print "Going to delete %s" % pkg.name + pkg.markDelete() else: - depcache.MarkDelete(iter) -res = depcache.Commit(fprogress, iprogress) + print "Going to install %s" % pkg.name + pkg.markInstall() +res = cache.commit(fprogress, iprogress) print res -print "Exiting" sys.exit(0) -- cgit v1.2.3 From cce2b71c2fd64c8587238178c27a049ec450ce07 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 7 Dec 2005 10:40:14 +0000 Subject: * make pkgAcqFile use the old interface so that we don't depend on a new apt and still work with breezys apt --- debian/changelog | 2 +- debian/control | 2 +- doc/examples/acquire.py | 28 +++++++++++++++++++++++----- python/acquire.cc | 12 ++++-------- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/debian/changelog b/debian/changelog index 2c202597..5f4c0856 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,7 +1,7 @@ python-apt (0.6.16) unstable; urgency=low * added GetPkgAcqFile to queue individual file downloads with the - system + system (dosn't make use of the improved pkgAcqFile yet) * added SourceList.GetIndexes() * rewrote apt.cache.update() to use the improved aquire interface * apt/ API change: apt.Package.candidateOrigin returns a list of origins diff --git a/debian/control b/debian/control index 472712d9..bfa67c67 100644 --- a/debian/control +++ b/debian/control @@ -4,7 +4,7 @@ Priority: optional Maintainer: APT Development Team Uploaders: Matt Zimmerman , Michael Vogt Standards-Version: 3.6.1.1 -Build-Depends: debhelper (>= 4.2.28), libapt-pkg-dev (>= 0.6.43), apt-utils, python-dev, python2.4-dev, python2.3-dev +Build-Depends: debhelper (>= 4.2.28), libapt-pkg-dev (>= 0.6.40), apt-utils, python-dev, python2.4-dev, python2.3-dev Package: python-apt Architecture: all diff --git a/doc/examples/acquire.py b/doc/examples/acquire.py index 516a3d6d..a0790c98 100644 --- a/doc/examples/acquire.py +++ b/doc/examples/acquire.py @@ -2,6 +2,28 @@ import apt import apt_pkg import os import sys +import tempfile + +def get_file(fetcher, uri, destFile): + cwd = os.getcwd() + # create a temp dir + dir = tempfile.mkdtemp() + os.chdir(dir) + # get the file + af = apt_pkg.GetPkgAcqFile(fetcher, + uri=uri, + descr="sample descr") + res = fetcher.Run() + if res != fetcher.ResultContinue: + os.rmdir(dir) + os.chdir(cwd) + return False + filename = os.path.basename(uri) + os.rename(dir+"/"+filename,destFile) + # cleanup + os.rmdir(dir) + os.chdir(cwd) + return True apt_pkg.init() @@ -45,11 +67,7 @@ pm = apt_pkg.GetPackageManager(depcache) print pm print fetcher -af = apt_pkg.GetPkgAcqFile(fetcher, - uri="ftp://ftp.debian.org/debian/dists/README", - descr="sample descr", - destFile="/tmp/lala2") -fetcher.Run() +get_file(fetcher, "ftp://ftp.debian.org/debian/dists/README", "/tmp/lala") sys.exit(1) pm.GetArchives(fetcher,list,recs) diff --git a/python/acquire.cc b/python/acquire.cc index 97064c43..65f8f2d7 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -250,12 +250,11 @@ PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject * kwds) uri = md5 = descr = shortDescr = destDir = destFile = ""; char * kwlist[] = {"owner","uri", "md5", "size", "descr", "shortDescr", - "destDir", "destFile", NULL}; + NULL}; - if (PyArg_ParseTupleAndKeywords(Args, kwds, "O!s|sissss", kwlist, + if (PyArg_ParseTupleAndKeywords(Args, kwds, "O!s|siss", kwlist, &PkgAcquireType, &pyfetcher, &uri, &md5, - &size, &descr, &shortDescr, &destDir, - &destFile) == 0) + &size, &descr, &shortDescr) == 0) return 0; pkgAcquire *fetcher = GetCpp(pyfetcher); @@ -264,10 +263,7 @@ PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject * kwds) md5, // md5 size, // size descr, // descr - shortDescr, // shortdescr - destDir, // destdir - destFile // destfile - ); + shortDescr); // short-desc CppPyObject *AcqFileObj = CppPyObject_NEW(&PkgAcquireFileType); AcqFileObj->Object = af; -- cgit v1.2.3 From a7073554674b0e9aaf262e4d981fbbb20713ac4a Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 7 Dec 2005 11:22:30 +0000 Subject: * InstallProgress.{error,conffile}() functions added --- apt/progress.py | 18 ++++++++++++++++-- doc/examples/inst.py | 9 ++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/apt/progress.py b/apt/progress.py index b02fb33a..3ebe3664 100644 --- a/apt/progress.py +++ b/apt/progress.py @@ -19,7 +19,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA -import sys, apt_pkg, os, fcntl, string +import sys, apt_pkg, os, fcntl, string, re class OpProgress: """ Abstract class to implement reporting on cache opening @@ -145,6 +145,12 @@ class InstallProgress(DumbInstallProgress): self.read = "" self.percent = 0.0 self.status = "" + def error(self, pkg, errormsg): + " called when a error is detected during the install " + pass + def conffile(self,current,new): + " called when a conffile question from dpkg is detected " + pass def updateInterface(self): if self.statusfd != None: try: @@ -154,14 +160,22 @@ class InstallProgress(DumbInstallProgress): if errno != 11: print errstr if self.read.endswith("\n"): - # FIXME: add errorhandling s = self.read #print s (status, pkg, percent, status_str) = string.split(s, ":") #print "percent: %s %s" % (pkg, float(percent)/100.0) + if status == "pmerror": + self.error(pkg,status_str) + elif status == "pmconffile": + # we get a string like this: + # 'current-conffile' 'new-conffile' useredited distedited + match = re.compile("\s*\'(.*)\'\s*\'(.*)\'.*").match(status_str) + if match: + self.conffile(match.group(1), match.group(2)) self.percent = float(percent) self.status = string.strip(status_str) self.read = "" + def fork(self): return os.fork() def waitChild(self): diff --git a/doc/examples/inst.py b/doc/examples/inst.py index 66b61c54..0e91c28f 100644 --- a/doc/examples/inst.py +++ b/doc/examples/inst.py @@ -19,13 +19,20 @@ class TextInstallProgress(InstallProgress): sys.stdout.write("\r[%s] %s\n" %(self.percent, self.status)) sys.stdout.flush() self.last = self.percent + def conffile(self,current,new): + print "conffile prompt: %s %s" % (current,new) + def error(self, errorstr): + print "got dpkg error: '%s'" % errorstr cache = apt.Cache(apt.progress.OpTextProgress()) fprogress = apt.progress.TextFetchProgress() iprogress = TextInstallProgress() -pkg = cache["base-config"] +pkg = cache["test-package"] +pkg.markUpgrade() +cache.commit(fprogress,iprogress) +sys.exit(1) # install or remove, the importend thing is to keep us busy :) if pkg.isInstalled: -- cgit v1.2.3 From 86878ca7de8c4b14da7e10a82b26905de80a6c98 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 9 Dec 2005 20:40:55 +0000 Subject: * CdromProgress.totalSteps added --- debian/changelog | 1 + python/cdrom.cc | 6 ++---- python/progress.cc | 4 ++++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/debian/changelog b/debian/changelog index 5f4c0856..d8a8527a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,6 +6,7 @@ python-apt (0.6.16) unstable; urgency=low * rewrote apt.cache.update() to use the improved aquire interface * apt/ API change: apt.Package.candidateOrigin returns a list of origins now instead of a single one + * apt_pkg.Cdrom.Add() returns a boolean now, CdromProgress has totalSteps -- Michael Vogt Thu, 1 Dec 2005 14:01:39 +0100 diff --git a/python/cdrom.cc b/python/cdrom.cc index 13889b31..aca1be26 100644 --- a/python/cdrom.cc +++ b/python/cdrom.cc @@ -30,10 +30,9 @@ static PyObject *PkgCdromAdd(PyObject *Self,PyObject *Args) PyCdromProgress progress; progress.setCallbackInst(pyCdromProgressInst); - Struct.cdrom.Add(&progress); + bool res = Struct.cdrom.Add(&progress); - Py_INCREF(Py_None); - return HandleErrors(Py_None); + return HandleErrors(Py_BuildValue("b", res)); } static PyObject *PkgCdromIdent(PyObject *Self,PyObject *Args) @@ -69,7 +68,6 @@ static PyObject *CdromAttr(PyObject *Self,char *Name) { PkgCdromStruct &Struct = GetCpp(Self); - return Py_FindMethod(PkgCdromMethods,Self,Name); } diff --git a/python/progress.cc b/python/progress.cc index d0c97839..f00058c9 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -299,6 +299,10 @@ pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) void PyCdromProgress::Update(string text, int current) { PyObject *arglist = Py_BuildValue("(si)", text.c_str(), current); + + PyObject *o = Py_BuildValue("i", totalSteps); + PyObject_SetAttrString(callbackInst, "totalSteps", o); + RunSimpleCallback("update", arglist); } -- cgit v1.2.3 From 9a97c512ec3e3bfd2b1df17b8ab350b79637780e Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 22 Dec 2005 09:21:45 +0000 Subject: * removed the fetchProgress from _fetchArchives() (no longer needed) --- apt/cache.py | 4 ++-- debian/changelog | 2 +- doc/examples/dependant-pkgs.py | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) mode change 100644 => 100755 doc/examples/dependant-pkgs.py diff --git a/apt/cache.py b/apt/cache.py index ed07f2c9..9a0ff96c 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -136,7 +136,7 @@ class Cache(object): raise IOError, errMsg return res - def _fetchArchives(self, fetcher, pm, fetchProgress): + def _fetchArchives(self, fetcher, pm): """ fetch the needed archives """ # get lock @@ -195,7 +195,7 @@ class Cache(object): fetcher = apt_pkg.GetAcquire(fetchProgress) while True: # fetch archives first - res = self._fetchArchives(fetcher, pm, fetchProgress) + res = self._fetchArchives(fetcher, pm) # then install res = self.installArchives(pm, installProgress) diff --git a/debian/changelog b/debian/changelog index d8a8527a..c421b58e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -8,7 +8,7 @@ python-apt (0.6.16) unstable; urgency=low now instead of a single one * apt_pkg.Cdrom.Add() returns a boolean now, CdromProgress has totalSteps - -- Michael Vogt Thu, 1 Dec 2005 14:01:39 +0100 + -- python-apt (0.6.15) unstable; urgency=low diff --git a/doc/examples/dependant-pkgs.py b/doc/examples/dependant-pkgs.py old mode 100644 new mode 100755 index 656e38bf..f36936a8 --- a/doc/examples/dependant-pkgs.py +++ b/doc/examples/dependant-pkgs.py @@ -20,13 +20,13 @@ for pkg in cache: if sys.argv[1] == tpkg.ParentPkg.Name: pkgs.add(pkg.name) -main = [] -universe = [] +main = set() +universe = set() for pkg in pkgs: if "universe" in cache[pkg].section: - universe.append(cache[pkg].sourcePackageName) + universe.add(cache[pkg].sourcePackageName) else: - main.append(cache[pkg].sourcePackageName) + main.add(cache[pkg].sourcePackageName) print "main:" print "\n".join(main) -- cgit v1.2.3 From 5462bd26c53ed6cddfec2d22a85034db2c786b51 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 29 Dec 2005 11:28:14 +0000 Subject: * improved the gui-inst example --- debian/changelog | 2 +- doc/examples/gui-inst.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index c421b58e..6c9d56ec 100644 --- a/debian/changelog +++ b/debian/changelog @@ -8,7 +8,7 @@ python-apt (0.6.16) unstable; urgency=low now instead of a single one * apt_pkg.Cdrom.Add() returns a boolean now, CdromProgress has totalSteps - -- + -- Michael Vogt Thu, 22 Dec 2005 10:21:51 +0100 python-apt (0.6.15) unstable; urgency=low diff --git a/doc/examples/gui-inst.py b/doc/examples/gui-inst.py index 1cb551ef..deb325fe 100755 --- a/doc/examples/gui-inst.py +++ b/doc/examples/gui-inst.py @@ -38,10 +38,12 @@ class GuiFetchProgress(gtk.Window, FetchProgress): def stop(self): self.hide() def pulse(self): - self.label.set_text("Speed: %s/s" % apt_pkg.SizeToStr(self.currentCPS)) + FetchProgress.pulse(self) + self.label.set_text("Speed: %s/s" % apt_pkg.SizeToStr(self.currentCPS)) #self.progressbar.set_fraction(self.currentBytes/self.totalBytes) while gtk.events_pending(): gtk.main_iteration() + return True class TermInstallProgress(InstallProgress, gtk.Window): def __init__(self): -- cgit v1.2.3 From 170c310e75aa0bc417cb67f6e560fdaab482d72e Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 4 Jan 2006 23:27:33 +0000 Subject: * added support for pkgIndexFile --- debian/changelog | 3 +- doc/examples/indexfile.py | 20 +++++++++++++ python/apt_pkgmodule.h | 4 +++ python/indexfile.cc | 76 +++++++++++++++++++++++++++++++++++++++++++++++ python/makefile | 3 +- python/sourcelist.cc | 22 ++++++++++++-- 6 files changed, 124 insertions(+), 4 deletions(-) create mode 100644 doc/examples/indexfile.py create mode 100644 python/indexfile.cc diff --git a/debian/changelog b/debian/changelog index 6c9d56ec..2635581d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -7,8 +7,9 @@ python-apt (0.6.16) unstable; urgency=low * apt/ API change: apt.Package.candidateOrigin returns a list of origins now instead of a single one * apt_pkg.Cdrom.Add() returns a boolean now, CdromProgress has totalSteps + * added support for pkgIndexFile and added SourcesList.FindIndex() - -- Michael Vogt Thu, 22 Dec 2005 10:21:51 +0100 + -- python-apt (0.6.15) unstable; urgency=low diff --git a/doc/examples/indexfile.py b/doc/examples/indexfile.py new file mode 100644 index 00000000..e7f81e61 --- /dev/null +++ b/doc/examples/indexfile.py @@ -0,0 +1,20 @@ + +import apt_pkg + +apt_pkg.init() + +sources = apt_pkg.GetPkgSourceList() +sources.ReadMainList() + +cache = apt_pkg.GetCache() +depcache = apt_pkg.GetDepCache(cache) +pkg = cache["bzr"] +cand = depcache.GetCandidateVer(pkg) +for (f,i) in cand.FileList: + index = sources.FindIndex(f) + print index + if index: + print index.Size + print index.IsTrusted + print index.Exists + print index.HasPackages diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index 84b0069f..fe7dfe88 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -91,4 +91,8 @@ PyObject *GetPkgSrcRecords(PyObject *Self,PyObject *Args); extern PyTypeObject PkgSourceListType; PyObject *GetPkgSourceList(PyObject *Self,PyObject *Args); +// pkgSourceList +extern PyTypeObject PackageIndexFileType; + + #endif diff --git a/python/indexfile.cc b/python/indexfile.cc new file mode 100644 index 00000000..4e106e25 --- /dev/null +++ b/python/indexfile.cc @@ -0,0 +1,76 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +// $Id: indexfile.cc,v 1.2 2003/12/26 17:04:22 mdz Exp $ +/* ###################################################################### + + pkgIndexFile - Wrapper for the pkgIndexFilefunctions + + ##################################################################### */ + /*}}}*/ +// Include Files /*{{{*/ +#include "generic.h" +#include "apt_pkgmodule.h" + +#include + +#include + + + +static PyObject *PackageIndexFileAttr(PyObject *Self,char *Name) +{ + pkgIndexFile *File = GetCpp(Self); + if (strcmp("Label",Name) == 0) + return Safe_FromString(File->GetType()->Label); + else if (strcmp("Describe",Name) == 0) + return Safe_FromString(File->Describe().c_str()); + else if (strcmp("Exists",Name) == 0) + return Py_BuildValue("i",(File->Exists())); + else if (strcmp("HasPackages",Name) == 0) + return Py_BuildValue("i",(File->HasPackages())); + else if (strcmp("Size",Name) == 0) + return Py_BuildValue("i",(File->Size())); + else if (strcmp("IsTrusted",Name) == 0) + return Py_BuildValue("i",(File->IsTrusted())); + + PyErr_SetString(PyExc_AttributeError,Name); + return 0; +} + +static PyObject *PackageIndexFileRepr(PyObject *Self) +{ + pkgIndexFile *File = GetCpp(Self); + + char S[300]; + snprintf(S,sizeof(S),"", + File->GetType()->Label, File->Describe().c_str(), File->Exists(), + File->HasPackages(), File->Size(), + File->IsTrusted(), File->ArchiveURI("").c_str()); + return PyString_FromString(S); +} +PyTypeObject PackageIndexFileType = +{ + PyObject_HEAD_INIT(&PyType_Type) + 0, // ob_size + "pkgIndexFile", // tp_name + sizeof(CppOwnedPyObject), // tp_basicsize + 0, // tp_itemsize + // Methods + CppOwnedDealloc, // tp_dealloc + 0, // tp_print + PackageIndexFileAttr, // tp_getattr + 0, // tp_setattr + 0, // tp_compare + PackageIndexFileRepr, // tp_repr + 0, // tp_as_number + 0, // tp_as_sequence + 0, // tp_as_mapping + 0, // tp_hash +}; + + + + diff --git a/python/makefile b/python/makefile index 7fb1d756..24ef3238 100644 --- a/python/makefile +++ b/python/makefile @@ -11,7 +11,8 @@ SLIBS = -lapt-pkg LIB_MAKES = apt-pkg/makefile APT_PKG_SRC = apt_pkgmodule.cc configuration.cc generic.cc tag.cc string.cc \ cache.cc pkgrecords.cc pkgsrcrecords.cc sourcelist.cc \ - depcache.cc progress.cc cdrom.cc acquire.cc pkgmanager.cc + depcache.cc progress.cc cdrom.cc acquire.cc pkgmanager.cc \ + indexfile.cc SOURCE := $(APT_PKG_SRC) include $(PYTHON_H) progress.h diff --git a/python/sourcelist.cc b/python/sourcelist.cc index 497731c0..16e51368 100644 --- a/python/sourcelist.cc +++ b/python/sourcelist.cc @@ -3,7 +3,7 @@ // $Id: sourcelist.cc,v 1.2 2003/12/26 17:04:22 mdz Exp $ /* ###################################################################### - Package Records - Wrapper for the package records functions + SourcesList - Wrapper for the SourcesList functions ##################################################################### */ /*}}}*/ @@ -16,6 +16,7 @@ #include /*}}}*/ + // PkgsourceList Class /*{{{*/ // --------------------------------------------------------------------- @@ -24,7 +25,24 @@ static char *doc_PkgSourceListFindIndex = "xxx"; static PyObject *PkgSourceListFindIndex(PyObject *Self,PyObject *Args) { pkgSourceList *list = GetCpp(Self); - return Py_BuildValue("i", 1); + PyObject *pyPkgFileIter; + PyObject *pyPkgIndexFile; + + if (PyArg_ParseTuple(Args, "O!", &PackageFileType,&pyPkgFileIter) == 0) + return 0; + + pkgCache::PkgFileIterator &i = GetCpp(pyPkgFileIter); + pkgIndexFile *index; + if(list->FindIndex(i, index)) + { + pyPkgIndexFile = CppOwnedPyObject_NEW(pyPkgFileIter,&PackageIndexFileType,index); + return pyPkgIndexFile; + } + + //&PackageIndexFileType,&pyPkgIndexFile) + + Py_INCREF(Py_None); + return Py_None; } static char *doc_PkgSourceListReadMainList = "xxx"; -- cgit v1.2.3 From 0b33dd41e471a36c3e28a22319c3e760346ed2f3 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 4 Jan 2006 23:45:32 +0000 Subject: * added "trusted" to the Origin class (in package.py) --- apt/cache.py | 3 ++- apt/package.py | 24 ++++++++++++++++-------- debian/changelog | 1 + 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/apt/cache.py b/apt/cache.py index 9a0ff96c..2821f287 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -65,7 +65,8 @@ class Cache(object): # drop stuff with no versions (cruft) if len(pkg.VersionList) > 0: self._dict[pkg.Name] = Package(self._cache, self._depcache, - self._records, self, pkg) + self._records, self._list, + self, pkg) i += 1 if progress != None: diff --git a/apt/package.py b/apt/package.py index 4ca27b81..c9a73597 100644 --- a/apt/package.py +++ b/apt/package.py @@ -25,12 +25,13 @@ import apt_pkg, string, sys, random class Package(object): """ This class represents a package in the cache """ - def __init__(self, cache, depcache, records, pcache, pkgiter): + def __init__(self, cache, depcache, records, list, pcache, pkgiter): """ Init the Package object """ self._cache = cache # low level cache self._depcache = depcache self._records = records self._pkg = pkgiter + self._list = list # sourcelist self._pcache = pcache # python cache in cache.py pass @@ -235,16 +236,22 @@ class Package(object): # canidate origin class Origin: - def __init__(self,VerFileIter): + def __init__(self, pkg, VerFileIter): self.component = VerFileIter.Component self.archive = VerFileIter.Archive self.origin = VerFileIter.Origin self.label = VerFileIter.Label self.site = VerFileIter.Site - def __str__(self): - return "component:%s\narchive: %s\norigin: %s\nlabel: %s" \ - "\nsite %s\n"% (self.component, self.archive, - self.origin, self.label, self.site) + # check the trust + indexfile = pkg._list.FindIndex(VerFileIter) + if indexfile and indexfile.IsTrusted: + self.trusted = True + self.trusted = False + def __repr__(self): + return "component: '%s' archive: '%s' origin: '%s' label: %s" \ + "site '%s' isTrusted: '%s'"% (self.component, self.archive, + self.origin, self.label, + self.site, self.trusted) def candidateOrigin(self): ver = self._depcache.GetCandidateVer(self._pkg) @@ -252,7 +259,7 @@ class Package(object): return None origins = [] for (verFileIter,index) in ver.FileList: - origins.append(self.Origin(verFileIter)) + origins.append(self.Origin(pkg, verFileIter)) return origins candidateOrigin = property(candidateOrigin) @@ -308,9 +315,10 @@ if __name__ == "__main__": cache = apt_pkg.GetCache() depcache = apt_pkg.GetDepCache(cache) records = apt_pkg.GetPkgRecords(cache) + list = apt_pkg.GetPkgSourceList() iter = cache["apt-utils"] - pkg = Package(cache, depcache, records, None, iter) + pkg = Package(cache, depcache, records, list, None, iter) print "Name: %s " % pkg.name print "ID: %s " % pkg.id print "Priority (Candidate): %s " % pkg.priority diff --git a/debian/changelog b/debian/changelog index 2635581d..f00d90b3 100644 --- a/debian/changelog +++ b/debian/changelog @@ -8,6 +8,7 @@ python-apt (0.6.16) unstable; urgency=low now instead of a single one * apt_pkg.Cdrom.Add() returns a boolean now, CdromProgress has totalSteps * added support for pkgIndexFile and added SourcesList.FindIndex() + * added "trusted" to the Origin class -- -- cgit v1.2.3 From 412fbe245a579008f1c7626e5550edbf6bedc849 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 5 Jan 2006 00:34:27 +0000 Subject: * small fixes in the new Origin.trusted code --- apt/package.py | 7 ++++--- debian/changelog | 2 +- doc/examples/indexfile.py | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/apt/package.py b/apt/package.py index c9a73597..019bf44c 100644 --- a/apt/package.py +++ b/apt/package.py @@ -246,9 +246,10 @@ class Package(object): indexfile = pkg._list.FindIndex(VerFileIter) if indexfile and indexfile.IsTrusted: self.trusted = True - self.trusted = False + else: + self.trusted = False def __repr__(self): - return "component: '%s' archive: '%s' origin: '%s' label: %s" \ + return "component: '%s' archive: '%s' origin: '%s' label: '%s' " \ "site '%s' isTrusted: '%s'"% (self.component, self.archive, self.origin, self.label, self.site, self.trusted) @@ -259,7 +260,7 @@ class Package(object): return None origins = [] for (verFileIter,index) in ver.FileList: - origins.append(self.Origin(pkg, verFileIter)) + origins.append(self.Origin(self, verFileIter)) return origins candidateOrigin = property(candidateOrigin) diff --git a/debian/changelog b/debian/changelog index f00d90b3..0591ce09 100644 --- a/debian/changelog +++ b/debian/changelog @@ -10,7 +10,7 @@ python-apt (0.6.16) unstable; urgency=low * added support for pkgIndexFile and added SourcesList.FindIndex() * added "trusted" to the Origin class - -- + -- Michael Vogt Thu, 5 Jan 2006 00:56:36 +0100 python-apt (0.6.15) unstable; urgency=low diff --git a/doc/examples/indexfile.py b/doc/examples/indexfile.py index e7f81e61..5eaab517 100644 --- a/doc/examples/indexfile.py +++ b/doc/examples/indexfile.py @@ -8,7 +8,7 @@ sources.ReadMainList() cache = apt_pkg.GetCache() depcache = apt_pkg.GetDepCache(cache) -pkg = cache["bzr"] +pkg = cache["libimlib2"] cand = depcache.GetCandidateVer(pkg) for (f,i) in cand.FileList: index = sources.FindIndex(f) -- cgit v1.2.3 From 2ebdc239bc9fd606bb748abd1d7ad49bea9669a3 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 9 Jan 2006 11:28:00 +0000 Subject: * added MinimizeUpgrade, Upgrade returns a bool now --- python/depcache.cc | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/python/depcache.cc b/python/depcache.cc index 51c25080..0d2a16b5 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -233,15 +233,30 @@ static PyObject *PkgDepCacheUpgrade(PyObject *Self,PyObject *Args) if (PyArg_ParseTuple(Args,"|b",&distUpgrade) == 0) return 0; + bool res; if(distUpgrade) - pkgDistUpgrade(*depcache); + res = pkgDistUpgrade(*depcache); else - pkgAllUpgrade(*depcache); + res = pkgAllUpgrade(*depcache); Py_INCREF(Py_None); - return HandleErrors(Py_None); + return HandleErrors(Py_BuildValue("b",res)); +} + +static PyObject *PkgDepCacheMinimizeUpgrade(PyObject *Self,PyObject *Args) +{ + pkgDepCache *depcache = GetCpp(Self); + + if (PyArg_ParseTuple(Args,"") == 0) + return 0; + + bool res = pkgMinimizeUpgrade(*depcache); + + Py_INCREF(Py_None); + return HandleErrors(Py_BuildValue("b",res)); } + static PyObject *PkgDepCacheReadPinFile(PyObject *Self,PyObject *Args) { pkgDepCache *depcache = GetCpp(Self); @@ -481,6 +496,7 @@ static PyMethodDef PkgDepCacheMethods[] = {"Upgrade",PkgDepCacheUpgrade,METH_VARARGS,"Perform Upgrade (optional boolean argument if dist-upgrade should be performed)"}, {"FixBroken",PkgDepCacheFixBroken,METH_VARARGS,"Fix broken packages"}, {"ReadPinFile",PkgDepCacheReadPinFile,METH_VARARGS,"Read the pin policy"}, + {"MinimizeUpgrade",PkgDepCacheMinimizeUpgrade, METH_VARARGS,"Go over the entire set of packages and try to keep each package marked for upgrade. If a conflict is generated then the package is restored."}, // 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)"}, -- cgit v1.2.3 From 1b303cad60722bb73805c2b6ae3eb896a495fde2 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 9 Jan 2006 11:48:16 +0000 Subject: * fix broken returns a usefull value now --- python/depcache.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/python/depcache.cc b/python/depcache.cc index 0d2a16b5..e8140e2b 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -279,14 +279,15 @@ static PyObject *PkgDepCacheReadPinFile(PyObject *Self,PyObject *Args) static PyObject *PkgDepCacheFixBroken(PyObject *Self,PyObject *Args) { pkgDepCache *depcache = GetCpp(Self); - + + bool res=true; if (PyArg_ParseTuple(Args,"") == 0) return 0; - pkgFixBroken(*depcache); + res &=pkgFixBroken(*depcache); + res &=pkgMinimizeUpgrade(*depcache); - Py_INCREF(Py_None); - return HandleErrors(Py_None); + return HandleErrors(Py_BuildValue("b",res)); } -- cgit v1.2.3 From 905fa15d019d0134f98472133a46a84672781d92 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 10 Jan 2006 20:52:59 +0000 Subject: * don't return a apt.Package.sourcePackageName if _lookupRecord failed --- apt/package.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apt/package.py b/apt/package.py index 019bf44c..6a3ade64 100644 --- a/apt/package.py +++ b/apt/package.py @@ -112,7 +112,8 @@ class Package(object): def sourcePackageName(self): """ Return the source package name as string """ - self._lookupRecord() + if not self._lookupRecord(): + return None src = self._records.SourcePkg if src != "": return src -- cgit v1.2.3 From 38efee6ebac24314f3e0284fd1f551aac22a5bfa Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 10 Jan 2006 20:56:59 +0000 Subject: * shutup about missing candiateVersions in loopkupRecords (returning false is enough) --- apt/package.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apt/package.py b/apt/package.py index 6a3ade64..d57730c5 100644 --- a/apt/package.py +++ b/apt/package.py @@ -46,7 +46,7 @@ class Package(object): # check if we found a version if ver == None: - print "No version for: %s (Candiate: %s)" % (self._pkg.Name, UseCandidate) + #print "No version for: %s (Candiate: %s)" % (self._pkg.Name, UseCandidate) return False if ver.FileList == None: -- cgit v1.2.3 From ff33c888f56a00e3dea542cfb1091be3585311c8 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 11 Jan 2006 11:27:18 +0000 Subject: * make sure to close the CacheFile when a pkgCache is deallocated --- python/cache.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/python/cache.cc b/python/cache.cc index 5e2d9819..b35a3ade 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -231,6 +231,17 @@ static PyObject *CacheMapOp(PyObject *Self,PyObject *Arg) return CppOwnedPyObject_NEW(Self,&PackageType,Pkg); } +// we need a special dealloc here to make sure that the CacheFile +// is closed before deallocation the cache (otherwise we have a bad) +// memory leak +void PkgCacheFileDealloc(PyObject *Self) +{ + PyObject *CacheFilePy = GetOwner(Self); + pkgCacheFile *CacheF = GetCpp(CacheFilePy); + CacheF->Close(); + CppOwnedDealloc(Self); +} + static PyMappingMethods CacheMap = {0,CacheMapOp,0}; PyTypeObject PkgCacheType = { @@ -240,7 +251,7 @@ PyTypeObject PkgCacheType = sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + PkgCacheFileDealloc, // tp_dealloc 0, // tp_print CacheAttr, // tp_getattr 0, // tp_setattr -- cgit v1.2.3 From 372588a9b38e30daa11f499647f0ba822fc2e77f Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 11 Jan 2006 11:54:08 +0000 Subject: * added memleak.py in tests --- tests/memleak.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 tests/memleak.py diff --git a/tests/memleak.py b/tests/memleak.py new file mode 100755 index 00000000..3e59cbb7 --- /dev/null +++ b/tests/memleak.py @@ -0,0 +1,42 @@ +#!/usr/bin/python + +import apt +import apt_pkg +import time +import gc +import sys + + +cache = apt.Cache() + +# memleak +#for i in range(100): +# cache.open(None) +# print cache["apt"].name +# time.sleep(1) +# gc.collect() + +# memleak +#for i in range(100): +# cache = apt.Cache() +# time.sleep(1) +# cache = None +# gc.collect() + +# no memleak, but more or less the apt.Cache.open() code +for i in range(100): + cache = apt_pkg.GetCache() + depcache = apt_pkg.GetDepCache(cache) + records = apt_pkg.GetPkgRecords(cache) + list = apt_pkg.GetPkgSourceList() + list.ReadMainList() + dict = {} + for pkg in cache.Packages: + if len(pkg.VersionList) > 0: + dict[pkg.Name] = apt.Package(cache,depcache, + records, list, None, pkg) + + print cache["apt"] + time.sleep(1) + + gc.collect() -- cgit v1.2.3 From 61f25c8c12ebe651eb187fed640a41c8ce466943 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 24 Jan 2006 16:55:08 +0000 Subject: * typos fixed, changelog prepared for new debian upload --- apt/package.py | 6 +++--- debian/changelog | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/apt/package.py b/apt/package.py index d57730c5..4633123a 100644 --- a/apt/package.py +++ b/apt/package.py @@ -46,7 +46,7 @@ class Package(object): # check if we found a version if ver == None: - #print "No version for: %s (Candiate: %s)" % (self._pkg.Name, UseCandidate) + #print "No version for: %s (Candidate: %s)" % (self._pkg.Name, UseCandidate) return False if ver.FileList == None: @@ -327,8 +327,8 @@ if __name__ == "__main__": print "Priority (Installed): %s " % pkg.installedPriority print "Installed: %s " % pkg.installedVersion print "Candidate: %s " % pkg.candidateVersion - print "CandiateDownloadable: %s" % pkg.candidateDownloadable - print "CandiateOrigins: %s" % pkg.candidateOrigin + print "CandidateDownloadable: %s" % pkg.candidateDownloadable + print "CandidateOrigins: %s" % pkg.candidateOrigin print "SourcePkg: %s " % pkg.sourcePackageName print "Section: %s " % pkg.section print "Summary: %s" % pkg.summary diff --git a/debian/changelog b/debian/changelog index 0591ce09..2e8ec5c7 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +python-apt (0.6.16.1) unstable; urgency=low + + * memleak fixed when pkgCache objects are deallocated + * typos fixed (thanks to Gustavo Franco) + + -- + python-apt (0.6.16) unstable; urgency=low * added GetPkgAcqFile to queue individual file downloads with the -- cgit v1.2.3 From 940c6ecb9e7494414c4554fa4487cb5d17b5dadb Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 24 Jan 2006 17:30:07 +0000 Subject: * added pkgRecords.Record --- debian/changelog | 1 + python/pkgrecords.cc | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/debian/changelog b/debian/changelog index 2e8ec5c7..3b84dd1e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,6 +2,7 @@ python-apt (0.6.16.1) unstable; urgency=low * memleak fixed when pkgCache objects are deallocated * typos fixed (thanks to Gustavo Franco) + * pkgRecords.Record added to get raw record data -- diff --git a/python/pkgrecords.cc b/python/pkgrecords.cc index a85b570a..c6f5aeb9 100644 --- a/python/pkgrecords.cc +++ b/python/pkgrecords.cc @@ -73,6 +73,12 @@ static PyObject *PkgRecordsAttr(PyObject *Self,char *Name) return CppPyString(Struct.Last->LongDesc()); else if (strcmp("Name",Name) == 0) return CppPyString(Struct.Last->Name()); + else if (strcmp("Record", Name) == 0) + { + const char *start, *stop; + Struct.Last->GetRec(start, stop); + return PyString_FromStringAndSize(start,stop-start); + } } return Py_FindMethod(PkgRecordsMethods,Self,Name); -- cgit v1.2.3 From b51b6bf42e6ccd487f902fe31685defa0bc6aedd Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 26 Jan 2006 15:40:59 +0000 Subject: * the pkgCache::VerIterator.DependsList[] dict does no longer depend on the localized depends name but on the english one --- apt/cache.py | 2 +- debian/changelog | 4 +++- python/cache.cc | 12 +++++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/apt/cache.py b/apt/cache.py index 2821f287..fbca0f2a 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -203,7 +203,7 @@ class Cache(object): if res == pm.ResultCompleted: break if res == pm.ResultFailed: - raise SystemError, "install failed" + raise SystemError, "installArchives() failed" # reload the fetcher for media swaping fetcher.Shutdown() return (res == pm.ResultCompleted) diff --git a/debian/changelog b/debian/changelog index 3b84dd1e..80634e36 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,8 +3,10 @@ python-apt (0.6.16.1) unstable; urgency=low * memleak fixed when pkgCache objects are deallocated * typos fixed (thanks to Gustavo Franco) * pkgRecords.Record added to get raw record data + * python/cache.cc: "key" in pkgCache::VerIterator.DependsList[key] is + no longer locale specific but always english - -- + -- Michael Vogt Thu, 26 Jan 2006 16:30:02 +0100 python-apt (0.6.16) unstable; urgency=low diff --git a/python/cache.cc b/python/cache.cc index b35a3ade..174423c2 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -463,7 +463,17 @@ static PyObject *MakeDepends(PyObject *Owner,pkgCache::VerIterator &Ver, // Switch/create a new dict entry if (LastDepType != Start->Type || LastDep != 0) { - PyObject *Dep = PyString_FromString(Start.DepType()); + // must be in sync with pkgCache::DepType in libapt + // it sucks to have it here duplicated, but we get it + // translated from libapt and that is certainly not what + // we want in a programing interface + const char *Types[] = + { + "", "Depends","PreDepends","Suggests", + "Recommends","Conflicts","Replaces", + "Obsoletes" + }; + PyObject *Dep = PyString_FromString(Types[Start->Type]); LastDepType = Start->Type; LastDep = PyDict_GetItem(Dict,Dep); if (LastDep == 0) -- cgit v1.2.3 From 44657add82d9df4d949f82c1b1d84667d9f1f784 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 14 Feb 2006 16:30:31 +0000 Subject: * try to read complete lines in update-interface --- apt/progress.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apt/progress.py b/apt/progress.py index 3ebe3664..40cf8e48 100644 --- a/apt/progress.py +++ b/apt/progress.py @@ -154,7 +154,8 @@ class InstallProgress(DumbInstallProgress): def updateInterface(self): if self.statusfd != None: try: - self.read += os.read(self.statusfd.fileno(),1) + while not self.read.endswith("\n"): + self.read += os.read(self.statusfd.fileno(),1) except OSError, (errno,errstr): # resource temporarly unavailable is ignored if errno != 11: -- cgit v1.2.3 -- cgit v1.2.3 From a6d05b8fe1d75e27ca938e684971e4e0cb0ea8c9 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 22 Feb 2006 09:41:54 +0000 Subject: * changelog finalized --- debian/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 80634e36..7b8925e0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,7 +6,7 @@ python-apt (0.6.16.1) unstable; urgency=low * python/cache.cc: "key" in pkgCache::VerIterator.DependsList[key] is no longer locale specific but always english - -- Michael Vogt Thu, 26 Jan 2006 16:30:02 +0100 + -- Michael Vogt Wed, 22 Feb 2006 10:41:13 +0100 python-apt (0.6.16) unstable; urgency=low -- cgit v1.2.3 From 55b2eeb0b63b544b3519b019f6d3969d88296618 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 28 Feb 2006 10:59:54 +0000 Subject: * interface fixes for kamion, pychecker fixes --- apt/cache.py | 18 +++++------------- apt/package.py | 18 ++++++++++-------- apt/progress.py | 18 +++++++++++++----- debian/changelog | 12 ++++++++++++ doc/examples/progress.py | 17 +++++++++++++++++ 5 files changed, 57 insertions(+), 26 deletions(-) diff --git a/apt/cache.py b/apt/cache.py index fbca0f2a..c98c0d49 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -83,11 +83,7 @@ class Cache(object): raise StopIteration def has_key(self, key): - try: - self._dict[key] - except KeyError: - return False - return True + return self._dict.has_key(key) def __len__(self): return len(self._dict) @@ -266,11 +262,7 @@ class FilteredCache(object): return self._filtered.keys() def has_key(self, key): - try: - self._filtered[key] - except KeyError: - return False - return True + return self._filtered.has_key(key) def _reapplyFilter(self): " internal helper to refilter " @@ -337,9 +329,9 @@ if __name__ == "__main__": # see if fetching works - for dir in ["/tmp/pytest", "/tmp/pytest/partial"]: - if not os.path.exists(dir): - os.mkdir(dir) + for d in ["/tmp/pytest", "/tmp/pytest/partial"]: + if not os.path.exists(d): + os.mkdir(d) apt_pkg.Config.Set("Dir::Cache::Archives","/tmp/pytest") pm = apt_pkg.GetPackageManager(c._depcache) fetcher = apt_pkg.GetAcquire(apt.progress.TextFetchProgress()) diff --git a/apt/package.py b/apt/package.py index 4633123a..9a4a90e6 100644 --- a/apt/package.py +++ b/apt/package.py @@ -19,19 +19,21 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA -import apt_pkg, string, sys, random +import apt_pkg +import sys +import random class Package(object): """ This class represents a package in the cache """ - def __init__(self, cache, depcache, records, list, pcache, pkgiter): + def __init__(self, cache, depcache, records, sourcelist, pcache, pkgiter): """ Init the Package object """ self._cache = cache # low level cache self._depcache = depcache self._records = records self._pkg = pkgiter - self._list = list # sourcelist + self._list = sourcelist # sourcelist self._pcache = pcache # python cache in cache.py pass @@ -52,8 +54,8 @@ class Package(object): if ver.FileList == None: print "No FileList for: %s " % self._pkg.Name() return False - file, index = ver.FileList.pop(0) - self._records.Lookup((file,index)) + f, index = ver.FileList.pop(0) + self._records.Lookup((f,index)) return True @@ -317,10 +319,10 @@ if __name__ == "__main__": cache = apt_pkg.GetCache() depcache = apt_pkg.GetDepCache(cache) records = apt_pkg.GetPkgRecords(cache) - list = apt_pkg.GetPkgSourceList() + sourcelist = apt_pkg.GetPkgSourceList() - iter = cache["apt-utils"] - pkg = Package(cache, depcache, records, list, None, iter) + pkgiter = cache["apt-utils"] + pkg = Package(cache, depcache, records, sourcelist, None, pkgiter) print "Name: %s " % pkg.name print "ID: %s " % pkg.id print "Priority (Candidate): %s " % pkg.priority diff --git a/apt/progress.py b/apt/progress.py index 40cf8e48..9958b9b7 100644 --- a/apt/progress.py +++ b/apt/progress.py @@ -21,7 +21,7 @@ import sys, apt_pkg, os, fcntl, string, re -class OpProgress: +class OpProgress(object): """ Abstract class to implement reporting on cache opening Subclass this class to implement simple Operation progress reporting """ @@ -117,7 +117,7 @@ class TextFetchProgress(FetchProgress): res = false; return res -class DumbInstallProgress: +class DumbInstallProgress(object): """ Report the install progress Subclass this class to implement install progress reporting """ @@ -135,9 +135,10 @@ class DumbInstallProgress: class InstallProgress(DumbInstallProgress): """ A InstallProgress that is pretty useful. It supports the attributes 'percent' 'status' and callbacks - for the dpkg errors and conffiles (not implemented yet) + for the dpkg errors and conffiles and status changes """ def __init__(self): + DumbInstallProgress.__init__(self) (read, write) = os.pipe() self.writefd=write self.statusfd = os.fdopen(read, "r") @@ -151,6 +152,9 @@ class InstallProgress(DumbInstallProgress): def conffile(self,current,new): " called when a conffile question from dpkg is detected " pass + def statusChange(self, pkg, percent, status): + " called when the status changed " + pass def updateInterface(self): if self.statusfd != None: try: @@ -173,8 +177,12 @@ class InstallProgress(DumbInstallProgress): match = re.compile("\s*\'(.*)\'\s*\'(.*)\'.*").match(status_str) if match: self.conffile(match.group(1), match.group(2)) - self.percent = float(percent) - self.status = string.strip(status_str) + elif status == "pmstatus": + if float(percent) != self.percent or \ + status_str != self.status: + self.statusChange(pkg, percent, status_str) + self.percent = float(percent) + self.status = string.strip(status_str) self.read = "" def fork(self): diff --git a/debian/changelog b/debian/changelog index 7b8925e0..4a37a69d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,15 @@ +python-apt (0.6.16.2) unstable; urgency=low + + * apt/progress.py: + - added InstallProgress.statusChange(pkg, percent, status) + - make DumbInstallProgress a new-style class + (thanks to kamion for the suggestions) + - fix various pychecker warnings + * apt/cache.py, apt/package.py: fix various pychecker warnings + + + -- Michael Vogt Tue, 28 Feb 2006 11:40:38 +0100 + python-apt (0.6.16.1) unstable; urgency=low * memleak fixed when pkgCache objects are deallocated diff --git a/doc/examples/progress.py b/doc/examples/progress.py index d820fcb2..2723c382 100644 --- a/doc/examples/progress.py +++ b/doc/examples/progress.py @@ -44,12 +44,16 @@ class TextFetchProgress(apt.FetchProgress): class TextInstallProgress(apt.InstallProgress): def __init__(self): + apt.InstallProgress.__init__(self) pass def startUpdate(self): print "StartUpdate" def finishUpdate(self): print "FinishUpdate" + def statusChange(self, pkg, percent, status): + print "[%s] %s: %s" % (percent, pkg, status) def updateInterface(self): + apt.InstallProgress.updateInterface(self) # usefull to e.g. redraw a GUI time.sleep(0.1) @@ -70,3 +74,16 @@ class TextCdromProgress(apt.CdromProgress): print "Please insert cdrom and press " answer = sys.stdin.readline() return True + + +if __name__ == "__main__": + c = apt.Cache() + pkg = c["3dchess"] + if pkg.isInstalled: + pkg.markDelete() + else: + pkg.markInstall() + + res = c.commit(TextFetchProgress(), TextInstallProgress()) + + print res -- cgit v1.2.3 From d38698d25c5fdda005f02427357fa97a7d7e2a86 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 28 Feb 2006 11:00:13 +0000 Subject: * un-finalize the changelog --- debian/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 4a37a69d..77e5794b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -8,7 +8,7 @@ python-apt (0.6.16.2) unstable; urgency=low * apt/cache.py, apt/package.py: fix various pychecker warnings - -- Michael Vogt Tue, 28 Feb 2006 11:40:38 +0100 + -- python-apt (0.6.16.1) unstable; urgency=low -- cgit v1.2.3 From ef973e43572c5748f908ae0e353e71d61028b479 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 28 Feb 2006 11:51:52 +0000 Subject: * initalize FetchProgress.eta as float and pass a float to InstallProgress.statusChanged() for percent --- apt/progress.py | 4 ++-- debian/changelog | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apt/progress.py b/apt/progress.py index 9958b9b7..1b437a46 100644 --- a/apt/progress.py +++ b/apt/progress.py @@ -62,7 +62,7 @@ class FetchProgress(object): dlIgnored : "Ignored"} def __init__(self): - self.eta = "" + self.eta = 0.0 self.percent = 0.0 pass @@ -180,7 +180,7 @@ class InstallProgress(DumbInstallProgress): elif status == "pmstatus": if float(percent) != self.percent or \ status_str != self.status: - self.statusChange(pkg, percent, status_str) + self.statusChange(pkg, float(percent), status_str) self.percent = float(percent) self.status = string.strip(status_str) self.read = "" diff --git a/debian/changelog b/debian/changelog index 77e5794b..aef1f70c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -python-apt (0.6.16.2) unstable; urgency=low +python-apt (0.6.16.2ubuntu1) dapper; urgency=low * apt/progress.py: - added InstallProgress.statusChange(pkg, percent, status) @@ -8,7 +8,7 @@ python-apt (0.6.16.2) unstable; urgency=low * apt/cache.py, apt/package.py: fix various pychecker warnings - -- + -- Michael Vogt Tue, 28 Feb 2006 12:04:37 +0100 python-apt (0.6.16.1) unstable; urgency=low -- cgit v1.2.3 From 6192052ee2e16c88303772c466016af6aa781ed0 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 28 Feb 2006 11:58:42 +0000 Subject: * strip status string before passing it, changelog updates --- apt/progress.py | 2 +- debian/changelog | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/apt/progress.py b/apt/progress.py index 1b437a46..4119067c 100644 --- a/apt/progress.py +++ b/apt/progress.py @@ -180,7 +180,7 @@ class InstallProgress(DumbInstallProgress): elif status == "pmstatus": if float(percent) != self.percent or \ status_str != self.status: - self.statusChange(pkg, float(percent), status_str) + self.statusChange(pkg, float(percent), status_str.strip()) self.percent = float(percent) self.status = string.strip(status_str) self.read = "" diff --git a/debian/changelog b/debian/changelog index aef1f70c..94283b9d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +python-apt (0.6.16.2ubuntu2) dapper; urgency=low + + * apt/progress.py: + - initialize FetchProgress.eta with the correct type + - strip the staus str before passing it to InstallProgress.statusChanged() + + -- + python-apt (0.6.16.2ubuntu1) dapper; urgency=low * apt/progress.py: -- cgit v1.2.3 From cc3414d9a1a42e1978834392a2bead330c19ec99 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 28 Feb 2006 13:11:50 +0000 Subject: * fix the return value of Cache.update() --- apt/cache.py | 6 +++--- debian/changelog | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/apt/cache.py b/apt/cache.py index c98c0d49..459ffc40 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -148,7 +148,6 @@ class Cache(object): # now run the fetcher, throw exception if something fails to be # fetched res = self._runFetcher(fetcher) - # cleanup os.close(lock) return res @@ -165,8 +164,9 @@ class Cache(object): self._list.GetIndexes(fetcher) # now run the fetcher, throw exception if something fails to be # fetched - res = self._runFetcher(fetcher) - return res + if self._runFetcher(fetcher) == fetcher.ResultContinue: + return True + return False def installArchives(self, pm, installProgress): installProgress.startUpdate() diff --git a/debian/changelog b/debian/changelog index 94283b9d..cc7e7e56 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,8 +3,10 @@ python-apt (0.6.16.2ubuntu2) dapper; urgency=low * apt/progress.py: - initialize FetchProgress.eta with the correct type - strip the staus str before passing it to InstallProgress.statusChanged() + * apt/cache.py: + - return useful values on Cache.update() - -- + -- Michael Vogt Tue, 28 Feb 2006 14:07:06 +0100 python-apt (0.6.16.2ubuntu1) dapper; urgency=low -- cgit v1.2.3 From 04fd391bf8f1b627f98b0aac4e4aa59c933eabe4 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 28 Feb 2006 13:18:48 +0000 Subject: * remove a useless check in Cache.update() --- apt/cache.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/apt/cache.py b/apt/cache.py index 459ffc40..9218263b 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -112,8 +112,6 @@ class Cache(object): def _runFetcher(self, fetcher): # do the actual fetching res = fetcher.Run() - if res == fetcher.ResultFailed: - return False # now check the result (this is the code from apt-get.cc) failed = False -- cgit v1.2.3 From cbcd7a454118a4633102969cdd3ff657b1b24655 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 28 Feb 2006 20:13:10 +0000 Subject: * updated changelog --- debian/changelog | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/debian/changelog b/debian/changelog index cc7e7e56..23f586d9 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,24 +1,18 @@ -python-apt (0.6.16.2ubuntu2) dapper; urgency=low +python-apt (0.6.16.2) unstable; urgency=low * apt/progress.py: - initialize FetchProgress.eta with the correct type - strip the staus str before passing it to InstallProgress.statusChanged() - * apt/cache.py: - - return useful values on Cache.update() - - -- Michael Vogt Tue, 28 Feb 2006 14:07:06 +0100 - -python-apt (0.6.16.2ubuntu1) dapper; urgency=low - - * apt/progress.py: - added InstallProgress.statusChange(pkg, percent, status) - make DumbInstallProgress a new-style class (thanks to kamion for the suggestions) - fix various pychecker warnings + * apt/cache.py: + - return useful values on Cache.update() * apt/cache.py, apt/package.py: fix various pychecker warnings - -- Michael Vogt Tue, 28 Feb 2006 12:04:37 +0100 + -- python-apt (0.6.16.1) unstable; urgency=low -- cgit v1.2.3 From eb14999105a40543ee791bfa1c22b5dcf3d6fe37 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 1 Mar 2006 14:29:21 +0000 Subject: * undo some damage from pychecker --- apt/package.py | 1 + 1 file changed, 1 insertion(+) diff --git a/apt/package.py b/apt/package.py index 9a4a90e6..4fceb904 100644 --- a/apt/package.py +++ b/apt/package.py @@ -22,6 +22,7 @@ import apt_pkg import sys import random +import string class Package(object): -- cgit v1.2.3 From 4e7cf23803ea29eb90b9c663cb6ded845067a6c7 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 21 Mar 2006 15:08:34 +0100 Subject: * fix lock-releasing on exception (thanks to kamion) --- apt/cache.py | 42 +++++++++++++++++++++++------------------- debian/changelog | 2 +- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/apt/cache.py b/apt/cache.py index 9218263b..01034cf9 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -140,31 +140,35 @@ class Cache(object): if lock < 0: raise IOError, "Failed to lock %s" % lockfile - # this may as well throw a SystemError exception - if not pm.GetArchives(fetcher, self._list, self._records): - return False - # now run the fetcher, throw exception if something fails to be - # fetched - res = self._runFetcher(fetcher) - # cleanup - os.close(lock) - return res + try: + # this may as well throw a SystemError exception + if not pm.GetArchives(fetcher, self._list, self._records): + return False + # now run the fetcher, throw exception if something fails to be + # fetched + return self._runFetcher(fetcher) + finally: + os.close(lock) def update(self, fetchProgress=None): lockfile = apt_pkg.Config.FindDir("Dir::State::Lists") + "lock" lock = apt_pkg.GetLock(lockfile) if lock < 0: raise IOError, "Failed to lock %s" % lockfile - if fetchProgress == None: - fetchProgress = apt.progress.FetchProgress() - fetcher = apt_pkg.GetAcquire(fetchProgress) - # this can throw a exception - self._list.GetIndexes(fetcher) - # now run the fetcher, throw exception if something fails to be - # fetched - if self._runFetcher(fetcher) == fetcher.ResultContinue: - return True - return False + + try: + if fetchProgress == None: + fetchProgress = apt.progress.FetchProgress() + fetcher = apt_pkg.GetAcquire(fetchProgress) + # this can throw a exception + self._list.GetIndexes(fetcher) + # now run the fetcher, throw exception if something fails to be + # fetched + if self._runFetcher(fetcher) == fetcher.ResultContinue: + return True + return False + finally: + os.close(lock) def installArchives(self, pm, installProgress): installProgress.startUpdate() diff --git a/debian/changelog b/debian/changelog index 23f586d9..e621b8d6 100644 --- a/debian/changelog +++ b/debian/changelog @@ -10,7 +10,7 @@ python-apt (0.6.16.2) unstable; urgency=low * apt/cache.py: - return useful values on Cache.update() * apt/cache.py, apt/package.py: fix various pychecker warnings - + * apt/cache.py: Release locks on failure (thanks to Colin Watson) -- -- cgit v1.2.3 From e02913b6f336d4bf5bc2c17032c91ade974de04f Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 22 Mar 2006 14:56:29 +0100 Subject: * fixes for the pkgSrcRecords code --- debian/changelog | 8 ++++++-- doc/examples/build-deps.py | 2 +- doc/examples/sources.py | 6 ++++++ python/pkgrecords.cc | 2 +- python/pkgsrcrecords.cc | 27 ++++++++++++++++++++++++--- tests/pkgsrcrecords.py | 2 +- 6 files changed, 39 insertions(+), 8 deletions(-) diff --git a/debian/changelog b/debian/changelog index e621b8d6..4b677c2e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -11,8 +11,12 @@ python-apt (0.6.16.2) unstable; urgency=low - return useful values on Cache.update() * apt/cache.py, apt/package.py: fix various pychecker warnings * apt/cache.py: Release locks on failure (thanks to Colin Watson) - - -- + * python/srcrecords.cc: + - add "Restart" method + - don't run auto "Restart" before performing a Lookup + - fix the initalization (no need to pass a PkgCacheType to the records) + + -- Michael Vogt Wed, 22 Mar 2006 11:19:34 +0100 python-apt (0.6.16.1) unstable; urgency=low diff --git a/doc/examples/build-deps.py b/doc/examples/build-deps.py index b580f5de..65e35f3d 100755 --- a/doc/examples/build-deps.py +++ b/doc/examples/build-deps.py @@ -24,7 +24,7 @@ cache = apt_pkg.GetCache() depcache = apt_pkg.GetDepCache(cache) depcache.Init() records = apt_pkg.GetPkgRecords(cache) -srcrecords = apt_pkg.GetPkgSrcRecords(cache) +srcrecords = apt_pkg.GetPkgSrcRecords() # base package that we use for build-depends calculation if len(sys.argv) < 2: diff --git a/doc/examples/sources.py b/doc/examples/sources.py index 79514621..0a90bae9 100644 --- a/doc/examples/sources.py +++ b/doc/examples/sources.py @@ -4,6 +4,12 @@ import apt_pkg apt_pkg.init() +#cache = apt_pkg.GetCache() +#sources = apt_pkg.GetPkgSrcRecords(cache) + sources = apt_pkg.GetPkgSrcRecords() +sources.Restart() while sources.Lookup('hello'): print sources.Package, sources.Version, sources.Maintainer, sources.Section, `sources.Binaries` + #print sources.Files + diff --git a/python/pkgrecords.cc b/python/pkgrecords.cc index c6f5aeb9..ec78f554 100644 --- a/python/pkgrecords.cc +++ b/python/pkgrecords.cc @@ -46,7 +46,7 @@ static PyObject *PkgRecordsLookup(PyObject *Self,PyObject *Args) // always return true (to make it consistent with the pkgsrcrecords object return Py_BuildValue("i", 1); } - + static PyMethodDef PkgRecordsMethods[] = { {"Lookup",PkgRecordsLookup,METH_VARARGS,"Changes to a new package"}, diff --git a/python/pkgsrcrecords.cc b/python/pkgsrcrecords.cc index 252810c7..abb29c74 100644 --- a/python/pkgsrcrecords.cc +++ b/python/pkgsrcrecords.cc @@ -43,7 +43,6 @@ static PyObject *PkgSrcRecordsLookup(PyObject *Self,PyObject *Args) if (PyArg_ParseTuple(Args,"s",&Name) == 0) return 0; - Struct.Records->Restart(); Struct.Last = Struct.Records->Find(Name, false); if (Struct.Last == 0) { Struct.Records->Restart(); @@ -54,9 +53,25 @@ static PyObject *PkgSrcRecordsLookup(PyObject *Self,PyObject *Args) return Py_BuildValue("i", 1); } +static char *doc_PkgSrcRecordsRestart = "Start Lookup from the begining"; +static PyObject *PkgSrcRecordsRestart(PyObject *Self,PyObject *Args) +{ + PkgSrcRecordsStruct &Struct = GetCpp(Self); + + char *Name = 0; + if (PyArg_ParseTuple(Args,"") == 0) + return 0; + + Struct.Records->Restart(); + + Py_INCREF(Py_None); + return HandleErrors(Py_None); +} + static PyMethodDef PkgSrcRecordsMethods[] = { {"Lookup",PkgSrcRecordsLookup,METH_VARARGS,doc_PkgSrcRecordsLookup}, + {"Restart",PkgSrcRecordsRestart,METH_VARARGS,doc_PkgSrcRecordsRestart}, {} }; @@ -126,10 +141,10 @@ PyTypeObject PkgSrcRecordsType = PyObject_HEAD_INIT(&PyType_Type) 0, // ob_size "pkgSrcRecords", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppDealloc, // tp_dealloc 0, // tp_print PkgSrcRecordsAttr, // tp_getattr 0, // tp_setattr @@ -145,11 +160,17 @@ PyTypeObject PkgSrcRecordsType = PyObject *GetPkgSrcRecords(PyObject *Self,PyObject *Args) { +#if 0 PyObject *Owner; if (PyArg_ParseTuple(Args,"O!",&PkgCacheType,&Owner) == 0) return 0; return HandleErrors(CppOwnedPyObject_NEW(Owner, &PkgSrcRecordsType)); +#endif + if (PyArg_ParseTuple(Args,"") == 0) + return 0; + + return HandleErrors(CppPyObject_NEW(&PkgSrcRecordsType)); } diff --git a/tests/pkgsrcrecords.py b/tests/pkgsrcrecords.py index dc4881dd..28df3f7c 100644 --- a/tests/pkgsrcrecords.py +++ b/tests/pkgsrcrecords.py @@ -14,7 +14,7 @@ def main(): print "Running PkgSrcRecords test on all packages:" for x in cache.Packages: i += 1 - src = apt_pkg.GetPkgSrcRecords(cache) + src = apt_pkg.GetPkgSrcRecords() if src.Lookup(x.Name): #print src.Package pass -- cgit v1.2.3 From eef094d6218739bc0147910bfdd478ac10f18ec1 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 22 Mar 2006 15:07:21 +0100 Subject: * added indexFile.ArchiveURI(string) --- doc/examples/indexfile.py | 1 + python/indexfile.cc | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/doc/examples/indexfile.py b/doc/examples/indexfile.py index 5eaab517..d383fd61 100644 --- a/doc/examples/indexfile.py +++ b/doc/examples/indexfile.py @@ -18,3 +18,4 @@ for (f,i) in cand.FileList: print index.IsTrusted print index.Exists print index.HasPackages + print index.ArchiveURI("some/path") diff --git a/python/indexfile.cc b/python/indexfile.cc index 4e106e25..ef6ffc8a 100644 --- a/python/indexfile.cc +++ b/python/indexfile.cc @@ -15,6 +15,22 @@ #include +static PyObject *PackageIndexFileArchiveURI(PyObject *Self,PyObject *Args) +{ + pkgIndexFile *File = GetCpp(Self); + char *path; + + if (PyArg_ParseTuple(Args, "s",&path) == 0) + return 0; + + return HandleErrors(Safe_FromString(File->ArchiveURI(path).c_str())); +} + +static PyMethodDef PackageIndexFileMethods[] = +{ + {"ArchiveURI",PackageIndexFileArchiveURI,METH_VARARGS,"Returns the ArchiveURI"}, + {} +}; static PyObject *PackageIndexFileAttr(PyObject *Self,char *Name) @@ -33,8 +49,7 @@ static PyObject *PackageIndexFileAttr(PyObject *Self,char *Name) else if (strcmp("IsTrusted",Name) == 0) return Py_BuildValue("i",(File->IsTrusted())); - PyErr_SetString(PyExc_AttributeError,Name); - return 0; + return Py_FindMethod(PackageIndexFileMethods,Self,Name); } static PyObject *PackageIndexFileRepr(PyObject *Self) @@ -51,6 +66,7 @@ static PyObject *PackageIndexFileRepr(PyObject *Self) File->IsTrusted(), File->ArchiveURI("").c_str()); return PyString_FromString(S); } + PyTypeObject PackageIndexFileType = { PyObject_HEAD_INIT(&PyType_Type) -- cgit v1.2.3 From 4399788cb0202968a7fe5098050cec8a851bd58f Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 22 Mar 2006 15:23:18 +0100 Subject: * add PkgSrcRecords.Index to the code --- doc/examples/sources.py | 2 +- python/pkgsrcrecords.cc | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/examples/sources.py b/doc/examples/sources.py index 0a90bae9..78913523 100644 --- a/doc/examples/sources.py +++ b/doc/examples/sources.py @@ -12,4 +12,4 @@ sources.Restart() while sources.Lookup('hello'): print sources.Package, sources.Version, sources.Maintainer, sources.Section, `sources.Binaries` #print sources.Files - + print sources.Index.ArchiveURI("") diff --git a/python/pkgsrcrecords.cc b/python/pkgsrcrecords.cc index abb29c74..5e04f5fc 100644 --- a/python/pkgsrcrecords.cc +++ b/python/pkgsrcrecords.cc @@ -96,8 +96,10 @@ static PyObject *PkgSrcRecordsAttr(PyObject *Self,char *Name) *b != 0; ++b) PyList_Append(List, CppPyString(*b)); - return List; // todo + } else if (strcmp("Index",Name) == 0) { + const pkgIndexFile &tmp = Struct.Last->Index(); + return CppOwnedPyObject_NEW(Self,&PackageIndexFileType, (pkgIndexFile*)&tmp); } else if (strcmp("Files",Name) == 0) { PyObject *List = PyList_New(0); -- cgit v1.2.3 From de94cc6cd97201a9cd3fc845b06b97e46251403d Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 22 Mar 2006 15:25:48 +0100 Subject: * updated changelog --- debian/changelog | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 4b677c2e..976e078f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -15,8 +15,11 @@ python-apt (0.6.16.2) unstable; urgency=low - add "Restart" method - don't run auto "Restart" before performing a Lookup - fix the initalization (no need to pass a PkgCacheType to the records) + - added "Index" attribute + * python/indexfile.cc: + - added ArchiveURI() method - -- Michael Vogt Wed, 22 Mar 2006 11:19:34 +0100 + -- python-apt (0.6.16.1) unstable; urgency=low -- cgit v1.2.3 From 8cc9bc319a5ed5237e4c4a40da241ee1159d9233 Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Tue, 28 Mar 2006 08:31:14 -0300 Subject: Fix documentation format. --- python/tar.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/tar.cc b/python/tar.cc index 20fb1f5f..22c0327e 100644 --- a/python/tar.cc +++ b/python/tar.cc @@ -88,7 +88,7 @@ bool ProcessTar::DoItem(Item &Itm,int &Fd) // --------------------------------------------------------------------- /* */ char *doc_tarExtract = -"tarExtract(File,Func,Comp) -> None" +"tarExtract(File,Func,Comp) -> None\n" "The tar file referenced by the file object File, Func called for each\n" "Tar member. Comp must be the string \"gzip\" (gzip is automatically invoked) \n"; PyObject *tarExtract(PyObject *Self,PyObject *Args) @@ -128,7 +128,7 @@ PyObject *tarExtract(PyObject *Self,PyObject *Args) // --------------------------------------------------------------------- /* */ char *doc_debExtract = -"debExtract(File,Func,Chunk) -> None" +"debExtract(File,Func,Chunk) -> None\n" "The deb referenced by the file object File is examined. The AR member\n" "given by Chunk is treated as a tar.gz and fed through Func like\n" "tarExtract\n"; -- cgit v1.2.3 From 1f1cc6179cd9c7f15231a4d082fdbf374ad7cace Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 26 Apr 2006 09:42:54 +0200 Subject: * added a simple "all_deps" recursive example --- doc/examples/all_deps.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 doc/examples/all_deps.py diff --git a/doc/examples/all_deps.py b/doc/examples/all_deps.py new file mode 100644 index 00000000..f4f1741c --- /dev/null +++ b/doc/examples/all_deps.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python + +import sys +import apt + + +def dependencies(cache, pkg, deps, key="Depends"): + #print "pkg: %s (%s)" % (pkg.name, deps) + candver = cache._depcache.GetCandidateVer(pkg._pkg) + if candver == None: + return deps + dependslist = candver.DependsList + if dependslist.has_key(key): + for depVerList in dependslist[key]: + for dep in depVerList: + if cache.has_key(dep.TargetPkg.Name): + if pkg.name != dep.TargetPkg.Name and not dep.TargetPkg.Name in deps: + deps.add(dep.TargetPkg.Name) + dependencies(cache, cache[dep.TargetPkg.Name], deps, key) + return deps + + +pkgname = sys.argv[1] +c = apt.Cache() +pkg = c[pkgname] + +deps = set() + +deps = dependencies(c,pkg, deps, "Depends") +print " ".join(deps) + +preDeps = set() +preDeps = dependencies(c,pkg, preDeps, "PreDepends") +print " ".join(preDeps) -- cgit v1.2.3 From 0e8fd33b1b741cc65c284a08faa50b3a2995ac3c Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 26 Apr 2006 10:17:09 +0200 Subject: * debian/compat: - debhelper compat level set to 5 * debian/changelog: - merged the changelog from the NMU * debian/control: - merged the changes from the NMU - set standards version to 3.6.2.0 * debian/rules: - fix arch-build target * setup.py: - simplify the patch magling by using map() instead of "for i in range()" --- debian/changelog | 13 +++++++++++-- debian/compat | 1 + debian/control | 8 ++++---- debian/rules | 5 +---- setup.py | 18 +++++++----------- 5 files changed, 24 insertions(+), 21 deletions(-) create mode 100644 debian/compat diff --git a/debian/changelog b/debian/changelog index 976e078f..e1dfd27a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -python-apt (0.6.16.2) unstable; urgency=low +python-apt (0.6.17) unstable; urgency=low * apt/progress.py: - initialize FetchProgress.eta with the correct type @@ -19,8 +19,17 @@ python-apt (0.6.16.2) unstable; urgency=low * python/indexfile.cc: - added ArchiveURI() method - -- + -- +python-apt (0.6.16.2) unstable; urgency=low + + * Non-maintainer upload. + * debian/control: + + Replaces: python-apt (<< 0.6.11), instead of Conflicts which is not + correct here. (closes: #308586). + + -- Pierre Habouzit Fri, 14 Apr 2006 19:30:51 +0200 + python-apt (0.6.16.1) unstable; urgency=low * memleak fixed when pkgCache objects are deallocated diff --git a/debian/compat b/debian/compat new file mode 100644 index 00000000..7813681f --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +5 \ No newline at end of file diff --git a/debian/control b/debian/control index bfa67c67..6966077f 100644 --- a/debian/control +++ b/debian/control @@ -3,8 +3,8 @@ Section: python Priority: optional Maintainer: APT Development Team Uploaders: Matt Zimmerman , Michael Vogt -Standards-Version: 3.6.1.1 -Build-Depends: debhelper (>= 4.2.28), libapt-pkg-dev (>= 0.6.40), apt-utils, python-dev, python2.4-dev, python2.3-dev +Standards-Version: 3.6.2.0 +Build-Depends: debhelper (>= 5.0), libapt-pkg-dev (>= 0.6.40), apt-utils, python-dev, python2.4-dev, python2.3-dev Package: python-apt Architecture: all @@ -23,7 +23,7 @@ Description: Python interface to libapt-pkg Package: python2.3-apt Architecture: any Depends: python2.3, ${shlibs:Depends} -Conflicts: python-apt (<< 0.6.11) +Replaces: python-apt (<< 0.6.11) Priority: optional Description: Python interface to libapt-pkg The apt-pkg Python interface will provide full access to the internal @@ -38,7 +38,7 @@ Description: Python interface to libapt-pkg Package: python2.4-apt Architecture: any Depends: python2.4, ${shlibs:Depends} -Conflicts: python-apt (<< 0.6.11) +Replaces: python-apt (<< 0.6.11) Priority: optional Description: Python interface to libapt-pkg The apt-pkg Python interface will provide full access to the internal diff --git a/debian/rules b/debian/rules index 0ab6fa27..584abdf5 100755 --- a/debian/rules +++ b/debian/rules @@ -6,9 +6,6 @@ # This has to be exported to make some magic below work. export DH_OPTIONS -# This is the debhelper compatibility version to use. -export DH_COMPAT=3 - 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) @@ -83,7 +80,7 @@ source diff: 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) + tar -c --exclude=arch-build --no-recursion -f - `bzr inventory` | (cd debian/arch-build/python-apt-$(DEBVER);tar xf -) (cd debian/arch-build/python-apt-$(DEBVER); $(DEB_BUILD_PROG)) binary: binary-indep binary-arch diff --git a/setup.py b/setup.py index f9255607..5adb0376 100644 --- a/setup.py +++ b/setup.py @@ -7,22 +7,18 @@ import string, glob # The apt_pkg module -files = string.split(parse_makefile("python/makefile")["APT_PKG_SRC"]); -for i in range(0,len(files)): - files[i] = "python/"+ files[i]; -apt_pkg = Extension("apt_pkg", files, - libraries=["apt-pkg"]); +files = map(lambda source: "python/"+source, + string.split(parse_makefile("python/makefile")["APT_PKG_SRC"])) +apt_pkg = Extension("apt_pkg", files, libraries=["apt-pkg"]); # The apt_inst module -files = string.split(parse_makefile("python/makefile")["APT_INST_SRC"]); -for i in range(0,len(files)): - files[i] = "python/"+ files[i]; -apt_inst = Extension("apt_inst", files, - libraries=["apt-pkg","apt-inst"]); +files = map(lambda source: "python/"+source, + string.split(parse_makefile("python/makefile")["APT_INST_SRC"])) +apt_inst = Extension("apt_inst", files, libraries=["apt-pkg","apt-inst"]); setup(name="python-apt", - version="0.6.13", + version="0.6.17", description="Python bindings for APT", author="APT Development Team", author_email="deity@lists.debian.org", -- cgit v1.2.3 From 0a6e7dc1aac196e640bda1160c9561a398d76044 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 17 May 2006 18:11:55 +0200 Subject: * apt/package.py: - check if _lookupRecords() succeeded when checking description/maintainer --- apt/package.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/apt/package.py b/apt/package.py index 4fceb904..55e1cd01 100644 --- a/apt/package.py +++ b/apt/package.py @@ -49,7 +49,7 @@ class Package(object): # check if we found a version if ver == None: - #print "No version for: %s (Candidate: %s)" % (self._pkg.Name, UseCandidate) + print "No version for: %s (Candidate: %s)" % (self._pkg.Name, UseCandidate) return False if ver.FileList == None: @@ -149,13 +149,15 @@ class Package(object): def summary(self): """ Return the short description (one line summary) """ - self._lookupRecord() + if not self._lookupRecord(): + return "" return self._records.ShortDesc summary = property(summary) def description(self, format=True): """ Return the formated long description """ - self._lookupRecord() + if not self._lookupRecord(): + return "" desc = "" for line in string.split(self._records.LongDesc, "\n"): tmp = string.strip(line) @@ -168,7 +170,8 @@ class Package(object): def rawDescription(self): """ return the long description (raw)""" - self._lookupRecord() + if not self._lookupRecord(): + return "" return self._records.LongDesc rawDescription = property(rawDescription) -- cgit v1.2.3 From 9835bc4332eba7c3a7ab27290cf103d10a8d090f Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 17 May 2006 18:12:04 +0200 Subject: * changelog updates --- debian/changelog | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index e1dfd27a..896e4a0d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -9,8 +9,12 @@ python-apt (0.6.17) unstable; urgency=low - fix various pychecker warnings * apt/cache.py: - return useful values on Cache.update() - * apt/cache.py, apt/package.py: fix various pychecker warnings - * apt/cache.py: Release locks on failure (thanks to Colin Watson) + - Release locks on failure (thanks to Colin Watson) + - fix various pychecker warnings + * apt/package.py: + - fix various pychecker warnings + - check if looupRecords succeeded + * apt/cache.py: * python/srcrecords.cc: - add "Restart" method - don't run auto "Restart" before performing a Lookup -- cgit v1.2.3 From 5042fb1f6160381c18a4add7076e8da175cba2d0 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 17 May 2006 18:14:20 +0200 Subject: * remove debug string --- apt/package.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apt/package.py b/apt/package.py index 55e1cd01..53f6c1f5 100644 --- a/apt/package.py +++ b/apt/package.py @@ -49,7 +49,7 @@ class Package(object): # check if we found a version if ver == None: - print "No version for: %s (Candidate: %s)" % (self._pkg.Name, UseCandidate) + #print "No version for: %s (Candidate: %s)" % (self._pkg.Name, UseCandidate) return False if ver.FileList == None: -- cgit v1.2.3 From 52ae9a181314398e4dc4996d1409e99b9bdbbf7e Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 17 May 2006 18:41:09 +0200 Subject: * apt/package.py: - actually return values in {candiate,installed}Downloadable() --- apt/package.py | 4 ++-- debian/changelog | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/apt/package.py b/apt/package.py index 53f6c1f5..7297a1bb 100644 --- a/apt/package.py +++ b/apt/package.py @@ -105,12 +105,12 @@ class Package(object): return ver.Downloadable def candidateDownloadable(self): " returns if the canidate is downloadable " - self._downloadable(useCandidate=True) + return self._downloadable(useCandidate=True) candidateDownloadable = property(candidateDownloadable) def installedDownloadable(self): " returns if the installed version is downloadable " - self._downloadable(useCandidate=False) + return self._downloadable(useCandidate=False) installedDownloadable = property(installedDownloadable) def sourcePackageName(self): diff --git a/debian/changelog b/debian/changelog index 896e4a0d..5eac06d1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -14,6 +14,7 @@ python-apt (0.6.17) unstable; urgency=low * apt/package.py: - fix various pychecker warnings - check if looupRecords succeeded + - fix bug in the return statement of _downloadable() * apt/cache.py: * python/srcrecords.cc: - add "Restart" method -- cgit v1.2.3 From 0bb531dbcf27b40861467b831b120fc8b257e8ff Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 9 Jun 2006 17:38:18 +0200 Subject: * changelog updated * prints_uris.py example added --- debian/changelog | 10 +++++++++- doc/examples/print_uris.py | 22 ++++++++++++++++++++++ doc/examples/sources.py | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100755 doc/examples/print_uris.py diff --git a/debian/changelog b/debian/changelog index 5eac06d1..a1a9858e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +python-apt (0.6.18) unstable; urgency=low + + * doc/examples/print_uris.py: + - added a example to show how the indexfile.ArchiveURI() can be used + with binary packages + + -- + python-apt (0.6.17) unstable; urgency=low * apt/progress.py: @@ -24,7 +32,7 @@ python-apt (0.6.17) unstable; urgency=low * python/indexfile.cc: - added ArchiveURI() method - -- + -- Michael Vogt Mon, 8 May 2006 22:34:58 +0200 python-apt (0.6.16.2) unstable; urgency=low diff --git a/doc/examples/print_uris.py b/doc/examples/print_uris.py new file mode 100755 index 00000000..c8a64223 --- /dev/null +++ b/doc/examples/print_uris.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +# +# a example that prints the URIs of all upgradable packages +# + +import apt +import apt_pkg + + +cache = apt.Cache() +upgradable = filter(lambda p: p.isUpgradable, cache) + + +for pkg in upgradable: + pkg._lookupRecord(True) + path = apt_pkg.ParseSection(pkg._records.Record)["Filename"] + cand = pkg._depcache.GetCandidateVer(pkg._pkg) + for (packagefile,i) in cand.FileList: + indexfile = cache._list.FindIndex(packagefile) + if indexfile: + uri = indexfile.ArchiveURI(path) + print uri diff --git a/doc/examples/sources.py b/doc/examples/sources.py index 78913523..c12c6f15 100644 --- a/doc/examples/sources.py +++ b/doc/examples/sources.py @@ -11,5 +11,5 @@ sources = apt_pkg.GetPkgSrcRecords() sources.Restart() while sources.Lookup('hello'): print sources.Package, sources.Version, sources.Maintainer, sources.Section, `sources.Binaries` - #print sources.Files + print sources.Files print sources.Index.ArchiveURI("") -- cgit v1.2.3 From 22e59d0dc92c45ea63d75d73474b5be610e57a58 Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Mon, 12 Jun 2006 18:48:16 -0300 Subject: * apt/cache.py: - fix commit doc string to also cite the open related callbacks --- apt/cache.py | 2 +- debian/changelog | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/apt/cache.py b/apt/cache.py index 01034cf9..8410fc56 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -218,7 +218,7 @@ class Cache(object): def connect(self, name, callback): """ connect to a signal, currently only used for - cache_{post,pre}_changed """ + cache_{post,pre}_{changed,open} """ if not self._callbacks.has_key(name): self._callbacks[name] = [] self._callbacks[name].append(callback) diff --git a/debian/changelog b/debian/changelog index a1a9858e..ff62eac6 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,9 +1,14 @@ python-apt (0.6.18) unstable; urgency=low + [ Michael Vogt ] * doc/examples/print_uris.py: - added a example to show how the indexfile.ArchiveURI() can be used with binary packages + [ Otavio Salvador ] + * apt/cache.py: + - fix commit doc string to also cite the open related callbacks + -- python-apt (0.6.17) unstable; urgency=low -- cgit v1.2.3 From 473031d5c8273643592d2f269fd532afb560303c Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Wed, 14 Jun 2006 00:31:49 -0300 Subject: - allow change of rootdir for APT database loading --- apt/cache.py | 6 +++++- debian/changelog | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/apt/cache.py b/apt/cache.py index 8410fc56..690510e3 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -31,10 +31,14 @@ class Cache(object): dictionary """ - def __init__(self, progress=None): + def __init__(self, progress=None, rootdir=None): self._callbacks = {} self.open(progress) + if rootdir: + apt_pkg.Config.Set("Dir", rootdir) + apt_pkg.Config.Set("Dir::State::status", rootdir + "/var/lib/dpkg/status") + def _runCallbacks(self, name): """ internal helper to run a callback """ if self._callbacks.has_key(name): diff --git a/debian/changelog b/debian/changelog index ff62eac6..287605e0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -8,6 +8,7 @@ python-apt (0.6.18) unstable; urgency=low [ Otavio Salvador ] * apt/cache.py: - fix commit doc string to also cite the open related callbacks + - allow change of rootdir for APT database loading -- -- cgit v1.2.3 From 3b12e19d8a19ae319646cc2a97c36e92cf65a1d5 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 15 Jun 2006 08:59:04 +0200 Subject: * apt/packages.py: - add autoInst option --- apt/package.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/apt/package.py b/apt/package.py index 7297a1bb..0d1145ea 100644 --- a/apt/package.py +++ b/apt/package.py @@ -290,10 +290,12 @@ class Package(object): Fix.InstallProtect() Fix.Resolve() self._pcache.cachePostChange() - def markInstall(self, autoFix=True): - """ mark a package for install. Run the resolver if autoFix is set """ + def markInstall(self, autoFix=True, autoInst=True): + """ mark a package for install. Run the resolver if autoFix is set, + automatically install required dependencies if autoInst is set + """ self._pcache.cachePreChange() - self._depcache.MarkInstall(self._pkg) + self._depcache.MarkInstall(self._pkg, autoInst) # try to fix broken stuff if autoFix and self._depcache.BrokenCount > 0: fixer = apt_pkg.GetPkgProblemResolver(self._depcache) -- cgit v1.2.3 From 76fb1f457228cc5efa5f45a7a875ec5bc0e17b3a Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 26 Jun 2006 06:08:07 +0200 Subject: * merging the NMU changes --- debian/changelog | 9 ++++++++- debian/control | 39 +++++++-------------------------------- debian/rules | 21 +++++---------------- 3 files changed, 20 insertions(+), 49 deletions(-) diff --git a/debian/changelog b/debian/changelog index 287605e0..d9b428bd 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -python-apt (0.6.18) unstable; urgency=low +python-apt (0.6.19) unstable; urgency=low [ Michael Vogt ] * doc/examples/print_uris.py: @@ -12,6 +12,13 @@ python-apt (0.6.18) unstable; urgency=low -- +python-apt (0.6.18) unstable; urgency=low + + * Non-maintainer upload. + * Update for the new Python policy. Closes: #373512 + + -- Raphael Hertzog Sat, 17 Jun 2006 15:09:28 +0200 + python-apt (0.6.17) unstable; urgency=low * apt/progress.py: diff --git a/debian/control b/debian/control index 6966077f..f313dff5 100644 --- a/debian/control +++ b/debian/control @@ -4,42 +4,17 @@ Priority: optional Maintainer: APT Development Team Uploaders: Matt Zimmerman , Michael Vogt Standards-Version: 3.6.2.0 -Build-Depends: debhelper (>= 5.0), libapt-pkg-dev (>= 0.6.40), apt-utils, python-dev, python2.4-dev, python2.3-dev +XS-Python-Version: all +Build-Depends: debhelper (>= 5.0.37.1), libapt-pkg-dev (>= 0.6.40), apt-utils, python-all-dev, python-central Package: python-apt -Architecture: all -Depends: ${python: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 - -Package: python2.3-apt Architecture: any -Depends: python2.3, ${shlibs:Depends} -Replaces: python-apt (<< 0.6.11) -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 - -Package: python2.4-apt -Architecture: any -Depends: python2.4, ${shlibs:Depends} -Replaces: python-apt (<< 0.6.11) +Depends: ${python:Depends} Priority: optional +Replaces: python2.3-apt (<< 0.6.18), python2.4-apt (<< 0.6.18) +Conflicts: python2.3-apt (<< 0.6.18), python2.4-apt (<< 0.6.18) +Provides: ${python:Provides} +XB-Python-Version: ${python:Versions} 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 diff --git a/debian/rules b/debian/rules index 584abdf5..ffd39a6f 100755 --- a/debian/rules +++ b/debian/rules @@ -12,7 +12,7 @@ DEB_BUILD_PROG:=debuild --preserve-envvar PATH --preserve-envvar CCACHE_DIR -us # Uncomment this to turn on verbose mode. #export DH_VERBOSE=1 -PYTHON=python2.3 python2.4 +PYTHON=$(shell pyversions -r debian/control) build: build-stamp build-stamp: @@ -38,18 +38,6 @@ clean: # Build architecture-independent files here. binary-indep: DH_OPTIONS=-i binary-indep: build - dh_testdir - dh_testroot - dh_installdocs - dh_installexamples doc/examples/*.py - dh_installchangelogs - dh_compress - dh_fixperms - dh_installdeb - dh_python - dh_gencontrol - dh_md5sums - dh_builddeb # Build architecture-dependent files here. binary-arch: DH_OPTIONS=-a @@ -57,11 +45,11 @@ binary-arch: build dh_testdir dh_testroot dh_clean -k - + for PY in $(PYTHON); do \ - /usr/bin/$$PY setup.py install --prefix=`pwd`/debian/$${PY}-apt/usr; \ + /usr/bin/$$PY setup.py install --prefix=`pwd`/debian/python-apt/usr; \ done - + dh_installdocs dh_installchangelogs dh_strip @@ -69,6 +57,7 @@ binary-arch: build dh_fixperms dh_installdeb dh_shlibdeps + dh_pycentral dh_python dh_gencontrol dh_md5sums -- cgit v1.2.3 From 6fc084d34105f336fdf090e2dd45e402e25cfc57 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 26 Jun 2006 10:11:25 +0200 Subject: * python/depcache.cc: - added "DepCache.IsGarbage" flag --- python/depcache.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/python/depcache.cc b/python/depcache.cc index e8140e2b..60bbc1a4 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -370,6 +370,20 @@ static PyObject *PkgDepCacheIsUpgradable(PyObject *Self,PyObject *Args) return HandleErrors(Py_BuildValue("b",state.Upgradable())); } +static PyObject *PkgDepCacheIsGarbage(PyObject *Self,PyObject *Args) +{ + pkgDepCache *depcache = GetCpp(Self); + + PyObject *PackageObj; + if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + return 0; + + pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); + pkgDepCache::StateCache &state = (*depcache)[Pkg]; + + return HandleErrors(Py_BuildValue("b",state.Garbage)); +} + static PyObject *PkgDepCacheIsNowBroken(PyObject *Self,PyObject *Args) { pkgDepCache *depcache = GetCpp(Self); @@ -507,6 +521,7 @@ static PyMethodDef PkgDepCacheMethods[] = {"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"}, + {"IsGarbage",PkgDepCacheIsGarbage,METH_VARARGS,"Is pkg garbage (mark-n-sweep)"}, {"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"}, -- cgit v1.2.3