From daaa814658b6d2b8e3e2437fcc625096c46395dd Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 13 Apr 2009 23:24:42 +0200 Subject: * python/cdrom.cc, python/depcache.cc: Use tp_methods for Cdrom, ProblemResolver, ActionGroup --- python/apt_pkgmodule.h | 1 + 1 file changed, 1 insertion(+) (limited to 'python/apt_pkgmodule.h') diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index e047bcd8..ea8e33df 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -71,6 +71,7 @@ extern PyTypeObject PkgProblemResolverType; PyObject *GetPkgProblemResolver(PyObject *Self, PyObject *Args); PyObject *GetPkgActionGroup(PyObject *Self, PyObject *Args); +extern PyTypeObject PkgActionGroupType; // cdrom extern PyTypeObject PkgCdromType; PyObject *GetCdrom(PyObject *Self,PyObject *Args); -- cgit v1.2.3 From 3caa05aa8e295d338be4bfbe7fdd2e825a59d947 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 14 Apr 2009 22:14:10 +0200 Subject: * python/pkgsrcrecords.cc: Use GetSet properties for PkgSrcRecordsType This time, it is a bit more complicated because we have to raise an AttributeError when no package has been looked up. --- python/apt_pkgmodule.cc | 1 + python/apt_pkgmodule.h | 1 + python/pkgsrcrecords.cc | 178 +++++++++++++++++++++++++++++++----------------- 3 files changed, 119 insertions(+), 61 deletions(-) (limited to 'python/apt_pkgmodule.h') diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 4e718ffa..92727b6f 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -488,6 +488,7 @@ extern "C" void initapt_pkg() if (PyType_Ready(&PkgAcquireType) == -1) return; if (PyType_Ready(&PackageIndexFileType) == -1) return; if (PyType_Ready(&PkgManagerType) == -1) return; + if (PyType_Ready(&PkgSrcRecordsType) == -1) return; // Initialize the module diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index ea8e33df..d2631864 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -89,6 +89,7 @@ PyObject *GetPkgManager(PyObject *Self,PyObject *Args); // PkgRecords Stuff extern PyTypeObject PkgRecordsType; +extern PyTypeObject PkgSrcRecordsType; PyObject *GetPkgRecords(PyObject *Self,PyObject *Args); PyObject *GetPkgSrcRecords(PyObject *Self,PyObject *Args); diff --git a/python/pkgsrcrecords.cc b/python/pkgsrcrecords.cc index f7f5d7a2..c830f8d2 100644 --- a/python/pkgsrcrecords.cc +++ b/python/pkgsrcrecords.cc @@ -75,71 +75,111 @@ static PyMethodDef PkgSrcRecordsMethods[] = {} }; -static PyObject *PkgSrcRecordsAttr(PyObject *Self,char *Name) -{ +/** + * Get the PkgSrcRecordsStruct from a PyObject. If no package has been looked + * up, set an AttributeError using the given name. + */ +static inline PkgSrcRecordsStruct &GetStruct(PyObject *Self,char *name) { PkgSrcRecordsStruct &Struct = GetCpp(Self); + if (Struct.Last == 0) + PyErr_SetString(PyExc_AttributeError,name); + return Struct; +} + +static PyObject *PkgSrcRecordsGetPackage(PyObject *Self,void*) { + PkgSrcRecordsStruct &Struct = GetStruct(Self,"Package"); + return (Struct.Last != 0) ? CppPyString(Struct.Last->Package()) : 0; +} +static PyObject *PkgSrcRecordsGetVersion(PyObject *Self,void*) { + PkgSrcRecordsStruct &Struct = GetStruct(Self,"Version"); + return (Struct.Last != 0) ? CppPyString(Struct.Last->Version()) : 0; +} +static PyObject *PkgSrcRecordsGetMaintainer(PyObject *Self,void*) { + PkgSrcRecordsStruct &Struct = GetStruct(Self,"Maintainer"); + return (Struct.Last != 0) ? CppPyString(Struct.Last->Maintainer()) : 0; +} +static PyObject *PkgSrcRecordsGetSection(PyObject *Self,void*) { + PkgSrcRecordsStruct &Struct = GetStruct(Self,"Section"); + return (Struct.Last != 0) ? CppPyString(Struct.Last->Section()) : 0; +} +static PyObject *PkgSrcRecordsGetRecord(PyObject *Self,void*) { + PkgSrcRecordsStruct &Struct = GetStruct(Self,"Record"); + return (Struct.Last != 0) ? CppPyString(Struct.Last->AsStr()) : 0; +} +static PyObject *PkgSrcRecordsGetBinaries(PyObject *Self,void*) { + PkgSrcRecordsStruct &Struct = GetStruct(Self,"Binaries"); + if (Struct.Last == 0) + return 0; + PyObject *List = PyList_New(0); + for(const char **b = Struct.Last->Binaries(); *b != 0; ++b) + PyList_Append(List, CppPyString(*b)); + return List; // todo +} +static PyObject *PkgSrcRecordsGetIndex(PyObject *Self,void*) { + PkgSrcRecordsStruct &Struct = GetStruct(Self,"Index"); + if (Struct.Last == 0) + return 0; + const pkgIndexFile &tmp = Struct.Last->Index(); + return CppOwnedPyObject_NEW(Self,&PackageIndexFileType, + (pkgIndexFile*)&tmp); +} - if (Struct.Last != 0) - { - if (strcmp("Package",Name) == 0) - return CppPyString(Struct.Last->Package()); - else if (strcmp("Version",Name) == 0) - return CppPyString(Struct.Last->Version()); - else if (strcmp("Maintainer",Name) == 0) - return CppPyString(Struct.Last->Maintainer()); - else if (strcmp("Section",Name) == 0) - return CppPyString(Struct.Last->Section()); - else if (strcmp("Record",Name) == 0) - return CppPyString(Struct.Last->AsStr()); - else if (strcmp("Binaries",Name) == 0) { - PyObject *List = PyList_New(0); - - for(const char **b = Struct.Last->Binaries(); - *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); - - vector f; - if(!Struct.Last->Files(f)) - return NULL; // error - - PyObject *v; - for(unsigned int i=0;i bd; - if(!Struct.Last->BuildDepends(bd, false /* arch-only*/)) - return NULL; // error - - PyObject *v; - for(unsigned int i=0;i f; + if(!Struct.Last->Files(f)) + return NULL; // error + + PyObject *v; + for(unsigned int i=0;i bd; + if(!Struct.Last->BuildDepends(bd, false /* arch-only*/)) + return NULL; // error + + PyObject *v; + for(unsigned int i=0;i, // tp_dealloc 0, // tp_print - PkgSrcRecordsAttr, // tp_getattr + 0, // tp_getattr 0, // tp_setattr 0, // tp_compare 0, // tp_repr @@ -158,6 +198,22 @@ PyTypeObject PkgSrcRecordsType = 0, // tp_as_sequence 0, // tp_as_mapping 0, // tp_hash + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + Py_TPFLAGS_DEFAULT, // tp_flags + "SourceRecords Object", // tp_doc + 0, // tp_traverse + 0, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + PkgSrcRecordsMethods, // tp_methods + 0, // tp_members + PkgSrcRecordsGetSet, // tp_getset }; /*}}}*/ -- cgit v1.2.3 From 7a901ee79863eb812cba6e87feadc0a548f920e7 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 15 Apr 2009 18:21:44 +0200 Subject: * python: Port AcquireItem,Package,Description to GetSet --- python/acquire.cc | 102 +++++++++++++++---------- python/apt_pkgmodule.cc | 4 +- python/apt_pkgmodule.h | 2 + python/cache.cc | 198 +++++++++++++++++++++++++++++------------------- 4 files changed, 188 insertions(+), 118 deletions(-) (limited to 'python/apt_pkgmodule.h') diff --git a/python/acquire.cc b/python/acquire.cc index 053753cd..abd3884d 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -12,46 +12,50 @@ #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()); - // 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; +#define MkGet(PyFunc,Ret) static PyObject *PyFunc(PyObject *Self,void*) \ +{ \ + pkgAcquire::ItemIterator &I = GetCpp(Self); \ + return Ret; \ } +// Define our getters +MkGet(AcquireItemGetComplete,Py_BuildValue("i",(*I)->Complete)); +MkGet(AcquireItemGetDescURI,Safe_FromString((*I)->DescURI().c_str())); +MkGet(AcquireItemGetDestFile,Safe_FromString((*I)->DestFile.c_str())); +MkGet(AcquireItemGetErrorText,Safe_FromString((*I)->ErrorText.c_str())); +MkGet(AcquireItemGetFileSize,Py_BuildValue("i",(*I)->FileSize)); +MkGet(AcquireItemGetID,Py_BuildValue("i",(*I)->ID)); +MkGet(AcquireItemGetIsTrusted,Py_BuildValue("i",(*I)->IsTrusted())); +MkGet(AcquireItemGetLocal,Py_BuildValue("i",(*I)->Local)); +MkGet(AcquireItemGetStatus,Py_BuildValue("i",(*I)->Status)); + +// Constants +MkGet(AcquireItemGetStatIdle,Py_BuildValue("i", pkgAcquire::Item::StatIdle)); +MkGet(AcquireItemGetStatFetching,Py_BuildValue("i", pkgAcquire::Item::StatFetching)); +MkGet(AcquireItemGetStatDone,Py_BuildValue("i", pkgAcquire::Item::StatDone)); +MkGet(AcquireItemGetStatError,Py_BuildValue("i", pkgAcquire::Item::StatError)); +MkGet(AcquireItemGetStatAuthError,Py_BuildValue("i", pkgAcquire::Item::StatAuthError)); +#undef MkGet + +static PyGetSetDef AcquireItemGetSet[] = { + {"Complete",AcquireItemGetComplete}, + {"DescURI",AcquireItemGetDescURI}, + {"DestFile",AcquireItemGetDestFile}, + {"ErrorText",AcquireItemGetErrorText}, + {"FileSize",AcquireItemGetFileSize}, + {"ID",AcquireItemGetID}, + {"IsTrusted",AcquireItemGetIsTrusted}, + {"Local",AcquireItemGetLocal}, + {"Status",AcquireItemGetStatus}, + {"StatIdle",AcquireItemGetStatIdle}, + {"StatFetching",AcquireItemGetStatFetching}, + {"StatDone",AcquireItemGetStatDone}, + {"StatError",AcquireItemGetStatError}, + {"StatAuthError",AcquireItemGetStatAuthError}, + {} +}; + + static PyObject *AcquireItemRepr(PyObject *Self) { @@ -81,14 +85,30 @@ PyTypeObject AcquireItemType = // Methods CppOwnedDealloc, // tp_dealloc 0, // tp_print - AcquireItemAttr, // tp_getattr + 0, // 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_as_sequence + 0, // tp_as_mapping 0, // tp_hash + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + Py_TPFLAGS_DEFAULT, // tp_flags + "AcquireItem Object", // tp_doc + 0, // tp_traverse + 0, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + 0, // tp_methods + 0, // tp_members + AcquireItemGetSet, // tp_getset }; diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index e71d8ee6..3beec747 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -524,7 +524,9 @@ extern "C" void initapt_pkg() if (PyType_Ready(&PkgManagerType) == -1) INIT_ERROR; if (PyType_Ready(&PkgSrcRecordsType) == -1) INIT_ERROR; if (PyType_Ready(&PkgRecordsType) == -1) INIT_ERROR; - + if (PyType_Ready(&AcquireItemType) == -1) INIT_ERROR; + if (PyType_Ready(&PackageType) == -1) INIT_ERROR; + if (PyType_Ready(&DescriptionType) == -1) INIT_ERROR; // Initialize the module #if PY_MAJOR_VERSION >= 3 diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index d2631864..424c4788 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -56,6 +56,7 @@ PyObject *StrCheckDomainList(PyObject *Self,PyObject *Args); extern PyTypeObject PkgCacheType; extern PyTypeObject PkgCacheFileType; extern PyTypeObject PkgListType; +extern PyTypeObject DescriptionType; extern PyTypeObject PackageType; extern PyTypeObject PackageFileType; extern PyTypeObject DependencyType; @@ -77,6 +78,7 @@ extern PyTypeObject PkgCdromType; PyObject *GetCdrom(PyObject *Self,PyObject *Args); // acquire +extern PyTypeObject AcquireItemType; extern PyTypeObject PkgAcquireType; extern char *doc_GetPkgAcqFile; PyObject *GetAcquire(PyObject *Self,PyObject *Args); diff --git a/python/cache.cc b/python/cache.cc index 957681ba..52c5982e 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -368,65 +368,73 @@ PyTypeObject PkgListType = 0, // tp_hash }; - /*}}}*/ -// Package Class /*{{{*/ -// --------------------------------------------------------------------- -static PyObject *PackageAttr(PyObject *Self,char *Name) +#define MkGet(PyFunc,Ret) static PyObject *PyFunc(PyObject *Self,void*) \ +{ \ + pkgCache::PkgIterator &Pkg = GetCpp(Self); \ + PyObject *Owner = GetOwner(Self); \ + return Ret; \ +} + +MkGet(PackageGetName,PyString_FromString(Pkg.Name())); +MkGet(PackageGetSection,Safe_FromString(Pkg.Section())); +MkGet(PackageGetRevDependsList,CppOwnedPyObject_NEW(Owner, + &RDepListType, Pkg.RevDependsList())); +MkGet(PackageGetProvidesList,CreateProvides(Owner,Pkg.ProvidesList())); +MkGet(PackageGetSelectedState,Py_BuildValue("i",Pkg->SelectedState)); +MkGet(PackageGetInstState,Py_BuildValue("i",Pkg->InstState)); +MkGet(PackageGetCurrentState,Py_BuildValue("i",Pkg->CurrentState)); +MkGet(PackageGetID,Py_BuildValue("i",Pkg->ID)); +# +MkGet(PackageGetAuto,Py_BuildValue("i",(Pkg->Flags & pkgCache::Flag::Auto) != 0)); +MkGet(PackageGetEssential,Py_BuildValue("i",(Pkg->Flags & pkgCache::Flag::Essential) != 0)); +MkGet(PackageGetImportant,Py_BuildValue("i",(Pkg->Flags & pkgCache::Flag::Important) != 0)); +#undef MkGet + +static PyObject *PackageGetVersionList(PyObject *Self,void*) { pkgCache::PkgIterator &Pkg = GetCpp(Self); PyObject *Owner = GetOwner(Self); - if (strcmp("Name",Name) == 0) - return PyString_FromString(Pkg.Name()); - else if (strcmp("VersionList",Name) == 0) + PyObject *List = PyList_New(0); + for (pkgCache::VerIterator I = Pkg.VersionList(); I.end() == false; I++) { - PyObject *List = PyList_New(0); - for (pkgCache::VerIterator I = Pkg.VersionList(); I.end() == false; I++) - { - PyObject *Obj; - Obj = CppOwnedPyObject_NEW(Owner,&VersionType,I); - PyList_Append(List,Obj); - Py_DECREF(Obj); - } - return List; + PyObject *Obj; + Obj = CppOwnedPyObject_NEW(Owner,&VersionType,I); + PyList_Append(List,Obj); + Py_DECREF(Obj); } - else if (strcmp("CurrentVer",Name) == 0) + return List; +} +static PyObject *PackageGetCurrentVer(PyObject *Self,void*) +{ + pkgCache::PkgIterator &Pkg = GetCpp(Self); + PyObject *Owner = GetOwner(Self); + if (Pkg->CurrentVer == 0) { - if (Pkg->CurrentVer == 0) - { - Py_INCREF(Py_None); - return Py_None; - } - - return CppOwnedPyObject_NEW(Owner,&VersionType, - Pkg.CurrentVer()); + Py_INCREF(Py_None); + return Py_None; } - else if (strcmp("Section",Name) == 0) - return Safe_FromString(Pkg.Section()); - else if (strcmp("RevDependsList",Name) == 0) - return CppOwnedPyObject_NEW(Owner,&RDepListType, - Pkg.RevDependsList()); - else if (strcmp("ProvidesList",Name) == 0) - return CreateProvides(Owner,Pkg.ProvidesList()); - else if (strcmp("SelectedState",Name) == 0) - return Py_BuildValue("i",Pkg->SelectedState); - else if (strcmp("InstState",Name) == 0) - return Py_BuildValue("i",Pkg->InstState); - else if (strcmp("CurrentState",Name) == 0) - return Py_BuildValue("i",Pkg->CurrentState); - else if (strcmp("ID",Name) == 0) - return Py_BuildValue("i",Pkg->ID); - else if (strcmp("Auto",Name) == 0) - return Py_BuildValue("i",(Pkg->Flags & pkgCache::Flag::Auto) != 0); - else if (strcmp("Essential",Name) == 0) - return Py_BuildValue("i",(Pkg->Flags & pkgCache::Flag::Essential) != 0); - else if (strcmp("Important",Name) == 0) - return Py_BuildValue("i",(Pkg->Flags & pkgCache::Flag::Important) != 0); - - PyErr_SetString(PyExc_AttributeError,Name); - return 0; + return CppOwnedPyObject_NEW(Owner,&VersionType, + Pkg.CurrentVer()); } +static PyGetSetDef PackageGetSet[] = { + {"Name",PackageGetName}, + {"Section",PackageGetSection}, + {"RevDependsList",PackageGetRevDependsList}, + {"ProvidesList",PackageGetProvidesList}, + {"SelectedState",PackageGetSelectedState}, + {"InstState",PackageGetInstState}, + {"CurrentState",PackageGetCurrentState}, + {"ID",PackageGetID}, + {"Auto",PackageGetID}, + {"Essential",PackageGetEssential}, + {"Important",PackageGetImportant}, + {"VersionList",PackageGetVersionList}, + {"CurrentVer",PackageGetCurrentVer}, + {} +}; + static PyObject *PackageRepr(PyObject *Self) { pkgCache::PkgIterator &Pkg = GetCpp(Self); @@ -450,7 +458,7 @@ PyTypeObject PackageType = // Methods CppOwnedDealloc, // tp_dealloc 0, // tp_print - PackageAttr, // tp_getattr + 0, // tp_getattr 0, // tp_setattr 0, // tp_compare PackageRepr, // tp_repr @@ -458,40 +466,62 @@ PyTypeObject PackageType = 0, // tp_as_sequence 0, // tp_as_mapping 0, // tp_hash + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + Py_TPFLAGS_DEFAULT, // tp_flags + "Package Object", // tp_doc + 0, // tp_traverse + 0, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + 0, // tp_methods + 0, // tp_members + PackageGetSet, // tp_getset }; - /*}}}*/ -// Description Class /*{{{*/ -// --------------------------------------------------------------------- -static PyObject *DescriptionAttr(PyObject *Self,char *Name) + +#define Description_MkGet(PyFunc,Ret) static PyObject \ + *PyFunc(PyObject *Self,void*) { \ + pkgCache::DescIterator &Desc = GetCpp(Self); \ + return Ret; } + +Description_MkGet(DescriptionGetLanguageCode, + PyString_FromString(Desc.LanguageCode())); +Description_MkGet(DescriptionGetMd5,Safe_FromString(Desc.md5())); +#undef Description_MkGet + +static PyObject *DescriptionGetFileList(PyObject *Self,void*) { pkgCache::DescIterator &Desc = GetCpp(Self); PyObject *Owner = GetOwner(Self); - if (strcmp("LanguageCode",Name) == 0) - return PyString_FromString(Desc.LanguageCode()); - else if (strcmp("md5",Name) == 0) - return Safe_FromString(Desc.md5()); - else if (strcmp("FileList",Name) == 0) + /* The second value in the tuple is the index of the VF item. If the + user wants to request a lookup then that number will be used. + Maybe later it can become an object. */ + PyObject *List = PyList_New(0); + for (pkgCache::DescFileIterator I = Desc.FileList(); I.end() == false; I++) { - /* The second value in the tuple is the index of the VF item. If the - user wants to request a lookup then that number will be used. - Maybe later it can become an object. */ - PyObject *List = PyList_New(0); - for (pkgCache::DescFileIterator I = Desc.FileList(); I.end() == false; I++) - { - PyObject *DescFile; - PyObject *Obj; - DescFile = CppOwnedPyObject_NEW(Owner,&PackageFileType,I.File()); - Obj = Py_BuildValue("Nl",DescFile,I.Index()); - PyList_Append(List,Obj); - Py_DECREF(Obj); - } - return List; + PyObject *DescFile; + PyObject *Obj; + DescFile = CppOwnedPyObject_NEW(Owner,&PackageFileType,I.File()); + Obj = Py_BuildValue("Nl",DescFile,I.Index()); + PyList_Append(List,Obj); + Py_DECREF(Obj); } - PyErr_SetString(PyExc_AttributeError,Name); - return 0; + return List; } +static PyGetSetDef DescriptionGetSet[] = { + {"LanguageCode",DescriptionGetLanguageCode}, + {"md5",DescriptionGetMd5}, + {"FileList",DescriptionGetFileList}, + {} +}; + static PyObject *DescriptionRepr(PyObject *Self) { pkgCache::DescIterator &Desc = GetCpp(Self); @@ -515,7 +545,7 @@ PyTypeObject DescriptionType = // Methods CppOwnedDealloc, // tp_dealloc 0, // tp_print - DescriptionAttr, // tp_getattr + 0, // tp_getattr 0, // tp_setattr 0, // tp_compare DescriptionRepr, // tp_repr @@ -523,6 +553,22 @@ PyTypeObject DescriptionType = 0, // tp_as_sequence 0, // tp_as_mapping 0, // tp_hash + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + Py_TPFLAGS_DEFAULT, // tp_flags + "AcquireItem Object", // tp_doc + 0, // tp_traverse + 0, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + 0, // tp_methods + 0, // tp_members + DescriptionGetSet, // tp_getset }; /*}}}*/ // Version Class /*{{{*/ -- cgit v1.2.3 From 45cdd4f2c6b04bfdfd37ef0e1a6358b29680afb8 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sun, 19 Apr 2009 15:17:32 +0200 Subject: * python/*.cc: Export all types and add a __new__() method to them. Some names may be changed before the release, but this is a good draft. --- python/acquire.cc | 119 ++++++++++++++++++++++++++++++++-------- python/apt_pkgmodule.cc | 49 +++++++++++++++++ python/apt_pkgmodule.h | 1 + python/cache.cc | 125 ++++++++++++++++++++++++------------------ python/cdrom.cc | 38 +++++++++---- python/configuration.cc | 23 ++++++-- python/depcache.cc | 140 +++++++++++++++++++++++++++++++++--------------- python/indexfile.cc | 2 +- python/metaindex.cc | 2 +- python/pkgmanager.cc | 52 +++++++++++------- python/pkgrecords.cc | 31 ++++++++--- python/pkgsrcrecords.cc | 18 ++++++- python/sourcelist.cc | 18 ++++++- python/tag.cc | 75 ++++++++++++++++++++------ 14 files changed, 519 insertions(+), 174 deletions(-) (limited to 'python/apt_pkgmodule.h') diff --git a/python/acquire.cc b/python/acquire.cc index abd3884d..1cdf0cb9 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -194,13 +194,41 @@ static PyGetSetDef PkgAcquireGetSet[] = { {} }; +static PyObject *PkgAcquireNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) { + pkgAcquire *fetcher; + + PyObject *pyFetchProgressInst = NULL; + static char *kwlist[] = {"progress", 0}; + if (PyArg_ParseTupleAndKeywords(Args,kwds,"|O",kwlist,&pyFetchProgressInst) == 0) + return 0; + + if (pyFetchProgressInst != NULL) { + // FIXME: memleak? + PyFetchProgress *progress = new PyFetchProgress(); + progress->setCallbackInst(pyFetchProgressInst); + fetcher = new pkgAcquire(progress); + } else { + fetcher = new pkgAcquire(); + } + + CppPyObject *FetcherObj = + CppPyObject_NEW(type, fetcher); + + return FetcherObj; +} + +static const char *doc_PkgAcquire = "Acquire(progress) -> Acquire() object.\n\n" + "Create a new acquire object. The parameter *progress* can be used to\n" + "specify a apt.progress.FetchProgress() object, which will display the\n" + "progress of the fetching."; + PyTypeObject PkgAcquireType = { PyObject_HEAD_INIT(&PyType_Type) #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "Acquire", // tp_name + "apt_pkg.Acquire", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -220,7 +248,7 @@ PyTypeObject PkgAcquireType = 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags - "pkgAcquire Object", // tp_doc + doc_PkgAcquire, // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare @@ -230,38 +258,66 @@ PyTypeObject PkgAcquireType = PkgAcquireMethods, // tp_methods 0, // tp_members PkgAcquireGetSet, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + PkgAcquireNew, // tp_new }; + PyObject *GetAcquire(PyObject *Self,PyObject *Args) { - pkgAcquire *fetcher; + return PkgAcquireNew(&PkgAcquireType,Args,0); +} - PyObject *pyFetchProgressInst = NULL; - if (PyArg_ParseTuple(Args,"|O",&pyFetchProgressInst) == 0) - return 0; +static PyObject *PkgAcquireFileNew(PyTypeObject *type, PyObject *Args, PyObject * kwds) +{ + PyObject *pyfetcher; + char *uri, *md5, *descr, *shortDescr, *destDir, *destFile; + int size = 0; + uri = md5 = descr = shortDescr = destDir = destFile = ""; - if (pyFetchProgressInst != NULL) { - // FIXME: memleak? - PyFetchProgress *progress = new PyFetchProgress(); - progress->setCallbackInst(pyFetchProgressInst); - fetcher = new pkgAcquire(progress); - } else { - fetcher = new pkgAcquire(); - } + char * kwlist[] = {"owner","uri", "md5", "size", "descr", "shortdescr", + "destdir", "destfile", NULL}; - CppPyObject *FetcherObj = - CppPyObject_NEW(&PkgAcquireType, fetcher); + if (PyArg_ParseTupleAndKeywords(Args, kwds, "O!s|sissss", kwlist, + &PkgAcquireType, &pyfetcher, &uri, &md5, + &size, &descr, &shortDescr, &destDir, &destFile) == 0) + return 0; - return FetcherObj; + pkgAcquire *fetcher = GetCpp(pyfetcher); + pkgAcqFile *af = new pkgAcqFile(fetcher, // owner + uri, // uri + md5, // md5 + size, // size + descr, // descr + shortDescr, + destDir, + destFile); // short-desc + CppPyObject *AcqFileObj = CppPyObject_NEW(type); + AcqFileObj->Object = af; + + return AcqFileObj; } + +static const char *doc_PkgAcquireFile = + "AcquireFile(owner, uri[, md5, size, descr, short_descr, dest_dir," + "dest_file]) -> New AcquireFile() object\n\n" + "The parameter *owner* refers to an apt_pkg.Acquire() object. You can use\n" + "*destdir* OR *destfile* to specify the destination directory/file."; + PyTypeObject PkgAcquireFileType = { PyObject_HEAD_INIT(&PyType_Type) #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgAcquireFile", // tp_name + "apt_pkg.AcquireFile", // tp_name sizeof(CppPyObject),// tp_basicsize 0, // tp_itemsize // Methods @@ -275,6 +331,30 @@ PyTypeObject PkgAcquireFileType = 0, // tp_as_sequence 0, // tp_as_mapping 0, // tp_hash + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + Py_TPFLAGS_DEFAULT, // tp_flags + doc_PkgAcquireFile, // tp_doc + 0, // tp_traverse + 0, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + 0, // tp_methods + 0, // tp_members + 0, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + PkgAcquireFileNew, // tp_new }; char *doc_GetPkgAcqFile = @@ -308,6 +388,3 @@ PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject * kwds) return AcqFileObj; } - - - /*}}}*/ diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 0fcf1f29..a54b3922 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -385,14 +385,18 @@ static PyObject *PkgSystemUnLock(PyObject *Self,PyObject *Args) static PyMethodDef methods[] = { // Constructors + #ifdef COMPAT_0_7 {"newConfiguration",newConfiguration,METH_VARARGS,doc_newConfiguration}, + #endif {"init",Init,METH_VARARGS,doc_Init}, {"InitConfig",InitConfig,METH_VARARGS,doc_InitConfig}, {"InitSystem",InitSystem,METH_VARARGS,doc_InitSystem}, // Tag File + #ifdef COMPAT_0_7 {"ParseSection",ParseSection,METH_VARARGS,doc_ParseSection}, {"ParseTagFile",ParseTagFile,METH_VARARGS,doc_ParseTagFile}, + #endif {"RewriteSection",RewriteSection,METH_VARARGS,doc_RewriteSection}, // Locking @@ -433,6 +437,7 @@ static PyMethodDef methods[] = {"StrToTime",StrStrToTime,METH_VARARGS,"StrToTime(String) -> Int"}, // Cache + #ifdef COMPAT_0_7 {"GetCache",TmpGetCache,METH_VARARGS,"GetCache() -> PkgCache"}, {"GetDepCache",GetDepCache,METH_VARARGS,"GetDepCache(Cache) -> DepCache"}, {"GetPkgRecords",GetPkgRecords,METH_VARARGS,"GetPkgRecords(Cache) -> PkgRecords"}, @@ -452,11 +457,16 @@ static PyMethodDef methods[] = // PkgManager {"GetPackageManager",GetPkgManager,METH_VARARGS,"GetPackageManager(DepCache) -> PackageManager"}, + #endif {} }; +#define ADDTYPE(mod,name,type) { Py_INCREF(type); \ + PyModule_AddObject(mod,name,(PyObject *)type); } + + #if PY_MAJOR_VERSION >= 3 struct module_state { PyObject *error; @@ -527,6 +537,45 @@ extern "C" void initapt_pkg() Config->Object = _config; PyModule_AddObject(Module,"Config",Config); + // Add our classes. + /* ============================ tag.cc ============================ */ + ADDTYPE(Module,"TagSection",&TagSecType); + ADDTYPE(Module,"TagFile",&TagFileType); + /* ============================ acquire.cc ============================ */ + ADDTYPE(Module,"Acquire",&PkgAcquireType); + ADDTYPE(Module,"AcquireFile",&PkgAcquireFileType); + ADDTYPE(Module,"AcquireItem",&AcquireItemType); // NO __new__() + /* ============================ cache.cc ============================ */ + ADDTYPE(Module,"Cache",&PkgCacheType); + ADDTYPE(Module,"Dependency",&DependencyType); // NO __new__() + ADDTYPE(Module,"Description",&DescriptionType); // NO __new__() + ADDTYPE(Module,"PackageFile",&PackageFileType); // NO __new__() + //ADDTYPE(Module,"PackageList",&PkgListType); // NO __new__(), internal + //ADDTYPE(Module,"DependencyList",&RDepListType); // NO __new__(), internal + ADDTYPE(Module,"Package",&PackageType); // NO __new__() + ADDTYPE(Module,"Version",&VersionType); // NO __new__() + /* ============================ cdrom.cc ============================ */ + ADDTYPE(Module,"Cdrom",&PkgCdromType); + /* ========================= configuration.cc ========================= */ + ADDTYPE(Module,"Configuration",&ConfigurationType); + //ADDTYPE(Module,"ConfigurationSub",&ConfigurationSubType); // NO __new__() + //ADDTYPE(Module,"ConfigurationPtr",&ConfigurationPtrType); // NO __new__() + /* ========================= depcache.cc ========================= */ + ADDTYPE(Module,"ActionGroup",&PkgActionGroupType); + ADDTYPE(Module,"DepCache",&PkgDepCacheType); + ADDTYPE(Module,"ProblemResolver",&PkgProblemResolverType); + /* ========================= indexfile.cc ========================= */ + ADDTYPE(Module,"PackageIndexFile",&PackageIndexFileType); // NO __new__() + /* ========================= metaindex.cc ========================= */ + ADDTYPE(Module,"MetaIndex",&MetaIndexType); // NO __new__() + /* ========================= pkgmanager.cc ========================= */ + ADDTYPE(Module,"PackageManager",&PkgManagerType); + /* ========================= pkgrecords.cc ========================= */ + ADDTYPE(Module,"PackageRecords",&PkgRecordsType); + /* ========================= pkgsrcrecords.cc ========================= */ + ADDTYPE(Module,"SourceRecords",&PkgSrcRecordsType); + /* ========================= sourcelist.cc ========================= */ + ADDTYPE(Module,"SourceList",&PkgSourceListType); // Tag file constants PyModule_AddObject(Module,"RewritePackageOrder", CharCharToList(TFRewritePackageOrder)); diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index 424c4788..f7ef63c2 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -80,6 +80,7 @@ PyObject *GetCdrom(PyObject *Self,PyObject *Args); // acquire extern PyTypeObject AcquireItemType; extern PyTypeObject PkgAcquireType; +extern PyTypeObject PkgAcquireFileType; extern char *doc_GetPkgAcqFile; PyObject *GetAcquire(PyObject *Self,PyObject *Args); PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject *kwds); diff --git a/python/cache.cc b/python/cache.cc index 92e064b2..0862cd77 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -235,6 +235,61 @@ void PkgCacheFileDealloc(PyObject *Self) CppOwnedDealloc(Self); } +static PyObject *PkgCacheNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) +{ + PyObject *pyCallbackInst = 0; + static char *kwlist[] = {"progress", 0}; + if (PyArg_ParseTupleAndKeywords (Args, kwds, "|O", kwlist, &pyCallbackInst) == 0) + return 0; + + if (_system == 0) { + PyErr_SetString(PyExc_ValueError,"_system not initialized"); + return 0; + } + + pkgCacheFile *Cache = new pkgCacheFile(); + + if(pyCallbackInst != 0) { + // sanity check for the progress object, see #497049 + if (PyObject_HasAttrString(pyCallbackInst, "done") != true) { + PyErr_SetString(PyExc_ValueError, + "OpProgress object must implement done()"); + return 0; + } + if (PyObject_HasAttrString(pyCallbackInst, "update") != true) { + PyErr_SetString(PyExc_ValueError, + "OpProgress object must implement update()"); + return 0; + } + PyOpProgress progress; + progress.setCallbackInst(pyCallbackInst); + if (Cache->Open(progress,false) == false) + return HandleErrors(); + } + else { + OpTextProgress Prog; + if (Cache->Open(Prog,false) == false) + return HandleErrors(); + } + + CppOwnedPyObject *CacheFileObj = + CppOwnedPyObject_NEW(0,&PkgCacheFileType, Cache); + + CppOwnedPyObject *CacheObj = + CppOwnedPyObject_NEW(CacheFileObj,type, + (pkgCache *)(*Cache)); + + //Py_DECREF(CacheFileObj); + return CacheObj; +} + +static const char *doc_PkgCache = "Cache([progress]) -> Cache() object.\n\n" + "The cache provides access to the packages and other stuff.\n\n" + "The optional parameter *progress* can be used to specify an \n" + "apt.progress.OpProgress() object (or similar) which displays\n" + "the opening progress.\n\n" + "If not specified, the progress is displayed in simple text form."; + static PyMappingMethods CacheMap = {0,CacheMapOp,0}; PyTypeObject PkgCacheType = { @@ -242,7 +297,7 @@ PyTypeObject PkgCacheType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgCache", // tp_name + "apt_pkg.Cache", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -262,7 +317,7 @@ PyTypeObject PkgCacheType = 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT , // tp_flags - "Cache Object", // tp_doc + doc_PkgCache, // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare @@ -272,6 +327,14 @@ PyTypeObject PkgCacheType = PkgCacheMethods, // tp_methods 0, // tp_members PkgCacheGetSet, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + PkgCacheNew, // tp_new }; /*}}}*/ // PkgCacheFile Class /*{{{*/ @@ -352,7 +415,7 @@ PyTypeObject PkgListType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgCache::PkgIterator", // tp_name + "apt_pkg.PackageList", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -452,7 +515,7 @@ PyTypeObject PackageType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgCache::Package", // tp_name + "apt_pkg.Package", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -539,7 +602,7 @@ PyTypeObject DescriptionType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgCache::DescIterator", // tp_name + "apt_pkg.Description", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -743,7 +806,7 @@ PyTypeObject VersionType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgCache::VerIterator", // tp_name + "apt_pkg.Version", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -820,7 +883,7 @@ PyTypeObject PackageFileType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgCache::PkgFileIterator", // tp_name + "apt_pkg.PackageFile", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -968,7 +1031,7 @@ PyTypeObject DependencyType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgCache::DepIterator", // tp_name + "apt_pkg.Dependency", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -1056,7 +1119,7 @@ PyTypeObject RDepListType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgCache::DepIterator", // tp_name + "apt_pkg.DependencyList", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -1078,47 +1141,5 @@ PyTypeObject RDepListType = PyObject *TmpGetCache(PyObject *Self,PyObject *Args) { - PyObject *pyCallbackInst = 0; - if (PyArg_ParseTuple(Args, "|O", &pyCallbackInst) == 0) - return 0; - - if (_system == 0) { - PyErr_SetString(PyExc_ValueError,"_system not initialized"); - return 0; - } - - pkgCacheFile *Cache = new pkgCacheFile(); - - if(pyCallbackInst != 0) { - // sanity check for the progress object, see #497049 - if (PyObject_HasAttrString(pyCallbackInst, "done") != true) { - PyErr_SetString(PyExc_ValueError, - "OpProgress object must implement done()"); - return 0; - } - if (PyObject_HasAttrString(pyCallbackInst, "update") != true) { - PyErr_SetString(PyExc_ValueError, - "OpProgress object must implement update()"); - return 0; - } - PyOpProgress progress; - progress.setCallbackInst(pyCallbackInst); - if (Cache->Open(progress,false) == false) - return HandleErrors(); - } - else { - OpTextProgress Prog; - if (Cache->Open(Prog,false) == false) - return HandleErrors(); - } - - CppOwnedPyObject *CacheFileObj = - CppOwnedPyObject_NEW(0,&PkgCacheFileType, Cache); - - CppOwnedPyObject *CacheObj = - CppOwnedPyObject_NEW(CacheFileObj,&PkgCacheType, - (pkgCache *)(*Cache)); - - //Py_DECREF(CacheFileObj); - return CacheObj; + return PkgCacheNew(&PkgCacheType,Args,0); } diff --git a/python/cdrom.cc b/python/cdrom.cc index b3a38438..bf94a390 100644 --- a/python/cdrom.cc +++ b/python/cdrom.cc @@ -58,19 +58,34 @@ static PyObject *PkgCdromIdent(PyObject *Self,PyObject *Args) static PyMethodDef PkgCdromMethods[] = { - {"Add",PkgCdromAdd,METH_VARARGS,"Add a cdrom"}, - {"Ident",PkgCdromIdent,METH_VARARGS,"Ident a cdrom"}, + {"Add",PkgCdromAdd,METH_VARARGS,"Add(progress) -> Add a cdrom"}, + {"Ident",PkgCdromIdent,METH_VARARGS,"Ident(progress) -> Ident a cdrom"}, {} }; +static PyObject *PkgCdromNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) +{ + pkgCdrom *cdrom = new pkgCdrom(); + + static char *kwlist[] = {}; + if (PyArg_ParseTupleAndKeywords(Args,kwds,"",kwlist) == 0) + return 0; + + CppOwnedPyObject *CdromObj = + CppOwnedPyObject_NEW(0,type, *cdrom); + + return CdromObj; +} + + PyTypeObject PkgCdromType = { PyObject_HEAD_INIT(&PyType_Type) #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "Cdrom", // tp_name + "apt_pkg.Cdrom", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -98,16 +113,21 @@ PyTypeObject PkgCdromType = 0, // tp_iter 0, // tp_iternext PkgCdromMethods, // tp_methods + 0, // tp_members + 0, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + PkgCdromNew, // tp_new }; PyObject *GetCdrom(PyObject *Self,PyObject *Args) { - pkgCdrom *cdrom = new pkgCdrom(); - - CppOwnedPyObject *CdromObj = - CppOwnedPyObject_NEW(0,&PkgCdromType, *cdrom); - - return CdromObj; + return PkgCdromNew(&PkgCdromType,Args,0); } diff --git a/python/configuration.cc b/python/configuration.cc index eaac48ec..abbed6d9 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -475,6 +475,13 @@ static PyMethodDef CnfMethods[] = {} }; +static PyObject *CnfNew(PyTypeObject *type, PyObject *args, PyObject *kwds) { + static char *kwlist[] = {}; + if (PyArg_ParseTupleAndKeywords(args,kwds,"",kwlist) == 0) + return 0; + return CppPyObject_NEW(type); +} + // Type for a Normal Configuration object static PySequenceMethods ConfigurationSeq = {0,0,0,0,0,0,0,CnfContains,0,0}; static PyMappingMethods ConfigurationMap = {0,CnfMap,CnfMapSet}; @@ -484,7 +491,7 @@ PyTypeObject ConfigurationType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "Configuration", // tp_name + "apt_pkg.Configuration", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -512,6 +519,16 @@ PyTypeObject ConfigurationType = 0, // tp_iter 0, // tp_iternext CnfMethods, // tp_methods + 0, // tp_members + 0, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + CnfNew, // tp_new }; PyTypeObject ConfigurationPtrType = @@ -520,7 +537,7 @@ PyTypeObject ConfigurationPtrType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "ConfigurationPtr", // tp_name + "apt_pkg.ConfigurationPtr", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -556,7 +573,7 @@ PyTypeObject ConfigurationSubType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "ConfigurationSub", // tp_name + "apt_pkg.ConfigurationSub", // tp_name sizeof(SubConfiguration), // tp_basicsize 0, // tp_itemsize // Methods diff --git a/python/depcache.cc b/python/depcache.cc index 1c9eeff7..0cadee64 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -591,13 +591,39 @@ static PyGetSetDef PkgDepCacheGetSet[] = { {} }; +static PyObject *PkgDepCacheNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) +{ + PyObject *Owner; + static char *kwlist[] = {"cache", 0}; + if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PkgCacheType, + &Owner) == 0) + return 0; + + + // the owner of the Python cache object is a cachefile object, get it + PyObject *CacheFilePy = GetOwner(Owner); + // get the pkgCacheFile from the cachefile + pkgCacheFile *CacheF = GetCpp(CacheFilePy); + // and now the depcache + pkgDepCache *depcache = (pkgDepCache *)(*CacheF); + + CppOwnedPyObject *DepCachePyObj; + DepCachePyObj = CppOwnedPyObject_NEW(Owner,type,depcache); + HandleErrors(DepCachePyObj); + + return DepCachePyObj; +} + +static const char *doc_PkgDepCache = "DepCache(cache) -> DepCache() object\n\n" + "A DepCache() holds extra information on the state of the packages.\n\n" + "The parameter *cache* refers to an apt_pkg.Cache() object."; PyTypeObject PkgDepCacheType = { PyObject_HEAD_INIT(&PyType_Type) #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgDepCache", // tp_name + "apt_pkg.DepCache", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -617,7 +643,7 @@ PyTypeObject PkgDepCacheType = 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags - "pkgDepCache Object", // tp_doc + doc_PkgDepCache, // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare @@ -627,30 +653,20 @@ PyTypeObject PkgDepCacheType = PkgDepCacheMethods, // tp_methods 0, // tp_members PkgDepCacheGetSet, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + PkgDepCacheNew, // tp_new }; PyObject *GetDepCache(PyObject *Self,PyObject *Args) { - PyObject *Owner; - if (PyArg_ParseTuple(Args,"O!",&PkgCacheType,&Owner) == 0) - return 0; - - - // the owner of the Python cache object is a cachefile object, get it - PyObject *CacheFilePy = GetOwner(Owner); - // get the pkgCacheFile from the cachefile - pkgCacheFile *CacheF = GetCpp(CacheFilePy); - // and now the depcache - pkgDepCache *depcache = (pkgDepCache *)(*CacheF); - - CppOwnedPyObject *DepCachePyObj; - DepCachePyObj = CppOwnedPyObject_NEW(Owner, - &PkgDepCacheType, - depcache); - HandleErrors(DepCachePyObj); - - return DepCachePyObj; + return PkgDepCacheNew(&PkgDepCacheType,Args,0); } @@ -661,26 +677,28 @@ PyObject *GetDepCache(PyObject *Self,PyObject *Args) // pkgProblemResolver Class /*{{{*/ // --------------------------------------------------------------------- - - -PyObject *GetPkgProblemResolver(PyObject *Self,PyObject *Args) +static PyObject *PkgProblemResolverNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) { PyObject *Owner; - if (PyArg_ParseTuple(Args,"O!",&PkgDepCacheType,&Owner) == 0) + static char *kwlist[] = {"depcache",0}; + if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PkgDepCacheType, + &Owner) == 0) return 0; pkgDepCache *depcache = GetCpp(Owner); pkgProblemResolver *fixer = new pkgProblemResolver(depcache); CppOwnedPyObject *PkgProblemResolverPyObj; PkgProblemResolverPyObj = CppOwnedPyObject_NEW(Owner, - &PkgProblemResolverType, + type, fixer); HandleErrors(PkgProblemResolverPyObj); return PkgProblemResolverPyObj; - } +PyObject *GetPkgProblemResolver(PyObject *Self,PyObject *Args) { + return PkgProblemResolverNew(&PkgProblemResolverType,Args,0); +} static PyObject *PkgProblemResolverResolve(PyObject *Self,PyObject *Args) { @@ -778,7 +796,7 @@ PyTypeObject PkgProblemResolverType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgProblemResolver", // tp_name + "apt_pkg.ProblemResolver", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -806,6 +824,16 @@ PyTypeObject PkgProblemResolverType = 0, // tp_iter 0, // tp_iternext PkgProblemResolverMethods, // tp_methods + 0, // tp_members + 0, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + PkgProblemResolverNew, // tp_new }; /*}}}*/ @@ -830,13 +858,40 @@ static PyMethodDef PkgActionGroupMethods[] = {} }; +static PyObject *PkgActionGroupNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) +{ + PyObject *Owner; + static char *kwlist[] = {"depcache", 0}; + if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PkgDepCacheType, + &Owner) == 0) + return 0; + + pkgDepCache *depcache = GetCpp(Owner); + pkgDepCache::ActionGroup *group = new pkgDepCache::ActionGroup(*depcache); + CppOwnedPyObject *PkgActionGroupPyObj; + PkgActionGroupPyObj = CppOwnedPyObject_NEW(Owner, + type, + group); + HandleErrors(PkgActionGroupPyObj); + + return PkgActionGroupPyObj; + +} + +static const char *doc_PkgActionGroup = "ActionGroup(depcache)\n\n" + "Create a new ActionGroup() object. ActionGroups disable certain cleanup\n" + "actions, so modifying many packages is much faster.\n\n" + "Creating an ActionGroup() makes it active, use release() to disable it\n" + "again.\n\n" + "The parameter *depcache* refers to an apt_pkg.DepCache() object."; + PyTypeObject PkgActionGroupType = { PyObject_HEAD_INIT(&PyType_Type) #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgActionGroup", // tp_name + "apt_pkg.ActionGroup", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -856,7 +911,7 @@ PyTypeObject PkgActionGroupType = 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags - "ActionGroup Object", // tp_doc + doc_PkgActionGroup, // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare @@ -864,24 +919,21 @@ PyTypeObject PkgActionGroupType = 0, // tp_iter 0, // tp_iternext PkgActionGroupMethods, // tp_methods + 0, // tp_members + 0, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + PkgActionGroupNew, // tp_new }; PyObject *GetPkgActionGroup(PyObject *Self,PyObject *Args) { - PyObject *Owner; - if (PyArg_ParseTuple(Args,"O!",&PkgDepCacheType,&Owner) == 0) - return 0; - - pkgDepCache *depcache = GetCpp(Owner); - pkgDepCache::ActionGroup *group = new pkgDepCache::ActionGroup(*depcache); - CppOwnedPyObject *PkgActionGroupPyObj; - PkgActionGroupPyObj = CppOwnedPyObject_NEW(Owner, - &PkgActionGroupType, - group); - HandleErrors(PkgActionGroupPyObj); - - return PkgActionGroupPyObj; - + return PkgActionGroupNew(&PkgActionGroupType,Args,0); } diff --git a/python/indexfile.cc b/python/indexfile.cc index bb40cdd0..600dc853 100644 --- a/python/indexfile.cc +++ b/python/indexfile.cc @@ -84,7 +84,7 @@ PyTypeObject PackageIndexFileType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgIndexFile", // tp_name + "apt_pkg.PackageIndexFile", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods diff --git a/python/metaindex.cc b/python/metaindex.cc index cbaeafbd..557aacd8 100644 --- a/python/metaindex.cc +++ b/python/metaindex.cc @@ -62,7 +62,7 @@ PyTypeObject MetaIndexType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "metaIndex", // tp_name + "apt_pkg.MetaIndex", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods diff --git a/python/pkgmanager.cc b/python/pkgmanager.cc index 8f56cddc..781acc8b 100644 --- a/python/pkgmanager.cc +++ b/python/pkgmanager.cc @@ -15,8 +15,32 @@ #include #include #include +#include +#include + #include +static PyObject *PkgManagerNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) +{ + PyObject *Owner; + char *kwlist[] = {"depcache",0}; + if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PkgDepCacheType, + &Owner) == 0) + return 0; + + pkgPackageManager *pm = _system->CreatePM(GetCpp(Owner)); + + CppPyObject *PkgManagerObj = + CppPyObject_NEW(type,pm); + + return PkgManagerObj; +} + +PyObject *GetPkgManager(PyObject *Self,PyObject *Args) +{ + return PkgManagerNew(&PkgManagerType,Args,0); +} + static PyObject *PkgManagerGetArchives(PyObject *Self,PyObject *Args) { @@ -98,7 +122,7 @@ PyTypeObject PkgManagerType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "PackageManager", // tp_name + "apt_pkg.PackageManager", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -128,26 +152,16 @@ PyTypeObject PkgManagerType = PkgManagerMethods, // tp_methods 0, // tp_members PkgManagerGetSet, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + PkgManagerNew, // tp_new }; -#include -#include - -PyObject *GetPkgManager(PyObject *Self,PyObject *Args) -{ - PyObject *Owner; - if (PyArg_ParseTuple(Args,"O!",&PkgDepCacheType,&Owner) == 0) - return 0; - - pkgPackageManager *pm = _system->CreatePM(GetCpp(Owner)); - - CppPyObject *PkgManagerObj = - CppPyObject_NEW(&PkgManagerType,pm); - - return PkgManagerObj; -} - - /*}}}*/ diff --git a/python/pkgrecords.cc b/python/pkgrecords.cc index 978de6b7..1cccfce2 100644 --- a/python/pkgrecords.cc +++ b/python/pkgrecords.cc @@ -132,13 +132,25 @@ static PyGetSetDef PkgRecordsGetSet[] = { {} }; +static PyObject *PkgRecordsNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) +{ + PyObject *Owner; + char *kwlist[] = {"cache",0}; + if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PkgCacheType, + &Owner) == 0) + return 0; + + return HandleErrors(CppOwnedPyObject_NEW(Owner,type, + GetCpp(Owner))); +} + PyTypeObject PkgRecordsType = { PyObject_HEAD_INIT(&PyType_Type) #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgRecords", // tp_name + "apt_pkg.PackageRecords", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -168,17 +180,22 @@ PyTypeObject PkgRecordsType = PkgRecordsMethods, // tp_methods 0, // tp_members PkgRecordsGetSet, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + PkgRecordsNew, // tp_new }; /*}}}*/ + + PyObject *GetPkgRecords(PyObject *Self,PyObject *Args) { - PyObject *Owner; - if (PyArg_ParseTuple(Args,"O!",&PkgCacheType,&Owner) == 0) - return 0; - - return HandleErrors(CppOwnedPyObject_NEW(Owner,&PkgRecordsType, - GetCpp(Owner))); + return PkgRecordsNew(&PkgRecordsType,Args,0); } diff --git a/python/pkgsrcrecords.cc b/python/pkgsrcrecords.cc index 97667d7a..8b4dce3e 100644 --- a/python/pkgsrcrecords.cc +++ b/python/pkgsrcrecords.cc @@ -180,13 +180,21 @@ static PyGetSetDef PkgSrcRecordsGetSet[] = { {} }; +static PyObject *PkgSrcRecordsNew(PyTypeObject *type,PyObject *args,PyObject *kwds) { + char *kwlist[] = {0}; + if (PyArg_ParseTupleAndKeywords(args,kwds,"",kwlist) == 0) + return 0; + + return HandleErrors(CppPyObject_NEW(type)); +} + PyTypeObject PkgSrcRecordsType = { PyObject_HEAD_INIT(&PyType_Type) #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgSrcRecords", // tp_name + "apt_pkg.SourceRecords", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -216,6 +224,14 @@ PyTypeObject PkgSrcRecordsType = PkgSrcRecordsMethods, // tp_methods 0, // tp_members PkgSrcRecordsGetSet, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + PkgSrcRecordsNew, // tp_new }; /*}}}*/ diff --git a/python/sourcelist.cc b/python/sourcelist.cc index 48b3b7c8..15311e94 100644 --- a/python/sourcelist.cc +++ b/python/sourcelist.cc @@ -97,13 +97,21 @@ static PyGetSetDef PkgSourceListGetSet[] = { {} }; +static PyObject *PkgSourceListNew(PyTypeObject *type,PyObject *args,PyObject *kwds) +{ + char *kwlist[] = {0}; + if (PyArg_ParseTupleAndKeywords(args,kwds,"",kwlist) == 0) + return 0; + return CppPyObject_NEW(type,new pkgSourceList()); +} + PyTypeObject PkgSourceListType = { PyObject_HEAD_INIT(&PyType_Type) #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "pkgSourceList", // tp_name + "apt_pkg.SourceList", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods @@ -133,6 +141,14 @@ PyTypeObject PkgSourceListType = PkgSourceListMethods, // tp_methods 0, // tp_members PkgSourceListGetSet, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + PkgSourceListNew, // tp_new }; PyObject *GetPkgSourceList(PyObject *Self,PyObject *Args) diff --git a/python/tag.cc b/python/tag.cc index 18d08580..007a6122 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -239,15 +239,14 @@ static PyObject *TagFileJump(PyObject *Self,PyObject *Args) /*}}}*/ // ParseSection - Parse a single section from a tag file /*{{{*/ // --------------------------------------------------------------------- -char *doc_ParseSection ="ParseSection(Text) -> SectionObject"; -PyObject *ParseSection(PyObject *self,PyObject *Args) -{ +static PyObject *TagSecNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) { char *Data; - if (PyArg_ParseTuple(Args,"s",&Data) == 0) + static char *kwlist[] = {"text", 0}; + if (PyArg_ParseTupleAndKeywords(Args,kwds,"s",kwlist,&Data) == 0) return 0; // Create the object.. - TagSecData *New = PyObject_NEW(TagSecData,&TagSecType); + TagSecData *New = PyObject_NEW(TagSecData,type); new (&New->Object) pkgTagSection(); New->Data = new char[strlen(Data)+2]; snprintf(New->Data,strlen(Data)+2,"%s\n",Data); @@ -264,21 +263,28 @@ PyObject *ParseSection(PyObject *self,PyObject *Args) return New; } + +char *doc_ParseSection ="ParseSection(Text) -> TagSection() object. Deprecated."; +PyObject *ParseSection(PyObject *self,PyObject *Args) +{ + return TagSecNew(&TagSecType,Args,0); +} /*}}}*/ // ParseTagFile - Parse a tagd file /*{{{*/ // --------------------------------------------------------------------- /* This constructs the parser state. */ -char *doc_ParseTagFile = "ParseTagFile(File) -> TagFile"; -PyObject *ParseTagFile(PyObject *self,PyObject *Args) + +static PyObject *TagFileNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) { PyObject *File; - if (PyArg_ParseTuple(Args,"O",&File) == 0) + static char *kwlist[] = {"file", 0}; + if (PyArg_ParseTupleAndKeywords(Args,kwds,"O",kwlist,&File) == 0) return 0; int fileno = PyObject_AsFileDescriptor(File); if (fileno == -1) return 0; - TagFileData *New = PyObject_NEW(TagFileData,&TagFileType); + TagFileData *New = PyObject_NEW(TagFileData,type); new (&New->Fd) FileFd(fileno,false); New->File = File; Py_INCREF(New->File); @@ -290,6 +296,10 @@ PyObject *ParseTagFile(PyObject *self,PyObject *Args) New->Section->Data = 0; return HandleErrors(New); +} +char *doc_ParseTagFile = "ParseTagFile(File) -> TagFile() object. Deprecated."; +PyObject *ParseTagFile(PyObject *self,PyObject *Args) { + return TagFileNew(&TagFileType,Args,0); } /*}}}*/ // RewriteSection - Rewrite a section.. /*{{{*/ @@ -381,13 +391,20 @@ static PyMethodDef TagSecMethods[] = PySequenceMethods TagSecSeqMeth = {0,0,0,0,0,0,0,TagSecContains,0,0}; PyMappingMethods TagSecMapMeth = {TagSecLength,TagSecMap,0}; + + +static const char *doc_TagSec = "TagSection(text) -> Create a new object.\n\n" + "TagSection() objects provide methods to access rfc822-style formatted\n" + "header sections, like those in debian/control or Packages files.\n\n" + "TagSection() behave like read-only dictionaries and also provide access\n" + "to the functions provided by the C++ class (e.g. Find)"; PyTypeObject TagSecType = { PyObject_HEAD_INIT(&PyType_Type) #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "TagSection", // tp_name + "apt_pkg.TagSection", // tp_name sizeof(TagSecData), // tp_basicsize 0, // tp_itemsize // Methods @@ -407,14 +424,24 @@ PyTypeObject TagSecType = 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags - "TagSection Object", // tp_doc + doc_TagSec, // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter 0, // tp_iternext - TagSecMethods // tp_methods + TagSecMethods, // tp_methods + 0, // tp_members + 0, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + TagSecNew, // tp_new }; // Method table for the Tag File object @@ -440,6 +467,15 @@ static PyGetSetDef TagFileGetSet[] = { {} }; +static const char *doc_TagFile = "TagFile(file) -> TagFile() object. \n\n" + "TagFile() objects provide access to debian control files, which consists\n" + "of multiple RFC822-like formatted sections.\n\n" + "A file may consists of multiple sections, and you can use Step() to move\n" + "forward. The current TagSection() is available via the attribute section" + ".\n\n" + "The parameter *file* refers to an object providing a fileno() method or\n" + "a file descriptor (an integer)"; + // Type for a Tag File PyTypeObject TagFileType = { @@ -447,7 +483,7 @@ PyTypeObject TagFileType = #if PY_MAJOR_VERSION < 3 0, // ob_size #endif - "TagFile", // tp_name + "apt_pkg.TagFile", // tp_name sizeof(TagFileData), // tp_basicsize 0, // tp_itemsize // Methods @@ -467,7 +503,7 @@ PyTypeObject TagFileType = 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags - "TagFile Object", // tp_doc + doc_TagFile, // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare @@ -476,5 +512,14 @@ PyTypeObject TagFileType = 0, // tp_iternext TagFileMethods, // tp_methods 0, // tp_members - TagFileGetSet // tp_getset + TagFileGetSet, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + TagFileNew, // tp_new + }; -- cgit v1.2.3 From 33293ab8c53a9b1427012c297f288972e11ea3bb Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 8 Jun 2009 17:47:46 +0200 Subject: Add apt_pkg.HashString and apt_pkg.IndexRecords (Closes: #456141) --- debian/changelog | 6 +++ python/apt_pkgmodule.cc | 2 + python/apt_pkgmodule.h | 7 +++ python/hashstring.cc | 140 ++++++++++++++++++++++++++++++++++++++++++++++++ python/indexrecords.cc | 121 +++++++++++++++++++++++++++++++++++++++++ python/makefile | 2 +- 6 files changed, 277 insertions(+), 1 deletion(-) create mode 100644 python/hashstring.cc create mode 100644 python/indexrecords.cc (limited to 'python/apt_pkgmodule.h') diff --git a/debian/changelog b/debian/changelog index ca215554..1a80d081 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +python-apt (0.7.92) experimental; urgency=low + + * Add apt_pkg.HashString and apt_pkg.IndexRecords (Closes: #456141) + + -- Julian Andres Klode Mon, 08 Jun 2009 17:23:37 +0200 + python-apt (0.7.91) experimental; urgency=low [ Julian Andres Klode ] diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 4ad4e56c..085d12f4 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -603,6 +603,8 @@ extern "C" void initapt_pkg() ADDTYPE(Module,"SourceRecords",&PkgSrcRecordsType); /* ========================= sourcelist.cc ========================= */ ADDTYPE(Module,"SourceList",&PkgSourceListType); + ADDTYPE(Module,"IndexRecords",&PyIndexRecords_Type); + ADDTYPE(Module,"HashString",&PyHashString_Type); // Tag file constants PyModule_AddObject(Module,"REWRITE_PACKAGE_ORDER", CharCharToList(TFRewritePackageOrder)); diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index f7ef63c2..043e29cc 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -11,6 +11,7 @@ #define APT_PKGMODULE_H #include +#include // Configuration Stuff #define Configuration_Check(op) ((op)->ob_type == &ConfigurationType || \ @@ -106,5 +107,11 @@ extern PyTypeObject PackageIndexFileType; // metaIndex extern PyTypeObject MetaIndexType; +// HashString +PyObject *PyHashString_FromCpp(HashString *obj); +extern PyTypeObject PyHashString_Type; + +// IndexRecord +extern PyTypeObject PyIndexRecords_Type; #endif diff --git a/python/hashstring.cc b/python/hashstring.cc new file mode 100644 index 00000000..02a80210 --- /dev/null +++ b/python/hashstring.cc @@ -0,0 +1,140 @@ +/* hashstring.cc - Wrapper around HashString + * + * Copyright 2009 Julian Andres Klode + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ +#include +#include "generic.h" +#include "apt_pkgmodule.h" +#include + +static PyObject *HashString_NEW(PyTypeObject *type,PyObject *Args, + PyObject *kwds) +{ + const char *Hash; + const char *Type; + char *kwlist[] = {"type", "hash", NULL}; + if (PyArg_ParseTupleAndKeywords(Args, kwds, "s|s", kwlist, &Type, + &Hash) == 0) + return 0; + CppPyObject *PyObj = CppPyObject_NEW(type); + if (Hash) + PyObj->Object = new HashString(Type,Hash); + else // Type is the combined form now (i.e. type:hash) + PyObj->Object = new HashString(Type); + return PyObj; +} + +PyObject *PyHashString_FromCpp(HashString *obj) +{ + return CppPyObject_NEW(&PyHashString_Type, obj); +} + +static PyObject *HashString_Repr(PyObject *self) +{ + HashString *hash = GetCpp(self); + char repr[100]; + sprintf(repr, "<%s: \"%s\">", self->ob_type->tp_name, hash->toStr().c_str()); + return PyString_FromString(repr); +} + +static PyObject *HashString_ToStr(PyObject *self) +{ + HashString *hash = GetCpp(self); + return CppPyString(hash->toStr()); +} + +static PyObject *HashString_HashType(PyObject *self) +{ + HashString *hash = GetCpp(self); + return CppPyString(hash->HashType()); +} + +static const char *HashString_VerifyFile_doc = + "verify_file(filename: str) --> bool\n\n" + "Verify that the file indicated by filename matches the hash."; + +static PyObject *HashString_VerifyFile(PyObject *self,PyObject *args) +{ + HashString *hash = GetCpp(self); + char *filename; + if (PyArg_ParseTuple(args, "s", &filename) == 0) + return 0; + return PyBool_FromLong(hash->VerifyFile(filename)); +} + +static PyMethodDef HashString_Methods[] = { + {"to_str",(PyCFunction)HashString_ToStr,METH_NOARGS, + "to_str() --> str\n\nReturn a string, consisting of type:hash"}, + {"verify_file",HashString_VerifyFile,METH_VARARGS, + HashString_VerifyFile_doc}, + {"hash_type",(PyCFunction)HashString_HashType,METH_NOARGS, + "hash_type() --> str\n\nReturn the type of hash (MD5Sum,SHA1,SHA256)"}, + {} +}; + +static const char *HashString_doc = + "HashString(type, hash) OR HashString('type:hash')\n\n" + "Create a new HashString object. The first form allows you to specify\n" + "a type and a hash, and the second form a single string where type and\n" + "hash are seperated by a colon, e.g.::\n\n" + " HashString('MD5Sum', '6cc1b6e6655e3555ac47e5b5fe26d04e')\n\n" + "Valid options for 'type' are: MD5Sum, SHA1, SHA256."; +PyTypeObject PyHashString_Type = { + PyObject_HEAD_INIT(&PyType_Type) +#if PY_MAJOR_VERSION < 3 + 0, // ob_size +#endif + "apt_pkg.HashString", // tp_name + sizeof(CppPyObject), // tp_basicsize + 0, // tp_itemsize + // Methods + CppDealloc, // tp_dealloc + 0, // tp_print + 0, // tp_getattr + 0, // tp_setattr + 0, // tp_compare + HashString_Repr, // tp_repr + 0, // tp_as_number + 0, // tp_as_sequence + 0, // tp_as_mapping + 0, // tp_hash + 0, // tp_call + HashString_ToStr, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + Py_TPFLAGS_DEFAULT, // tp_flags + HashString_doc, // tp_doc + 0, // tp_traverse + 0, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + HashString_Methods, // tp_methods + 0, // tp_members + 0, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + HashString_NEW, // tp_new +}; diff --git a/python/indexrecords.cc b/python/indexrecords.cc new file mode 100644 index 00000000..e6099a69 --- /dev/null +++ b/python/indexrecords.cc @@ -0,0 +1,121 @@ +/* + * indexrecords.cc - Wrapper around indexRecords + * + * Copyright 2009 Julian Andres Klode + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ +#include +#include "apt_pkgmodule.h" +#include "generic.h" +#include + +static PyObject *IndexRecords_NEW(PyTypeObject *type,PyObject *Args, + PyObject *kwds) +{ + char * kwlist[] = {NULL}; + if (PyArg_ParseTupleAndKeywords(Args, kwds, "", kwlist) == 0) + return 0; + indexRecords *records = new indexRecords(); + CppPyObject *New = CppPyObject_NEW(type, + records); + return New; +} + +static PyObject *IndexRecords_Load(PyObject *self,PyObject *args) +{ + const char *filename; + if (PyArg_ParseTuple(args, "s", &filename) == 0) + return 0; + indexRecords *records = GetCpp(self); + return HandleErrors(Py_BuildValue("i", records->Load(filename))); +} + +static const char *IndexRecords_Lookup_doc = "lookup(metakey)\n\n" + "Lookup the filename given by metakey, return a tuple (size,hash).\n" + "The hash part is a HashString() object."; +static PyObject *IndexRecords_Lookup(PyObject *self,PyObject *args) +{ + const char *keyname; + if (PyArg_ParseTuple(args, "s", &keyname) == 0) + return 0; + indexRecords *records = GetCpp(self); + const indexRecords::checkSum *result = records->Lookup(keyname); + return Py_BuildValue("(iO)",result->Size, + PyHashString_FromCpp((HashString*)&result->Hash)); +} + +static PyObject *IndexRecords_GetDist(PyObject *self) +{ + indexRecords *records = GetCpp(self); + return HandleErrors(PyString_FromString(records->GetDist().c_str())); +} + +static PyMethodDef IndexRecords_Methods[] = { + {"load",IndexRecords_Load,METH_VARARGS, + "load(filename: str)\n\nLoad the file given by filename."}, + {"get_dist",(PyCFunction)IndexRecords_GetDist,METH_NOARGS, + "get_dist() -> str\n\nReturn a distribution set in the release file."}, + {"lookup",IndexRecords_Lookup,METH_VARARGS,IndexRecords_Lookup_doc}, + {} +}; + +static char *IndexRecords_doc = "IndexRecords()\n\n" + "Representation of a release file."; +PyTypeObject PyIndexRecords_Type = { + PyObject_HEAD_INIT(&PyType_Type) +#if PY_MAJOR_VERSION < 3 + 0, // ob_size +#endif + "apt_pkg.IndexRecords", // tp_name + sizeof(CppPyObject), // tp_basicsize + 0, // tp_itemsize + // Methods + CppDealloc, // tp_dealloc + 0, // tp_print + 0, // 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 + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + Py_TPFLAGS_DEFAULT, // tp_flags + IndexRecords_doc, // tp_doc + 0, // tp_traverse + 0, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + IndexRecords_Methods, // tp_methods + 0, // tp_members + 0, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + IndexRecords_NEW, // tp_new +}; diff --git a/python/makefile b/python/makefile index 3e6458f4..f4d559ce 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 metaindex.cc + indexfile.cc metaindex.cc hashstring.cc indexrecords.cc SOURCE := $(APT_PKG_SRC) include $(PYTHON_H) progress.h -- cgit v1.2.3 From a307f6c405d55895690e16d55de36549f5b05d8b Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 9 Jun 2009 20:44:58 +0200 Subject: Add apt_pkg.Policy class (Closes: #382725) --- debian/changelog | 3 +- python/apt_pkgmodule.cc | 1 + python/apt_pkgmodule.h | 3 + python/makefile | 2 +- python/policy.cc | 189 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 196 insertions(+), 2 deletions(-) create mode 100644 python/policy.cc (limited to 'python/apt_pkgmodule.h') diff --git a/debian/changelog b/debian/changelog index 818bf630..3e85c5be 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,9 +1,10 @@ python-apt (0.7.92) experimental; urgency=low * Add apt_pkg.HashString and apt_pkg.IndexRecords (Closes: #456141) + * Add apt_pkg.Policy class (Closes: #382725) * Allow types providing __new__() to be subclassed. - -- Julian Andres Klode Tue, 09 Jun 2009 18:09:53 +0200 + -- Julian Andres Klode Tue, 09 Jun 2009 20:39:39 +0200 python-apt (0.7.91) experimental; urgency=low diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 95b72de4..3d76894d 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -606,6 +606,7 @@ extern "C" void initapt_pkg() ADDTYPE(Module,"SourceList",&PkgSourceListType); ADDTYPE(Module,"IndexRecords",&PyIndexRecords_Type); ADDTYPE(Module,"HashString",&PyHashString_Type); + ADDTYPE(Module,"Policy",&PyPolicy_Type); // Tag file constants PyModule_AddObject(Module,"REWRITE_PACKAGE_ORDER", CharCharToList(TFRewritePackageOrder)); diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index 043e29cc..21355072 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -114,4 +114,7 @@ extern PyTypeObject PyHashString_Type; // IndexRecord extern PyTypeObject PyIndexRecords_Type; +// Policy +extern PyTypeObject PyPolicy_Type; + #endif diff --git a/python/makefile b/python/makefile index f4d559ce..6799d749 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 metaindex.cc hashstring.cc indexrecords.cc + indexfile.cc metaindex.cc hashstring.cc indexrecords.cc policy.cc SOURCE := $(APT_PKG_SRC) include $(PYTHON_H) progress.h diff --git a/python/policy.cc b/python/policy.cc new file mode 100644 index 00000000..89604e9a --- /dev/null +++ b/python/policy.cc @@ -0,0 +1,189 @@ +/* + * policy.cc - Wrapper around pkgPolicy + * + * Copyright 2009 Julian Andres Klode + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ +#include +#include "apt_pkgmodule.h" +#include "generic.h" +#include + +static PyObject *Policy_NEW(PyTypeObject *type,PyObject *Args, + PyObject *kwds) { + PyObject *cache; + char *kwlist[] = {"cache", NULL}; + if (PyArg_ParseTupleAndKeywords(Args, kwds, "O", kwlist, &cache) == 0) + return 0; + if (!PyObject_TypeCheck(cache, &PkgCacheType)) { + PyErr_SetString(PyExc_TypeError,"`cache` must be a apt_pkg.Cache()."); + return 0; + } + pkgPolicy *policy = new pkgPolicy(GetCpp(cache)); + return CppOwnedPyObject_NEW(cache,&PyPolicy_Type,policy); +} + +static char *Policy_GetPriority_doc = "get_priority(package: apt_pkg.Package)" + " -> int\n\n" + "Return the priority of the package."; + +PyObject *Policy_GetPriority(PyObject *self, PyObject *arg) { + pkgPolicy *policy = GetCpp(self); + if (PyObject_TypeCheck(arg, &PackageType)) { + pkgCache::PkgIterator pkg = GetCpp(arg); + return Py_BuildValue("i", policy->GetPriority(pkg)); + } else { + PyErr_SetString(PyExc_TypeError,"Argument must be of Package()."); + return 0; + } +} + +static char *Policy_GetCandidateVer_doc = "get_match(package: apt_pkg.Package)" + " -> apt_pkg.Version\n\n" + "Get the best package for the job."; + +PyObject *Policy_GetCandidateVer(PyObject *self, PyObject *arg) { + if (PyObject_TypeCheck(arg, &PackageType)) { + pkgPolicy *policy = GetCpp(self); + pkgCache::PkgIterator pkg = GetCpp(arg); + pkgCache::VerIterator ver = policy->GetCandidateVer(pkg); + return CppOwnedPyObject_NEW(arg,&VersionType, + ver); + } else { + PyErr_SetString(PyExc_TypeError,"Argument must be of Package()."); + return 0; + } +} + +static char *Policy_GetMatch_doc = "get_match(package: apt_pkg.Package) -> " + "apt_pkg.Version\n\n" + "Return a matching version for the given package."; + +static PyObject *Policy_GetMatch(PyObject *self, PyObject *arg) { + if (PyObject_TypeCheck(arg, &PackageType) == 0) { + PyErr_SetString(PyExc_TypeError,"Argument must be of Package()."); + return 0; + } + pkgPolicy *policy = GetCpp(self); + pkgCache::PkgIterator pkg = GetCpp(arg); + pkgCache::VerIterator ver = policy->GetMatch(pkg); + return CppOwnedPyObject_NEW(arg,&VersionType,ver); +} + +static char *Policy_ReadPinFile_doc = "read_pinfile(filename: str) -> bool\n\n" + "Read the pin file given by filename (e.g. '/etc/apt/preferences') and\n" + "add it to the policy."; + +static PyObject *Policy_ReadPinFile(PyObject *self, PyObject *arg) { + if (!PyString_Check(arg)) + return 0; + pkgPolicy *policy = GetCpp(self); + + return PyBool_FromLong(ReadPinFile(*policy, PyString_AsString(arg))); +} + +static char *Policy_CreatePin_doc = "create_pin(type: str, pkg: str, " + "data: str, priority: int)\n\n" + "Create a pin for the policy. The parameter 'type' refers to one of the\n" + "following strings: 'Version', 'Release', 'Origin'. The argument 'pkg'\n" + "is the name of the package, the parameter 'data' refers to the value\n" + "e.g. unstable for type='Release' and the other possible options. \n" + "The parameter 'priority' gives the priority of the pin."; + +static PyObject *Policy_CreatePin(PyObject *self, PyObject *args) { + pkgVersionMatch::MatchType match_type; + const char *type, *pkg, *data; + signed short priority; + if (PyArg_ParseTuple(args, "sssh", &type, &pkg, &data, &priority) == 0) + return 0; + pkgPolicy *policy = GetCpp(self); + if (type == "Version" || type == "version") + match_type = pkgVersionMatch::Version; + if (type == "Release" || type == "release") + match_type = pkgVersionMatch::Release; + if (type == "Origin" || type == "origin") + match_type = pkgVersionMatch::Origin; + else + match_type = pkgVersionMatch::None; + policy->CreatePin(match_type,pkg,data,priority); + HandleErrors(); + Py_RETURN_NONE; +} + +static PyMethodDef Policy_Methods[] = { + {"get_priority",(PyCFunction)Policy_GetPriority,METH_O, + Policy_GetPriority_doc}, + {"get_candidate_ver",(PyCFunction)Policy_GetCandidateVer,METH_O, + Policy_GetCandidateVer_doc}, + {"read_pinfile",(PyCFunction)Policy_ReadPinFile,METH_O, + Policy_ReadPinFile_doc}, + {"create_pin",Policy_CreatePin,METH_VARARGS,Policy_CreatePin_doc}, + {"get_match",(PyCFunction)Policy_GetMatch,METH_O, Policy_GetMatch_doc}, + {} +}; + +static char *Policy_doc = "Policy(cache)\n\n" + "Representation of the policy of the Cache object given by cache. This\n" + "provides a superset of policy-related functionality compared to the\n" + "DepCache class. The DepCache can be used for most purposes, but there\n" + "may be some cases where a special policy class is needed."; + +PyTypeObject PyPolicy_Type = { + PyObject_HEAD_INIT(&PyType_Type) +#if PY_MAJOR_VERSION < 3 + 0, // ob_size +#endif + "apt_pkg.Policy", // tp_name + sizeof(CppOwnedPyObject),// tp_basicsize + 0, // tp_itemsize + // Methods + CppOwnedDealloc, // tp_dealloc + 0, // tp_print + 0, // 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 + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + (Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE), + Policy_doc, // tp_doc + 0, // tp_traverse + 0, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + Policy_Methods, // tp_methods + 0, // tp_members + 0, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + Policy_NEW, // tp_new +}; -- cgit v1.2.3 From 5b489a994d009771d7f4d5beec45bbbb5468cd58 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sun, 12 Jul 2009 19:07:55 +0200 Subject: python/hashes.cc: Introduce the Hashes class. The Hashes class is a function which calculates all supported hashes for one input. DebImg will use this for calculating the hashes of files. --- debian/changelog | 3 +- doc/source/apt_pkg.rst | 26 +++++++-- python/apt_pkgmodule.cc | 1 + python/apt_pkgmodule.h | 1 + python/hashes.cc | 136 ++++++++++++++++++++++++++++++++++++++++++++++++ python/makefile | 5 +- 6 files changed, 164 insertions(+), 8 deletions(-) create mode 100644 python/hashes.cc (limited to 'python/apt_pkgmodule.h') diff --git a/debian/changelog b/debian/changelog index 8bc3e320..1f43cc8c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -30,6 +30,7 @@ python-apt (0.7.92) UNRELEASED; urgency=low + Closes: #468123 - there is no need anymore for binding CompType or CompTypeDeb, because we don't return integer values for CompType anymore. + * Introduce apt_pkg.Hashes class. [ Sebastian Heinlein ] * apt/progress.py: Extract the package name from the status message @@ -45,7 +46,7 @@ python-apt (0.7.92) UNRELEASED; urgency=low * python/progress.cc: - low level code for update_status_full and pulse_items() - -- Julian Andres Klode Tue, 07 Jul 2009 16:56:44 +0200 + -- Julian Andres Klode Sun, 12 Jul 2009 18:51:57 +0200 python-apt (0.7.91) experimental; urgency=low diff --git a/doc/source/apt_pkg.rst b/doc/source/apt_pkg.rst index 2af934a0..9a14266e 100644 --- a/doc/source/apt_pkg.rst +++ b/doc/source/apt_pkg.rst @@ -1139,15 +1139,31 @@ installation. the file using the parameter *destfile*. You can not combine both. +Hashes +------ +The apt_pkg module also provides several hash functions. If you develop +applications with python-apt it is often easier to use these functions instead +of the ones provides in Python's :mod:`hashlib` module. +.. class:: Hashes(object) + Calculate all supported hashes of the object. *object* may either be a + string, in which cases the hashes of the string are calculated, or a + :class:`file()` object or file descriptor, in which case the hashes of + its contents is calculated. The calculated hashes are then available via + attributes: + .. attribute:: md5 -Hash functions --------------- -The apt_pkg module also provides several hash functions. If you develop -applications with python-apt it is often easier to use these functions instead -of the ones provides in Python's :mod:`hashlib` module. + The MD5 hash of the data, as string. + + .. attribute:: sha1 + + The SHA1 hash of the data, as string. + + .. attribute:: sha256 + + The SHA256 hash of the data, as string. .. function:: md5sum(object) diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 3f4aae37..4c0fd5ed 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -618,6 +618,7 @@ extern "C" void initapt_pkg() ADDTYPE(Module,"IndexRecords",&PyIndexRecords_Type); ADDTYPE(Module,"HashString",&PyHashString_Type); ADDTYPE(Module,"Policy",&PyPolicy_Type); + ADDTYPE(Module,"Hashes",&PyHashes_Type); // Tag file constants PyModule_AddObject(Module,"REWRITE_PACKAGE_ORDER", CharCharToList(TFRewritePackageOrder)); diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index 21355072..1a2f1a1a 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -116,5 +116,6 @@ extern PyTypeObject PyIndexRecords_Type; // Policy extern PyTypeObject PyPolicy_Type; +extern PyTypeObject PyHashes_Type; #endif diff --git a/python/hashes.cc b/python/hashes.cc new file mode 100644 index 00000000..a1ace6fc --- /dev/null +++ b/python/hashes.cc @@ -0,0 +1,136 @@ +/* hashes.cc - Wrapper around apt-pkg's Hashes. + * + * Copyright 2009 Julian Andres Klode + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ +#include +#include "generic.h" +#include "apt_pkgmodule.h" +#include + +static PyObject *hashes_new(PyTypeObject *type,PyObject *args, + PyObject *kwds) +{ + return CppPyObject_NEW(type); +} + +static int hashes_init(PyObject *self, PyObject *args, PyObject *kwds) +{ + PyObject *object = 0; + int Fd; + char *kwlist[] = {"object", NULL}; + + if (PyArg_ParseTupleAndKeywords(args, kwds, "|O:__init__", kwlist, + &object) == 0) + return -1; + if (object == 0) + return 0; + Hashes &hashes = GetCpp(self); + + if (PyBytes_Check(object) != 0) { + char *s; + Py_ssize_t len; + PyBytes_AsStringAndSize(object, &s, &len); + hashes.Add((const unsigned char*)s, len); + } + else if ((Fd = PyObject_AsFileDescriptor(object)) != -1) { + struct stat St; + if (fstat(Fd, &St) != 0 || hashes.AddFD(Fd, St.st_size) == false) { + PyErr_SetFromErrno(PyExc_SystemError); + return -1; + } + } + else { + PyErr_SetString(PyExc_TypeError, "__init__() only understand strings" + " and files"); + return -1; + } + return 0; +} + +static PyObject *hashes_get_md5(PyObject *self, void*) +{ + return CppPyString(GetCpp(self).MD5.Result().Value()); +} + +static PyObject *hashes_get_sha1(PyObject *self, void*) +{ + return CppPyString(GetCpp(self).SHA1.Result().Value()); +} + +static PyObject *hashes_get_sha256(PyObject *self, void*) +{ + return CppPyString(GetCpp(self).SHA256.Result().Value()); +} + +static PyGetSetDef hashes_getset[] = { + {"md5",hashes_get_md5,0,"The MD5Sum of the file as a string."}, + {"sha1",hashes_get_sha1,0,"The SHA1Sum of the file as a string."}, + {"sha256",hashes_get_sha256,0,"The SHA256Sum of the file as a string."}, + {} +}; + +static char *hashes_doc = + "Hashes([object: (bytes, file)])\n\n" + "Calculate hashes for the given object. It can be used to create all\n" + "supported hashes for a file.\n\n" + "The parameter *object* can be a bytes (3.X) / str (2.X) object, or an\n" + "object providing the fileno() method or an integer describing a file\n" + "descriptor."; + +PyTypeObject PyHashes_Type = { + PyVarObject_HEAD_INIT(&PyType_Type, 0) + "apt_pkg.Hashes", // tp_name + sizeof(CppPyObject), // tp_basicsize + 0, // tp_itemsize + // Methods + CppDealloc, // tp_dealloc + 0, // tp_print + 0, // 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 + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE, + hashes_doc, // tp_doc + 0, // tp_traverse + 0, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + 0, // tp_methods + 0, // tp_members + hashes_getset, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + hashes_init, // tp_init + 0, // tp_alloc + hashes_new, // tp_new +}; diff --git a/python/makefile b/python/makefile index 6799d749..fff3a2e8 100644 --- a/python/makefile +++ b/python/makefile @@ -11,8 +11,9 @@ 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 \ - indexfile.cc metaindex.cc hashstring.cc indexrecords.cc policy.cc + depcache.cc progress.cc cdrom.cc acquire.cc pkgmanager.cc \ + indexfile.cc metaindex.cc hashstring.cc indexrecords.cc \ + policy.cc hashes.cc SOURCE := $(APT_PKG_SRC) include $(PYTHON_H) progress.h -- cgit v1.2.3 From dabc8c6796afdaf0e2918db77117a07eae8b1fd4 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 13 Jul 2009 14:25:06 +0200 Subject: python: Rename all PyTypeObject's to conform to PEP 7. This is the first step towards implementing coding guidelines for the C++ code and providing an usable C++ API. --- python/acquire.cc | 18 +++++++------- python/apt_pkgmodule.cc | 62 +++++++++++++++++++++++------------------------ python/apt_pkgmodule.h | 60 +++++++++++++++++++++++----------------------- python/cache.cc | 60 +++++++++++++++++++++++----------------------- python/cdrom.cc | 4 ++-- python/configuration.cc | 16 ++++++------- python/depcache.cc | 64 ++++++++++++++++++++++++------------------------- python/indexfile.cc | 2 +- python/metaindex.cc | 4 ++-- python/pkgmanager.cc | 12 +++++----- python/pkgrecords.cc | 8 +++---- python/pkgsrcrecords.cc | 6 ++--- python/policy.cc | 12 +++++----- python/sourcelist.cc | 14 +++++------ python/tag.cc | 12 +++++----- 15 files changed, 177 insertions(+), 177 deletions(-) (limited to 'python/apt_pkgmodule.h') diff --git a/python/acquire.cc b/python/acquire.cc index 054956ea..4329e790 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -140,7 +140,7 @@ static void AcquireItemDealloc(PyObject *self) { -PyTypeObject AcquireItemType = +PyTypeObject PyAcquireItem_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.AcquireItem", // tp_name @@ -238,7 +238,7 @@ static PyObject *PkgAcquireGetItems(PyObject *Self,void*) I != fetcher->ItemsEnd(); I++) { PyAcquireItemObject *Obj; - Obj = CppOwnedPyObject_NEW(Self,&AcquireItemType,*I); + Obj = CppOwnedPyObject_NEW(Self,&PyAcquireItem_Type,*I); Obj->NoDelete = true; PyList_Append(List,Obj); ((PyAcquireObject *)Self)->items.push_back(Obj); @@ -305,7 +305,7 @@ static char *doc_PkgAcquire = "Acquire(progress) -> Acquire() object.\n\n" "specify a apt.progress.FetchProgress() object, which will display the\n" "progress of the fetching."; -PyTypeObject PkgAcquireType = +PyTypeObject PyAcquire_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Acquire", // tp_name @@ -354,7 +354,7 @@ PyObject *GetAcquire(PyObject *Self,PyObject *Args) { PyErr_WarnEx(PyExc_DeprecationWarning,"apt_pkg.GetAcquire() is deprecated." " Please see apt_pkg.Acquire() for the replacement.", 1); - return PkgAcquireNew(&PkgAcquireType,Args,0); + return PkgAcquireNew(&PyAcquire_Type,Args,0); } #endif @@ -369,7 +369,7 @@ static PyObject *PkgAcquireFileNew(PyTypeObject *type, PyObject *Args, PyObject "destdir", "destfile", NULL}; if (PyArg_ParseTupleAndKeywords(Args, kwds, "O!s|sissss", kwlist, - &PkgAcquireType, &pyfetcher, &uri, &md5, + &PyAcquire_Type, &pyfetcher, &uri, &md5, &size, &descr, &shortDescr, &destDir, &destFile) == 0) return 0; @@ -397,7 +397,7 @@ static char *doc_PkgAcquireFile = "The parameter *owner* refers to an apt_pkg.Acquire() object. You can use\n" "*destdir* OR *destfile* to specify the destination directory/file."; -PyTypeObject PkgAcquireFileType = +PyTypeObject PyAcquireFile_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.AcquireFile", // tp_name @@ -432,7 +432,7 @@ PyTypeObject PkgAcquireFileType = 0, // tp_methods 0, // tp_members 0, // tp_getset - &AcquireItemType, // tp_base + &PyAcquireItem_Type, // tp_base 0, // tp_dict 0, // tp_descr_get 0, // tp_descr_set @@ -459,7 +459,7 @@ PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject * kwds) "destDir", "destFile", NULL}; if (PyArg_ParseTupleAndKeywords(Args, kwds, "O!s|sissss", kwlist, - &PkgAcquireType, &pyfetcher, &uri, &md5, + &PyAcquire_Type, &pyfetcher, &uri, &md5, &size, &descr, &shortDescr, &destDir, &destFile) == 0) return 0; @@ -472,7 +472,7 @@ PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject * kwds) shortDescr, destDir, destFile); // short-desc - CppPyObject *AcqFileObj = CppPyObject_NEW(&PkgAcquireFileType); + CppPyObject *AcqFileObj = CppPyObject_NEW(&PyAcquireFile_Type); AcqFileObj->Object = af; AcqFileObj->NoDelete = true; diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 4c0fd5ed..d236820a 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -36,7 +36,7 @@ static PyObject *newConfiguration(PyObject *self,PyObject *args) { PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.newConfiguration() is " "deprecated. Use apt_pkg.Configuration() instead.", 1); - return CppPyObject_NEW(&ConfigurationType); + return CppPyObject_NEW(&PyConfiguration_Type); } #endif /*}}}*/ @@ -556,9 +556,9 @@ extern "C" void initapt_pkg() #endif { // Finalize our types to add slots, etc. - if (PyType_Ready(&ConfigurationPtrType) == -1) INIT_ERROR; - if (PyType_Ready(&ConfigurationSubType) == -1) INIT_ERROR; - if (PyType_Ready(&PkgCacheFileType) == -1) INIT_ERROR; + if (PyType_Ready(&PyConfigurationPtr_Type) == -1) INIT_ERROR; + if (PyType_Ready(&PyConfigurationSub_Type) == -1) INIT_ERROR; + if (PyType_Ready(&PyCacheFile_Type) == -1) INIT_ERROR; // Initialize the module #if PY_MAJOR_VERSION >= 3 @@ -568,7 +568,7 @@ extern "C" void initapt_pkg() #endif // Global variable linked to the global configuration class - CppPyObject *Config = CppPyObject_NEW(&ConfigurationPtrType); + CppPyObject *Config = CppPyObject_NEW(&PyConfigurationPtr_Type); Config->Object = _config; PyModule_AddObject(Module,"config",Config); #ifdef COMPAT_0_7 @@ -578,43 +578,43 @@ extern "C" void initapt_pkg() // Add our classes. /* ============================ tag.cc ============================ */ - ADDTYPE(Module,"TagSection",&TagSecType); - ADDTYPE(Module,"TagFile",&TagFileType); + ADDTYPE(Module,"TagSection",&PyTagSection_Type); + ADDTYPE(Module,"TagFile",&PyTagFile_Type); /* ============================ acquire.cc ============================ */ - ADDTYPE(Module,"Acquire",&PkgAcquireType); - ADDTYPE(Module,"AcquireFile",&PkgAcquireFileType); - ADDTYPE(Module,"AcquireItem",&AcquireItemType); // NO __new__() + ADDTYPE(Module,"Acquire",&PyAcquire_Type); + ADDTYPE(Module,"AcquireFile",&PyAcquireFile_Type); + ADDTYPE(Module,"AcquireItem",&PyAcquireItem_Type); // NO __new__() /* ============================ cache.cc ============================ */ - ADDTYPE(Module,"Cache",&PkgCacheType); - ADDTYPE(Module,"Dependency",&DependencyType); // NO __new__() - ADDTYPE(Module,"Description",&DescriptionType); // NO __new__() - ADDTYPE(Module,"PackageFile",&PackageFileType); // NO __new__() - ADDTYPE(Module,"PackageList",&PkgListType); // NO __new__(), internal - ADDTYPE(Module,"DependencyList",&RDepListType); // NO __new__(), internal - ADDTYPE(Module,"Package",&PackageType); // NO __new__() - ADDTYPE(Module,"Version",&VersionType); // NO __new__() + ADDTYPE(Module,"Cache",&PyCache_Type); + ADDTYPE(Module,"Dependency",&PyDependency_Type); // NO __new__() + ADDTYPE(Module,"Description",&PyDescription_Type); // NO __new__() + ADDTYPE(Module,"PackageFile",&PyPackageFile_Type); // NO __new__() + ADDTYPE(Module,"PackageList",&PyPackageList_Type); // NO __new__(), internal + ADDTYPE(Module,"DependencyList",&PyDependencyList_Type); // NO __new__(), internal + ADDTYPE(Module,"Package",&PyPackage_Type); // NO __new__() + ADDTYPE(Module,"Version",&PyVersion_Type); // NO __new__() /* ============================ cdrom.cc ============================ */ - ADDTYPE(Module,"Cdrom",&PkgCdromType); + ADDTYPE(Module,"Cdrom",&PyCdrom_Type); /* ========================= configuration.cc ========================= */ - ADDTYPE(Module,"Configuration",&ConfigurationType); - //ADDTYPE(Module,"ConfigurationSub",&ConfigurationSubType); // NO __new__() - //ADDTYPE(Module,"ConfigurationPtr",&ConfigurationPtrType); // NO __new__() + ADDTYPE(Module,"Configuration",&PyConfiguration_Type); + //ADDTYPE(Module,"ConfigurationSub",&PyConfigurationSub_Type); // NO __new__() + //ADDTYPE(Module,"ConfigurationPtr",&PyConfigurationPtr_Type); // NO __new__() /* ========================= depcache.cc ========================= */ - ADDTYPE(Module,"ActionGroup",&PkgActionGroupType); - ADDTYPE(Module,"DepCache",&PkgDepCacheType); - ADDTYPE(Module,"ProblemResolver",&PkgProblemResolverType); + ADDTYPE(Module,"ActionGroup",&PyActionGroup_Type); + ADDTYPE(Module,"DepCache",&PyDepCache_Type); + ADDTYPE(Module,"ProblemResolver",&PyProblemResolver_Type); /* ========================= indexfile.cc ========================= */ - ADDTYPE(Module,"PackageIndexFile",&PackageIndexFileType); // NO __new__() + ADDTYPE(Module,"PackageIndexFile",&PyPackageIndexFile_Type); // NO __new__() /* ========================= metaindex.cc ========================= */ - ADDTYPE(Module,"MetaIndex",&MetaIndexType); // NO __new__() + ADDTYPE(Module,"MetaIndex",&PyMetaIndex_Type); // NO __new__() /* ========================= pkgmanager.cc ========================= */ - ADDTYPE(Module,"PackageManager",&PkgManagerType); + ADDTYPE(Module,"PackageManager",&PyPackageManager_Type); /* ========================= pkgrecords.cc ========================= */ - ADDTYPE(Module,"PackageRecords",&PkgRecordsType); + ADDTYPE(Module,"PackageRecords",&PyPackageRecords_Type); /* ========================= pkgsrcrecords.cc ========================= */ - ADDTYPE(Module,"SourceRecords",&PkgSrcRecordsType); + ADDTYPE(Module,"SourceRecords",&PySourceRecords_Type); /* ========================= sourcelist.cc ========================= */ - ADDTYPE(Module,"SourceList",&PkgSourceListType); + ADDTYPE(Module,"SourceList",&PySourceList_Type); ADDTYPE(Module,"IndexRecords",&PyIndexRecords_Type); ADDTYPE(Module,"HashString",&PyHashString_Type); ADDTYPE(Module,"Policy",&PyPolicy_Type); diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index 1a2f1a1a..7b835ca8 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -14,13 +14,13 @@ #include // Configuration Stuff -#define Configuration_Check(op) ((op)->ob_type == &ConfigurationType || \ - (op)->ob_type == &ConfigurationPtrType || \ - (op)->ob_type == &ConfigurationSubType) -extern PyTypeObject ConfigurationType; -extern PyTypeObject ConfigurationPtrType; -extern PyTypeObject ConfigurationSubType; -extern PyTypeObject VersionType; +#define Configuration_Check(op) ((op)->ob_type == &PyConfiguration_Type || \ + (op)->ob_type == &PyConfigurationPtr_Type || \ + (op)->ob_type == &PyConfigurationSub_Type) +extern PyTypeObject PyConfiguration_Type; +extern PyTypeObject PyConfigurationPtr_Type; +extern PyTypeObject PyConfigurationSub_Type; +extern PyTypeObject PyVersion_Type; extern char *doc_LoadConfig; extern char *doc_LoadConfigISC; @@ -32,8 +32,8 @@ PyObject *LoadConfigDir(PyObject *Self,PyObject *Args); PyObject *ParseCommandLine(PyObject *Self,PyObject *Args); // Tag File Stuff -extern PyTypeObject TagSecType; -extern PyTypeObject TagFileType; +extern PyTypeObject PyTagSection_Type; +extern PyTypeObject PyTagFile_Type; extern char *doc_ParseSection; extern char *doc_ParseTagFile; extern char *doc_RewriteSection; @@ -54,58 +54,58 @@ PyObject *StrStrToTime(PyObject *self,PyObject *Args); PyObject *StrCheckDomainList(PyObject *Self,PyObject *Args); // Cache Stuff -extern PyTypeObject PkgCacheType; -extern PyTypeObject PkgCacheFileType; -extern PyTypeObject PkgListType; -extern PyTypeObject DescriptionType; -extern PyTypeObject PackageType; -extern PyTypeObject PackageFileType; -extern PyTypeObject DependencyType; -extern PyTypeObject RDepListType; +extern PyTypeObject PyCache_Type; +extern PyTypeObject PyCacheFile_Type; +extern PyTypeObject PyPackageList_Type; +extern PyTypeObject PyDescription_Type; +extern PyTypeObject PyPackage_Type; +extern PyTypeObject PyPackageFile_Type; +extern PyTypeObject PyDependency_Type; +extern PyTypeObject PyDependencyList_Type; PyObject *TmpGetCache(PyObject *Self,PyObject *Args); // DepCache -extern PyTypeObject PkgDepCacheType; +extern PyTypeObject PyDepCache_Type; PyObject *GetDepCache(PyObject *Self,PyObject *Args); // pkgProblemResolver -extern PyTypeObject PkgProblemResolverType; +extern PyTypeObject PyProblemResolver_Type; PyObject *GetPkgProblemResolver(PyObject *Self, PyObject *Args); PyObject *GetPkgActionGroup(PyObject *Self, PyObject *Args); -extern PyTypeObject PkgActionGroupType; +extern PyTypeObject PyActionGroup_Type; // cdrom -extern PyTypeObject PkgCdromType; +extern PyTypeObject PyCdrom_Type; PyObject *GetCdrom(PyObject *Self,PyObject *Args); // acquire -extern PyTypeObject AcquireItemType; -extern PyTypeObject PkgAcquireType; -extern PyTypeObject PkgAcquireFileType; +extern PyTypeObject PyAcquireItem_Type; +extern PyTypeObject PyAcquire_Type; +extern PyTypeObject PyAcquireFile_Type; extern char *doc_GetPkgAcqFile; PyObject *GetAcquire(PyObject *Self,PyObject *Args); PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject *kwds); // packagemanager -extern PyTypeObject PkgManagerType; +extern PyTypeObject PyPackageManager_Type; PyObject *GetPkgManager(PyObject *Self,PyObject *Args); // PkgRecords Stuff -extern PyTypeObject PkgRecordsType; -extern PyTypeObject PkgSrcRecordsType; +extern PyTypeObject PyPackageRecords_Type; +extern PyTypeObject PySourceRecords_Type; PyObject *GetPkgRecords(PyObject *Self,PyObject *Args); PyObject *GetPkgSrcRecords(PyObject *Self,PyObject *Args); // pkgSourceList -extern PyTypeObject PkgSourceListType; +extern PyTypeObject PySourceList_Type; PyObject *GetPkgSourceList(PyObject *Self,PyObject *Args); // pkgSourceList -extern PyTypeObject PackageIndexFileType; +extern PyTypeObject PyPackageIndexFile_Type; // metaIndex -extern PyTypeObject MetaIndexType; +extern PyTypeObject PyMetaIndex_Type; // HashString PyObject *PyHashString_FromCpp(HashString *obj); diff --git a/python/cache.cc b/python/cache.cc index 40d7b18a..d3a8a949 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -62,7 +62,7 @@ static PyObject *CreateProvides(PyObject *Owner,pkgCache::PrvIterator I) { PyObject *Obj; PyObject *Ver; - Ver = CppOwnedPyObject_NEW(Owner,&VersionType, + Ver = CppOwnedPyObject_NEW(Owner,&PyVersion_Type, I.OwnerVer()); Obj = Py_BuildValue("ssN",I.ParentPkg().Name(),I.ProvideVersion(), Ver); @@ -150,7 +150,7 @@ static PyMethodDef PkgCacheMethods[] = static PyObject *PkgCacheGetPackages(PyObject *Self, void*) { pkgCache *Cache = GetCpp(Self); - return CppOwnedPyObject_NEW(Self,&PkgListType,Cache->PkgBegin()); + return CppOwnedPyObject_NEW(Self,&PyPackageList_Type,Cache->PkgBegin()); } static PyObject *PkgCacheGetPackageCount(PyObject *Self, void*) { @@ -188,7 +188,7 @@ static PyObject *PkgCacheGetFileList(PyObject *Self, void*) { for (pkgCache::PkgFileIterator I = Cache->FileBegin(); I.end() == false; I++) { PyObject *Obj; - Obj = CppOwnedPyObject_NEW(Self,&PackageFileType,I); + Obj = CppOwnedPyObject_NEW(Self,&PyPackageFile_Type,I); PyList_Append(List,Obj); Py_DECREF(Obj); } @@ -238,7 +238,7 @@ static PyObject *CacheMapOp(PyObject *Self,PyObject *Arg) return 0; } - return CppOwnedPyObject_NEW(Self,&PackageType,Pkg); + return CppOwnedPyObject_NEW(Self,&PyPackage_Type,Pkg); } static PyObject *PkgCacheNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) @@ -279,7 +279,7 @@ static PyObject *PkgCacheNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) } CppOwnedPyObject *CacheFileObj = - CppOwnedPyObject_NEW(0,&PkgCacheFileType, Cache); + CppOwnedPyObject_NEW(0,&PyCacheFile_Type, Cache); CppOwnedPyObject *CacheObj = CppOwnedPyObject_NEW(CacheFileObj,type, @@ -299,7 +299,7 @@ static char *doc_PkgCache = "Cache([progress]) -> Cache() object.\n\n" "If not specified, the progress is displayed in simple text form."; static PyMappingMethods CacheMap = {0,CacheMapOp,0}; -PyTypeObject PkgCacheType = +PyTypeObject PyCache_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Cache", // tp_name @@ -346,7 +346,7 @@ PyTypeObject PkgCacheType = /*}}}*/ // PkgCacheFile Class /*{{{*/ // --------------------------------------------------------------------- -PyTypeObject PkgCacheFileType = +PyTypeObject PyCacheFile_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "pkgCacheFile", // tp_name @@ -404,7 +404,7 @@ static PyObject *PkgListItem(PyObject *iSelf,Py_ssize_t Index) } } - return CppOwnedPyObject_NEW(GetOwner(iSelf),&PackageType, + return CppOwnedPyObject_NEW(GetOwner(iSelf),&PyPackage_Type, Self.Iter); } @@ -419,7 +419,7 @@ static PySequenceMethods PkgListSeq = 0 // assign slice }; -PyTypeObject PkgListType = +PyTypeObject PyPackageList_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.PackageList", // tp_name @@ -457,7 +457,7 @@ PyTypeObject PkgListType = MkGet(PackageGetName,PyString_FromString(Pkg.Name())); MkGet(PackageGetSection,Safe_FromString(Pkg.Section())); MkGet(PackageGetRevDependsList,CppOwnedPyObject_NEW(Owner, - &RDepListType, Pkg.RevDependsList())); + &PyDependencyList_Type, Pkg.RevDependsList())); MkGet(PackageGetProvidesList,CreateProvides(Owner,Pkg.ProvidesList())); MkGet(PackageGetSelectedState,Py_BuildValue("i",Pkg->SelectedState)); MkGet(PackageGetInstState,Py_BuildValue("i",Pkg->InstState)); @@ -479,7 +479,7 @@ static PyObject *PackageGetVersionList(PyObject *Self,void*) for (pkgCache::VerIterator I = Pkg.VersionList(); I.end() == false; I++) { PyObject *Obj; - Obj = CppOwnedPyObject_NEW(Owner,&VersionType,I); + Obj = CppOwnedPyObject_NEW(Owner,&PyVersion_Type,I); PyList_Append(List,Obj); Py_DECREF(Obj); } @@ -494,7 +494,7 @@ static PyObject *PackageGetCurrentVer(PyObject *Self,void*) Py_INCREF(Py_None); return Py_None; } - return CppOwnedPyObject_NEW(Owner,&VersionType, + return CppOwnedPyObject_NEW(Owner,&PyVersion_Type, Pkg.CurrentVer()); } @@ -541,7 +541,7 @@ static PyObject *PackageRepr(PyObject *Self) return PyString_FromString(S); } -PyTypeObject PackageType = +PyTypeObject PyPackage_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Package", // tp_name @@ -599,7 +599,7 @@ static PyObject *DescriptionGetFileList(PyObject *Self,void*) { PyObject *DescFile; PyObject *Obj; - DescFile = CppOwnedPyObject_NEW(Owner,&PackageFileType,I.File()); + DescFile = CppOwnedPyObject_NEW(Owner,&PyPackageFile_Type,I.File()); Obj = Py_BuildValue("Nl",DescFile,I.Index()); PyList_Append(List,Obj); Py_DECREF(Obj); @@ -629,7 +629,7 @@ static PyObject *DescriptionRepr(PyObject *Self) return PyString_FromString(S); } -PyTypeObject DescriptionType = +PyTypeObject PyDescription_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Description", // tp_name @@ -711,7 +711,7 @@ static PyObject *MakeDepends(PyObject *Owner,pkgCache::VerIterator &Ver, { PyObject *Obj; if (AsObj == true) - Obj = CppOwnedPyObject_NEW(Owner,&DependencyType, + Obj = CppOwnedPyObject_NEW(Owner,&PyDependency_Type, Start); else { @@ -763,7 +763,7 @@ static PyObject *VersionGetFileList(PyObject *Self, void*) { { PyObject *PkgFile; PyObject *Obj; - PkgFile = CppOwnedPyObject_NEW(Owner,&PackageFileType,I.File()); + PkgFile = CppOwnedPyObject_NEW(Owner,&PyPackageFile_Type,I.File()); Obj = Py_BuildValue("Nl",PkgFile,I.Index()); PyList_Append(List,Obj); Py_DECREF(Obj); @@ -783,7 +783,7 @@ static PyObject *VersionGetDependsList(PyObject *Self, void*) { } static PyObject *VersionGetParentPkg(PyObject *Self, void*) { PyObject *Owner = GetOwner(Self); - return CppOwnedPyObject_NEW(Owner,&PackageType, + return CppOwnedPyObject_NEW(Owner,&PyPackage_Type, Version_GetVer(Self).ParentPkg()); } static PyObject *VersionGetProvidesList(PyObject *Self, void*) { @@ -815,7 +815,7 @@ static PyObject *VersionGetTranslatedDescription(PyObject *Self, void*) { pkgCache::VerIterator &Ver = GetCpp(Self); PyObject *Owner = GetOwner(Self); return CppOwnedPyObject_NEW(Owner, - &DescriptionType, + &PyDescription_Type, Ver.TranslatedDescription()); } @@ -889,7 +889,7 @@ static PyGetSetDef VersionGetSet[] = { {} }; -PyTypeObject VersionType = +PyTypeObject PyVersion_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Version", // tp_name @@ -1051,7 +1051,7 @@ static PyGetSetDef PackageFileGetSet[] = { {} }; -PyTypeObject PackageFileType = { +PyTypeObject PyPackageFile_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.PackageFile", // tp_name sizeof(CppOwnedPyObject), // tp_basicsize @@ -1113,7 +1113,7 @@ static PyObject *DepSmartTargetPkg(PyObject *Self,PyObject *Args) return Py_None; } - return CppOwnedPyObject_NEW(Owner,&PackageType,P); + return CppOwnedPyObject_NEW(Owner,&PyPackage_Type,P); } static PyObject *DepAllTargets(PyObject *Self,PyObject *Args) @@ -1129,7 +1129,7 @@ static PyObject *DepAllTargets(PyObject *Self,PyObject *Args) for (pkgCache::Version **I = Vers; *I != 0; I++) { PyObject *Obj; - Obj = CppOwnedPyObject_NEW(Owner,&VersionType, + Obj = CppOwnedPyObject_NEW(Owner,&PyVersion_Type, pkgCache::VerIterator(*Dep.Cache(),*I)); PyList_Append(List,Obj); Py_DECREF(Obj); @@ -1163,7 +1163,7 @@ static PyObject *DependencyGetTargetPkg(PyObject *Self,void*) { pkgCache::DepIterator &Dep = GetCpp(Self); PyObject *Owner = GetOwner(Self); - return CppOwnedPyObject_NEW(Owner,&PackageType, + return CppOwnedPyObject_NEW(Owner,&PyPackage_Type, Dep.TargetPkg()); } @@ -1171,7 +1171,7 @@ static PyObject *DependencyGetParentVer(PyObject *Self,void*) { pkgCache::DepIterator &Dep = GetCpp(Self); PyObject *Owner = GetOwner(Self); - return CppOwnedPyObject_NEW(Owner,&VersionType, + return CppOwnedPyObject_NEW(Owner,&PyVersion_Type, Dep.ParentVer()); } @@ -1179,7 +1179,7 @@ static PyObject *DependencyGetParentPkg(PyObject *Self,void*) { pkgCache::DepIterator &Dep = GetCpp(Self); PyObject *Owner = GetOwner(Self); - return CppOwnedPyObject_NEW(Owner,&PackageType, + return CppOwnedPyObject_NEW(Owner,&PyPackage_Type, Dep.ParentPkg()); } @@ -1222,7 +1222,7 @@ static PyGetSetDef DependencyGetSet[] = { }; -PyTypeObject DependencyType = +PyTypeObject PyDependency_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Dependency", // tp_name @@ -1293,7 +1293,7 @@ static PyObject *RDepListItem(PyObject *iSelf,Py_ssize_t Index) } return CppOwnedPyObject_NEW(GetOwner(iSelf), - &DependencyType,Self.Iter); + &PyDependency_Type,Self.Iter); } static PySequenceMethods RDepListSeq = @@ -1307,7 +1307,7 @@ static PySequenceMethods RDepListSeq = 0 // assign slice }; -PyTypeObject RDepListType = +PyTypeObject PyDependencyList_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.DependencyList", // tp_name @@ -1343,6 +1343,6 @@ PyObject *TmpGetCache(PyObject *Self,PyObject *Args) { PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetCache() is deprecated. " "Please see apt_pkg.Cache() for the replacement.", 1); - return PkgCacheNew(&PkgCacheType,Args,0); + return PkgCacheNew(&PyCache_Type,Args,0); } #endif diff --git a/python/cdrom.cc b/python/cdrom.cc index b5b87758..84d7179f 100644 --- a/python/cdrom.cc +++ b/python/cdrom.cc @@ -77,7 +77,7 @@ static PyObject *PkgCdromNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) } -PyTypeObject PkgCdromType = +PyTypeObject PyCdrom_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Cdrom", // tp_name @@ -126,7 +126,7 @@ PyObject *GetCdrom(PyObject *Self,PyObject *Args) { PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetCdrom() is deprecated. " "Please see apt_pkg.Cdrom() for the replacement.", 1); - return PkgCdromNew(&PkgCdromType,Args,0); + return PkgCdromNew(&PyCdrom_Type,Args,0); } #endif diff --git a/python/configuration.cc b/python/configuration.cc index 07f55957..c7d7d796 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -49,7 +49,7 @@ void CnfSubFree(PyObject *Obj) /* */ static inline Configuration &GetSelf(PyObject *Obj) { - if (Obj->ob_type == &ConfigurationPtrType) + if (Obj->ob_type == &PyConfigurationPtr_Type) return *GetCpp(Obj); return GetCpp(Obj); } @@ -161,8 +161,8 @@ static PyObject *CnfSubTree(PyObject *Self,PyObject *Args) } // Create a new sub configuration. - SubConfiguration *New = (SubConfiguration*)(&ConfigurationSubType) - ->tp_alloc(&ConfigurationSubType,0); + SubConfiguration *New = (SubConfiguration*)(&PyConfigurationSub_Type) + ->tp_alloc(&PyConfigurationSub_Type,0); new (&New->Object) Configuration(Itm); New->Owner = Self; Py_INCREF(Self); @@ -501,7 +501,7 @@ static PyObject *CnfNew(PyTypeObject *type, PyObject *args, PyObject *kwds) { // Type for a Normal Configuration object static PySequenceMethods ConfigurationSeq = {0,0,0,0,0,0,0,CnfContains,0,0}; static PyMappingMethods ConfigurationMap = {0,CnfMap,CnfMapSet}; -PyTypeObject ConfigurationType = +PyTypeObject PyConfiguration_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Configuration", // tp_name @@ -545,7 +545,7 @@ PyTypeObject ConfigurationType = CnfNew, // tp_new }; -PyTypeObject ConfigurationPtrType = +PyTypeObject PyConfigurationPtr_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.ConfigurationPtr", // tp_name @@ -578,10 +578,10 @@ PyTypeObject ConfigurationPtrType = CnfMethods, // tp_methods 0, // tp_members 0, // tp_getset - &ConfigurationType, // tp_base + &PyConfiguration_Type, // tp_base }; -PyTypeObject ConfigurationSubType = +PyTypeObject PyConfigurationSub_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.ConfigurationSub", // tp_name @@ -614,6 +614,6 @@ PyTypeObject ConfigurationSubType = CnfMethods, // tp_methods 0, // tp_members 0, // tp_getset - &ConfigurationType, // tp_base + &PyConfiguration_Type, // tp_base }; diff --git a/python/depcache.cc b/python/depcache.cc index 68ca3a3b..2d72a82a 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -190,8 +190,8 @@ static PyObject *PkgDepCacheSetCandidateVer(PyObject *Self,PyObject *Args) PyObject *PackageObj; PyObject *VersionObj; if (PyArg_ParseTuple(Args,"O!O!", - &PackageType, &PackageObj, - &VersionType, &VersionObj) == 0) + &PyPackage_Type, &PackageObj, + &PyVersion_Type, &VersionObj) == 0) return 0; pkgCache::VerIterator &I = GetCpp(VersionObj); @@ -208,7 +208,7 @@ static PyObject *PkgDepCacheGetCandidateVer(PyObject *Self,PyObject *Args) pkgDepCache *depcache = GetCpp(Self); PyObject *PackageObj; PyObject *CandidateObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -219,7 +219,7 @@ static PyObject *PkgDepCacheGetCandidateVer(PyObject *Self,PyObject *Args) Py_INCREF(Py_None); return Py_None; } - CandidateObj = CppOwnedPyObject_NEW(PackageObj,&VersionType,I); + CandidateObj = CppOwnedPyObject_NEW(PackageObj,&PyVersion_Type,I); return CandidateObj; } @@ -300,7 +300,7 @@ static PyObject *PkgDepCacheMarkKeep(PyObject *Self,PyObject *Args) pkgDepCache *depcache = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -316,7 +316,7 @@ static PyObject *PkgDepCacheSetReInstall(PyObject *Self,PyObject *Args) PyObject *PackageObj; char value = 0; - if (PyArg_ParseTuple(Args,"O!b",&PackageType,&PackageObj, &value) == 0) + if (PyArg_ParseTuple(Args,"O!b",&PyPackage_Type,&PackageObj, &value) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -333,7 +333,7 @@ static PyObject *PkgDepCacheMarkDelete(PyObject *Self,PyObject *Args) PyObject *PackageObj; char purge = 0; - if (PyArg_ParseTuple(Args,"O!|b",&PackageType,&PackageObj, &purge) == 0) + if (PyArg_ParseTuple(Args,"O!|b",&PyPackage_Type,&PackageObj, &purge) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -351,7 +351,7 @@ static PyObject *PkgDepCacheMarkInstall(PyObject *Self,PyObject *Args) PyObject *PackageObj; char autoInst=1; char fromUser=1; - if (PyArg_ParseTuple(Args,"O!|bb",&PackageType,&PackageObj, + if (PyArg_ParseTuple(Args,"O!|bb",&PyPackage_Type,&PackageObj, &autoInst, &fromUser) == 0) return 0; @@ -370,7 +370,7 @@ static PyObject *PkgDepCacheMarkAuto(PyObject *Self,PyObject *Args) PyObject *PackageObj; char value = 0; - if (PyArg_ParseTuple(Args,"O!b",&PackageType,&PackageObj, &value) == 0) + if (PyArg_ParseTuple(Args,"O!b",&PyPackage_Type,&PackageObj, &value) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -386,7 +386,7 @@ static PyObject *PkgDepCacheIsUpgradable(PyObject *Self,PyObject *Args) pkgDepCache *depcache = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -400,7 +400,7 @@ static PyObject *PkgDepCacheIsGarbage(PyObject *Self,PyObject *Args) pkgDepCache *depcache = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -414,7 +414,7 @@ static PyObject *PkgDepCacheIsAutoInstalled(PyObject *Self,PyObject *Args) pkgDepCache *depcache = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -428,7 +428,7 @@ static PyObject *PkgDepCacheIsNowBroken(PyObject *Self,PyObject *Args) pkgDepCache *depcache = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -442,7 +442,7 @@ static PyObject *PkgDepCacheIsInstBroken(PyObject *Self,PyObject *Args) pkgDepCache *depcache = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -457,7 +457,7 @@ static PyObject *PkgDepCacheMarkedInstall(PyObject *Self,PyObject *Args) pkgDepCache *depcache = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -472,7 +472,7 @@ static PyObject *PkgDepCacheMarkedUpgrade(PyObject *Self,PyObject *Args) pkgDepCache *depcache = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -486,7 +486,7 @@ static PyObject *PkgDepCacheMarkedDelete(PyObject *Self,PyObject *Args) pkgDepCache *depcache = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -500,7 +500,7 @@ static PyObject *PkgDepCacheMarkedKeep(PyObject *Self,PyObject *Args) pkgDepCache *depcache = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -514,7 +514,7 @@ static PyObject *PkgDepCacheMarkedDowngrade(PyObject *Self,PyObject *Args) pkgDepCache *depcache = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -528,7 +528,7 @@ static PyObject *PkgDepCacheMarkedReinstall(PyObject *Self,PyObject *Args) pkgDepCache *depcache = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); @@ -656,7 +656,7 @@ static PyObject *PkgDepCacheNew(PyTypeObject *type,PyObject *Args,PyObject *kwds { PyObject *Owner; static char *kwlist[] = {"cache", 0}; - if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PkgCacheType, + if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PyCache_Type, &Owner) == 0) return 0; @@ -680,7 +680,7 @@ static PyObject *PkgDepCacheNew(PyTypeObject *type,PyObject *Args,PyObject *kwds static char *doc_PkgDepCache = "DepCache(cache) -> DepCache() object\n\n" "A DepCache() holds extra information on the state of the packages.\n\n" "The parameter *cache* refers to an apt_pkg.Cache() object."; -PyTypeObject PkgDepCacheType = +PyTypeObject PyDepCache_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.DepCache", // tp_name @@ -730,7 +730,7 @@ PyObject *GetDepCache(PyObject *Self,PyObject *Args) { PyErr_WarnEx(PyExc_DeprecationWarning,"apt_pkg.GetDepCache() is deprecated" ". Please see apt_pkg.DepCache() for the replacement.",1); - return PkgDepCacheNew(&PkgDepCacheType,Args,0); + return PkgDepCacheNew(&PyDepCache_Type,Args,0); } #endif @@ -745,7 +745,7 @@ static PyObject *PkgProblemResolverNew(PyTypeObject *type,PyObject *Args,PyObjec { PyObject *Owner; static char *kwlist[] = {"depcache",0}; - if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PkgDepCacheType, + if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PyDepCache_Type, &Owner) == 0) return 0; @@ -765,7 +765,7 @@ PyObject *GetPkgProblemResolver(PyObject *Self,PyObject *Args) { PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPkgProblemResolver() is" " deprecated. Please see apt_pkg.ProblemResolver() for the " "replacement.", 1); - return PkgProblemResolverNew(&PkgProblemResolverType,Args,0); + return PkgProblemResolverNew(&PyProblemResolver_Type,Args,0); } #endif @@ -803,7 +803,7 @@ static PyObject *PkgProblemResolverProtect(PyObject *Self,PyObject *Args) { pkgProblemResolver *fixer = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); fixer->Protect(Pkg); @@ -815,7 +815,7 @@ static PyObject *PkgProblemResolverRemove(PyObject *Self,PyObject *Args) { pkgProblemResolver *fixer = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); fixer->Remove(Pkg); @@ -827,7 +827,7 @@ static PyObject *PkgProblemResolverClear(PyObject *Self,PyObject *Args) { pkgProblemResolver *fixer = GetCpp(Self); PyObject *PackageObj; - if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + if (PyArg_ParseTuple(Args,"O!",&PyPackage_Type,&PackageObj) == 0) return 0; pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); fixer->Clear(Pkg); @@ -867,7 +867,7 @@ static PyMethodDef PkgProblemResolverMethods[] = {} }; -PyTypeObject PkgProblemResolverType = +PyTypeObject PyProblemResolver_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.ProblemResolver", // tp_name @@ -953,7 +953,7 @@ static PyObject *PkgActionGroupNew(PyTypeObject *type,PyObject *Args,PyObject *k { PyObject *Owner; static char *kwlist[] = {"depcache", 0}; - if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PkgDepCacheType, + if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PyDepCache_Type, &Owner) == 0) return 0; @@ -983,7 +983,7 @@ static char *doc_PkgActionGroup = "ActionGroup(depcache)\n\n" "automatically released from the cache."; -PyTypeObject PkgActionGroupType = +PyTypeObject PyActionGroup_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.ActionGroup", // tp_name @@ -1034,7 +1034,7 @@ PyObject *GetPkgActionGroup(PyObject *Self,PyObject *Args) PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPkgActionGroup() is " "deprecated. Please see apt_pkg.ActionGroup() for the " "replacement.", 1); - return PkgActionGroupNew(&PkgActionGroupType,Args,0); + return PkgActionGroupNew(&PyActionGroup_Type,Args,0); } #endif diff --git a/python/indexfile.cc b/python/indexfile.cc index f2180cd7..7bf646d0 100644 --- a/python/indexfile.cc +++ b/python/indexfile.cc @@ -88,7 +88,7 @@ static PyGetSetDef PackageIndexFileGetSet[] = { {} }; -PyTypeObject PackageIndexFileType = +PyTypeObject PyPackageIndexFile_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.PackageIndexFile", // tp_name diff --git a/python/metaindex.cc b/python/metaindex.cc index 195394d6..d67c0ada 100644 --- a/python/metaindex.cc +++ b/python/metaindex.cc @@ -38,7 +38,7 @@ static PyObject *MetaIndexGetIndexFiles(PyObject *Self,void*) { I != indexFiles->end(); I++) { CppOwnedPyObject *Obj; - Obj = CppOwnedPyObject_NEW(Self, &PackageIndexFileType,*I); + Obj = CppOwnedPyObject_NEW(Self, &PyPackageIndexFile_Type,*I); // Do not delete pkgIndexFile*, they are managed by metaIndex. Obj->NoDelete = true; PyList_Append(List,Obj); @@ -73,7 +73,7 @@ static PyObject *MetaIndexRepr(PyObject *Self) return PyString_FromString(S); } -PyTypeObject MetaIndexType = +PyTypeObject PyMetaIndex_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.MetaIndex", // tp_name diff --git a/python/pkgmanager.cc b/python/pkgmanager.cc index 9e9cc32d..f4f84a2b 100644 --- a/python/pkgmanager.cc +++ b/python/pkgmanager.cc @@ -24,7 +24,7 @@ static PyObject *PkgManagerNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) { PyObject *Owner; char *kwlist[] = {"depcache",0}; - if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PkgDepCacheType, + if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PyDepCache_Type, &Owner) == 0) return 0; @@ -42,7 +42,7 @@ PyObject *GetPkgManager(PyObject *Self,PyObject *Args) PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPackageManager() is " "deprecated. Please see apt_pkg.PackageManager() for the " "replacement.", 1); - return PkgManagerNew(&PkgManagerType,Args,0); + return PkgManagerNew(&PyPackageManager_Type,Args,0); } #endif @@ -53,9 +53,9 @@ static PyObject *PkgManagerGetArchives(PyObject *Self,PyObject *Args) PyObject *fetcher, *list, *recs; if (PyArg_ParseTuple(Args, "O!O!O!", - &PkgAcquireType,&fetcher, - &PkgSourceListType, &list, - &PkgRecordsType, &recs) == 0) + &PyAcquire_Type,&fetcher, + &PySourceList_Type, &list, + &PyPackageRecords_Type, &recs) == 0) return 0; pkgAcquire *s_fetcher = GetCpp(fetcher); @@ -131,7 +131,7 @@ static PyGetSetDef PkgManagerGetSet[] = { {} }; -PyTypeObject PkgManagerType = +PyTypeObject PyPackageManager_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.PackageManager", // tp_name diff --git a/python/pkgrecords.cc b/python/pkgrecords.cc index 886bdb58..d34ba0d2 100644 --- a/python/pkgrecords.cc +++ b/python/pkgrecords.cc @@ -27,7 +27,7 @@ static PyObject *PkgRecordsLookup(PyObject *Self,PyObject *Args) PyObject *PkgFObj; long int Index; - if (PyArg_ParseTuple(Args,"(O!l)",&PackageFileType,&PkgFObj,&Index) == 0) + if (PyArg_ParseTuple(Args,"(O!l)",&PyPackageFile_Type,&PkgFObj,&Index) == 0) return 0; // Get the index and check to make sure it is reasonable @@ -153,7 +153,7 @@ static PyObject *PkgRecordsNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) { PyObject *Owner; char *kwlist[] = {"cache",0}; - if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PkgCacheType, + if (PyArg_ParseTupleAndKeywords(Args,kwds,"O!",kwlist,&PyCache_Type, &Owner) == 0) return 0; @@ -161,7 +161,7 @@ static PyObject *PkgRecordsNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) GetCpp(Owner))); } -PyTypeObject PkgRecordsType = +PyTypeObject PyPackageRecords_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.PackageRecords", // tp_name @@ -215,6 +215,6 @@ PyObject *GetPkgRecords(PyObject *Self,PyObject *Args) PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPkgRecords() is " "deprecated. Please see apt_pkg.Records() for the " "replacement.", 1); - return PkgRecordsNew(&PkgRecordsType,Args,0); + return PkgRecordsNew(&PyPackageRecords_Type,Args,0); } #endif diff --git a/python/pkgsrcrecords.cc b/python/pkgsrcrecords.cc index 99711585..fbc9a293 100644 --- a/python/pkgsrcrecords.cc +++ b/python/pkgsrcrecords.cc @@ -124,7 +124,7 @@ static PyObject *PkgSrcRecordsGetIndex(PyObject *Self,void*) { return 0; const pkgIndexFile &tmp = Struct.Last->Index(); CppOwnedPyObject *PyObj; - PyObj = CppOwnedPyObject_NEW(Self,&PackageIndexFileType, + PyObj = CppOwnedPyObject_NEW(Self,&PyPackageIndexFile_Type, (pkgIndexFile*)&tmp); // Do not delete the pkgIndexFile*, it is managed by PkgSrcRecords::Parser. PyObj->NoDelete=true; @@ -255,7 +255,7 @@ static PyObject *PkgSrcRecordsNew(PyTypeObject *type,PyObject *args,PyObject *kw return HandleErrors(CppPyObject_NEW(type)); } -PyTypeObject PkgSrcRecordsType = +PyTypeObject PySourceRecords_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.SourceRecords", // tp_name @@ -310,6 +310,6 @@ PyObject *GetPkgSrcRecords(PyObject *Self,PyObject *Args) if (PyArg_ParseTuple(Args,"") == 0) return 0; - return HandleErrors(CppPyObject_NEW(&PkgSrcRecordsType)); + return HandleErrors(CppPyObject_NEW(&PySourceRecords_Type)); } #endif diff --git a/python/policy.cc b/python/policy.cc index d086c4fc..faf53b38 100644 --- a/python/policy.cc +++ b/python/policy.cc @@ -29,7 +29,7 @@ static PyObject *Policy_NEW(PyTypeObject *type,PyObject *Args, char *kwlist[] = {"cache", NULL}; if (PyArg_ParseTupleAndKeywords(Args, kwds, "O", kwlist, &cache) == 0) return 0; - if (!PyObject_TypeCheck(cache, &PkgCacheType)) { + if (!PyObject_TypeCheck(cache, &PyCache_Type)) { PyErr_SetString(PyExc_TypeError,"`cache` must be a apt_pkg.Cache()."); return 0; } @@ -43,7 +43,7 @@ static char *Policy_GetPriority_doc = "get_priority(package: apt_pkg.Package)" PyObject *Policy_GetPriority(PyObject *self, PyObject *arg) { pkgPolicy *policy = GetCpp(self); - if (PyObject_TypeCheck(arg, &PackageType)) { + if (PyObject_TypeCheck(arg, &PyPackage_Type)) { pkgCache::PkgIterator pkg = GetCpp(arg); return Py_BuildValue("i", policy->GetPriority(pkg)); } else { @@ -57,11 +57,11 @@ static char *Policy_GetCandidateVer_doc = "get_match(package: apt_pkg.Package)" "Get the best package for the job."; PyObject *Policy_GetCandidateVer(PyObject *self, PyObject *arg) { - if (PyObject_TypeCheck(arg, &PackageType)) { + if (PyObject_TypeCheck(arg, &PyPackage_Type)) { pkgPolicy *policy = GetCpp(self); pkgCache::PkgIterator pkg = GetCpp(arg); pkgCache::VerIterator ver = policy->GetCandidateVer(pkg); - return CppOwnedPyObject_NEW(arg,&VersionType, + return CppOwnedPyObject_NEW(arg,&PyVersion_Type, ver); } else { PyErr_SetString(PyExc_TypeError,"Argument must be of Package()."); @@ -74,14 +74,14 @@ static char *Policy_GetMatch_doc = "get_match(package: apt_pkg.Package) -> " "Return a matching version for the given package."; static PyObject *Policy_GetMatch(PyObject *self, PyObject *arg) { - if (PyObject_TypeCheck(arg, &PackageType) == 0) { + if (PyObject_TypeCheck(arg, &PyPackage_Type) == 0) { PyErr_SetString(PyExc_TypeError,"Argument must be of Package()."); return 0; } pkgPolicy *policy = GetCpp(self); pkgCache::PkgIterator pkg = GetCpp(arg); pkgCache::VerIterator ver = policy->GetMatch(pkg); - return CppOwnedPyObject_NEW(arg,&VersionType,ver); + return CppOwnedPyObject_NEW(arg,&PyVersion_Type,ver); } static char *Policy_ReadPinFile_doc = "read_pinfile(filename: str) -> bool\n\n" diff --git a/python/sourcelist.cc b/python/sourcelist.cc index beb249dc..e86f7fd3 100644 --- a/python/sourcelist.cc +++ b/python/sourcelist.cc @@ -28,20 +28,20 @@ static PyObject *PkgSourceListFindIndex(PyObject *Self,PyObject *Args) PyObject *pyPkgFileIter; CppOwnedPyObject *pyPkgIndexFile; - if (PyArg_ParseTuple(Args, "O!", &PackageFileType,&pyPkgFileIter) == 0) + if (PyArg_ParseTuple(Args, "O!", &PyPackageFile_Type,&pyPkgFileIter) == 0) return 0; pkgCache::PkgFileIterator &i = GetCpp(pyPkgFileIter); pkgIndexFile *index; if(list->FindIndex(i, index)) { - pyPkgIndexFile = CppOwnedPyObject_NEW(pyPkgFileIter,&PackageIndexFileType,index); + pyPkgIndexFile = CppOwnedPyObject_NEW(pyPkgFileIter,&PyPackageIndexFile_Type,index); // Do not delete the pkgIndexFile*, it is managed by pkgSourceList. pyPkgIndexFile->NoDelete = true; return pyPkgIndexFile; } - //&PackageIndexFileType,&pyPkgIndexFile) + //&PyPackageIndexFile_Type,&pyPkgIndexFile) Py_INCREF(Py_None); return Py_None; @@ -63,7 +63,7 @@ static PyObject *PkgSourceListGetIndexes(PyObject *Self,PyObject *Args) PyObject *pyFetcher; char all = 0; - if (PyArg_ParseTuple(Args, "O!|b",&PkgAcquireType,&pyFetcher, &all) == 0) + if (PyArg_ParseTuple(Args, "O!|b",&PyAcquire_Type,&pyFetcher, &all) == 0) return 0; pkgAcquire *fetcher = GetCpp(pyFetcher); @@ -93,7 +93,7 @@ static PyObject *PkgSourceListGetList(PyObject *Self,void*) I != list->end(); I++) { CppOwnedPyObject *Obj; - Obj = CppOwnedPyObject_NEW(Self, &MetaIndexType,*I); + Obj = CppOwnedPyObject_NEW(Self, &PyMetaIndex_Type,*I); // Never delete metaIndex*, they are managed by the pkgSourceList. Obj->NoDelete = true; PyList_Append(List,Obj); @@ -118,7 +118,7 @@ static PyObject *PkgSourceListNew(PyTypeObject *type,PyObject *args,PyObject *kw return CppPyObject_NEW(type,new pkgSourceList()); } -PyTypeObject PkgSourceListType = +PyTypeObject PySourceList_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.SourceList", // tp_name @@ -168,6 +168,6 @@ PyObject *GetPkgSourceList(PyObject *Self,PyObject *Args) PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPkgSourceList() is " "deprecated. Please see apt_pkg.SourceList() for the " "replacement.", 1); - return PkgSourceListNew(&PkgSourceListType,Args,0); + return PkgSourceListNew(&PySourceList_Type,Args,0); } #endif diff --git a/python/tag.cc b/python/tag.cc index 2b71517d..573e8ce2 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -290,7 +290,7 @@ PyObject *ParseSection(PyObject *self,PyObject *Args) PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.ParseSection() is " "deprecated. Please see apt_pkg.TagSection() for the " "replacement.", 1); - return TagSecNew(&TagSecType,Args,0); + return TagSecNew(&PyTagSection_Type,Args,0); } #endif /*}}}*/ @@ -315,7 +315,7 @@ static PyObject *TagFileNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) new (&New->Object) pkgTagFile(&New->Fd); // Create the section - New->Section = (TagSecData*)(&TagSecType)->tp_alloc(&TagSecType, 0); + New->Section = (TagSecData*)(&PyTagSection_Type)->tp_alloc(&PyTagSection_Type, 0); new (&New->Section->Object) pkgTagSection(); New->Section->Owner = New; Py_INCREF(New->Section->Owner); @@ -329,7 +329,7 @@ PyObject *ParseTagFile(PyObject *self,PyObject *Args) { PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.ParseTagFile() is " "deprecated. Please see apt_pkg.TagFile() for the " "replacement.", 1); - return TagFileNew(&TagFileType,Args,0); + return TagFileNew(&PyTagFile_Type,Args,0); } #endif /*}}}*/ @@ -357,7 +357,7 @@ PyObject *RewriteSection(PyObject *self,PyObject *Args) PyObject *Section; PyObject *Order; PyObject *Rewrite; - if (PyArg_ParseTuple(Args,"O!O!O!",&TagSecType,&Section, + if (PyArg_ParseTuple(Args,"O!O!O!",&PyTagSection_Type,&Section, &PyList_Type,&Order,&PyList_Type,&Rewrite) == 0) return 0; @@ -436,7 +436,7 @@ static char *doc_TagSec = "TagSection(text) -> Create a new object.\n\n" "header sections, like those in debian/control or Packages files.\n\n" "TagSection() behave like read-only dictionaries and also provide access\n" "to the functions provided by the C++ class (e.g. Find)"; -PyTypeObject TagSecType = +PyTypeObject PyTagSection_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.TagSection", // tp_name @@ -522,7 +522,7 @@ static char *doc_TagFile = "TagFile(file) -> TagFile() object. \n\n" "a file descriptor (an integer)"; // Type for a Tag File -PyTypeObject TagFileType = +PyTypeObject PyTagFile_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.TagFile", // tp_name -- cgit v1.2.3 From 8430dbf041ce70dcba81101678beee0492252fd2 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 14 Jul 2009 20:43:56 +0200 Subject: python/configuration.cc: Unify all Configuration,ConfigurationPtr,ConfigurationSub into one type. This makes the whole API easier. The disadvantage is that we require 8 bytes (??) more per object for the owner object pointer, which is NULL for most cases (the only exception being objects created by Configuration.sub_tree). --- debian/changelog | 3 +- python/apt_pkgmodule.cc | 9 ++-- python/apt_pkgmodule.h | 6 +-- python/configuration.cc | 116 ++++-------------------------------------------- 4 files changed, 15 insertions(+), 119 deletions(-) (limited to 'python/apt_pkgmodule.h') diff --git a/debian/changelog b/debian/changelog index 304237c1..4ae6e574 100644 --- a/debian/changelog +++ b/debian/changelog @@ -33,6 +33,7 @@ python-apt (0.7.92) UNRELEASED; urgency=low * Introduce apt_pkg.Hashes class. * Make AcquireItem objects raise ValueError instead of segfaulting when the Acquire() object is shut down or the main object (e.g. AcquireFile) is deallocated. + * Unify all Configuration,ConfigurationPtr,ConfigurationSub into one type. [ Sebastian Heinlein ] * apt/progress.py: Extract the package name from the status message @@ -48,7 +49,7 @@ python-apt (0.7.92) UNRELEASED; urgency=low * python/progress.cc: - low level code for update_status_full and pulse_items() - -- Julian Andres Klode Sun, 12 Jul 2009 21:19:40 +0200 + -- Julian Andres Klode Tue, 14 Jul 2009 20:42:03 +0200 python-apt (0.7.91) experimental; urgency=low diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 3f18f785..e4fd0dfc 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -527,8 +527,7 @@ extern "C" void initapt_pkg() #endif { // Finalize our types to add slots, etc. - if (PyType_Ready(&PyConfigurationPtr_Type) == -1) INIT_ERROR; - if (PyType_Ready(&PyConfigurationSub_Type) == -1) INIT_ERROR; + if (PyType_Ready(&PyConfiguration_Type) == -1) INIT_ERROR; if (PyType_Ready(&PyCacheFile_Type) == -1) INIT_ERROR; // Initialize the module @@ -539,8 +538,10 @@ extern "C" void initapt_pkg() #endif // Global variable linked to the global configuration class - CppPyObject *Config = CppPyObject_NEW(&PyConfigurationPtr_Type); + CppOwnedPyObject *Config = CppOwnedPyObject_NEW(NULL, &PyConfiguration_Type); Config->Object = _config; + // Global configuration, should never be deleted. + Config->NoDelete = true; PyModule_AddObject(Module,"config",Config); #ifdef COMPAT_0_7 Py_INCREF(Config); @@ -568,8 +569,6 @@ extern "C" void initapt_pkg() ADDTYPE(Module,"Cdrom",&PyCdrom_Type); /* ========================= configuration.cc ========================= */ ADDTYPE(Module,"Configuration",&PyConfiguration_Type); - //ADDTYPE(Module,"ConfigurationSub",&PyConfigurationSub_Type); // NO __new__() - //ADDTYPE(Module,"ConfigurationPtr",&PyConfigurationPtr_Type); // NO __new__() /* ========================= depcache.cc ========================= */ ADDTYPE(Module,"ActionGroup",&PyActionGroup_Type); ADDTYPE(Module,"DepCache",&PyDepCache_Type); diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index 7b835ca8..f77c5e73 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -14,12 +14,8 @@ #include // Configuration Stuff -#define Configuration_Check(op) ((op)->ob_type == &PyConfiguration_Type || \ - (op)->ob_type == &PyConfigurationPtr_Type || \ - (op)->ob_type == &PyConfigurationSub_Type) +#define Configuration_Check(op) ((op)->ob_type == &PyConfiguration_Type) extern PyTypeObject PyConfiguration_Type; -extern PyTypeObject PyConfigurationPtr_Type; -extern PyTypeObject PyConfigurationSub_Type; extern PyTypeObject PyVersion_Type; extern char *doc_LoadConfig; diff --git a/python/configuration.cc b/python/configuration.cc index ba075133..e7e31cc8 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -5,11 +5,8 @@ Configuration - Binding for the configuration object. - There are three seperate classes.. - Configuration - A stand alone configuration instance - ConfigurationPtr - A pointer to a configuration instance, used only - for the global instance (_config) - ConfigurationSub - A subtree - has a reference to its owner. + The Configuration object can have an owner (a parent Configuration object), + and it always uses a pointer. The wrapping is mostly 1:1 with the C++ code, but there are additions to wrap the linked tree walking into nice flat sequence walking. @@ -25,33 +22,13 @@ #include /*}}}*/ -/* If we create a sub tree then it is of this type, the Owner is used - to manage reference counting. */ -struct SubConfiguration : public CppPyObject -{ - PyObject *Owner; -}; - - /*}}}*/ -// CnfSubFree - Free a sub configuration /*{{{*/ -// --------------------------------------------------------------------- -/* */ -void CnfSubFree(PyObject *Obj) -{ - SubConfiguration *Self = (SubConfiguration *)Obj; - Py_DECREF(Self->Owner); - CppDealloc(Obj); -} - /*}}}*/ // GetSelf - Convert PyObject to Configuration /*{{{*/ // --------------------------------------------------------------------- /* */ static inline Configuration &GetSelf(PyObject *Obj) { - if (Obj->ob_type == &PyConfigurationPtr_Type) - return *GetCpp(Obj); - return GetCpp(Obj); + return *GetCpp(Obj); } /*}}}*/ @@ -160,13 +137,8 @@ static PyObject *CnfSubTree(PyObject *Self,PyObject *Args) return 0; } - // Create a new sub configuration. - SubConfiguration *New = (SubConfiguration*)(&PyConfigurationSub_Type) - ->tp_alloc(&PyConfigurationSub_Type,0); - new (&New->Object) Configuration(Itm); - New->Owner = Self; - Py_INCREF(Self); - return New; + return CppOwnedPyObject_NEW(Self,&PyConfiguration_Type, + new Configuration(Itm)); } // Return a list of items at a specific level @@ -495,7 +467,7 @@ static PyObject *CnfNew(PyTypeObject *type, PyObject *args, PyObject *kwds) { char *kwlist[] = {NULL}; if (PyArg_ParseTupleAndKeywords(args,kwds,"",kwlist) == 0) return 0; - return CppPyObject_NEW(type); + return CppOwnedPyObject_NEW(NULL, type, new Configuration()); } // Type for a Normal Configuration object @@ -505,10 +477,10 @@ PyTypeObject PyConfiguration_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Configuration", // tp_name - sizeof(CppPyObject), // tp_basicsize + sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppDealloc, // tp_dealloc + CppOwnedDeallocPtr, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -545,75 +517,3 @@ PyTypeObject PyConfiguration_Type = CnfNew, // tp_new }; -PyTypeObject PyConfigurationPtr_Type = -{ - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "apt_pkg.ConfigurationPtr", // tp_name - sizeof(CppPyObject), // tp_basicsize - 0, // tp_itemsize - // Methods - (destructor)PyObject_Free, // tp_dealloc - 0, // tp_print - 0, // tp_getattr - 0, // tp_setattr - 0, // tp_compare - 0, // tp_repr - 0, // tp_as_number - &ConfigurationSeq, // tp_as_sequence - &ConfigurationMap, // tp_as_mapping - 0, // tp_hash - 0, // tp_call - 0, // tp_str - 0, // tp_getattro - 0, // tp_setattro - 0, // tp_as_buffer - Py_TPFLAGS_DEFAULT, // tp_flags - "ConfigurationPtr Object", // tp_doc - 0, // tp_traverse - 0, // tp_clear - 0, // tp_richcompare - 0, // tp_weaklistoffset - 0, // tp_iter - 0, // tp_iternext - CnfMethods, // tp_methods - 0, // tp_members - 0, // tp_getset - &PyConfiguration_Type, // tp_base -}; - -PyTypeObject PyConfigurationSub_Type = -{ - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "apt_pkg.ConfigurationSub", // tp_name - sizeof(SubConfiguration), // tp_basicsize - 0, // tp_itemsize - // Methods - CnfSubFree, // tp_dealloc - 0, // tp_print - 0, // tp_getattr - 0, // tp_setattr - 0, // tp_compare - 0, // tp_repr - 0, // tp_as_number - &ConfigurationSeq, // tp_as_sequence - &ConfigurationMap, // tp_as_mapping - 0, // tp_hash - 0, // tp_call - 0, // tp_str - 0, // tp_getattro - 0, // tp_setattro - 0, // tp_as_buffer - Py_TPFLAGS_DEFAULT, // tp_flags - "ConfigurationSub Object", // tp_doc - 0, // tp_traverse - 0, // tp_clear - 0, // tp_richcompare - 0, // tp_weaklistoffset - 0, // tp_iter - 0, // tp_iternext - CnfMethods, // tp_methods - 0, // tp_members - 0, // tp_getset - &PyConfiguration_Type, // tp_base -}; - -- cgit v1.2.3 From 360477dcc304b8a18c467e59435d8c766bbb76bb Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 15 Jul 2009 14:14:44 +0200 Subject: python/python-apt.h: Introduce the C++ API The C++ API provides support for creating Python objects from C++ objects given by pointer or reference (depending on the implementation of the Python object) and for retrieving the underlying C++ object from the Python object and for checking the type of the Python object. --- debian/changelog | 1 + debian/control | 11 ++ debian/python-apt-dev.examples | 1 + debian/python-apt-dev.install | 2 + doc/client-example.cc | 46 ++++++++ python/apt_pkgmodule.cc | 38 ++++++ python/apt_pkgmodule.h | 4 +- python/hashstring.cc | 5 - python/python-apt.h | 259 +++++++++++++++++++++++++++++++++++++++++ 9 files changed, 360 insertions(+), 7 deletions(-) create mode 100644 debian/python-apt-dev.examples create mode 100644 debian/python-apt-dev.install create mode 100644 doc/client-example.cc create mode 100644 python/python-apt.h (limited to 'python/apt_pkgmodule.h') diff --git a/debian/changelog b/debian/changelog index 4ae6e574..415ebdd2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,6 +3,7 @@ python-apt (0.7.92) UNRELEASED; urgency=low [ Julian Andres Klode ] * Add apt_pkg.HashString and apt_pkg.IndexRecords (Closes: #456141) * Add apt_pkg.Policy class (Closes: #382725) + * Provide a C++ API in the package python-apt-dev (Closes: #334923) * Allow types providing __new__() to be subclassed. * Bugfix: Delete pointers correctly, fixing memory leaks. (LP: #370149) * apt/package.py: Return VersionList objects in Package.versions, which diff --git a/debian/control b/debian/control index 10b9bc31..a16ae10e 100644 --- a/debian/control +++ b/debian/control @@ -54,3 +54,14 @@ Description: Python interface to libapt-pkg (debug extension) variety of functions. . This package contains the extension built for the Python debug interpreter. + +Package: python-apt-dev +Architecture: all +Depends: python-apt (>= ${source:Version}), libapt-pkg-dev (>= 0.7.10) +Description: Python interface to libapt-pkg (development files) + 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. + . + This package contains the header files needed to use python-apt objects from + C++ applications. diff --git a/debian/python-apt-dev.examples b/debian/python-apt-dev.examples new file mode 100644 index 00000000..39f7bf97 --- /dev/null +++ b/debian/python-apt-dev.examples @@ -0,0 +1 @@ +doc/client-example.cc diff --git a/debian/python-apt-dev.install b/debian/python-apt-dev.install new file mode 100644 index 00000000..2a1405fd --- /dev/null +++ b/debian/python-apt-dev.install @@ -0,0 +1,2 @@ +python/python-apt.h usr/include/python-apt/ +python/generic.h usr/include/python-apt/ diff --git a/doc/client-example.cc b/doc/client-example.cc new file mode 100644 index 00000000..7fa6672f --- /dev/null +++ b/doc/client-example.cc @@ -0,0 +1,46 @@ +/* + * client-example.cc - A simple example for using the python-apt C++ API. + * + * Copyright 2009 Julian Andres Klode + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ +#include + +int main(int argc, char *argv[]) { + Py_Initialize(); + if (import_apt_pkg() < 0) + return 1; + + // Initialize a module. + PyObject *Module = Py_InitModule("client", NULL); + + // Create a HashString, which will be added to the module. + HashString *hash = new HashString("0966a120bb936bdc6fdeac445707aa6b"); + // Create a Python object for the hashstring and add it to the module + PyModule_AddObject(Module, "hash", PyHashString_FromCpp(hash)); + + // Another example: Add the HashString type to the module. + Py_INCREF(&PyHashString_Type); + PyModule_AddObject(Module, "HashString", (PyObject*)(&PyHashString_Type)); + + // Run IPython, adding the client module to the namespace. + PySys_SetArgv(argc, argv); + PyRun_SimpleString("from IPython.Shell import start\n"); + PyRun_SimpleString("import client\n"); + PyRun_SimpleString("start(user_ns=dict(client=client)).mainloop()\n"); + Py_Finalize(); +} diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index e4fd0dfc..bc2f4258 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -498,6 +498,38 @@ static PyMethodDef methods[] = {} }; +static struct _PyAptPkgAPIStruct API = { + &PyAcquire_Type, // acquire_type + &PyAcquireFile_Type, // acquirefile_type + &PyAcquireItem_Type, // acquireitem_type + &PyActionGroup_Type, // actiongroup_type + &PyCache_Type, // cache_type + &PyCacheFile_Type, // cachefile_type + &PyCdrom_Type, // cdrom_type + &PyConfiguration_Type, // configuration_type + &PyDepCache_Type, // depcache_type + &PyDependency_Type, // dependency_type + &PyDependencyList_Type, // dependencylist_type + &PyDescription_Type, // description_type + &PyHashes_Type, // hashes_type + &PyHashString_Type, // hashstring_type + &PyIndexRecords_Type, // indexrecords_type + &PyMetaIndex_Type, // metaindex_type + &PyPackage_Type, // package_type + &PyPackageFile_Type, // packagefile_type + &PyPackageIndexFile_Type, // packageindexfile_type + &PyPackageList_Type, // packagelist_type + &PyPackageManager_Type, // packagemanager_type + &PyPackageRecords_Type, // packagerecords_type + &PyPolicy_Type, // policy_type + &PyProblemResolver_Type, // problemresolver_type + &PySourceList_Type, // sourcelist_type + &PySourceRecords_Type, // sourcerecords_type + &PyTagFile_Type, // tagfile_type + &PyTagSection_Type, // tagsection_type + &PyVersion_Type, // version_type +}; + #define ADDTYPE(mod,name,type) { \ if (PyType_Ready(type) == -1) INIT_ERROR; \ @@ -596,6 +628,12 @@ extern "C" void initapt_pkg() PyModule_AddObject(Module,"REWRITE_SOURCE_ORDER", CharCharToList(TFRewriteSourceOrder)); +#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 1 + PyObject *PyCapsule = PyCapsule_New(&API, "apt_pkg._C_API", NULL); +#else + PyObject *PyCapsule = PyCObject_FromVoidPtr(&API, NULL); +#endif + PyModule_AddObject(Module, "_C_API", PyCapsule); // Version.. PyModule_AddStringConstant(Module,"VERSION",(char *)pkgVersion); PyModule_AddStringConstant(Module,"LIB_VERSION",(char *)pkgLibVersion); diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index f77c5e73..97be5d5c 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -104,7 +104,6 @@ extern PyTypeObject PyPackageIndexFile_Type; extern PyTypeObject PyMetaIndex_Type; // HashString -PyObject *PyHashString_FromCpp(HashString *obj); extern PyTypeObject PyHashString_Type; // IndexRecord @@ -113,5 +112,6 @@ extern PyTypeObject PyIndexRecords_Type; // Policy extern PyTypeObject PyPolicy_Type; extern PyTypeObject PyHashes_Type; - +#include "python-apt.h" #endif + diff --git a/python/hashstring.cc b/python/hashstring.cc index d303049a..b76dc127 100644 --- a/python/hashstring.cc +++ b/python/hashstring.cc @@ -39,11 +39,6 @@ static PyObject *HashString_NEW(PyTypeObject *type,PyObject *Args, return PyObj; } -PyObject *PyHashString_FromCpp(HashString *obj) -{ - return CppPyObject_NEW(&PyHashString_Type, obj); -} - static PyObject *HashString_Repr(PyObject *self) { HashString *hash = GetCpp(self); diff --git a/python/python-apt.h b/python/python-apt.h new file mode 100644 index 00000000..557f5a3b --- /dev/null +++ b/python/python-apt.h @@ -0,0 +1,259 @@ +/* + * python-apt.h - Header file for the public interface. + * + * Copyright 2009 Julian Andres Klode + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#ifndef PYTHON_APT_H +#define PYTHON_APT_H +#include +#include +#include "generic.h" + +struct _PyAptPkgAPIStruct { + PyTypeObject *acquire_type; + PyTypeObject *acquirefile_type; + PyTypeObject *acquireitem_type; + PyTypeObject *actiongroup_type; + PyTypeObject *cache_type; + PyTypeObject *cachefile_type; + PyTypeObject *cdrom_type; + PyTypeObject *configuration_type; + PyTypeObject *depcache_type; + PyTypeObject *dependency_type; + PyTypeObject *dependencylist_type; + PyTypeObject *description_type; + PyTypeObject *hashes_type; + PyTypeObject *hashstring_type; + PyTypeObject *indexrecords_type; + PyTypeObject *metaindex_type; + PyTypeObject *package_type; + PyTypeObject *packagefile_type; + PyTypeObject *packageindexfile_type; + PyTypeObject *packagelist_type; + PyTypeObject *packagemanager_type; + PyTypeObject *packagerecords_type; + PyTypeObject *policy_type; + PyTypeObject *problemresolver_type; + PyTypeObject *sourcelist_type; + PyTypeObject *sourcerecords_type; + PyTypeObject *tagfile_type; + PyTypeObject *tagsection_type; + PyTypeObject *version_type; +}; + +# ifndef APT_PKGMODULE_H +# define PyAcquire_Type *(_PyAptPkg_API->acquire_type) +# define PyAcquireFile_Type *(_PyAptPkg_API->acquirefile_type) +# define PyAcquireItem_Type *(_PyAptPkg_API->acquireitem_type) +# define PyActionGroup_Type *(_PyAptPkg_API->actiongroup_type) +# define PyCache_Type *(_PyAptPkg_API->cache_type) +# define PyCacheFile_Type *(_PyAptPkg_API->cachefile_type) +# define PyCdrom_Type *(_PyAptPkg_API->cdrom_type) +# define PyConfiguration_Type *(_PyAptPkg_API->configuration_type) +# define PyDepCache_Type *(_PyAptPkg_API->depcache_type) +# define PyDependency_Type *(_PyAptPkg_API->dependency_type) +# define PyDependencyList_Type *(_PyAptPkg_API->dependencylist_type) +# define PyDescription_Type *(_PyAptPkg_API->description_type) +# define PyHashes_Type *(_PyAptPkg_API->hashes_type) +# define PyHashString_Type *(_PyAptPkg_API->hashstring_type) +# define PyIndexRecords_Type *(_PyAptPkg_API->indexrecords_type) +# define PyMetaIndex_Type *(_PyAptPkg_API->metaindex_type) +# define PyPackage_Type *(_PyAptPkg_API->package_type) +# define PyPackageFile_Type *(_PyAptPkg_API->packagefile_type) +# define PyPackageIndexFile_Type *(_PyAptPkg_API->packageindexfile_type) +# define PyPackageList_Type *(_PyAptPkg_API->packagelist_type) +# define PyPackageManager_Type *(_PyAptPkg_API->packagemanager_type) +# define PyPackageRecords_Type *(_PyAptPkg_API->packagerecords_type) +# define PyPolicy_Type *(_PyAptPkg_API->policy_type) +# define PyProblemResolver_Type *(_PyAptPkg_API->problemresolver_type) +# define PySourceList_Type *(_PyAptPkg_API->sourcelist_type) +# define PySourceRecords_Type *(_PyAptPkg_API->sourcerecords_type) +# define PyTagFile_Type *(_PyAptPkg_API->tagfile_type) +# define PyTagSection_Type *(_PyAptPkg_API->tagsection_type) +# define PyVersion_Type *(_PyAptPkg_API->version_type) + +// Creating + +static struct _PyAptPkgAPIStruct *_PyAptPkg_API; + +static int import_apt_pkg(void) { +# if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 1 + _PyAptPkg_API = (_PyAptPkgAPIStruct *)PyCapsule_Import("apt_pkg._C_API", 0); + return (_PyAptPkg_API != NULL) ? 0 : -1; +# else + + PyObject *module = PyImport_ImportModule("apt_pkg"); + + if (module == NULL) { + return -1; + } + if (module != NULL) { + PyObject *c_api_object = PyObject_GetAttrString(module, "_C_API"); + if (c_api_object == NULL) + return -1; + if (PyCObject_Check(c_api_object)) + _PyAptPkg_API = (struct _PyAptPkgAPIStruct *)PyCObject_AsVoidPtr(c_api_object); + Py_DECREF(c_api_object); + } + return 0; +# endif // PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 1 +} +# endif // APT_PKGMODULE_H + +// Checking macros. +# define PyAcquire_Check(op) PyObject_TypeCheck(op, &PyAcquire_Type) +# define PyAcquireFile_Check(op) PyObject_TypeCheck(op, &PyAcquireFile_Type) +# define PyAcquireItem_Check(op) PyObject_TypeCheck(op, &PyAcquireItem_Type) +# define PyActionGroup_Check(op) PyObject_TypeCheck(op, &PyActionGroup_Type) +# define PyCache_Check(op) PyObject_TypeCheck(op, &PyCache_Type) +# define PyCacheFile_Check(op) PyObject_TypeCheck(op, &PyCacheFile_Type) +# define PyCdrom_Check(op) PyObject_TypeCheck(op, &PyCdrom_Type) +# define PyConfiguration_Check(op) PyObject_TypeCheck(op, &PyConfiguration_Type) +# define PyDepCache_Check(op) PyObject_TypeCheck(op, &PyDepCache_Type) +# define PyDependency_Check(op) PyObject_TypeCheck(op, &PyDependency_Type) +# define PyDependencyList_Check(op) PyObject_TypeCheck(op, &PyDependencyList_Type) +# define PyDescription_Check(op) PyObject_TypeCheck(op, &PyDescription_Type) +# define PyHashes_Check(op) PyObject_TypeCheck(op, &PyHashes_Type) +# define PyHashString_Check(op) PyObject_TypeCheck(op, &PyHashString_Type) +# define PyIndexRecords_Check(op) PyObject_TypeCheck(op, &PyIndexRecords_Type) +# define PyMetaIndex_Check(op) PyObject_TypeCheck(op, &PyMetaIndex_Type) +# define PyPackage_Check(op) PyObject_TypeCheck(op, &PyPackage_Type) +# define PyPackageFile_Check(op) PyObject_TypeCheck(op, &PyPackageFile_Type) +# define PyPackageIndexFile_Check(op) PyObject_TypeCheck(op, &PyPackageIndexFile_Type) +# define PyPackageList_Check(op) PyObject_TypeCheck(op, &PyPackageList_Type) +# define PyPackageManager_Check(op) PyObject_TypeCheck(op, &PyPackageManager_Type) +# define PyPackageRecords_Check(op) PyObject_TypeCheck(op, &PyPackageRecords_Type) +# define PyPolicy_Check(op) PyObject_TypeCheck(op, &PyPolicy_Type) +# define PyProblemResolver_Check(op) PyObject_TypeCheck(op, &PyProblemResolver_Type) +# define PySourceList_Check(op) PyObject_TypeCheck(op, &PySourceList_Type) +# define PySourceRecords_Check(op) PyObject_TypeCheck(op, &PySourceRecords_Type) +# define PyTagFile_Check(op) PyObject_TypeCheck(op, &PyTagFile_Type) +# define PyTagSection_Check(op) PyObject_TypeCheck(op, &PyTagSection_Type) +# define PyVersion_Check(op) PyObject_TypeCheck(op, &PyVersion_Type) +// Exact check macros. +# define PyAcquire_CheckExact(op) (Py_TYPE(op) == &PyAcquire_Type) +# define PyAcquireFile_CheckExact(op) (Py_TYPE(op) == &PyAcquireFile_Type) +# define PyAcquireItem_CheckExact(op) (Py_TYPE(op) == &PyAcquireItem_Type) +# define PyActionGroup_CheckExact(op) (Py_TYPE(op) == &PyActionGroup_Type) +# define PyCache_CheckExact(op) (Py_TYPE(op) == &PyCache_Type) +# define PyCacheFile_CheckExact(op) (Py_TYPE(op) == &PyCacheFile_Type) +# define PyCdrom_CheckExact(op) (Py_TYPE(op) == &PyCdrom_Type) +# define PyConfiguration_CheckExact(op) (Py_TYPE(op) == &PyConfiguration_Type) +# define PyDepCache_CheckExact(op) (Py_TYPE(op) == &PyDepCache_Type) +# define PyDependency_CheckExact(op) (Py_TYPE(op) == &PyDependency_Type) +# define PyDependencyList_CheckExact(op) (Py_TYPE(op) == &PyDependencyList_Type) +# define PyDescription_CheckExact(op) (Py_TYPE(op) == &PyDescription_Type) +# define PyHashes_CheckExact(op) (Py_TYPE(op) == &PyHashes_Type) +# define PyHashString_CheckExact(op) (Py_TYPE(op) == &PyHashString_Type) +# define PyIndexRecords_CheckExact(op) (Py_TYPE(op) == &PyIndexRecords_Type) +# define PyMetaIndex_CheckExact(op) (Py_TYPE(op) == &PyMetaIndex_Type) +# define PyPackage_CheckExact(op) (Py_TYPE(op) == &PyPackage_Type) +# define PyPackageFile_CheckExact(op) (Py_TYPE(op) == &PyPackageFile_Type) +# define PyPackageIndexFile_CheckExact(op) (Py_TYPE(op) == &PyPackageIndexFile_Type) +# define PyPackageList_CheckExact(op) (Py_TYPE(op) == &PyPackageList_Type) +# define PyPackageManager_CheckExact(op) (Py_TYPE(op) == &PyPackageManager_Type) +# define PyPackageRecords_CheckExact(op) (Py_TYPE(op) == &PyPackageRecords_Type) +# define PyPolicy_CheckExact(op) (Py_TYPE(op) == &PyPolicy_Type) +# define PyProblemResolver_CheckExact(op) (Py_TYPE(op) == &PyProblemResolver_Type) +# define PySourceList_CheckExact(op) (Py_TYPE(op) == &PySourceList_Type) +# define PySourceRecords_CheckExact(op) (Py_TYPE(op) == &PySourceRecords_Type) +# define PyTagFile_CheckExact(op) (Py_TYPE(op) == &PyTagFile_Type) +# define PyTagSection_CheckExact(op) (Py_TYPE(op) == &PyTagSection_Type) +# define PyVersion_CheckExact(op) (Py_TYPE(op) == &PyVersion_Type) + +// Get the underlying C++ reference or pointer from the Python object. +# define PyAcquire_ToCpp GetCpp +# define PyAcquireFile_ToCpp GetCpp +# define PyAcquireItem_ToCpp GetCpp +# define PyActionGroup_ToCpp GetCpp +# define PyCache_ToCpp GetCpp +# define PyCacheFile_ToCpp GetCpp +# define PyCdrom_ToCpp GetCpp +# define PyConfiguration_ToCpp GetCpp +# define PyDepCache_ToCpp GetCpp +# define PyDependency_ToCpp GetCpp +//# define PyDependencyList_ToCpp GetCpp // NOT EXPORTED +# define PyDescription_ToCpp GetCpp +# define PyHashes_ToCpp GetCpp +# define PyHashString_ToCpp GetCpp +# define PyIndexRecords_ToCpp GetCpp +# define PyMetaIndex_ToCpp GetCpp +# define PyPackage_ToCpp GetCpp +# define PyPackageFile_ToCpp GetCpp +# define PyPackageIndexFile_ToCpp GetCpp +//# define PyPackageList_ToCpp GetCpp // NOT EXPORTED. +# define PyPackageManager_ToCpp GetCpp +//# define PyPackageRecords_ToCpp GetCpp // NOT EXPORTED +# define PyPolicy_ToCpp GetCpp +# define PyProblemResolver_ToCpp GetCpp +# define PySourceList_ToCpp GetCpp +//# define PySourceRecords_ToCpp GetCpp // NOT EXPORTED +# define PyTagFile_ToCpp GetCpp +# define PyTagSection_ToCpp GetCpp +# define PyVersion_ToCpp GetCpp + +// Python object creation, using two inline template functions and one variadic +// macro per type. +template +inline PyObject *FromCpp(PyTypeObject *pytype, Cpp obj, bool Delete=false) +{ + CppPyObject *Obj = CppPyObject_NEW(pytype, obj); + Obj->NoDelete = (!Delete); + return Obj; +} + +template +inline PyObject *FromCppOwned(PyTypeObject *pytype, Cpp const &obj, + bool Delete=false, PyObject *Owner=NULL) +{ + CppOwnedPyObject *Obj = CppOwnedPyObject_NEW(Owner, pytype, obj); + Obj->NoDelete = (!Delete); + return Obj; +} + +# define PyAcquire_FromCpp(...) FromCpp(&PyAcquire_Type, ##__VA_ARGS__) +# define PyAcquireFile_FromCpp(...) FromCppOwned(&PyAcquireFile_Type, ##__VA_ARGS__) +# define PyAcquireItem_FromCpp(...) FromCppOwned(&PyAcquireItemType,##__VA_ARGS__) +# define PyActionGroup_FromCpp(...) FromCppOwned(&PyActionGroup_Type,##__VA_ARGS__) +# define PyCache_FromCpp(...) FromCppOwned(&PyCache_Type,##__VA_ARGS__) +# define PyCacheFile_FromCpp(...) FromCpp(&PyCacheFile_Type,##__VA_ARGS__) +# define PyCdrom_FromCpp(...) FromCpp(&PyCdromType,##__VA_ARGS__) +# define PyConfiguration_FromCpp(...) FromCppOwned(&PyConfiguration_Type, ##__VA_ARGS__) +# define PyDepCache_FromCpp(...) FromCppOwned(&PyDepCache_Type,##__VA_ARGS__) +# define PyDependency_FromCpp(...) FromCppOwned(&PyDependency_Type,##__VA_ARGS__) +//# define PyDependencyList_FromCpp(...) FromCppOwned(&PyDependencyList_Type,##__VA_ARGS__) +# define PyDescription_FromCpp(...) FromCppOwned(&PyDescription_Type,##__VA_ARGS__) +# define PyHashes_FromCpp(...) FromCpp(&PyHashes_Type,##__VA_ARGS__) +# define PyHashString_FromCpp(...) FromCpp(&PyHashString_Type,##__VA_ARGS__) +# define PyIndexRecords_FromCpp(...) FromCpp(&PyIndexRecords_Type,##__VA_ARGS__) +# define PyMetaIndex_FromCpp(...) FromCppOwned(&PyMetaIndex_Type,##__VA_ARGS__) +# define PyPackage_FromCpp(...) FromCppOwned(&PyPackage_Type,##__VA_ARGS__) +# define PyPackageIndexFile_FromCpp(...) FromCppOwned(&PyPackageIndexFile_Type,##__VA_ARGS__) +# define PyPackageFile_FromCpp(...) FromCppOwned(&PyPackageFile_Type,##__VA_ARGS__) +//# define PyPackageList_FromCpp(...) FromCppOwned(&PyPackageList_Type,##__VA_ARGS__) +# define PyPackageManager_FromCpp(...) FromCpp(&PyPackageManagerType,##__VA_ARGS__) +//# define PyPackageRecords_FromCpp(...) FromCppOwned(&PyPackageRecords_Type,##__VA_ARGS__) +# define PyPolicy_FromCpp(...) FromCppOwned(&PyPolicy_Type,##__VA_ARGS__) +# define PyProblemResolver_FromCpp(...) FromCppOwned(&PyProblemResolver_Type,##__VA_ARGS__) +# define PySourceList_FromCpp(...) FromCpp(&PySourceList_Type,##__VA_ARGS__) +//# define PySourceRecords_FromCpp(...) FromCpp(&PySourceRecords_Type,##__VA_ARGS__) +//# define PyTagFile_FromCpp(...) FromCppOwned(&PyTagFile_Type,##__VA_ARGS__) +# define PyTagSection_FromCpp(...) FromCppOwned(&PyTagSection_Type,##__VA_ARGS__) +# define PyVersion_FromCpp(...) FromCppOwned(&PyVersion_Type,##__VA_ARGS__) +#endif -- cgit v1.2.3 From aaf5907863bed9a044fa0e3e2eacd1ca2de53c59 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 15 Jul 2009 21:36:58 +0200 Subject: Introduce new progress (base) classes in apt_pkg: - apt_pkg.AcquireProgress - apt_pkg.OpProgress --- debian/changelog | 3 + python/acquireprogress.cc | 198 ++++++++++++++++++++++++++++++++++++++++++++++ python/apt_pkgmodule.cc | 2 + python/apt_pkgmodule.h | 2 + python/opprogress.cc | 173 ++++++++++++++++++++++++++++++++++++++++ python/progress.cc | 14 +++- setup.py | 5 +- 7 files changed, 393 insertions(+), 4 deletions(-) create mode 100644 python/acquireprogress.cc create mode 100644 python/opprogress.cc (limited to 'python/apt_pkgmodule.h') diff --git a/debian/changelog b/debian/changelog index 5e3ec667..b2936ba1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -39,6 +39,9 @@ python-apt (0.7.92) UNRELEASED; urgency=low work around a bug in debhelper. * Build-Depend on python-all-dev (>= 2.5.4-3), so we build for Python 2.6 * Simplify the whole building, build all Python versions with setup.py + * Introduce new progress (base) classes in apt_pkg: + - apt_pkg.AcquireProgress + - apt_pkg.OpProgress [ Sebastian Heinlein ] * apt/progress.py: Extract the package name from the status message diff --git a/python/acquireprogress.cc b/python/acquireprogress.cc new file mode 100644 index 00000000..ac3b8fd9 --- /dev/null +++ b/python/acquireprogress.cc @@ -0,0 +1,198 @@ +/* acquireprogress.cc - Base class for FetchProgress classes. + * + * Copyright 2009 Julian Andres Klode + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#include "generic.h" +#include +#include + +typedef struct { + PyObject_HEAD + double last_bytes; + double current_cps; + double current_bytes; + double total_bytes; + double fetched_bytes; + unsigned long elapsed_time; + unsigned long total_items; + unsigned long current_items; +} PyAcquireProgressObject; + + +// DUMMY IMPLEMENTATIONS. +static char *acquireprogress_media_change_doc = + "media_change(media: str, drive: str) -> bool\n\n" + "Invoked when the user should be prompted to change the inserted\n" + "removable media.\n\n" + "This method should not return until the user has confirmed to the user\n" + "interface that the media change is complete.\n\n" + ":param:media The name of the media type that should be changed.\n" + ":param:drive The identifying name of the drive whose media should be\n" + " changed.\n\n" + "Return True if the user confirms the media change, False if it is\n" + "cancelled."; +static PyObject *acquireprogress_media_change(PyObject *self, PyObject *args) +{ + Py_RETURN_FALSE; +} + +static char *acquireprogress_ims_hit_doc = "ims_hit(item: AcquireItemDesc)\n\n" + "Invoked when an item is confirmed to be up-to-date. For instance,\n" + "when an HTTP download is informed that the file on the server was\n" + "not modified."; +static PyObject *acquireprogress_ims_hit(PyObject *self, PyObject *arg) +{ + // TODO: Add type check. + Py_RETURN_NONE; +} + +static char *acquireprogress_fetch_doc = "fetch(item: AcquireItemDesc)\n\n" + "Invoked when some of an item's data is fetched."; +static PyObject *acquireprogress_fetch(PyObject *self, PyObject *args) +{ + // TODO: Add type check. + Py_RETURN_NONE; +} + +static char *acquireprogress_done_doc = "done(item: AcquireItemDesc)\n\n" + "Invoked when an item is successfully and completely fetched."; +static PyObject *acquireprogress_done(PyObject *self, PyObject *args) +{ + // TODO: Add type check. + Py_RETURN_NONE; +} + +static char *acquireprogress_fail_doc = "fail(item: AcquireItemDesc)\n\n" + "Invoked when the process of fetching an item encounters a fatal error."; +static PyObject *acquireprogress_fail(PyObject *self, PyObject *args) +{ + // TODO: Add type check. + Py_RETURN_NONE; +} + +static char *acquireprogress_pulse_doc = "pulse(owner: Acquire) -> bool\n\n" + "Periodically invoked while the Acquire process is underway.\n\n" + "Return False if the user asked to cancel the whole Acquire process."; +static PyObject *acquireprogress_pulse(PyObject *self, PyObject *args) +{ + // TODO: Add type check. + Py_RETURN_TRUE; +} + +static char *acquireprogress_start_doc = "start()\n\n" + "Invoked when the Acquire process starts running."; +static PyObject *acquireprogress_start(PyObject *self, PyObject *args) +{ + Py_RETURN_NONE; +} + +static char *acquireprogress_stop_doc = "stop()\n\n" + "Invoked when the Acquire process stops running."; +static PyObject *acquireprogress_stop(PyObject *self, PyObject *args) +{ + Py_RETURN_NONE; +} + +static PyMethodDef acquireprogress_methods[] = { + {"media_change", acquireprogress_media_change, METH_VARARGS, + acquireprogress_media_change_doc}, + {"ims_hit",acquireprogress_ims_hit,METH_VARARGS, + acquireprogress_ims_hit_doc}, + {"fetch",acquireprogress_fetch,METH_VARARGS,acquireprogress_fetch_doc}, + {"done",acquireprogress_done,METH_VARARGS,acquireprogress_done_doc}, + {"fail",acquireprogress_fail,METH_VARARGS,acquireprogress_fail_doc}, + {"pulse",acquireprogress_pulse,METH_VARARGS,acquireprogress_pulse_doc}, + {"start",acquireprogress_start,METH_NOARGS,acquireprogress_start_doc}, + {"stop",acquireprogress_stop,METH_NOARGS,acquireprogress_stop_doc}, + {NULL} +}; + +static PyMemberDef acquireprogress_members[] = { + {"last_bytes", T_DOUBLE, offsetof(PyAcquireProgressObject, last_bytes), 0, + "The number of bytes fetched as of the previous call to pulse(),\n" + "including local items."}, + {"current_cps", T_DOUBLE, offsetof(PyAcquireProgressObject, current_cps), 0, + "The current rate of download, in bytes per second."}, + {"current_bytes", T_DOUBLE, offsetof(PyAcquireProgressObject, current_bytes), + 0, "The number of bytes fetched."}, + {"total_bytes", T_DOUBLE, offsetof(PyAcquireProgressObject, total_bytes), 0, + "The total number of bytes that need to be fetched. This member is\n" + "inaccurate, as new items might be enqueued while the download is\n" + "in progress!"}, + {"fetched_bytes", T_DOUBLE,offsetof(PyAcquireProgressObject, fetched_bytes), + 0, "The total number of bytes accounted for by items that were\n" + "successfully fetched."}, + {"elapsed_time", T_ULONG, offsetof(PyAcquireProgressObject, elapsed_time),0, + "The amount of time that has elapsed since the download started."}, + {"total_items", T_ULONG, offsetof(PyAcquireProgressObject, total_items),0, + "The total number of items that need to be fetched. This member is\n" + "inaccurate, as new items might be enqueued while the download is\n" + "in progress!"}, + {"current_items", T_ULONG, offsetof(PyAcquireProgressObject, current_items), + 0, "The number of items that have been successfully downloaded."}, + {NULL} +}; + +static char *acquireprogress_doc = "AcquireProgress()\n\n" + "A monitor object for downloads controlled by the Acquire class. This is\n" + "an mostly abstract class. You should subclass it and implement the\n" + "methods to get something useful."; + +PyTypeObject PyAcquireProgress_Type = { + PyVarObject_HEAD_INIT(&PyType_Type, 0) + "apt_pkg.AcquireProgress", // tp_name + sizeof(PyAcquireProgressObject), // tp_basicsize + 0, // tp_itemsize + // Methods + 0, // tp_dealloc + 0, // tp_print + 0, // 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 + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE, + acquireprogress_doc, // tp_doc + 0, // tp_traverse + 0, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + acquireprogress_methods, // tp_methods + acquireprogress_members, // tp_members + 0, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + PyType_GenericNew, // tp_new +}; diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index bc2f4258..4f948847 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -621,6 +621,8 @@ extern "C" void initapt_pkg() ADDTYPE(Module,"HashString",&PyHashString_Type); ADDTYPE(Module,"Policy",&PyPolicy_Type); ADDTYPE(Module,"Hashes",&PyHashes_Type); + ADDTYPE(Module,"OpProgress",&PyOpProgress_Type); + ADDTYPE(Module,"AcquireProgress",&PyAcquireProgress_Type); // Tag file constants PyModule_AddObject(Module,"REWRITE_PACKAGE_ORDER", CharCharToList(TFRewritePackageOrder)); diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index 97be5d5c..34bc2ae5 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -112,6 +112,8 @@ extern PyTypeObject PyIndexRecords_Type; // Policy extern PyTypeObject PyPolicy_Type; extern PyTypeObject PyHashes_Type; +extern PyTypeObject PyOpProgress_Type; +extern PyTypeObject PyAcquireProgress_Type; #include "python-apt.h" #endif diff --git a/python/opprogress.cc b/python/opprogress.cc new file mode 100644 index 00000000..450e290a --- /dev/null +++ b/python/opprogress.cc @@ -0,0 +1,173 @@ +/* op-progress.cc - Base class for OpProgress classes. + * + * Copyright 2009 Julian Andres Klode + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#include "generic.h" +#include +#include + +typedef struct { + PyObject_HEAD + PyObject *op; + PyObject *subop; + int major_change; + float percent; +} PyOpProgressObject; + +static PyObject *opprogress_update(PyObject *Self, PyObject *args) +{ + Py_RETURN_NONE; +} + +static PyObject *opprogress_done(PyObject *Self, PyObject *args) +{ + Py_RETURN_NONE; +} + +static PyObject *opprogress_get_op(PyOpProgressObject *self, void *closure) +{ + return self->op; +} + +static int opprogress_set_op(PyOpProgressObject *self, PyObject *value, + void *closure) +{ + if (value == NULL) { + PyErr_SetString(PyExc_TypeError, "Cannot delete 'op'"); + return -1; + } + if (!PyString_Check(value)) { + PyErr_SetString(PyExc_TypeError,"'op' must be a string."); + return -1; + } + Py_DECREF(self->op); + Py_INCREF(value); + + self->op = value; + return 0; +} + +static PyObject *opprogress_get_subop(PyOpProgressObject *self, void *closure) +{ + return self->subop; +} + +static int opprogress_set_subop(PyOpProgressObject *self, PyObject *value, + void *closure) +{ + if (value == NULL) { + PyErr_SetString(PyExc_TypeError, "Cannot delete 'subop'."); + return -1; + } + if (!PyString_Check(value)) { + PyErr_SetString(PyExc_TypeError,"'subop' must be a string."); + return -1; + } + Py_DECREF(self->subop); + Py_INCREF(value); + self->subop = value; + return 0; +} + +static PyMethodDef opprogress_methods[] = { + {"update",opprogress_update,METH_NOARGS,"update()\n\nCalled periodically."}, + {"done",opprogress_done,METH_NOARGS,"update()\n\nCalled when done."}, + {NULL}, +}; + +static PyMemberDef opprogress_members[] = { + {"major_change", T_INT, offsetof(PyOpProgressObject, major_change), 0, + "Boolean value indicating whether the change is a major change."}, + {"percent", T_FLOAT, offsetof(PyOpProgressObject, percent), 0, + "Percentage of completion (float value)."}, + {NULL} +}; + +static PyGetSetDef opprogress_getset[] = { + {"op", (getter)opprogress_get_op, (setter)opprogress_set_op, + "Description of the current operation"}, + {"subop", (getter)opprogress_get_subop, (setter)opprogress_set_subop, + "Description of the current sub-operation"}, + {NULL}, +}; + +static void opprogress_dealloc(PyObject *self) +{ + Py_XDECREF(((PyOpProgressObject *)self)->op); + Py_XDECREF(((PyOpProgressObject *)self)->subop); + self->ob_type->tp_free(self); +} + +static PyObject *opprogress_new(PyTypeObject *type, PyObject *args, + PyObject *kwds) +{ + PyOpProgressObject *res = (PyOpProgressObject *)type->tp_alloc(type, 0); + res->op = PyString_FromString(""); + res->subop = PyString_FromString(""); + return (PyObject *)res; +} + +static char *opprogress_doc = "OpProgress()\n\n" + "A base class for writing custom operation progress classes. Subclasses\n" + "should override all the methods (and call the parent ones) but shall\n" + "not override any of the inherited descriptors because they may be\n" + "ignored."; + +PyTypeObject PyOpProgress_Type = { + PyVarObject_HEAD_INIT(&PyType_Type, 0) + "apt_pkg.OpProgress", // tp_name + sizeof(PyOpProgressObject), // tp_basicsize + 0, // tp_itemsize + // Methods + opprogress_dealloc, // tp_dealloc + 0, // tp_print + 0, // 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 + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE, + opprogress_doc, // tp_doc + 0, // tp_traverse + 0, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + opprogress_methods, // tp_methods + opprogress_members, // tp_members + opprogress_getset, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + opprogress_new, // tp_new +}; diff --git a/python/progress.cc b/python/progress.cc index 44f27b0c..b1845f0a 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -15,6 +15,7 @@ #include #include "progress.h" #include "generic.h" +#include "apt_pkgmodule.h" // generic bool PyCallbackObj::RunSimpleCallback(const char* method_name, @@ -75,11 +76,20 @@ void PyOpProgress::Update() PyObject_SetAttrString(callbackInst, "majorChange", o); Py_XDECREF(o); + + // Build up the argument list... if(CheckChange(0.05)) { - PyObject *arglist = Py_BuildValue("(f)", Percent); - RunSimpleCallback("update", arglist); + if (PyObject_TypeCheck(callbackInst, &PyOpProgress_Type)) { + o = Py_BuildValue("f", Percent); + PyObject_SetAttrString(callbackInst, "percent", o); + RunSimpleCallback("update"); + Py_XDECREF(o); + } else { + PyObject *arglist = Py_BuildValue("(f)", Percent); + RunSimpleCallback("update", arglist); + } } }; diff --git a/setup.py b/setup.py index af373632..b6dde3f9 100644 --- a/setup.py +++ b/setup.py @@ -34,8 +34,9 @@ files = ['apt_pkgmodule.cc', 'acquire.cc', 'cache.cc', 'cdrom.cc', 'configuration.cc', 'depcache.cc', 'generic.cc', 'hashes.cc', 'hashstring.cc', 'indexfile.cc', 'indexrecords.cc', 'metaindex.cc', 'pkgmanager.cc', 'pkgrecords.cc', 'pkgsrcrecords.cc', 'policy.cc', - 'progress.cc', 'sourcelist.cc', 'string.cc', 'tag.cc'] -files = ['python/' + fname for fname in files] + 'progress.cc', 'sourcelist.cc', 'string.cc', 'tag.cc', + 'opprogress.cc', 'acquireprogress.cc'] +files = sorted(['python/' + fname for fname in files]) apt_pkg = Extension("apt_pkg", files, libraries=["apt-pkg"]) # The apt_inst module -- cgit v1.2.3 From 48097301f9cc685a8ad1229a28f34d36ad19665b Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 15 Jul 2009 22:20:02 +0200 Subject: python/acquire.cc: Add AcquireItemDesc. --- python/acquire.cc | 73 ++++++++++++++++++++++++++++++++++++++++++++++++- python/apt_pkgmodule.cc | 2 ++ python/apt_pkgmodule.h | 1 + python/python-apt.h | 6 ++++ 4 files changed, 81 insertions(+), 1 deletion(-) (limited to 'python/apt_pkgmodule.h') diff --git a/python/acquire.cc b/python/acquire.cc index c3f2fc5d..6c4baf9c 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -20,6 +20,78 @@ struct PyAcquireObject : public CppPyObject { vector items; }; +static PyObject *acquireitemdesc_get_uri(PyObject *self, void *closure) +{ + return CppPyString(GetCpp(self).URI); +} +static PyObject *acquireitemdesc_get_description(PyObject *self, void *closure) +{ + return CppPyString(GetCpp(self).Description); +} +static PyObject *acquireitemdesc_get_shortdesc(PyObject *self, void *closure) +{ + return CppPyString(GetCpp(self).ShortDesc); +} +static PyObject *acquireitemdesc_get_owner(PyObject *self, void *closure) +{ + return GetOwner(self); +} + +static PyGetSetDef acquireitemdesc_getset[] = { + {"uri",acquireitemdesc_get_uri,0,"The URI from which to download this item."}, + {"description",acquireitemdesc_get_description}, + {"shortdesc",acquireitemdesc_get_shortdesc}, + {"owner",acquireitemdesc_get_owner}, + {NULL} +}; + +static char *acquireitemdesc_doc = + "Represent an AcquireItemDesc"; + +PyTypeObject PyAcquireItemDesc_Type = +{ + PyVarObject_HEAD_INIT(&PyType_Type, 0) + "apt_pkg.AcquireItemDesc", // tp_name + sizeof(CppOwnedPyObject),// tp_basicsize + 0, // tp_itemsize + // Methods + CppOwnedDealloc, // tp_dealloc + 0, // tp_print + 0, // 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 + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + (Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_HAVE_GC), + acquireitemdesc_doc, // tp_doc + CppOwnedTraverse,// tp_traverse + CppOwnedClear, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + 0, // tp_methods + 0, // tp_members + acquireitemdesc_getset, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + 0, // tp_new +}; + inline pkgAcquire::Item *acquireitem_tocpp(PyObject *self) { pkgAcquire::Item *itm = GetCpp(self); if (itm == 0) @@ -47,7 +119,6 @@ MkGet(AcquireItemGetIsTrusted,Py_BuildValue("i",Itm->IsTrusted())); MkGet(AcquireItemGetLocal,Py_BuildValue("i",Itm->Local)); MkGet(AcquireItemGetStatus,Py_BuildValue("i",Itm->Status)); - // Constants MkGet(AcquireItemGetStatIdle,Py_BuildValue("i", pkgAcquire::Item::StatIdle)); MkGet(AcquireItemGetStatFetching,Py_BuildValue("i", pkgAcquire::Item::StatFetching)); diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 4f948847..5d7b6c47 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -502,6 +502,7 @@ static struct _PyAptPkgAPIStruct API = { &PyAcquire_Type, // acquire_type &PyAcquireFile_Type, // acquirefile_type &PyAcquireItem_Type, // acquireitem_type + &PyAcquireItemDesc_Type, // acquireitemdesc_type &PyActionGroup_Type, // actiongroup_type &PyCache_Type, // cache_type &PyCacheFile_Type, // cachefile_type @@ -623,6 +624,7 @@ extern "C" void initapt_pkg() ADDTYPE(Module,"Hashes",&PyHashes_Type); ADDTYPE(Module,"OpProgress",&PyOpProgress_Type); ADDTYPE(Module,"AcquireProgress",&PyAcquireProgress_Type); + ADDTYPE(Module,"AcquireItemDesc",&PyAcquireItemDesc_Type); // Tag file constants PyModule_AddObject(Module,"REWRITE_PACKAGE_ORDER", CharCharToList(TFRewritePackageOrder)); diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index 34bc2ae5..835cfd9b 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -114,6 +114,7 @@ extern PyTypeObject PyPolicy_Type; extern PyTypeObject PyHashes_Type; extern PyTypeObject PyOpProgress_Type; extern PyTypeObject PyAcquireProgress_Type; +extern PyTypeObject PyAcquireItemDesc_Type; #include "python-apt.h" #endif diff --git a/python/python-apt.h b/python/python-apt.h index 16734238..53f6b0bb 100644 --- a/python/python-apt.h +++ b/python/python-apt.h @@ -28,6 +28,7 @@ struct _PyAptPkgAPIStruct { PyTypeObject *acquire_type; PyTypeObject *acquirefile_type; PyTypeObject *acquireitem_type; + PyTypeObject *acquireitemdesc_type; PyTypeObject *actiongroup_type; PyTypeObject *cache_type; PyTypeObject *cachefile_type; @@ -60,6 +61,7 @@ struct _PyAptPkgAPIStruct { # define PyAcquire_Type *(_PyAptPkg_API->acquire_type) # define PyAcquireFile_Type *(_PyAptPkg_API->acquirefile_type) # define PyAcquireItem_Type *(_PyAptPkg_API->acquireitem_type) +# define PyAcquireItemDesc_Type *(_PyAptPkg_API->acquireitemdesc_type) # define PyActionGroup_Type *(_PyAptPkg_API->actiongroup_type) # define PyCache_Type *(_PyAptPkg_API->cache_type) # define PyCacheFile_Type *(_PyAptPkg_API->cachefile_type) @@ -119,6 +121,7 @@ static int import_apt_pkg(void) { # define PyAcquire_Check(op) PyObject_TypeCheck(op, &PyAcquire_Type) # define PyAcquireFile_Check(op) PyObject_TypeCheck(op, &PyAcquireFile_Type) # define PyAcquireItem_Check(op) PyObject_TypeCheck(op, &PyAcquireItem_Type) +# define PyAcquireItemDesc_Check(op) PyObject_TypeCheck(op, &PyAcquireItemDesc_Type) # define PyActionGroup_Check(op) PyObject_TypeCheck(op, &PyActionGroup_Type) # define PyCache_Check(op) PyObject_TypeCheck(op, &PyCache_Type) # define PyCacheFile_Check(op) PyObject_TypeCheck(op, &PyCacheFile_Type) @@ -149,6 +152,7 @@ static int import_apt_pkg(void) { # define PyAcquire_CheckExact(op) (Py_TYPE(op) == &PyAcquire_Type) # define PyAcquireFile_CheckExact(op) (Py_TYPE(op) == &PyAcquireFile_Type) # define PyAcquireItem_CheckExact(op) (Py_TYPE(op) == &PyAcquireItem_Type) +# define PyAcquireItemDesc_CheckExact(op) (Py_TYPE(op) == &PyAcquireItemDesc_Type) # define PyActionGroup_CheckExact(op) (Py_TYPE(op) == &PyActionGroup_Type) # define PyCache_CheckExact(op) (Py_TYPE(op) == &PyCache_Type) # define PyCacheFile_CheckExact(op) (Py_TYPE(op) == &PyCacheFile_Type) @@ -180,6 +184,7 @@ static int import_apt_pkg(void) { # define PyAcquire_ToCpp GetCpp # define PyAcquireFile_ToCpp GetCpp # define PyAcquireItem_ToCpp GetCpp +# define PyAcquireItemDesc_ToCpp GetCpp # define PyActionGroup_ToCpp GetCpp # define PyCache_ToCpp GetCpp # define PyCacheFile_ToCpp GetCpp @@ -229,6 +234,7 @@ inline PyObject *FromCppOwned(PyTypeObject *pytype, Cpp const &obj, # define PyAcquire_FromCpp(...) FromCpp(&PyAcquire_Type, ##__VA_ARGS__) # define PyAcquireFile_FromCpp(...) FromCppOwned(&PyAcquireFile_Type, ##__VA_ARGS__) # define PyAcquireItem_FromCpp(...) FromCppOwned(&PyAcquireItemType,##__VA_ARGS__) +# define PyAcquireItemDesc_FromCpp(...) FromCppOwned(&PyAcquireItemDesc_Type,##__VA_ARGS__) # define PyActionGroup_FromCpp(...) FromCppOwned(&PyActionGroup_Type,##__VA_ARGS__) # define PyCache_FromCpp(...) FromCppOwned(&PyCache_Type,##__VA_ARGS__) # define PyCacheFile_FromCpp(...) FromCpp(&PyCacheFile_Type,##__VA_ARGS__) -- cgit v1.2.3 From ef106396218522fce5856744741c7b3f87261cc2 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 16 Jul 2009 16:03:02 +0200 Subject: python/acquire.cc: Introduce PyAcquireWorker_Type, make PyAcquireItemDesc_Type contain a pointer. --- python/acquire.cc | 108 +++++++++++++++++++++++++++++++++++++++++++----- python/apt_pkgmodule.cc | 13 +++--- python/apt_pkgmodule.h | 1 + python/progress.cc | 8 ++-- python/python-apt.h | 4 +- 5 files changed, 112 insertions(+), 22 deletions(-) (limited to 'python/apt_pkgmodule.h') diff --git a/python/acquire.cc b/python/acquire.cc index 6c4baf9c..25b10b06 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -11,6 +11,7 @@ #include "progress.h" #include +#include typedef CppPyObject PyAcquireItemObject; @@ -20,21 +21,93 @@ struct PyAcquireObject : public CppPyObject { vector items; }; + +static PyObject *acquireworker_get_current_item(PyObject *self, void *closure) +{ + return PyAcquireItemDesc_FromCpp((GetCpp(self)->CurrentItem),false,self); +} + +static PyObject *acquireworker_get_status(PyObject *self, void *closure) +{ + return CppPyString(GetCpp(self)->Status); +} + +static PyObject *acquireworker_get_current_size(PyObject *self, void *closure) +{ + return Py_BuildValue("k",GetCpp(self)->CurrentSize); +} + +static PyObject *acquireworker_get_total_size(PyObject *self, void *closure) +{ + return Py_BuildValue("k",GetCpp(self)->TotalSize); +} + +static PyObject *acquireworker_get_resumepoint(PyObject *self, void *closure) +{ + return Py_BuildValue("k",GetCpp(self)->ResumePoint); +} + +static PyGetSetDef acquireworker_getset[] = { + {"current_item",acquireworker_get_current_item}, + {"status",acquireworker_get_status}, + {"current_size",acquireworker_get_current_size}, + {"total_size",acquireworker_get_total_size}, + {"resumepoint",acquireworker_get_resumepoint}, + {NULL} +}; + + +PyTypeObject PyAcquireWorker_Type = +{ + PyVarObject_HEAD_INIT(&PyType_Type, 0) + "apt_pkg.AcquireWorker", // tp_name + sizeof(CppOwnedPyObject),// tp_basicsize + 0, // tp_itemsize + // Methods + CppOwnedDealloc, // tp_dealloc + 0, // tp_print + 0, // 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 + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + Py_TPFLAGS_DEFAULT| // tp_flags + Py_TPFLAGS_HAVE_GC, + 0, // tp_doc + CppOwnedTraverse, // tp_traverse + CppOwnedClear, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + 0, // tp_methods + 0, // tp_members + acquireworker_getset, // tp_getset +}; + static PyObject *acquireitemdesc_get_uri(PyObject *self, void *closure) { - return CppPyString(GetCpp(self).URI); + return CppPyString(GetCpp(self)->URI); } static PyObject *acquireitemdesc_get_description(PyObject *self, void *closure) { - return CppPyString(GetCpp(self).Description); + return CppPyString(GetCpp(self)->Description); } static PyObject *acquireitemdesc_get_shortdesc(PyObject *self, void *closure) { - return CppPyString(GetCpp(self).ShortDesc); + return CppPyString(GetCpp(self)->ShortDesc); } static PyObject *acquireitemdesc_get_owner(PyObject *self, void *closure) { - return GetOwner(self); + return GetOwner(self); } static PyGetSetDef acquireitemdesc_getset[] = { @@ -52,10 +125,10 @@ PyTypeObject PyAcquireItemDesc_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.AcquireItemDesc", // tp_name - sizeof(CppOwnedPyObject),// tp_basicsize + sizeof(CppOwnedPyObject),// tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppOwnedDealloc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -73,8 +146,8 @@ PyTypeObject PyAcquireItemDesc_Type = (Py_TPFLAGS_DEFAULT | // tp_flags Py_TPFLAGS_HAVE_GC), acquireitemdesc_doc, // tp_doc - CppOwnedTraverse,// tp_traverse - CppOwnedClear, // tp_clear + CppOwnedTraverse,// tp_traverse + CppOwnedClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -184,13 +257,13 @@ static void AcquireItemDealloc(PyObject *self) { pkgAcquire::Item *file = GetCpp(self); PyAcquireObject *owner = (PyAcquireObject *)GetOwner(self); - // Simply deallocate the object if we have no owner. + // Simply deallocate the object if we have no owner. if (owner == NULL) { CppOwnedDeallocPtr(self); return; } vector &items = owner->items; - bool DeletePtr = !((CppPyObject *)self)->NoDelete; + bool DeletePtr = !((CppPyObject *)self)->NoDelete; // Cleanup the other objects as well... for (vector::iterator I = items.begin(); @@ -307,6 +380,20 @@ static PyObject *PkgAcquireGetPartialPresent(PyObject *Self,void*) { return Py_BuildValue("d", fetcher->PartialPresent()); } #undef fetcher + +static PyObject *PkgAcquireGetWorkers(PyObject *self, void *closure) +{ + PyObject *List = PyList_New(0); + pkgAcquire *Owner = GetCpp(self); + CppOwnedPyObject *PyWorker = NULL; + for(pkgAcquire::Worker *Worker = Owner->WorkersBegin(); + Worker != 0; Worker = Owner->WorkerStep(Worker)) { + PyWorker = CppOwnedPyObject_NEW(self,&PyAcquireWorker_Type, Worker); + PyWorker->NoDelete = true; + PyList_Append(List, PyWorker); + } + return List; +} static PyObject *PkgAcquireGetItems(PyObject *Self,void*) { pkgAcquire *fetcher = GetCpp(Self); @@ -337,6 +424,7 @@ static PyObject *PkgAcquireGetResultCancelled(PyObject *Self,void*) { static PyGetSetDef PkgAcquireGetSet[] = { {"fetch_needed",PkgAcquireGetFetchNeeded}, {"items",PkgAcquireGetItems}, + {"workers",PkgAcquireGetWorkers}, {"partial_present",PkgAcquireGetPartialPresent}, {"result_cancelled",PkgAcquireGetResultCancelled}, {"result_continue",PkgAcquireGetResultContinue}, diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 5d7b6c47..a7392f58 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -450,27 +450,27 @@ static PyMethodDef methods[] = {"newConfiguration",newConfiguration,METH_VARARGS,doc_newConfiguration}, {"InitConfig",InitConfig,METH_VARARGS,doc_InitConfig}, {"InitSystem",InitSystem,METH_VARARGS,doc_InitSystem}, - + {"ParseSection",ParseSection,METH_VARARGS,doc_ParseSection}, {"ParseTagFile",ParseTagFile,METH_VARARGS,doc_ParseTagFile}, {"RewriteSection",RewriteSection,METH_VARARGS,doc_RewriteSection}, - + {"GetLock",GetLock,METH_VARARGS,doc_GetLock}, {"PkgSystemLock",PkgSystemLock,METH_VARARGS,doc_PkgSystemLock}, {"PkgSystemUnLock",PkgSystemUnLock,METH_VARARGS,doc_PkgSystemUnLock}, - + {"ReadConfigFile",LoadConfig,METH_VARARGS,doc_LoadConfig}, {"ReadConfigDir",LoadConfigDir,METH_VARARGS,doc_LoadConfigDir}, {"ReadConfigFileISC",LoadConfigISC,METH_VARARGS,doc_LoadConfig}, {"ParseCommandLine",ParseCommandLine,METH_VARARGS,doc_ParseCommandLine}, - + {"VersionCompare",VersionCompare,METH_VARARGS,doc_VersionCompare}, {"CheckDep",CheckDep,METH_VARARGS,doc_CheckDep}, {"UpstreamVersion",UpstreamVersion,METH_VARARGS,doc_UpstreamVersion}, {"ParseDepends",ParseDepends_old,METH_VARARGS,doc_ParseDepends}, {"ParseSrcDepends",ParseSrcDepends_old,METH_VARARGS,doc_ParseDepends}, - + {"CheckDomainList",StrCheckDomainList,METH_VARARGS,"CheckDomainList(String,String) -> Bool"}, {"QuoteString",StrQuoteString,METH_VARARGS,"QuoteString(String,String) -> String"}, {"DeQuoteString",StrDeQuote,METH_VARARGS,"DeQuoteString(String) -> String"}, @@ -481,7 +481,7 @@ static PyMethodDef methods[] = {"StringToBool",StrStringToBool,METH_VARARGS,"StringToBool(String) -> int"}, {"TimeRFC1123",StrTimeRFC1123,METH_VARARGS,"TimeRFC1123(int) -> String"}, {"StrToTime",StrStrToTime,METH_VARARGS,"StrToTime(String) -> Int"}, - + {"GetCache",TmpGetCache,METH_VARARGS,"GetCache() -> PkgCache"}, {"GetDepCache",GetDepCache,METH_VARARGS,"GetDepCache(Cache) -> DepCache"}, {"GetPkgRecords",GetPkgRecords,METH_VARARGS,"GetPkgRecords(Cache) -> PkgRecords"}, @@ -589,6 +589,7 @@ extern "C" void initapt_pkg() ADDTYPE(Module,"Acquire",&PyAcquire_Type); ADDTYPE(Module,"AcquireFile",&PyAcquireFile_Type); ADDTYPE(Module,"AcquireItem",&PyAcquireItem_Type); // NO __new__() + ADDTYPE(Module,"AcquireWorker",&PyAcquireWorker_Type); // NO __new__() /* ============================ cache.cc ============================ */ ADDTYPE(Module,"Cache",&PyCache_Type); ADDTYPE(Module,"Dependency",&PyDependency_Type); // NO __new__() diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index 835cfd9b..ad1fe9fe 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -115,6 +115,7 @@ extern PyTypeObject PyHashes_Type; extern PyTypeObject PyOpProgress_Type; extern PyTypeObject PyAcquireProgress_Type; extern PyTypeObject PyAcquireItemDesc_Type; +extern PyTypeObject PyAcquireWorker_Type; #include "python-apt.h" #endif diff --git a/python/progress.cc b/python/progress.cc index 753949af..18e038dd 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -156,7 +156,7 @@ void PyFetchProgress::UpdateStatus(pkgAcquire::ItemDesc &Itm, int status) void PyFetchProgress::IMSHit(pkgAcquire::ItemDesc &Itm) { if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) - RunSimpleCallback("ims_hit", TUPLEIZE(PyAcquireItemDesc_FromCpp(Itm))); + RunSimpleCallback("ims_hit", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); else UpdateStatus(Itm, DLHit); } @@ -164,7 +164,7 @@ void PyFetchProgress::IMSHit(pkgAcquire::ItemDesc &Itm) void PyFetchProgress::Fetch(pkgAcquire::ItemDesc &Itm) { if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) - RunSimpleCallback("fetch", TUPLEIZE(PyAcquireItemDesc_FromCpp(Itm))); + RunSimpleCallback("fetch", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); else UpdateStatus(Itm, DLQueued); } @@ -172,7 +172,7 @@ void PyFetchProgress::Fetch(pkgAcquire::ItemDesc &Itm) void PyFetchProgress::Done(pkgAcquire::ItemDesc &Itm) { if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) - RunSimpleCallback("done", TUPLEIZE(PyAcquireItemDesc_FromCpp(Itm))); + RunSimpleCallback("done", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); else UpdateStatus(Itm, DLDone); } @@ -190,7 +190,7 @@ void PyFetchProgress::Fail(pkgAcquire::ItemDesc &Itm) if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) - RunSimpleCallback("fail", TUPLEIZE(PyAcquireItemDesc_FromCpp(Itm))); + RunSimpleCallback("fail", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); else UpdateStatus(Itm, DLFailed); } diff --git a/python/python-apt.h b/python/python-apt.h index fa589c55..d2693920 100644 --- a/python/python-apt.h +++ b/python/python-apt.h @@ -184,7 +184,7 @@ static int import_apt_pkg(void) { # define PyAcquire_ToCpp GetCpp # define PyAcquireFile_ToCpp GetCpp # define PyAcquireItem_ToCpp GetCpp -# define PyAcquireItemDesc_ToCpp GetCpp +# define PyAcquireItemDesc_ToCpp GetCpp # define PyActionGroup_ToCpp GetCpp # define PyCache_ToCpp GetCpp # define PyCacheFile_ToCpp GetCpp @@ -234,7 +234,7 @@ inline PyObject *FromCppOwned(PyTypeObject *pytype, Cpp const &obj, # define PyAcquire_FromCpp(...) FromCpp(&PyAcquire_Type, ##__VA_ARGS__) # define PyAcquireFile_FromCpp(...) FromCppOwned(&PyAcquireFile_Type, ##__VA_ARGS__) # define PyAcquireItem_FromCpp(...) FromCppOwned(&PyAcquireItem_Type,##__VA_ARGS__) -# define PyAcquireItemDesc_FromCpp(...) FromCppOwned(&PyAcquireItemDesc_Type,##__VA_ARGS__) +# define PyAcquireItemDesc_FromCpp(...) FromCppOwned(&PyAcquireItemDesc_Type,##__VA_ARGS__) # define PyActionGroup_FromCpp(...) FromCppOwned(&PyActionGroup_Type,##__VA_ARGS__) # define PyCache_FromCpp(...) FromCppOwned(&PyCache_Type,##__VA_ARGS__) # define PyCacheFile_FromCpp(...) FromCpp(&PyCacheFile_Type,##__VA_ARGS__) -- cgit v1.2.3 From 5c219e07aea347f652cf7949dc74f37282a17144 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sun, 19 Jul 2009 14:39:41 +0200 Subject: python/cdromprogress.cc: Add apt_pkg.CdromProgress. --- apt/progress/old.py | 22 ++-------- python/apt_pkgmodule.cc | 1 + python/apt_pkgmodule.h | 1 + python/cdrom.cc | 11 +++++ python/cdromprogress.cc | 106 ++++++++++++++++++++++++++++++++++++++++++++++++ python/progress.cc | 12 ++++-- python/progress.h | 6 +++ 7 files changed, 137 insertions(+), 22 deletions(-) create mode 100644 python/cdromprogress.cc (limited to 'python/apt_pkgmodule.h') diff --git a/apt/progress/old.py b/apt/progress/old.py index d4ff5815..63fc5d2e 100644 --- a/apt/progress/old.py +++ b/apt/progress/old.py @@ -343,27 +343,13 @@ class InstallProgress(DumbInstallProgress): updateInterface = function_deprecated_by(update_interface) -class CdromProgress(object): +class CdromProgress(apt_pkg.CdromProgress): """Report the cdrom add progress. - Subclass this class to implement cdrom add progress reporting. + This class has been replaced by apt_pkg.CdromProgress. """ - - def __init__(self): - pass - - def update(self, text, step): - """Called periodically to update the user interface.""" - - def ask_cdrom_name(self): - """Called to ask for the name of the cdrom.""" - - def change_cdrom(self): - """Called to ask for the cdrom to be changed.""" - - if apt_pkg._COMPAT_0_7: - askCdromName = function_deprecated_by(ask_cdrom_name) - changeCdrom = function_deprecated_by(change_cdrom) + askCdromName = function_deprecated_by(apt_pkg.CdromProgress.ask_cdrom_name) + changeCdrom = function_deprecated_by(apt_pkg.CdromProgress.change_cdrom) class DpkgInstallProgress(InstallProgress): diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index d6b8e3d1..b6ae709e 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -651,6 +651,7 @@ extern "C" void initapt_pkg() ADDTYPE(Module,"OpProgress",&PyOpProgress_Type); ADDTYPE(Module,"AcquireProgress",&PyAcquireProgress_Type); ADDTYPE(Module,"AcquireItemDesc",&PyAcquireItemDesc_Type); + ADDTYPE(Module,"CdromProgress",&PyCdromProgress_Type); // Tag file constants PyModule_AddObject(Module,"REWRITE_PACKAGE_ORDER", CharCharToList(TFRewritePackageOrder)); diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index ad1fe9fe..1277ab60 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -114,6 +114,7 @@ extern PyTypeObject PyPolicy_Type; extern PyTypeObject PyHashes_Type; extern PyTypeObject PyOpProgress_Type; extern PyTypeObject PyAcquireProgress_Type; +extern PyTypeObject PyCdromProgress_Type; extern PyTypeObject PyAcquireItemDesc_Type; extern PyTypeObject PyAcquireWorker_Type; #include "python-apt.h" diff --git a/python/cdrom.cc b/python/cdrom.cc index 50d1b4b1..6ee3becd 100644 --- a/python/cdrom.cc +++ b/python/cdrom.cc @@ -34,9 +34,20 @@ static PyObject *PkgCdromIdent(PyObject *Self,PyObject *Args) pkgCdrom &Cdrom = GetCpp(Self); PyObject *pyCdromProgressInst = 0; +#ifdef COMPAT_0_7 if (PyArg_ParseTuple(Args, "O", &pyCdromProgressInst) == 0) { +#else + if (PyArg_ParseTuple(Args, "O!", &PyCdromProgress_Type, + &pyCdromProgressInst) == 0) { +#endif return 0; } +#ifdef COMPAT_0_7 + if (!PyObject_TypeCheck(pyCdromProgressInst, &PyCdromProgress_Type)) { + PyErr_WarnEx(PyExc_DeprecationWarning, "Argument should be a subclass of" + " apt_pkg.CdromProgress.", 1); + } +#endif PyCdromProgress progress; progress.setCallbackInst(pyCdromProgressInst); diff --git a/python/cdromprogress.cc b/python/cdromprogress.cc new file mode 100644 index 00000000..09c76a2a --- /dev/null +++ b/python/cdromprogress.cc @@ -0,0 +1,106 @@ +/* cdromprogress.cc - Base class for CdromProgress classes. + * + * Copyright 2009 Julian Andres Klode + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ +#include "apt_pkgmodule.h" +#include "progress.h" +#include +#include + +// Takes two arguments (string, int) +static PyObject *cdromprogress_update(PyObject *self, PyObject *args) +{ + Py_RETURN_NONE; +} + +// Takes no arguments +static PyObject *cdromprogress_change_cdrom(PyObject *self, PyObject *args) +{ + Py_RETURN_FALSE; +} + +// Takes a single PyObject argument as *arg +static PyObject *cdromprogress_ask_cdrom_name(PyObject *self, PyObject *arg) +{ + Py_RETURN_FALSE; +} + +static PyMethodDef cdromprogress_methods[] = { + {"update",cdromprogress_update,METH_VARARGS, + "update(text: str, current: int)\n\nCalled regularly."}, + {"change_cdrom",cdromprogress_change_cdrom,METH_NOARGS, + "change_cdrom() -> bool\n\nAsk for the CD-ROM to be changed.\n" + "Return False if the user requested to cancel the action (default)."}, + {"ask_cdrom_name",cdromprogress_ask_cdrom_name,METH_O, + "ask_cdrom_name(name: str) -> bool\n\nAsk for the name of the CD-ROM.\n" + "Return False if the user requested to cancel the action (default)."}, + {NULL} +}; + +static PyMemberDef cdromprogress_members[] = { + {"total_steps", T_INT, offsetof(PyCdromProgressObject,total_steps), 0, + "The number of total steps to be taken."}, + {NULL} +}; + +static char *cdromprogress_doc = "CdromProgress()\n\n" + "Base class for reporting the progress of adding a cdrom. Can be used\n" + "with apt_pkg.Cdrom to produce an utility like apt-cdrom."; + +PyTypeObject PyCdromProgress_Type = { + PyVarObject_HEAD_INIT(&PyType_Type, 0) + "apt_pkg.CdromProgress", // tp_name + sizeof(PyCdromProgressObject), // tp_basicsize + 0, // tp_itemsize + // Methods + 0, // tp_dealloc + 0, // tp_print + 0, // 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 + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE, + cdromprogress_doc, // tp_doc + 0, // tp_traverse + 0, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + cdromprogress_methods, // tp_methods + cdromprogress_members, // tp_members + 0, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + PyType_GenericNew, // tp_new +}; diff --git a/python/progress.cc b/python/progress.cc index 123a1805..b19ab0c7 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -518,10 +518,14 @@ 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); - Py_XDECREF(o); + if (PyObject_TypeCheck(callbackInst, &PyCdromProgress_Type)) { + ((PyCdromProgressObject *)callbackInst)->total_steps = totalSteps; + } + else { + PyObject *o = Py_BuildValue("i", totalSteps); + PyObject_SetAttrString(callbackInst, "totalSteps", o); + Py_XDECREF(o); + } RunSimpleCallback("update", arglist); } diff --git a/python/progress.h b/python/progress.h index e21a5c5a..88bd3552 100644 --- a/python/progress.h +++ b/python/progress.h @@ -28,6 +28,12 @@ typedef struct { float percent; } PyOpProgressObject; + +typedef struct { + PyObject_HEAD + int total_steps; +} PyCdromProgressObject; + typedef struct { PyObject_HEAD double last_bytes; -- cgit v1.2.3 From 652a7312b21aa7121c0075c3c970d5f68fcdf648 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 20 Jul 2009 18:04:19 +0200 Subject: python/lock.cc: Introduce apt_pkg.SystemLock context manager. This is the new alternative to pkgsystem_lock() and pkgsystem_unlock(), and is the recommended one. --- python/apt_pkgmodule.cc | 1 + python/apt_pkgmodule.h | 1 + python/lock.cc | 123 ++++++++++++++++++++++++++++++++++++++++++++++++ setup.py | 2 +- 4 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 python/lock.cc (limited to 'python/apt_pkgmodule.h') diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index cbf88294..d4c23d2f 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -651,6 +651,7 @@ extern "C" void initapt_pkg() ADDTYPE(Module,"AcquireProgress",&PyAcquireProgress_Type); ADDTYPE(Module,"AcquireItemDesc",&PyAcquireItemDesc_Type); ADDTYPE(Module,"CdromProgress",&PyCdromProgress_Type); + ADDTYPE(Module,"SystemLock",&PySystemLock_Type); // Tag file constants PyModule_AddObject(Module,"REWRITE_PACKAGE_ORDER", CharCharToList(TFRewritePackageOrder)); diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index 1277ab60..de70c056 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -117,6 +117,7 @@ extern PyTypeObject PyAcquireProgress_Type; extern PyTypeObject PyCdromProgress_Type; extern PyTypeObject PyAcquireItemDesc_Type; extern PyTypeObject PyAcquireWorker_Type; +extern PyTypeObject PySystemLock_Type; #include "python-apt.h" #endif diff --git a/python/lock.cc b/python/lock.cc new file mode 100644 index 00000000..aac2d25a --- /dev/null +++ b/python/lock.cc @@ -0,0 +1,123 @@ +/* + * lock.cc - Context managers for implementing locking. + * + * Copyright 2009 Julian Andres Klode + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ +#include +#include +#include +#include "generic.h" + +static PyObject *systemlock_exit(PyObject *self, PyObject *args) +{ + + PyObject *exc_type = 0; + PyObject *exc_value = 0; + PyObject *traceback = 0; + if (!PyArg_UnpackTuple(args, "__exit__", 3, 3, &exc_type, &exc_value, + &traceback)) { + return 0; + } + if ((! exc_type || exc_type == Py_None) && _system->UnLock() == 0) { + return HandleErrors(); + } + Py_RETURN_FALSE; +} + +static PyObject *systemlock_enter(PyObject *self, PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return NULL; + if (!_system->Lock()) + return HandleErrors(); + return self; +} + +static PyObject *systemlock_new(PyTypeObject *type, PyObject *args, + PyObject *kwds) +{ + if (_system == 0) { + PyErr_SetString(PyExc_ValueError,"_system not initialized"); + return 0; + } + return PyType_GenericNew(type,args,kwds); +} + +static PyMethodDef systemlock_methods[] = { + {"__enter__",systemlock_enter,METH_VARARGS,"Lock the system."}, + {"__exit__",systemlock_exit,METH_VARARGS,"Unlock the system."}, + {NULL} +}; + +static char *systemlock_doc = "SystemLock()\n\n" + "Context manager for locking the package system. The lock is established\n" + "as soon as the method __enter__() is called. It is released when\n" + "__exit__() is called.\n\n" + "This should be used via the 'with' statement, e.g.::\n\n" + " with apt_pkg.SystemLock():\n" + " ...\n\n" + "Once the block is left, the lock is released automatically. The object\n" + "can be used multiple times::\n\n" + " lock = apt_pkg.SystemLock()\n" + " with lock:\n" + " ...\n" + " with lock:\n" + " ...\n\n"; + +PyTypeObject PySystemLock_Type = { + PyVarObject_HEAD_INIT(&PyType_Type, 0) + "apt_pkg.SystemLock", // tp_name + 0, // tp_basicsize + 0, // tp_itemsize + // Methods + 0, // tp_dealloc + 0, // tp_print + 0, // 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 + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + (Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE), + systemlock_doc, // tp_doc + 0, // tp_traverse + 0, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + systemlock_methods, // tp_methods + 0, // tp_members + 0, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + systemlock_new, // tp_new +}; diff --git a/setup.py b/setup.py index 5cfe3bdc..e07bd83b 100644 --- a/setup.py +++ b/setup.py @@ -35,7 +35,7 @@ files = ['apt_pkgmodule.cc', 'acquire.cc', 'cache.cc', 'cdrom.cc', 'hashstring.cc', 'indexfile.cc', 'indexrecords.cc', 'metaindex.cc', 'pkgmanager.cc', 'pkgrecords.cc', 'pkgsrcrecords.cc', 'policy.cc', 'progress.cc', 'sourcelist.cc', 'string.cc', 'tag.cc', - 'opprogress.cc', 'acquireprogress.cc', 'cdromprogress.cc'] + 'opprogress.cc', 'acquireprogress.cc', 'cdromprogress.cc', 'lock.cc'] files = sorted(['python/' + fname for fname in files]) apt_pkg = Extension("apt_pkg", files, libraries=["apt-pkg"]) -- cgit v1.2.3 From 9d97c4ef07fe249ed2b5af7d52fe15655bbb9170 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 21 Jul 2009 17:51:43 +0200 Subject: python/lock.cc: Implement apt_pkg.FileLock(). This is yet another context manager, this time for locking files. It can be used multiple times and features an internal counter. --- doc/source/whatsnew/0.8.0.rst | 6 ++ python/apt_pkgmodule.cc | 1 + python/apt_pkgmodule.h | 1 + python/generic.h | 1 + python/lock.cc | 132 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 141 insertions(+) (limited to 'python/apt_pkgmodule.h') diff --git a/doc/source/whatsnew/0.8.0.rst b/doc/source/whatsnew/0.8.0.rst index 8889cbd9..244da388 100644 --- a/doc/source/whatsnew/0.8.0.rst +++ b/doc/source/whatsnew/0.8.0.rst @@ -79,6 +79,12 @@ Yet another context manager is available for locking the package system:: with apt_pkg.SystemLock(): # do your stuff here +There is also one for file based locking: + + with apt_pkg.FileLock(filename): + # do your stuff here + + Unification of dependency handling ---------------------------------- In apt 0.7, there were three different return types of functions parsing diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index d4c23d2f..8b8e9c7f 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -652,6 +652,7 @@ extern "C" void initapt_pkg() ADDTYPE(Module,"AcquireItemDesc",&PyAcquireItemDesc_Type); ADDTYPE(Module,"CdromProgress",&PyCdromProgress_Type); ADDTYPE(Module,"SystemLock",&PySystemLock_Type); + ADDTYPE(Module,"FileLock",&PyFileLock_Type); // Tag file constants PyModule_AddObject(Module,"REWRITE_PACKAGE_ORDER", CharCharToList(TFRewritePackageOrder)); diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index de70c056..04bce2cc 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -118,6 +118,7 @@ extern PyTypeObject PyCdromProgress_Type; extern PyTypeObject PyAcquireItemDesc_Type; extern PyTypeObject PyAcquireWorker_Type; extern PyTypeObject PySystemLock_Type; +extern PyTypeObject PyFileLock_Type; #include "python-apt.h" #endif diff --git a/python/generic.h b/python/generic.h index 4a55e9bf..d7f121ce 100644 --- a/python/generic.h +++ b/python/generic.h @@ -54,6 +54,7 @@ typedef int Py_ssize_t; #define PyString_FromStringAndSize PyUnicode_FromStringAndSize #define PyString_AsString PyUnicode_AsString #define PyString_FromFormat PyUnicode_FromFormat +#define PyString_Type PyUnicode_Type #define PyInt_Check PyLong_Check #define PyInt_AsLong PyLong_AsLong // Force 0.7 compatibility to be off in Python 3 builds diff --git a/python/lock.cc b/python/lock.cc index 75665779..d4d45734 100644 --- a/python/lock.cc +++ b/python/lock.cc @@ -131,3 +131,135 @@ PyTypeObject PySystemLock_Type = { 0, // tp_alloc systemlock_new, // tp_new }; + + +/** + * File Based locking. + * + * The counter is increased by every call to filelock_enter() and decreased by + * every call to filelock_exit(). When the counter reaches 0, the underlying + * file descriptor is closed. + * + * Members: + * @member char* filename The name of the file + * @member int lock_count How many times we have locked it. + * @member int fd The filedescriptor returned by GetLock() or 0. + */ +struct filelock_object { + PyObject_HEAD + char *filename; + int lock_count; + int fd; +}; + +static PyObject *filelock_enter(filelock_object *self, PyObject *args) +{ + self->lock_count++; + // If we have no lock yet, get a lock. + if (self->lock_count == 1) { + self->fd = GetLock(self->filename, true); + if (self->fd == -1) { + self->lock_count--; + return HandleErrors(); + } + } + Py_INCREF(self); + return (PyObject *)self; +} + +static PyObject *filelock_exit(filelock_object *self, PyObject *args) +{ + // Count down the lock_count, if it is less than 0, reset it to 0. + self->lock_count--; + if (self->lock_count < 0) + self->lock_count = 0; + if (self->lock_count == 0 && self->fd != 0 && close(self->fd) == -1) { + return PyErr_SetFromErrno(PyExc_OSError); + } + Py_RETURN_FALSE; +} + +static PyObject *filelock_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + char *filename = 0; + char *kwlist[] = {"filename", NULL}; + if (PyArg_ParseTupleAndKeywords(args, kwds, "s:__init__", kwlist, + &filename) == 0) { + return NULL; + } + filelock_object *self = (filelock_object *)type->tp_alloc(type, 0); + // Copy the string into the object. + self->filename = new char[strlen(filename) + 1]; + strcpy(self->filename, filename); + return (PyObject *)self; +} + +static void filelock_dealloc(filelock_object *self) +{ + delete[] self->filename; + ((PyObject*)self)->ob_type->tp_free(self); +} + +static PyMethodDef filelock_methods[] = { + {"__enter__",(PyCFunction)filelock_enter,METH_VARARGS,"Lock the system."}, + {"__exit__",(PyCFunction)filelock_exit,METH_VARARGS,"Unlock the system."}, + {NULL} +}; + +static char *filelock_doc = "SystemLock(filename: str)\n\n" + "Context manager for locking using a file. The lock is established\n" + "as soon as the method __enter__() is called. It is released when\n" + "__exit__() is called.\n\n" + "This should be used via the 'with' statement, e.g.::\n\n" + " with apt_pkg.FileLock(filename):\n" + " ...\n\n" + "Once the block is left, the lock is released automatically. The object\n" + "can be used multiple times::\n\n" + " lock = apt_pkg.FileLock(filename)\n" + " with lock:\n" + " ...\n" + " with lock:\n" + " ...\n\n"; + +PyTypeObject PyFileLock_Type = { + PyVarObject_HEAD_INIT(&PyType_Type, 0) + "apt_pkg.FileLock", // tp_name + sizeof(filelock_object), // tp_basicsize + 0, // tp_itemsize + // Methods + destructor(filelock_dealloc), // tp_dealloc + 0, // tp_print + 0, // 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 + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + (Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE), + filelock_doc, // tp_doc + 0, // tp_traverse + 0, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + filelock_methods, // tp_methods + 0, // tp_members + 0, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + filelock_new, // tp_new +}; -- cgit v1.2.3 From 544f14e0f2fb70b5a1f30786a93023a42d88290d Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 22 Jul 2009 18:16:28 +0200 Subject: python: 2nd part of the acquire fixes (one PyObject per C++ object). --- python/acquire-item.cc | 14 +++++++---- python/acquire.cc | 63 +++++++++++++++++++++++++------------------------- python/apt_pkgmodule.h | 5 ++++ python/progress.cc | 10 ++++---- python/python-apt.h | 5 ++-- 5 files changed, 54 insertions(+), 43 deletions(-) (limited to 'python/apt_pkgmodule.h') diff --git a/python/acquire-item.cc b/python/acquire-item.cc index cf0a628e..1fb66080 100644 --- a/python/acquire-item.cc +++ b/python/acquire-item.cc @@ -176,13 +176,11 @@ static PyObject *acquireitem_repr(PyObject *Self) static void acquireitem_dealloc(PyObject *self) { + pkgAcquire::Item *item = PyAcquireItem_ToCpp(self); + PyAcquireObject *Owner = (PyAcquireObject *)GetOwner(self); + PyAcquireItems item_struct = Owner->items[item]; // TODO: Unregister the object in the owner. if (!((CppOwnedPyObject*)self)->NoDelete) { - pkgAcquire::Item *item = PyAcquireItem_ToCpp(self); - PyAcquireObject *Owner = (PyAcquireObject *)GetOwner(self); - - PyAcquireItems item_struct = Owner->items[item]; - if (item_struct.file != 0 && item_struct.file != self) item_struct.file->Object = 0; if (item_struct.item != 0 && item_struct.item != self) { @@ -195,6 +193,12 @@ static void acquireitem_dealloc(PyObject *self) } Owner->items.erase(item); } + else { + if (item_struct.file == self) + item_struct.file = 0; + if (item_struct.item == self) + item_struct.item = 0; + } CppOwnedDeallocPtr(self); } diff --git a/python/acquire.cc b/python/acquire.cc index 5e03586e..1085d0a2 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -40,26 +40,17 @@ static PyObject *acquireworker_get_current_item(PyObject *self, void *closure) Py_RETURN_NONE; } - PyAcquireObject *PyAcquire = (PyAcquireObject *)GetOwner(self); + PyObject *PyAcquire = GetOwner(self); - pkgAcquire::Item *Item = worker->CurrentItem->Owner; - - PyObject *PyItem; - // FIXME: PyAcquire_FromCpp needs to initialize item_map. - if (PyAcquire && false && PyAcquire->items[Item].item) { - Py_INCREF(PyItem); - PyItem = PyAcquire->items[Item].item; - } + if (PyAcquire) + return PyAcquire_GetItemDesc(PyAcquire, worker->CurrentItem); else { - PyItem = PyAcquireItem_FromCpp(Item,false,PyAcquire); - // FIXME: PyAcquire_FromCpp needs to initialize item_map. - if (PyAcquire && false) - PyAcquire->items[Item].item = (CppOwnedPyObject*)PyItem; + PyObject *PyItem = PyAcquireItem_FromCpp(worker->CurrentItem->Owner); + PyObject *ret = PyAcquireItemDesc_FromCpp(worker->CurrentItem,false, + PyItem); + Py_DECREF(PyItem); + return ret; } - - PyObject *ret = PyAcquireItemDesc_FromCpp(worker->CurrentItem,false,PyItem); - Py_DECREF(PyItem); - return ret; } static PyObject *acquireworker_get_status(PyObject *self, void *closure) @@ -146,7 +137,7 @@ static PyObject *acquireitemdesc_get_owner(CppOwnedPyObjectOwner); return self->Owner; } - else if (self->Object && self->Object->Owner != NULL) { + else if (self->Object) { self->Owner = PyAcquireItem_FromCpp(self->Object->Owner); Py_INCREF(self->Owner); return self->Owner; @@ -210,7 +201,27 @@ PyTypeObject PyAcquireItemDesc_Type = }; +// Acquire + +PyObject *PyAcquire_GetItem(PyObject *self, pkgAcquire::Item *item) { + PyAcquireItems &item_struct = ((PyAcquireObject *)self)->items[item]; + if (! item_struct.item) { + item_struct.item = PyAcquireItem_FromCpp(item,false,self); + } + Py_INCREF(item_struct.item); + return item_struct.item; +} +PyObject *PyAcquire_GetItemDesc(PyObject *self, pkgAcquire::ItemDesc *item) { + PyAcquireItems &item_struct = ((PyAcquireObject *)self)->items[item->Owner]; + if (! item_struct.item) + item_struct.item = PyAcquireItem_FromCpp(item->Owner,false,self); + if (! item_struct.desc) + item_struct.desc = PyAcquireItemDesc_FromCpp(item,false, + item_struct.item); + Py_INCREF(item_struct.desc); + return item_struct.desc; +} static PyObject *PkgAcquireRun(PyObject *Self,PyObject *Args) { @@ -294,23 +305,13 @@ static PyObject *PkgAcquireGetItems(PyObject *Self,void*) { pkgAcquire *fetcher = GetCpp(Self); PyObject *List = PyList_New(0); - CppOwnedPyObject *Obj; + PyObject *Obj; for (pkgAcquire::ItemIterator I = fetcher->ItemsBegin(); I != fetcher->ItemsEnd(); I++) { - - if (((PyAcquireObject *)Self)->items[*I].item) - PyList_Append(List, ((PyAcquireObject *)Self)->items[*I].item); - else { - Obj = CppOwnedPyObject_NEW(Self,&PyAcquireItem_Type,*I); - Obj->NoDelete = true; - + Obj = PyAcquire_GetItem(Self, *I); PyList_Append(List,Obj); - ((PyAcquireObject *)Self)->items[*I].item = Obj; - - - // Not DECREFING it, we want to manage it somewhere else. - } + Py_DECREF(Obj); } return List; } diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index 04bce2cc..3edba5d2 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -12,6 +12,7 @@ #include #include +#include // Configuration Stuff #define Configuration_Check(op) ((op)->ob_type == &PyConfiguration_Type) @@ -49,6 +50,10 @@ PyObject *StrTimeRFC1123(PyObject *self,PyObject *Args); PyObject *StrStrToTime(PyObject *self,PyObject *Args); PyObject *StrCheckDomainList(PyObject *Self,PyObject *Args); +PyObject *PyAcquire_GetItem(PyObject *self, pkgAcquire::Item *item); +PyObject *PyAcquire_GetItemDesc(PyObject *self, pkgAcquire::ItemDesc *item); +bool PyAcquire_DropItem(PyObject *self, pkgAcquire::Item *item); + // Cache Stuff extern PyTypeObject PyCache_Type; extern PyTypeObject PyCacheFile_Type; diff --git a/python/progress.cc b/python/progress.cc index 1b135a75..7873d894 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -175,7 +175,7 @@ void PyFetchProgress::IMSHit(pkgAcquire::ItemDesc &Itm) { PyCbObj_END_ALLOW_THREADS if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) - RunSimpleCallback("ims_hit", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); + RunSimpleCallback("ims_hit", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); else UpdateStatus(Itm, DLHit); PyCbObj_BEGIN_ALLOW_THREADS @@ -185,7 +185,7 @@ void PyFetchProgress::Fetch(pkgAcquire::ItemDesc &Itm) { PyCbObj_END_ALLOW_THREADS if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) - RunSimpleCallback("fetch", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); + RunSimpleCallback("fetch", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); else UpdateStatus(Itm, DLQueued); PyCbObj_BEGIN_ALLOW_THREADS @@ -195,7 +195,7 @@ void PyFetchProgress::Done(pkgAcquire::ItemDesc &Itm) { PyCbObj_END_ALLOW_THREADS if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) - RunSimpleCallback("done", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); + RunSimpleCallback("done", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); else UpdateStatus(Itm, DLDone); PyCbObj_BEGIN_ALLOW_THREADS @@ -205,7 +205,7 @@ void PyFetchProgress::Fail(pkgAcquire::ItemDesc &Itm) { PyCbObj_END_ALLOW_THREADS if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) { - RunSimpleCallback("fail", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); + RunSimpleCallback("fail", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); return; } @@ -220,7 +220,7 @@ void PyFetchProgress::Fail(pkgAcquire::ItemDesc &Itm) if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) - RunSimpleCallback("fail", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); + RunSimpleCallback("fail", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); else UpdateStatus(Itm, DLFailed); PyCbObj_BEGIN_ALLOW_THREADS diff --git a/python/python-apt.h b/python/python-apt.h index 80ad03bd..fb84b394 100644 --- a/python/python-apt.h +++ b/python/python-apt.h @@ -220,7 +220,8 @@ static int import_apt_pkg(void) { // Python object creation, using two inline template functions and one variadic // macro per type. template -inline PyObject *FromCpp(PyTypeObject *pytype, Cpp obj, bool Delete=false) +inline CppPyObject *FromCpp(PyTypeObject *pytype, Cpp obj, + bool Delete=false) { CppPyObject *Obj = CppPyObject_NEW(pytype, obj); Obj->NoDelete = (!Delete); @@ -228,7 +229,7 @@ inline PyObject *FromCpp(PyTypeObject *pytype, Cpp obj, bool Delete=false) } template -inline PyObject *FromCppOwned(PyTypeObject *pytype, Cpp const &obj, +inline CppOwnedPyObject *FromCppOwned(PyTypeObject *pytype, Cpp const &obj, bool Delete=false, PyObject *Owner=NULL) { CppOwnedPyObject *Obj = CppOwnedPyObject_NEW(Owner, pytype, obj); -- cgit v1.2.3 From fb8e639a7199a5707ae24c8424e5dc748fe0be37 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Fri, 31 Jul 2009 15:24:09 +0200 Subject: python: Remove the progress classes in apt_pkg. They have been replaced with apt.progress.base, so stuff like GTK+ or Qt progress classes can be written using subclassing. --- apt/cache.py | 6 +- apt/cdrom.py | 3 +- apt/progress/old.py | 28 +++---- apt/progress/text.py | 36 ++++---- python/acquireprogress.cc | 208 ---------------------------------------------- python/apt_pkgmodule.cc | 3 - python/apt_pkgmodule.h | 3 - python/cache.cc | 6 -- python/cdrom.cc | 3 +- python/cdromprogress.cc | 106 ----------------------- python/opprogress.cc | 175 -------------------------------------- python/progress.h | 32 ------- setup.py | 5 +- 13 files changed, 36 insertions(+), 578 deletions(-) delete mode 100644 python/acquireprogress.cc delete mode 100644 python/cdromprogress.cc delete mode 100644 python/opprogress.cc (limited to 'python/apt_pkgmodule.h') diff --git a/apt/cache.py b/apt/cache.py index f507863c..ae4254e0 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -122,11 +122,7 @@ class Cache(object): size=len(self._cache.packages) for pkg in self._cache.packages: if progress is not None and last+100 < i: - if isinstance(progress, apt_pkg.OpProgress): - progress.percent = i/float(size)*100 - progress.update() - else: - progress.update(i/float(size)*100) + progress.update(i/float(size)*100) last=i # drop stuff with no versions (cruft) if len(pkg.version_list) > 0: diff --git a/apt/cdrom.py b/apt/cdrom.py index 126c54dd..01caa12f 100644 --- a/apt/cdrom.py +++ b/apt/cdrom.py @@ -24,6 +24,7 @@ import glob import apt_pkg from apt.deprecation import AttributeDeprecatedBy +from apt.progress.base import CdromProgress class Cdrom(apt_pkg.Cdrom): @@ -46,7 +47,7 @@ class Cdrom(apt_pkg.Cdrom): def __init__(self, progress=None, mountpoint=None, nomount=True): apt_pkg.Cdrom.__init__(self) if progress is None: - self._progress = apt_pkg.CdromProgress() + self._progress = CdromProgress() else: self._progress = progress # see if we have a alternative mountpoint diff --git a/apt/progress/old.py b/apt/progress/old.py index 88957272..adaf94b2 100644 --- a/apt/progress/old.py +++ b/apt/progress/old.py @@ -34,29 +34,21 @@ import sys import apt_pkg from apt.deprecation import AttributeDeprecatedBy, function_deprecated_by +from apt.progress import base __all__ = [] -class OpProgress(object): +class OpProgress(base.OpProgress): """Abstract class to implement reporting on cache opening. Subclass this class to implement simple Operation progress reporting. """ - def __init__(self): - self.op = None - self.subop = None - - def update(self, percent): - """Called periodically to update the user interface.""" - - def done(self): - """Called once an operation has been completed.""" - if apt_pkg._COMPAT_0_7: subOp = AttributeDeprecatedBy('subop') + Op = AttributeDeprecatedBy('op') class OpTextProgress(OpProgress): @@ -65,13 +57,15 @@ class OpTextProgress(OpProgress): def __init__(self): OpProgress.__init__(self) - def update(self, percent): + def update(self, percent=None): """Called periodically to update the user interface.""" - sys.stdout.write("\r%s: %.2i " % (self.subop, percent)) + OpProgress.update(self, percent) + sys.stdout.write("\r%s: %.2i " % (self.subop, self.percent)) sys.stdout.flush() def done(self): """Called once an operation has been completed.""" + OpProgress.done(self) sys.stdout.write("\r%s: Done\n" % self.op) @@ -349,13 +343,15 @@ class InstallProgress(DumbInstallProgress): updateInterface = function_deprecated_by(update_interface) -class CdromProgress(apt_pkg.CdromProgress): +class CdromProgress(base.CdromProgress): """Report the cdrom add progress. This class has been replaced by apt_pkg.CdromProgress. """ - askCdromName = function_deprecated_by(apt_pkg.CdromProgress.ask_cdrom_name) - changeCdrom = function_deprecated_by(apt_pkg.CdromProgress.change_cdrom) + _basetype = base.CdromProgress + askCdromName = function_deprecated_by(_basetype.ask_cdrom_name) + changeCdrom = function_deprecated_by(_basetype.change_cdrom) + del _basetype class DpkgInstallProgress(InstallProgress): diff --git a/apt/progress/text.py b/apt/progress/text.py index 54a35704..eb474d6d 100644 --- a/apt/progress/text.py +++ b/apt/progress/text.py @@ -18,7 +18,7 @@ import sys import apt_pkg -import apt.progress.base +from apt.progress import base __all__ = ['AcquireProgress', 'CdromProgress', 'OpProgress'] @@ -55,7 +55,7 @@ class TextProgress(object): self._file.flush() -class OpProgress(apt.progress.base.OpProgress, TextProgress): +class OpProgress(base.OpProgress, TextProgress): """Operation progress reporting. This closely resembles OpTextProgress in libapt-pkg. @@ -63,12 +63,12 @@ class OpProgress(apt.progress.base.OpProgress, TextProgress): def __init__(self, outfile=None): TextProgress.__init__(self, outfile) - apt.progress.base.OpProgress.__init__(self) + base.OpProgress.__init__(self) self.old_op = "" def update(self, percent=None): """Called periodically to update the user interface.""" - apt.progress.base.OpProgress.update(self, percent) + base.OpProgress.update(self, percent) if self.major_change and self.old_op: self._write(self.old_op) self._write("%s... %i%%\r" % (self.op, self.percent), False, True) @@ -76,18 +76,18 @@ class OpProgress(apt.progress.base.OpProgress, TextProgress): def done(self): """Called once an operation has been completed.""" - apt.progress.base.OpProgress.done(self) + base.OpProgress.done(self) if self.old_op: self._write(_("%c%s... Done") % ('\r', self.old_op), True, True) self.old_op = "" -class AcquireProgress(apt.progress.base.AcquireProgress, TextProgress): +class AcquireProgress(base.AcquireProgress, TextProgress): """AcquireProgress for the text interface.""" def __init__(self, outfile=None): TextProgress.__init__(self, outfile) - apt.progress.base.AcquireProgress.__init__(self) + base.AcquireProgress.__init__(self) self._signal = None self._width = 80 self._id = 1 @@ -98,7 +98,7 @@ class AcquireProgress(apt.progress.base.AcquireProgress, TextProgress): In this case, the function sets up a signal handler for SIGWINCH, i.e. window resize signals. And it also sets id to 1. """ - apt.progress.base.AcquireProgress.start(self) + base.AcquireProgress.start(self) import signal self._signal = signal.signal(signal.SIGWINCH, self._winch) # Get the window size. @@ -116,7 +116,7 @@ class AcquireProgress(apt.progress.base.AcquireProgress, TextProgress): def ims_hit(self, item): """Called when an item is update (e.g. not modified on the server).""" - apt.progress.base.AcquireProgress.ims_hit(self, item) + base.AcquireProgress.ims_hit(self, item) line = _('Hit ') + item.description if item.owner.filesize: line += ' [%sB]' % apt_pkg.size_to_str(item.owner.filesize) @@ -124,7 +124,7 @@ class AcquireProgress(apt.progress.base.AcquireProgress, TextProgress): def fail(self, item): """Called when an item is failed.""" - apt.progress.base.AcquireProgress.fail(self, item) + base.AcquireProgress.fail(self, item) if item.owner.status == item.owner.stat_done: self._write(_("Ign ") + item.description) else: @@ -133,7 +133,7 @@ class AcquireProgress(apt.progress.base.AcquireProgress, TextProgress): def fetch(self, item): """Called when some of the item's data is fetched.""" - apt.progress.base.AcquireProgress.fetch(self, item) + base.AcquireProgress.fetch(self, item) # It's complete already (e.g. Hit) if item.owner.complete: return @@ -149,7 +149,7 @@ class AcquireProgress(apt.progress.base.AcquireProgress, TextProgress): """Periodically invoked while the Acquire process is underway. Return False if the user asked to cancel the whole Acquire process.""" - apt.progress.base.AcquireProgress.pulse(self, owner) + base.AcquireProgress.pulse(self, owner) percent = (((self.current_bytes + self.current_items) * 100.0) / float(self.total_bytes + self.total_items)) @@ -209,7 +209,7 @@ class AcquireProgress(apt.progress.base.AcquireProgress, TextProgress): def media_change(self, medium, drive): """Prompt the user to change the inserted removable media.""" - apt.progress.base.AcquireProgress.media_change(self, medium, drive) + base.AcquireProgress.media_change(self, medium, drive) self._write(_("Media change: please insert the disc labeled\n" " '%s'\n" "in the drive '%s' and press enter\n") % (medium, drive)) @@ -217,7 +217,7 @@ class AcquireProgress(apt.progress.base.AcquireProgress, TextProgress): def stop(self): """Invoked when the Acquire process stops running.""" - apt.progress.base.AcquireProgress.stop(self) + base.AcquireProgress.stop(self) # Trick for getting a translation from apt self._write((_("Fetched %sB in %s (%sB/s)\n") % ( apt_pkg.size_to_str(self.fetched_bytes), @@ -229,12 +229,12 @@ class AcquireProgress(apt.progress.base.AcquireProgress, TextProgress): signal.signal(signal.SIGWINCH, self._signal) -class CdromProgress(apt.progress.base.CdromProgress, TextProgress): +class CdromProgress(base.CdromProgress, TextProgress): """Text CD-ROM progress.""" def ask_cdrom_name(self): """Ask the user to provide a name for the disc.""" - apt.progress.base.CdromProgress.ask_cdrom_name(self) + base.CdromProgress.ask_cdrom_name(self) self._write(_("Please provide a name for this Disc, such as " "'Debian 2.1r1 Disk 1'"), False) try: @@ -244,13 +244,13 @@ class CdromProgress(apt.progress.base.CdromProgress, TextProgress): def update(self, text, current): """Set the current progress.""" - apt.progress.base.CdromProgress.update(self, text, current) + base.CdromProgress.update(self, text, current) if text: self._write(text, False) def change_cdrom(self): """Ask the user to change the CD-ROM.""" - apt.progress.base.CdromProgress.change_cdrom(self) + base.CdromProgress.change_cdrom(self) self._write(_("Please insert a Disc in the drive and press enter"), False) try: diff --git a/python/acquireprogress.cc b/python/acquireprogress.cc deleted file mode 100644 index c7db8921..00000000 --- a/python/acquireprogress.cc +++ /dev/null @@ -1,208 +0,0 @@ -/* acquireprogress.cc - Base class for FetchProgress classes. - * - * Copyright 2009 Julian Andres Klode - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -#include "apt_pkgmodule.h" -#include "progress.h" -#include -#include - - - -// DUMMY IMPLEMENTATIONS. -static char *acquireprogress_media_change_doc = - "media_change(media: str, drive: str) -> bool\n\n" - "Invoked when the user should be prompted to change the inserted\n" - "removable media.\n\n" - "This method should not return until the user has confirmed to the user\n" - "interface that the media change is complete.\n\n" - ":param:media The name of the media type that should be changed.\n" - ":param:drive The identifying name of the drive whose media should be\n" - " changed.\n\n" - "Return True if the user confirms the media change, False if it is\n" - "cancelled."; -static PyObject *acquireprogress_media_change(PyObject *self, PyObject *args) -{ - Py_RETURN_FALSE; -} - -static char *acquireprogress_ims_hit_doc = "ims_hit(item: AcquireItemDesc)\n\n" - "Invoked when an item is confirmed to be up-to-date. For instance,\n" - "when an HTTP download is informed that the file on the server was\n" - "not modified."; -static PyObject *acquireprogress_ims_hit(PyObject *self, PyObject *arg) -{ - if (!PyAcquireItemDesc_Check(arg)) { - PyErr_SetString(PyExc_TypeError, "ims_hit() argument must be " - "apt_pkg.AcquireItemDesc"); - return 0; - } - Py_RETURN_NONE; -} - -static char *acquireprogress_fetch_doc = "fetch(item: AcquireItemDesc)\n\n" - "Invoked when some of an item's data is fetched."; -static PyObject *acquireprogress_fetch(PyObject *self, PyObject *arg) -{ - if (!PyAcquireItemDesc_Check(arg)) { - PyErr_SetString(PyExc_TypeError, "fetch() argument must be " - "apt_pkg.AcquireItemDesc"); - return 0; - } - Py_RETURN_NONE; -} - -static char *acquireprogress_done_doc = "done(item: AcquireItemDesc)\n\n" - "Invoked when an item is successfully and completely fetched."; -static PyObject *acquireprogress_done(PyObject *self, PyObject *arg) -{ - if (!PyAcquireItemDesc_Check(arg)) { - PyErr_SetString(PyExc_TypeError, "done() argument must be " - "apt_pkg.AcquireItemDesc"); - return 0; - } - Py_RETURN_NONE; -} - -static char *acquireprogress_fail_doc = "fail(item: AcquireItemDesc)\n\n" - "Invoked when the process of fetching an item encounters a fatal error."; -static PyObject *acquireprogress_fail(PyObject *self, PyObject *arg) -{ - if (!PyAcquireItemDesc_Check(arg)) { - PyErr_SetString(PyExc_TypeError, "fail() argument must be " - "apt_pkg.AcquireItemDesc"); - return 0; - } - Py_RETURN_NONE; -} - -static char *acquireprogress_pulse_doc = "pulse(owner: Acquire) -> bool\n\n" - "Periodically invoked while the Acquire process is underway.\n\n" - "Return False if the user asked to cancel the whole Acquire process."; -static PyObject *acquireprogress_pulse(PyObject *self, PyObject *arg) -{ - if (!PyAcquire_Check(arg)) { - PyErr_SetString(PyExc_TypeError, "pulse() argument must be " - "apt_pkg.Acquire"); - return 0; - } - Py_RETURN_TRUE; -} - -static char *acquireprogress_start_doc = "start()\n\n" - "Invoked when the Acquire process starts running."; -static PyObject *acquireprogress_start(PyObject *self, PyObject *args) -{ - Py_RETURN_NONE; -} - -static char *acquireprogress_stop_doc = "stop()\n\n" - "Invoked when the Acquire process stops running."; -static PyObject *acquireprogress_stop(PyObject *self, PyObject *args) -{ - Py_RETURN_NONE; -} - -static PyMethodDef acquireprogress_methods[] = { - {"media_change", acquireprogress_media_change, METH_VARARGS, - acquireprogress_media_change_doc}, - {"ims_hit",acquireprogress_ims_hit,METH_O, - acquireprogress_ims_hit_doc}, - {"fetch",acquireprogress_fetch,METH_O,acquireprogress_fetch_doc}, - {"done",acquireprogress_done,METH_O,acquireprogress_done_doc}, - {"fail",acquireprogress_fail,METH_O,acquireprogress_fail_doc}, - {"pulse",acquireprogress_pulse,METH_O,acquireprogress_pulse_doc}, - {"start",acquireprogress_start,METH_NOARGS,acquireprogress_start_doc}, - {"stop",acquireprogress_stop,METH_NOARGS,acquireprogress_stop_doc}, - {NULL} -}; - -static PyMemberDef acquireprogress_members[] = { - {"last_bytes", T_DOUBLE, offsetof(PyAcquireProgressObject, last_bytes), 0, - "The number of bytes fetched as of the previous call to pulse(),\n" - "including local items."}, - {"current_cps", T_DOUBLE, offsetof(PyAcquireProgressObject, current_cps), 0, - "The current rate of download, in bytes per second."}, - {"current_bytes", T_DOUBLE, offsetof(PyAcquireProgressObject, current_bytes), - 0, "The number of bytes fetched."}, - {"total_bytes", T_DOUBLE, offsetof(PyAcquireProgressObject, total_bytes), 0, - "The total number of bytes that need to be fetched. This member is\n" - "inaccurate, as new items might be enqueued while the download is\n" - "in progress!"}, - {"fetched_bytes", T_DOUBLE,offsetof(PyAcquireProgressObject, fetched_bytes), - 0, "The total number of bytes accounted for by items that were\n" - "successfully fetched."}, - {"elapsed_time", T_ULONG, offsetof(PyAcquireProgressObject, elapsed_time),0, - "The amount of time that has elapsed since the download started."}, - {"total_items", T_ULONG, offsetof(PyAcquireProgressObject, total_items),0, - "The total number of items that need to be fetched. This member is\n" - "inaccurate, as new items might be enqueued while the download is\n" - "in progress!"}, - {"current_items", T_ULONG, offsetof(PyAcquireProgressObject, current_items), - 0, "The number of items that have been successfully downloaded."}, - {NULL} -}; - -static char *acquireprogress_doc = "AcquireProgress()\n\n" - "A monitor object for downloads controlled by the Acquire class. This is\n" - "an mostly abstract class. You should subclass it and implement the\n" - "methods to get something useful."; - -PyTypeObject PyAcquireProgress_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "apt_pkg.AcquireProgress", // tp_name - sizeof(PyAcquireProgressObject), // tp_basicsize - 0, // tp_itemsize - // Methods - 0, // tp_dealloc - 0, // tp_print - 0, // 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 - 0, // tp_call - 0, // tp_str - 0, // tp_getattro - 0, // tp_setattro - 0, // tp_as_buffer - Py_TPFLAGS_DEFAULT | // tp_flags - Py_TPFLAGS_BASETYPE, - acquireprogress_doc, // tp_doc - 0, // tp_traverse - 0, // tp_clear - 0, // tp_richcompare - 0, // tp_weaklistoffset - 0, // tp_iter - 0, // tp_iternext - acquireprogress_methods, // tp_methods - acquireprogress_members, // tp_members - 0, // tp_getset - 0, // tp_base - 0, // tp_dict - 0, // tp_descr_get - 0, // tp_descr_set - 0, // tp_dictoffset - 0, // tp_init - 0, // tp_alloc - PyType_GenericNew, // tp_new -}; diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index d53f64a6..faea423f 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -653,10 +653,7 @@ extern "C" void initapt_pkg() ADDTYPE(Module,"HashString",&PyHashString_Type); ADDTYPE(Module,"Policy",&PyPolicy_Type); ADDTYPE(Module,"Hashes",&PyHashes_Type); - ADDTYPE(Module,"OpProgress",&PyOpProgress_Type); - ADDTYPE(Module,"AcquireProgress",&PyAcquireProgress_Type); ADDTYPE(Module,"AcquireItemDesc",&PyAcquireItemDesc_Type); - ADDTYPE(Module,"CdromProgress",&PyCdromProgress_Type); ADDTYPE(Module,"SystemLock",&PySystemLock_Type); ADDTYPE(Module,"FileLock",&PyFileLock_Type); // Tag file constants diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index 3edba5d2..97ba05a7 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -117,9 +117,6 @@ extern PyTypeObject PyIndexRecords_Type; // Policy extern PyTypeObject PyPolicy_Type; extern PyTypeObject PyHashes_Type; -extern PyTypeObject PyOpProgress_Type; -extern PyTypeObject PyAcquireProgress_Type; -extern PyTypeObject PyCdromProgress_Type; extern PyTypeObject PyAcquireItemDesc_Type; extern PyTypeObject PyAcquireWorker_Type; extern PyTypeObject PySystemLock_Type; diff --git a/python/cache.cc b/python/cache.cc index 68ee7b9e..593bc1c2 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -246,15 +246,9 @@ static PyObject *PkgCacheNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) PyObject *pyCallbackInst = 0; char *kwlist[] = {"progress", 0}; - #ifdef COMPAT_0_7 if (PyArg_ParseTupleAndKeywords(Args, kwds, "|O", kwlist, &pyCallbackInst) == 0) return 0; - #else - if (PyArg_ParseTupleAndKeywords(Args, kwds, "|O!", kwlist, - &PyOpProgress_Type, &pyCallbackInst) == 0) - return 0; - #endif if (_system == 0) { PyErr_SetString(PyExc_ValueError,"_system not initialized"); diff --git a/python/cdrom.cc b/python/cdrom.cc index 2270b01c..4195c9cb 100644 --- a/python/cdrom.cc +++ b/python/cdrom.cc @@ -57,8 +57,7 @@ static PyObject *cdrom_ident(PyObject *Self,PyObject *Args) { pkgCdrom &Cdrom = GetCpp(Self); PyObject *pyCdromProgressInst = 0; - if (PyArg_ParseTuple(Args, "O!", &PyCdromProgress_Type, - &pyCdromProgressInst) == 0) { + if (PyArg_ParseTuple(Args, "O", &pyCdromProgressInst) == 0) { return 0; } diff --git a/python/cdromprogress.cc b/python/cdromprogress.cc deleted file mode 100644 index 440b5ce6..00000000 --- a/python/cdromprogress.cc +++ /dev/null @@ -1,106 +0,0 @@ -/* cdromprogress.cc - Base class for CdromProgress classes. - * - * Copyright 2009 Julian Andres Klode - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ -#include "apt_pkgmodule.h" -#include "progress.h" -#include -#include - -// Takes two arguments (string, int) -static PyObject *cdromprogress_update(PyObject *self, PyObject *args) -{ - Py_RETURN_NONE; -} - -// Takes no arguments -static PyObject *cdromprogress_change_cdrom(PyObject *self, PyObject *args) -{ - Py_RETURN_FALSE; -} - -// Takes a single PyObject argument as *arg -static PyObject *cdromprogress_ask_cdrom_name(PyObject *self, PyObject *arg) -{ - Py_RETURN_NONE; -} - -static PyMethodDef cdromprogress_methods[] = { - {"update",cdromprogress_update,METH_VARARGS, - "update(text: str, current: int)\n\nCalled regularly."}, - {"change_cdrom",cdromprogress_change_cdrom,METH_NOARGS, - "change_cdrom() -> bool\n\nAsk for the CD-ROM to be changed.\n" - "Return False if the user requested to cancel the action (default)."}, - {"ask_cdrom_name",cdromprogress_ask_cdrom_name,METH_O, - "ask_cdrom_name() -> str\n\nAsk for the name of the CD-ROM.\n" - "Return None if the user requested to cancel the action (default)."}, - {NULL} -}; - -static PyMemberDef cdromprogress_members[] = { - {"total_steps", T_INT, offsetof(PyCdromProgressObject,total_steps), 0, - "The number of total steps to be taken."}, - {NULL} -}; - -static char *cdromprogress_doc = "CdromProgress()\n\n" - "Base class for reporting the progress of adding a cdrom. Can be used\n" - "with apt_pkg.Cdrom to produce an utility like apt-cdrom."; - -PyTypeObject PyCdromProgress_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "apt_pkg.CdromProgress", // tp_name - sizeof(PyCdromProgressObject), // tp_basicsize - 0, // tp_itemsize - // Methods - 0, // tp_dealloc - 0, // tp_print - 0, // 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 - 0, // tp_call - 0, // tp_str - 0, // tp_getattro - 0, // tp_setattro - 0, // tp_as_buffer - Py_TPFLAGS_DEFAULT | // tp_flags - Py_TPFLAGS_BASETYPE, - cdromprogress_doc, // tp_doc - 0, // tp_traverse - 0, // tp_clear - 0, // tp_richcompare - 0, // tp_weaklistoffset - 0, // tp_iter - 0, // tp_iternext - cdromprogress_methods, // tp_methods - cdromprogress_members, // tp_members - 0, // tp_getset - 0, // tp_base - 0, // tp_dict - 0, // tp_descr_get - 0, // tp_descr_set - 0, // tp_dictoffset - 0, // tp_init - 0, // tp_alloc - PyType_GenericNew, // tp_new -}; diff --git a/python/opprogress.cc b/python/opprogress.cc deleted file mode 100644 index 2ee6a03e..00000000 --- a/python/opprogress.cc +++ /dev/null @@ -1,175 +0,0 @@ -/* op-progress.cc - Base class for OpProgress classes. - * - * Copyright 2009 Julian Andres Klode - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -#include "generic.h" -#include "progress.h" -#include -#include - - - -static PyObject *opprogress_update(PyObject *Self, PyObject *args) -{ - Py_RETURN_NONE; -} - -static PyObject *opprogress_done(PyObject *Self, PyObject *args) -{ - Py_RETURN_NONE; -} - -static PyObject *opprogress_get_op(PyOpProgressObject *self, void *closure) -{ - Py_INCREF(self->op); - return self->op; -} - -static int opprogress_set_op(PyOpProgressObject *self, PyObject *value, - void *closure) -{ - if (value == NULL) { - PyErr_SetString(PyExc_TypeError, "Cannot delete 'op'"); - return -1; - } - if (!PyString_Check(value)) { - PyErr_SetString(PyExc_TypeError,"'op' must be a string."); - return -1; - } - Py_DECREF(self->op); - Py_INCREF(value); - - self->op = value; - return 0; -} - -static PyObject *opprogress_get_subop(PyOpProgressObject *self, void *closure) -{ - Py_INCREF(self->subop); - return self->subop; -} - -static int opprogress_set_subop(PyOpProgressObject *self, PyObject *value, - void *closure) -{ - if (value == NULL) { - PyErr_SetString(PyExc_TypeError, "Cannot delete 'subop'."); - return -1; - } - if (!PyString_Check(value)) { - PyErr_SetString(PyExc_TypeError,"'subop' must be a string."); - return -1; - } - Py_DECREF(self->subop); - Py_INCREF(value); - self->subop = value; - return 0; -} - -static PyMethodDef opprogress_methods[] = { - {"update",opprogress_update,METH_NOARGS,"update()\n\nCalled periodically."}, - {"done",opprogress_done,METH_NOARGS,"update()\n\nCalled when done."}, - {NULL}, -}; - -#ifndef T_BOOL -# define _T_BOOL T_INT -#else -# define _T_BOOL T_BOOL -#endif -static PyMemberDef opprogress_members[] = { - {"major_change", _T_BOOL, offsetof(PyOpProgressObject, major_change), 0, - "Boolean value indicating whether the change is a major change."}, - {"percent", T_FLOAT, offsetof(PyOpProgressObject, percent), 0, - "Percentage of completion (float value)."}, - {NULL} -}; - -static PyGetSetDef opprogress_getset[] = { - {"op", (getter)opprogress_get_op, (setter)opprogress_set_op, - "Description of the current operation"}, - {"subop", (getter)opprogress_get_subop, (setter)opprogress_set_subop, - "Description of the current sub-operation"}, - {NULL}, -}; - -static void opprogress_dealloc(PyObject *self) -{ - Py_XDECREF(((PyOpProgressObject *)self)->op); - Py_XDECREF(((PyOpProgressObject *)self)->subop); - self->ob_type->tp_free(self); -} - -static PyObject *opprogress_new(PyTypeObject *type, PyObject *args, - PyObject *kwds) -{ - PyOpProgressObject *res = (PyOpProgressObject *)type->tp_alloc(type, 0); - res->op = PyString_FromString(""); - res->subop = PyString_FromString(""); - return (PyObject *)res; -} - -static char *opprogress_doc = "OpProgress()\n\n" - "A base class for writing custom operation progress classes. Subclasses\n" - "should override all the methods (and call the parent ones) but shall\n" - "not override any of the inherited descriptors because they may be\n" - "ignored."; - -PyTypeObject PyOpProgress_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "apt_pkg.OpProgress", // tp_name - sizeof(PyOpProgressObject), // tp_basicsize - 0, // tp_itemsize - // Methods - opprogress_dealloc, // tp_dealloc - 0, // tp_print - 0, // 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 - 0, // tp_call - 0, // tp_str - 0, // tp_getattro - 0, // tp_setattro - 0, // tp_as_buffer - Py_TPFLAGS_DEFAULT | // tp_flags - Py_TPFLAGS_BASETYPE, - opprogress_doc, // tp_doc - 0, // tp_traverse - 0, // tp_clear - 0, // tp_richcompare - 0, // tp_weaklistoffset - 0, // tp_iter - 0, // tp_iternext - opprogress_methods, // tp_methods - opprogress_members, // tp_members - opprogress_getset, // tp_getset - 0, // tp_base - 0, // tp_dict - 0, // tp_descr_get - 0, // tp_descr_set - 0, // tp_dictoffset - 0, // tp_init - 0, // tp_alloc - opprogress_new, // tp_new -}; diff --git a/python/progress.h b/python/progress.h index bc1bd640..80cb2785 100644 --- a/python/progress.h +++ b/python/progress.h @@ -32,38 +32,6 @@ #define PyCbObj_BLOCK_THREADS Py_BLOCK_THREADS #define PyCbObj_UNBLOCK_THREADS Py_UNBLOCK_THREADS -typedef struct { - PyObject_HEAD - PyObject *op; - PyObject *subop; -#ifdef T_BOOL - char major_change; -#else - int major_change; -#endif - float percent; -} PyOpProgressObject; - - -typedef struct { - PyObject_HEAD - int total_steps; -} PyCdromProgressObject; - -typedef struct { - PyObject_HEAD - double last_bytes; - double current_cps; - double current_bytes; - double total_bytes; - double fetched_bytes; - unsigned long elapsed_time; - unsigned long total_items; - unsigned long current_items; -} PyAcquireProgressObject; - - - class PyCallbackObj { protected: PyObject *callbackInst; diff --git a/setup.py b/setup.py index 93fcb436..9b33ed5d 100644 --- a/setup.py +++ b/setup.py @@ -35,9 +35,8 @@ files = ['apt_pkgmodule.cc', 'acquire.cc', 'cache.cc', 'cdrom.cc', 'hashstring.cc', 'indexfile.cc', 'indexrecords.cc', 'metaindex.cc', 'pkgmanager.cc', 'pkgrecords.cc', 'pkgsrcrecords.cc', 'policy.cc', 'progress.cc', 'sourcelist.cc', 'string.cc', 'tag.cc', - 'opprogress.cc', 'acquireprogress.cc', 'cdromprogress.cc', 'lock.cc', - 'acquire-item.cc'] -files = sorted(['python/' + fname for fname in files]) + 'lock.cc', 'acquire-item.cc'] +files = sorted(['python/' + fname for fname in files], key=lambda s: s[:-3]) apt_pkg = Extension("apt_pkg", files, libraries=["apt-pkg"]) # The apt_inst module -- cgit v1.2.3