Functionality related to packages.
Representation of a package in a cache.
This class provides methods and properties for working with a package. It lets you mark the package for installation, check if it is installed, and much more.
Note
Several methods have been deprecated in version 0.7.9 of python-apt, please see the Version class for the new alternatives.
Return the Architecture of the package.
Changed in version 0.7.100.3: This is now the package’s architecture in the multi-arch sense, previously it was the architecture of the candidate version and deprecated.
Return the candidate version of the package.
This property is writeable to allow you to set the candidate version of the package. Just assign a Version() object, and it will be set as the candidate version.
Commit the changes.
The parameter fprogress refers to a apt_pkg.AcquireProgress() object, like apt.progress.text.AcquireProgress().
The parameter iprogress refers to an InstallProgress() object, as found in apt.progress.base.
Return True if the package is an essential part of the system.
Return the name of the package, including architecture.
New in version 0.7.100.3.
Download the changelog of the package and return it as unicode string.
The parameter uri refers to the uri of the changelog file. It may contain multiple named variables which will be substitued. These variables are (src_section, prefix, src_pkg, src_ver). An example is the Ubuntu changelog:
"http://changelogs.ubuntu.com/changelogs/pool" \
"/%(src_section)s/%(prefix)s/%(src_pkg)s" \
"/%(src_pkg)s_%(src_ver)s/changelog"
The parameter cancel_lock refers to an instance of threading.Lock, which if set, prevents the download.
Checks whether the package is is the config-files state.
Return a uniq ID for the package.
This can be used eg. to store additional information about the pkg.
Return the currently installed version of the package.
New in version 0.7.9.
Return a list of files installed by the package.
Return a list of unicode names of the files which have been installed by this package
Return whether the package is marked as automatically installed.
Return True if the package is no longer required.
If the package has been installed automatically as a dependency of another package, and if no packages depend on it anymore, the package is no longer required.
Return True if the to-be-installed package is broken.
Return True if the package is installed.
Return True if the installed package is broken.
Return True if the package is upgradable.
Mark a package as automatically installed.
Call this function to mark a package as automatically installed. If the optional parameter auto is set to False, the package will not be marked as automatically installed anymore. The default is True.
Mark a package for deletion.
If auto_fix is True, the resolver will be run, trying to fix broken packages. This is the default.
If purge is True, remove the configuration files of the package as well. The default is to keep the configuration.
Mark a package for install.
If autoFix is True, the resolver will be run, trying to fix broken packages. This is the default.
If autoInst is True, the dependencies of the packages will be installed automatically. This is the default.
If fromUser is True, this package will not be marked as automatically installed. This is the default. Set it to False if you want to be able to automatically remove the package at a later stage when no other package depends on it.
Mark a package for keep.
Mark a package for upgrade.
Return True if the package is marked for delete.
Package is marked for downgrade
Return True if the package is marked for install.
Return True if the package is marked for keep.
Return True if the package is marked for reinstall.
Return True if the package is marked for upgrade.
Return the name of the package, possibly including architecture.
If the package is not part of the system’s preferred architecture, return the same as fullname, otherwise return the same as shortname
Changed in version 0.7.100.3.
As part of multi-arch, this field now may include architecture information.
Return the section of the package.
Return the name of the package, without architecture.
New in version 0.7.100.3.
Return a VersionList() object for all available versions.
New in version 0.7.9.
Representation of a package version.
The Version class contains all information related to a specific package version.
New in version 0.7.9.
Return the architecture of the package version.
Return the dependencies of the package version.
Return the formatted long description.
Return the formatted long description according to the Debian policy (Chapter 5.6.13). See http://www.debian.org/doc/debian-policy/ch-controlfields.html for more information.
Return whether the version of the package is downloadable.
Return the list of enhances for the package version.
Fetch the binary version of the package.
The parameter destdir specifies the directory where the package will be fetched to.
The parameter progress may refer to an apt_pkg.AcquireProgress() object. If not specified or None, apt.progress.text.AcquireProgress() is used.
New in version 0.7.10.
Get the source code of a package.
The parameter destdir specifies the directory where the source will be fetched to.
The parameter progress may refer to an apt_pkg.AcquireProgress() object. If not specified or None, apt.progress.text.AcquireProgress() is used.
The parameter unpack describes whether the source should be unpacked (True) or not (False). By default, it is unpacked.
If unpack is True, the path to the extracted directory is returned. Otherwise, the path to the .dsc file is returned.
Return the path to the file inside the archive.
New in version 0.7.10.
Return a list of Dependency objects for the given types.
Return the homepage for the package.
Return the size of the package when installed.
Return the md5sum of the binary.
New in version 0.7.10.
Return a list of origins for the package version.
Return the internal policy priority as a number. See apt_preferences(5) for more information about what it means.
Return the priority of the package, as string.
Return a list of names that this version provides.
return the long description (raw).
Return the recommends of the package version.
Return a Record() object for this version.
Return a Record() object for this version which provides access to the raw attributes of the candidate version
Return the section of the package.
Return the sha1sum of the binary.
New in version 0.7.10.
Return the sha256sum of the binary.
New in version 0.7.10.
Return the size of the package.
Return the name of the source package.
Return the version of the source package.
Return the suggests of the package version.
Return the short description (one line summary).
Get the tasks of the package.
A set of the names of the tasks this package belongs to.
New in version 0.8.0.
Return a single URI for the binary.
New in version 0.7.10.
Return a list of all available uris for the binary.
New in version 0.7.10.
Return the version as a string.
A single dependency.
The name of the target package.
Whether this is a PreDepends.
Type of the dependency.
This should be one of ‘Breaks’, ‘Conflicts’, ‘Depends’, ‘Enhances’, ‘PreDepends’, ‘Recommends’, ‘Replaces’, ‘Suggests’.
Additional types might be added in the future.
The relation (<, <=, !=, =, >=, >, ).
Note that the empty string is a valid string as well, if no version is specified.
The target version or None.
It is None if and only if relation is the empty string.
The dependency class represents a Or-Group of dependencies. It provides an attribute to access the BaseDependency object for the available choices.
A list of BaseDependency objects which could satisfy the requirement of the Or-Group.
The Origin class provides access to the origin of the package. It allows you to check the component, archive, the hostname, and even if this package can be trusted.
The archive (eg. unstable)
The component (eg. main)
The Label, as set in the Release file
The Origin, as set in the Release file
The hostname of the site.
Boolean value whether this is trustworthy. An origin can be trusted, if it provides a GPG-signed Release file and the GPG-key used is in the keyring used by apt (see apt-key).
Record in a Packages file
Represent a record as stored in a Packages file. You can use this like a dictionary mapping the field names of the record to their values:
>>> record = Record("Package: python-apt\nVersion: 0.8.0\n\n")
>>> record["Package"]
'python-apt'
>>> record["Version"]
'0.8.0'
For example, to get the tasks of a package from a cache, you could do:
package.candidate.record["Tasks"].split()
Of course, you can also use the Version.tasks property.
Note
Changed in version 0.7.100: This class is a subclass of collections.Mapping when used in Python 2.6 or newer.
Return the value of the field with the name name.
Return whether a field name exists in record.
The number of fields in the record
Display the record as a string
Return record[key] if key in record, else default.
The parameter default must be either a string or None.
deprecated form of key in x.
An iterator over the (key, value) items of the record.
import apt
cache = apt.Cache()
pkg = cache['python-apt'] # Access the Package object for python-apt
print 'python-apt is trusted:', pkg.candidate.origins[0].trusted
# Mark python-apt for install
pkg.mark_install()
print 'python-apt is marked for install:', pkg.marked_install
print 'python-apt is (summary):', pkg.candidate.summary
# Now, really install it
cache.commit()