|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "generic.h" |
|
#include "apt_pkgmodule.h" |
|
|
|
#include <apt-pkg/sourcelist.h> |
|
|
|
#include <Python.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static char *doc_PkgSourceListFindIndex = |
|
"find_index(pkgfile: apt_pkg.PackageFile) -> apt_pkg.IndexFile\n\n" |
|
"Return the index file for the given package file, or None if none\n" |
|
"could be found."; |
|
static PyObject *PkgSourceListFindIndex(PyObject *Self,PyObject *Args) |
|
{ |
|
pkgSourceList *list = GetCpp<pkgSourceList*>(Self); |
|
PyObject *pyPkgFileIter; |
|
CppPyObject<pkgIndexFile*> *pyPkgIndexFile; |
|
|
|
if (PyArg_ParseTuple(Args, "O!", &PyPackageFile_Type,&pyPkgFileIter) == 0) |
|
return 0; |
|
|
|
pkgCache::PkgFileIterator &i = GetCpp<pkgCache::PkgFileIterator>(pyPkgFileIter); |
|
pkgIndexFile *index; |
|
if(list->FindIndex(i, index)) |
|
{ |
|
pyPkgIndexFile = CppPyObject_NEW<pkgIndexFile*>(pyPkgFileIter,&PyIndexFile_Type,index); |
|
|
|
pyPkgIndexFile->NoDelete = true; |
|
return pyPkgIndexFile; |
|
} |
|
|
|
|
|
|
|
Py_INCREF(Py_None); |
|
return Py_None; |
|
} |
|
|
|
static char *doc_PkgSourceListReadMainList = |
|
"read_main_list() -> bool\n\n" |
|
"Read /etc/apt/sources.list and similar files to populate the list\n" |
|
"of indexes."; |
|
static PyObject *PkgSourceListReadMainList(PyObject *Self,PyObject *Args) |
|
{ |
|
pkgSourceList *list = GetCpp<pkgSourceList*>(Self); |
|
bool res = list->ReadMainList(); |
|
|
|
return HandleErrors(PyBool_FromLong(res)); |
|
} |
|
|
|
static char *doc_PkgSourceListGetIndexes = |
|
"get_indexes(acquire: apt_pkg.Acquire[, all: bool=False]) -> bool\n\n" |
|
"Add all indexes (i.e. stuff like Release files, Packages files)\n" |
|
"to the Acquire object 'acquire'. If 'all' is True, all indexes\n" |
|
"will be added, otherwise only changed indexes will be added."; |
|
static PyObject *PkgSourceListGetIndexes(PyObject *Self,PyObject *Args) |
|
{ |
|
pkgSourceList *list = GetCpp<pkgSourceList*>(Self); |
|
|
|
PyObject *pyFetcher; |
|
char all = 0; |
|
if (PyArg_ParseTuple(Args, "O!|b",&PyAcquire_Type,&pyFetcher, &all) == 0) |
|
return 0; |
|
|
|
pkgAcquire *fetcher = GetCpp<pkgAcquire*>(pyFetcher); |
|
bool res = list->GetIndexes(fetcher, all); |
|
|
|
return HandleErrors(PyBool_FromLong(res)); |
|
} |
|
|
|
static PyMethodDef PkgSourceListMethods[] = |
|
{ |
|
{"find_index",PkgSourceListFindIndex,METH_VARARGS,doc_PkgSourceListFindIndex}, |
|
{"read_main_list",PkgSourceListReadMainList,METH_VARARGS,doc_PkgSourceListReadMainList}, |
|
{"get_indexes",PkgSourceListGetIndexes,METH_VARARGS,doc_PkgSourceListGetIndexes}, |
|
{} |
|
}; |
|
|
|
static PyObject *PkgSourceListGetList(PyObject *Self,void*) |
|
{ |
|
pkgSourceList *list = GetCpp<pkgSourceList*>(Self); |
|
PyObject *List = PyList_New(0); |
|
for (std::vector<metaIndex *>::const_iterator I = list->begin(); |
|
I != list->end(); I++) |
|
{ |
|
CppPyObject<metaIndex*> *Obj; |
|
Obj = CppPyObject_NEW<metaIndex*>(Self, &PyMetaIndex_Type,*I); |
|
|
|
Obj->NoDelete = true; |
|
PyList_Append(List,Obj); |
|
Py_DECREF(Obj); |
|
} |
|
return List; |
|
} |
|
|
|
static PyGetSetDef PkgSourceListGetSet[] = { |
|
{"list",PkgSourceListGetList,0,"A list of MetaIndex() objects.",0}, |
|
{} |
|
}; |
|
|
|
static PyObject *PkgSourceListNew(PyTypeObject *type,PyObject *args,PyObject *kwds) |
|
{ |
|
char *kwlist[] = {0}; |
|
if (PyArg_ParseTupleAndKeywords(args,kwds,"",kwlist) == 0) |
|
return 0; |
|
return CppPyObject_NEW<pkgSourceList*>(NULL, type,new pkgSourceList()); |
|
} |
|
|
|
static const char *sourcelist_doc = |
|
"SourceList()\n\n" |
|
"Represent the list of sources stored in /etc/apt/sources.list and\n" |
|
"similar files."; |
|
PyTypeObject PySourceList_Type = |
|
{ |
|
PyVarObject_HEAD_INIT(&PyType_Type, 0) |
|
"apt_pkg.SourceList", |
|
sizeof(CppPyObject<pkgSourceList*>), |
|
0, |
|
|
|
CppDeallocPtr<pkgSourceList*>, |
|
0, |
|
0, |
|
0, |
|
0, |
|
0, |
|
0, |
|
0, |
|
0, |
|
0, |
|
0, |
|
0, |
|
_PyAptObject_getattro, |
|
0, |
|
0, |
|
(Py_TPFLAGS_DEFAULT | |
|
Py_TPFLAGS_BASETYPE), |
|
sourcelist_doc, |
|
0, |
|
0, |
|
0, |
|
0, |
|
0, |
|
0, |
|
PkgSourceListMethods, |
|
0, |
|
PkgSourceListGetSet, |
|
0, |
|
0, |
|
0, |
|
0, |
|
0, |
|
0, |
|
0, |
|
PkgSourceListNew, |
|
}; |
|
|
|
|