The D-Bus API of the aptdaemon

Aptdaemon provides two D-Bus interfaces on the system bus.

org.debian.apt — The aptdaemon interface

This is the main interface which allows you to perform package managing tasks. It is proivded by the aptdaemon object at /org/debian/apt.

There are two kind of tasks: ones which are performed immediately and ones which are queued up in transaction and performed in a sequence.

Non-transaction based methods

AptDaemon.GetTrustedVendorKeys() -> array(string)

Get the list of the installed vendor keys which are used to authenticate packages.

Requires the org.debian.apt.get-trusted-vendor-keys PolicyKit privilege.

Returns:Fingerprints of all installed keys.
AptDaemon.Quit()

Request a shutdown of the daemon.

Transaction based methos

Instead of performing the task immediately, a new transaction will be created and the method will return the D-Bus path of it. Afterwards you can simulate the transaction or put it on the queue.

Life cycle of a transaction based action and Chaining Transactions are described in the Python client documentation with code examples.

AptDaemon.UpdateCache() → string

Download the latest information about available packages from the repositories and rebuild the package cache.

Requires the org.debian.apt.update-cache PolicyKit privilege.

Returns:The D-Bus path of the new transaction object which performs this action.
AptDaemon.UpdateCachePartially(sources_list : string) → string

Update the cache from the repositories defined in the given sources.list only.

Requires the org.debian.apt.update-cache PolicyKit privilege.

Parameters:sources_list (s) – The absolute path to a sources.list, e.g. /etc/apt/sources.list.d/ppa-aptdaemon.list or the name of the snippet in /etc/apt/sources.list.d/, e.g. ppa-aptdaemon.list.
Returns:The D-Bus path of the new transaction object which performs this action.
AptDaemon.AddRepository(src_type : string, uri : string, dist : string, comps : array(string), comment : string, sourcesfile : string) → string

Add given repository to the sources list.

Requires the org.debian.apt.change-repositories PolicyKit privilege.

