1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
:mod:`apt_inst` - Working with local Debian packages
====================================================
.. module:: apt_inst
The :mod:`apt_inst` extension provides access to functions for working with
locally available Debian packages (.deb files) and tar files.
Checking packages
------------------
.. 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.
.. versionchanged:: 0.7.11
Added support for file descriptors and objects implementing a :meth:`fileno` method.
Listing contents
-----------------
.. 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.
An example would be::
debExtract(open("package.deb"), my_callback, "data.tar.gz")
See :ref:`emulating-dpkg-contents` for a more detailed example.
.. versionchanged:: 0.7.11
Added support for file descriptors and objects implementing a :meth:`fileno` method.
.. 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 "lzma", "bzip2" and "gzip".
The parameter *file* may be a :class:`file()` object, a file descriptor, or
anything implementing a :meth:`fileno` method.
.. versionchanged:: 0.7.11
Added support for file descriptors and objects implementing a :meth:`fileno` method.
Callback
^^^^^^^^^
Both of these functions expect 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.
Extracting contents
-------------------
.. 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.
See :ref:`emulating-dpkg-extract` for an example.
.. warning::
If the directory given by *rootdir* does not exist, the package is
extracted into the current directory.
.. versionchanged:: 0.7.11
Added support for file descriptors and objects implementing a :meth:`fileno` method.
.. 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.
If you want to print the control file of a given package, you could do
something like::
print debExtractControl(open("package.deb"))
.. versionchanged:: 0.7.11
Added support for file descriptors and objects implementing a :meth:`fileno` method.
.. _emulating-dpkg-extract:
Example: Emulating :program:`dpkg` :option:`--extract`
-------------------------------------------------------
Here is a code snippet which emulates dpkg -x. It can be run as
:program:`tool` :option:`pkg.deb` :option:`outdir`.
.. literalinclude:: examples/dpkg-extract.py
.. _emulating-dpkg-contents:
Example: Emulating :program:`dpkg` :option:`--contents`
-------------------------------------------------------
.. literalinclude:: examples/dpkg-contents.py
Example: Emulating :program:`dpkg` :option:`--info`
----------------------------------------------------
.. literalinclude:: examples/dpkg-info.py
|