apt.package
— Classes for package handling¶
Functionality related to packages.
The Package class¶
-
class
apt.package.
Package
(pcache: apt.cache.Cache, pkgiter: apt_pkg.Package)¶ 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
() → str¶ Return the Architecture of the package.
Note that for Architecture: all packages, this returns the native architecture, as they are internally treated like native packages. To get the concrete architecture, look at the
Version.architecture
attribute.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.
-
property
candidate
¶ 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
(fprogress: apt.progress.base.AcquireProgress, iprogress: apt.progress.base.InstallProgress) → None¶ 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.
-
property
essential
¶ Return True if the package is an essential part of the system.
-
property
fullname
¶ Return the name of the package, including architecture.
Note that as for
architecture()
, this returns the native architecture for Architecture: all packages.New in version 0.7.100.3.
-
get_changelog
(uri: Optional[str] = None, cancel_lock: Optional[threading.Event] = None) → str¶ 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.Event, which if set, prevents the download.
-
property
has_config_files
¶ Checks whether the package is is the config-files state.
-
property
id
¶ Return a uniq ID for the package.
This can be used eg. to store additional information about the pkg.
-
property
installed
¶ Return the currently installed version of the package.
New in version 0.7.9.
-
property
installed_files
¶ 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
-
property
is_auto_installed
¶ Return whether the package is marked as automatically installed.
-
property
is_auto_removable
¶ 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.
-
property
is_inst_broken
¶ Return True if the to-be-installed package is broken.
-
property
is_installed
¶ Return
True
if the package is installed.
-
property
is_now_broken
¶ Return True if the installed package is broken.
-
property
is_upgradable
¶ Return
True
if the package is upgradable.
-
mark_auto
(auto: bool = True) → None¶ 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 isTrue
.
-
mark_delete
(auto_fix: bool = True, purge: bool = False) → None¶ 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_install
(auto_fix: bool = True, auto_inst: bool = True, from_user: bool = True) → None¶ 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.
-
property
marked_delete
¶ Return
True
if the package is marked for delete.
-
property
marked_downgrade
¶ Package is marked for downgrade
-
property
marked_install
¶ Return
True
if the package is marked for install.
-
property
marked_keep
¶ Return
True
if the package is marked for keep.
-
property
marked_reinstall
¶ Return
True
if the package is marked for reinstall.
-
property
marked_upgrade
¶ Return
True
if the package is marked for upgrade.
-
property
name
¶ 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 asshortname
Changed in version 0.7.100.3.
As part of multi-arch, this field now may include architecture information.
-
property
shortname
¶ Return the name of the package, without architecture.
New in version 0.7.100.3.
-
property
versions
¶ Return a VersionList() object for all available versions.
New in version 0.7.9.
-
The Version class¶
-
class
apt.package.
Version
(package: apt.package.Package, cand: apt_pkg.Version)¶ Representation of a package version.
The Version class contains all information related to a specific package version.
New in version 0.7.9.
-
property
architecture
¶ Return the architecture of the package version.
-
property
dependencies
¶ Return the dependencies of the package version.
-
property
description
¶ 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.
-
property
downloadable
¶ Return whether the version of the package is downloadable.
-
property
enhances
¶ Return the list of enhances for the package version.
-
fetch_binary
(destdir: str = '', progress: Optional[apt.progress.base.AcquireProgress] = None, allow_unauthenticated: Optional[bool] = None) → str¶ 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.
The keyword-only parameter allow_unauthenticated specifies whether to allow unauthenticated downloads. If not specified, it defaults to the configuration option APT::Get::AllowUnauthenticated.
New in version 0.7.10.
-
fetch_source
(destdir: str = '', progress: Optional[apt.progress.base.AcquireProgress] = None, unpack: bool = True, allow_unauthenticated: Optional[bool] = None) → str¶ 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.The keyword-only parameter allow_unauthenticated specifies whether to allow unauthenticated downloads. If not specified, it defaults to the configuration option APT::Get::AllowUnauthenticated.
-
property
filename
¶ Return the path to the file inside the archive.
New in version 0.7.10.
-
get_dependencies
(*types: str) → List[apt.package.Dependency]¶ Return a list of Dependency objects for the given types.
Multiple types can be specified. Possible types are: ‘Breaks’, ‘Conflicts’, ‘Depends’, ‘Enhances’, ‘PreDepends’, ‘Recommends’, ‘Replaces’, ‘Suggests’
Additional types might be added in the future.
-
property
homepage
¶ Return the homepage for the package.
-
property
installed_size
¶ Return the size of the package when installed.
-
property
is_installed
¶ Return wether this version of the package is currently installed.
New in version 1.0.0.
-
property
md5
¶ Return the md5sum of the binary.
New in version 0.7.10.
-
property
origins
¶ Return a list of origins for the package version.
-
property
policy_priority
¶ Return the internal policy priority as a number. See apt_preferences(5) for more information about what it means.
-
property
priority
¶ Return the priority of the package, as string.
-
property
provides
¶ Return a list of names that this version provides.
-
property
raw_description
¶ return the long description (raw).
-
property
recommends
¶ Return the recommends of the package version.
-
property
record
¶ 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
-
property
section
¶ Return the section of the package.
-
property
sha1
¶ Return the sha1sum of the binary.
New in version 0.7.10.
-
property
sha256
¶ Return the sha256sum of the binary.
New in version 0.7.10.
-
property
size
¶ Return the size of the package.
-
property
source_name
¶ Return the name of the source package.
-
property
source_version
¶ Return the version of the source package.
-
property
suggests
¶ Return the suggests of the package version.
-
property
summary
¶ Return the short description (one line summary).
-
property
tasks
¶ Get the tasks of the package.
A set of the names of the tasks this package belongs to.
New in version 0.8.0.
-
property
uri
¶ Return a single URI for the binary.
New in version 0.7.10.
-
property
uris
¶ Return a list of all available uris for the binary.
New in version 0.7.10.
-
property
version
¶ Return the version as a string.
-
property
Dependency Information¶
-
class
apt.package.
BaseDependency
(version: apt.package.Version, dep: apt_pkg.Dependency)¶ A single dependency.
-
property
installed_target_versions
¶ A list of all installed Version objects which satisfy this dep.
New in version 1.0.0.
-
property
name
¶ The name of the target package.
-
property
pre_depend
¶ Whether this is a PreDepends.
-
property
rawstr
¶ String represenation of the dependency.
Returns the string representation of the dependency as it would be written in the debian/control file. The string representation does not include the type of the dependency.
- Example for an unversioned dependency:
python3
- Example for a versioned dependency:
python3 >= 3.2
New in version 1.0.0.
-
property
rawtype
¶ 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.
-
property
relation
¶ The relation (<, <=, =, !=, >=, >, ‘’) in mathematical notation.
The empty string will be returned in case of an unversioned dependency.
-
property
relation_deb
¶ The relation (<<, <=, =, !=, >=, >>, ‘’) in Debian notation.
The empty string will be returned in case of an unversioned dependency. For more details see the Debian Policy Manual on the syntax of relationship fields: https://www.debian.org/doc/debian-policy/ch-relationships.html#s-depsyntax # noqa
New in version 1.0.0.
-
property
target_versions
¶ A list of all Version objects which satisfy this dependency.
New in version 1.0.0.
-
property
version
¶ The target version or an empty string.
Note that the version is only an empty string in case of an unversioned dependency. In this case the relation is also an empty string.
-
property
-
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).
-
The Record class¶
-
class
apt.package.
Record
(record_str: str)¶ 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.-
record[name]
Return the value of the field with the name name.
-
name in record
Return whether a field name exists in record.
-
len(record)
The number of fields in the record
-
str(record)
Display the record as a string
-
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.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()