From 9d88586c37e9a5702949f90fc589ef941d57f661 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 28 Aug 2007 14:54:36 +0200 Subject: * python/string.cc: - fix overflow in SizeToStr() --- python/string.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python') diff --git a/python/string.cc b/python/string.cc index d0926da5..1fa5a901 100644 --- a/python/string.cc +++ b/python/string.cc @@ -55,7 +55,7 @@ PyObject *StrSizeToStr(PyObject *Self,PyObject *Args) if (PyInt_Check(Obj)) return CppPyString(SizeToStr(PyInt_AsLong(Obj))); if (PyLong_Check(Obj)) - return CppPyString(SizeToStr(PyLong_AsLong(Obj))); + return CppPyString(SizeToStr(PyLong_AsDouble(Obj))); if (PyFloat_Check(Obj)) return CppPyString(SizeToStr(PyFloat_AsDouble(Obj))); -- cgit v1.2.3 From 8ad58480ce8a161519339b41eacefc26059bebf7 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 4 Sep 2007 16:28:25 +0200 Subject: * python/metaindex.cc: - added support for the metaIndex objects * python/sourceslist.cc: - support new "List" attribute that returns the list of metaIndex source entries --- debian/changelog | 5 +++ doc/examples/metaindex.py | 15 +++++++++ python/apt_pkgmodule.h | 3 ++ python/makefile | 2 +- python/metaindex.cc | 78 +++++++++++++++++++++++++++++++++++++++++++++++ python/sourcelist.cc | 16 +++++++++- 6 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 doc/examples/metaindex.py create mode 100644 python/metaindex.cc (limited to 'python') diff --git a/debian/changelog b/debian/changelog index 24d8baa5..2d6784ae 100644 --- a/debian/changelog +++ b/debian/changelog @@ -10,6 +10,11 @@ python-apt (0.7.4) UNRELEASED; urgency=low can be found * python/string.cc: - fix overflow in SizeToStr() + * python/metaindex.cc: + - added support for the metaIndex objects + * python/sourceslist.cc: + - support new "List" attribute that returns the list of + metaIndex source entries -- Michael Vogt Mon, 30 Jul 2007 22:33:59 +0200 diff --git a/doc/examples/metaindex.py b/doc/examples/metaindex.py new file mode 100644 index 00000000..1bce0dba --- /dev/null +++ b/doc/examples/metaindex.py @@ -0,0 +1,15 @@ + +import apt_pkg + +apt_pkg.init() + +sources = apt_pkg.GetPkgSourceList() +sources.ReadMainList() + + +for metaindex in sources.List: + print metaindex + print "URI: ",metaindex.URI + print "Dist: ",metaindex.Dist + print "IndexFiles: ","\n".join([str(i) for i in metaindex.IndexFiles]) + print diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index d58f4589..f59c8ca0 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -95,5 +95,8 @@ PyObject *GetPkgSourceList(PyObject *Self,PyObject *Args); // pkgSourceList extern PyTypeObject PackageIndexFileType; +// metaIndex +extern PyTypeObject MetaIndexType; + #endif diff --git a/python/makefile b/python/makefile index 24ef3238..e0c62541 100644 --- a/python/makefile +++ b/python/makefile @@ -12,7 +12,7 @@ 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 \ - indexfile.cc + indexfile.cc metaindex.cc SOURCE := $(APT_PKG_SRC) include $(PYTHON_H) progress.h diff --git a/python/metaindex.cc b/python/metaindex.cc new file mode 100644 index 00000000..c9a86ab4 --- /dev/null +++ b/python/metaindex.cc @@ -0,0 +1,78 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +// $Id: metaindex.cc,v 1.2 2003/12/26 17:04:22 mdz Exp $ +/* ###################################################################### + + metaindex - Wrapper for the metaIndex functions + + ##################################################################### */ + /*}}}*/ +// Include Files /*{{{*/ +#include "generic.h" +#include "apt_pkgmodule.h" + +#include + +#include + + +static PyObject *MetaIndexAttr(PyObject *Self,char *Name) +{ + metaIndex *meta = GetCpp(Self); + if (strcmp("URI",Name) == 0) + return Safe_FromString(meta->GetURI().c_str()); + else if (strcmp("Dist",Name) == 0) + return Safe_FromString(meta->GetDist().c_str()); + else if (strcmp("IsTrusted",Name) == 0) + return Py_BuildValue("i",(meta->IsTrusted())); + else if (strcmp("IndexFiles",Name) == 0) + { + PyObject *List = PyList_New(0); + vector *indexFiles = meta->GetIndexFiles(); + for (vector::const_iterator I = indexFiles->begin(); + I != indexFiles->end(); I++) + { + PyObject *Obj; + Obj = CppPyObject_NEW(&PackageIndexFileType,*I); + PyList_Append(List,Obj); + } + return List; + } +} + +static PyObject *MetaIndexRepr(PyObject *Self) +{ + metaIndex *meta = GetCpp(Self); + + char S[1024]; + snprintf(S,sizeof(S),"", + meta->GetType(), meta->GetURI().c_str(), meta->GetDist().c_str(), + meta->IsTrusted()); + + return PyString_FromString(S); +} + +PyTypeObject MetaIndexType = +{ + PyObject_HEAD_INIT(&PyType_Type) + 0, // ob_size + "metaIndex", // tp_name + sizeof(CppOwnedPyObject), // tp_basicsize + 0, // tp_itemsize + // Methods + CppOwnedDealloc, // tp_dealloc + 0, // tp_print + MetaIndexAttr, // tp_getattr + 0, // tp_setattr + 0, // tp_compare + MetaIndexRepr, // tp_repr + 0, // tp_as_number + 0, // tp_as_sequence + 0, // tp_as_mapping + 0, // tp_hash +}; + + + + diff --git a/python/sourcelist.cc b/python/sourcelist.cc index 16e51368..68b764f8 100644 --- a/python/sourcelist.cc +++ b/python/sourcelist.cc @@ -80,7 +80,21 @@ static PyMethodDef PkgSourceListMethods[] = static PyObject *PkgSourceListAttr(PyObject *Self,char *Name) { - return Py_FindMethod(PkgSourceListMethods,Self,Name); + pkgSourceList *list = GetCpp(Self); + + if (strcmp("List",Name) == 0) + { + PyObject *List = PyList_New(0); + for (vector::const_iterator I = list->begin(); + I != list->end(); I++) + { + PyObject *Obj; + Obj = CppPyObject_NEW(&MetaIndexType,*I); + PyList_Append(List,Obj); + } + return List; + } + return Py_FindMethod(PkgSourceListMethods,Self,Name); } PyTypeObject PkgSourceListType = { -- cgit v1.2.3 From 3dc72516fe915b5ba3722b11e07fb70211169509 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 23 Nov 2007 13:40:03 +0100 Subject: * python/progress.cc: - fix refcount problem in OpProgress - fix refcount problem in FetchProgress - fix refcount problem in CdromProgress --- debian/changelog | 4 ++++ python/progress.cc | 11 +++++++++-- tests/refcount.py | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100755 tests/refcount.py (limited to 'python') diff --git a/debian/changelog b/debian/changelog index ef68c616..ca3308c8 100644 --- a/debian/changelog +++ b/debian/changelog @@ -17,6 +17,10 @@ python-apt (0.7.4) UNRELEASED; urgency=low * python/sourceslist.cc: - support new "List" attribute that returns the list of metaIndex source entries + * python/progress.cc: + - fix refcount problem in OpProgress + - fix refcount problem in FetchProgress + - fix refcount problem in CdromProgress -- Michael Vogt Mon, 30 Jul 2007 22:33:59 +0200 diff --git a/python/progress.cc b/python/progress.cc index df9c2ec1..793265db 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -65,10 +65,11 @@ void PyOpProgress::Update() Py_XDECREF(o); // Build up the argument list... - PyObject *arglist = Py_BuildValue("(f)", Percent); if(CheckChange(0.05)) + { + PyObject *arglist = Py_BuildValue("(f)", Percent); RunSimpleCallback("update", arglist); - Py_XDECREF(arglist); + } }; void PyOpProgress::Done() @@ -163,14 +164,19 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) PyObject *o; o = Py_BuildValue("f", CurrentCPS); PyObject_SetAttrString(callbackInst, "currentCPS", o); + Py_XDECREF(o); o = Py_BuildValue("f", CurrentBytes); PyObject_SetAttrString(callbackInst, "currentBytes", o); + Py_XDECREF(o); o = Py_BuildValue("i", CurrentItems); PyObject_SetAttrString(callbackInst, "currentItems", o); + Py_XDECREF(o); o = Py_BuildValue("i", TotalItems); PyObject_SetAttrString(callbackInst, "totalItems", o); + Py_XDECREF(o); o = Py_BuildValue("f", TotalBytes); PyObject_SetAttrString(callbackInst, "totalBytes", o); + Py_XDECREF(o); PyObject *arglist = Py_BuildValue("()"); PyObject *result; @@ -306,6 +312,7 @@ void PyCdromProgress::Update(string text, int current) PyObject *o = Py_BuildValue("i", totalSteps); PyObject_SetAttrString(callbackInst, "totalSteps", o); + Py_XDECREF(o); RunSimpleCallback("update", arglist); } diff --git a/tests/refcount.py b/tests/refcount.py new file mode 100755 index 00000000..e8bd9c6d --- /dev/null +++ b/tests/refcount.py @@ -0,0 +1,35 @@ +#!/usr/bin/python-dbg + +from pprint import pprint,pformat +import apt +import sys +import gc +import difflib + +# get initial cache +print sys.gettotalrefcount() +progress= apt.progress.OpTextProgress() +c = apt.Cache(progress) +print "refcount after first cache instance: ", sys.gettotalrefcount() + +# test open() +c.open(progress) +print "refcount after cache open: ", sys.gettotalrefcount() +#pprint(sys.getobjects(10)) + +c.open(apt.progress.OpProgress()) +print "refcount after seconf cache open: ", sys.gettotalrefcount() +#pprint(sys.getobjects(10)) + +# FIXME: find a way to get a efficient diff +#before = gc.get_objects() +#c.open(apt.progress.OpProgress()) +#after = gc.get_objects() + + +# test update() +print "refcount before cache.update(): ", sys.gettotalrefcount() +c.update() +gc.collect() +print "refcount after cache.update(): ", sys.gettotalrefcount() +pprint(sys.getobjects(20)) -- cgit v1.2.3 From 9fa44c4a7c9ba0b856858b268445bd0f87ee58ae Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 23 Nov 2007 19:43:52 +0100 Subject: * python/depcache.cc: - be more threading friendly --- debian/changelog | 2 ++ python/depcache.cc | 25 ++++++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) (limited to 'python') diff --git a/debian/changelog b/debian/changelog index ca3308c8..538ee2c3 100644 --- a/debian/changelog +++ b/debian/changelog @@ -17,6 +17,8 @@ python-apt (0.7.4) UNRELEASED; urgency=low * python/sourceslist.cc: - support new "List" attribute that returns the list of metaIndex source entries + * python/depcache.cc: + - be more threading friendly * python/progress.cc: - fix refcount problem in OpProgress - fix refcount problem in FetchProgress diff --git a/python/depcache.cc b/python/depcache.cc index 94ff708c..f44f2f32 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -227,17 +227,19 @@ static PyObject *PkgDepCacheGetCandidateVer(PyObject *Self,PyObject *Args) static PyObject *PkgDepCacheUpgrade(PyObject *Self,PyObject *Args) { + bool res; pkgDepCache *depcache = GetCpp(Self); char distUpgrade=0; if (PyArg_ParseTuple(Args,"|b",&distUpgrade) == 0) return 0; - bool res; + Py_BEGIN_ALLOW_THREADS if(distUpgrade) res = pkgDistUpgrade(*depcache); else res = pkgAllUpgrade(*depcache); + Py_END_ALLOW_THREADS Py_INCREF(Py_None); return HandleErrors(Py_BuildValue("b",res)); @@ -245,12 +247,15 @@ static PyObject *PkgDepCacheUpgrade(PyObject *Self,PyObject *Args) static PyObject *PkgDepCacheMinimizeUpgrade(PyObject *Self,PyObject *Args) { + bool res; pkgDepCache *depcache = GetCpp(Self); if (PyArg_ParseTuple(Args,"") == 0) return 0; - bool res = pkgMinimizeUpgrade(*depcache); + Py_BEGIN_ALLOW_THREADS + res = pkgMinimizeUpgrade(*depcache); + Py_END_ALLOW_THREADS Py_INCREF(Py_None); return HandleErrors(Py_BuildValue("b",res)); @@ -351,8 +356,10 @@ static PyObject *PkgDepCacheMarkInstall(PyObject *Self,PyObject *Args) &autoInst, &fromUser) == 0) return 0; + Py_BEGIN_ALLOW_THREADS pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); depcache->MarkInstall(Pkg, autoInst, 0, fromUser); + Py_END_ALLOW_THREADS Py_INCREF(Py_None); return HandleErrors(Py_None); @@ -652,23 +659,31 @@ PyObject *GetPkgProblemResolver(PyObject *Self,PyObject *Args) static PyObject *PkgProblemResolverResolve(PyObject *Self,PyObject *Args) { + bool res; pkgProblemResolver *fixer = GetCpp(Self); char brokenFix=1; if (PyArg_ParseTuple(Args,"|b",&brokenFix) == 0) return 0; - bool res = fixer->Resolve(brokenFix); + Py_BEGIN_ALLOW_THREADS + res = fixer->Resolve(brokenFix); + Py_END_ALLOW_THREADS return HandleErrors(Py_BuildValue("b", res)); } static PyObject *PkgProblemResolverResolveByKeep(PyObject *Self,PyObject *Args) -{ +{ + bool res; pkgProblemResolver *fixer = GetCpp(Self); if (PyArg_ParseTuple(Args,"") == 0) return 0; - bool res = fixer->ResolveByKeep(); + + Py_BEGIN_ALLOW_THREADS + res = fixer->ResolveByKeep(); + Py_END_ALLOW_THREADS + return HandleErrors(Py_BuildValue("b", res)); } -- cgit v1.2.3 From ef9c8e692fd184824d29cba42c26daa9b20bdfdb Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 29 Nov 2007 12:07:01 +0100 Subject: * python/tag.cc - support "None" as default in ParseSection(control).get(field, default), LP: #44470 --- debian/changelog | 7 +++++-- python/tag.cc | 7 ++----- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'python') diff --git a/debian/changelog b/debian/changelog index 538ee2c3..0e80122f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -python-apt (0.7.4) UNRELEASED; urgency=low +python-apt (0.7.4) unstable; urgency=low * apt/debfile.py: - added wrapper around apt_inst.debExtract() @@ -19,12 +19,15 @@ python-apt (0.7.4) UNRELEASED; urgency=low metaIndex source entries * python/depcache.cc: - be more threading friendly + * python/tag.cc + - support "None" as default in + ParseSection(control).get(field, default), LP: #44470 * python/progress.cc: - fix refcount problem in OpProgress - fix refcount problem in FetchProgress - fix refcount problem in CdromProgress - -- Michael Vogt Mon, 30 Jul 2007 22:33:59 +0200 + -- Michael Vogt Thu, 29 Nov 2007 11:52:43 +0100 python-apt (0.7.3.1) unstable; urgency=low diff --git a/python/tag.cc b/python/tag.cc index d0d862c9..4b378a55 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -78,7 +78,7 @@ static PyObject *TagSecFind(PyObject *Self,PyObject *Args) { char *Name = 0; char *Default = 0; - if (PyArg_ParseTuple(Args,"s|s",&Name,&Default) == 0) + if (PyArg_ParseTuple(Args,"s|z",&Name,&Default) == 0) return 0; const char *Start; @@ -86,10 +86,7 @@ static PyObject *TagSecFind(PyObject *Self,PyObject *Args) if (GetCpp(Self).Find(Name,Start,Stop) == false) { if (Default == 0) - { - Py_INCREF(Py_None); - return Py_None; - } + Py_RETURN_NONE; return PyString_FromString(Default); } return PyString_FromStringAndSize(Start,Stop-Start); -- cgit v1.2.3