File size: 2,012 Bytes
859a779 |
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 |
:mod:`apt.cache` --- The Cache class
=====================================
.. automodule:: apt.cache
The Cache class
---------------
.. autoclass:: Cache
:members:
:undoc-members:
.. describe:: cache[pkgname]
Return a :class:`Package()` for the package with the name *pkgname*.
Example
^^^^^^^
The following example shows how to load the cache, update it, and upgrade
all the packages on the system::
import apt
import apt.progress
# First of all, open the cache
cache = apt.Cache()
# Now, lets update the package list
cache.update()
# We need to re-open the cache because it needs to read the package list
cache.open(None)
# Now we can do the same as 'apt-get upgrade' does
cache.upgrade()
# or we can play 'apt-get dist-upgrade'
cache.upgrade(True)
# Q: Why does nothing happen?
# A: You forgot to call commit()!
cache.commit(apt.progress.TextFetchProgress(),
apt.progress.InstallProgress())
Working with Filters
--------------------
.. autoclass:: Filter
:members:
:inherited-members:
:undoc-members:
.. autoclass:: MarkedChangesFilter
:members:
:inherited-members:
:undoc-members:
.. autoclass:: FilteredCache
:members:
:inherited-members:
:undoc-members:
Example
^^^^^^^
This is an example for a filtered cache, which only allows access to the
packages whose state has been changed, eg. packages marked for installation::
>>> from apt.cache import FilteredCache, Cache, MarkedChangesFilter
>>> cache = apt.Cache()
>>> changed = apt.FilteredCache(cache)
>>> changed.set_filter(MarkedChangesFilter())
>>> print(len(changed) == len(cache.get_changes())) # Both need to have same length
True
The ProblemResolver class
--------------------------
.. autoclass:: ProblemResolver
:members:
Exceptions
----------
.. autoexception:: FetchCancelledException
.. autoexception:: FetchFailedException
.. autoexception:: LockFailedException
|