diff options
| author | Julian Andres Klode <jak@debian.org> | 2009-07-16 16:03:02 +0200 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2009-07-16 16:03:02 +0200 |
| commit | ef106396218522fce5856744741c7b3f87261cc2 (patch) | |
| tree | be4b380fab270e31927056f1506b4e52e105e77d | |
| parent | 16995d9f7f53d93f08ae0b438c70ea9d5e4d35e1 (diff) | |
| download | python-apt-ef106396218522fce5856744741c7b3f87261cc2.tar.gz | |
python/acquire.cc: Introduce PyAcquireWorker_Type, make PyAcquireItemDesc_Type contain a pointer.
| -rw-r--r-- | python/acquire.cc | 108 | ||||
| -rw-r--r-- | python/apt_pkgmodule.cc | 13 | ||||
| -rw-r--r-- | python/apt_pkgmodule.h | 1 | ||||
| -rw-r--r-- | python/progress.cc | 8 | ||||
| -rw-r--r-- | python/python-apt.h | 4 |
5 files changed, 112 insertions, 22 deletions
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 <apt-pkg/acquire-item.h> +#include <apt-pkg/acquire-worker.h> typedef CppPyObject<pkgAcquire::Item*> PyAcquireItemObject; @@ -20,21 +21,93 @@ struct PyAcquireObject : public CppPyObject<pkgAcquire*> { vector<PyAcquireItemObject *> items; }; + +static PyObject *acquireworker_get_current_item(PyObject *self, void *closure) +{ + return PyAcquireItemDesc_FromCpp((GetCpp<pkgAcquire::Worker*>(self)->CurrentItem),false,self); +} + +static PyObject *acquireworker_get_status(PyObject *self, void *closure) +{ + return CppPyString(GetCpp<pkgAcquire::Worker*>(self)->Status); +} + +static PyObject *acquireworker_get_current_size(PyObject *self, void *closure) +{ + return Py_BuildValue("k",GetCpp<pkgAcquire::Worker*>(self)->CurrentSize); +} + +static PyObject *acquireworker_get_total_size(PyObject *self, void *closure) +{ + return Py_BuildValue("k",GetCpp<pkgAcquire::Worker*>(self)->TotalSize); +} + +static PyObject *acquireworker_get_resumepoint(PyObject *self, void *closure) +{ + return Py_BuildValue("k",GetCpp<pkgAcquire::Worker*>(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<pkgAcquire::Worker*>),// tp_basicsize + 0, // tp_itemsize + // Methods + CppOwnedDealloc<pkgAcquire::Worker*>, // 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<pkgAcquire::Worker*>, // tp_traverse + CppOwnedClear<pkgAcquire::Worker*>, // 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<pkgAcquire::ItemDesc>(self).URI); + return CppPyString(GetCpp<pkgAcquire::ItemDesc*>(self)->URI); } static PyObject *acquireitemdesc_get_description(PyObject *self, void *closure) { - return CppPyString(GetCpp<pkgAcquire::ItemDesc>(self).Description); + return CppPyString(GetCpp<pkgAcquire::ItemDesc*>(self)->Description); } static PyObject *acquireitemdesc_get_shortdesc(PyObject *self, void *closure) { - return CppPyString(GetCpp<pkgAcquire::ItemDesc>(self).ShortDesc); + return CppPyString(GetCpp<pkgAcquire::ItemDesc*>(self)->ShortDesc); } static PyObject *acquireitemdesc_get_owner(PyObject *self, void *closure) { - return GetOwner<pkgAcquire::ItemDesc>(self); + return GetOwner<pkgAcquire::ItemDesc*>(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<pkgAcquire::ItemDesc>),// tp_basicsize + sizeof(CppOwnedPyObject<pkgAcquire::ItemDesc*>),// tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc<pkgAcquire::ItemDesc>, // tp_dealloc + CppOwnedDealloc<pkgAcquire::ItemDesc*>, // 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<pkgAcquire::ItemDesc>,// tp_traverse - CppOwnedClear<pkgAcquire::ItemDesc>, // tp_clear + CppOwnedTraverse<pkgAcquire::ItemDesc*>,// tp_traverse + CppOwnedClear<pkgAcquire::ItemDesc*>, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -184,13 +257,13 @@ static void AcquireItemDealloc(PyObject *self) { pkgAcquire::Item *file = GetCpp<pkgAcquire::Item*>(self); PyAcquireObject *owner = (PyAcquireObject *)GetOwner<pkgAcquire::Item*>(self); - // Simply deallocate the object if we have no owner. + // Simply deallocate the object if we have no owner. if (owner == NULL) { CppOwnedDeallocPtr<pkgAcquire::Item*>(self); return; } vector<PyAcquireItemObject *> &items = owner->items; - bool DeletePtr = !((CppPyObject<pkgAcquire::Item*> *)self)->NoDelete; + bool DeletePtr = !((CppPyObject<pkgAcquire::Item*> *)self)->NoDelete; // Cleanup the other objects as well... for (vector<PyAcquireItemObject *>::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<pkgAcquire*>(self); + CppOwnedPyObject<pkgAcquire::Worker*> *PyWorker = NULL; + for(pkgAcquire::Worker *Worker = Owner->WorkersBegin(); + Worker != 0; Worker = Owner->WorkerStep(Worker)) { + PyWorker = CppOwnedPyObject_NEW<pkgAcquire::Worker*>(self,&PyAcquireWorker_Type, Worker); + PyWorker->NoDelete = true; + PyList_Append(List, PyWorker); + } + return List; +} static PyObject *PkgAcquireGetItems(PyObject *Self,void*) { pkgAcquire *fetcher = GetCpp<pkgAcquire*>(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<pkgAcquire*> # define PyAcquireFile_ToCpp GetCpp<pkgAcqFile*> # define PyAcquireItem_ToCpp GetCpp<pkgAcquire::Item*> -# define PyAcquireItemDesc_ToCpp GetCpp<pkgAcquire::ItemDesc> +# define PyAcquireItemDesc_ToCpp GetCpp<pkgAcquire::ItemDesc*> # define PyActionGroup_ToCpp GetCpp<pkgDepCache::ActionGroup*> # define PyCache_ToCpp GetCpp<pkgCache*> # define PyCacheFile_ToCpp GetCpp<pkgCacheFile*> @@ -234,7 +234,7 @@ inline PyObject *FromCppOwned(PyTypeObject *pytype, Cpp const &obj, # define PyAcquire_FromCpp(...) FromCpp<pkgAcquire*>(&PyAcquire_Type, ##__VA_ARGS__) # define PyAcquireFile_FromCpp(...) FromCppOwned<pkgAcqFile*>(&PyAcquireFile_Type, ##__VA_ARGS__) # define PyAcquireItem_FromCpp(...) FromCppOwned<pkgAcquire::Item*>(&PyAcquireItem_Type,##__VA_ARGS__) -# define PyAcquireItemDesc_FromCpp(...) FromCppOwned<pkgAcquire::ItemDesc>(&PyAcquireItemDesc_Type,##__VA_ARGS__) +# define PyAcquireItemDesc_FromCpp(...) FromCppOwned<pkgAcquire::ItemDesc*>(&PyAcquireItemDesc_Type,##__VA_ARGS__) # define PyActionGroup_FromCpp(...) FromCppOwned<pkgDepCache::ActionGroup*>(&PyActionGroup_Type,##__VA_ARGS__) # define PyCache_FromCpp(...) FromCppOwned<pkgCache*>(&PyCache_Type,##__VA_ARGS__) # define PyCacheFile_FromCpp(...) FromCpp<pkgCacheFile*>(&PyCacheFile_Type,##__VA_ARGS__) |
