diff options
Diffstat (limited to 'python/apt_instmodule.cc')
| -rw-r--r-- | python/apt_instmodule.cc | 79 |
1 files changed, 65 insertions, 14 deletions
diff --git a/python/apt_instmodule.cc b/python/apt_instmodule.cc index 48868d86..2721509e 100644 --- a/python/apt_instmodule.cc +++ b/python/apt_instmodule.cc @@ -23,26 +23,31 @@ #include <Python.h> /*}}}*/ +#ifdef COMPAT_0_7 + // debExtractControl - Exctract an arbitary control member /*{{{*/ // --------------------------------------------------------------------- /* This is a common operation so this function will stay, but others that expose the full range of the apt-inst .deb processing will join it some day. */ static char *doc_debExtractControl = -"debExtractControl(File[,Member]) -> String\n" +"deb_extract_control(file[,member]) -> String\n" "Returns the indicated file from the control tar. The default is 'control'\n"; static PyObject *debExtractControl(PyObject *Self,PyObject *Args) { char *Member = "control"; PyObject *File; - if (PyArg_ParseTuple(Args,"O!|s",&PyFile_Type,&File,&Member) == 0) + if (PyArg_ParseTuple(Args,"O|s",&File,&Member) == 0) return 0; // Subscope makes sure any clean up errors are properly handled. PyObject *Res = 0; { // Open the file and associate the .deb - FileFd Fd(fileno(PyFile_AsFile(File)),false); + int fileno = PyObject_AsFileDescriptor(File); + if (fileno == -1) + return 0; + FileFd Fd(fileno,false); debDebFile Deb(Fd); if (_error->PendingError() == true) return HandleErrors(); @@ -69,14 +74,14 @@ static PyObject *debExtractControl(PyObject *Self,PyObject *Args) // debExtractArchive - Exctract the archive /*{{{*/ // --------------------------------------------------------------------- static char *doc_debExtractArchive = -"debExtractArchve(File,rootdir) -> Bool\n" +"deb_extract_archive(File,rootdir) -> Bool\n" "Extracts the Archive into the given root dir"; static PyObject *debExtractArchive(PyObject *Self,PyObject *Args) { char *Rootdir = NULL; char cwd[512]; PyObject *File; - if (PyArg_ParseTuple(Args,"O!|s",&PyFile_Type,&File,&Rootdir) == 0) + if (PyArg_ParseTuple(Args,"O|s",&File,&Rootdir) == 0) return 0; // Subscope makes sure any clean up errors are properly handled. @@ -89,7 +94,10 @@ static PyObject *debExtractArchive(PyObject *Self,PyObject *Args) } // Open the file and associate the .deb - FileFd Fd(fileno(PyFile_AsFile(File)),false); + int fileno = PyObject_AsFileDescriptor(File); + if (fileno == -1) + return 0; + FileFd Fd(fileno,false); debDebFile Deb(Fd); if (_error->PendingError() == true) { if (Rootdir != NULL) @@ -112,17 +120,20 @@ static PyObject *debExtractArchive(PyObject *Self,PyObject *Args) // arFindMember - Find member in AR archive /*{{{*/ // --------------------------------------------------------------------- static char *doc_arCheckMember = -"arCheckMember(File, membername) -> Bool\n"; +"ar_check_member(file, membername) -> Bool\n"; static PyObject *arCheckMember(PyObject *Self,PyObject *Args) { char *Member = NULL; bool res = false; PyObject *File; - if (PyArg_ParseTuple(Args,"O!s",&PyFile_Type,&File,&Member) == 0) + if (PyArg_ParseTuple(Args,"Os",&File,&Member) == 0) return 0; // Open the file and associate the .deb - FileFd Fd(fileno(PyFile_AsFile(File)),false); + int fileno = PyObject_AsFileDescriptor(File); + if (fileno == -1) + return 0; + FileFd Fd(fileno,false); ARArchive AR(Fd); if (_error->PendingError() == true) return HandleErrors(Py_BuildValue("b",res)); @@ -145,16 +156,56 @@ static PyMethodDef methods[] = // access to deb files {"debExtractControl",debExtractControl,METH_VARARGS,doc_debExtractControl}, {"debExtractArchive",debExtractArchive,METH_VARARGS,doc_debExtractArchive}, - + // access to tar streams {"tarExtract",tarExtract,METH_VARARGS,doc_tarExtract}, {"debExtract",debExtract,METH_VARARGS,doc_debExtract}, - {} }; - +#else +static PyMethodDef *methods = 0; +#endif // defined(COMPAT_0_7) + + +static const char *apt_inst_doc = + "Functions for working with AR,tar archives and .deb packages.\n\n" + "This module provides useful classes and functions to work with\n" + "archives, modelled after the 'TarFile' class in the 'tarfile' module."; +#define ADDTYPE(mod,name,type) { \ + if (PyType_Ready(type) == -1) RETURN(0); \ + Py_INCREF(type); \ + PyModule_AddObject(mod,name,(PyObject *)type); } + + +#if PY_MAJOR_VERSION >= 3 +static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, + "apt_inst", + apt_inst_doc, + -1, + methods, + 0, + 0, + 0, + 0 +}; +#define RETURN(x) return x +extern "C" PyObject * PyInit_apt_inst() +#else extern "C" void initapt_inst() +#define RETURN(x) +#endif { - Py_InitModule("apt_inst",methods); +#if PY_MAJOR_VERSION >= 3 + PyObject *module = PyModule_Create(&moduledef); +#else + PyObject *module = Py_InitModule3("apt_inst",methods, apt_inst_doc); +#endif + + ADDTYPE(module,"ArMember",&PyArMember_Type); + ADDTYPE(module,"ArArchive",&PyArArchive_Type); + ADDTYPE(module,"DebFile",&PyDebFile_Type); + ADDTYPE(module,"TarFile",&PyTarFile_Type); + ADDTYPE(module,"TarMember",&PyTarMember_Type); + RETURN(module); } - /*}}}*/ |
