1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
// Description /*{{{*/
// $Id: progress.cc,v 1.5 2003/06/03 03:03:23 mdz Exp $
/* ######################################################################
Progress - Wrapper for the progress related functions
##################################################################### */
#include <iostream>
#include "progress.h"
// OpProgress interface
// FIXME: add "string Op, string SubOp" as attribute to the callbackInst
void PyOpProgress::Update()
{
if(callbackInst == 0)
return;
// Build up the argument list...
PyObject *arglist = Py_BuildValue("(f)", Percent);
// ...for calling the Python compare function.
PyObject *method = PyObject_GetAttrString(callbackInst, "Update");
if(method == NULL) {
// FIXME: make this silent
Py_DECREF(arglist);
return;
}
PyObject *result = PyEval_CallObject(method,arglist);
Py_XDECREF(result);
Py_XDECREF(method);
Py_DECREF(arglist);
return;
};
void PyOpProgress::Done()
{
if(callbackInst == 0)
return;
// Build up the argument list...
PyObject *arglist = Py_BuildValue("()", NULL);
// ...for calling the Python compare function.
PyObject *method = PyObject_GetAttrString(callbackInst, "Done");
if(method == NULL) {
Py_DECREF(arglist);
return;
}
PyObject *result = PyEval_CallObject(method,arglist);
Py_XDECREF(result);
Py_XDECREF(method);
Py_DECREF(arglist);
}
// fetcher interface
// PyFetchProgress::
// apt interface
bool PyFetchProgress::MediaChange(string Media, string Drive)
{
std::cout << "MediaChange" << std::endl;
}
void PyFetchProgress::IMSHit(pkgAcquire::ItemDesc &Itm)
{
std::cout << "IMSHit" << std::endl;
}
void PyFetchProgress::Fetch(pkgAcquire::ItemDesc &Itm)
{
std::cout << "Fetch" << std::endl;
}
void PyFetchProgress::Done(pkgAcquire::ItemDesc &Itm)
{
std::cout << "Done" << std::endl;
}
void PyFetchProgress::Fail(pkgAcquire::ItemDesc &Itm)
{
std::cout << "Fail" << std::endl;
}
void PyFetchProgress::Start()
{
std::cout << "Start" << std::endl;
pkgAcquireStatus::Start();
}
void PyFetchProgress::Stop()
{
std::cout << "Stop" << std::endl;
pkgAcquireStatus::Stop();
}
// FIXME: it should just set the attribute for
// CurrentCPS, Current...
bool PyFetchProgress::Pulse(pkgAcquire * Owner)
{
pkgAcquireStatus::Pulse(Owner);
//std::cout << "Pulse" << std::endl;
if(callbackInst == 0)
return false;
// set stats
PyObject *o;
o = Py_BuildValue("f", CurrentCPS);
PyObject_SetAttrString(callbackInst, "CurrentCPS", o);
o = Py_BuildValue("f", CurrentBytes);
PyObject_SetAttrString(callbackInst, "CurrentBytes", o);
o = Py_BuildValue("i", CurrentItems);
PyObject_SetAttrString(callbackInst, "CurrentItems", o);
o = Py_BuildValue("i", TotalItems);
PyObject_SetAttrString(callbackInst, "TotalItems", o);
o = Py_BuildValue("f", TotalBytes);
PyObject_SetAttrString(callbackInst, "TotalBytes", o);
// Call the pulse method
PyObject *arglist = Py_BuildValue("()");
PyObject *method = PyObject_GetAttrString(callbackInst, "Pulse");
if(method == NULL) {
// FIXME: make this silent
std::cerr << "Can't find 'Pulse' method" << std::endl;
Py_DECREF(arglist);
return false;
}
PyObject *result = PyEval_CallObject(method,arglist);
// FIXME: throw some exception here if the method was unsuccessfull
Py_XDECREF(result);
Py_XDECREF(method);
Py_DECREF(arglist);
// this can be canceld by returning false
return true;
}
|