diff options
| author | Julian Andres Klode <jak@debian.org> | 2010-01-15 15:22:12 +0100 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2010-01-15 15:22:12 +0100 |
| commit | 7bfefb84523645fe24d0e5603d56c23cf410328e (patch) | |
| tree | 3965ce6e2e968a2facd5efa2e3ea4fb34c4140ff /doc/source/tutorials/apt-get.rst | |
| parent | 71aad7e28bbaf1ee8efdad77ebfb4e4c0fd0ec26 (diff) | |
| parent | 52cca77b8179a7f625673f19cb132686c0d416c9 (diff) | |
| download | python-apt-7bfefb84523645fe24d0e5603d56c23cf410328e.tar.gz | |
Merge debian-experimental.
Diffstat (limited to 'doc/source/tutorials/apt-get.rst')
| -rw-r--r-- | doc/source/tutorials/apt-get.rst | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/doc/source/tutorials/apt-get.rst b/doc/source/tutorials/apt-get.rst new file mode 100644 index 00000000..575f0c46 --- /dev/null +++ b/doc/source/tutorials/apt-get.rst @@ -0,0 +1,45 @@ +Doing stuff :command:`apt-get` does +=================================== +:Author: Julian Andres Klode <jak@debian.org> +:Release: |release| +:Date: |today| + +The following article will show how you can use python-apt to do actions done +by the :command:`apt-get` command. + + +Printing the URIs of all index files +------------------------------------ +We all now that we can print the URIs of all our index files by running a +simple ``apt-get -s --print-uris update``. We can do the same. Responsible for +the source entries is the class :class:`apt_pkg.SourceList`, which can be +combined with an :class:`apt_pkg.Acquire` object using :meth:`get_indexes`. + +First of all, we have to create the objects:: + + acquire = apt_pkg.Acquire() + slist = apt_pkg.SourceList() + +Now we have to parse /etc/apt/sources.list and its friends, by using +:meth:`apt_pkg.SourceList.read_main_list`:: + slist.read_main_list() + +Now the **slist** object knows about the location of the indexes. We now have +to load those indexes into the *acquire* object by calling +:meth:`apt_pkg.SourceList.get_indexes`:: + + slist.get_indexes(acquire, True) + +The first argument is the acquire object into which we will load these indexes, +and the second argument means that we want to fetch all indexes. Now the only +thing left to do is iterating over the list of items and printing out their +URIs. Luckily, there is :attr:`apt_pkg.Acquire.items` which allows us to +iterate over the items:: + + for item in acquire.items: + print item.desc_uri + +In the end a program could look like this: + +.. literalinclude:: ../examples/update-print-uris.py + |
