summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2009-07-16 19:36:58 +0200
committerJulian Andres Klode <jak@debian.org>2009-07-16 19:36:58 +0200
commit0153cede3726849504b04dabdebc8460c1c0fc91 (patch)
tree97519b677c42cab89faa794621713664a17473f9
parent7e5b2dee624fb0fb7a6536cfdc74d30eeca8ffbe (diff)
downloadpython-apt-0153cede3726849504b04dabdebc8460c1c0fc91.tar.gz
python/progress.h: Add Py{Acquire,Op}ProgressObject.
-rw-r--r--python/acquireprogress.cc12
-rw-r--r--python/opprogress.cc9
-rw-r--r--python/progress.cc85
-rw-r--r--python/progress.h20
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 <Python.h>
#include <structmember.h>
-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 <Python.h>
#include <structmember.h>
-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 <apt-pkg/cdrom.h>
#include <Python.h>
+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: