File: embedding.rst

package info (click to toggle)
python-apt 0.7.100.1%2Bsqueeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,748 kB
  • ctags: 1,919
  • sloc: cpp: 8,937; python: 5,750; makefile: 89; sh: 9
file content (34 lines) | stat: -rw-r--r-- 947 bytes parent folder | download | duplicates (4)
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
.. highlightlang:: c++

Embedding Python APT
====================
This is a very basic tutorial for working with the C++ bindings.

Basics
-------
To use the python-apt C++ bindings, first include the
``python-apt/python-apt.h`` header::

    #include <python-apt/python-apt.h>

Now, the module needs to be initialized. This is done by calling the function
:cfunc:`import_apt_pkg`. This function returns 0 on success and a negative
value in case of failure::

    if (import_apt_pkg() < 0)
        return;

Longer example
--------------
The following code will create a standalone application which provides a
module ``client`` with the attribute ``hash`` which stores an object of the
type :class:`apt_pkg.HashString`:

.. literalinclude:: ../../client-example.cc


.. highlightlang:: sh

If this file were called client-example.cc, you could compile it using::

    g++ -lapt-pkg -lpython2.5 -I/usr/include/python2.5 -o client client-example.cc