summaryrefslogtreecommitdiff
path: root/python/indexfile.cc
blob: 7accaa5066302a043229ce1aafdafed4bd4222e7 (plain)
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
// -*- mode: cpp; mode: fold -*-
// Description								/*{{{*/
// $Id: indexfile.cc,v 1.2 2003/12/26 17:04:22 mdz Exp $
/* ######################################################################

   pkgIndexFile - Wrapper for the pkgIndexFilefunctions

   ##################################################################### */
									/*}}}*/
// Include Files							/*{{{*/
#include "generic.h"
#include "apt_pkgmodule.h"

#include <apt-pkg/indexfile.h>

#include <Python.h>

static PyObject *IndexFileArchiveURI(PyObject *Self,PyObject *Args)
{
   pkgIndexFile *File = GetCpp<pkgIndexFile*>(Self);
   char *path;

   if (PyArg_ParseTuple(Args, "s",&path) == 0)
      return 0;
   return HandleErrors(Safe_FromString(File->ArchiveURI(path).c_str()));
}

static PyMethodDef IndexFileMethods[] =
{
   {"archive_uri",IndexFileArchiveURI,METH_VARARGS,"Returns the ArchiveURI"},
   #ifdef COMPAT_0_7
   {"ArchiveURI",IndexFileArchiveURI,METH_VARARGS,"Returns the ArchiveURI"},
   #endif
   {}
};

#define File (GetCpp<pkgIndexFile*>(Self))
static PyObject *IndexFileGetLabel(PyObject *Self,void*) {
   return Safe_FromString(File->GetType()->Label);
}
static PyObject *IndexFileGetDescribe(PyObject *Self,void*) {
   return Safe_FromString(File->Describe().c_str());
}
static PyObject *IndexFileGetExists(PyObject *Self,void*) {
   return Py_BuildValue("i",(File->Exists()));
}
static PyObject *IndexFileGetHasPackages(PyObject *Self,void*) {
   return Py_BuildValue("i",(File->HasPackages()));
}
static PyObject *IndexFileGetSize(PyObject *Self,void*) {
   return Py_BuildValue("i",(File->Size()));
}
static PyObject *IndexFileGetIsTrusted(PyObject *Self,void*) {
   return Py_BuildValue("i",(File->IsTrusted()));
}
#undef File

#define S(x) (x ? x : "")
static PyObject *IndexFileRepr(PyObject *Self)
{
   pkgIndexFile *File = GetCpp<pkgIndexFile*>(Self);
   return PyString_FromFormat("<pkIndexFile object: "
			"Label:'%s' Describe='%s' Exists='%i' "
	                "HasPackages='%i' Size='%lu'  "
 	                "IsTrusted='%i' ArchiveURI='%s'>",
	    S(File->GetType()->Label),  File->Describe().c_str(), File->Exists(),
	    File->HasPackages(), File->Size(),
            File->IsTrusted(), File->ArchiveURI("").c_str());
}
#undef S

static PyGetSetDef IndexFileGetSet[] = {
    {"describe",IndexFileGetDescribe},
    {"exists",IndexFileGetExists},
    {"has_packages",IndexFileGetHasPackages},
    {"is_trusted",IndexFileGetIsTrusted},
    {"label",IndexFileGetLabel},
    {"size",IndexFileGetSize},
    #ifdef COMPAT_0_7
    {"Describe",IndexFileGetDescribe},
    {"Exists",IndexFileGetExists},
    {"HasPackages",IndexFileGetHasPackages},
    {"IsTrusted",IndexFileGetIsTrusted},
    {"Label",IndexFileGetLabel},
    {"Size",IndexFileGetSize},
    #endif
    {}
};

PyTypeObject PyIndexFile_Type =
{
   PyVarObject_HEAD_INIT(&PyType_Type, 0)
   "apt_pkg.IndexFile",          // tp_name
   sizeof(CppOwnedPyObject<pkgIndexFile*>),   // tp_basicsize
   0,                                   // tp_itemsize
   // Methods
   // Not ..Ptr, because the pointer is managed somewhere else.
   CppOwnedDeallocPtr<pkgIndexFile*>,   // tp_dealloc
   0,                                   // tp_print
   0,                                   // tp_getattr
   0,                                   // tp_setattr
   0,                                   // tp_compare
   IndexFileRepr,                // tp_repr
   0,                                   // tp_as_number
   0,                                   // tp_as_sequence
   0,                                   // tp_as_mapping
   0,                                   // tp_hash
   0,                                   // tp_call
   0,                                   // tp_str
   0,                                   // tp_getattro
   0,                                   // tp_setattro
   0,                                   // tp_as_buffer
   Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags
   "IndexFile Object",               // tp_doc
   CppOwnedTraverse<pkgIndexFile*>,     // tp_traverse
   CppOwnedClear<pkgIndexFile*>,        // tp_clear
   0,                                   // tp_richcompare
   0,                                   // tp_weaklistoffset
   0,                                   // tp_iter
   0,                                   // tp_iternext
   IndexFileMethods,             // tp_methods
   0,                                   // tp_members
   IndexFileGetSet,              // tp_getset
};