Parameters:
  • src_type (s) – The type of the repository (deb, deb-src).
  • uri (s) – The main repository URI (e.g. http://archive.ubuntu.com/ubuntu)
  • dist (s) – The distribution to use (e.g. stable or lenny-backports).
  • comps (as) – List of components (e.g. main, restricted).
  • comment (s) – A comment which should be added to the sources.list.
  • sourcesfile (s) – (Optoinal) filename in sources.list.d.
Returns:

The D-Bus path of the new transaction object which performs this action.

AptDaemon.EnableDistroComponent(component : string) → string

Enable the component in the distribution repositories. This will not affect third-party repositories.

The repositories of a distribution are often separated into different components because of policy reasons. E.g. Debian uses main for DFSG-free software and non-free for re-distributable but not free in the sense of the Debian Free Software Guidelines.

Requires the org.debian.apt.change-repositories PolicyKit privilege.

Parameters:component (s) – The component, e,g, main or non-free.
Returns:The D-Bus path of the new transaction object which performs this action.
AptDaemon.InstallFile(path : string, force : boolean) → string

Install the given local package file.

Requires the org.debian.apt.install-file PolicyKit privilege.

Parameters:
  • path (s) – The absolute path to the package file.
  • force (b) – If the installation of a package which violates the Debian/Ubuntu policy should be forced.
Returns:

The D-Bus path of the new transaction object which performs this action.

AptDaemon.InstallPackages(package_names : array(string)) → string

Fetch and install the given packages from the repositories.

The version number and target release of the packages can be specified using the traditional apt-get syntax, e.g. “xterm=281.1” to force installing the version 281.1 of xterm or “xterm/experimental” to force installing xterm from the experimental release.

Requires the org.debian.apt.install-or-remove-packages PolicyKit privilege.

Parameters:package_names (as) – Packages to be upgraded
Returns:The D-Bus path of the new transaction object which performs this action.
AptDaemon.RemovePackages(package_names : array(string)) → string

Remove the given packages from the system. The configuration files will be kept by default. Use CommitPackages() to also purge the configuration files.

Requires the org.debian.apt.install-or-packages PolicyKit privilege.

Parameters:package_names (as) – packages to be removed
Returns:The D-Bus path of the new transaction object which performs this action.
AptDaemon.UpgradePackages(package_names : array(string)) → string

Upgrade the given packages to their latest version.

The version number and target release of the packages can be specified using the traditional apt-get syntax, e.g. “xterm=281.1” to force installing the version 281.1 of xterm or “xterm/experimental” to force installing xterm from the experimental release.

Requires the org.debian.apt.upgrade-packages PolicyKit privilege.

Parameters:package_names (as) – Packages to be upgraded
Returns:The D-Bus path of the new transaction object which performs this action.
AptDaemon.CommitPackages(install : array(string), reinstall : array(string), remove : array(string), purge : array(string), upgrade : array(string), downgrade : array(string)) → string

Perform several package changes at the same time.

The version number and target release of the packages can be specified using the traditional apt-get syntax, e.g. “xterm=281.1” to force installing the version 281.1 of xterm or “xterm/experimental” to force installing xterm from the experimental release.

Requires the org.debian.apt.install-or-remove-packages PolicyKit privilege.

Parameters:
  • install (as) – Packages to be installed.
  • reinstall (as) – Packages to be re-installed
  • remove (as) – Packages to be removed
  • purge (as) – Package to be removed including theirs configuration files.
  • upgrade (as) – Packages to be upgraded.
  • downgrade (as) – Packages to be downgraded. You have to append the target version to the package name separated by “=”
Returns:

The D-Bus path of the new transaction object which performs this action.

AptDaemon.UpgradeSystem(safe_mode : boolean) → string

Apply all available upgrades and try to resolve conflicts.

Requires the org.debian.apt.upgrade-packages PolicyKit privilege.

Parameters:safe_mode – If True only already installed packages will be updated. Updates which require to remove installed packages or to install additional packages will be skipped.
Returns:The D-Bus path of the new transaction object which performs this action.
AptDaemon.FixIncompleteInstall() → string

Try to complete cancelled installations. This is equivalent to a call of dpkg --configure -a.

Requires the org.debian.apt.install-or-remove-packages PolicyKit privilege.

Returns:The D-Bus path of the new transaction object which performs this action.
AptDaemon.FixBrokenDepends() → string

Try to resolve unsatisfied dependencies of installed packages.

Requires the org.debian.apt.install-or-remove-packages PolicyKit privilege.

Returns:The D-Bus path of the new transaction object which performs this action.
AptDaemon.AddVendorKeyFromKeyserver(keyid : string, keyserver : string) → string

Download and install the key of a software vendor. The key is used to authenticate packages of the vendor.

Requires the org.debian.apt.change-repositories PolicyKit privilege.

Parameters:
  • keyid (s) – The id of the GnuPG key (e.g. 0x0EB12F05)
  • keyserver (s) – The server to get the key from (e.g. keyserver.ubuntu.com)
Returns:

The D-Bus path of the new transaction object which performs this action.

AptDaemon.AddVendorKeyFromFile(path : string) → string

Install the key file of a software vendor. The key is used to authenticate packages of the vendor.

Requires the org.debian.apt.change-repositories PolicyKit privilege.

Parameters:path (s) – The absolute path to the key file.
Returns:The D-Bus path of the new transaction object which performs this action.

Signals

The following singal can be emitted on the org.debian.apt interface.

AptDaemon.ActiveTransactionsChanged(current : string, queued : array(string))

The currently processed or the queued transactions changed.

Parameters:
  • current (s) – The path of the currently running transaction or an empty string.
  • queued (as) – List of the ids of the queued transactions.

Properties

The daemon interface provides a set of properties which can be accessed and modified through Set(), Get() and GetAll() methods of the org.freedesktop.DBus.Properties interface. See the D-Bus specification for more details.

The following properties are available:

AutoCleanInterval : i

The interval in days in which the cache of downloaded packages should should be cleaned. A value of 0 disables this feature.

writable

AutoDownload : b

If available upgrades should be already downloaded in the background. The upgrades won’t get installed automatically.

writable

AutoUpdateInterval : i

The interval in days in which the software repositories should be checked for updates. A value of 0 disables the automatic check.

writable

PopConParticipation : b

If statistics about installed software and how often it is used should be sent to the distribution anonymously. This helps to determine which software should be shipped on the first install CDROMs and to make software recommendations.

writable

UnattendedUpgrade : i

The interval in days in which updates should be installed automatically. A value of 0 disables this feature.

writable

RebootRequired : b

Set if a reboot is required in order to complete the update.

readonly

org.debian.apt.transaction — The transaction interface

This is the main interface of a transaction object. It allows to control and monitor the transaction. Transactions are created by using the org.debian.apt interface of aptdaemon.

The path of a transaction object consists of /org/debian/apt/transaction/ and an unique identifier.

Methods

Transaction.Run()

Check the authentication, simulate and queue the transaction for processing.

Transaction.RunAfter(tid : string)

Queue the transaction for processing after the given transaction.

The transaction will also fail if the previous one failed. Several transactions can be chained up.

Parameters:tid (s) – The id of the transaction which should be executed before.
Transaction.Cancel()

Cancel the transaction.

Transaction.Simulate()

Simulate a transaction to update its dependencies, download size and required disk space.

Call this method if you want to show changes before queuing the transaction.

Transaction.ProvideMedium(medium : string)

Continue paused transaction with the inserted medium.

If a media change is required to install packages from CD/DVD the transaction will be paused and could be resumed with this method.

Parameters:medium (s) – The label of the CD/DVD.
Transaction.ResolveConfigFileConflict(config : string, answer : string)

Resolve a configuration file conflict and continue the transaction.

If a config file prompt is detected the transaction will be paused and could be resumed with this method.

Parameters:
  • config (s) – The path to the original config file.
  • answer (s) – The answer to the configuration file question, can be “keep” or “replace”

Signals

Transaction.Finished() → string

The signal gets emitted if the transaction has been finished.

Parameters:exit_state (s) – The exit state of the transaction, e.g. exit-failed.
Transaction.PropertyChanged() → string, variant

The signal gets emitted if a property of the transaction changed.

Parameters:
  • property (s) – The name of the property.
  • value (v) – The new value of the property.

Properties

The transaction interface provides a set of properties which can be accessed and modified through Set(), Get() and GetAll() methods of the org.freedesktop.DBus.Properties interface. See the D-Bus specification for more details.

For the documentation of the available string enumerations, see aptdaemon.enums.

The following properties are available:

AllowUnauthenticated : b

If it is allowed to install not authenticated packages by the transaction. Defaults to False.

writable

Cancellable : b

If the transaction can be cancelled at the moment.

read-only

ConfigFileConflict : (ss)

If the transaction waits for the resolution of a configuration file conflict, this property contains an array of the path to the old and the path to the new configuration file. See ResolveConfigFileConflict().

read-only

DebconfSocket : s

The path to the socket which should be used to proxy debconf communication to the user.

writable

Dependencies : (asasasasasasas)

Array of package groups which will be modified as dependencies:

  • array of the packages to install
  • array of the packages to re-install
  • array of the packages to remove
  • array of the packages to purge
  • array of the packages to upgrade
  • array of the packages to downgrade
  • array of the packages to not upgrade (keep)

The packages are specified by their name and a version number separated by an “=”, e.g. “xterm=261-1”. The dependencies are calculated after Simulate() or Run() was called.

read-only

Download : x

The required download size in Bytes.

The property is available after Simulate() or Run() has been called.

read-only

Error : (ss)

If the transaction failed this property contains an array of the error code, e.g. error-no-lock and a detailed error message.

read-only

ExitState : s

If the transaction is completed it contains the exit status enum of the transaction, e.g. exit-failed. If the transaction has not yet been completed it is exit-unfinished.

read-only

HttpProxy : s

The URL of an http proxy which should be used for downloads by the transaction, e.g. http://proxy:8080.

writable

Locale : s

The locale which is used to translate messages, e.g. de_DE@UTF-8.

writable

MetaData : a{sv}

The meta data dictionary allows client applications to store additional data persistently in the transaction object. The key has to be a string and be prefixed by an underscore separated identifier of the client application, e.g. Software Center uses sc_app to store the application corresponding to the transaction.

If a dict is written to the property it will be merged with the existing one. It is not allowed to override already existing keys.

writable

Progress : i

The progress in percent of the transaction.

read-only

Packages : (asasasasasas)

Array of package groups which have been specified by the user intially to be modified:

  • array of the packages to install
  • array of the packages to re-install
  • array of the packages to remove
  • array of the packages to purge
  • array of the packages to upgrade
  • array of the packages to downgrade

The packages are specified by their name and an optional version number separated by an “=”, e.g. “xterm=261-1”. Furthermore if specified the target release of the package will be separated by a “/”, e.g. “xterm/experimental”.

read-only

Paused : b

If the transaction is paused, e.g. it is waiting for a medium or the resolution of a configuration file conflict.

read-only

ProgressDetails : (iixxdx)

A list with detailed progress information:

  • number of already processed items
  • number of total items
  • number of already downloaded bytes
  • number of total bytes which have to be downloaded
  • number of bytes downloaded per second
  • remaining time in seconds

read-only

ProgressDownload : (sssxxs)

The last progress information update of a currently running download. A list of ..

  • URL of the download
  • status enum of the download, e.g. download-fetching.
  • short description of the download
  • number of already downloaded bytes
  • number of total bytes which have to be downloaded
  • Status message

read-only

RemoveObsoletedDepends : b

If in the case of a removal obsolete dependencies which have been installed automatically before should be removed, too. writable

RequiredMedium : (ss)

If the transaction waits for a medium to be inserted this property contains an array of the medium name and the path to the drive in which it should be inserted. read-only

Role : s

The enum representing the type of action performed by the transaction e.g. role-install-packages. read-only

Space : x

The required disk space in Bytes. If disk spaces is freed the value will be negative.

The property is available after Simulate() or Run() has been called.

read-only

Status : s

The status enum of the transaction, e.g. status-loading-cache.

read-only

StatusDetails : s

A human readable string with additional download information.

read-only

Terminal : s

The path to the slave end of the controlling terminal which should be used to controll the underlying dpkg call.

writable

TerminalAttached : b

If the controlling terminal can be used to control the underlying dpkg call.

read-only

Unauthenticated : as

List of packages which are going to be installed but are not from an authenticated repository.

read-only

PolicyKit privileges

Most actions require the user to authenticate. The PolicyKit framework is used by aptdaemon for the authentication process. This allows to run aptdaemon as root and the client application as normal user.

For non-transaction based actions the authentication will happen immediately. For transaction based actions the privilege will be checked after Run() has been called. If the privilege has not yet been granted the user will be requested to authenticate interactively. This allows the user to simulate a transaction before having to authenticate.

Aptdaemon supports so called high level privileges which allow to perform a specified set of actions in a row without having to authenticate for each one separately. This only works if the client application authenticates for the high level privilge before running the transactions and the authentication is cached.

There are two high level privileges install-packages-from-new-repo and install-purchased-software. Both allow to add a repository, install the key of vendor from a keyserver, update the cache and to install packages.

#!/usr/bin/python

import dbus
import gobject

from aptdaemon.client import AptClient
from aptdaemon.defer import inline_callbacks
from aptdaemon import policykit1

loop = gobject.MainLoop()

def on_finished(trans, exit):
    loop.quit()
    print exit

@inline_callbacks
def main():
    repo = ["deb", "http://packages.glatzor.de/silly-packages", "sid", ["main"],
            "Silly packages", "silly.list"]
    aptclient = AptClient()
    bus = dbus.SystemBus()
    name = bus.get_unique_name()
    # high level auth
    try:
        # Preauthentication
        action = policykit1.PK_ACTION_INSTALL_PURCHASED_PACKAGES
        flags = policykit1.CHECK_AUTH_ALLOW_USER_INTERACTION
        yield policykit1.check_authorization_by_name(name, action, flags=flags)
        # Setting up transactions
        trans_add = yield aptclient.add_repository(*repo)
        trans_update = yield aptclient.update_cache("silly.list")
        trans_inst = yield aptclient.install_packages(["silly-base"])
        yield trans_inst.set_allow_unauthenticated(True)
        # Check when the last transaction was done
        trans_inst.connect("finished", on_finished)
        # Chaining transactions
        yield trans_update.run_after(trans_add)
        yield trans_inst.run_after(trans_update)
        yield trans_add.run()
    except Exception as error:
        print error
        loop.quit()

if __name__ == "__main__":
    main()
    loop.run()