metaindex.cc 4.31 KB
Newer Older
Michael Vogt's avatar
Michael Vogt committed
1
// -*- mode: cpp; mode: fold -*-
2
// Description                                /*{{{*/
Michael Vogt's avatar
Michael Vogt committed
3 4 5 6 7 8
// $Id: metaindex.cc,v 1.2 2003/12/26 17:04:22 mdz Exp $
/* ######################################################################

   metaindex - Wrapper for the metaIndex functions

   ##################################################################### */
9 10
                                    /*}}}*/
// Include Files                            /*{{{*/
Michael Vogt's avatar
Michael Vogt committed
11 12 13 14 15 16 17
#include "generic.h"
#include "apt_pkgmodule.h"

#include <apt-pkg/metaindex.h>

#include <Python.h>

18 19
static PyObject *MetaIndexGetURI(PyObject *Self,void*) {
    metaIndex *meta = GetCpp<metaIndex*>(Self);
20
    return CppPyString(meta->GetURI().c_str());
21
}
Michael Vogt's avatar
Michael Vogt committed
22

23 24
static PyObject *MetaIndexGetDist(PyObject *Self,void*) {
    metaIndex *meta = GetCpp<metaIndex*>(Self);
25
    return CppPyString(meta->GetDist().c_str());
26
}
Michael Vogt's avatar
Michael Vogt committed
27

28 29
static PyObject *MetaIndexGetIsTrusted(PyObject *Self,void*) {
    metaIndex *meta = GetCpp<metaIndex*>(Self);
30
    return PyBool_FromLong((meta->IsTrusted()));
Michael Vogt's avatar
Michael Vogt committed
31 32
}

33 34 35
static PyObject *MetaIndexGetIndexFiles(PyObject *Self,void*) {
    metaIndex *meta = GetCpp<metaIndex*>(Self);
    PyObject *List = PyList_New(0);
36 37
    std::vector<pkgIndexFile *> *indexFiles = meta->GetIndexFiles();
    for (std::vector<pkgIndexFile *>::const_iterator I = indexFiles->begin();
38 39
        I != indexFiles->end(); I++)
    {
40 41
        CppPyObject<pkgIndexFile*> *Obj;
        Obj = CppPyObject_NEW<pkgIndexFile*>(Self, &PyIndexFile_Type,*I);
42 43
        // Do not delete pkgIndexFile*, they are managed by metaIndex.
        Obj->NoDelete = true;
44
        PyList_Append(List,Obj);
45
        Py_DECREF(Obj);
46 47 48 49 50
    }
    return List;
}

static PyGetSetDef MetaIndexGetSet[] = {
51 52 53 54 55 56 57
   {"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."},
58 59 60
   {}
};

61
#define S(x) (x ? x : "")
Michael Vogt's avatar
Michael Vogt committed
62 63
static PyObject *MetaIndexRepr(PyObject *Self)
{
64
    metaIndex *meta = GetCpp<metaIndex*>(Self);
65 66
    return PyString_FromFormat("<%s object: type='%s', uri:'%s' dist='%s' "
                               "is_trusted='%i'>", Self->ob_type->tp_name,
67
                               S(meta->GetType()),  meta->GetURI().c_str(),
68
                               meta->GetDist().c_str(), meta->IsTrusted());
Michael Vogt's avatar
Michael Vogt committed
69
}
70
#undef S
Michael Vogt's avatar
Michael Vogt committed
71

72 73

static const char *metaindex_doc =
74 75
    "Provide information on meta-indexes (i.e. Release files), such as\n"
    "whether they are trusted or their URI.";
76
    
77
PyTypeObject PyMetaIndex_Type =
Michael Vogt's avatar
Michael Vogt committed
78
{
79
   PyVarObject_HEAD_INIT(&PyType_Type, 0)
80
   "apt_pkg.MetaIndex",                    // tp_name
81
   sizeof(CppPyObject<metaIndex*>),   // tp_basicsize
82
   0,                                      // tp_itemsize
Michael Vogt's avatar
Michael Vogt committed
83
   // Methods
84
   CppDeallocPtr<metaIndex*>,         // tp_dealloc
85 86 87 88 89 90 91 92 93 94 95
   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
Julian Andres Klode's avatar
Julian Andres Klode committed
96
   _PyAptObject_getattro,                  // tp_getattro
97 98 99
   0,                                      // tp_setattro
   0,                                      // tp_as_buffer
   Py_TPFLAGS_DEFAULT,                     // tp_flags
100
   metaindex_doc,                          // tp_doc
101 102 103 104 105 106 107 108 109
   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
Michael Vogt's avatar
Michael Vogt committed
110
};