diff options
| author | Michael Vogt <michael.vogt@ubuntu.com> | 2005-11-21 10:33:10 +0000 |
|---|---|---|
| committer | Michael Vogt <michael.vogt@ubuntu.com> | 2005-11-21 10:33:10 +0000 |
| commit | a9d234dfe2ab0358d3e61a53645e4ee1d83e53cb (patch) | |
| tree | 9b66689add80af09a4b328a4b7891fb7841b82b8 | |
| parent | 2fa652df49918cbfd8def4868b327bab3b30feb9 (diff) | |
| download | python-apt-a9d234dfe2ab0358d3e61a53645e4ee1d83e53cb.tar.gz | |
* apt_inst.debExtractArchive() added
| -rw-r--r-- | apt/progress.py | 2 | ||||
| -rwxr-xr-x | doc/examples/deb_inspect.py | 12 | ||||
| -rw-r--r-- | python/apt_instmodule.cc | 38 |
3 files changed, 49 insertions, 3 deletions
diff --git a/apt/progress.py b/apt/progress.py index de675587..6b4a10e3 100644 --- a/apt/progress.py +++ b/apt/progress.py @@ -19,7 +19,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA -import sys +import sys, apt_pkg class OpProgress: """ Abstract class to implement reporting on cache opening diff --git a/doc/examples/deb_inspect.py b/doc/examples/deb_inspect.py index 4173c196..0befd2bb 100755 --- a/doc/examples/deb_inspect.py +++ b/doc/examples/deb_inspect.py @@ -4,6 +4,7 @@ import apt_pkg import apt_inst import sys +import os.path def Callback(What,Name,Link,Mode,UID,GID,Size,MTime,Major,Minor): """ callback for debExtract """ @@ -35,5 +36,12 @@ if __name__ == "__main__": print apt_pkg.ParseDepends(depends) - - + print "extracting archive" + dir = "/tmp/deb" + os.mkdir(dir) + apt_inst.debExtractArchive(open(file),dir) + def visit(arg, dirname, names): + print "%s/" % dirname + for file in names: + print "\t%s" % file + os.path.walk(dir, visit, None) diff --git a/python/apt_instmodule.cc b/python/apt_instmodule.cc index 96bd029b..d672a40a 100644 --- a/python/apt_instmodule.cc +++ b/python/apt_instmodule.cc @@ -66,6 +66,43 @@ static PyObject *debExtractControl(PyObject *Self,PyObject *Args) } /*}}}*/ +// debExtractArchive - Exctract the archive /*{{{*/ +// --------------------------------------------------------------------- +static char *doc_debExtractArchive = +"debExtractArchve(File,rootdir) -> Bool\n" +"Extracts the Archive into the given root dir"; +static PyObject *debExtractArchive(PyObject *Self,PyObject *Args) +{ + char *Rootdir = NULL; + PyObject *File; + if (PyArg_ParseTuple(Args,"O!|s",&PyFile_Type,&File,&Rootdir) == 0) + return 0; + + // Subscope makes sure any clean up errors are properly handled. + bool res = false; + { + if(Rootdir != NULL) + { + chdir(Rootdir); + } + + // Open the file and associate the .deb + FileFd Fd(fileno(PyFile_AsFile(File)),false); + debDebFile Deb(Fd); + if (_error->PendingError() == true) + return HandleErrors(); + + // extracts relative to the current dir + pkgDirStream Extract; + res = Deb.ExtractArchive(Extract); + + if (res == false) + return HandleErrors(); + } + return HandleErrors(Py_BuildValue("b",res)); +} + /*}}}*/ + // initapt_inst - Core Module Initialization /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -73,6 +110,7 @@ static PyMethodDef methods[] = { // Stuff {"debExtractControl",debExtractControl,METH_VARARGS,doc_debExtractControl}, + {"debExtractArchive",debExtractArchive,METH_VARARGS,doc_debExtractArchive}, {"tarExtract",tarExtract,METH_VARARGS,doc_tarExtract}, {"debExtract",debExtract,METH_VARARGS,doc_debExtract}, |
