summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArch Librarian <arch@canonical.com>2004-11-24 10:00:21 +0000
committerArch Librarian <arch@canonical.com>2004-11-24 10:00:21 +0000
commit051ebe1ac22fdbf427abc4fd9ee5cc8279649b07 (patch)
tree30e49d1a91b67fee9992b236b962e5347ce4c62a
parent043b67f398897f7689006162b7702974c1fabb8a (diff)
downloadpython-apt-051ebe1ac22fdbf427abc4fd9ee5cc8279649b07.tar.gz
Tar examining support
Author: jgg Date: 2001-09-30 03:52:58 GMT Tar examining support
-rw-r--r--python/apt_instmodule.cc9
-rw-r--r--python/apt_instmodule.h20
-rw-r--r--python/makefile2
-rw-r--r--python/tar.cc165
4 files changed, 192 insertions, 4 deletions
diff --git a/python/apt_instmodule.cc b/python/apt_instmodule.cc
index 519d4730..2eea4e77 100644
--- a/python/apt_instmodule.cc
+++ b/python/apt_instmodule.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: apt_instmodule.cc,v 1.1 2001/02/20 06:32:01 jgg Exp $
+// $Id: apt_instmodule.cc,v 1.2 2001/09/30 03:52:58 jgg Exp $
/* ######################################################################
apt_intmodule - Top level for the python module. Create the internal
@@ -12,11 +12,12 @@
##################################################################### */
/*}}}*/
// Include Files /*{{{*/
+#include "apt_instmodule.h"
#include "generic.h"
#include <apt-pkg/debfile.h>
#include <apt-pkg/error.h>
-
+
#include <sys/stat.h>
#include <unistd.h>
#include <python/Python.h>
@@ -72,7 +73,9 @@ static PyMethodDef methods[] =
{
// Stuff
{"debExtractControl",debExtractControl,METH_VARARGS,doc_debExtractControl},
-
+ {"tarExtract",tarExtract,METH_VARARGS,doc_tarExtract},
+ {"debExtract",debExtract,METH_VARARGS,doc_debExtract},
+
{}
};
diff --git a/python/apt_instmodule.h b/python/apt_instmodule.h
new file mode 100644
index 00000000..478b9e2b
--- /dev/null
+++ b/python/apt_instmodule.h
@@ -0,0 +1,20 @@
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+// $Id: apt_instmodule.h,v 1.1 2001/09/30 03:52:58 jgg Exp $
+/* ######################################################################
+
+ Prototypes for the module
+
+ ##################################################################### */
+ /*}}}*/
+#ifndef APT_INSTMODULE_H
+#define APT_INSTMODULE_H
+
+#include <python/Python.h>
+
+PyObject *debExtract(PyObject *Self,PyObject *Args);
+extern char *doc_debExtract;
+PyObject *tarExtract(PyObject *Self,PyObject *Args);
+extern char *doc_tarExtract;
+
+#endif
diff --git a/python/makefile b/python/makefile
index f8639c93..abe08d50 100644
--- a/python/makefile
+++ b/python/makefile
@@ -17,5 +17,5 @@ include $(PYTHON_H)
MODULE=apt_inst
SLIBS = -lapt-inst -lapt-pkg
LIB_MAKES = apt-inst/makefile
-SOURCE = apt_instmodule.cc generic.cc
+SOURCE = apt_instmodule.cc tar.cc generic.cc
include $(PYTHON_H)
diff --git a/python/tar.cc b/python/tar.cc
new file mode 100644
index 00000000..09f6b680
--- /dev/null
+++ b/python/tar.cc
@@ -0,0 +1,165 @@
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+// $Id: tar.cc,v 1.1 2001/09/30 03:52:58 jgg Exp $
+/* ######################################################################
+
+ Tar Inteface
+
+ ##################################################################### */
+ /*}}}*/
+// Include Files /*{{{*/
+#include "generic.h"
+
+#include <apt-pkg/extracttar.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/debfile.h>
+#include "apt_instmodule.h"
+
+#include <python/Python.h>
+ /*}}}*/
+
+class ProcessTar : public pkgDirStream
+{
+ public:
+
+ PyObject *Function;
+
+ virtual bool DoItem(Item &Itm,int &Fd);
+
+ ProcessTar(PyObject *Function) : Function(Function)
+ {
+ Py_INCREF(Function);
+ }
+ virtual ~ProcessTar()
+ {
+ Py_DECREF(Function);
+ }
+};
+
+// ProcessTar::DoItem - Feed an item to a python function /*{{{*/
+// ---------------------------------------------------------------------
+/* The function is called with a tuple that has:
+ (FileName,Link,Mode,UID,GID,Size,MTime,Major,Minor) */
+bool ProcessTar::DoItem(Item &Itm,int &Fd)
+{
+ const char *Type;
+ switch (Itm.Type)
+ {
+ case Item::File:
+ Type = "FILE";
+ break;
+
+ case Item::HardLink:
+ Type = "HARDLINK";
+ break;
+
+ case Item::SymbolicLink:
+ Type = "SYMLINK";
+ break;
+
+ case Item::CharDevice:
+ Type = "CHARDEV";
+ break;
+
+ case Item::BlockDevice:
+ Type = "BLKDEV";
+ break;
+
+ case Item::Directory:
+ Type = "DIR";
+ break;
+
+ case Item::FIFO:
+ Type = "FIFO";
+ break;
+ }
+
+ if (PyObject_CallFunction(Function,"sssiiiiiii",Type,Itm.Name,
+ Itm.LinkTarget,Itm.Mode,Itm.UID,Itm.GID,Itm.Size,
+ Itm.MTime,Itm.Major,Itm.Minor) == 0)
+ return false;
+
+ Fd = -1;
+ return true;
+}
+ /*}}}*/
+
+// tarExtract - Examine files from a tar /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+char *doc_tarExtract =
+"tarExtract(File,Func,Comp) -> None"
+"The tar file referenced by the file object File, Func called for each\n"
+"Tar member. Comp must be the string \"gzip\" (gzip is automatically invoked) \n";
+PyObject *tarExtract(PyObject *Self,PyObject *Args)
+{
+ PyObject *File;
+ PyObject *Function;
+ char *Comp;
+
+ if (PyArg_ParseTuple(Args,"O!O!s",&PyFile_Type,&File,&PyFunction_Type,
+ &Function,&Comp) == 0)
+ return 0;
+
+ {
+ // Open the file and associate the tar
+ FileFd Fd(fileno(PyFile_AsFile(File)),false);
+ ExtractTar Tar(Fd,0xFFFFFFFF);
+ if (_error->PendingError() == true)
+ return HandleErrors();
+
+ ProcessTar Proc(Function);
+ if (Tar.Go(Proc) == false)
+ return HandleErrors();
+ }
+
+ Py_INCREF(Py_None);
+ return HandleErrors(Py_None);
+}
+ /*}}}*/
+
+// debExtract - Examine files from a deb /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+char *doc_debExtract =
+"debExtract(File,Func,Chunk) -> None"
+"The deb referenced by the file object File is examined. The AR member\n"
+"given by Chunk is treated as a tar.gz and fed through Func like\n"
+"tarExtract\n";
+PyObject *debExtract(PyObject *Self,PyObject *Args)
+{
+ PyObject *File;
+ PyObject *Function;
+ char *Chunk;
+
+ if (PyArg_ParseTuple(Args,"O!O!s",&PyFile_Type,&File,&PyFunction_Type,
+ &Function,&Chunk) == 0)
+ return 0;
+
+ {
+ // Open the file and associate the tar
+ // Open the file and associate the .deb
+ FileFd Fd(fileno(PyFile_AsFile(File)),false);
+ debDebFile Deb(Fd);
+ if (_error->PendingError() == true)
+ return HandleErrors();
+
+ // Get the archive member and positition the file
+ const ARArchive::Member *Member = Deb.GotoMember(Chunk);
+ if (Member == 0)
+ {
+ _error->Error("Cannot fund chunk %s",Chunk);
+ return HandleErrors();
+ }
+
+ // Extract it.
+ ExtractTar Tar(Deb.GetFile(),Member->Size);
+ ProcessTar Proc(Function);
+ if (Tar.Go(Proc) == false)
+ return HandleErrors();
+ }
+
+ Py_INCREF(Py_None);
+ return HandleErrors(Py_None);
+}
+ /*}}}*/