summaryrefslogtreecommitdiff
path: root/python/sourcelist.cc
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2010-03-23 14:18:44 +0100
committerMichael Vogt <michael.vogt@ubuntu.com>2010-03-23 14:18:44 +0100
commit37650a078f5504dfbc6622d2c06f4435a3302dd4 (patch)
tree35d7df75535420cbe0712a5f7b7b66d61f5e44d1 /python/sourcelist.cc
parent2aa709e41d8896ef897863ea9181c409c4c87a8c (diff)
parent3a08cfb10590d5cf5df1f45d94a424ef6a0f674b (diff)
downloadpython-apt-37650a078f5504dfbc6622d2c06f4435a3302dd4.tar.gz
merged from lp:~mvo/python-apt/mvo
Diffstat (limited to 'python/sourcelist.cc')
-rw-r--r--python/sourcelist.cc100
1 files changed, 71 insertions, 29 deletions
diff --git a/python/sourcelist.cc b/python/sourcelist.cc
index 5dcaf86b..6184fee3 100644
--- a/python/sourcelist.cc
+++ b/python/sourcelist.cc
@@ -26,20 +26,22 @@ static PyObject *PkgSourceListFindIndex(PyObject *Self,PyObject *Args)
{
pkgSourceList *list = GetCpp<pkgSourceList*>(Self);
PyObject *pyPkgFileIter;
- PyObject *pyPkgIndexFile;
+ CppPyObject<pkgIndexFile*> *pyPkgIndexFile;
- if (PyArg_ParseTuple(Args, "O!", &PackageFileType,&pyPkgFileIter) == 0)
+ 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 = CppOwnedPyObject_NEW<pkgIndexFile*>(pyPkgFileIter,&PackageIndexFileType,index);
+ pyPkgIndexFile = CppPyObject_NEW<pkgIndexFile*>(pyPkgFileIter,&PyIndexFile_Type,index);
+ // Do not delete the pkgIndexFile*, it is managed by pkgSourceList.
+ pyPkgIndexFile->NoDelete = true;
return pyPkgIndexFile;
}
- //&PackageIndexFileType,&pyPkgIndexFile)
+ //&PyIndexFile_Type,&pyPkgIndexFile)
Py_INCREF(Py_None);
return Py_None;
@@ -61,7 +63,7 @@ static PyObject *PkgSourceListGetIndexes(PyObject *Self,PyObject *Args)
PyObject *pyFetcher;
char all = 0;
- if (PyArg_ParseTuple(Args, "O!|b",&PkgAcquireType,&pyFetcher, &all) == 0)
+ if (PyArg_ParseTuple(Args, "O!|b",&PyAcquire_Type,&pyFetcher, &all) == 0)
return 0;
pkgAcquire *fetcher = GetCpp<pkgAcquire*>(pyFetcher);
@@ -72,41 +74,52 @@ static PyObject *PkgSourceListGetIndexes(PyObject *Self,PyObject *Args)
static PyMethodDef PkgSourceListMethods[] =
{
- {"FindIndex",PkgSourceListFindIndex,METH_VARARGS,doc_PkgSourceListFindIndex},
- {"ReadMainList",PkgSourceListReadMainList,METH_VARARGS,doc_PkgSourceListReadMainList},
- {"GetIndexes",PkgSourceListGetIndexes,METH_VARARGS,doc_PkgSourceListReadMainList},
+ {"find_index",PkgSourceListFindIndex,METH_VARARGS,doc_PkgSourceListFindIndex},
+ {"read_main_list",PkgSourceListReadMainList,METH_VARARGS,doc_PkgSourceListReadMainList},
+ {"get_indexes",PkgSourceListGetIndexes,METH_VARARGS,doc_PkgSourceListGetIndexes},
{}
};
-static PyObject *PkgSourceListAttr(PyObject *Self,char *Name)
+static PyObject *PkgSourceListGetList(PyObject *Self,void*)
{
pkgSourceList *list = GetCpp<pkgSourceList*>(Self);
-
- if (strcmp("List",Name) == 0)
+ PyObject *List = PyList_New(0);
+ for (vector<metaIndex *>::const_iterator I = list->begin();
+ I != list->end(); I++)
{
- PyObject *List = PyList_New(0);
- for (vector<metaIndex *>::const_iterator I = list->begin();
- I != list->end(); I++)
- {
- PyObject *Obj;
- Obj = CppPyObject_NEW<metaIndex*>(&MetaIndexType,*I);
- PyList_Append(List,Obj);
- }
- return List;
+ CppPyObject<metaIndex*> *Obj;
+ Obj = CppPyObject_NEW<metaIndex*>(Self, &PyMetaIndex_Type,*I);
+ // Never delete metaIndex*, they are managed by the pkgSourceList.
+ Obj->NoDelete = true;
+ PyList_Append(List,Obj);
+ Py_DECREF(Obj);
}
- return Py_FindMethod(PkgSourceListMethods,Self,Name);
+ return List;
}
-PyTypeObject PkgSourceListType =
+
+static PyGetSetDef PkgSourceListGetSet[] = {
+ {"list",PkgSourceListGetList,0,"A list of MetaIndex() objects.",0},
+ {}
+};
+
+static PyObject *PkgSourceListNew(PyTypeObject *type,PyObject *args,PyObject *kwds)
{
- PyObject_HEAD_INIT(&PyType_Type)
- 0, // ob_size
- "pkgSourceList", // tp_name
+ char *kwlist[] = {0};
+ if (PyArg_ParseTupleAndKeywords(args,kwds,"",kwlist) == 0)
+ return 0;
+ return CppPyObject_NEW<pkgSourceList*>(NULL, type,new pkgSourceList());
+}
+
+PyTypeObject PySourceList_Type =
+{
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ "apt_pkg.SourceList", // tp_name
sizeof(CppPyObject<pkgSourceList*>), // tp_basicsize
0, // tp_itemsize
// Methods
- CppDealloc<pkgSourceList*>, // tp_dealloc
+ CppDeallocPtr<pkgSourceList*>, // tp_dealloc
0, // tp_print
- PkgSourceListAttr, // tp_getattr
+ 0, // tp_getattr
0, // tp_setattr
0, // tp_compare
0, // tp_repr
@@ -114,10 +127,39 @@ PyTypeObject PkgSourceListType =
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
+ Py_TPFLAGS_BASETYPE),
+ "pkgSourceList Object", // tp_doc
+ 0, // tp_traverse
+ 0, // tp_clear
+ 0, // tp_richcompare
+ 0, // tp_weaklistoffset
+ 0, // tp_iter
+ 0, // tp_iternext
+ PkgSourceListMethods, // tp_methods
+ 0, // tp_members
+ PkgSourceListGetSet, // tp_getset
+ 0, // tp_base
+ 0, // tp_dict
+ 0, // tp_descr_get
+ 0, // tp_descr_set
+ 0, // tp_dictoffset
+ 0, // tp_init
+ 0, // tp_alloc
+ PkgSourceListNew, // tp_new
};
+#ifdef COMPAT_0_7
PyObject *GetPkgSourceList(PyObject *Self,PyObject *Args)
{
- return CppPyObject_NEW<pkgSourceList*>(&PkgSourceListType,new pkgSourceList());
+ PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPkgSourceList() is "
+ "deprecated. Please see apt_pkg.SourceList() for the "
+ "replacement.", 1);
+ return PkgSourceListNew(&PySourceList_Type,Args,0);
}
-
+#endif