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
|
// 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>
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());
// 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;
}
/*}}}*/
|