Dictionary-like package cache.
This class has all the packages that are available in it’s dictionary.
Keyword arguments: progress – a OpProgress object rootdir – a alternative root directory. if that is given
the system sources.list and system lists/ files are not read, only files relative to the given rootdir
memonly – build the cache in memory only
Return an ActionGroup() object for the current cache.
Action groups can be used to speedup actions. The action group is active as soon as it is created, and disabled when the object is deleted or when release() is called.
You can use the action group as a context manager, this is the recommended way:
with cache.actiongroup():
for package in my_selected_packages:
package.mark_install()
This way, the ActionGroup is automatically released as soon as the with statement block is left. It also has the benefit of making it clear which parts of the code run with a action group and which don’t.
Apply the marked changes to the cache.
The first parameter, fetch_progress, refers to a FetchProgress() object as found in apt.progress, the default being apt.progress.FetchProgress().
The second parameter, install_progress, is a apt.progress.InstallProgress() object.
Return True if the dpkg was interrupted
All dpkg operations will fail until this is fixed, the action to fix the system if dpkg got interrupted is to run ‘dpkg –configure -a’ as root.
Return a list of all packages providing a package.
Return a list of packages which provide the virtual package of the specified name.
If ‘candidate_only’ is False, return all packages with at least one version providing the virtual package. Otherwise, return only those packages where the candidate version provides the virtual package.
If ‘include_nonvirtual’ is True then it will search for all packages providing pkgname, even if pkgname is not itself a virtual pkg.
The first parameter pm refers to an object returned by apt_pkg.PackageManager().
The second parameter install_progress refers to an InstallProgress() object of the module apt.progress.
Run the equivalent of apt-get update.
The first parameter fetch_progress may be set to an instance of apt.progress.FetchProgress, the default is apt.progress.FetchProgress() .
Upgrade all packages.
If the parameter dist_upgrade is True, new dependencies will be installed as well (and conflicting packages may be removed). The default value is False.
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())
Filter base class
A package cache that is filtered.
Can work on a existing cache or create a new one
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
Resolve problems due to dependencies and conflicts.
The first argument ‘cache’ is an instance of apt.Cache.