diff options
| author | Arch Librarian <arch@canonical.com> | 2004-11-24 10:00:36 +0000 |
|---|---|---|
| committer | Arch Librarian <arch@canonical.com> | 2004-11-24 10:00:36 +0000 |
| commit | e5d16b671f2a625893731b4ea0bd684bbd444323 (patch) | |
| tree | 73f3a71281ad33ff97a624b3679ce9644031d1a2 | |
| parent | 626a19f14cf2728cab14f3c71cc8d689c7ebc169 (diff) | |
| download | python-apt-e5d16b671f2a625893731b4ea0bd684bbd444323.tar.gz | |
Initial support for accessing source package data
Author: mdz
Date: 2003-07-23 02:20:24 GMT
Initial support for accessing source package data
| -rw-r--r-- | debian/changelog | 3 | ||||
| -rw-r--r-- | doc/examples/sources.py | 9 | ||||
| -rw-r--r-- | python/apt_pkgmodule.cc | 6 | ||||
| -rw-r--r-- | python/apt_pkgmodule.h | 4 | ||||
| -rw-r--r-- | python/makefile | 2 | ||||
| -rw-r--r-- | python/pkgsrcrecords.cc | 118 | ||||
| -rw-r--r-- | python/sourcelist.cc | 83 |
7 files changed, 220 insertions, 5 deletions
diff --git a/debian/changelog b/debian/changelog index 7ffc11d5..dc31fd8c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,8 +1,9 @@ python-apt (0.5.5.2) unstable; urgency=low * Add myself to Uploaders so that bugs don't get tagged as NMU-fixed anymore + * Initial support for working with source packages (Closes: #199716) - -- + -- Matt Zimmerman <mdz@debian.org> Tue, 22 Jul 2003 22:20:00 -0400 python-apt (0.5.5.1) unstable; urgency=low diff --git a/doc/examples/sources.py b/doc/examples/sources.py new file mode 100644 index 00000000..79514621 --- /dev/null +++ b/doc/examples/sources.py @@ -0,0 +1,9 @@ +#!/usr/bin/python + +import apt_pkg + +apt_pkg.init() + +sources = apt_pkg.GetPkgSrcRecords() +while sources.Lookup('hello'): + print sources.Package, sources.Version, sources.Maintainer, sources.Section, `sources.Binaries` diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 6c2a61e1..d9d0911f 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: apt_pkgmodule.cc,v 1.4 2002/01/08 06:53:04 jgg Exp $ +// $Id: apt_pkgmodule.cc,v 1.5 2003/07/23 02:20:24 mdz Exp $ /* ###################################################################### apt_pkgmodule - Top level for the python module. Create the internal @@ -331,7 +331,9 @@ static PyMethodDef methods[] = // Cache {"GetCache",TmpGetCache,METH_VARARGS,"GetCache() -> PkgCache"}, - {"GetPkgRecords",GetPkgRecords,METH_VARARGS,"GetPkgRecords(Cache) -> PkgRecrods"}, + {"GetPkgRecords",GetPkgRecords,METH_VARARGS,"GetPkgRecords(Cache) -> PkgRecords"}, + {"GetPkgSrcRecords",GetPkgSrcRecords,METH_VARARGS,"GetPkgSrcRecords() -> PkgSrcRecords"}, + {"GetPkgSourceList",GetPkgSourceList,METH_VARARGS,"GetPkgSourceList() -> PkgSourceList"}, {} }; diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index bc3e286c..b2222df4 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: apt_pkgmodule.h,v 1.3 2002/01/08 06:53:04 jgg Exp $ +// $Id: apt_pkgmodule.h,v 1.4 2003/07/23 02:20:24 mdz Exp $ /* ###################################################################### Prototypes for the module @@ -62,5 +62,7 @@ PyObject *TmpGetCache(PyObject *Self,PyObject *Args); // PkgRecords Stuff extern PyTypeObject PkgRecordsType; PyObject *GetPkgRecords(PyObject *Self,PyObject *Args); +PyObject *GetPkgSrcRecords(PyObject *Self,PyObject *Args); +PyObject *GetPkgSourceList(PyObject *Self,PyObject *Args); #endif diff --git a/python/makefile b/python/makefile index 12dea22f..b2f51372 100644 --- a/python/makefile +++ b/python/makefile @@ -10,7 +10,7 @@ MODULE=apt_pkg SLIBS = -lapt-pkg LIB_MAKES = apt-pkg/makefile APT_PKG_SRC = apt_pkgmodule.cc configuration.cc generic.cc tag.cc string.cc \ - cache.cc pkgrecords.cc + cache.cc pkgrecords.cc pkgsrcrecords.cc sourcelist.cc SOURCE := $(APT_PKG_SRC) include $(PYTHON_H) diff --git a/python/pkgsrcrecords.cc b/python/pkgsrcrecords.cc new file mode 100644 index 00000000..8f6dbbcf --- /dev/null +++ b/python/pkgsrcrecords.cc @@ -0,0 +1,118 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +// $Id: pkgsrcrecords.cc,v 1.1 2003/07/23 02:20:24 mdz Exp $ +/* ###################################################################### + + Package Records - Wrapper for the package records functions + + ##################################################################### */ + /*}}}*/ +// Include Files /*{{{*/ +#include "generic.h" +#include "apt_pkgmodule.h" + +#include <apt-pkg/sourcelist.h> + +#include <Python.h> + /*}}}*/ + +struct PkgSrcRecordsStruct +{ + pkgSourceList List; + pkgSrcRecords *Records; + pkgSrcRecords::Parser *Last; + + PkgSrcRecordsStruct() : Last(0) { + List.ReadMainList(); + Records = new pkgSrcRecords(List); + }; +}; + +// PkgSrcRecords Class /*{{{*/ +// --------------------------------------------------------------------- + +static char *doc_PkgSrcRecordsLookup = "xxx"; +static PyObject *PkgSrcRecordsLookup(PyObject *Self,PyObject *Args) +{ + PkgSrcRecordsStruct &Struct = GetCpp<PkgSrcRecordsStruct>(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(); + return Py_None; + } + + return Py_BuildValue("i", 1); +} + +static PyMethodDef PkgSrcRecordsMethods[] = +{ + {"Lookup",PkgSrcRecordsLookup,METH_VARARGS,doc_PkgSrcRecordsLookup}, + {} +}; + +static PyObject *PkgSrcRecordsAttr(PyObject *Self,char *Name) +{ + PkgSrcRecordsStruct &Struct = GetCpp<PkgSrcRecordsStruct>(Self); + + if (Struct.Last != 0) + { + if (strcmp("Package",Name) == 0) + return CppPyString(Struct.Last->Package()); + else if (strcmp("Version",Name) == 0) + return CppPyString(Struct.Last->Version()); + else if (strcmp("Maintainer",Name) == 0) + return CppPyString(Struct.Last->Maintainer()); + else if (strcmp("Section",Name) == 0) + return CppPyString(Struct.Last->Section()); + else if (strcmp("Binaries",Name) == 0) { + PyObject *List = PyList_New(0); + + for(const char **b = Struct.Last->Binaries(); + *b != 0; + ++b) + PyList_Append(List, CppPyString(*b)); + + return List; // todo + } else if (strcmp("Files",Name) == 0) + return 0; // todo + } + + return Py_FindMethod(PkgSrcRecordsMethods,Self,Name); +} +PyTypeObject PkgSrcRecordsType = +{ + PyObject_HEAD_INIT(&PyType_Type) + 0, // ob_size + "pkgSrcRecords", // tp_name + sizeof(CppOwnedPyObject<PkgSrcRecordsStruct>), // tp_basicsize + 0, // tp_itemsize + // Methods + CppOwnedDealloc<PkgSrcRecordsStruct>, // tp_dealloc + 0, // tp_print + PkgSrcRecordsAttr, // 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 +}; + + /*}}}*/ + +PyObject *GetPkgSrcRecords(PyObject *Self,PyObject *Args) +{ + PyObject *Owner; +// if (PyArg_ParseTuple(Args,"O!",&PkgCacheType,&Owner) == 0) +// return 0; + + return HandleErrors(CppOwnedPyObject_NEW<PkgSrcRecordsStruct>(Owner, + &PkgSrcRecordsType)); +} + diff --git a/python/sourcelist.cc b/python/sourcelist.cc new file mode 100644 index 00000000..0bee8d8c --- /dev/null +++ b/python/sourcelist.cc @@ -0,0 +1,83 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +// $Id: sourcelist.cc,v 1.1 2003/07/23 02:20:24 mdz Exp $ +/* ###################################################################### + + Package Records - Wrapper for the package records functions + + ##################################################################### */ + /*}}}*/ +// Include Files /*{{{*/ +#include "generic.h" +#include "apt_pkgmodule.h" + +#include <apt-pkg/sourcelist.h> + +#include <Python.h> + /*}}}*/ + +struct PkgSourceListStruct +{ + pkgSourceList List; +}; + +// PkgsourceList Class /*{{{*/ +// --------------------------------------------------------------------- + +static char *doc_PkgSourceListFindIndex = "xxx"; +static PyObject *PkgSourceListFindIndex(PyObject *Self,PyObject *Args) +{ + PkgSourceListStruct &Struct = GetCpp<PkgSourceListStruct>(Self); + return Py_BuildValue("i", 1); +} + +static char *doc_PkgSourceListReadMainList = "xxx"; +static PyObject *PkgSourceListReadMainList(PyObject *Self,PyObject *Args) +{ + PkgSourceListStruct &Struct = GetCpp<PkgSourceListStruct>(Self); + Struct.List.ReadMainList(); + + return Py_None; +} + +static PyMethodDef PkgSourceListMethods[] = +{ + {"FindIndex",PkgSourceListFindIndex,METH_VARARGS,doc_PkgSourceListFindIndex}, + {"ReadMainList",PkgSourceListReadMainList,METH_VARARGS,doc_PkgSourceListReadMainList}, + {} +}; + +static PyObject *PkgSourceListAttr(PyObject *Self,char *Name) +{ + return Py_FindMethod(PkgSourceListMethods,Self,Name); +} +PyTypeObject PkgSourceListType = +{ + PyObject_HEAD_INIT(&PyType_Type) + 0, // ob_size + "pkgSourceList", // tp_name + sizeof(CppOwnedPyObject<PkgSourceListStruct>), // tp_basicsize + 0, // tp_itemsize + // Methods + CppOwnedDealloc<PkgSourceListStruct>, // tp_dealloc + 0, // tp_print + PkgSourceListAttr, // 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 +}; + +PyObject *GetPkgSourceList(PyObject *Self,PyObject *Args) +{ + PyObject *Owner; +// if (PyArg_ParseTuple(Args,"O!",&PkgCacheType,&Owner) == 0) +// return 0; + + return HandleErrors(CppOwnedPyObject_NEW<PkgSourceListStruct>(Owner, + &PkgSourceListType)); +} + |
