// -*- mode: cpp; mode: fold -*- // Description /*{{{*/ // $Id: pkgsrcrecords.cc,v 1.2 2003/12/26 17:04:22 mdz Exp $ /* ###################################################################### Package Records - Wrapper for the package records functions ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ #include "generic.h" #include "apt_pkgmodule.h" #include #include /*}}}*/ struct PkgSrcRecordsStruct { pkgSourceList List; pkgSrcRecords *Records; pkgSrcRecords::Parser *Last; PkgSrcRecordsStruct() : Last(0) { List.ReadMainList(); Records = new pkgSrcRecords(List); }; ~PkgSrcRecordsStruct() { delete Records; }; }; // PkgSrcRecords Class /*{{{*/ // --------------------------------------------------------------------- static char *doc_PkgSrcRecordsLookup = "lookup(name: str) -> bool\n\n" "Look up the source package with the given name. Each call moves\n" "the position of the records parser forward. If there are no\n" "more records, return None. If the lookup failed this way,\n" "access to any of the attributes will result in an AttributeError."; static PyObject *PkgSrcRecordsLookup(PyObject *Self,PyObject *Args) { PkgSrcRecordsStruct &Struct = GetCpp(Self); char *Name = 0; if (PyArg_ParseTuple(Args,"s",&Name) == 0) return 0; Struct.Last = Struct.Records->Find(Name, false); if (Struct.Last == 0) { Struct.Records->Restart(); Py_INCREF(Py_None); return HandleErrors(Py_None); } return PyBool_FromLong(1); } static char *doc_PkgSrcRecordsRestart = "restart()\n\n" "Restart the lookup process. This moves the parser to the first\n" "package and lookups can now be made just like on a new object."; static PyObject *PkgSrcRecordsRestart(PyObject *Self,PyObject *Args) { PkgSrcRecordsStruct &Struct = GetCpp(Self); if (PyArg_ParseTuple(Args,"") == 0) return 0; Struct.Records->Restart(); Py_INCREF(Py_None); return HandleErrors(Py_None); } static PyMethodDef PkgSrcRecordsMethods[] = { {"lookup",PkgSrcRecordsLookup,METH_VARARGS,doc_PkgSrcRecordsLookup}, {"restart",PkgSrcRecordsRestart,METH_VARARGS,doc_PkgSrcRecordsRestart}, {} }; /** * Get the PkgSrcRecordsStruct from a PyObject. If no package has been looked * up, set an AttributeError using the given name. */ static inline PkgSrcRecordsStruct &GetStruct(PyObject *Self,char *name) { PkgSrcRecordsStruct &Struct = GetCpp(Self); if (Struct.Last == 0) PyErr_SetString(PyExc_AttributeError,name); return Struct; } static PyObject *PkgSrcRecordsGetPackage(PyObject *Self,void*) { PkgSrcRecordsStruct &Struct = GetStruct(Self,"Package"); return (Struct.Last != 0) ? CppPyString(Struct.Last->Package()) : 0; } static PyObject *PkgSrcRecordsGetVersion(PyObject *Self,void*) { PkgSrcRecordsStruct &Struct = GetStruct(Self,"Version"); return (Struct.Last != 0) ? CppPyString(Struct.Last->Version()) : 0; } static PyObject *PkgSrcRecordsGetMaintainer(PyObject *Self,void*) { PkgSrcRecordsStruct &Struct = GetStruct(Self,"Maintainer"); return (Struct.Last != 0) ? CppPyString(Struct.Last->Maintainer()) : 0; } static PyObject *PkgSrcRecordsGetSection(PyObject *Self,void*) { PkgSrcRecordsStruct &Struct = GetStruct(Self,"Section"); return (Struct.Last != 0) ? CppPyString(Struct.Last->Section()) : 0; } static PyObject *PkgSrcRecordsGetRecord(PyObject *Self,void*) { PkgSrcRecordsStruct &Struct = GetStruct(Self,"Record"); return (Struct.Last != 0) ? CppPyString(Struct.Last->AsStr()) : 0; } static PyObject *PkgSrcRecordsGetBinaries(PyObject *Self,void*) { PkgSrcRecordsStruct &Struct = GetStruct(Self,"Binaries"); if (Struct.Last == 0) return 0; PyObject *List = PyList_New(0); for(const char **b = Struct.Last->Binaries(); *b != 0; ++b) PyList_Append(List, CppPyString(*b)); return List; // todo } static PyObject *PkgSrcRecordsGetIndex(PyObject *Self,void*) { PkgSrcRecordsStruct &Struct = GetStruct(Self,"Index"); if (Struct.Last == 0) return 0; const pkgIndexFile &tmp = Struct.Last->Index(); CppPyObject *PyObj; PyObj = CppPyObject_NEW(Self,&PyIndexFile_Type, (pkgIndexFile*)&tmp); // Do not delete the pkgIndexFile*, it is managed by PkgSrcRecords::Parser. PyObj->NoDelete=true; return PyObj; } static PyObject *PkgSrcRecordsGetFiles(PyObject *Self,void*) { PkgSrcRecordsStruct &Struct = GetStruct(Self,"Files"); if (Struct.Last == 0) return 0; PyObject *List = PyList_New(0); vector f; if(!Struct.Last->Files(f)) return NULL; // error PyObject *v; for(unsigned int i=0;i bd; if(!Struct.Last->BuildDepends(bd, false /* arch-only*/)) return NULL; // error PyObject *v; for(unsigned int i=0;i bd; if(!Struct.Last->BuildDepends(bd, false /* arch-only*/)) return NULL; // error PyObject *v; for(unsigned int i=0;i(NULL, type)); } static const char *sourcerecords_doc = "SourceRecords()\n\n" "Provide an easy way to look up the records of source packages and\n" "provide easy attributes for some widely used fields of the record."; PyTypeObject PySourceRecords_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.SourceRecords", // tp_name sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods CppDealloc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr 0, // tp_compare 0, // tp_repr 0, // tp_as_number 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), sourcerecords_doc, // tp_doc 0, // tp_traverse 0, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter 0, // tp_iternext PkgSrcRecordsMethods, // tp_methods 0, // tp_members PkgSrcRecordsGetSet, // 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 PkgSrcRecordsNew, // tp_new }; /*}}}*/ #ifdef COMPAT_0_7 PyObject *GetPkgSrcRecords(PyObject *Self,PyObject *Args) { PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPkgSrcRecords() is " "deprecated. Please see apt_pkg.SourceRecords() for the " "replacement.", 1); if (PyArg_ParseTuple(Args,"") == 0) return 0; return HandleErrors(CppPyObject_NEW(NULL, &PySourceRecords_Type)); } #endif