apt.package — Classes for package handling

Functionality related to packages.

The Package class

class apt.package.Package(pcache, pkgiter)

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.

architecture
Deprecated:Return the Architecture of the package
candidateDependencies
Deprecated:Return a list of candidate dependencies.
candidateDownloadable
Deprecated:Return True if the candidate is downloadable.
candidateInstalledSize
Deprecated:Return the size of the candidate installed package.
candidateOrigin
Deprecated:Return a list of Origin() objects for the candidate version.
candidateRecord
Deprecated:Return the Record of the candidate version of the package.
candidateVersion
Deprecated:Return the candidate version as string.
commit(fprogress, iprogress)

Commit the changes.

The parameter fprogress refers to a FetchProgress() object, as found in apt.progress.

The parameter iprogress refers to an InstallProgress() object, as found in apt.progress.

description
Deprecated:Return the formatted long description.

Return the formated 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.

getChangelog(uri=None, cancel_lock=None)

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.

homepage
Deprecated:Return the homepage field as string.
installedDependencies
Deprecated:Return a list of installed dependencies.
installedDownloadable
Deprecated:Return True if the installed version is downloadable.
installedPackageSize
Deprecated:Return the size of the installed deb package.
installedPriority
Deprecated:Return the priority (of the installed version).
installedRecord
Deprecated:Return the Record of the candidate version of the package.
installedSize
Deprecated:Return the size of the currently installed package.
installedVersion
Deprecated:Return the installed version as string.

Deprecated, please use installed.version instead.

markDelete(autoFix=True, purge=False)

Mark a package for install.

If autoFix 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.

markInstall(autoFix=True, autoInst=True, fromUser=True)

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 remove the package at a later stage if no other package depends on it.

markKeep()
Mark a package for keep.
markUpgrade()
Mark a package for upgrade.
packageSize
Deprecated:Return the size of the candidate deb package.
priority
Deprecated:Return the priority (of the candidate version).
rawDescription
Deprecated:return the long description (raw).
sourcePackageName
Deprecated:Return the source package name as string.
summary
Deprecated:Return the short description (one line summary).

The Version class

class apt.package.Version(package, cand)

Representation of a package version.

Since:0.7.9
fetch_source()
Get the source code of a package

Dependency Information

class apt.package.BaseDependency

The BaseDependency class defines various attributes for accessing the parts of a dependency. The attributes are as follows:

name
The name of the dependency
relation
The relation (>>,>=,==,<<,<=,)
version
The version or None.
preDepend
Boolean value whether this is a pre-dependency.
class apt.package.Dependency

The dependency class represents a Or-Group of dependencies. It provides an attribute to access the BaseDependency object for the available choices.

or_dependencies
A list of BaseDependency objects which could satisfy the requirement of the Or-Group.

Origin Information

class apt.package.Origin

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.

archive
The archive (eg. unstable)
component
The component (eg. main)
label
The Label, as set in the Release file
origin
The Origin, as set in the Release file
site
The hostname of the site.
trusted
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).

Examples

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.markInstall()

print 'python-apt is marked for install:', pkg.markedInstall

print 'python-apt is (summary):', pkg.candidate.summary

# Now, really install it
cache.commit()