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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
// Description /*{{{*/
// $Id: acquire.cc,v 1.1 2003/06/03 03:03:23 mvo Exp $
/* ######################################################################
Acquire - Wrapper for the acquire code
##################################################################### */
#include "generic.h"
#include "apt_pkgmodule.h"
#include "acquire.h"
#include "progress.h"
#include <apt-pkg/acquire-item.h>
// pkgAcquire::Item
static PyObject *AcquireItemAttr(PyObject *Self,char *Name)
{
pkgAcquire::ItemIterator &I = GetCpp<pkgAcquire::ItemIterator>(Self);
if (strcmp("ID",Name) == 0)
return Py_BuildValue("i",(*I)->ID);
else if (strcmp("Status",Name) == 0)
return Py_BuildValue("i",(*I)->Status);
else if (strcmp("Complete",Name) == 0)
return Py_BuildValue("i",(*I)->Complete);
else if (strcmp("Local",Name) == 0)
return Py_BuildValue("i",(*I)->Local);
else if (strcmp("IsTrusted",Name) == 0)
return Py_BuildValue("i",(*I)->IsTrusted());
else if (strcmp("FileSize",Name) == 0)
return Py_BuildValue("i",(*I)->FileSize);
else if (strcmp("ErrorText",Name) == 0)
return Safe_FromString((*I)->ErrorText.c_str());
else if (strcmp("DestFile",Name) == 0)
return Safe_FromString((*I)->DestFile.c_str());
else if (strcmp("DescURI",Name) == 0)
return Safe_FromString((*I)->DescURI().c_str());
PyErr_SetString(PyExc_AttributeError,Name);
return 0;
}
static PyObject *AcquireItemRepr(PyObject *Self)
{
pkgAcquire::ItemIterator &I = GetCpp<pkgAcquire::ItemIterator>(Self);
char S[300];
snprintf(S,sizeof(S),"<pkgAcquire::ItemIterator object: "
"DestFile:'%s' ID:%i>",
(*I)->DestFile.c_str(),(*I)->ID);
return PyString_FromString(S);
}
PyTypeObject AcquireItemType =
{
PyObject_HEAD_INIT(&PyType_Type)
0, // ob_size
"pkgAcquire::ItemIterator", // tp_name
sizeof(CppOwnedPyObject<pkgAcquire::ItemIterator>), // tp_basicsize
0, // tp_itemsize
// Methods
CppOwnedDealloc<pkgAcquire::ItemIterator>, // tp_dealloc
0, // tp_print
AcquireItemAttr, // tp_getattr
0, // tp_setattr
0, // tp_compare
AcquireItemRepr, // tp_repr
0, // tp_as_number
0, // tp_as_sequence
0, // tp_as_mapping
0, // tp_hash
};
static PyObject *PkgAcquireRun(PyObject *Self,PyObject *Args)
{
PkgAcquireStruct &Struct = GetCpp<PkgAcquireStruct>(Self);
if (PyArg_ParseTuple(Args, "") == 0)
return 0;
//FIXME: add pulse interval here
pkgAcquire::RunResult run = Struct.fetcher.Run();
return HandleErrors(Py_BuildValue("i",run));
}
static PyObject *PkgAcquireShutdown(PyObject *Self,PyObject *Args)
{
PkgAcquireStruct &Struct = GetCpp<PkgAcquireStruct>(Self);
if (PyArg_ParseTuple(Args, "") == 0)
return 0;
Struct.fetcher.Shutdown();
Py_INCREF(Py_None);
return HandleErrors(Py_None);
}
static PyMethodDef PkgAcquireMethods[] =
{
{"Run",PkgAcquireRun,METH_VARARGS,"Run the fetcher"},
{}
};
static PyObject *AcquireAttr(PyObject *Self,char *Name)
{
PkgAcquireStruct &Struct = GetCpp<PkgAcquireStruct>(Self);
if(strcmp("TotalNeeded",Name) == 0)
return Py_BuildValue("l", Struct.fetcher.TotalNeeded());
if(strcmp("FetchNeeded",Name) == 0)
return Py_BuildValue("l", Struct.fetcher.FetchNeeded());
if(strcmp("PartialPresent",Name) == 0)
return Py_BuildValue("l", Struct.fetcher.PartialPresent());
if(strcmp("Items",Name) == 0)
{
PyObject *List = PyList_New(0);
for (pkgAcquire::ItemIterator I = Struct.fetcher.ItemsBegin();
I != Struct.fetcher.ItemsEnd(); I++)
{
PyObject *Obj;
Obj = CppOwnedPyObject_NEW<pkgAcquire::ItemIterator>(Self,&AcquireItemType,I);
PyList_Append(List,Obj);
Py_DECREF(Obj);
}
return List;
}
// some constants
if(strcmp("ResultContinue",Name) == 0)
return Py_BuildValue("i", pkgAcquire::Continue);
if(strcmp("ResultFailed",Name) == 0)
return Py_BuildValue("i", pkgAcquire::Failed);
if(strcmp("ResultCancelled",Name) == 0)
return Py_BuildValue("i", pkgAcquire::Cancelled);
return Py_FindMethod(PkgAcquireMethods,Self,Name);
}
PyTypeObject PkgAcquireType =
{
PyObject_HEAD_INIT(&PyType_Type)
0, // ob_size
"Acquire", // tp_name
sizeof(CppOwnedPyObject<PkgAcquireStruct>), // tp_basicsize
0, // tp_itemsize
// Methods
CppOwnedDealloc<PkgAcquireStruct>, // tp_dealloc
0, // tp_print
AcquireAttr, // 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
};
PyObject *GetAcquire(PyObject *Self,PyObject *Args)
{
pkgAcquire *fetcher;
PyObject *pyFetchProgressInst = NULL;
if (PyArg_ParseTuple(Args,"|O",&pyFetchProgressInst) == 0)
return 0;
if (pyFetchProgressInst != NULL) {
// FIXME: memleak?
PyFetchProgress *progress = new PyFetchProgress();
progress->setCallbackInst(pyFetchProgressInst);
fetcher = new pkgAcquire(progress);
} else {
fetcher = new pkgAcquire();
}
CppOwnedPyObject<pkgAcquire> *FetcherObj =
CppOwnedPyObject_NEW<pkgAcquire>(0,&PkgAcquireType, *fetcher);
return FetcherObj;
}
/*}}}*/
|