Commit 6bf525e7 authored by Julian Andres Klode's avatar Julian Andres Klode

apt_inst: Do not mention deprecated functions, except for porting

This should still help people port over code, if they are looking
at some old code. The old API was so vastly different that I like
to keep this, there's no harm in doing so.

Closes: #807103
parent 6409c882
......@@ -10,9 +10,15 @@ import time
import apt_inst
def format_mode(what, mode):
def format_mode(member):
"""Return the symbolic mode"""
s_mode = dict(DIR="d", HARDLINK="h", FILE="-").get(what)
mode = member.mode
if member.isdir():
s_mode = "d"
elif member.islnk():
s_mode = "h"
else:
s_mode = "-"
s_mode += ((mode & stat.S_IRUSR) and "r" or "-")
s_mode += ((mode & stat.S_IWUSR) and "w" or "-")
s_mode += ((mode & stat.S_IXUSR) and
......@@ -29,14 +35,16 @@ def format_mode(what, mode):
return s_mode
def callback(what, name, link, mode, uid, gid, size, mtime, major, minor):
def callback(member, data):
"""callback for deb_extract"""
s_mode = format_mode(what, mode)
s_owner = "%s/%s" % (pwd.getpwuid(uid)[0], grp.getgrgid(gid)[0])
s_size = "%9d" % size
s_time = time.strftime("%Y-%m-%d %H:%M", time.localtime(mtime))
s_name = name.startswith(".") and name or ("./" + name)
if link:
s_mode = format_mode(member)
s_owner = "%s/%s" % (pwd.getpwuid(member.uid)[0],
grp.getgrgid(member.gid)[0])
s_size = "%9d" % member.size
s_time = time.strftime("%Y-%m-%d %H:%M", time.localtime(member.mtime))
s_name = (member.name if member.name.startswith(".")
else ("./" + member.name))
if member.islnk():
s_name += " link to %s" % link
print s_mode, s_owner, s_size, s_time, s_name
......@@ -49,7 +57,7 @@ def main():
fobj = open(sys.argv[1])
try:
apt_inst.deb_extract(fobj, callback, "data.tar.gz")
apt_inst.DebFile(fobj).data.go(callback)
finally:
fobj.close()
......
......@@ -17,7 +17,7 @@ def main():
fobj = open(sys.argv[1])
try:
apt_inst.deb_extract_archive(fobj, sys.argv[2])
apt_inst.DebFile(fobj).data.extractall(sys.argv[2])
finally:
fobj.close()
......
......@@ -259,40 +259,23 @@ Tar Archives
Deprecated functions
Removed functions
---------------------
The following functions have been shipped in python-apt for a longer time and
are deprecated as of release 0.7.92. They are listed here to help developers
to port their applications to the new API which is completely different. For
this purpose each function documentation includes an example showing how the
function can be replaced.
The following functions have been removed in python-apt 0.8.
They are listed here to help developers port their applications to the new
API which is completely different. For this purpose each function documentation
includes an example showing how the function can be replaced.
.. function:: arCheckMember(file, membername)
Check if the member specified by the parameter *membername* exists in
the AR file referenced by the parameter *file*, which may be a
:class:`file()` object, a file descriptor, or anything implementing a
:meth:`fileno` method.
This function has been replaced by using the :keyword:`in` check on an
:class:`ArArchive` object::
member in ArArchive(file)
member in ArArchive(file)
.. function:: debExtract(file, func, chunk)
Call the function referenced by *func* for each member of the tar file
*chunk* which is contained in the AR file referenced by the parameter
*file*, which may be a :class:`file()` object, a file descriptor, or
anything implementing a :meth:`fileno` method.
The function *func* is a callback with the signature
``(what, name, link, mode, uid, gid, size, mtime, major, minor)``. The
parameter *what* describes the type of the member. It can be 'FILE',
'DIR', or 'HARDLINK'. The parameter *name* refers to the name of the
member. In case of links, *link* refers to the target of the link.
This function is deprecated and has been replaced by the :meth:`TarFile.go`
This function has been replaced by the :meth:`TarFile.go`
method. The following example shows the old code and the new code::
debExtract(open("package.deb"), my_callback, "data.tar.gz") #old
......@@ -304,36 +287,18 @@ function can be replaced.
.. function:: tarExtract(file,func,comp)
Call the function *func* for each member of the tar file *file*.
The parameter *comp* is a string determining the compressor used. Possible
options are "xz", "lzma", "bzip2" and "gzip". The parameter *file* may be
a :class:`file()` object, a file descriptor, or anything implementing
a :meth:`fileno` method.
The function *func* is a callback with the signature
``(what, name, link, mode, uid, gid, size, mtime, major, minor)``. The
parameter *what* describes the type of the member. It can be 'FILE',
'DIR', or 'HARDLINK'. The parameter *name* refers to the name of the
member. In case of links, *link* refers to the target of the link.
This function is deprecated and has been replaced by the :meth:`TarFile.go`
This function has been replaced by the :meth:`TarFile.go`
method. The following example shows the old code and the new code::
tarExtract(open("archive.tar.gz"), my_callback, "gzip") #old
TarFile("archive.tar.gz", 0, 0, "gzip").go(my_callback)
Please note that the signature of the callback is different in
:meth:`TarFile.go`.
:meth:`TarFile.go`, it now expects a :class:`TarMember` and a bytestring
of the data.
.. function:: debExtractArchive(file, rootdir)
Extract the archive referenced by the :class:`file` object *file*
into the directory specified by *rootdir*.
The parameter *file* may be a :class:`file()` object, a file descriptor, or
anything implementing a :meth:`fileno` method.
This function has been replaced by :meth:`TarFile.extractall` and
:attr:`DebFile.data`::
......@@ -342,10 +307,6 @@ function can be replaced.
.. function:: debExtractControl(file[, member='control'])
Return the indicated file as a string from the control tar. The default
is 'control'. The parameter *file* may be a :class:`file()` object, a
file descriptor, or anything implementing a :meth:`fileno` method.
This function has been replaced by :attr:`DebFile.control` and
:meth:`TarFile.extractdata`. In the following example, both commands
return the contents of the control file::
......
#!/usr/bin/python
import sys
import apt_inst
def Callback(What, name, Link, Mode, UID, GID, size, MTime, Major, Minor):
print "%s '%s','%s',%u,%u,%u,%u,%u,%u,%u" % (
What, name, Link, Mode, UID, GID, size, MTime, Major, Minor)
def main():
member = "data.tar.lzma"
if len(sys.argv) > 2:
member = sys.argv[2]
apt_inst.debExtract(open(sys.argv[1]), Callback, member)
main()
#!/usr/bin/python
import apt
import apt_inst
import os
import sys
print os.getcwd()
apt_inst.debExtractArchive(open(sys.argv[1]), "/tmp/")
print os.getcwd()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment