From 0153cede3726849504b04dabdebc8460c1c0fc91 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 16 Jul 2009 19:36:58 +0200 Subject: python/progress.h: Add Py{Acquire,Op}ProgressObject. --- python/acquireprogress.cc | 12 +------ python/opprogress.cc | 9 ++--- python/progress.cc | 85 ++++++++++++++++++++++++++--------------------- python/progress.h | 20 +++++++++++ 4 files changed, 71 insertions(+), 55 deletions(-) diff --git a/python/acquireprogress.cc b/python/acquireprogress.cc index eb02d018..c7db8921 100644 --- a/python/acquireprogress.cc +++ b/python/acquireprogress.cc @@ -19,20 +19,10 @@ */ #include "apt_pkgmodule.h" +#include "progress.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. diff --git a/python/opprogress.cc b/python/opprogress.cc index ba9acd14..d3738904 100644 --- a/python/opprogress.cc +++ b/python/opprogress.cc @@ -19,16 +19,11 @@ */ #include "generic.h" +#include "progress.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) { diff --git a/python/progress.cc b/python/progress.cc index 1f17afdf..6f226ef8 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -245,43 +245,54 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) if(callbackInst == 0) return false; - // set stats - PyObject *o; - - - o = Py_BuildValue("d", FetchedBytes); - PyObject_SetAttrString(callbackInst, "fetched_bytes", o); - Py_DECREF(o); - o = Py_BuildValue("d", CurrentCPS); - if(PyObject_HasAttrString(callbackInst, "current_cps")) - PyObject_SetAttrString(callbackInst, "current_cps", o); - else - PyObject_SetAttrString(callbackInst, "currentCPS", o); - Py_XDECREF(o); - o = Py_BuildValue("d", CurrentBytes); - if(PyObject_HasAttrString(callbackInst, "current_bytes")) - PyObject_SetAttrString(callbackInst, "current_bytes", o); - else - PyObject_SetAttrString(callbackInst, "currentBytes", o); - Py_XDECREF(o); - o = Py_BuildValue("k", CurrentItems); - if(PyObject_HasAttrString(callbackInst, "current_items")) - PyObject_SetAttrString(callbackInst, "current_items", o); - else - PyObject_SetAttrString(callbackInst, "currentItems", o); - Py_XDECREF(o); - o = Py_BuildValue("k", TotalItems); - if(PyObject_HasAttrString(callbackInst, "total_items")) - PyObject_SetAttrString(callbackInst, "total_items", o); - else - PyObject_SetAttrString(callbackInst, "totalItems", o); - Py_XDECREF(o); - o = Py_BuildValue("d", TotalBytes); - if(PyObject_HasAttrString(callbackInst, "total_bytes")) - PyObject_SetAttrString(callbackInst, "total_bytes", o); - else - PyObject_SetAttrString(callbackInst, "totalBytes", o); - Py_XDECREF(o); + if (PyObject_TypeCheck(callbackInst, &PyAcquireProgress_Type)) { + PyAcquireProgressObject *obj = (PyAcquireProgressObject *)callbackInst; + obj->last_bytes = LastBytes; + obj->current_cps = CurrentCPS; + obj->current_bytes = CurrentBytes; + obj->total_bytes = TotalBytes; + obj->fetched_bytes = FetchedBytes; + obj->elapsed_time = ElapsedTime; + obj->total_items = TotalItems; + obj->current_items = CurrentItems; + } + else { + // set stats + PyObject *o; + o = Py_BuildValue("d", FetchedBytes); + PyObject_SetAttrString(callbackInst, "fetched_bytes", o); + Py_DECREF(o); + o = Py_BuildValue("d", CurrentCPS); + if(PyObject_HasAttrString(callbackInst, "current_cps")) + PyObject_SetAttrString(callbackInst, "current_cps", o); + else + PyObject_SetAttrString(callbackInst, "currentCPS", o); + Py_XDECREF(o); + o = Py_BuildValue("d", CurrentBytes); + if(PyObject_HasAttrString(callbackInst, "current_bytes")) + PyObject_SetAttrString(callbackInst, "current_bytes", o); + else + PyObject_SetAttrString(callbackInst, "currentBytes", o); + Py_XDECREF(o); + o = Py_BuildValue("k", CurrentItems); + if(PyObject_HasAttrString(callbackInst, "current_items")) + PyObject_SetAttrString(callbackInst, "current_items", o); + else + PyObject_SetAttrString(callbackInst, "currentItems", o); + Py_XDECREF(o); + o = Py_BuildValue("k", TotalItems); + if(PyObject_HasAttrString(callbackInst, "total_items")) + PyObject_SetAttrString(callbackInst, "total_items", o); + else + PyObject_SetAttrString(callbackInst, "totalItems", o); + Py_XDECREF(o); + o = Py_BuildValue("d", TotalBytes); + if(PyObject_HasAttrString(callbackInst, "total_bytes")) + PyObject_SetAttrString(callbackInst, "total_bytes", o); + else + PyObject_SetAttrString(callbackInst, "totalBytes", o); + Py_XDECREF(o); + } if (PyObject_TypeCheck(callbackInst, &PyAcquireProgress_Type)) { PyObject *result1; diff --git a/python/progress.h b/python/progress.h index 5ac67b1c..50fd7f20 100644 --- a/python/progress.h +++ b/python/progress.h @@ -15,6 +15,26 @@ #include #include +typedef struct { + PyObject_HEAD + PyObject *op; + PyObject *subop; + int major_change; + float percent; +} PyOpProgressObject; + +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: -- cgit v1.2.3