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') 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