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
|
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
// $Id: metaindex.cc,v 1.2 2003/12/26 17:04:22 mdz Exp $
/* ######################################################################
metaindex - Wrapper for the metaIndex functions
##################################################################### */
/*}}}*/
// Include Files /*{{{*/
#include "generic.h"
#include "apt_pkgmodule.h"
#include <apt-pkg/metaindex.h>
#include <Python.h>
static PyObject *MetaIndexGetURI(PyObject *Self,void*) {
metaIndex *meta = GetCpp<metaIndex*>(Self);
return CppPyString(meta->GetURI().c_str());
}
static PyObject *MetaIndexGetDist(PyObject *Self,void*) {
metaIndex *meta = GetCpp<metaIndex*>(Self);
return CppPyString(meta->GetDist().c_str());
}
static PyObject *MetaIndexGetIsTrusted(PyObject *Self,void*) {
metaIndex *meta = GetCpp<metaIndex*>(Self);
return PyBool_FromLong((meta->IsTrusted()));
}
static PyObject *MetaIndexGetType(PyObject *Self,void*) {
metaIndex *meta = GetCpp<metaIndex*>(Self);
return CppPyString(meta->GetType());
}
static PyObject *MetaIndexGetIndexFiles(PyObject *Self,void*) {
metaIndex *meta = GetCpp<metaIndex*>(Self);
PyObject *List = PyList_New(0);
std::vector<pkgIndexFile *> *indexFiles = meta->GetIndexFiles();
for (std::vector<pkgIndexFile *>::const_iterator I = indexFiles->begin();
I != indexFiles->end(); I++)
{
CppPyObject<pkgIndexFile*> *Obj;
Obj = CppPyObject_NEW<pkgIndexFile*>(Self, &PyIndexFile_Type,*I);
// Do not delete pkgIndexFile*, they are managed by metaIndex.
Obj->NoDelete = true;
PyList_Append(List,Obj);
Py_DECREF(Obj);
}
return List;
}
static PyGetSetDef MetaIndexGetSet[] = {
{"dist",MetaIndexGetDist,0,"The distribution, as a string."},
{"index_files",MetaIndexGetIndexFiles,0,
"A list of all IndexFile objects associated with this meta index."},
{"is_trusted",MetaIndexGetIsTrusted,0,
"A boolean value determining whether the file can be trusted."},
{"uri",MetaIndexGetURI,0,
"The uri the meta index is located at."},
{"type",MetaIndexGetType,0,
"The type of the meta index."},
{}
};
#define S(x) (x ? x : "")
static PyObject *MetaIndexRepr(PyObject *Self)
{
metaIndex *meta = GetCpp<metaIndex*>(Self);
return PyString_FromFormat("<%s object: type='%s', uri:'%s' dist='%s' "
"is_trusted='%i'>", Self->ob_type->tp_name,
S(meta->GetType()), meta->GetURI().c_str(),
meta->GetDist().c_str(), meta->IsTrusted());
}
#undef S
static const char *metaindex_doc =
"Provide information on meta-indexes (i.e. Release files), such as\n"
"whether they are trusted or their URI.";
PyTypeObject PyMetaIndex_Type =
{
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"apt_pkg.MetaIndex", // tp_name
sizeof(CppPyObject<metaIndex*>), // tp_basicsize
0, // tp_itemsize
// Methods
CppDeallocPtr<metaIndex*>, // tp_dealloc
0, // tp_print
0, // tp_getattr
0, // tp_setattr
0, // tp_compare
MetaIndexRepr, // tp_repr
0, // tp_as_number
0, // tp_as_sequence
0, // tp_as_mapping
0, // tp_hash
0, // tp_call
0, // tp_str
_PyAptObject_getattro, // tp_getattro
0, // tp_setattro
0, // tp_as_buffer
Py_TPFLAGS_DEFAULT, // tp_flags
metaindex_doc, // tp_doc
0, // tp_traverse
0, // tp_clear
0, // tp_richcompare
0, // tp_weaklistoffset
0, // tp_iter
0, // tp_iternext
0, // tp_methods
0, // tp_members
MetaIndexGetSet, // tp_getset
};
|