forked from excid3/python-apt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetaindex.cc
More file actions
81 lines (66 loc) · 2.44 KB
/
metaindex.cc
File metadata and controls
81 lines (66 loc) · 2.44 KB
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
// -*- 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 *MetaIndexAttr(PyObject *Self,char *Name)
{
metaIndex *meta = GetCpp<metaIndex*>(Self);
if (strcmp("URI",Name) == 0)
return Safe_FromString(meta->GetURI().c_str());
else if (strcmp("Dist",Name) == 0)
return Safe_FromString(meta->GetDist().c_str());
else if (strcmp("IsTrusted",Name) == 0)
return Py_BuildValue("i",(meta->IsTrusted()));
else if (strcmp("IndexFiles",Name) == 0)
{
PyObject *List = PyList_New(0);
vector<pkgIndexFile *> *indexFiles = meta->GetIndexFiles();
for (vector<pkgIndexFile *>::const_iterator I = indexFiles->begin();
I != indexFiles->end(); I++)
{
PyObject *Obj;
Obj = CppPyObject_NEW<pkgIndexFile*>(&PackageIndexFileType,*I);
PyList_Append(List,Obj);
}
return List;
}
PyErr_SetString(PyExc_AttributeError,Name);
return 0;
}
static PyObject *MetaIndexRepr(PyObject *Self)
{
metaIndex *meta = GetCpp<metaIndex*>(Self);
char S[1024];
snprintf(S,sizeof(S),"<metaIndex object: "
"Type='%s', URI:'%s' Dist='%s' IsTrusted='%i'>",
meta->GetType(), meta->GetURI().c_str(), meta->GetDist().c_str(),
meta->IsTrusted());
return PyString_FromString(S);
}
PyTypeObject MetaIndexType =
{
PyObject_HEAD_INIT(&PyType_Type)
0, // ob_size
"metaIndex", // tp_name
sizeof(CppOwnedPyObject<metaIndex*>), // tp_basicsize
0, // tp_itemsize
// Methods
CppOwnedDealloc<metaIndex*>, // tp_dealloc
0, // tp_print
MetaIndexAttr, // 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
};